Add a bunch of APNs
Fork of C027_Support by
Diff: MDM.cpp
- Revision:
- 63:42cb563a25bc
- Parent:
- 59:382695f1ce85
- Child:
- 64:ba4ea655a451
diff -r 1f65abb842be -r 42cb563a25bc MDM.cpp --- a/MDM.cpp Tue May 13 07:13:27 2014 +0000 +++ b/MDM.cpp Tue May 13 12:31:33 2014 +0000 @@ -3,8 +3,8 @@ #include <string.h> #include "MDM.h" -#define TRACE (1/*1=off,0=trace*/)?:printf -//#define DEBUG // enable this for AT command debugging +#define TRACE (0/*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 @@ -121,12 +121,7 @@ // Socket Specific Command --------------------------------- // +UUSORD: <socket>,<length> } else if ((sscanf(cmd, "UUSORD: %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; - // +UUSORF: <socket>,<length> - } else if ((sscanf(cmd, "UUSORF: %d,%d", &a, &b) == 2) && - ISSOCKET(a) && (_sockets[a].state == SOCK_CONNECTED)) { + ISSOCKET(a) /*&& (_sockets[a].state == SOCK_CONNECTED)*/) { TRACE("Socket %d: %d bytes pending\r\n", a, b); _sockets[a].pending = b; // +UUSOCL: <socket> @@ -686,18 +681,18 @@ return WAIT; } -int MDMParser::socketSocket(IpProtocol ipproto) +int MDMParser::socketSocket(IpProtocol ipproto, int port) { TRACE("socketSocket(%d)\r\n", ipproto); - const char* cmd; if(ipproto == IPPROTO_TCP) { - cmd = "AT+USOCR=6\r\n"; - } else if(ipproto == IPPROTO_UDP) { - cmd = "AT+USOCR=17\r\n"; + sendFormated("AT+USOCR=6\r\n"); + } else if ((ipproto == IPPROTO_UDP) && (port == -1)){ + sendFormated("AT+USOCR=17\r\n"); + } else if (ipproto == IPPROTO_UDP){ + sendFormated("AT+USOCR=17,%d\r\n", port); } else { // other types not supported return SOCKET_ERROR; } - sendFormated(cmd); int socket = -1; if (RESP_OK != waitFinalResp(_cbUSOCR, &socket)) return SOCKET_ERROR; @@ -785,12 +780,12 @@ { TRACE("socketSendTo(%d," IPSTR "%d,,%d)\r\n", socket, IPNUM(ip),port,len); if(len > 0) { - sendFormated("AT+USOWR=%d,\"" IPSTR "\",%d,%d\r\n",socket,IPNUM(ip),port,len); + sendFormated("AT+USOST=%d,\"" IPSTR "\",%d,%d\r\n",socket,IPNUM(ip),port,len); if (RESP_PROMPT != waitFinalResp()) return SOCKET_ERROR; wait_ms(50); send(buf, len); - if (RESP_OK != waitFinalResp()) + if (RESP_OK != waitFinalResp()) return SOCKET_ERROR; } return len; @@ -873,10 +868,10 @@ return WAIT; } -int MDMParser::socketRecvFrom(int socket, char* buf, int len, IP* ip) +int MDMParser::socketRecvFrom(int socket, IP* ip, int* port, char* buf, int len) { int cnt = 0; - TRACE("socketRecvFrom(%d,,%d" IPSTR ")\r\n", socket, len, IPNUM(*ip)); + TRACE("socketRecvFrom(%d,,%d)\r\n", socket, len); if (!ISSOCKET(socket)) return SOCKET_ERROR; memset(buf, '\0', len); @@ -895,14 +890,13 @@ return SOCKET_ERROR; } *ip = param.ip; - //*port = param.port; + *port = param.port; len -= blk; cnt += blk; buf += blk; _sockets[socket].pending -= blk; - } else if ((_sockets[socket].state == SOCK_CONNECTED) && ( - (_sockets[socket].timeout_ms == (unsigned int)-1 /* blocking */) || - (timer.read_ms() < _sockets[socket].timeout_ms))){ + } else if ((_sockets[socket].timeout_ms == (unsigned int)-1 /* blocking */) || + (timer.read_ms() < _sockets[socket].timeout_ms)) { // allow to receive unsolicited commands waitFinalResp(NULL, NULL, 10); } else {