Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MTS-Cellular by
Diff: Cellular/EasyIP.cpp
- Revision:
- 28:f93d7b3f7c2e
- Parent:
- 27:ec44d5a9544f
- Child:
- 29:edc613ed3f2e
diff -r ec44d5a9544f -r f93d7b3f7c2e Cellular/EasyIP.cpp --- a/Cellular/EasyIP.cpp Mon Jun 30 17:13:00 2014 +0000 +++ b/Cellular/EasyIP.cpp Tue Jul 01 19:50:39 2014 +0000 @@ -126,21 +126,25 @@ void EasyIP::disconnect() { + bool complete = false; + Timer dctmr; //AT#SGACT=1,0: Close a PPP connection - logDebug("Closing PPP Connection"); - + logDebug("Closing PPP Connection"); if(socketOpened) { close(); //Calls another EasyIP //function to close socket before disconnect } //Sends AT#SGACT=1,0 command - - if(sendBasicCommand("AT#SGACT=1,0", 10000) == MTS_SUCCESS) { - logDebug("Successfully closed PPP Connection"); - } else { - logError("Closing PPP Connection. Continuing ..."); - } - pppConnected = false; //We can do this since the cell will drop their side after timeout + dctmr.start(); + do { + if(sendBasicCommand("AT#SGACT=1,0", 10000) == MTS_SUCCESS) { + complete = true; + } else { + wait(0.050); + } + } while((!complete) && (dctmr.read() < 5)); + logDebug("Successfully closed PPP Connection"); + pppConnected = false; //Cell will drop connection if we go silent } bool EasyIP::isConnected() @@ -259,13 +263,29 @@ int Timeout=0; //Format parameters for sending to radio - sprintf(buffer, "AT#PING=%s,1,32,%d", address.c_str(), (10*PINGDELAY)); + sprintf(buffer, "AT#PING=%s,1,32,%d", address.c_str(), (5*PINGDELAY)); 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 + std::string response = sendCommand(buffer, (PINGDELAY*1000)); //Send 1 ping + //printf("Response [%s]\n", response.c_str()); //remove + if(response.empty()) { + //printf("Response empty!\n"); //remove + continue; //Skip current loop if send command fails + } + if(response.find("ERROR") != std::string::npos) { + //printf("ERROR found\n"); //remove + continue; //Skip current loop if send command fails + } parts = Text::split(response, "\r\n"); + if(parts.size() < 2) { + //printf("Response newline-split size %d\n", parts.size()); //remove + continue; + } parts = Text::split(parts[1], ","); + if(parts.size() < 4) { + //printf("Response comma-split size %d\n", parts.size()); //remove + continue; + } //Parse TTL and Timeout values Timeout = std::atoi(parts[2].c_str()); TTL = std::atoi(parts[3].c_str());