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 35:9275215a3a5b, committed 2014-04-10
- Comitter:
- mazgch
- Date:
- Thu Apr 10 13:05:45 2014 +0000
- Parent:
- 34:3b3b7807c0c3
- Child:
- 36:c4df7bcf9b6e
- Commit message:
- fix low power mode
Changed in this revision
--- a/MDM.cpp Wed Apr 09 14:25:41 2014 +0000 +++ b/MDM.cpp Thu Apr 10 13:05:45 2014 +0000 @@ -4,7 +4,7 @@ #include "MDM.h" #define TRACE (0)?:printf -//#define DEBUG // enable this for AT command debugging +#define DEBUG // enable this for AT command debugging #define PROFILE "0" // this is the psd profile used #define MAX_SIZE 256 // max expected messages // some helper @@ -40,7 +40,7 @@ { memset(&_dev, 0, sizeof(_dev)); memset(&_net, 0, sizeof(_net)); - _ip = NOIP; + _ip = NOIP; memset(_sockets, 0, sizeof(_sockets)); } @@ -78,6 +78,7 @@ int len = LENGTH(ret); int type = TYPE(ret); const char* s = (type == TYPE_UNKNOWN)? YEL("UNK") : + (type == TYPE_TEXT) ? MAG("TXT") : (type == TYPE_OK ) ? GRE("OK ") : (type == TYPE_ERROR) ? RED("ERR") : (type == TYPE_PLUS) ? CYA(" + ") : @@ -179,7 +180,7 @@ int MDMParser::_cbString(int type, const char* buf, int len, char* str) { - if (str && (type == TYPE_UNKNOWN)) { + if (str && (type == TYPE_TEXT)) { if (sscanf(buf, "\r\n%s\r\n", str) == 1) /*nothing*/; } @@ -188,7 +189,7 @@ int MDMParser::_cbInt(int type, const char* buf, int len, int* val) { - if (val && (type == TYPE_UNKNOWN)) { + if (val && (type == TYPE_TEXT)) { if (sscanf(buf, "\r\n%d\r\n", val) == 1) /*nothing*/; } @@ -199,12 +200,15 @@ bool MDMParser::init(const char* pin, DevStatus* status) { - for(int i = 0; i < 5; i++) { + int i = 5; + while (i--) { // check interface and disable local echo sendFormated("AT\r\n"); if(OK == waitFinalResp()) break; } + if (i == 0) + return false; // echo off sendFormated("AT E0\r\n"); if(OK != waitFinalResp()) @@ -226,10 +230,6 @@ return false; // device specific init if (_dev.dev == DEV_LISA_C200) { - // disable flow control - sendFormated("AT+IFC=0,0\r\n"); - if (OK != waitFinalResp()) - return false; // get the manufacturer sendFormated("AT+GMI\r\n"); if (OK != waitFinalResp(_cbString, _dev.manu)) @@ -247,20 +247,13 @@ if (OK != waitFinalResp(_cbString, _dev.meid)) return false; } else { - // disable flow control - sendFormated("AT&K0\r\n"); - if (OK != waitFinalResp()) - return false; - // enable power saving - sendFormated("AT+UPSV=1\r\n"); - if (OK != waitFinalResp()) - return false; - // enable the network identification feature if (_dev.dev == DEV_LISA_U200) { + // enable the network identification feature sendFormated("AT+UGPIOC=20,2\r\n"); if (OK != waitFinalResp()) return false; } else { + // enable the network identification feature sendFormated("AT+UGPIOC=16,2\r\n"); if (OK != waitFinalResp()) return false; @@ -324,6 +317,14 @@ sendFormated("AT+CIMI\r\n"); if (OK != waitFinalResp(_cbString, _dev.imsi)) return false; + // enable power saving + if (_dev.lpm != LPM_DISABLED) { + // enable power saving (requires flow control, cts at least) + sendFormated("AT+UPSV=1\r\n"); + if (OK != waitFinalResp()) + return false; + _dev.lpm = LPM_ACTIVE; + } if (status) memcpy(status, &_dev, sizeof(DevStatus)); return true; @@ -331,7 +332,7 @@ int MDMParser::_cbATI(int type, const char* buf, int len, Dev* dev) { - if ((type == TYPE_UNKNOWN) && dev) { + if ((type == TYPE_TEXT) && dev) { if (strstr(buf, "SARA-G350")) { *dev = DEV_SARA_G350; /*TRACE("Identified Device: SARA-G350 2G\\n")*/; @@ -857,7 +858,7 @@ if (type == TYPE_PLUS) { if (sscanf(buf, "\r\n+CMGR: \"%*[^\"]\",\"%[^\"]", param->num) == 1) { } - } else if ((type == TYPE_UNKNOWN) && (buf[len-2] == '\r') && (buf[len-1] == '\n')) { + } else if ((type == TYPE_TEXT) && (buf[len-2] == '\r') && (buf[len-1] == '\n')) { memcpy(param->buf, buf, len-2); param->buf[len-2] = '\0'; } @@ -912,6 +913,10 @@ } } if (!end) return o; // no termination + // at least any char + if (++o > len) return WAIT; + pipe->next(); + // check the end int x = 0; while (end[x]) { if (++o > len) return WAIT; @@ -988,6 +993,7 @@ { "\r\n+", "\r\n", TYPE_PLUS }, { "\r\n@", NULL, TYPE_PROMPT }, // Sockets { "\r\n>", NULL, TYPE_PROMPT }, // SMS + { "\r\n", "\r\n", TYPE_TEXT }, }; for (int i = 0; i < sizeof(lutF)/sizeof(*lutF); i ++) { pipe->set(unkn); @@ -1022,22 +1028,26 @@ 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) -#endif + SerialPipe(tx, rx, rxSize, txSize) { baud(baudrate); + // have it fix low +#if DEVICE_SERIAL_FC + if ((rts != NC) || (cts != NC)) + { + Flow flow = (cts == NC) ? RTS : + (rts == NC) ? CTS : RTSCTS ; + set_flow_control(flow, rts, cts); + if (cts != NC) _dev.lpm = LPM_ENABLED; + } +#endif } int MDMSerial::_send(const void* buf, int len) { - return put((const char*)buf, len, true/*=blocking*/); + return put((const char*)buf, len, true/*=blocking*/); } int MDMSerial::getLine(char* buffer, int length) @@ -1054,4 +1064,4 @@ MDMUsb::MDMUsb(void) { } int MDMUsb::_send(const void* buf, int len) { return len; } int MDMUsb::getLine(char* buffer, int length) { return NOT_FOUND; } -#endif \ No newline at end of file +#endif
--- a/MDM.h Wed Apr 09 14:25:41 2014 +0000 +++ b/MDM.h Thu Apr 10 13:05:45 2014 +0000 @@ -19,15 +19,17 @@ { public: //! Constructor - MDMParser(void); + MDMParser(); // ---------------------------------------------------------------- // Types // ---------------------------------------------------------------- typedef enum { DEV_UNKNOWN, DEV_SARA_G350, DEV_LISA_U200, DEV_LISA_C200 } Dev; //!< MT Device Types typedef enum { SIM_UNKNOWN, SIM_PIN, SIM_READY } Sim; //!< SIM Status + typedef enum { LPM_DISABLED, LPM_ENABLED, LPM_ACTIVE, LPM_SLEEP } Lpm; //!< SIM Status typedef struct { Dev dev; //!< Device Type + Lpm lpm; //!< Power Saving Sim sim; //!< SIM Card Status char ccid[20+1]; //!< Integrated Circuit Card ID char imsi[15+1]; //!< International Mobile Station Identity @@ -255,6 +257,7 @@ #define TYPE_NOANSWER 0x260000 #define TYPE_PROMPT 0x300000 #define TYPE_PLUS 0x400000 + #define TYPE_TEXT 0x500000 /** Get a line from the physical interface. This function need to be implemented in a inherited class. Usually just calls @@ -351,7 +354,7 @@ */ static int _parseFormated(Pipe<char>* pipe, int len, const char* fmt); -private: +protected: // parsing callbacks for different AT commands and their parameter arguments static int _cbString(int type, const char* buf, int len, char* str); static int _cbInt(int type, const char* buf, int len, int* val); @@ -386,7 +389,7 @@ // management struture for sockets typedef enum { SOCK_FREE, SOCK_CREATED, SOCK_CONNECTED } SockState; typedef struct { SockState state; int pending; } SockCtrl; - SockCtrl _sockets[16]; + SockCtrl _sockets[16]; }; // ----------------------------------------------------------------------- @@ -397,10 +400,10 @@ MDMSerial(PinName tx _C027DEFAULT(MDMTXD), PinName rx _C027DEFAULT(MDMRXD), int baudrate _C027DEFAULT(MDMBAUD), -#if DEVICE_SERIAL_FC + #if DEVICE_SERIAL_FC PinName rts _C027DEFAULT(MDMRTS), PinName cts _C027DEFAULT(MDMCTS), -#endif + #endif int rxSize = 256 , int txSize = 128 ); virtual int getLine(char* buffer, int length);
--- a/SerialPipe.cpp Wed Apr 09 14:25:41 2014 +0000 +++ b/SerialPipe.cpp Thu Apr 10 13:05:45 2014 +0000 @@ -9,19 +9,6 @@ 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) -{ - attach(this, &SerialPipe::rxIrqBuf, RxIrq); - attach(this, &SerialPipe::txIrqBuf, TxIrq); - - set_flow_control(RTSCTS, rts, cts); -} -#endif - SerialPipe::~SerialPipe(void) { attach(NULL, RxIrq);
--- a/SerialPipe.h Wed Apr 09 14:25:41 2014 +0000 +++ b/SerialPipe.h Thu Apr 10 13:05:45 2014 +0000 @@ -9,9 +9,6 @@ { 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);