Own fork of C027_Support

Dependents:   MbedSmartRestMain MbedSmartRestMain

Fork of C027_Support by u-blox

Files at this revision

API Documentation at this revision

Comitter:
mazgch
Date:
Wed Apr 09 13:03:48 2014 +0000
Parent:
31:a0bed6c1e05d
Child:
33:fb8fb5021b09
Commit message:
some improvement on cdma

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	Wed Apr 09 11:48:04 2014 +0000
+++ b/MDM.cpp	Wed Apr 09 13:03:48 2014 +0000
@@ -121,7 +121,7 @@
                     TRACE("Socket %d: closed by remote host\r\n", a);
                     _sockets[a].state = SOCK_CREATED/*=CLOSED*/;
                 }                
-                if (_dev.model == MODEL_LISA_C200) {
+                if (_dev.dev == DEV_LISA_C200) {
                     // CDMA Specific -------------------------------------------
                     // +CREG: <n><SID>,<NID>,<stat>
                     if (sscanf(cmd, "CREG: %*d,%*d,%*d,%d",&a) == 1) {
@@ -220,16 +220,28 @@
     wait_ms(40);
     // identify the module 
     sendFormated("ATI\r\n");
-    if (OK != waitFinalResp(_cbATI, &_dev.model))
+    if (OK != waitFinalResp(_cbATI, &_dev.dev))
         return false;
-    if (_dev.model == MODEL_UNKNOWN)
+    if (_dev.dev == DEV_UNKNOWN)
         return false;
-    // model specific init
-    if (_dev.model == MODEL_LISA_C200) {
+    // device specific init
+    if (_dev.dev == DEV_LISA_C200) {
         // disable flow control
         sendFormated("AT+IFC=0,0\r\n");
         if (OK != waitFinalResp())
             return false;
+        // get the manufacturer
+        sendFormated("AT+GMI\r\n");
+        if (OK != waitFinalResp(_cbString, _dev.manu))
+            return false;
+        // get the model identification
+        sendFormated("AT+GMM\r\n");
+        if (OK != waitFinalResp(_cbString, _dev.model))
+            return false;
+        // get the sw version
+        sendFormated("AT+GMR\r\n");
+        if (OK != waitFinalResp(_cbString, _dev.ver))
+            return false;
         // Return the pseudo ESN or MEID
         sendFormated("AT+GSN\r\n");
         if (OK != waitFinalResp(_cbString, _dev.imei))
@@ -244,7 +256,7 @@
         if (OK != waitFinalResp())
             return false;
         // enable the network identification feature 
-        if (_dev.model == MODEL_LISA_U200) {
+        if (_dev.dev == DEV_LISA_U200) {
             sendFormated("AT+UGPIOC=20,2\r\n");
             if (OK != waitFinalResp())
                 return false;
@@ -273,6 +285,18 @@
         }
         if (_dev.sim != SIM_READY)
             return false;
+        // get the manufacturer
+        sendFormated("AT+CGMI\r\n");
+        if (OK != waitFinalResp(_cbString, _dev.manu))
+            return false;
+        // get the model identification
+        sendFormated("AT+CGMM\r\n");
+        if (OK != waitFinalResp(_cbString, _dev.model))
+            return false;
+        // get the 
+        sendFormated("AT+CGMR\r\n");
+        if (OK != waitFinalResp(_cbString, _dev.ver))
+            return false;            
         // Returns the ICCID (Integrated Circuit Card ID) of the SIM-card. 
         // ICCID is a serial number identifying the SIM.
         sendFormated("AT+CCID\r\n");
@@ -305,18 +329,18 @@
     return true; 
 }
 
-int MDMParser::_cbATI(int type, const char* buf, int len, Model* model)
+int MDMParser::_cbATI(int type, const char* buf, int len, Dev* dev)
 {
-    if ((type == TYPE_UNKNOWN) && model) {
+    if ((type == TYPE_UNKNOWN) && dev) {
         if (strstr(buf, "SARA-G350")) {
-            *model = MODEL_SARA_G350;
-            /*TRACE("Identified Model: SARA-G350 2G\\n")*/;
+            *dev = DEV_SARA_G350;
+            /*TRACE("Identified Device: SARA-G350 2G\\n")*/;
         } else if (strstr(buf, "LISA-U200")) {
-            *model = MODEL_LISA_U200;
-            /*TRACE("Identified Model: LISA-U200 2G/3G\r\n")*/;
+            *dev = DEV_LISA_U200;
+            /*TRACE("Identified Device: LISA-U200 2G/3G\r\n")*/;
         } else if (strstr(buf, "LISA-C200")) {
-            *model= MODEL_LISA_C200;
-            /*TRACE("Identified Model: LISA-C200 CDMA\r\n")*/;
+            *dev= DEV_LISA_C200;
+            /*TRACE("Identified Device: LISA-C200 CDMA\r\n")*/;
         }
     }
     return WAIT;
@@ -351,10 +375,22 @@
     if ((_net.reg != REG_ROAMING) && (_net.reg != REG_HOME))
         return false;
     // check modem specific status messages 
-    if (_dev.model == MODEL_LISA_C200) {
+    if (_dev.dev == DEV_LISA_C200) {
         sendFormated("AT+CSS?\r\n");
         if (OK != waitFinalResp())
             return false;
+        // get the Telephone number
+        sendFormated("AT$MDN?\r\n");
+        if (OK != waitFinalResp(_cbString, _net.num))
+            return false;
+        // check if we have a Mobile Directory Number
+        if (memcmp(_net.num, "0000", 4) == 0);
+            return false;
+        // get the the Network access identifier string
+        char nai[64];
+        sendFormated("AT$QCMIPNAI?\r\n");
+        if (OK != waitFinalResp(_cbString, nai))
+            return false;
     } else {
         // check GPRS attach status
         int state = 0;
@@ -440,20 +476,14 @@
 
 MDMParser::IP MDMParser::join(const char* apn /*= NULL*/, const char* user /*= NULL*/, const char* password /*= NULL*/)
 {
-    IP ip = NOIP;
-    if (_dev.model == MODEL_LISA_C200) {
-#ifdef TODO // TODO implement 
-        // enable the 
-        sendFormated("AT$QCMIPEP=1\r\n");
-        if (OK != waitFinalResp())
-            return NOIP;
+    _ip = NOIP;
+    if (_dev.dev == DEV_LISA_C200) {
+        // TODO: is there something to do here?
+         
         //Get local IP address
         sendFormated("AT+CMIP?\r\n");
-        // extract: +CMIP: xxx.xxx.xxx.xxx
-        if (OK != waitFinalResp())
+        if (OK != waitFinalResp(_cbCMIP, &_ip))
             return NOIP;
-        
-#endif
     } else { 
         // check gprs attach status 
         sendFormated("AT+CGATT?\r\n");
@@ -497,12 +527,22 @@
             return NOIP;
         //Get local IP address
         sendFormated("AT+UPSND=" PROFILE ",0\r\n");
-        if (OK != waitFinalResp(_cbUPSND, &ip))
+        if (OK != waitFinalResp(_cbUPSND, &_ip))
             return NOIP;
     }
-    return ip;
+    return _ip;
 }
 
+int MDMParser::_cbCMIP(int type, const char* buf, int len, IP* ip)
+{
+    if ((type == TYPE_PLUS) && ip) {
+        int a,b,c,d;
+        if (sscanf(buf, "\r\n+CMIP: " IPSTR, &a,&b,&c,&d) == 4)
+            *ip = IPADR(a,b,c,d);
+    }
+    return WAIT;
+}
+        
 int MDMParser::_cbUPSND(int type, const char* buf, int len, int* act)
 {
     if ((type == TYPE_PLUS) && act) {
@@ -537,15 +577,13 @@
 {
     if (_ip == NOIP)
         return true;
-    if (_dev.model == MODEL_LISA_C200) {
-#ifdef TODO // TODO implement 
-        sendFormated("AT$QCMIPEP=0\r\n");
-#endif
+    if (_dev.dev == DEV_LISA_C200) {
+        // TODO: is there something to do here?
     } else { 
         sendFormated("AT+UPSDA=" PROFILE ",4\r\n");
+        if (OK != waitFinalResp())
+            return false;
     }
-    if (OK != waitFinalResp())
-        return false;
     _ip = NOIP;
     return true;
 }
--- a/MDM.h	Wed Apr 09 11:48:04 2014 +0000
+++ b/MDM.h	Wed Apr 09 13:03:48 2014 +0000
@@ -26,11 +26,12 @@
     // ----------------------------------------------------------------
     
     //! MT models
-    typedef enum { MODEL_UNKNOWN, MODEL_SARA_G350, MODEL_LISA_U200, MODEL_LISA_C200 } Model; 
+    typedef enum { DEV_UNKNOWN, DEV_SARA_G350, DEV_LISA_U200, DEV_LISA_C200 } Dev; 
     //! SIM Status
     typedef enum { SIM_UNKNOWN, SIM_PIN, SIM_READY } Sim; 
     //! Device status
-    typedef struct { Model model; Sim sim; char ccid[20]; char imsi[16]; char imei[16]; } DevStatus;
+    typedef struct { Dev dev; Sim sim; char ccid[20]; char imsi[16]; char imei[16]; 
+                     char manu[16]; char model[16]; char ver[16]; } DevStatus;
     //! Network Registration Status
     typedef enum { REG_UNKNOWN, REG_DENIED, REG_NONE, REG_HOME, REG_ROAMING } Reg; 
     // Access Technology
@@ -349,7 +350,7 @@
     static int _cbString(int type, const char* buf, int len, char* str);
     static int _cbInt(int type, const char* buf, int len, int* val);
     // device
-    static int _cbATI(int type, const char* buf, int len, Model* model);
+    static int _cbATI(int type, const char* buf, int len, Dev* dev);
     static int _cbCPIN(int type, const char* buf, int len, Sim* sim);
     static int _cbCCID(int type, const char* buf, int len, char* ccid);
     // network 
@@ -358,6 +359,7 @@
     static int _cbCNUM(int type, const char* buf, int len, char* num);
     static int _cbCGATT(int type, const char* buf, int len, int* state);
     // sockets
+    static int _cbCMIP(int type, const char* buf, int len, IP* ip);
     static int _cbUPSND(int type, const char* buf, int len, int* act);
     static int _cbUPSND(int type, const char* buf, int len, IP* ip);
     static int _cbUDNSRN(int type, const char* buf, int len, IP* ip);