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.

Files at this revision

API Documentation at this revision

Comitter:
mazgch
Date:
Thu Aug 20 07:53:34 2015 +0000
Parent:
122:5f6804915d77
Child:
124:65eb7d58f2da
Commit message:
first draft for toby

Changed in this revision

MDM.cpp Show annotated file Show diff for this revision Revisions of this file
MDM.h Show annotated file Show diff for this revision Revisions of this file
--- a/MDM.cpp	Thu Mar 12 17:29:29 2015 +0000
+++ b/MDM.cpp	Thu Aug 20 07:53:34 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:
@@ -646,6 +666,17 @@
     return false;
 }
 
+int MDMParser::_cbUACTIND(int type, const char* buf, int len, int* i)
+{
+    if ((type == TYPE_PLUS) && i){
+        int a;
+        if (sscanf(buf, "\r\n+UACTIND: %d", &a) == 1) {
+            *i = a;
+        }
+    }
+    return WAIT;
+}
+
 int MDMParser::_cbCOPS(int type, const char* buf, int len, NetStatus* status)
 {
     if ((type == TYPE_PLUS) && status){
@@ -654,6 +685,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;
@@ -684,17 +716,6 @@
     return WAIT;
 }
 
-int MDMParser::_cbUACTIND(int type, const char* buf, int len, int* i)
-{
-    if ((type == TYPE_PLUS) && i){
-        int a;
-        if (sscanf(buf, "\r\n+UACTIND: %d", &a) == 1) {
-            *i = a;
-        }
-    }
-    return WAIT;
-}
-
 // ----------------------------------------------------------------
 // internet connection 
 
@@ -1391,20 +1412,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 +1460,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) 
--- a/MDM.h	Thu Mar 12 17:29:29 2015 +0000
+++ b/MDM.h	Thu Aug 20 07:53:34 2015 +0000
@@ -6,7 +6,7 @@
 #include "Pipe.h"
 #include "SerialPipe.h"
 
-#ifdef TARGET_UBLOX_C027
+#if 0//def TARGET_UBLOX_C027
  #define MDM_IF(onboard,shield) onboard
 #else
  #define MDM_IF(onboard,shield) shield
@@ -31,8 +31,10 @@
     // Types 
     // ----------------------------------------------------------------
     //! MT Device Types 
-    typedef enum { DEV_UNKNOWN, DEV_SARA_G350, DEV_LISA_U200, DEV_LISA_C200, 
-                   DEV_SARA_U260, DEV_SARA_U270, DEV_LEON_G200 } Dev; 
+    typedef enum { DEV_UNKNOWN, 
+                   DEV_SARA_G350, DEV_LISA_U200, DEV_LISA_C200, 
+                   DEV_SARA_U260, DEV_SARA_U270, DEV_LEON_G200, 
+                   DEV_TOBY_L200, DEV_TOBY_L201, DEV_TOBY_L210,  } Dev; 
     //! SIM Status
     typedef enum { SIM_UNKNOWN, SIM_MISSING, SIM_PIN, SIM_READY } Sim;
     //! SIM Status
@@ -53,11 +55,12 @@
     //! Registration Status
     typedef enum { REG_UNKNOWN, REG_DENIED, REG_NONE, REG_HOME, REG_ROAMING } Reg; 
     //! Access Technology
-    typedef enum { ACT_UNKNOWN, ACT_GSM, ACT_EDGE, ACT_UTRAN, ACT_CDMA } AcT; 
+    typedef enum { ACT_UNKNOWN, ACT_GSM, ACT_EDGE, ACT_UTRAN, ACT_CDMA, ACT_LTE } AcT; 
     //! Network Status
     typedef struct { 
         Reg csd;        //!< CSD Registration Status (Circuit Switched Data)
         Reg psd;        //!< PSD Registration status (Packet Switched Data)
+        Reg eps;        //!< EPS Registration status
         AcT act;        //!< Access Technology
         int rssi;       //!< Received Signal Strength Indication (in dBm, range -113..-51)
         int ber;        //!< Bit Error Rate (BER), see 3GPP TS 45.008 [20] subclause 8.2.4
@@ -105,8 +108,10 @@
         \param status an optional struture to with device information 
         \return true if successful, false otherwise
     */
-    bool init(const char* simpin = NULL, DevStatus* status = NULL, 
+    virtual bool init(const char* simpin = NULL, DevStatus* status = NULL, 
                 PinName pn MDM_IF( = MDMPWRON, = D4));
+
+    void getDevStatus(MDMParser::DevStatus* dev) { memcpy(dev, &_dev, sizeof(DevStatus)); }
     
     /** register to the network 
         \param status an optional structure to with network information 
@@ -152,6 +157,8 @@
     */
     MDMParser::IP gethostbyname(const char* host);
     
+    MDMParser::IP getIpAddress(void) { return _ip; }
+
     // ----------------------------------------------------------------
     // Sockets
     // ----------------------------------------------------------------
@@ -507,6 +514,8 @@
     virtual void lock(void)        { } 
     //! override the unlock in a rtos system
     virtual void unlock(void)      { } 
+    //! wakeup the modem
+    bool _wakeup(PinName pn);
 protected:
     // parsing callbacks for different AT commands and their parameter arguments
     static int _cbString(int type, const char* buf, int len, char* str);
@@ -593,7 +602,7 @@
               int txSize    = 128 );
     //! Destructor          
     virtual ~MDMSerial(void);
-    
+     
     /** Get a line from the physical interface. 
         \param buf the buffer to store it
         \param buf size of the buffer