diff options
-rw-r--r-- | include/mts/MTS_IO_EG95Radio.h | 1 | ||||
-rw-r--r-- | src/MTS_IO_EG95Radio.cpp | 71 |
2 files changed, 72 insertions, 0 deletions
diff --git a/include/mts/MTS_IO_EG95Radio.h b/include/mts/MTS_IO_EG95Radio.h index 5296e16..5c093db 100644 --- a/include/mts/MTS_IO_EG95Radio.h +++ b/include/mts/MTS_IO_EG95Radio.h @@ -41,6 +41,7 @@ namespace MTS { private: CODE getSupportedCellularModes(CELLULAR_MODES &networks) override; CODE setCellularMode(CELLULAR_MODES networks) override; + CODE getRegistration(REGISTRATION& eRegistration) override; }; } } diff --git a/src/MTS_IO_EG95Radio.cpp b/src/MTS_IO_EG95Radio.cpp index f1c040a..cdd750e 100644 --- a/src/MTS_IO_EG95Radio.cpp +++ b/src/MTS_IO_EG95Radio.cpp @@ -87,3 +87,74 @@ ICellularRadio::CODE EG95Radio::setCellularMode(CELLULAR_MODES networks) { } return SUCCESS; } + +ICellularRadio::REGISTRATION parseRegResponse(std::string sResult) +{ + size_t start = sResult.find(','); + size_t stop = sResult.find(' ', start); + std::string sRegStat = sResult.substr(start + 1, stop - start - 1); + int32_t value; + sscanf(sRegStat.c_str(), "%d", &value); + + return (ICellularRadio::REGISTRATION)value; +} + +ICellularRadio::CODE EG95Radio::getRegistration(REGISTRATION& eRegistration) { + std::string sCmd; + std::string sResp; + + // On the EG95 we need to check CREG, CGREG, and CEREG for possible success. + // Depending on the carrier, roaming, and some other factors the registration + // will come back differently depending on the type of connection that is possible. + + sCmd = "AT+CREG?"; + sResp = "+CREG: "; + std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 5000); + if (sResult.find(sResp) == std::string::npos) { + if(sResult.size() == 0) { + printDebug("%s| Registration command returned no response: [EG95]"); + } + printDebug("%s| Registration command returned unexpected response: [EG95]"); + } + + eRegistration = parseRegResponse(sResult); + if (eRegistration == REGISTERED) { + return SUCCESS; + } + + + sCmd = "AT+CGREG?"; + sResp = "+CGREG: "; + sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 5000); + if (sResult.find(sResp) == std::string::npos) { + if(sResult.size() == 0) { + printDebug("%s| Registration command returned no response: [EG95]"); + } + printDebug("%s| Registration command returned unexpected response: [EG95]"); + } + + + eRegistration = parseRegResponse(sResult); + if (eRegistration == REGISTERED) { + return SUCCESS; + } + + sCmd = "AT+CEREG?"; + sResp = "+CEREG: "; + sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 5000); + if (sResult.find(sResp) == std::string::npos) { + if(sResult.size() == 0) { + printDebug("%s| Registration command returned no response: [EG95]"); + return NO_RESPONSE; + } + printDebug("%s| Registration command returned unexpected response: [EG95]"); + return FAILURE; + } + + eRegistration = parseRegResponse(sResult); + if (eRegistration == REGISTERED) { + return SUCCESS; + } + + return SUCCESS; +} |