diff options
author | Brandon Bayer <bbayer@multitech.com> | 2016-05-19 14:27:07 -0500 |
---|---|---|
committer | Brandon Bayer <bbayer@multitech.com> | 2016-05-19 14:27:07 -0500 |
commit | 7953fdc639605461bacb6abe2487c66cd7e25a37 (patch) | |
tree | 0fede96ceaf3e73d169fa833d57d15ff0324c2de /src | |
parent | 4df714d95f33006ee1d38b6719e3548b98355984 (diff) | |
download | libmts-io-7953fdc639605461bacb6abe2487c66cd7e25a37.tar.gz libmts-io-7953fdc639605461bacb6abe2487c66cd7e25a37.tar.bz2 libmts-io-7953fdc639605461bacb6abe2487c66cd7e25a37.zip |
refactor: getCommonNetworkStats before AT#RFSTS0.7
This allows the basic stats like time & rssi to be returned even if
AT#RFSTS fails like it does for LTE radios without a signal
Diffstat (limited to 'src')
-rw-r--r-- | src/MTS_IO_CellularRadio.cpp | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index cb1a59c..5f4966d 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -937,6 +937,10 @@ CellularRadio::CODE CellularRadio::getNetworkStatus(Json::Value& jData) { printTrace("%s| Get Network Status", m_sName.c_str()); + //Always get common network stats because this should never fail + //This way the basic stats are always returned even if AT#RFSTS fails below + getCommonNetworkStats(jData); + std::string sCmd; std::string sResult; // LE910 radios have a bug where issuing AT#RFSTS with a locked SIM @@ -947,35 +951,33 @@ CellularRadio::CODE CellularRadio::getNetworkStatus(Json::Value& jData) { sResult = sendCommand(sCmd); if (sResult.find("+CPIN:") == std::string::npos) { printDebug("%s| AT+CPIN? returned unexpected response: [%s][%s]", m_sName.c_str(), sCmd.c_str(), sResult.c_str()); - return FAILURE; + printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); + return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function } if (sResult.find("SIM PIN") != std::string::npos) { printError("%s| The SIM is locked and must first be unlocked", m_sName.c_str()); - return FAILURE; + printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); + return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function } } sCmd = "AT#RFSTS"; sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 200); if (sResult.find("#RFSTS:") == std::string::npos) { + //On LTE radios without signal, this case will run because AT#RFSTS just returns "OK" printDebug("%s| Network Status command returned unexpected response: [%s][%s]", m_sName.c_str(), sCmd.c_str(), sResult.c_str()); - - if (sResult.find(CellularRadio::RSP_OK) < 3) { - //Command returns only "OK". Actual response is usually "\r\nOK", so check index < 3 - //This will happen when LTE radios don't have a signal - //Since AT#RFSTS failed, just get common network stats and return - //This will update RSSI which'll show that signal is gone - getCommonNetworkStats(jData); - printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); - return SUCCESS; - } - return FAILURE; + printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); + return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function } size_t start = sResult.find(":") + 1; //Position right after "#RFSTS:" std::vector<std::string> vParts = MTS::Text::split(MTS::Text::trim(sResult.substr(start)), ","); - if(vParts.size() >= 3) { + if (vParts.size() < 3) { + printDebug("%s| Network Status command reponse is an unknown format: [%s][%s]", m_sName.c_str(), sCmd.c_str(), sResult.c_str()); + printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); + return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function + } else { //Country Code and Operator Code std::vector<std::string> vPLMN = MTS::Text::split(vParts[0], ' '); if(vPLMN.size() == 2) { @@ -984,12 +986,9 @@ CellularRadio::CODE CellularRadio::getNetworkStatus(Json::Value& jData) { } jData[KEY_CHANNEL] = vParts[1]; - } else { - //Unknown Format - return FAILURE; } - if(vParts.size() == GSM_NETWORK_FORMAT ) { + if (vParts.size() == GSM_NETWORK_FORMAT ) { //Parse as GSM Network Format jData[KEY_RSSIDBM] = vParts[2]; jData[KEY_LAC] = vParts[3]; @@ -1084,10 +1083,7 @@ CellularRadio::CODE CellularRadio::getNetworkStatus(Json::Value& jData) { jData[KEY_DEBUG] = jDebug; } - getCommonNetworkStats(jData); - printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); - return SUCCESS; } |