diff options
author | Jeff Hatch <jhatch@multitech.com> | 2020-02-13 11:53:55 -0600 |
---|---|---|
committer | Jeff Hatch <jhatch@multitech.com> | 2020-02-13 11:53:55 -0600 |
commit | f3425f9f5b32060895b7cd33d337b7ac50f9e714 (patch) | |
tree | a0d3033fae481fd3393bae759fe76b8ad2fe805f | |
parent | 53f54b1929d08869494d1f724814cd7ae77820f5 (diff) | |
parent | 24310f73209b97dd805d09dcaa504d02740d1c23 (diff) | |
download | libmts-io-f3425f9f5b32060895b7cd33d337b7ac50f9e714.tar.gz libmts-io-f3425f9f5b32060895b7cd33d337b7ac50f9e714.tar.bz2 libmts-io-f3425f9f5b32060895b7cd33d337b7ac50f9e714.zip |
Merge branch 'CREG_CGREG_CEREG' into 'master'
Commands CREG, CGREG and CEREG should be utilized to get registered status
See merge request !9
-rw-r--r-- | include/mts/MTS_IO_CellularRadio.h | 4 | ||||
-rw-r--r-- | include/mts/MTS_IO_EG95Radio.h | 1 | ||||
-rw-r--r-- | src/MTS_IO_CellularRadio.cpp | 80 | ||||
-rw-r--r-- | src/MTS_IO_EG95Radio.cpp | 71 |
4 files changed, 63 insertions, 93 deletions
diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index 1e80274..4b53382 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -168,6 +168,10 @@ namespace MTS { virtual std::string queryCGREGstring(); virtual void setCGREG(std::string value); + const std::vector<std::string> getRegistrationCommands(); + REGISTRATION parseRegResponse(std::string sResult); + CODE getRegistration(REGISTRATION& eRegistration, const std::string& sType); + class RadioBandMap : public MTS::NonCopyable { public: RadioBandMap() diff --git a/include/mts/MTS_IO_EG95Radio.h b/include/mts/MTS_IO_EG95Radio.h index 5c093db..5296e16 100644 --- a/include/mts/MTS_IO_EG95Radio.h +++ b/include/mts/MTS_IO_EG95Radio.h @@ -41,7 +41,6 @@ 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_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index 6f45da4..8bdd00e 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -736,41 +736,79 @@ void CellularRadio::initMipProfile(Json::Value& jData) { jData[ICellularRadio::KEY_MIP_MNHASS] = false; } -ICellularRadio::CODE CellularRadio::getRegistration(REGISTRATION& eRegistration) { - std::string sCmd; - std::string sResp; - - // LE910C1-NS is an LE910, so we stop the scan after the 0. - // NOTE: Eventually this may need to be changed to try all three of CREG, CGREG, and CEREG - if ((m_sName.find("LE910") != std::string::npos) || (m_sName.find("ME910") != std::string::npos)) { - // use AT+CGREG instead for LE910 models - sCmd = "AT+CGREG?"; - sResp = "+CGREG: "; - } - else { - sCmd = "AT+CREG?"; - sResp = "+CREG: "; +const std::vector<std::string> CellularRadio::getRegistrationCommands() { + std::string sType; + convertModelToType(getName(), sType); + + if (sType == VALUE_TYPE_LTE) { + return { "CREG", "CGREG", "CEREG" }; + } else { + return { "CREG", "CGREG" }; } +} + +ICellularRadio::REGISTRATION CellularRadio::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 CellularRadio::getRegistration(REGISTRATION& eRegistration, const std::string& sType) { + std::string sCmd = "AT+" + sType + "?"; + std::string sResp = "+" + sType + ": "; 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: [%s]", m_sName.c_str()); + printDebug("%s| Registration command returned no response", m_sName.c_str()); return NO_RESPONSE; } printDebug("%s| Registration command returned unexpected response: [%s]", m_sName.c_str(), sResult.c_str()); return FAILURE; } - 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); - eRegistration = (REGISTRATION)value; + eRegistration = parseRegResponse(sResult); return SUCCESS; } +ICellularRadio::CODE CellularRadio::getRegistration(REGISTRATION& eRegistration) { + /* REGISTRATION_PRIORITY: + * REGISTERED = 0 + * ROAMING = 1 + * DENIED = 2 + * SEARCHING = 3 + * NOT_REGISTERED = 4 + * UNKNOWN = 5 + */ + uint8_t uRegPriority[] = { 4, 0, 3, 2, 5, 1 }; + ICellularRadio::CODE ret = ERROR; + REGISTRATION eReg = UNKNOWN; + eRegistration = UNKNOWN; + + // We need to check CREG, CGREG, and CEREG for possible success. + // Depending on the radio, carrier, roaming, sim card, cellular mode and some other factors the registration + // will come back differently depending on the type of connection that is possible. + + const auto & commands = getRegistrationCommands(); + for (const auto & cmd : commands) { + ret = getRegistration(eReg, cmd); + if (ret != SUCCESS) { + break; + } + + if (eReg == REGISTERED || eReg == ROAMING) { + eRegistration = eReg; + break; + } + eRegistration = (uRegPriority[eRegistration] > uRegPriority[eReg]) ? eReg : eRegistration; + } + + return ret; +} + ICellularRadio::CODE CellularRadio::getCellularMode(CELLULAR_MODES &networks) { networks = CELLULAR_MODE_NA; std::string cmdResult = sendCommand("AT+COPS?"); diff --git a/src/MTS_IO_EG95Radio.cpp b/src/MTS_IO_EG95Radio.cpp index cdd750e..f1c040a 100644 --- a/src/MTS_IO_EG95Radio.cpp +++ b/src/MTS_IO_EG95Radio.cpp @@ -87,74 +87,3 @@ 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; -} |