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:
125:25a292afbac6
Parent:
124:65eb7d58f2da
Child:
126:bfbb9e19f6e0
--- a/MDM.cpp	Thu Aug 20 08:07:37 2015 +0000
+++ b/MDM.cpp	Thu Aug 20 13:47:29 2015 +0000
@@ -4,7 +4,7 @@
  #include "C027_api.h"
 #endif
 #include "MDMAPN.h"
-                
+        
 #define PROFILE         "0"   //!< this is the psd profile used
 #define MAX_SIZE        128   //!< max expected messages
 // num sockets
@@ -187,7 +187,7 @@
                     if ((socket != SOCKET_ERROR) && _sockets[socket].connected)
                         _sockets[socket].connected = false;
                 }
-                if (_dev.dev == DEV_LISA_C200) {
+                if (_dev.dev == DEV_LISA_C2) {
                     // CDMA Specific -------------------------------------------
                     // +CREG: <n><SID>,<NID>,<stat>
                     if (sscanf(cmd, "CREG: %*d,%d,%d,%d",&a,&b,&c) == 3) {
@@ -368,7 +368,7 @@
     if (_dev.dev == DEV_UNKNOWN)
         goto failure;
     // device specific init
-    if (_dev.dev == DEV_LISA_C200) {
+    if (_dev.dev == DEV_LISA_C2) {
         // get the manufacturer
         sendFormated("AT+GMI\r\n");
         if (RESP_OK != waitFinalResp(_cbString, _dev.manu))
@@ -396,23 +396,17 @@
         }
 #endif
     } else {
-        if ((_dev.dev == DEV_LISA_U200) || (_dev.dev == DEV_LEON_G200)) {
+        if ((_dev.dev == DEV_LISA_U2) || (_dev.dev == DEV_LEON_G2) || 
+            (_dev.dev == DEV_TOBY_L2)) {
             // enable the network identification feature 
             sendFormated("AT+UGPIOC=20,2\r\n");
             if (RESP_OK != waitFinalResp())
                 goto failure;
-        } else if ((_dev.dev == DEV_SARA_U260) || (_dev.dev == DEV_SARA_U270) || 
-                   (_dev.dev == DEV_SARA_G350)) {
+        } else if ((_dev.dev == DEV_SARA_U2) || (_dev.dev == DEV_SARA_G35)) {
             // enable the network identification feature 
             sendFormated("AT+UGPIOC=16,2\r\n");
             if (RESP_OK != waitFinalResp())
                 goto failure;
-        } else if ((_dev.dev == DEV_TOBY_L200) || (_dev.dev == DEV_TOBY_L201) || 
-                   (_dev.dev == DEV_TOBY_L210)) {
-            // enable the network identification feature 
-            //sendFormated("AT+UGPIOC=20,2\r\n");
-            //if (RESP_OK != waitFinalResp())
-            //    goto failure;
         }
         // check the sim card
         for (int i = 0; (i < 5) && (_dev.sim != SIM_READY); i++) {
@@ -474,7 +468,7 @@
             goto failure;
     } 
     // enable the network registration unsolicited result code
-    sendFormated("AT+CREG=%d\r\n", (_dev.dev == DEV_LISA_C200) ? 1 : 2);
+    sendFormated("AT+CREG=%d\r\n", (_dev.dev == DEV_LISA_C2) ? 1 : 2);
     if (RESP_OK != waitFinalResp())
         goto failure;
     // Setup SMS in text mode 
@@ -517,15 +511,13 @@
 int MDMParser::_cbATI(int type, const char* buf, int len, Dev* dev)
 {
     if ((type == TYPE_UNKNOWN) && dev) {
-        if      (strstr(buf, "SARA-G350")) *dev = DEV_SARA_G350;
-        else if (strstr(buf, "LISA-U200")) *dev = DEV_LISA_U200;
-        else if (strstr(buf, "LISA-C200")) *dev = DEV_LISA_C200;
-        else if (strstr(buf, "SARA-U260")) *dev = DEV_SARA_U260;
-        else if (strstr(buf, "SARA-U270")) *dev = DEV_SARA_U270;
-        else if (strstr(buf, "LEON-G200")) *dev = DEV_LEON_G200;
-        else if (strstr(buf, "TOBY-L200") || strstr(buf, "MPCI-L200")) *dev = DEV_TOBY_L200;
-        else if (strstr(buf, "TOBY-L201") || strstr(buf, "MPCI-L201")) *dev = DEV_TOBY_L201;
-        else if (strstr(buf, "TOBY-L210") || strstr(buf, "MPCI-L210")) *dev = DEV_TOBY_L210;
+        if      (strstr(buf, "SARA-G35"))   *dev = DEV_SARA_G35;
+        else if (strstr(buf, "LISA-U2"))    *dev = DEV_LISA_U2;
+        else if (strstr(buf, "LISA-C2"))    *dev = DEV_LISA_C2;
+        else if (strstr(buf, "SARA-U2"))    *dev = DEV_SARA_U2;
+        else if (strstr(buf, "LEON-G2"))    *dev = DEV_LEON_G2;
+        else if (strstr(buf, "TOBY-L2"))    *dev = DEV_TOBY_L2;
+        else if (strstr(buf, "MPCI-L2"))    *dev = DEV_MPCI_L2;
     }
     return WAIT;
 }
@@ -577,21 +569,20 @@
     // check registration
     sendFormated("AT+CREG?\r\n");
     waitFinalResp();     // don't fail as service could be not subscribed 
-    if (_dev.dev != DEV_LISA_C200) {
+    if (_dev.dev != DEV_LISA_C2) {
         // check PSD registration
         sendFormated("AT+CGREG?\r\n");
         waitFinalResp(); // don't fail as service could be not subscribed 
+        if ((_dev.dev == DEV_TOBY_L2) ||  (_dev.dev == DEV_MPCI_L2)) {
+            // check EPS network registration
+            sendFormated("AT+CEREG?\r\n");
+            waitFinalResp(); // don't fail as service could be not subscribed
+        }
     }
-    if ((_dev.dev == DEV_TOBY_L201) || (_dev.dev == DEV_TOBY_L210)||
-        (_dev.dev == DEV_TOBY_L201)) {
-        // check EPS network registration
-        sendFormated("AT+CEREG?\r\n");
-        waitFinalResp(); // don't fail as service could be not subscribed
-     }
     if (REG_OK(_net.csd) || REG_OK(_net.psd) || REG_OK(_net.eps))
     {
         // check modem specific status messages 
-        if (_dev.dev == DEV_LISA_C200) {
+        if (_dev.dev == DEV_LISA_C2) {
             sendFormated("AT+CSS?\r\n");
             if (RESP_OK != waitFinalResp())
                 goto failure;
@@ -726,7 +717,7 @@
     LOCK();
     INFO("Modem::join\r\n");
     _ip = NOIP;
-    if (_dev.dev == DEV_LISA_C200) {
+    if (_dev.dev == DEV_LISA_C2) {
         // make a dumy dns lookup (which will fail, so ignore the result) 
         sendFormated("AT+UDNSRN=0,\"u-blox.com\"\r\n");
         waitFinalResp(); 
@@ -737,6 +728,7 @@
         sendFormated("AT+CMIP?\r\n");
         if (RESP_OK != waitFinalResp(_cbCMIP, &_ip))
             goto failure;
+    
     } else { 
         // check gprs attach status 
         sendFormated("AT+CGATT=1\r\n");
@@ -762,31 +754,36 @@
             const char* config = NULL;
             if (!apn && !username && !password)
                 config = apnconfig(_dev.imsi);
-            
-            // Set up the dynamic IP address assignment.
-            sendFormated("AT+UPSD=" PROFILE ",7,\"0.0.0.0\"\r\n");
-            if (RESP_OK != waitFinalResp())
-                goto failure;
- 
+/*NOT SUP*/ if ((_dev.dev != DEV_TOBY_L2) && (_dev.dev != DEV_MPCI_L2)) {
+                // Set up the dynamic IP address assignment.
+                sendFormated("AT+UPSD=" PROFILE ",7,\"0.0.0.0\"\r\n");
+                if (RESP_OK != waitFinalResp())
+                    goto failure;
+            }
             do {
                 if (config) {
                     apn      = _APN_GET(config);
                     username = _APN_GET(config);
                     password = _APN_GET(config);
-                    TRACE("Testing APN Settings(\"%s\",\"%s\",\"%s\")\r\n", apn, username, password);
                 }
+                // convert pointer to empty strings
+                apn      = apn      ? apn      : "";
+                username = username ? username : "";
+                password = password ? password : "";
+                auth = (*username && *password) ? auth : AUTH_NONE;
+                TRACE("Testing APN Settings(\"%s\",\"%s\",\"%s\",%d)\r\n", apn, username, password, auth);
                 // Set up the APN
-                if (apn && *apn) {
+                if (*apn) {
                     sendFormated("AT+UPSD=" PROFILE ",1,\"%s\"\r\n", apn);
                     if (RESP_OK != waitFinalResp())
                         goto failure;
                 }
-                if (username && *username) {
+                if (*username) {
                     sendFormated("AT+UPSD=" PROFILE ",2,\"%s\"\r\n", username);
                     if (RESP_OK != waitFinalResp())
                         goto failure;
                 }
-                if (password && *password) {
+                if (*password) {
                     sendFormated("AT+UPSD=" PROFILE ",3,\"%s\"\r\n", password);
                     if (RESP_OK != waitFinalResp())
                         goto failure;
@@ -797,10 +794,12 @@
                 // 2 = CHAP (Challenge Handshake Authentication Protocol)
                 for (int i = AUTH_NONE; i <= AUTH_CHAP && !ok; i ++) {
                     if ((auth == AUTH_DETECT) || (auth == i)) {
-                        // Set up the Authentication Protocol
-                        sendFormated("AT+UPSD=" PROFILE ",6,%d\r\n", i);
-                        if (RESP_OK != waitFinalResp())
-                            goto failure;
+/*NOT SUP*/             if ((_dev.dev != DEV_TOBY_L2) && (_dev.dev != DEV_MPCI_L2)) {
+                            // Set up the Authentication Protocol
+                            sendFormated("AT+UPSD=" PROFILE ",6,%d\r\n",i);
+                            if (RESP_OK != waitFinalResp())
+                                goto failure;
+                        }
                         // Activate the profile and make connection
                         sendFormated("AT+UPSDA=" PROFILE ",3\r\n");
                         if (RESP_OK == waitFinalResp(NULL,NULL,150*1000))
@@ -880,7 +879,7 @@
     LOCK();
     INFO("Modem::disconnect\r\n");
     if (_ip != NOIP) {
-        if (_dev.dev == DEV_LISA_C200) {
+        if (_dev.dev == DEV_LISA_C2) {
             // There something to do here
             _ip = NOIP;
             ok = true;
@@ -935,7 +934,7 @@
     if (socket != SOCKET_ERROR) {
         if (ipproto == IPPROTO_UDP) {
             // sending port can only be set on 2G/3G modules
-            if ((port != -1) && (_dev.dev != DEV_LISA_C200)) {
+            if ((port != -1) && (_dev.dev != DEV_LISA_C2)) {
                 sendFormated("AT+USOCR=17,%d\r\n", port);
             } else {
                 sendFormated("AT+USOCR=17\r\n");
@@ -1339,7 +1338,7 @@
     bool ok = false;
     LOCK();
     *buf = '\0';
-    if (_dev.dev != DEV_LISA_C200) {
+    if (_dev.dev != DEV_LISA_C2) {
         sendFormated("AT+CUSD=1,\"%s\"\r\n",cmd);
         ok = (RESP_OK == waitFinalResp(_cbCUSD, buf));
     }
@@ -1424,10 +1423,8 @@
             _DPRINT dprint, void* param) 
 {
     dprint(param, "Modem::devStatus\r\n");
-    const char* txtDev[] = { "Unknown", 
-                             "SARA-G350", "LISA-U200", "LISA-C200", 
-                             "SARA-U260", "SARA-U270", "LEON-G200",
-                             "TOBY-L200", "TOBY-L201", "TOBY-L210" };
+    const char* txtDev[] = { "Unknown",  "SARA-G35", "LISA-U2", "LISA-C2", 
+                             "SARA-U2",  "LEON-G2",  "TOBY-L2", "MPCI-L2" };
     if (status->dev < sizeof(txtDev)/sizeof(*txtDev) && (status->dev != DEV_UNKNOWN))
         dprint(param, "  Device:       %s\r\n", txtDev[status->dev]);
     const char* txtLpm[] = { "Disabled", "Enabled", "Active" };