diff options
-rw-r--r-- | include/mts/MTS_IO_QuectelRadio.h | 3 | ||||
-rw-r--r-- | src/MTS_IO_QuectelRadio.cpp | 79 |
2 files changed, 82 insertions, 0 deletions
diff --git a/include/mts/MTS_IO_QuectelRadio.h b/include/mts/MTS_IO_QuectelRadio.h index b486323..81da1ce 100644 --- a/include/mts/MTS_IO_QuectelRadio.h +++ b/include/mts/MTS_IO_QuectelRadio.h @@ -48,6 +48,9 @@ namespace MTS { bool getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier) override; bool getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware) override; + CODE getIsSimInserted(bool& bData) override; + CODE getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk) override; + virtual CODE getServiceDomain(SERVICEDOMAIN& sd); virtual CODE convertToActiveBand(const std::string& sQuectelBand, ACTIVEBAND& band); diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 2f3c9b5..0a054ff 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -478,6 +478,85 @@ bool QuectelRadio::getHardwareVersionFromFirmware(const std::string& sFirmware, return false; } +CellularRadio::CODE QuectelRadio::getIsSimInserted(bool& bData) { + printTrace("%s| Get SIM insertion status", getName().c_str()); + std::string sCmd("AT+QSIMSTAT?"); + std::string sResult = sendCommand(sCmd); + + const std::string sPrefix = "+QSIMSTAT: "; + size_t start = sResult.find(sPrefix); + size_t end = sResult.rfind(ICellularRadio::RSP_OK); + + if (end == std::string::npos) { + printWarning("%s| Unable to get SIM insertion status from radio using command [%s]", getName().c_str(), sCmd.c_str()); + return FAILURE; + } + + if (start == std::string::npos) { + printDebug("%s| AT+QSIMSTAT? returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), sResult.c_str()); + return FAILURE; + } + + // +QSIMSTAT: <enable>,<inserted_status> + start += sPrefix.size(); + std::vector<std::string> vParts = MTS::Text::split(MTS::Text::trim(sResult.substr(start, end-start)), ','); + + if(vParts.size() != 2) { + printWarning("%s| Unable to parse SIM insertion status from response [%s]", getName().c_str(), sResult.c_str()); + return FAILURE; + } + + if (vParts[1] == "1") { // Inserted + bData = true; + } else { // Removed or Unknown, before (U)SIM initialization + bData = false; + } + + return SUCCESS; +} + +CellularRadio::CODE QuectelRadio::getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk) { + printTrace("%s| Get SIM unlock attempts left", getName().c_str()); + std::string sCmd("AT+QPINC=\"SC\""); + std::string sResult = sendCommand(sCmd); + + const std::string sPrefix = "+QPINC: \"SC\","; + size_t start = sResult.find(sPrefix); + size_t end = sResult.rfind(ICellularRadio::RSP_OK); + + if (end == std::string::npos) { + printWarning("%s| Unable to get SIM unlock attempts from radio using command [%s]", getName().c_str(), sCmd.c_str()); + return FAILURE; + } + + if (start == std::string::npos) { + printDebug("%s| AT+QPINC returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), sResult.c_str()); + return FAILURE; + } + + // +QPINC: <facility>,<pincounter>,<pukcounter> + // [x] ,[0] ,[1] + start += sPrefix.size(); + std::vector<std::string> vParts = MTS::Text::split(MTS::Text::trim(sResult.substr(start, end-start)), ','); + + if(vParts.size() != 2) { + printWarning("%s| Unable to parse SIM unlock attempts left from response [%s]", getName().c_str(), sResult.c_str()); + return FAILURE; + } + + if (!MTS::Text::parse(iAttemptsPin, vParts[0])) { + printWarning("%s| Unable to parse SIM PIM unlock attempts from response [%s]", getName().c_str(), sResult.c_str()); + return FAILURE; + } + + if (!MTS::Text::parse(iAttemptsPuk, vParts[1])) { + printWarning("%s| Unable to parse SIM PUK unlock attempts from response [%s]", getName().c_str(), sResult.c_str()); + return FAILURE; + } + + return SUCCESS; +} + CellularRadio::CODE QuectelRadio::convertToActiveBand(const std::string& sQuectelBand, ICellularRadio::ACTIVEBAND& band) { int iQuectelBand = -1; |