Add a bunch of APNs
Fork of C027_Support by
Diff: MDM.cpp
- Revision:
- 65:dd94f920a762
- Parent:
- 62:a02f026bdd7c
- Parent:
- 64:ba4ea655a451
- Child:
- 66:69072b3c5bca
diff -r a02f026bdd7c -r dd94f920a762 MDM.cpp --- a/MDM.cpp Tue May 13 13:54:05 2014 +0000 +++ b/MDM.cpp Tue May 13 14:41:03 2014 +0000 @@ -122,12 +122,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> @@ -226,6 +221,7 @@ bool dump) { DevStatus devStatus = {}; + WAIT_MS(2000); bool mdmOk = init(simpin, &devStatus); if (dump) dumpDevStatus(&devStatus); if (!mdmOk) @@ -254,7 +250,6 @@ { int i = 5; // we should wait some time before - WAIT_MS(1000); while (i--) { // check interface and disable local echo sendFormated("AT\r\n"); @@ -691,18 +686,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; @@ -788,14 +783,14 @@ int MDMParser::socketSendTo(int socket, IP ip, int port, const char * buf, int len) { - TRACE("socketSendTo(%d," IPSTR "%d,,%d)\r\n", socket, IPNUM(ip),port,len); + 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; @@ -878,10 +873,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); @@ -900,14 +895,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 {