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.
Diff: MDM.cpp
- Revision:
- 69:4d6fa520dfca
- Parent:
- 68:33a96cf64986
- Child:
- 70:0a87d256cd24
--- a/MDM.cpp Tue May 13 16:25:56 2014 +0000 +++ b/MDM.cpp Wed May 14 05:54:37 2014 +0000 @@ -6,11 +6,12 @@ #define TRACE (1/*1=off,0=trace*/)?:printf //#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 #define ISSOCKET(s) (((s) >= 0) && ((s) < (sizeof(_sockets)/sizeof(*_sockets)))) #define WAIT_MS(ms) wait_ms(ms) // you may choose to use Thread::wait(ms) +#define MAX_SIZE 128 // max expected messages + #ifdef DEBUG void dump(const char* buf, int len) { @@ -80,7 +81,7 @@ void* param /* = NULL*/, int timeout_ms /*= 5000*/) { - char buf[MAX_SIZE]; + char buf[MAX_SIZE + 64 /* add some more space for framing */]; Timer timer; timer.start(); do { @@ -125,6 +126,11 @@ ISSOCKET(a) /*&& (_sockets[a].state == SOCK_CONNECTED)*/) { TRACE("Socket %d: %d bytes pending\r\n", a, b); _sockets[a].pending = b; + // +UUSORF: <socket>,<length> + } else if ((sscanf(cmd, "UUSORF: %d,%d", &a, &b) == 2) && + ISSOCKET(a) /*&& (_sockets[a].state == SOCK_CONNECTED)*/) { + TRACE("Socket %d: %d bytes pending\r\n", a, b); + _sockets[a].pending = b; // +UUSOCL: <socket> } else if ((sscanf(cmd, "UUSOCL: %d", &a) == 1) && ISSOCKET(a) && (_sockets[a].state == SOCK_CONNECTED)) { @@ -767,12 +773,14 @@ return true; } +#define USO_MAX_WRITE 1024 //!< maximum number of bytes to write to socket + int MDMParser::socketSend(int socket, const char * buf, int len) { TRACE("socketSend(%d,,%d)\r\n", socket,len); int cnt = len; while (cnt > 0) { - int blk = MAX_SIZE; + int blk = USO_MAX_WRITE; if (cnt < blk) blk = cnt; sendFormated("AT+USOWR=%d,%d\r\n",socket,blk); @@ -793,7 +801,7 @@ TRACE("socketSendTo(%d," IPSTR ",%d,,%d)\r\n", socket, IPNUM(ip),port,len); int cnt = len; while (cnt > 0) { - int blk = MAX_SIZE; + int blk = USO_MAX_WRITE; if (cnt < blk) blk = cnt; sendFormated("AT+USOST=%d,\"" IPSTR "\",%d,%d\r\n",socket,IPNUM(ip),port,blk); @@ -843,7 +851,7 @@ Timer timer; timer.start(); while (len) { - int blk = MAX_SIZE - 64; // still need space for headers and unsolicited commands + int blk = MAX_SIZE; // still need space for headers and unsolicited commands if (_sockets[socket].pending < blk) blk = _sockets[socket].pending; if (len < blk) blk = len; @@ -896,7 +904,7 @@ Timer timer; timer.start(); while (len) { - int blk = MAX_SIZE - 64; // still need space for headers and unsolicited commands + int blk = MAX_SIZE; // still need space for headers and unsolicited commands if (_sockets[socket].pending < blk) blk = _sockets[socket].pending; if (len < blk) blk = len;