454
Fork of C027_Support by
Diff: MDM.cpp
- Revision:
- 139:aef5dad89a7b
- Parent:
- 128:0415646a9934
- Child:
- 141:acb569d2a138
--- a/MDM.cpp Fri Aug 21 09:13:56 2015 +0000 +++ b/MDM.cpp Fri Mar 24 05:42:17 2017 +0000 @@ -317,6 +317,7 @@ bool MDMParser::init(const char* simpin, DevStatus* status, PinName pn) { int i = 10; + //printf("MDMParser::init LOCK\n"); LOCK(); memset(&_dev, 0, sizeof(_dev)); if (pn != NC) { @@ -486,9 +487,11 @@ if (status) memcpy(status, &_dev, sizeof(DevStatus)); UNLOCK(); + //printf("MDMParser::init UNLOCK\n"); return true; failure: unlock(); + //printf("MDMParser::init UNLOCK\n"); return false; } @@ -496,6 +499,7 @@ { bool ok = false; if (_init) { + //printf("MDMParser::powerOff LOCK\n"); LOCK(); INFO("Modem::powerOff\r\n"); sendFormated("AT+CPWROFF\r\n"); @@ -504,6 +508,7 @@ ok = true; } UNLOCK(); + //printf("MDMParser::powerOff UNLOCK\n"); } return ok; } @@ -562,6 +567,7 @@ bool MDMParser::checkNetStatus(NetStatus* status /*= NULL*/) { bool ok = false; + //printf("MDMParser::checkNetStatus LOCK\n"); LOCK(); memset(&_net, 0, sizeof(_net)); _net.lac = 0xFFFF; @@ -651,6 +657,7 @@ ok = REG_DONE(_net.csd) && (REG_DONE(_net.psd) || REG_DONE(_net.eps)); UNLOCK(); + //printf("MDMParser::checkNetStatus UNLOCK\n"); return ok; failure: unlock(); @@ -771,6 +778,7 @@ MDMParser::IP MDMParser::join(const char* apn /*= NULL*/, const char* username /*= NULL*/, const char* password /*= NULL*/, Auth auth /*= AUTH_DETECT*/) { + //printf("MDMParser::join LOCK\n"); LOCK(); INFO("Modem::join\r\n"); _ip = NOIP; @@ -838,6 +846,7 @@ goto failure; } UNLOCK(); + //printf("MDMParser::join UNLOCK\n"); return _ip; failure: unlock(); @@ -896,6 +905,7 @@ bool MDMParser::disconnect(void) { bool ok = false; + //printf("MDMParser::disconnect LOCK\n"); LOCK(); INFO("Modem::disconnect\r\n"); if (_ip != NOIP) { @@ -912,6 +922,7 @@ } } UNLOCK(); + //printf("MDMParser::disconnect UNLOCK\n"); return ok; } @@ -922,11 +933,13 @@ if (sscanf(host, IPSTR, &a,&b,&c,&d) == 4) ip = IPADR(a,b,c,d); else { + //printf("MDMParser::gethostbyname LOCK\n"); LOCK(); sendFormated("AT+UDNSRN=0,\"%s\"\r\n", host); if (RESP_OK != waitFinalResp(_cbUDNSRN, &ip)) ip = NOIP; UNLOCK(); + //printf("MDMParser::gethostbyname UNLOCK\n"); } return ip; } @@ -947,6 +960,7 @@ int MDMParser::socketSocket(IpProtocol ipproto, int port) { int socket; + //printf("MDMParser::socketSocket LOCK\n"); LOCK(); // find an free socket socket = _findSocket(); @@ -975,6 +989,7 @@ socket = SOCKET_ERROR; } UNLOCK(); + //printf("MDMParser::socketSocket UNLOCK\n"); return socket; } @@ -985,6 +1000,7 @@ return false; // connect to socket bool ok = false; + //printf("MDMParser::socketConnect LOCK\n"); LOCK(); if (ISSOCKET(socket) && (!_sockets[socket].connected)) { TRACE("socketConnect(%d,%s,%d)\r\n", socket,host,port); @@ -993,22 +1009,26 @@ ok = _sockets[socket].connected = true; } UNLOCK(); + //printf("MDMParser::socketConnect UNLOCK\n"); return ok; } bool MDMParser::socketIsConnected(int socket) { bool ok = false; + //printf("MDMParser::socketIsConnected LOCK\n"); LOCK(); ok = ISSOCKET(socket) && _sockets[socket].connected; TRACE("socketIsConnected(%d) %s\r\n", socket, ok?"yes":"no"); UNLOCK(); + //printf("MDMParser::socketIsConnected UNLOCK\n"); return ok; } bool MDMParser::socketSetBlocking(int socket, int timeout_ms) { bool ok = false; + //printf("MDMParser::socketSetBlocking LOCK\n"); LOCK(); TRACE("socketSetBlocking(%d,%d)\r\n", socket,timeout_ms); if (ISSOCKET(socket)) { @@ -1016,12 +1036,14 @@ ok = true; } UNLOCK(); + //printf("MDMParser::socketSetBlocking UNLOCK\n"); return ok; } bool MDMParser::socketClose(int socket) { bool ok = false; + //printf("MDMParser::socketClose LOCK\n"); LOCK(); if (ISSOCKET(socket) && _sockets[socket].connected) { TRACE("socketClose(%d)\r\n", socket); @@ -1032,6 +1054,7 @@ } } UNLOCK(); + //printf("MDMParser::socketClose UNLOCK\n"); return ok; } @@ -1040,6 +1063,7 @@ // make sure it is closed socketClose(socket); bool ok = true; + //printf("MDMParser::socketFree LOCK\n"); LOCK(); if (ISSOCKET(socket)) { TRACE("socketFree(%d)\r\n", socket); @@ -1050,6 +1074,7 @@ ok = true; } UNLOCK(); + //printf("MDMParser::socketFree UNLOCK\n"); return ok; } @@ -1064,6 +1089,7 @@ if (cnt < blk) blk = cnt; bool ok = false; + //printf("MDMParser::socketSend LOCK\n"); LOCK(); if (ISSOCKET(socket)) { sendFormated("AT+USOWR=%d,%d\r\n",_sockets[socket].handle,blk); @@ -1075,6 +1101,7 @@ } } UNLOCK(); + //printf("MDMParser::socketSend UNLOCK\n"); if (!ok) return SOCKET_ERROR; buf += blk; @@ -1085,13 +1112,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); + printf("socketSendTo(%d," IPSTR ",%d,,%d)\r\n", socket,IPNUM(ip),port,len); int cnt = len; while (cnt > 0) { int blk = USO_MAX_WRITE; if (cnt < blk) blk = cnt; bool ok = false; + //printf("MDMParser::socketSendTo LOCK\n"); LOCK(); if (ISSOCKET(socket)) { sendFormated("AT+USOST=%d,\"" IPSTR "\",%d,%d\r\n",_sockets[socket].handle,IPNUM(ip),port,blk); @@ -1103,6 +1131,7 @@ } } UNLOCK(); + //printf("MDMParser::socketSendTo UNLOCK\n"); if (!ok) return SOCKET_ERROR; buf += blk; @@ -1114,6 +1143,7 @@ int MDMParser::socketReadable(int socket) { int pending = SOCKET_ERROR; + //printf("MDMParser::socketReadable LOCK\n"); LOCK(); if (ISSOCKET(socket) && _sockets[socket].connected) { TRACE("socketReadable(%d)\r\n", socket); @@ -1123,6 +1153,7 @@ pending = _sockets[socket].pending; } UNLOCK(); + //printf("MDMParser::socketReadable UNLOCK\n"); return pending; } @@ -1150,7 +1181,8 @@ while (len) { int blk = MAX_SIZE; // still need space for headers and unsolicited commands if (len < blk) blk = len; - bool ok = false; + bool ok = false; + //printf("MDMParser::socketRecv LOCK\n"); LOCK(); if (ISSOCKET(socket)) { if (_sockets[socket].connected) { @@ -1177,6 +1209,7 @@ } } UNLOCK(); + //printf("MDMParser::socketRecv UNLOCK\n"); if (!ok) { TRACE("socketRecv: ERROR\r\n"); return SOCKET_ERROR; @@ -1213,7 +1246,8 @@ while (len) { int blk = MAX_SIZE; // still need space for headers and unsolicited commands if (len < blk) blk = len; - bool ok = false; + bool ok = false; + //printf("MDMParser::socketRecvFrom LOCK\n"); LOCK(); if (ISSOCKET(socket)) { if (_sockets[socket].pending < blk) @@ -1240,6 +1274,7 @@ } } UNLOCK(); + //printf("MDMParser::socketRecvFrom UNLOCK\n"); if (!ok) { TRACE("socketRecv: ERROR\r\n"); return SOCKET_ERROR; @@ -1277,6 +1312,7 @@ int MDMParser::smsList(const char* stat /*= "ALL"*/, int* ix /*=NULL*/, int num /*= 0*/) { int ret = -1; + //printf("MDMParser::smsList LOCK\n"); LOCK(); sendFormated("AT+CMGL=\"%s\"\r\n", stat); CMGLparam param; @@ -1285,12 +1321,14 @@ if (RESP_OK == waitFinalResp(_cbCMGL, ¶m)) ret = num - param.num; UNLOCK(); + //printf("MDMParser::smsList UNLOCK\n"); return ret; } bool MDMParser::smsSend(const char* num, const char* buf) { bool ok = false; + //printf("MDMParser::smsSend LOCK\n"); LOCK(); sendFormated("AT+CMGS=\"%s\"\r\n",num); if (RESP_PROMPT == waitFinalResp(NULL,NULL,150*1000)) { @@ -1300,16 +1338,19 @@ ok = (RESP_OK == waitFinalResp()); } UNLOCK(); + //printf("MDMParser::smsSend UNLOCK\n"); return ok; } bool MDMParser::smsDelete(int ix) { bool ok = false; + //printf("MDMParser::smsDelete LOCK\n"); LOCK(); sendFormated("AT+CMGD=%d\r\n",ix); ok = (RESP_OK == waitFinalResp()); UNLOCK(); + //printf("MDMParser::smsDelete UNLOCK\n"); return ok; } @@ -1330,6 +1371,7 @@ bool MDMParser::smsRead(int ix, char* num, char* buf, int len) { bool ok = false; + //printf("MDMParser::smsRead LOCK\n"); LOCK(); CMGRparam param; param.num = num; @@ -1337,6 +1379,7 @@ sendFormated("AT+CMGR=%d\r\n",ix); ok = (RESP_OK == waitFinalResp(_cbCMGR, ¶m)); UNLOCK(); + //printf("MDMParser::smsRead UNLOCK\n"); return ok; } @@ -1356,6 +1399,7 @@ bool MDMParser::ussdCommand(const char* cmd, char* buf) { bool ok = false; + //printf("MDMParser::ussdCommand LOCK\n"); LOCK(); *buf = '\0'; if (_dev.dev != DEV_LISA_C2) { @@ -1363,6 +1407,7 @@ ok = (RESP_OK == waitFinalResp(_cbCUSD, buf)); } UNLOCK(); + //printf("MDMParser::ussdCommand UNLOCK\n"); return ok; } @@ -1378,16 +1423,19 @@ bool MDMParser::delFile(const char* filename) { bool ok = false; + //printf("MDMParser::delFile LOCK\n"); LOCK(); sendFormated("AT+UDELFILE=\"%s\"\r\n", filename); ok = (RESP_OK == waitFinalResp(_cbUDELFILE)); UNLOCK(); + //printf("MDMParser::delFile UNLOCK\n"); return ok; } int MDMParser::writeFile(const char* filename, const char* buf, int len) { bool ok = false; + //printf("MDMParser::writeFile LOCK\n"); LOCK(); sendFormated("AT+UDWNFILE=\"%s\",%d\r\n", filename, len); if (RESP_PROMPT == waitFinalResp()) { @@ -1395,6 +1443,7 @@ ok = (RESP_OK == waitFinalResp()); } UNLOCK(); + //printf("MDMParser::writeFile UNLOCK\n"); return ok ? len : -1; } @@ -1405,6 +1454,7 @@ param.buf = buf; param.sz = len; param.len = 0; + //printf("MDMParser::readFile LOCK\n"); LOCK(); sendFormated("AT+URDFILE=\"%s\"\r\n", filename, len); if (RESP_OK != waitFinalResp(_cbURDFILE, ¶m))