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:
Mon May 12 13:58:47 2014 +0000
Parent:
56:3115ef44c771
Child:
58:e38a2e942fbb
Commit message:
simple connect api

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	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));
 }
 
 // ----------------------------------------------------------------
--- a/MDM.h	Mon May 12 13:05:27 2014 +0000
+++ b/MDM.h	Mon May 12 13:58:47 2014 +0000
@@ -78,15 +78,27 @@
 
     
     // ----------------------------------------------------------------
-    // Data Connection (GPRS)
+    // Device 
     // ----------------------------------------------------------------
     
+    /** Combined Init, checkNetStatus, join suitable for simple applications
+        \param simpin a optional pin of the SIM card
+        \param apn  the of the network provider e.g. "internet" or "apn.provider.com"
+        \param username is the user name text string for the authentication phase
+        \param password is the password text string for the authentication phase
+        \param dump set to true if you like to dump the status if successful
+        \return true if successful, false otherwise
+    */
+    bool connect(const char* simpin, 
+            const char* apn, const char* username, const char* password,
+            bool dump);    
+
     /** register (Attach) the MT to the GPRS service. 
-        \param pin  a optional pin of the SIM card
+        \param simpin a optional pin of the SIM card
         \param status an optional struture to with device information 
         \return true if successful, false otherwise
     */
-    bool init(const char* pin = NULL, DevStatus* status = NULL);
+    bool init(const char* simpin = NULL, DevStatus* status = NULL);
     
     /** check if the network is available 
         \param status an optional structure to with network information 
@@ -106,11 +118,12 @@
     
     /** register (Attach) the MT to the GPRS service. 
         \param apn  the of the network provider e.g. "internet" or "apn.provider.com"
-        \param user is the user name text string for the authentication phase
+        \param username is the user name text string for the authentication phase
         \param password is the password text string for the authentication phase
+        \param dump set to true if you like to dump the status if successful
         \return the ip that is assigned 
     */
-    MDMParser::IP join(const char* apn = NULL, const char* user = NULL, const char* password = NULL);
+    MDMParser::IP join(const char* apn = NULL, const char* username = NULL, const char* password = NULL);
     
     /** deregister (detach) the MT from the GPRS service.
         \return true if successful, false otherwise