summaryrefslogtreecommitdiff
path: root/src/MTS_IO_CellularRadio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/MTS_IO_CellularRadio.cpp')
-rw-r--r--src/MTS_IO_CellularRadio.cpp122
1 files changed, 101 insertions, 21 deletions
diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp
index 6f45da4..50fdf5c 100644
--- a/src/MTS_IO_CellularRadio.cpp
+++ b/src/MTS_IO_CellularRadio.cpp
@@ -306,7 +306,7 @@ ICellularRadio::CODE CellularRadio::getSimStatusSummary(Json::Value& jData) {
}
if (!bIsSimInserted) {
- // There is no left much to do. Return one field only.
+ // There is not much left to do. Return one field only.
jData[KEY_IS_SIM_INSERTED] = bIsSimInserted;
break;
}
@@ -314,6 +314,16 @@ ICellularRadio::CODE CellularRadio::getSimStatusSummary(Json::Value& jData) {
// The following code assumes that the SIM card is inserted
retCode = getSimLockStatus(sSimLockStatus);
if (retCode != SUCCESS) {
+ /* IN:4033:
+ *
+ * On some devices #SIMDET reports "inserted" but +CPIN? returns ERROR when there is
+ * no SIM card in the slot. It's also the case when only plastic holder is inserted
+ * instead of the SIM itself.
+ *
+ * Interpret this error as "SIM card not detected" for such cases.
+ */
+ jData[KEY_IS_SIM_INSERTED] = false;
+ retCode = SUCCESS;
break;
}
@@ -694,6 +704,14 @@ void CellularRadio::getCommonNetworkStats(Json::Value& jData) {
jData[ICellularRadio::KEY_NETWORK_REG] = sNetworkReg;
}
}
+
+ std::string sCurrentCellMode;
+ CELLULAR_MODES eModes;
+ if (getCellularMode(eModes) == SUCCESS) {
+ if (convertCellModesToString(eModes, sCurrentCellMode) == SUCCESS) {
+ jData[ICellularRadio::KEY_CELL_MODE] = sCurrentCellMode;
+ }
+ }
}
ICellularRadio::CODE CellularRadio::getSimLockStatus(std::string& sData)
@@ -736,41 +754,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;
+const std::vector<std::string> CellularRadio::getRegistrationCommands() {
+ std::string sType;
+ convertModelToType(getName(), sType);
- // 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: ";
+ 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?");
@@ -813,6 +869,30 @@ ICellularRadio::CODE CellularRadio::convertRegistrationToString(REGISTRATION eRe
return eCode;
}
+ICellularRadio::CODE CellularRadio::convertCellModesToString(ICellularRadio::CELLULAR_MODES eCellModes, std::string& sCellModes) {
+ std::string sResult;
+
+ if (eCellModes & CELLULAR_MODE_2G) {
+ sResult += "2g,";
+ }
+ if (eCellModes & CELLULAR_MODE_3G) {
+ sResult += "3g,";
+ }
+ if (eCellModes & CELLULAR_MODE_4G) {
+ sResult += "4g,";
+ }
+ if (eCellModes & CELLULAR_MODE_5G) {
+ sResult += "5g,";
+ }
+
+ if (!sResult.empty()) {
+ sResult.pop_back(); // remove trailing comma
+ }
+
+ sCellModes = sResult;
+ return SUCCESS;
+}
+
ICellularRadio::CODE CellularRadio::unlockSimCard(const Json::Value& jArgs) {
printTrace("%s| Unlock the SIM card using PIN code", m_sName.c_str());