C027 updated to work with latest mBed libraries
Dependents: Cellular_HelloMQTT UBLOXModemDriver UBLOXMQTTDriver
Fork of C027_Support by
Diff: MDM.cpp
- Revision:
- 69:4d6fa520dfca
- Parent:
- 68:33a96cf64986
- Child:
- 70:0a87d256cd24
diff -r 33a96cf64986 -r 4d6fa520dfca MDM.cpp --- 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;