From a07abd74684cdbd6413cd4489627a236018725c8 Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Tue, 15 Mar 2016 14:44:14 -0500 Subject: fix: set CGREG back to original setting instead of 0 --- src/MTS_IO_CellularRadio.cpp | 72 ++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index 7234a98..6954368 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -1046,29 +1046,7 @@ CellularRadio::CODE CellularRadio::getNetworkStatus(Json::Value& jData) { RadioBandMap radioBandMap(vParts[1], CellularRadio::VALUE_TYPE_LTE); jData[KEY_ABND] = radioBandMap.getRadioBandName(); - // Get the LAC for the LTE radio that's not in the #RFSTS response - // Temporarily set CGREG=2 to get more info - sCmd = "AT+CGREG=2"; - sResult = sendCommand(sCmd); - if (sResult.find("OK") == std::string::npos) { - printDebug("%s| AT#CGREG=2 returned unexpected response: [%s][%s]", m_sName.c_str(), sCmd.c_str(), sResult.c_str()); - } - sCmd = "AT+CGREG?"; - sResult = sendCommand(sCmd); - if (sResult.find("+CGREG:") == std::string::npos) { - printDebug("%s| AT#CGREG? returned unexpected response: [%s][%s]", m_sName.c_str(), sCmd.c_str(), sResult.c_str()); - jData[KEY_LAC] = CellularRadio::VALUE_UNKNOWN; - } else { - size_t start = sResult.find(":") + 1; //Position right after "#RFSTS:" - std::vector vParts = MTS::Text::split(MTS::Text::trim(sResult.substr(start)), ","); - jData[KEY_LAC] = MTS::Text::strip(vParts[2], '"'); - } - // Revert CGREG to default - sCmd = "AT+CGREG=0"; - sResult = sendCommand(sCmd); - if (sResult.find("OK") == std::string::npos) { - printDebug("%s| AT#CGREG=0 returned unexpected response: [%s][%s]", m_sName.c_str(), sCmd.c_str(), sResult.c_str()); - } + jData[KEY_LAC] = queryLteLac(); if(MTS::Text::parse(iValue, vParts[14]) && convertServiceDomainToString((SERVICEDOMAIN)iValue, sValue) == SUCCESS) { jDebug[KEY_SD] = sValue; @@ -1084,6 +1062,54 @@ CellularRadio::CODE CellularRadio::getNetworkStatus(Json::Value& jData) { return SUCCESS; } +// Get the LAC for the LTE radio that's not in the #RFSTS response +std::string CellularRadio::queryLteLac() { + std::string CGREGstring; + std::string originalCGREG; + std::string result; + + CGREGstring = queryCGREGstring(); + if (CGREGstring == RSP_ERROR) { + originalCGREG = "0"; + } else { + originalCGREG = CGREGstring.at(CGREGstring.find(",") - 1); //Position right before first comma ("+CGREG: 0,1") + } + + // Temporarily set CGREG=2 to get more info + setCGREG("2"); + + CGREGstring = queryCGREGstring(); + if (CGREGstring == RSP_ERROR) { + result = CellularRadio::VALUE_UNKNOWN; + } else { + size_t start = CGREGstring.find(":") + 1; //Position right after "#RFSTS:" + std::vector vParts = MTS::Text::split(MTS::Text::trim(CGREGstring.substr(start)), ","); + result = MTS::Text::strip(vParts[2], '"'); + } + + setCGREG(originalCGREG); + + return result; +} + +void CellularRadio::setCGREG(std::string value) { + std::string sCmd("AT+CGREG=" + value); + std::string cmdResult(sendCommand(sCmd)); + if (cmdResult.find("OK") == std::string::npos) { + printDebug("%s| AT#CGREG=%s returned unexpected response: [%s][%s]", m_sName.c_str(), value.c_str(), sCmd.c_str(), cmdResult.c_str()); + } +} + +std::string CellularRadio::queryCGREGstring() { + std::string sCmd("AT+CGREG?"); + std::string cmdResult(sendCommand(sCmd)); + if (cmdResult.find("+CGREG:") == std::string::npos) { + printDebug("%s| AT#CGREG? returned unexpected response: [%s][%s]", m_sName.c_str(), sCmd.c_str(), cmdResult.c_str()); + return RSP_ERROR; + } + return cmdResult; +} + void CellularRadio::getCommonNetworkStats(Json::Value& jData) { bool bRoaming = false; -- cgit v1.2.3