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:
Mon Jun 30 17:13:00 2014 +0000
Parent:
26:2b769ed8de4f
Child:
28:f93d7b3f7c2e
Commit message:
Implemented echo() function under EasyIP.; Fixed ping() function under EasyIP.; Made a pure virtual echo() under Cellular.h for EasyIP and UIP inheritance; Made echo() virtual under both UIP.h and EasyIP.h

Changed in this revision

Cellular/Cellular.h 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/EasyIP.h Show annotated file Show diff for this revision Revisions of this file
Cellular/UIP.h Show annotated file Show diff for this revision Revisions of this file
--- a/Cellular/Cellular.h	Thu Jun 26 21:12:37 2014 +0000
+++ b/Cellular/Cellular.h	Mon Jun 30 17:13:00 2014 +0000
@@ -322,6 +322,12 @@
     * @returns the enumeration name as a string.
     */
     static std::string getRadioNames(Radio radio);
+    /** A method for changing the echo commands from radio.
+    * @param state Echo mode is off (an argument of 1 turns echos off, anything else turns echo on)
+    * @returns standard Code enumeration
+    */
+    virtual Code echo(bool state)=0; //Implemented the same way in both UIP and EasyIP, 
+                                        //and thus could be moved to cellular class
 
 protected:
     MTSBufferedIO* io; //IO interface obect that the radio is accessed through.
--- a/Cellular/CellularFactory.cpp	Thu Jun 26 21:12:37 2014 +0000
+++ b/Cellular/CellularFactory.cpp	Mon Jun 30 17:13:00 2014 +0000
@@ -38,7 +38,7 @@
     /* AT#VVERSION is a UIP specific AT command
      * if we get an error response, we're not using a UIP board */
     reply = sendCommand(io, "AT#VVERSION", 2000);
-    if (reply.find("ERROR") != string::npos) {
+    if ((reply.find("ERROR") != string::npos) || (reply.find("error") != string::npos)) {
         uip = false;
     } else {
         uip = true;
--- a/Cellular/EasyIP.cpp	Thu Jun 26 21:12:37 2014 +0000
+++ b/Cellular/EasyIP.cpp	Mon Jun 30 17:13:00 2014 +0000
@@ -98,7 +98,7 @@
         }
     } while(tmr.read() < 30);
 
-    //AT#CONNECTIONSTART: Make a PPP connection
+    //Similar to AT#CONNECTIONSTART: Make a PPP connection
     if (type == MTSMC_H5 || type == MTSMC_G3) {
         logDebug("Making PPP Connection Attempt. APN[%s]", apn.c_str());
     } else {
@@ -140,12 +140,14 @@
     } else {
         logError("Closing PPP Connection. Continuing ...");
     }
-    pppConnected = false; 
+    pppConnected = false; //We can do this since the cell will drop their side after timeout
 }
-//++++++++++++++++++++++++++++++++++++++++++++
+
 bool EasyIP::isConnected()
 {
     
+    
+    
     return pppConnected;
 }
 //Binds the socket to a specific port if able
@@ -155,19 +157,19 @@
    
     return true;
 }
-//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
 bool EasyIP::open(const std::string& address, unsigned int port, Mode mode)
 {
    
     return socketOpened;
 }
-//++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
 bool EasyIP::isOpen()
 {
     
     return socketOpened;
 }
-//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
 bool EasyIP::close()
 {
     
@@ -224,7 +226,7 @@
         return MTS_SUCCESS;
     }
 }
-//++++++++++++++++++++++++++++++++++++++++++++++++++
+
 void EasyIP::reset()
 {
 }
@@ -237,29 +239,51 @@
 //Turns off echo when it receives a 1, turns on when it receives anything else
 Code EasyIP::echo(bool state)
 {
-    return MTS_SUCCESS;
+    Code code;
+    if (state) {
+        code = sendBasicCommand("ATE0", 1000);
+        echoMode = (code == MTS_SUCCESS) ? false : echoMode;
+    } else {
+        code = sendBasicCommand("ATE1", 1000);
+        echoMode = (code == MTS_SUCCESS) ? true : echoMode;
+    }
+    return code;
 }
 
 bool EasyIP::ping(const std::string& address)
 {
     char buffer[256] = {0};
-    std::string response;
+    std::vector<std::string> parts;
+    int pingsRec=0;
+    int TTL=0;
+    int Timeout=0;
+    
+    //Format parameters for sending to radio
+    sprintf(buffer, "AT#PING=%s,1,32,%d", address.c_str(), (10*PINGDELAY));
     
-    //Sends "PINGNUM" of pings to "address" with a timeout of "PINGDELAY"
-    //AT command takes pingdelay as units of 100ms, so seconds would be 10 times bigger
-    //Concatenate parameters into one string
-    sprintf(buffer, "AT#PING=%s,%d,32,%d", address.c_str(), PINGNUM, (10*PINGDELAY));
-    response = sendCommand(buffer,PINGDELAY*10000);
-    if(response.find("OK") != std::string::npos) {
-        //Not sure if I need a wait here, or if it is included in the sendcommand wait time
-        return true;
-    }
-    
-
+    for(int pngs=0; pngs<PINGNUM; pngs++) {
+        std::string response = sendCommand(buffer, (PINGDELAY*1500)); //Send 1 ping
+        if(response.empty()) continue; //Skip current loop if send command fails
+        parts = Text::split(response, "\r\n");
+        parts = Text::split(parts[1], ",");
+        //Parse TTL and Timeout values
+        Timeout = std::atoi(parts[2].c_str());
+        TTL = std::atoi(parts[3].c_str());
+                
+        if((Timeout < 600) && (TTL < 255)) {
+            pingsRec++;
+        }
+    }   //Success if less than 50% packet loss
+        if( ((pingsRec/PINGNUM)>= 0.5) ) {
+            return true;
+        }
     return false;
 }
 
+//Pass 1 to enable socket closeable
+//Pass 0 to disable socket closeable
 Code EasyIP::setSocketCloseable(bool enabled)
 {
+
     return MTS_SUCCESS;
 }
--- a/Cellular/EasyIP.h	Thu Jun 26 21:12:37 2014 +0000
+++ b/Cellular/EasyIP.h	Mon Jun 30 17:13:00 2014 +0000
@@ -77,7 +77,7 @@
     * @param state if true echo will be turned off, otherwise it will be turned on.
     * @returns the standard AT Code enumeration.
     */
-    Code echo(bool state);
+    virtual Code echo(bool state);
 
     /** This method can be used to trade socket functionality for performance.
     * In order to enable a socket connection to be closed by the client side programtically,
--- a/Cellular/UIP.h	Thu Jun 26 21:12:37 2014 +0000
+++ b/Cellular/UIP.h	Mon Jun 30 17:13:00 2014 +0000
@@ -86,7 +86,7 @@
     * @param state if true echo will be turned off, otherwise it will be turned on.
     * @returns the standard AT Code enumeration.
     */
-    Code echo(bool state);
+    virtual Code echo(bool state);
 
     /** This method can be used to trade socket functionality for performance.
     * In order to enable a socket connection to be closed by the client side programtically,