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/Cellular.cpp
- Revision:
- 41:8b9b5098696f
- Parent:
- 38:b2088faa8bfd
- Child:
- 45:b9ead235ab7c
--- a/Cellular/Cellular.cpp Tue Jul 29 19:39:01 2014 +0000 +++ b/Cellular/Cellular.cpp Wed Jul 30 20:22:23 2014 +0000 @@ -197,43 +197,48 @@ return ""; } } - int time_done = 0; - //Time in 100s of milliseconds maximum between character transmissions - const int MAX_INPUT_DELAY = 2; - int timer = 0; - size_t previous = 0; + mbed::Timer tmr; char tmp[256]; tmp[255] = 0; - bool started = !echoMode; bool done = false; + tmr.start(); do { - wait(0.1); - timer += 100; + wait(0.05); - previous = result.size(); //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); } - if(!started) { - //In Echo Mode (Command will have echo'd + 2 characters for \r\n) - if(result.size() > command.size() + 2) { - started = true; - } - } else { - //Uses an timer to make sure no characters are received - //within a period of time after the last recevied character. - if(result.size() == previous) { - time_done++; - if(time_done > MAX_INPUT_DELAY) { - done = true; - } - } else { - time_done = 0; + + //If there is a response, check that the response is not finished with a response code + //OK, ERROR, CONNECT are the 3 most likely responses + if(result.size() > (command.size() + 2)) { + if(result.find("OK") != std::string::npos) { + //Found OK + done = true; + } else if(result.find("ERROR") != std::string::npos) { + //Found ERROR + done = true; + } else if(result.find("CONNECT") != std::string::npos) { + //Found CONNECT] + ////Could add socketOpened flag check here if CONNECT is found + done = true; + } else if(result.find("NO CARRIER") != std::string::npos) { + //Found NO CARRIER + done = true; + } else if(result.find("RING") != std::string::npos) { + done = true; + } else if(result.find("NO DIALTONE") != std::string::npos) { + done = true; + } else if(result.find("BUSY") != std::string::npos) { + done = true; + } else if(result.find("NO ANSWER") != std::string::npos) { + done = true; } } - if(timer >= timeoutMillis) { + + if(tmr.read_ms() >= timeoutMillis) { if (command != "AT" && command != "at") { logWarning("sendCommand [%s] timed out after %d milliseconds", command.c_str(), timeoutMillis); }