Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: App_Pese_Ruche_SYSBEE
Fork of C027_Support by
Revision 18:e5697801df29, committed 2014-03-14
- Comitter:
- mazgch
- Date:
- Fri Mar 14 13:07:48 2014 +0000
- Parent:
- 17:296d94a006b4
- Child:
- 19:2b5d097ca15d
- Child:
- 20:535ef78655df
- Commit message:
- extend Api for GPS and GNSS
Changed in this revision
--- a/GPS.cpp Fri Jan 31 09:49:51 2014 +0000
+++ b/GPS.cpp Fri Mar 14 13:07:48 2014 +0000
@@ -203,6 +203,24 @@
return false;
}
+bool GPSParser::getNmeaAngle(int ix, char* buf, int len, double& d)
+{
+ char ch;
+ char val;
+ if (getNmeaItem(ix,buf,len,val) && getNmeaItem(ix+1,buf,len,ch) &&
+ ((ch == 'S') || (ch == 'N') || (ch == 'E') || (ch == 'W')))
+ {
+ val *= 0.01;
+ int i = (int)d;
+ val = (val - i) / 0.6 + i;
+ if (ch == 'S' || ch == 'W')
+ val = -val;
+ d = val;
+ return true;
+ }
+ return false;
+}
+
const char GPSParser::toHex[] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };
// ----------------------------------------------------------------
@@ -221,11 +239,6 @@
return _getMessage(&_pipeRx, buf, len);
}
-char GPSSerial::next(void)
-{
- return _pipeRx.next();
-}
-
int GPSSerial::_send(const void* buf, int len)
{
return put((const char*)buf, len, true/*=blocking*/);
@@ -319,11 +332,6 @@
return read;
}
-char GPSI2C::next(void)
-{
- return _pipe.next();
-}
-
int GPSI2C::_send(const void* buf, int len)
{
return !I2C::write(GPSADR,(const char*)buf,len,true) ? len : 0;
--- a/GPS.h Fri Jan 31 09:49:51 2014 +0000
+++ b/GPS.h Fri Mar 14 13:07:48 2014 +0000
@@ -28,6 +28,7 @@
static bool getNmeaItem(int ix, char* buf, int len, double& val);
static bool getNmeaItem(int ix, char* buf, int len, int& val, int base/*=10*/);
static bool getNmeaItem(int ix, char* buf, int len, char& val);
+ static bool getNmeaAngle(int ix, char* buf, int len, double& d);
protected:
static int _getMessage(Pipe<char>* pipe, char* buf, int len);
static int _parseNmea(Pipe<char>* pipe, int len);
@@ -43,7 +44,6 @@
int rxSize = RX_SIZE, int txSize = TX_SIZE);
virtual int getMessage(char* buf, int len);
protected:
- virtual char next(void);
virtual int _send(const void* buf, int len);
};
@@ -59,7 +59,6 @@
virtual int sendNmea(const char* buf, int len);
virtual int sendUbx(unsigned char cls, unsigned char id, const void* buf = NULL, int len = 0);
protected:
- virtual char next(void);
bool writeable(void) { return true; }
bool putc(int c) { char ch = c; return send(&ch, 1); }
virtual int _send(const void* buf, int len);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MDM.cpp Fri Mar 14 13:07:48 2014 +0000
@@ -0,0 +1,113 @@
+#include "mbed.h"
+#include <ctype.h>
+#include "MDM.h"
+
+
+int MDMParser::send(const char* buf, int len)
+{
+ return _send(buf, len);
+}
+
+int MDMParser::_getLine(Pipe<char>* pipe, char* buffer, int length)
+{
+ int o = 0;
+ int i = 0;
+ int l = pipe->start();
+ while ((i < l) && (o < length))
+ {
+ int t = pipe->next();
+ i ++;
+ if (t == '\r') // terminate commands with carriage return
+ {
+ pipe->done();
+ if (length > o)
+ buffer[o] = '\0';
+ return o; // if enter send the zero char
+ }
+ else if (t == '\n') // skip/filter new line
+ /* skip */;
+ else if (t != '\b') // normal char (no backspace)
+ buffer[o++] = t;
+ else if (o > 0) // backspace
+ o --; // remove it
+ }
+ o = 0;
+ if (length > 0)
+ buffer[0] = '\0';
+ return WAIT;
+}
+
+int MDMParser::_getResp(Pipe<char>* pipe, char* buffer, int length)
+{
+ int o = 0;
+ int i = 0;
+ int l = pipe->start();
+ static const char erTxt[] = "ERROR\r\n";
+ static const char okTxt[] = "OK\r\n";
+ int er = 0;
+ int ok = 0;
+ while ((i < pipe->size()) && (o < length))
+ {
+ int t = pipe->next();
+ i ++;
+ buffer[o++] = t;
+ ok = (t == okTxt[ok]) ? ok + 1 : 0;
+ er = (t == erTxt[er]) ? er + 1 : 0;
+ if ((okTxt[ok] == '\0') || (erTxt[er] == '\0'))
+ {
+ pipe->done();
+ if (length > o)
+ buffer[o] = '\0';
+ return o;
+ }
+ }
+ o = 0;
+ if (length > 0)
+ buffer[0] = '\0';
+ return WAIT;
+}
+
+// ----------------------------------------------------------------
+// Serial Implementation
+// ----------------------------------------------------------------
+
+MDMSerial::MDMSerial(PinName tx /*= MDMTXD*/, PinName rx /*= MDMRXD*/, int baudrate /*= MDMBAUD*/,
+ int rxSize /*= 256*/, int txSize /*= 128*/) :
+ SerialPipe(tx, rx, rxSize, txSize)
+{
+ baud(baudrate);
+}
+
+MDMSerial::MDMSerial(PinName tx /*= MDMTXD*/, PinName rx /*= MDMRXD*/, int baudrate /*= MDMBAUD*/,
+ PinName rts /*= MDMRTS*/, PinName cts /*= MDMCTS*/, int rxSize /*= 256*/, int txSize /*= 128*/) :
+ SerialPipe(tx, rx, rts, cts, rxSize, txSize)
+{
+ baud(baudrate);
+}
+
+int MDMSerial::_send(const void* buf, int len)
+{
+ return put((const char*)buf, len, true/*=blocking*/);
+}
+
+int MDMSerial::getLine(char* buffer, int length)
+{
+ return _getLine(&_pipeRx, buffer, length);
+}
+
+int MDMSerial::getResp(char* buffer, int length)
+{
+ return _getResp(&_pipeRx, buffer, length);
+}
+
+// ----------------------------------------------------------------
+// USB Implementation
+// ----------------------------------------------------------------
+
+#ifdef HAVE_MDMUSB
+// TODO properly implement with USB
+MDMUsb::MDMUsb(void) { }
+int MDMUsb::_send(const void* buf, int len) { return len; }
+int MDMUsb::getLine(char* buffer, int length) { return NOT_FOUND; }
+int MDMUsb::getResp(char* buffer, int length) { return NOT_FOUND; }
+#endif
\ No newline at end of file
--- a/MDM.h Fri Jan 31 09:49:51 2014 +0000
+++ b/MDM.h Fri Mar 14 13:07:48 2014 +0000
@@ -1,14 +1,60 @@
#pragma once
#include "mbed.h"
+#include "Pipe.h"
+#include "SerialPipe.h"
#include "C027_PinNames.h"
-class MDMSerial : public RawSerial
+#define RX_SIZE 256
+#define TX_SIZE 128
+
+class MDMParser
+{
+public:
+ #define WAIT -1
+ #define NOT_FOUND 0
+
+ #define LENGTH(x) (x & 0x00FFFF)
+// #define PROTOCOL(x) (x & 0xFF0000)
+ virtual int getLine(char* buf, int len) = 0;
+ virtual int getResp(char* buf, int len) = 0;
+ virtual int send(const char* buf, int len);
+
+protected:
+ static int _getLine(Pipe<char>* pipe, char* buffer, int length);
+ static int _getResp(Pipe<char>* pipe, char* buffer, int length);
+ virtual int _send(const void* buf, int len) = 0;
+};
+
+// -----------------------------------------------------------------------
+
+class MDMSerial : public SerialPipe, public MDMParser
{
public:
- MDMSerial() : RawSerial(MDMTXD,MDMRXD)
- {
- baud(MDMBAUD);
- set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
- }
+ MDMSerial(PinName tx = MDMTXD, PinName rx = MDMRXD, int baudrate = MDMBAUD,
+ int rxSize = RX_SIZE, int txSize = TX_SIZE);
+ MDMSerial(PinName tx = MDMTXD, PinName rx = MDMRXD, int baudrate = MDMBAUD,
+ PinName rts = MDMRTS, PinName cts = MDMCTS,
+ int rxSize = RX_SIZE, int txSize = TX_SIZE);
+ virtual int getLine(char* buffer, int length);
+ virtual int getResp(char* buffer, int length);
+protected:
+ virtual int _send(const void* buf, int len);
};
+
+// -----------------------------------------------------------------------
+
+#define HAVE_MDMUSB
+#ifdef HAVE_MDMUSB
+class MDMUsb : /*public UsbSerial,*/ public MDMParser
+{
+public:
+ MDMUsb(void);
+ virtual int getLine(char* buffer, int length);
+ virtual int getResp(char* buffer, int length);
+protected:
+ virtual int _send(const void* buf, int len);
+};
+#endif
+
+
--- a/SerialPipe.cpp Fri Jan 31 09:49:51 2014 +0000
+++ b/SerialPipe.cpp Fri Mar 14 13:07:48 2014 +0000
@@ -102,73 +102,3 @@
}
}
-// -----------------------------------------------------------------------
-
-int SerialPipeEx::getLine(char* buffer, int length)
-{
- return getLine(buffer, length, &_pipeRx);
-}
-
-int SerialPipeEx::getLine(char* buffer, int length, Pipe<char>* pipe)
-{
- int o = 0;
- int i = 0;
- int l = pipe->start();
- while ((i < l) && (o < length))
- {
- int t = pipe->next();
- i ++;
- if (t == '\r') // terminate commands with carriage return
- {
- pipe->done();
- if (length > o)
- buffer[o] = '\0';
- return o; // if enter send the zero char
- }
- else if (t == '\n') // skip/filter new line
- /* skip */;
- else if (t != '\b') // normal char (no backspace)
- buffer[o++] = t;
- else if (o > 0) // backspace
- o --; // remove it
- }
- o = 0;
- if (length > 0)
- buffer[0] = '\0';
- return WAIT;
-}
-
-int SerialPipeEx::getResp(char* buffer, int length)
-{
- return getResp(buffer, length, &_pipeRx);
-}
-
-int SerialPipeEx::getResp(char* buffer, int length, Pipe<char>* pipe)
-{
- int o = 0;
- int i = 0;
- int l = pipe->start();
- static const char erTxt[] = "ERROR\r\n";
- static const char okTxt[] = "OK\r\n";
- int er = 0;
- int ok = 0;
- while ((i < pipe->size()) && (o < length))
- {
- int t = pipe->next();
- i ++;
- buffer[o++] = t;
- ok = (t == okTxt[ok]) ? ok + 1 : 0;
- er = (t == erTxt[er]) ? er + 1 : 0;
- if ((okTxt[ok] == '\0') || (erTxt[er] == '\0'))
- {
- pipe->done();
- if (length > o)
- buffer[o] = '\0';
- return o;
- }
- }
- o = 0;
- if (length > 0)
- buffer[0] = '\0';
- return WAIT;
-}
--- a/SerialPipe.h Fri Jan 31 09:49:51 2014 +0000
+++ b/SerialPipe.h Fri Mar 14 13:07:48 2014 +0000
@@ -26,16 +26,3 @@
Pipe<char> _pipeRx;
Pipe<char> _pipeTx;
};
-
-// -----------------------------------------------------------------------
-#define WAIT -1
-#define NOT_FOUND 0
-
-class SerialPipeEx : public SerialPipe
-{
-public:
- int getLine(char* buffer, int length);
- static int getLine(char* buffer, int length, Pipe<char>* pipe);
- int getResp(char* buffer, int length);
- static int getResp(char* buffer, int length, Pipe<char>* pipe);
-};
