Simple detection for LE910-NA1 modules
Fork of MTS-Cellular by
Diff: Cellular/Cellular.cpp
- Revision:
- 52:2cb58398a4f9
- Parent:
- 51:ffc556ba33f7
- Child:
- 55:85c04afa939a
--- 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; }