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:
Tue Apr 08 11:59:28 2014 +0000
Parent:
24:0e287a85ac9e
Child:
26:07be5faf8925
Commit message:
added possibility to get network status struct

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	Tue Apr 08 11:15:33 2014 +0000
+++ b/MDM.cpp	Tue Apr 08 11:59:28 2014 +0000
@@ -30,9 +30,11 @@
     _model   = MODEL_UNKNOWN;
     _sim     = SIM_UNKNOWN;
     _net     = NET_UNKNOWN;
+    _act     = ACT_UNKNOWN;
     _ip      = 0;
     _rssi    = 0;
     *_num    = '\0';
+    *_opr    = '\0';
     for (int socket = 0; socket < sizeof(_sockets)/sizeof(*_sockets); socket++) {
         _sockets[socket].state = SOCK_FREE;
         _sockets[socket].pending = 0;
@@ -114,6 +116,7 @@
                         else if (a == 2) _net = NET_NONE;     // not registered, but MT is currently searching a new operator to register to
                         else if (a == 3) _net = NET_DENIED;   // registration denied
                         else if (a == 5) _net = NET_ROAMING;  // registered, roaming
+                        _act = ACT_CDMA;
                     // +CSS: <mode>[,<format>,<oper>[,<AcT>]]
                     } else if (sscanf(cmd, "CSS %*c,%2s,%*d",s) == 1) {
                         //_net = (strcmp("Z", s) == 0) ? NET_UNKNOWN : NET_HOME;
@@ -134,17 +137,18 @@
                         else if (a == 4) _net = NET_UNKNOWN;  // 4: unknown
                         else if (a == 5) _net = NET_ROAMING;  // 5: registered, roaming
                         // access technology
-                        if      (b == 0) ;                    // 0: GSM
-                        else if (b == 1) ;                    // 1: GSM COMPACT
-                        else if (b == 2) ;                    // 2: UTRAN
-                        else if (b == 3) ;                    // 3: GSM with EDGE availability
-                        else if (b == 4) ;                    // 4: UTRAN with HSDPA availability
-                        else if (b == 5) ;                    // 5: UTRAN with HSUPA availability
-                        else if (b == 6) ;                    // 6: UTRAN with HSDPA and HSUPA availability
+                        if      (b == 0) _act = ACT_GSM;      // 0: GSM
+                        else if (b == 1) _act = ACT_GSM;      // 1: GSM COMPACT
+                        else if (b == 2) _act = ACT_UTRAN;    // 2: UTRAN
+                        else if (b == 3) _act = ACT_EDGE;     // 3: GSM with EDGE availability
+                        else if (b == 4) _act = ACT_UTRAN;    // 4: UTRAN with HSDPA availability
+                        else if (b == 5) _act = ACT_UTRAN;    // 5: UTRAN with HSUPA availability
+                        else if (b == 6) _act = ACT_UTRAN;    // 6: UTRAN with HSDPA and HSUPA availability
                     // +COPS: <mode>[,<format>,<oper>[,<AcT>]]
-                    } else if (sscanf(cmd, "COPS: %*d,%*d,\"%*[^\"]\",%d",&a) == 1) {
-                    //  if      (a == 0) ;                    // 0: GSM, 
-                    //  else if (a == 2) ;                    // 2: UTRAN
+                    } else if (sscanf(cmd, "COPS: %*d,%*d,\"%[^\"]\",%d",s,&b) >= 1) {
+                        strcpy(_opr,s);
+                        if      (a == 0) _act = ACT_GSM;      // 0: GSM, 
+                        else if (a == 2) _act = ACT_UTRAN;    // 2: UTRAN
                     // +CPIN: <code>
                     } else if (sscanf(cmd, "CPIN: %7s",s) == 1) {
                         _sim = (strcmp("READY", s) == 0) ? SIM_READY : SIM_UNKNOWN;
@@ -288,7 +292,7 @@
     return true; 
 }
 
-bool MDMParser::checkNetStatus(void)
+bool MDMParser::checkNetStatus(Status* info /*= NULL*/)
 {
     // check registration
     sendFormated("AT+CREG?\r\n");
@@ -317,10 +321,13 @@
     sendFormated("AT+CSQ\r\n");
     if (OK != waitFinalResp())
         return false;
-    if (*_num)
-        TRACE("Phone number: \"%s\"\n", _num);
-    if (_rssi)
-        TRACE("Signal Strength: %d dBm\n", _rssi);
+    if (info) {
+        info->num = _num;
+        info->opr = _opr;
+        info->rssi = _rssi;
+        info->net = _net;
+        info->act = _act;
+    }
     return true;
 }
 
--- a/MDM.h	Tue Apr 08 11:15:33 2014 +0000
+++ b/MDM.h	Tue Apr 08 11:59:28 2014 +0000
@@ -42,6 +42,9 @@
     #define SOCKET_ERROR -1
     #define SOCKET_OK     0 
     typedef uint32_t IP;
+    typedef enum { NET_UNKNOWN, NET_DENIED, NET_NONE, NET_HOME, NET_ROAMING } Net; 
+    typedef enum { ACT_UNKNOWN, ACT_GSM, ACT_EDGE, ACT_UTRAN, ACT_CDMA } AcT; 
+    typedef struct { const char* num; const char* opr; int rssi; Net net; AcT act; } Status;
     
     MDMParser(void);
     
@@ -54,7 +57,7 @@
 
     // network
     bool init(const char* pin = NULL);
-    bool checkNetStatus(void);
+    bool checkNetStatus(Status* info = NULL);
     bool powerOff(void);
     // internet connection
     bool join(const char* apn, const char* user = NULL, const char* password = NULL);
@@ -84,7 +87,6 @@
     virtual int _send(const void* buf, int len) = 0;
 private:
     typedef enum { MODEL_UNKNOWN, MODEL_SARA_G350, MODEL_LISA_U200, MODEL_LISA_C200 } Model; 
-    typedef enum { NET_UNKNOWN, NET_DENIED, NET_NONE, NET_HOME, NET_ROAMING } Net; 
     typedef enum { SIM_UNKNOWN, SIM_PIN, SIM_READY } Sim; 
     static int _cbATI(int type, const char* buf, int len, Model* model);
     static int _cbUDNSRN(int type, const char* buf, int len, IP* ip);
@@ -100,7 +102,9 @@
     Model _model;
     Sim _sim;
     Net _net;
+    AcT _act;
     char _num[32];
+    char _opr[32];
     int _rssi;
 private:
     typedef enum { SOCK_FREE, SOCK_CREATED, SOCK_CONNECTED } SockState;