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:
124:65eb7d58f2da
Parent:
123:66cef6353b13
Child:
125:25a292afbac6
--- a/MDM.cpp	Wed Jul 01 13:21:31 2015 +0000
+++ b/MDM.cpp	Thu Aug 20 08:07:37 2015 +0000
@@ -218,7 +218,8 @@
                             r = sscanf(cmd, "%s %d,\"%X\",\"%X\",%d",s,&a,&b,&c,&d);
                         if (r >= 2) {
                             Reg *reg = !strcmp(s, "CREG:")  ? &_net.csd : 
-                                       !strcmp(s, "CGREG:") ? &_net.psd : NULL;
+                                       !strcmp(s, "CGREG:") ? &_net.psd : 
+                                       !strcmp(s, "CEREG:") ? &_net.eps : NULL;
                             if (reg) {
                                 // network status
                                 if      (a == 0) *reg = REG_NONE;     // 0: not registered, home network
@@ -227,6 +228,7 @@
                                 else if (a == 3) *reg = REG_DENIED;   // 3: registration denied
                                 else if (a == 4) *reg = REG_UNKNOWN;  // 4: unknown
                                 else if (a == 5) *reg = REG_ROAMING;  // 5: registered, roaming
+                                else if (a == 6) *reg = REG_HOME;     // 6: registered, sms only, home
                                 if ((r >= 3) && (b != 0xFFFF))      _net.lac = b; // location area code
                                 if ((r >= 4) && (c != 0xFFFFFFFF))  _net.ci  = c; // cell ID
                                 // access technology
@@ -238,6 +240,7 @@
                                     else if (d == 4) _net.act = ACT_UTRAN;    // 4: UTRAN with HSDPA availability
                                     else if (d == 5) _net.act = ACT_UTRAN;    // 5: UTRAN with HSUPA availability
                                     else if (d == 6) _net.act = ACT_UTRAN;    // 6: UTRAN with HSDPA and HSUPA availability
+                                    else if (d == 7) _net.act = ACT_LTE;      // 7: LTE
                                 }
                             }
                         }
@@ -404,6 +407,12 @@
             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++) {
@@ -514,6 +523,9 @@
         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;
     }
     return WAIT;
 }
@@ -551,7 +563,8 @@
         wait_ms(1000);
     if (_net.csd == REG_DENIED) ERROR("CSD Registration Denied\r\n");
     if (_net.psd == REG_DENIED) ERROR("PSD Registration Denied\r\n");
-    return REG_OK(_net.csd) || REG_OK(_net.psd);
+    if (_net.eps == REG_DENIED) ERROR("EPS Registration Denied\r\n");
+    return REG_OK(_net.csd) || REG_OK(_net.psd) || REG_OK(_net.eps);
 }
 
 bool MDMParser::checkNetStatus(NetStatus* status /*= NULL*/)
@@ -569,7 +582,13 @@
         sendFormated("AT+CGREG?\r\n");
         waitFinalResp(); // don't fail as service could be not subscribed 
     }
-    if (REG_OK(_net.csd) || REG_OK(_net.psd))
+    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) {
@@ -638,7 +657,8 @@
     if (status) {
         memcpy(status, &_net, sizeof(NetStatus));
     }
-    ok = REG_DONE(_net.csd) && REG_DONE(_net.psd);
+    ok = REG_DONE(_net.csd) && 
+        (REG_DONE(_net.psd) || REG_DONE(_net.eps));
     UNLOCK();
     return ok;
 failure:
@@ -654,6 +674,7 @@
         if (sscanf(buf, "\r\n+COPS: %*d,%*d,\"%[^\"]\",%d",status->opr,&act) >= 1) {
             if      (act == 0) status->act = ACT_GSM;      // 0: GSM, 
             else if (act == 2) status->act = ACT_UTRAN;    // 2: UTRAN
+            else if (act == 7) status->act = ACT_LTE;    // 2: UTRAN
         }
     }
     return WAIT;
@@ -677,13 +698,14 @@
         char _ber[] = { 49, 43, 37, 25, 19, 13, 7, 0 }; // see 3GPP TS 45.008 [20] subclause 8.2.4
         // +CSQ: <rssi>,<qual>
         if (sscanf(buf, "\r\n+CSQ: %d,%d",&a,&b) == 2) {
-            if (a != 99) status->rssi = -113 + 2*a;  // 0: -113 1: -111 ... 30: -53 dBm with 2 dBm steps
+            if (a != 99) status->rssi = -113 + 2*a;  // 0: -113 1: -111 ... 30: -53 dBm with 2 dBm steps, 31: >-51 dBm
             if ((b != 99) && (b < sizeof(_ber))) status->ber = _ber[b];  // 
         }
     }
     return WAIT;
 }
 
+
 int MDMParser::_cbUACTIND(int type, const char* buf, int len, int* i)
 {
     if ((type == TYPE_PLUS) && i){
@@ -1391,20 +1413,21 @@
 bool MDMParser::setDebug(int level) 
 {
 #ifdef MDM_DEBUG
-    if ((_debugLevel >= -1) && (level >= -1) &&
-        (_debugLevel <=  3) && (level <=  3)) {
-        _debugLevel = level;
-        return true;
-    }
+    _debugLevel = (level < -1) ? -1 : 
+                  (level >  3) ?  3 : 
+                                 level;
 #endif
-    return false;
+    return _debugLevel == level;
 }
 
 void MDMParser::dumpDevStatus(MDMParser::DevStatus* status, 
             _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" };
+    const char* txtDev[] = { "Unknown", 
+                             "SARA-G350", "LISA-U200", "LISA-C200", 
+                             "SARA-U260", "SARA-U270", "LEON-G200",
+                             "TOBY-L200", "TOBY-L201", "TOBY-L210" };
     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" };
@@ -1438,7 +1461,9 @@
         dprint(param, "  CSD Registration:   %s\r\n", txtReg[status->csd]);
     if (status->psd < sizeof(txtReg)/sizeof(*txtReg) && (status->psd != REG_UNKNOWN))
         dprint(param, "  PSD Registration:   %s\r\n", txtReg[status->psd]);
-    const char* txtAct[] = { "Unknown", "GSM", "Edge", "3G", "CDMA" };
+    if (status->eps < sizeof(txtReg)/sizeof(*txtReg) && (status->eps != REG_UNKNOWN))
+        dprint(param, "  EPS Registration:   %s\r\n", txtReg[status->eps]);
+    const char* txtAct[] = { "Unknown", "GSM", "Edge", "3G", "CDMA", "LTE" };
     if (status->act < sizeof(txtAct)/sizeof(*txtAct) && (status->act != ACT_UNKNOWN))
         dprint(param, "  Access Technology:  %s\r\n", txtAct[status->act]);
     if (status->rssi)