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:
80:34985b4d821e
Parent:
79:291df065e345
Child:
81:3966a5c17037
--- a/MDM.cpp	Mon May 26 11:55:16 2014 +0000
+++ b/MDM.cpp	Tue May 27 08:21:53 2014 +0000
@@ -11,8 +11,9 @@
 #define ISSOCKET(s)     (((s) >= 0) && ((s) < (sizeof(_sockets)/sizeof(*_sockets))))
 //! check for timeout
 #define TIMEOUT(t, ms)  ((ms != TIMEOUT_BLOCKING) && (ms < t.read_ms())) 
-
+//! registration ok check helper
 #define REG_OK(r)       ((r == REG_HOME) || (r == REG_ROAMING)) 
+//! registration done check helper (no need to poll further)
 #define REG_DONE(r)     ((r == REG_HOME) || (r == REG_ROAMING) || (r == REG_DENIED)) 
 
 #ifdef MDM_DEBUG
@@ -255,7 +256,8 @@
 
 bool MDMParser::connect(
             const char* simpin, 
-            const char* apn, const char* username, const char* password,
+            const char* apn, const char* username, 
+            const char* password, Auth auth,
             PinName pn)
 {
     bool ok = init(simpin, NULL, pn);  
@@ -270,7 +272,7 @@
 #endif
     if (!ok)
         return false;
-    IP ip = join(apn,username,password);
+    IP ip = join(apn,username,password,auth);
 #ifdef MDM_DEBUG
     if (_debugLevel >= 1) dumpIp(ip);
 #endif
@@ -1044,7 +1046,7 @@
 
 bool MDMParser::smsSend(const char* num, const char* buf)
 {
-    sendFormated("AT+CMGS=\"%s\"\r",num);
+    sendFormated("AT+CMGS=\"%s\"\r\n",num);
     if (RESP_PROMPT != waitFinalResp(NULL,NULL,150*1000)) {
         return false;
     }
@@ -1107,6 +1109,8 @@
 
 bool MDMParser::ussdCommand(const char* cmd, char* buf)
 {
+    if (_dev.dev == DEV_LISA_C200) 
+        return false;
     *buf = '\0';
     sendFormated("AT+CUSD=1,\"%s\"\r\n",cmd);
     if (RESP_OK != waitFinalResp(_cbCUSD, buf)) {
@@ -1114,7 +1118,56 @@
     }
     return true;
 }
+
+// ----------------------------------------------------------------
    
+bool MDMParser::delFile(const char* filename)
+{
+    sendFormated("AT+UDELFILE=\"%s\"\r\n", filename);
+    if (RESP_OK != waitFinalResp())
+        return false;
+    return true;
+}
+
+int MDMParser::writeFile(const char* filename, const char* buf, int len)
+{
+    sendFormated("AT+UDWNFILE=\"%s\",%d\r\n", filename, len);
+    if (RESP_PROMPT != waitFinalResp())
+        return 0;
+    send(buf, len);
+    if (RESP_OK != waitFinalResp())
+        return 0;
+    return len;
+}
+
+int MDMParser::readFile(const char* filename, char* buf, int len)
+{
+    sendFormated("AT+URDFILE=\"%s\"\r\n", filename, len);
+    URDFILEparam param;
+    param.filename = filename;
+    param.buf = buf; 
+    param.sz = len; 
+    param.len = 0;
+    if (RESP_OK != waitFinalResp(_cbURDFILE, &param))
+        return -1;
+    return param.len;
+}
+
+int MDMParser::_cbURDFILE(int type, const char* buf, int len, URDFILEparam* param)
+{
+    if ((type == TYPE_PLUS) && param && param->filename && param->buf) {
+        char filename[48];
+        int sz;
+        if ((sscanf(buf, "\r\n+URDFILE: \"%[^\"]\",%d,", filename, &sz) == 2) && 
+            (0 == strcmp(param->filename, filename)) &&
+            (buf[len-sz-2] == '\"') && (buf[len-1] == '\"')) {
+            param->len = (sz < param->sz) ? sz : param->sz;
+            memcpy(param->buf, &buf[len-1-sz], param->len);
+        }
+    }
+    return WAIT;
+}
+  
 // ----------------------------------------------------------------
 bool MDMParser::setDebug(int level) 
 {
@@ -1242,6 +1295,16 @@
                         ch = pipe->next();
                     }   
                 }
+                else if (*fmt == 's') {
+                    fmt ++;
+                    if (ch != '\"')         return NOT_FOUND;
+                    do {
+                        if (++o > len)      return WAIT;
+                        ch = pipe->next();
+                    } while (ch != '\"');
+                    if (++o > len)          return WAIT;
+                    ch = pipe->next();
+                }
             }
             if (*fmt++ != ch)               return NOT_FOUND;
         }
@@ -1263,6 +1326,7 @@
         } lutF[] = {
             { "\r\n+USORD: %d,%d,\"%c\"",                   TYPE_PLUS       },
             { "\r\n+USORF: %d,\""IPSTR"\",%d,%d,\"%c\"",    TYPE_PLUS       },
+            { "\r\n+URDFILE: %s,%d,\"%c\"",                 TYPE_PLUS       },
         };
         static struct { 
               const char* sta;          const char* end;    int type; 
@@ -1280,6 +1344,7 @@
             { "\r\n+",                  "\r\n",             TYPE_PLUS       },
             { "\r\n@",                  NULL,               TYPE_PROMPT     }, // Sockets
             { "\r\n>",                  NULL,               TYPE_PROMPT     }, // SMS
+            { "\n>",                    NULL,               TYPE_PROMPT     }, // File
         };
         for (int i = 0; i < sizeof(lutF)/sizeof(*lutF); i ++) {
             pipe->set(unkn);