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 Aug 11 16:03:19 2014 +0000
Parent:
51:ffc556ba33f7
Child:
53:1aee5fe47adb
Commit message:
Removed parse response '>' from sendCommand() under Cellular.cpp, changed sendSMS() to verify sending SMS message under Cellular.cpp, changed disconnect() to have better flow under EasyIP.cpp, changed isConnected() to be simpler under EasyIP.cpp

Changed in this revision

Cellular/Cellular.cpp Show annotated file Show diff for this revision Revisions of this file
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.cpp 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
Test/TestSMS.h Show annotated file Show diff for this revision Revisions of this file
--- a/Cellular/Cellular.cpp	Tue Aug 05 18:35:22 2014 +0000
+++ b/Cellular/Cellular.cpp	Mon Aug 11 16:03:19 2014 +0000
@@ -132,9 +132,6 @@
     return UNKNOWN;
 }
 
-//Removed setAPN to be implemented in the individual cellular classes,
-//as UIP and EasyIP implement it in different ways.
-
 Code Cellular::setDns(const std::string& primary, const std::string& secondary)
 {
     return sendBasicCommand("AT#DNS=1," + primary + "," + secondary, 1000);
@@ -212,47 +209,30 @@
         //Check for a response to signify the completion of the AT command
         //OK, ERROR, CONNECT are the 3 most likely responses
         if(result.size() > (command.size() + 2)) {
-                if(result.find("OK") != std::string::npos) {
-                    done = true;
-                } else if (result.find("ERROR") != std::string::npos) {
-                    done = true;
-                } else if (result.find("NO CARRIER") != std::string::npos) {
-                    done = true;
-                } else if (result.find("RING") != std::string::npos) {
+                if(result.find("OK\r\n",command.size()) != std::string::npos) {
                     done = true;
-                } else if (result.find("BUSY") != std::string::npos) {
-                    done = true;
-                } else if (result.find("NO ANSWER") != std::string::npos) {
+                } else if (result.find("ERROR\r\n") != std::string::npos) {
                     done = true;
-                }
-                
-                if (command.find("AT+CMGS=") != string::npos) {
-                    if (result.find('>') != string::npos) {
-                        done = true;
-                    }
+                } else if (result.find("NO CARRIER\r\n") != std::string::npos) {
+                    done = true;
                 }
                 
                 if(type == MTSMC_H5 || type == MTSMC_G3 || type == MTSMC_EV3 || type == MTSMC_C2) {
-                    if (result.find("CONNECT") != std::string::npos) {
-                        //Could add socketOpened flag check here if CONNECT is found
-                        done = true;
-                    } else if(result.find("NO DIALTONE") != std::string::npos) {
+                    if (result.find("CONNECT\r\n") != std::string::npos) {
                         done = true;
                     } 
                 } else if (type == MTSMC_H5_IP || type == MTSMC_EV3_IP || type == MTSMC_C2_IP) {
-                    if (result.find("Ok_Info_WaitingForData") != std::string::npos) {
+                    if (result.find("Ok_Info_WaitingForData\r\n") != std::string::npos) {
                         done = true;
-                    } else if (result.find("Ok_Info_SocketClosed") != std::string::npos) {
+                    } else if (result.find("Ok_Info_SocketClosed\r\n") != std::string::npos) {
                         done = true;
-                    } else if (result.find("Ok_Info_DataBegin") != std::string::npos) {
+                    } else if (result.find("Ok_Info_PPP\r\n") != 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) {
+                    } else if (result.find("Ok_Info_GprsActivation\r\n") != std::string::npos) {
                         done = true;
-                    } else if (result.find("Ok_Info_PPP") != std::string::npos) {
+                    } else if (result.find("alive") != std::string::npos) {
                         done = true;
-                    }
+                    } 
                 }
         }
         
@@ -263,7 +243,7 @@
             done = true;
         }
     } while (!done);
-
+    
     return result;
 }
 
@@ -286,11 +266,13 @@
         logError("CMGF failed");
         return code;
     }
+    
     code = sendBasicCommand(csmp, 1000);
     if (code != MTS_SUCCESS) {
         logError("CSMP failed [%s]", getRadioNames(type).c_str());
         return code;
     }
+    
     string cmd = "AT+CMGS=\"";
     cmd.append("+");
     cmd.append(phoneNumber);
@@ -304,15 +286,20 @@
             logError("CMGS phone number failed");
             return MTS_NO_RESPONSE;
         }
-
         wait(1);
     }
     wait(.2);
-    string  response2 = sendCommand(message, 4000, CTRL_Z);
-    logInfo("SMS Response: [%s]", response2.c_str());
-    if ((response2.find("+CMGS:") == string::npos) || (response2.find("ERROR") != std::string::npos)) {
-        logError("CMGS message failed");
-        return MTS_FAILURE;
+    
+    for (int i = 0; i < 5; i++) {
+        string  response2 = sendCommand(message, 4000, CTRL_Z);
+        if (response2.find("+CMGS:") != string::npos) {
+            break;
+        }
+        if (i >= 5) {
+            logError("CMGS message failed");
+            return MTS_FAILURE;
+        }
+        wait(1);
     }
     return MTS_SUCCESS;
 }
--- a/Cellular/Cellular.h	Tue Aug 05 18:35:22 2014 +0000
+++ b/Cellular/Cellular.h	Mon Aug 11 16:03:19 2014 +0000
@@ -187,18 +187,13 @@
     * to your favorite serial library.
     *
     * @param io the io interface that is attached to the cellular radio.
-    * @param DCD this is the dcd signal from the radio. If attached the
-    * the pin must be passed in here for this class to operate correctly.
-    * The default is not connected.
-    * @param DTR this is the dtr signal from the radio. If attached the
-    * the pin must be passed in here for this class to operate correctly.
     * The default is not connected.
     * @returns true if the init was successful, otherwise false.
     */
     virtual bool init(MTSBufferedIO* io);
     
     /** Sets up the physical connection pins
-    *   (DTR,DCD, and RESET obviously)
+    *   (DTR,DCD, and RESET)
     */
     bool configureSignals(unsigned int DCD = NC, unsigned int DTR = NC, unsigned int RESET = NC);
 
@@ -234,7 +229,7 @@
     * @param the APN as a string.
     * @returns the standard AT Code enumeration.
     */
-    virtual Code setApn(const std::string& apn)=0;
+    virtual Code setApn(const std::string& apn) = 0;
 
     /** This method is used to set the DNS which enables the use of URLs instead
     * of IP addresses when making a socket connection.
--- a/Cellular/CellularFactory.cpp	Tue Aug 05 18:35:22 2014 +0000
+++ b/Cellular/CellularFactory.cpp	Mon Aug 11 16:03:19 2014 +0000
@@ -29,11 +29,10 @@
         if (model.find("error") == string::npos && model.find("ERROR") == string::npos && !model.empty()) {
             /* 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 an unsolicited response, and to try again.
+                //Temporary fix for unsolicited #STN from radio startup
                 continue;
             }
-                break;
+            break;
         }
         
         wait(1);
@@ -47,21 +46,19 @@
     } else {
         uip = true;
     }
-    
 
     if (uip && model.find("HE910") != string::npos) {
         type = Cellular::MTSMC_H5_IP;
-        logDebug("radio model: HE910");
+        logDebug("UIP radio model: HE910");
         cell = new UIP(type);
     } else if (uip && model.find("DE910") != string::npos) {
         type = Cellular::MTSMC_EV3_IP;
-        logDebug("radio model: DE910");
+        logDebug("UIP radio model: DE910");
         cell = new UIP(type);
     } else if (uip && model.find("CE910") != string::npos) {
         type = Cellular::MTSMC_C2_IP;
-        logDebug("radio model: CE910");
+        logDebug("UIP radio model: CE910");
         cell = new UIP(type);
-    
     } else if (model.find("HE910") != string::npos) {
         type = Cellular::MTSMC_H5;
         logDebug("radio model: HE910");
@@ -78,7 +75,6 @@
         type = Cellular::MTSMC_C2;
         logDebug("radio model: CE910");
         cell = new EasyIP(type);
-    
     } else {
         logError("cannot continue - could not determine radio type");
         return NULL;
--- a/Cellular/EasyIP.cpp	Tue Aug 05 18:35:22 2014 +0000
+++ b/Cellular/EasyIP.cpp	Mon Aug 11 16:03:19 2014 +0000
@@ -6,8 +6,6 @@
 
 using namespace mts;
 
-
-
 EasyIP::EasyIP(Radio type)
 {
     this->type = type;
@@ -46,7 +44,7 @@
     logDebug("radio type: %s", Cellular::getRadioNames(type).c_str());
     //Turns on the HW flow control
     if(sendBasicCommand("AT&K3", 2000) != MTS_SUCCESS) {
-        logWarning("Failed to set flow control to radio");
+        logWarning("Failed to enable serial flow control");
     }
     return true;
 }
@@ -62,21 +60,17 @@
     }
     
     //Check if socket is open
-    //flag stored in Cellular.h
     if(socketOpened) {
         return true;
     }
 
     //Check if already connected
-    //by calling the function isConnected() in EasyIP.cpp
     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();
@@ -89,7 +83,6 @@
     } while(tmr.read() < 30); 
     
     //Check RSSI: AT+CSQ
-    //Does the command inside Cellular
     tmr.reset();
     do {
         int rssi = getSignalStrength();
@@ -102,14 +95,12 @@
         }
     } while(tmr.read() < 30);
 
-    //Similar to AT#CONNECTIONSTART: Make a PPP connection
+    //Make PPP connection
     if (type == MTSMC_H5 || type == MTSMC_G3) {
         logDebug("Making PPP Connection Attempt. APN[%s]", apn.c_str());
     } else {
         logDebug("Making PPP Connection Attempt");
     }
-    //The main thing going on; Sends the AT command to start a connection
-    //Assuming context is already stored in the modem
     std::string pppResult = sendCommand("AT#SGACT=1,1", 5000);
     std::vector<std::string> parts;
     if(pppResult.find("OK") != std::string::npos) {
@@ -123,15 +114,12 @@
 
     } else {
         pppResult = sendCommand("AT#SGACT?", 2000);
-        if(pppResult.empty() || (pppResult.find("ERROR") != std::string::npos)) {
-            pppConnected = false;
+        if(pppResult.find("1,1") != std::string::npos) {
+           logDebug("Radio is already connected");
+           pppConnected = true;
         } else {
-            if(pppResult.find("1,1") != std::string::npos) {
-                logDebug("Radio is already connected");
-                pppConnected = true;
-            } else {
-                pppConnected = false;
-            }
+            logError("PPP connection attempt failed");
+            pppConnected = false;
         }
     }
 
@@ -140,32 +128,27 @@
 
 void EasyIP::disconnect()
 {
-    //AT#SGACT=1,0: Close a PPP connection
-    logDebug("Closing PPP Connection");    
-    if(socketOpened) {
-        if(!close()) { //Calls another EasyIP function to close socket before disconnect
-            logDebug("Failed to close socket for disconnect");
-            return; //Can't close connection without AT commands
-                    //(and thus need socket closed)
-        }
-    }
+    //AT#SGACT=1,0: Close PPP connection
+    logDebug("Closing PPP Connection"); 
     std::string result;
     Timer tmr;
+       
+    if(socketOpened) {
+        close();
+    }
+    
     //Sends AT#SGACT=1,0 command
     if (sendBasicCommand("AT#SGACT=1,0", 1000) == MTS_SUCCESS) {
-        pppConnected = false;
         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)
+    /* Ensure PPP link is down, else ping commands will put radio in unknown state
+     * (Link is not immediate in disconnection, even though OK is returned)
      */
     tmr.start();
     while(tmr.read() < 30) {
         result = sendCommand("AT#SGACT?", 1000);
         if(result.find("1,0") != std::string::npos) {
-            pppConnected = false;
             break;
         } else if(result.find("ERROR") != std::string::npos) {
             break;
@@ -174,19 +157,13 @@
         }
     }
     
-    //If still unable to close PPP connection, wait for 30 seconds to drop connection
-    if(pppConnected) {
-        wait(30);
-        pppConnected = false;
-    }
-    
+    pppConnected = false;
     return;
 }
 
 bool EasyIP::isConnected()
 {
-    std::string stateString;
-    std::vector<std::string> pieces;
+    enum RadioState {IDLE, CONNECTING, CONNECTED, DISCONNECTED};
     //state flags for various connection components
     bool signal = false, regist = false, active = false;
     
@@ -199,118 +176,70 @@
     }
     
     //2) Check that we do not have a live connection up
-    if(socketOpened) {
+    if (socketOpened) {
         logDebug("Socket is opened");
         return true;
     }
     
-    
     //3) Query the radio
-    //3.a) Check antenna signal
-    std::string reply = sendCommand("AT+CSQ", 500);
-    if(reply.empty() || (reply.find("ERROR") != std::string::npos)) {
+    int rssi = getSignalStrength();
+    if (rssi == 99 || rssi == -1) {
+        //Signal strength is nonexistent
         signal = false;
     } else {
-        pieces = Text::split(reply, "\r\n");
-        if(pieces.size() >= 2) {
-            pieces = Text::split(pieces[1], " ");
-            if(pieces.size() >= 2) {
-                if((pieces[1].find("0,0") != std::string::npos) || (pieces[1].find("99,99") != std::string::npos)) {
-                    signal = false;
-                } else {
-                    signal = true;
-                }
-            }
-        }
+        signal = true;
     }
     
-    //3.b) Check cell tower registration
-    reply = sendCommand("AT+CREG?", 500);
-    if(reply.empty() || (reply.find("ERROR") != std::string::npos)) {
-        regist = false;
+    Registration creg = getRegistration();
+    if (creg == REGISTERED) {
+        regist = true;
     } else {
-        pieces = Text::split(reply, "\r\n");
-        if(pieces.size() >= 2) {
-            pieces = Text::split(pieces[1], " ");
-            if(pieces.size() >= 2) {
-                if((pieces[1].find("0,1") != std::string::npos) || (pieces[1].find("0,5") != std::string::npos)) {
-                    regist = true; //1 for connected, 5 for roaming connected
-                } else {
-                    regist = false; //Cell tower not registered
-                }
-            }
-        }
+        regist = false;
     }
     
-    //3.c) Check active context (SGACT = 1,1)
-    reply = sendCommand("AT#SGACT?", 500);
-    if(reply.empty() || (reply.find("ERROR") != std::string::npos)) {
-        active = false;
+    string reply = sendCommand("AT#SGACT?", 500);
+    if (reply.find("1,1") != std::string::npos) {
+        active = true;
     } else {
-        pieces = Text::split(reply, "\r\n");
-        if(pieces.size() >= 2) {
-            pieces = Text::split(pieces[1], " ");
-            if(pieces.size() >= 2) {
-                if(pieces[1].find("1,1") != std::string::npos) {
-                    active = true; //1 for an active connection mode
-                } else {
-                    active = false; //0, or unknown value, is an inactive connection mode
-                }
-            }
-        }
+        active = false;
     }
-    //4) Determine radio state
-    if(regist && signal) {
-        if(pppConnected) {
-            if(active) {
-                if(ping()) {
-                    stateString = "CONNECTED";
-                    pppConnected = true;
-                } else {
-                    stateString = "AUTHENTICATING";
-                    pppConnected = true;
-                    return false; //Return false instead of changing pppConnected due to the fact
-                                  //that it is connected to ppp, it just can't ping successfully
-                }
-            } else {
-                stateString = "DISCONNECTING";
-                pppConnected = false;
-            }
-        } else {
-            if(active) {
-                if(ping()) {
-                    pppConnected = true;
-                    stateString = "CONNECTED";
-                } else {
-                    stateString = "CONNECTING";
-                }
-            } else {
-                stateString = "IDLE";
-            }
-        }
-    } else if(regist != signal) {
-        stateString = "CHECKING";
-        return false;
-    } else if(!regist && !signal) {
-        stateString = "DISCONNECTED";
+    
+    RadioState state;
+    bool ppp = pppConnected;
+    if (signal && regist && active) {
+        //Radio connected
+        state = CONNECTED;
+        pppConnected = true;
+    } else if (signal && !regist && !active) {
+        //Radio idle
+        state = IDLE;
+        pppConnected = false;
+    } else if (active) {
+        //Radio Connecting
+        state = CONNECTING;
+    } else {
+        //Radio Disconnected
+        state = DISCONNECTED;
         pppConnected = false;
     }
     
-    std::string pppStatus = pppConnected ? "CONNECTED" : "DISCONNECTED";
-    if(stateString != pppStatus) {
-        logDebug("Internal PPP state[%s], radio state[%s])",pppStatus.c_str() ,stateString.c_str());
+    if (!ppp && state == CONNECTED) {
+        logWarning("Internal PPP state tracking differs from radio (DISCONNECTED:CONNECTED)");
+    } else if (ppp && state != CONNECTED) {
+        logWarning("Internal PPP state tracking differs from radio (CONNECTED:%s)", state);
     }
+    
     return pppConnected;
 }
 
-//Resets the radio
 void EasyIP::reset()
 {
     disconnect();
+    
     if(sendBasicCommand("AT#REBOOT", 10000) != MTS_SUCCESS) {
-        logError("Socket Modem did not accept RESET command\n\r");
+        logError("Socket Modem did not accept RESET command");
     } else {
-        logWarning("Socket Modem is resetting, allow 30 seconds for it to come back\n\r");
+        logWarning("Socket Modem is resetting, allow 30 seconds for it to come back");
         return;
     }
 }
@@ -417,7 +346,7 @@
 bool EasyIP::isOpen()
 {
     if(io->readable()) {
-        logDebug("Assuming open, data available to read.\n\r");
+        logDebug("Assuming open, data available to read.");
         return true;
     }
     return socketOpened;
@@ -597,7 +526,7 @@
     if (address.compare("DHCP") == 0) {
         return true;
     } else {
-        logWarning("Radio does not support static IPs, using DHCP.\n\r");
+        logWarning("Radio does not support static IPs, using DHCP.");
         return false;
     }
 }
@@ -641,7 +570,6 @@
 {
     char buffer[256] = {0};
     std::vector<std::string> parts;
-    int pingsRec=0;
     int TTL=0;
     int Timeout=0;
     
@@ -650,12 +578,7 @@
     
     for(int pngs=0; pngs<PINGNUM; pngs++) {
         std::string response = sendCommand(buffer, (PINGDELAY*2000)); //Send 1 ping
-        wait(0.5); //Radio seems to get stuck if no wait is incurred between issuing ping commands
-                   //leads to unknown registration state eventually :(
-        if(response.empty()) {
-            continue; //Skip current loop if send command fails
-        }
-        if(response.find("ERROR") != std::string::npos) {
+        if(response.empty() || response.find("ERROR") != std::string::npos) {
             continue; //Skip current loop if send command fails
         }
         parts = Text::split(response, "\r\n");
@@ -671,12 +594,9 @@
         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;
 }
 
@@ -706,7 +626,8 @@
         return false;
     }
     if(!socketOpened) {
-        logError("Socket is not open. +++ Escape sequence should fail");
+        logError("Socket is not open.");
+        return false;
     }
     
     if(!socketCloseable) {
@@ -718,43 +639,40 @@
     io->txClear();
     
     std::string result;
-    unsigned int timeoutMillis = 10000; //time in ms
+    unsigned int timeoutMillis = 10000;
     //Attempt to write command
-    wait(1.2); //Format for +++ command is 1 second wait, send +++, then another second wait
-             //1s wait after command is implemented as a polling function for 2 seconds
-             //Option: Could change wait periods to be longer/shorter (0-255)*50ms
+    //Format for +++ command is 1 second wait, send +++, then another second wait
+    wait(1.2); 
     if(io->write("+++", 3, timeoutMillis) != 3) {
         //Failed to write command
         logError("failed to send command to radio within %d milliseconds", timeoutMillis);
         return false;
     }
     
-    int timer = 0;
+    Timer tmr;
     char tmp[256];
     tmp[255] = 0;
     bool done = false;
-    io->read(tmp,255,0);
     bool exitmode = false;
-    
+    tmr.start();
     do {
-        wait(0.1);
-        timer += 100;
         //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) {
-                result.append(tmp, size);
-            }
+        int size = io->read(tmp,255,0);    //1 less than allocated (timeout is instant)
+        if(size > 0) {
+            result.append(tmp, size);
+        }
         if(result.find("OK") != std::string::npos) {
             exitmode = true;
             done = true;
         } else if(result.find("NO CARRIER") != std::string::npos) {
+            socketOpened = false;
             exitmode = true;
             done = true;
         } else if(result.find("ERROR") != std::string::npos) {
             exitmode = false;
             done = true;
         }
-        if(timer >= timeoutMillis) {
+        if(tmr.read_ms() >= timeoutMillis) {
             logDebug("Escape sequence [+++] timed out after %d milliseconds", timeoutMillis);
             exitmode = true;
             done = true;
@@ -766,40 +684,37 @@
 
 bool EasyIP::socketCheck() {
     bool status = false;
-    std::string socketInfo = "9"; //9 is unrecognized
+    int socketInfo = 9; //error
+    enum SocketStatus {SOCKETCLOSED, SOCKETACTIVEDATA, SOCKETSUSPEND, SOCKETSUSPENDDATA, SOCKETLISTEN, SOCKETINCOMING, ERROR = 9};
     std::vector<std::string> params;
     
     //Goes from data mode to command mode
     if(sendEscapeCommand()) {
-        socketOpened = false;
-        if(sendBasicCommand("AT", 1000) == MTS_SUCCESS) {
-            socketInfo = sendCommand("AT#SS=1", 2000);
-            if(socketInfo.find("OK") != std::string::npos) {
-                //Found valid response
-                params = Text::split(socketInfo, "\r\n");
-                params = Text::split(params[1], ",");
-                socketInfo = params[1];
-                //Check comparison of params[1] to response codes
-            } else {
-                logError("Could not determine socket status[%s]",socketInfo.c_str());
-                socketInfo == "9"; //9 is unrecognized
-            }
+        std::string reply = sendCommand("AT#SS=1", 2000);
+        if(reply.find("OK") != std::string::npos) {
+            //Found valid response
+            params = Text::split(reply, "\r\n");
+            params = Text::split(params[1], ",");
+            socketInfo = atoi(params[1].c_str());
+        } else {
+            logError("Could not determine socket status[%d]",socketInfo);
+            socketInfo = 9; //9 is unrecognized
         }
     } else {
         status = false; //Return value of socketOpened when checking
     }
     
     //Check socket status query
-    if(socketInfo == "2" || socketInfo == "3" || socketInfo == "1" || socketInfo == "4") {
-        status = true; //2 and 3 are suspended connections
-    } else if(socketInfo == "0" || socketInfo == "5") {
-        status = false; //0 is closed socket, probably won't occur
+    if(socketInfo < 5 && socketInfo > 0) { //Socket opened responses
+        status = true;
+    } else if(socketInfo == SOCKETCLOSED || socketInfo == SOCKETINCOMING) {
+        status = false;
     } else {
         logError("Could not determine socket status");
-        status = false; //anything else is unknown status
+        status = false;
     }
     
-    //Reconnects to active socket if able
+    //Reconnect to active socket if able
     if(status) {
         std::string reconnect = sendCommand("AT#SO=1", 2000);
         if(reconnect.find("CONNECT") != std::string::npos || reconnect.find("OK") != std::string::npos) {
--- a/Cellular/EasyIP.h	Tue Aug 05 18:35:22 2014 +0000
+++ b/Cellular/EasyIP.h	Mon Aug 11 16:03:19 2014 +0000
@@ -1,5 +1,5 @@
-#ifndef SMC_H
-#define SMC_H
+#ifndef EASYIP_H
+#define EASYIP_H
 
 #include <string>
 #include <vector>
@@ -23,287 +23,7 @@
     * the mbed library.
     * The default baud rate for the cellular radio is 115200 bps.
     *
-    * @code
-    * #include "mbed.h"
-    * #include "mtsas.h"
-    * #include "TCPSocketConnection.h"
-    *
-    * int main(){
-    *   //Modify to match your apn if you are using an HSPA radio with a SIM card
-    *   const char APN[] = "";
-    *
-    *   //Sets the log level to INFO, which is about midway on priority levels
-    *   //Possible levels: FATAL, ERROR, WARNING, INFO, DEBUG, TRACE, NONE
-    *   MTSLog::setLogLevel(MTSLog::TRACE_LEVEL);
-    *
-    *   // STMicro Nucelo F401RE
-    *   // The supported jumper configurations of the MTSAS do not line up with
-    *   // the pin mapping of the Nucleo F401RE. Therefore, the MTSAS serial TX
-    *   // pin (JP8 Pin 2) must be manually jumped to Serial1 RX (Shield pin D2)
-    *   // and the MTSAS serial RX pin (JP9 Pin 2) pin must be manually jumped to
-    *   // Serial1 TX (Shield pin D8).
-    *   // Uncomment the following line to use the STMicro Nuceleo F401RE
-    *   MTSSerialFlowControl* io = new MTSSerialFlowControl(D8, D2, D3, D6);
-    *
-    *   // Freescale KL46Z
-    *   // To configure the pins for the Freescale KL46Z board, use configuration B
-    *   // for the SocketModem.
-    *   // Uncomment the following line to use the Freescale KL46Z board
-    *   // MTSSerialFlowControl* io = new MTSSerialFlowControl(D2, D9, D3, D6);
-    *
-    *   // Freescale KL64F
-    *   // To configure the pins for the Freescale KL46Z board, use configuration A
-    *   // for the SocketModem.
-    *   // Uncomment te following line to use the Freescale KL46F board
-    *   // MTSSerialFlowControl* io = new MTSSerialFlowControl(D1, D0, D3, D6);
-    *
-    *   // Sets the baudrate for communicating with the radio
-    *   io->baud(115200);
-    *
-    *   // Sets up the interfacing with the radio through the MTS library
-    *   Cellular* radio = CellularFactory::create(io);
-    *   radio->configureSignals(D4, D7, RESET);
-    *   Transport::setTransport(radio);
-    *
-    *   // Sets the APN on the device (if necessary)
-    *   for (int i = 0; i < 10; i++) {
-    *       if (i >= 10) {
-    *           logError("Failed to set APN to %s", APN);
-    *       }
-    *       if (radio->setApn(APN) == MTS_SUCCESS) {
-    *           logInfo("Successfully set APN to %s", APN);
-    *           break;
-    *       } else {
-    *           wait(1);
-    *       }
-    *   }
-    *
-    *   //Establish PPP link
-    *   for (int i = 0; i < 10; i++) {
-    *       if (i >= 10) {
-    *       logError("Failed to establish PPP link");
-    *       }
-    *       if (radio->connect() == true) {
-    *           logInfo("Successfully established PPP link");
-    *           break;
-    *       } else {
-    *           wait(1);
-    *       }
-    *   }
-    *
-    *   //Ping google.com (optional)
-    *   for (int i = 0; i < 10; i++) {
-    *       if (i >= 10) {
-    *           logError("Failed to ping www.google.com");
-    *       }
-    *       if (radio->ping("www.google.com") == true) {
-    *           logInfo("Successfully pinged www.google.com");
-    *           break;
-    *       } else {
-    *           wait(1);
-    *       }
-    *   }
-    *
-    *   //Used for packet verification from server's data response
-    *   const char PATTERN_LINE1[] = "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}|";
-    *   const char PATTERN[] = "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}|\r\n"
-    *                          "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}/\r\n"
-    *                          "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}-\r\n"
-    *                          "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}\\\r\n"
-    *                          "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}|\r\n"
-    *                          "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}/\r\n"
-    *                          "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}-\r\n"
-    *                          "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}\\\r\n"
-    *                          "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}*\r\n";
-    *   
-    *   const char MENU_LINE1[] = "send ascii pattern until keypress";
-    *   const char MENU[] = "1       send ascii pattern until keypress"
-    *                       "2       send ascii pattern (numbered)"
-    *                       "3       send pattern and close socket"
-    *                       "4       send [ETX] and wait for keypress"
-    *                       "5       send [DLE] and wait for keypress"
-    *                       "6       send all hex values (00-FF)"
-    *                       "q       quit"
-    *                       ">:";
-    *   
-    *   const char TCP_TEST_SERVER[] = "204.26.122.5";
-    *   const int TCP_TEST_PORT = 7000;
-    *   
-    *   //Creates TCP socket pointer instance
-    *   TCPSocketConnection* sock = new TCPSocketConnection();
-    *   //Turns off read_blocking and sets socket timeout to 2s
-    *   sock->set_blocking(false, 2);
-    *   
-    *   Timer tmr; //Used for timeouts
-    *   int bytesRead = 0; //Number of bytes read
-    *   const int readSize = 1024; //Size of buffer
-    *   char buffer[readSize] = {0}; //Read buffer
-    *   string result; //Result as a string
-    *   
-    *   //Open TCP socket
-    *   for (int i = 0; i < 5; i++) {
-    *       if (i >= 5) {
-    *           logError("Failed to open socket");
-    *       }
-    *       if (! sock->connect(TCP_TEST_SERVER, TCP_TEST_PORT)) {
-    *           logInfo("Opened TCP server");
-    *           break;
-    *       } else {
-    *           wait(1);
-    *       }
-    *   }
-    *   
-    *   //Waiting for menu from remote server
-    *   logInfo("Receiving Menu");
-    *   tmr.reset();
-    *   tmr.start();
-    *   do {
-    *       bytesRead = sock->receive(buffer, readSize);
-    *       if (bytesRead > 0) {
-    *           result.append(buffer, bytesRead);
-    *       }
-    *       logInfo("Total Bytes Read: %d", result.size());
-    *       if(result.find(MENU_LINE1) != std::string::npos) {
-    *           break;
-    *       }
-    *   } while(tmr.read() <= 40);
-    *   
-    *   wait(5);
-    *
-    *   logInfo("Received: [%d] [%s]", result.size(), result.c_str());
-    *
-    *   //Checking that menu was successfully received
-    *   size_t pos = result.find(MENU_LINE1);
-    *   if(pos != string::npos) {
-    *       logInfo("Found Menu 1st Line");
-    *   } else {
-    *       logError("Failed To Find Menu 1st Line");
-    *       sock->close();
-    *       return 0;
-    *   }
-    *
-    *   result.clear();
-    *
-    *   //Sends a response of '2' back to choose option 2 from the menu
-    *   logInfo("Writing To Socket: 2");
-    *   if(sock->send("2\r\n", 3) == 3) {
-    *       logInfo("Successfully Wrote '2'");
-    *   } else {
-    *       logError("Failed To Write '2'");
-    *       sock->close();
-    *       return 0;
-    *   }
-    *   logInfo("Expecting 'how many ? >:'");
-    *   tmr.reset();
-    *   tmr.start();
-    *   do {
-    *       bytesRead = sock->receive(buffer, readSize);
-    *       if (bytesRead > 0) {
-    *           result.append(buffer, bytesRead);
-    *       }
-    *       logInfo("Total Bytes Read: %d", result.size());
-    *       if(result.find("how many") != std::string::npos) {
-    *           break;
-    *       }
-    *   } while(tmr.read() <= 40);
-    *
-    *   logInfo("Received: [%d] [%s]", result.size(), result.c_str());
-    *
-    *   //Sends 2 to have the server send the pattern twice
-    *   if(result.find("how many") != std::string::npos) {
-    *       logInfo("Successfully Found 'how many'");
-    *       logInfo("Writing To Socket: 2");
-    *       if(sock->send("2\r\n", 3) == 3) {
-    *           logInfo("Successfully wrote '2'");
-    *       } else {
-    *           logError("Failed to write '2'");
-    *           sock->close();
-    *           return 0;
-    *       }
-    *   } else {
-    *       logError("didn't receive 'how many'");
-    *       sock->close();
-    *       return 0;
-    *   }
-    *
-    *   result.clear();
-    *
-    *   //Receives data from request sent to server
-    *   logInfo("Receiving Data");
-    *   tmr.reset();
-    *   tmr.start();
-    *   do {
-    *       bytesRead = sock->receive(buffer, readSize);
-    *       if (bytesRead > 0) {
-    *           result.append(buffer, bytesRead);
-    *       }
-    *       logInfo("Total Bytes Read: %d", result.size());
-    *       if(result.size() >= 1645) {
-    *           break;
-    *       }
-    *   } while(tmr.read() <= 40);
-    *
-    *   logInfo("Received Data: [%d] [%s]", result.size(), result.c_str());
-    *
-    *   //Compares received data with expected data
-    *   pos = result.find(PATTERN_LINE1);
-    *   if(pos != string::npos) {
-    *       int patternSize = sizeof(PATTERN) - 1;
-    *       const char* ptr = &result.data()[pos];
-    *       bool match = true;
-    *       for(int i = 0; i < patternSize; i++) {
-    *           if(PATTERN[i] != ptr[i]) {
-    *               logError("1st Pattern Doesn't Match At [%d]", i);
-    *               logError("Pattern [%02X]  Buffer [%02X]", PATTERN[i], ptr[i]);
-    *               match = false;
-    *               break;
-    *           }
-    *       }
-    *       if(match) {
-    *           logInfo("Found 1st Pattern");
-    *       } else {
-    *           logError("Failed To Find 1st Pattern");
-    *           sock->close();
-    *           return 0;
-    *       }
-    *
-    *       pos = result.find(PATTERN_LINE1, pos + patternSize);
-    *       if(pos != std::string::npos) {
-    *           ptr = &result.data()[pos];
-    *           match = true;
-    *           for(int i = 0; i < patternSize; i++) {
-    *               if(PATTERN[i] != ptr[i]) {
-    *                   logError("2nd Pattern Doesn't Match At [%d]", i);
-    *                   logError("Pattern [%02X]  Buffer [%02X]", PATTERN[i], ptr[i]);
-    *                   match = false;
-    *                   break;
-    *               }
-    *           }
-    *           if(match) {
-    *               logInfo("Found 2nd Pattern");
-    *           } else {
-    *               logError("Failed To Find 2nd Pattern");
-    *               sock->close();
-    *               return 0;
-    *           }
-    *       }
-    *   } else {
-    *       logError("Failed To Find Pattern 1st Line");
-    *       sock->close();
-    *       return 0;
-    *   }
-    *
-    *   //Clears the result, and closes the socket connection.
-    *   result.clear();
-    *   sock->close();
-    *   
-    *   //Disconnect ppp link
-    *   radio->disconnect();
-    *   
-    *   logInfo("End of example code");
-    *   return 0;
-    * }
-    * @endcode
+    * Example code is found under Cellular.h
     */
 class EasyIP : public Cellular
 {
@@ -371,7 +91,12 @@
     virtual int write(const char* data, int length, int timeout = -1);
     virtual unsigned int readable();
     virtual unsigned int writeable();
-    virtual bool ping(const std::string& address = "8.8.8.8"); //Google DNS server used as default ping address
+    
+    /** Pings specified DNS or IP address
+     * Google DNS server used as default ping address
+     * @returns true if ping received alive response else false
+     */
+    virtual bool ping(const std::string& address = "8.8.8.8"); 
     virtual std::string getDeviceIP();
     virtual bool setDeviceIP(std::string address = "DHCP");
     
@@ -434,4 +159,4 @@
 
 }
 
-#endif /* SMC_H */
+#endif /* EASYIP_H */
--- a/Cellular/UIP.cpp	Tue Aug 05 18:35:22 2014 +0000
+++ b/Cellular/UIP.cpp	Mon Aug 11 16:03:19 2014 +0000
@@ -46,6 +46,14 @@
 
 bool UIP::connect()
 {
+    //Check if APN is not set, if it is not, connect will not work.
+    if (type == MTSMC_H5_IP || type == MTSMC_H5 || type == MTSMC_G3) {
+        if(apn.size() == 0) {
+            logDebug("APN is not set");
+            return false;
+        }
+    }
+    
     //Check if socket is open
     if(socketOpened) {
         return true;
@@ -91,7 +99,6 @@
     }
     std::string pppResult = sendCommand("AT#CONNECTIONSTART", 120000);
     
-
     if(pppResult.find("Ok_Info_GprsActivation") != std::string::npos) {
         std::vector<std::string> parts = Text::split(pppResult, "\r\n");
         if(parts.size() >= 2) {
@@ -314,8 +321,6 @@
         return false;
     }
 
-
-
     if(io->write(ETX, 1000) != 1) {
         logError("Timed out attempting to close socket");
         return false;
--- a/Cellular/UIP.h	Tue Aug 05 18:35:22 2014 +0000
+++ b/Cellular/UIP.h	Mon Aug 11 16:03:19 2014 +0000
@@ -29,288 +29,6 @@
 * using GPIOs. To disable this you will need to change settings on the radio module and
 * and use the MTSSerial class instead of MTSSerialFlowControl. The default baud rate for the
 * cellular radio is 115200 bps.
-*
-* @code
-* #include "mbed.h"
-* #include "mtsas.h"
-* #include "TCPSocketConnection.h"
-*
-* int main(){
-*   //Modify to match your apn if you are using an HSPA radio with a SIM card
-*   const char APN[] = "";
-*
-*   //Sets the log level to INFO, which is about midway on priority levels
-*   //Possible levels: FATAL, ERROR, WARNING, INFO, DEBUG, TRACE, NONE
-*   MTSLog::setLogLevel(MTSLog::TRACE_LEVEL);
-*
-*   // STMicro Nucelo F401RE
-*   // The supported jumper configurations of the MTSAS do not line up with
-*   // the pin mapping of the Nucleo F401RE. Therefore, the MTSAS serial TX
-*   // pin (JP8 Pin 2) must be manually jumped to Serial1 RX (Shield pin D2)
-*   // and the MTSAS serial RX pin (JP9 Pin 2) pin must be manually jumped to
-*   // Serial1 TX (Shield pin D8).
-*   // Uncomment the following line to use the STMicro Nuceleo F401RE
-*   MTSSerialFlowControl* io = new MTSSerialFlowControl(D8, D2, D3, D6);
-*
-*   // Freescale KL46Z
-*   // To configure the pins for the Freescale KL46Z board, use configuration B
-*   // for the SocketModem.
-*   // Uncomment the following line to use the Freescale KL46Z board
-*   // MTSSerialFlowControl* io = new MTSSerialFlowControl(D2, D9, D3, D6);
-*
-*   // Freescale KL64F
-*   // To configure the pins for the Freescale KL46Z board, use configuration A
-*   // for the SocketModem.
-*   // Uncomment te following line to use the Freescale KL46F board
-*   // MTSSerialFlowControl* io = new MTSSerialFlowControl(D1, D0, D3, D6);
-*
-*   // Sets the baudrate for communicating with the radio
-*   io->baud(115200);
-*
-*   // Sets up the interfacing with the radio through the MTS library
-*   Cellular* radio = CellularFactory::create(io);
-*   radio->configureSignals(D4, D7, RESET);
-*   Transport::setTransport(radio);
-*
-*   // Sets the APN on the device (if necessary)
-*   for (int i = 0; i < 10; i++) {
-*       if (i >= 10) {
-*           logError("Failed to set APN to %s", APN);
-*       }
-*       if (radio->setApn(APN) == MTS_SUCCESS) {
-*           logInfo("Successfully set APN to %s", APN);
-*           break;
-*       } else {
-*           wait(1);
-*       }
-*   }
-*
-*   //Establish PPP link
-*   for (int i = 0; i < 10; i++) {
-*       if (i >= 10) {
-*       logError("Failed to establish PPP link");
-*       }
-*       if (radio->connect() == true) {
-*           logInfo("Successfully established PPP link");
-*           break;
-*       } else {
-*           wait(1);
-*       }
-*   }
-*
-*   //Ping google.com (optional)
-*   for (int i = 0; i < 10; i++) {
-*       if (i >= 10) {
-*           logError("Failed to ping www.google.com");
-*       }
-*       if (radio->ping("www.google.com") == true) {
-*           logInfo("Successfully pinged www.google.com");
-*           break;
-*       } else {
-*           wait(1);
-*       }
-*   }
-*
-*   //Used for packet verification from server's data response
-*   const char PATTERN_LINE1[] = "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}|";
-*   const char PATTERN[] = "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}|\r\n"
-*                          "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}/\r\n"
-*                          "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}-\r\n"
-*                          "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}\\\r\n"
-*                          "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}|\r\n"
-*                          "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}/\r\n"
-*                          "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}-\r\n"
-*                          "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}\\\r\n"
-*                          "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}*\r\n";
-*   
-*   const char MENU_LINE1[] = "send ascii pattern until keypress";
-*   const char MENU[] = "1       send ascii pattern until keypress"
-*                       "2       send ascii pattern (numbered)"
-*                       "3       send pattern and close socket"
-*                       "4       send [ETX] and wait for keypress"
-*                       "5       send [DLE] and wait for keypress"
-*                       "6       send all hex values (00-FF)"
-*                       "q       quit"
-*                       ">:";
-*   
-*   const char TCP_TEST_SERVER[] = "204.26.122.5";
-*   const int TCP_TEST_PORT = 7000;
-*   
-*   //Creates TCP socket pointer instance
-*   TCPSocketConnection* sock = new TCPSocketConnection();
-*   //Turns off read_blocking and sets socket timeout to 2s
-*   sock->set_blocking(false, 2);
-*   
-*   Timer tmr; //Used for timeouts
-*   int bytesRead = 0; //Number of bytes read
-*   const int readSize = 1024; //Size of buffer
-*   char buffer[readSize] = {0}; //Read buffer
-*   string result; //Result as a string
-*   
-*   //Open TCP socket
-*   for (int i = 0; i < 5; i++) {
-*       if (i >= 5) {
-*           logError("Failed to open socket");
-*       }
-*       if (! sock->connect(TCP_TEST_SERVER, TCP_TEST_PORT)) {
-*           logInfo("Opened TCP server");
-*           break;
-*       } else {
-*           wait(1);
-*       }
-*   }
-*   
-*   //Waiting for menu from remote server
-*   logInfo("Receiving Menu");
-*   tmr.reset();
-*   tmr.start();
-*   do {
-*       bytesRead = sock->receive(buffer, readSize);
-*       if (bytesRead > 0) {
-*           result.append(buffer, bytesRead);
-*       }
-*       logInfo("Total Bytes Read: %d", result.size());
-*       if(result.find(MENU_LINE1) != std::string::npos) {
-*           break;
-*       }
-*   } while(tmr.read() <= 40);
-*   
-*   wait(5);
-*
-*   logInfo("Received: [%d] [%s]", result.size(), result.c_str());
-*
-*   //Checking that menu was successfully received
-*   size_t pos = result.find(MENU_LINE1);
-*   if(pos != string::npos) {
-*       logInfo("Found Menu 1st Line");
-*   } else {
-*       logError("Failed To Find Menu 1st Line");
-*       sock->close();
-*       return 0;
-*   }
-*
-*   result.clear();
-*
-*   //Sends a response of '2' back to choose option 2 from the menu
-*   logInfo("Writing To Socket: 2");
-*   if(sock->send("2\r\n", 3) == 3) {
-*       logInfo("Successfully Wrote '2'");
-*   } else {
-*       logError("Failed To Write '2'");
-*       sock->close();
-*       return 0;
-*   }
-*   logInfo("Expecting 'how many ? >:'");
-*   tmr.reset();
-*   tmr.start();
-*   do {
-*       bytesRead = sock->receive(buffer, readSize);
-*       if (bytesRead > 0) {
-*           result.append(buffer, bytesRead);
-*       }
-*       logInfo("Total Bytes Read: %d", result.size());
-*       if(result.find("how many") != std::string::npos) {
-*           break;
-*       }
-*   } while(tmr.read() <= 40);
-*
-*   logInfo("Received: [%d] [%s]", result.size(), result.c_str());
-*
-*   //Sends 2 to have the server send the pattern twice
-*   if(result.find("how many") != std::string::npos) {
-*       logInfo("Successfully Found 'how many'");
-*       logInfo("Writing To Socket: 2");
-*       if(sock->send("2\r\n", 3) == 3) {
-*           logInfo("Successfully wrote '2'");
-*       } else {
-*           logError("Failed to write '2'");
-*           sock->close();
-*           return 0;
-*       }
-*   } else {
-*       logError("didn't receive 'how many'");
-*       sock->close();
-*       return 0;
-*   }
-*
-*   result.clear();
-*
-*   //Receives data from request sent to server
-*   logInfo("Receiving Data");
-*   tmr.reset();
-*   tmr.start();
-*   do {
-*       bytesRead = sock->receive(buffer, readSize);
-*       if (bytesRead > 0) {
-*           result.append(buffer, bytesRead);
-*       }
-*       logInfo("Total Bytes Read: %d", result.size());
-*       if(result.size() >= 1645) {
-*           break;
-*       }
-*   } while(tmr.read() <= 40);
-*
-*   logInfo("Received Data: [%d] [%s]", result.size(), result.c_str());
-*
-*   //Compares received data with expected data
-*   pos = result.find(PATTERN_LINE1);
-*   if(pos != string::npos) {
-*       int patternSize = sizeof(PATTERN) - 1;
-*       const char* ptr = &result.data()[pos];
-*       bool match = true;
-*       for(int i = 0; i < patternSize; i++) {
-*           if(PATTERN[i] != ptr[i]) {
-*               logError("1st Pattern Doesn't Match At [%d]", i);
-*               logError("Pattern [%02X]  Buffer [%02X]", PATTERN[i], ptr[i]);
-*               match = false;
-*               break;
-*           }
-*       }
-*       if(match) {
-*           logInfo("Found 1st Pattern");
-*       } else {
-*           logError("Failed To Find 1st Pattern");
-*           sock->close();
-*           return 0;
-*       }
-*
-*       pos = result.find(PATTERN_LINE1, pos + patternSize);
-*       if(pos != std::string::npos) {
-*           ptr = &result.data()[pos];
-*           match = true;
-*           for(int i = 0; i < patternSize; i++) {
-*               if(PATTERN[i] != ptr[i]) {
-*                   logError("2nd Pattern Doesn't Match At [%d]", i);
-*                   logError("Pattern [%02X]  Buffer [%02X]", PATTERN[i], ptr[i]);
-*                   match = false;
-*                   break;
-*               }
-*           }
-*           if(match) {
-*               logInfo("Found 2nd Pattern");
-*           } else {
-*               logError("Failed To Find 2nd Pattern");
-*               sock->close();
-*               return 0;
-*           }
-*       }
-*   } else {
-*       logError("Failed To Find Pattern 1st Line");
-*       sock->close();
-*       return 0;
-*   }
-*
-*   //Clears the result, and closes the socket connection.
-*   result.clear();
-*   sock->close();
-*   
-*   //Disconnect ppp link
-*   radio->disconnect();
-*   
-*   logInfo("End of example code");
-*   return 0;
-* }
-* @endcode
 */
 
 class UIP : public Cellular
--- a/Test/TestSMS.h	Tue Aug 05 18:35:22 2014 +0000
+++ b/Test/TestSMS.h	Mon Aug 11 16:03:19 2014 +0000
@@ -56,17 +56,8 @@
         }
     }
     
-    //For determining when the SIM card is ready
-    std::string result;
-    for (int i = 0; i < 25; i++) {
-        if (i >= 25) {
-            Test::assertTrue(false);
-        }
-        if(radio->sendBasicCommand("AT+CMGD=1,4", 1000) == MTS_SUCCESS) {
-            break;
-        }
-        wait(1);
-    }
+    //Wait until the SIM card is ready
+    while (radio->sendBasicCommand("AT+CMGD=1,4", 1000) != MTS_SUCCESS);
     
     Test::assertTrue(radio->deleteAllReceivedSms() == MTS_SUCCESS);
     Test::assertTrue(radio->getReceivedSms().size() == 0);
@@ -81,8 +72,8 @@
         }
         wait(1);
     }
-    //Response doesn't contain "My Number", and thus will always fail
-    //Code seems to not be the same for UIP versus EasyIP
+    
+    //Read phone number from radio
     if (response.find("+CNUM:") != string::npos) {
         parts = Text::split(response, ",");
         number = parts[1];