summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrandon Bayer <bbayer@multitech.com>2016-03-15 14:44:14 -0500
committerBrandon Bayer <bbayer@multitech.com>2016-03-16 11:39:41 -0500
commita07abd74684cdbd6413cd4489627a236018725c8 (patch)
tree7d28f6f27d8a72add42e8805c14f2f33246205cb /src
parent57f3714c9ae1287e842fa32f14832d3e4d15e96d (diff)
downloadlibmts-io-a07abd74684cdbd6413cd4489627a236018725c8.tar.gz
libmts-io-a07abd74684cdbd6413cd4489627a236018725c8.tar.bz2
libmts-io-a07abd74684cdbd6413cd4489627a236018725c8.zip
fix: set CGREG back to original setting instead of 00.3
Diffstat (limited to 'src')
-rw-r--r--src/MTS_IO_CellularRadio.cpp72
1 files changed, 49 insertions, 23 deletions
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<std::string> 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<std::string> 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;