summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrii Pientsov <andrii.pientsov@globallogic.com>2020-02-13 15:59:34 +0200
committerMykyta Dorokhin <mykyta.dorokhin@globallogic.com>2020-02-13 16:57:01 +0200
commit24310f73209b97dd805d09dcaa504d02740d1c23 (patch)
treea0d3033fae481fd3393bae759fe76b8ad2fe805f /src
parent53f54b1929d08869494d1f724814cd7ae77820f5 (diff)
downloadlibmts-io-24310f73209b97dd805d09dcaa504d02740d1c23.tar.gz
libmts-io-24310f73209b97dd805d09dcaa504d02740d1c23.tar.bz2
libmts-io-24310f73209b97dd805d09dcaa504d02740d1c23.zip
Commands CREG, CGREG and CEREG should be utilized to get registered status
Diffstat (limited to 'src')
-rw-r--r--src/MTS_IO_CellularRadio.cpp80
-rw-r--r--src/MTS_IO_EG95Radio.cpp71
2 files changed, 59 insertions, 92 deletions
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;
-}