Cellular library for MTS Socket Modem Arduino Shield devices from Multi-Tech Systems

Dependents:   mtsas mtsas mtsas mtsas

Files at this revision

API Documentation at this revision

Comitter:
Vanger
Date:
Tue Aug 05 18:35:22 2014 +0000
Parent:
50:144099030d9b
Child:
52:2cb58398a4f9
Commit message:
Changed some comment lines in CellularFactory.cpp, EasyIP.cpp, UIP.cpp; Changed Cellular.cpp sendCommand() function to explicitly check for UIP responses, and removed 5ms wait between read cycles.

Changed in this revision

Cellular/Cellular.cpp Show annotated file Show diff for this revision Revisions of this file
Cellular/CellularFactory.cpp Show annotated file Show diff for this revision Revisions of this file
Cellular/EasyIP.cpp Show annotated file Show diff for this revision Revisions of this file
Cellular/UIP.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Cellular/Cellular.cpp	Tue Aug 05 15:02:00 2014 +0000
+++ b/Cellular/Cellular.cpp	Tue Aug 05 18:35:22 2014 +0000
@@ -203,8 +203,6 @@
     bool done = false;
     tmr.start();
     do {
-        wait(0.05);
-        
         //Make a non-blocking read call by passing timeout of zero
         int size = io->read(tmp,255,0);    //1 less than allocated (timeout is instant)
         if(size > 0) {
@@ -242,7 +240,17 @@
                         done = true;
                     } 
                 } else if (type == MTSMC_H5_IP || type == MTSMC_EV3_IP || type == MTSMC_C2_IP) {
-                    if (result.find("Ok_Info_") != std::string::npos) {
+                    if (result.find("Ok_Info_WaitingForData") != std::string::npos) {
+                        done = true;
+                    } else if (result.find("Ok_Info_SocketClosed") != std::string::npos) {
+                        done = true;
+                    } else if (result.find("Ok_Info_DataBegin") != std::string::npos) {
+                        done = true;
+                    } else if (result.find("Ok_Info_NoMail") != std::string::npos) {
+                        done = true;
+                    } else if (result.find("Ok_Info_Mail") != std::string::npos) {
+                        done = true;
+                    } else if (result.find("Ok_Info_PPP") != std::string::npos) {
                         done = true;
                     }
                 }
--- a/Cellular/CellularFactory.cpp	Tue Aug 05 15:02:00 2014 +0000
+++ b/Cellular/CellularFactory.cpp	Tue Aug 05 18:35:22 2014 +0000
@@ -30,7 +30,7 @@
             /* didn't get an error - keep going */
             if(model.find("#STN") != string::npos) {
                 //If response found is from unsolicited response #STN: from the radio,
-                //then we got a "corrupted" response, and to try again.
+                //then we got an unsolicited response, and to try again.
                 continue;
             }
                 break;
--- a/Cellular/EasyIP.cpp	Tue Aug 05 15:02:00 2014 +0000
+++ b/Cellular/EasyIP.cpp	Tue Aug 05 18:35:22 2014 +0000
@@ -72,12 +72,12 @@
     if(isConnected()) {
         return true;
     }
+    
     //Create an mbed timer object
     Timer tmr;
     //Check Registration: AT+CREG? == 0,1
     //(Does the AT command inside Cellular class)
     tmr.start();
-    
     do {
         Registration registration = getRegistration();
         if(registration != REGISTERED) {
@@ -87,13 +87,14 @@
             break;
         }
     } while(tmr.read() < 30); 
+    
     //Check RSSI: AT+CSQ
     //Does the command inside Cellular
     tmr.reset();
     do {
         int rssi = getSignalStrength();
         logDebug("Signal strength: %d", rssi);
-        if((rssi == 99) || (rssi == -1)) {
+        if(rssi == 99 || rssi == -1) {
             logTrace("No Signal ... waiting");
             wait(1);
         } else {
@@ -156,6 +157,10 @@
         logDebug("Successfully closed PPP Connection");
     }
     
+    /* Radio was entering unknown state if ping command was sent after calling 
+     * disconnect, due to context being closed between radio sending ping and 
+     * waiting for ping response (which will never occur with connection closed)
+     */
     tmr.start();
     while(tmr.read() < 30) {
         result = sendCommand("AT#SGACT?", 1000);
@@ -169,6 +174,7 @@
         }
     }
     
+    //If still unable to close PPP connection, wait for 30 seconds to drop connection
     if(pppConnected) {
         wait(30);
         pppConnected = false;
@@ -181,7 +187,7 @@
 {
     std::string stateString;
     std::vector<std::string> pieces;
-    //state flags for various connection checks
+    //state flags for various connection components
     bool signal = false, regist = false, active = false;
     
     //1) Check if APN was set if we're on an HSPA radio
@@ -200,7 +206,7 @@
     
     
     //3) Query the radio
-    //Check antenna signal
+    //3.a) Check antenna signal
     std::string reply = sendCommand("AT+CSQ", 500);
     if(reply.empty() || (reply.find("ERROR") != std::string::npos)) {
         signal = false;
@@ -218,7 +224,7 @@
         }
     }
     
-    //Check cell tower registration
+    //3.b) Check cell tower registration
     reply = sendCommand("AT+CREG?", 500);
     if(reply.empty() || (reply.find("ERROR") != std::string::npos)) {
         regist = false;
@@ -236,7 +242,7 @@
         }
     }
     
-    //Check active context (SGACT = 1,1)
+    //3.c) Check active context (SGACT = 1,1)
     reply = sendCommand("AT#SGACT?", 500);
     if(reply.empty() || (reply.find("ERROR") != std::string::npos)) {
         active = false;
--- a/Cellular/UIP.cpp	Tue Aug 05 15:02:00 2014 +0000
+++ b/Cellular/UIP.cpp	Tue Aug 05 18:35:22 2014 +0000
@@ -75,7 +75,7 @@
     do {
         int rssi = getSignalStrength();
         logDebug("Signal strength: %d", rssi);
-        if(rssi == 99) {
+        if(rssi == 99 || rssi == -1) {
             logTrace("No Signal ... waiting");
             wait(1);
         } else {