support library for C027 helper functions for Buffer Pipes, Buffered Serial Port (rtos capable) and GPS parsing. It includes modem APIs for USSD, SMS and Sockets.
Dependents: HTTPClient_Cellular_HelloWorld Cellular_HelloMQTT MbedSmartRestMain Car_Bon_car_module ... more
This library is intended to be used with u-blox products such as the C027 or a shield with u-blox cellular and GPS modules like the cellular and positioning shield from Embedded Artist.
For 2G/GSM and 3G/UMTS you need to:
- have a SIM card and know its PIN number
- need to know you network operators APN setting These setting should be passed to the connect or init and join functions. You can also extend the APN database in MDMAPN.h.
For CDMA products you need to make sure that you have provisioned and activated the modem with either Sprint or Verizon.
Revision 19:2b5d097ca15d, committed 2014-03-24
- Comitter:
- mazgch
- Date:
- Mon Mar 24 07:38:05 2014 +0000
- Parent:
- 18:e5697801df29
- Child:
- 21:c4d64830bf02
- Commit message:
- prepare for native C027 platform support; add api to get lat/lon; better separation of mdm libarary from serial
Changed in this revision
--- a/GPS.cpp Fri Mar 14 13:07:48 2014 +0000 +++ b/GPS.cpp Mon Mar 24 07:38:05 2014 +0000 @@ -206,12 +206,12 @@ bool GPSParser::getNmeaAngle(int ix, char* buf, int len, double& d) { char ch; - char val; + double 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; + int i = (int)val; val = (val - i) / 0.6 + i; if (ch == 'S' || ch == 'W') val = -val; @@ -249,9 +249,10 @@ // ---------------------------------------------------------------- GPSI2C::GPSI2C(PinName sda /*= GPSSDA*/, PinName scl /*= GPSSCL*/, - int rxSize /*= 256*/) : + unsigned char i2cAdr /*=GPSADR*/, int rxSize /*= 256*/) : I2C(sda,scl), - _pipe(rxSize) + _pipe(rxSize), + _i2cAdr(i2cAdr) { found = false; } @@ -260,7 +261,7 @@ { if (!found) { - int w = I2C::write(GPSADR,®STREAM,sizeof(REGSTREAM)); + int w = I2C::write(_i2cAdr,®STREAM,sizeof(REGSTREAM)); if (w == 0) found = true; } @@ -284,7 +285,7 @@ int sent = 0; if (len) { - if (!I2C::write(GPSADR,®STREAM,sizeof(REGSTREAM),true)) + if (!I2C::write(_i2cAdr,®STREAM,sizeof(REGSTREAM),true)) sent = send(buf, len); found = (len == sent); stop(); @@ -295,7 +296,7 @@ int GPSI2C::sendNmea(const char* buf, int len) { int sent = 0; - if (!I2C::write(GPSADR,®STREAM,sizeof(REGSTREAM),true)) + if (!I2C::write(_i2cAdr,®STREAM,sizeof(REGSTREAM),true)) sent = GPSParser::sendNmea(buf, len); found = (len == sent); stop(); @@ -305,7 +306,7 @@ int GPSI2C::sendUbx(unsigned char cls, unsigned char id, const void* buf, int len) { int sent = 0; - if (!I2C::write(GPSADR,®STREAM,sizeof(REGSTREAM),true)) + if (!I2C::write(_i2cAdr,®STREAM,sizeof(REGSTREAM),true)) sent = GPSParser::sendUbx(cls, id, buf, len); found = (len == sent); I2C::stop(); @@ -316,14 +317,14 @@ { int read = 0; unsigned char sz[2]; - if (!I2C::write(GPSADR,®LEN,sizeof(REGLEN),true) && - !I2C::read(GPSADR,(char*)sz,sizeof(sz),true)) + if (!I2C::write(_i2cAdr,®LEN,sizeof(REGLEN),true) && + !I2C::read(_i2cAdr,(char*)sz,sizeof(sz),true)) { int size = 256 * (int)sz[0] + sz[1]; if (size > len) size = len; if (size > 0) - read = !I2C::read(GPSADR,buf,size, true) ? size : 0; + read = !I2C::read(_i2cAdr,buf,size, true) ? size : 0; found = (read == size); } else @@ -334,7 +335,7 @@ int GPSI2C::_send(const void* buf, int len) { - return !I2C::write(GPSADR,(const char*)buf,len,true) ? len : 0; + return !I2C::write(_i2cAdr,(const char*)buf,len,true) ? len : 0; } const char GPSI2C::REGLEN = 0xFD;
--- a/GPS.h Fri Mar 14 13:07:48 2014 +0000 +++ b/GPS.h Mon Mar 24 07:38:05 2014 +0000 @@ -3,10 +3,15 @@ #include "mbed.h" #include "Pipe.h" #include "SerialPipe.h" -#include "C027_PinNames.h" -#define RX_SIZE 256 -#define TX_SIZE 128 +#ifdef TARGET_UBLOX_C027 + // if we detect the C027 platform we will assign the + // default pinname and baudrate in the constructor + // this helper macro will be used. + #define _C027DEFAULT(name) = name +#else + #define _C027DEFAULT(name) +#endif class GPSParser { @@ -40,8 +45,11 @@ class GPSSerial : public SerialPipe, public GPSParser { public: - GPSSerial(PinName tx = GPSTXD, PinName rx = GPSRXD, int baudrate = GPSBAUD, - int rxSize = RX_SIZE, int txSize = TX_SIZE); + GPSSerial(PinName tx _C027DEFAULT( GPSTXD ), + PinName rx _C027DEFAULT( GPSRXD ), + int baudrate _C027DEFAULT( GPSBAUD ), + int rxSize = 256 , + int txSize = 128 ); virtual int getMessage(char* buf, int len); protected: virtual int _send(const void* buf, int len); @@ -50,8 +58,10 @@ class GPSI2C : public I2C, public GPSParser { public: - GPSI2C(PinName sda = GPSSDA, PinName scl = GPSSCL, - int rxSize = RX_SIZE); + GPSI2C(PinName sda _C027DEFAULT( GPSSDA ), + PinName scl _C027DEFAULT( GPSSCL ), + unsigned char i2cAdr _C027DEFAULT( GPSADR ), + int rxSize = 256 ); bool detect(void); virtual int getMessage(char* buf, int len); @@ -66,6 +76,7 @@ Pipe<char> _pipe; bool found; + unsigned char _i2cAdr; static const char REGLEN; static const char REGSTREAM; };
--- a/MDM.cpp Fri Mar 14 13:07:48 2014 +0000 +++ b/MDM.cpp Mon Mar 24 07:38:05 2014 +0000 @@ -71,16 +71,17 @@ // Serial Implementation // ---------------------------------------------------------------- -MDMSerial::MDMSerial(PinName tx /*= MDMTXD*/, PinName rx /*= MDMRXD*/, int baudrate /*= MDMBAUD*/, +MDMSerial::MDMSerial(PinName tx /*= MDMTXD*/, PinName rx /*= MDMRXD*/, + int baudrate /*= MDMBAUD*/, +#if DEVICE_SERIAL_FC + PinName rts /*= MDMRTS*/, PinName cts /*= MDMCTS*/, +#endif int rxSize /*= 256*/, int txSize /*= 128*/) : +#if DEVICE_SERIAL_FC + SerialPipe(tx, rx, rts, cts, rxSize, txSize) +#else 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) +#endif { baud(baudrate); }
--- a/MDM.h Fri Mar 14 13:07:48 2014 +0000 +++ b/MDM.h Mon Mar 24 07:38:05 2014 +0000 @@ -3,10 +3,15 @@ #include "mbed.h" #include "Pipe.h" #include "SerialPipe.h" -#include "C027_PinNames.h" -#define RX_SIZE 256 -#define TX_SIZE 128 +#ifdef TARGET_UBLOX_C027 + // if we detect the C027 platform we will assign the + // default pinname and baudrate in the constructor + // this helper macro will be used. + #define _C027DEFAULT(name) = name +#else + #define _C027DEFAULT(name) +#endif class MDMParser { @@ -31,11 +36,15 @@ class MDMSerial : public SerialPipe, public MDMParser { public: - 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); + MDMSerial(PinName tx _C027DEFAULT(MDMTXD), + PinName rx _C027DEFAULT(MDMRXD), + int baudrate _C027DEFAULT(MDMBAUD), +#if DEVICE_SERIAL_FC + PinName rts _C027DEFAULT(MDMRTS), + PinName cts _C027DEFAULT(MDMCTS), +#endif + int rxSize = 256 , + int txSize = 256 ); virtual int getLine(char* buffer, int length); virtual int getResp(char* buffer, int length); protected:
--- a/SerialPipe.cpp Fri Mar 14 13:07:48 2014 +0000 +++ b/SerialPipe.cpp Mon Mar 24 07:38:05 2014 +0000 @@ -9,6 +9,8 @@ attach(this, &SerialPipe::txIrqBuf, TxIrq); } + +#if DEVICE_SERIAL_FC SerialPipe::SerialPipe(PinName tx, PinName rx, PinName rts, PinName cts, int rxSize, int txSize) : _SerialPipeBase(tx,rx), _pipeRx(rxSize), _pipeTx(txSize) @@ -18,6 +20,7 @@ set_flow_control(RTSCTS, rts, cts); } +#endif SerialPipe::~SerialPipe(void) {
--- a/SerialPipe.h Fri Mar 14 13:07:48 2014 +0000 +++ b/SerialPipe.h Mon Mar 24 07:38:05 2014 +0000 @@ -9,7 +9,9 @@ { public: SerialPipe(PinName tx, PinName rx, int rxSize = 128, int txSize = 128); +#if DEVICE_SERIAL_FC SerialPipe(PinName tx, PinName rx, PinName rts, PinName cts, int rxSize = 128, int txSize = 128); +#endif virtual ~SerialPipe(void); // tx channel int writeable(void);