final 1

Fork of C027_Support by jajn HA

Revision:
57:869bd35f44cc
Parent:
56:3115ef44c771
Child:
58:e38a2e942fbb
--- a/MDM.cpp	Mon May 12 13:05:27 2014 +0000
+++ b/MDM.cpp	Mon May 12 13:58:47 2014 +0000
@@ -211,7 +211,37 @@
 
 // ----------------------------------------------------------------
 
-bool MDMParser::init(const char* pin, DevStatus* status)
+bool MDMParser::connect(
+            const char* simpin, 
+            const char* apn, const char* username, const char* password,
+            bool dump)
+{
+    DevStatus devStatus = {};
+    bool mdmOk = init(simpin, &devStatus);
+    if (dump) dumpDevStatus(&devStatus);
+    if (!mdmOk)
+        return false;
+    // wait until we are connected
+    int i = 60;
+    NetStatus netStatus = {};
+    while (!checkNetStatus(&netStatus))
+    {
+        if ((netStatus.reg == REG_DENIED) || (i == 0))
+            break;;
+        i --;
+        wait_ms(1000);
+    }
+    if (dump) dumpNetStatus(&netStatus);
+    if ((netStatus.reg == REG_DENIED) || (i == 0))
+        return false;
+    IP ip = join(apn,username,password);
+    if (dump) dumpIp(ip);
+    if (ip == NOIP)
+        return false; 
+    return true;
+}
+
+bool MDMParser::init(const char* simpin, DevStatus* status)
 {
     int i = 5;
     while (i--) {
@@ -289,11 +319,11 @@
                 return false;
             // Enter PIN if needed
             if (_dev.sim == SIM_PIN) {
-                if (!pin) {
+                if (!simpin) {
                     TRACE("SIM PIN not available\r\n");
                     return false;
                 }
-                sendFormated("AT+CPIN=%s\r\n", pin);
+                sendFormated("AT+CPIN=%s\r\n", simpin);
                 if (RESP_OK != waitFinalResp(_cbCPIN, &_dev.sim))
                     return false;
             } else if (_dev.sim != SIM_READY)
@@ -504,7 +534,7 @@
 // ----------------------------------------------------------------
 // internet connection 
 
-MDMParser::IP MDMParser::join(const char* apn /*= NULL*/, const char* user /*= NULL*/, const char* password /*= NULL*/)
+MDMParser::IP MDMParser::join(const char* apn /*= NULL*/, const char* username /*= NULL*/, const char* password /*= NULL*/)
 {
     _ip = NOIP;
     if (_dev.dev == DEV_LISA_C200) {
@@ -537,8 +567,8 @@
             if (RESP_OK != waitFinalResp())
                 return NOIP;
         }
-        if (user) {    
-            sendFormated("AT+UPSD=" PROFILE ",2,\"%s\"\r\n", user);
+        if (username) {    
+            sendFormated("AT+UPSD=" PROFILE ",2,\"%s\"\r\n", username);
             if (RESP_OK != waitFinalResp())
                 return NOIP;
         }
@@ -952,7 +982,7 @@
  
 void MDMParser::dumpDevStatus(MDMParser::DevStatus* status) 
 {
-    printf("Device Status:\r\n");
+    printf("Modem Device Status:\r\n");
     const char* txtDev[] = { "Unknown", "SARA-G350", "LISA-U200", "LISA-C200" };
     if (status->dev < sizeof(txtDev)/sizeof(*txtDev) && (status->dev != MDMParser::DEV_UNKNOWN))
         printf("  Device:       %s\r\n", txtDev[status->dev]);
@@ -980,7 +1010,7 @@
 
 void MDMParser::dumpNetStatus(MDMParser::NetStatus *status)
 {
-    printf("Network Status:\r\n");
+    printf("Modem Network Status:\r\n");
     const char* txtReg[] = { "Unknown", "Denied", "None", "Home", "Roaming" };
     if (status->reg < sizeof(txtReg)/sizeof(*txtReg) && (status->reg != MDMParser::REG_UNKNOWN))
         printf("  Registration:       %s\r\n", txtReg[status->reg]);
@@ -1003,7 +1033,8 @@
 
 void MDMParser::dumpIp(MDMParser::IP ip) 
 {
-    printf("IP Address: " IPSTR "\r\n", IPNUM(ip));
+    if (ip != NOIP)
+        printf("Modem IP Address: " IPSTR "\r\n", IPNUM(ip));
 }
 
 // ----------------------------------------------------------------