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.

Revision:
65:dd94f920a762
Parent:
62:a02f026bdd7c
Parent:
64:ba4ea655a451
Child:
66:69072b3c5bca
--- 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 {