From 53efcef2e2f521135b323e194c45f1d9fa7b5d5d Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Thu, 6 Jun 2019 14:45:58 +0300 Subject: [MTS-MTQ] refactoring: namespace usage Using identificators in appropriate namespace --- include/mts/MTS_IO_ME910C1WWRadio.h | 4 +- src/MTS_IO_CE910Radio.cpp | 2 +- src/MTS_IO_CdmaRadio.cpp | 84 ++++++++++++++++++------------------- src/MTS_IO_DE910Radio.cpp | 2 +- src/MTS_IO_GE910Radio.cpp | 2 +- src/MTS_IO_HE910Radio.cpp | 2 +- src/MTS_IO_LE910C1APRadio.cpp | 2 +- src/MTS_IO_LE910C1NSRadio.cpp | 2 +- src/MTS_IO_LE910NA1Radio.cpp | 8 ++-- src/MTS_IO_LE910Radio.cpp | 6 +-- src/MTS_IO_LE910SVGRadio.cpp | 2 +- src/MTS_IO_ME910C1NVRadio.cpp | 68 +++++++++++++++--------------- src/MTS_IO_ME910C1WWRadio.cpp | 8 ++-- src/MTS_IO_ME910Radio.cpp | 4 +- 14 files changed, 98 insertions(+), 98 deletions(-) diff --git a/include/mts/MTS_IO_ME910C1WWRadio.h b/include/mts/MTS_IO_ME910C1WWRadio.h index bfbb8a6..6612d83 100644 --- a/include/mts/MTS_IO_ME910C1WWRadio.h +++ b/include/mts/MTS_IO_ME910C1WWRadio.h @@ -33,8 +33,8 @@ namespace MTS { ME910C1WWRadio(const std::string& sPort); virtual ~ME910C1WWRadio(){}; - CellularRadio::CODE setActiveFirmware(const Json::Value& jArgs); - CellularRadio::CODE getActiveFirmware(std::string& sFwId); + CODE setActiveFirmware(const Json::Value& jArgs); + CODE getActiveFirmware(std::string& sFwId); protected: diff --git a/src/MTS_IO_CE910Radio.cpp b/src/MTS_IO_CE910Radio.cpp index 7bdf280..fc6cfd4 100644 --- a/src/MTS_IO_CE910Radio.cpp +++ b/src/MTS_IO_CE910Radio.cpp @@ -39,7 +39,7 @@ CE910Radio::CE910Radio(const std::string& sPort) } -CellularRadio::CODE CE910Radio::setRxDiversity(const Json::Value& jArgs) { +CE910Radio::CODE CE910Radio::setRxDiversity(const Json::Value& jArgs) { /* Command string for CE radios: N/A */ return FAILURE; } diff --git a/src/MTS_IO_CdmaRadio.cpp b/src/MTS_IO_CdmaRadio.cpp index 5b53f02..8057650 100644 --- a/src/MTS_IO_CdmaRadio.cpp +++ b/src/MTS_IO_CdmaRadio.cpp @@ -44,16 +44,16 @@ CdmaRadio::~CdmaRadio() { } -CellularRadio::CODE CdmaRadio::getImei(std::string& sImei) { +CdmaRadio::CODE CdmaRadio::getImei(std::string& sImei) { printTrace("%s| Get IMEI", getName().c_str()); return getMeid(sImei); } -CellularRadio::CODE CdmaRadio::getMeid(std::string& sMeid) { +CdmaRadio::CODE CdmaRadio::getMeid(std::string& sMeid) { printTrace("%s| Get MEID", getName().c_str()); sMeid = VALUE_NOT_SUPPORTED; std::string sCmd("AT#MEIDESN?"); - std::string sResult = CellularRadio::sendCommand(sCmd); + std::string sResult = sendCommand(sCmd); size_t pos = sResult.find(RSP_OK); if (pos == std::string::npos) { printWarning("%s| Unable to get MEID from radio using command [%s]", getName().c_str(), sCmd.c_str()); @@ -72,11 +72,11 @@ CellularRadio::CODE CdmaRadio::getMeid(std::string& sMeid) { return SUCCESS; } -CellularRadio::CODE CdmaRadio::getMsid(std::string& sMsid) { +CdmaRadio::CODE CdmaRadio::getMsid(std::string& sMsid) { printTrace("%s| Get MSID", getName().c_str()); sMsid = VALUE_NOT_SUPPORTED; std::string sCmd("AT$MSID?"); - std::string sResult = CellularRadio::sendCommand(sCmd); + std::string sResult = sendCommand(sCmd); size_t end = sResult.find(RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get MSID from radio using command [%s]", getName().c_str(), sCmd.c_str()); @@ -92,7 +92,7 @@ CellularRadio::CODE CdmaRadio::getMsid(std::string& sMsid) { return SUCCESS; } -CellularRadio::CODE CdmaRadio::getCarrier(std::string& sCarrier) { +CdmaRadio::CODE CdmaRadio::getCarrier(std::string& sCarrier) { if(m_sCarrier != "") { sCarrier = m_sCarrier; return SUCCESS; @@ -113,33 +113,33 @@ CellularRadio::CODE CdmaRadio::getCarrier(std::string& sCarrier) { return SUCCESS; } -CellularRadio::CODE CdmaRadio::getNetwork(std::string& sNetwork) { +CdmaRadio::CODE CdmaRadio::getNetwork(std::string& sNetwork) { return getCarrier(sNetwork); } -CellularRadio::CODE CdmaRadio::getSimStatus(std::string& sSimStatus) { +CdmaRadio::CODE CdmaRadio::getSimStatus(std::string& sSimStatus) { printTrace("%s| Get SIM Status", getName().c_str()); sSimStatus = VALUE_NOT_SUPPORTED; return NOT_APPLICABLE; } -CellularRadio::CODE CdmaRadio::getIccid(std::string& sIccid) { +CdmaRadio::CODE CdmaRadio::getIccid(std::string& sIccid) { printTrace("%s| Get ICCID", getName().c_str()); sIccid = VALUE_NOT_SUPPORTED; return NOT_APPLICABLE; } -CellularRadio::CODE CdmaRadio::getLac(std::string& sLac) { +CdmaRadio::CODE CdmaRadio::getLac(std::string& sLac) { printTrace("%s| Get LAC", getName().c_str()); sLac = VALUE_NOT_SUPPORTED; return NOT_APPLICABLE; } -CellularRadio::CODE CdmaRadio::getService(std::string& sService) { +CdmaRadio::CODE CdmaRadio::getService(std::string& sService) { printTrace("%s| Get Service", getName().c_str()); sService = VALUE_NOT_SUPPORTED; std::string sCmd("AT+SERVICE?"); - std::string sResult = CellularRadio::sendCommand(sCmd); + std::string sResult = sendCommand(sCmd); size_t end = sResult.find(RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get Service from radio using command [%s]", getName().c_str(), sCmd.c_str()); @@ -167,11 +167,11 @@ CellularRadio::CODE CdmaRadio::getService(std::string& sService) { return SUCCESS; } -CellularRadio::CODE CdmaRadio::getHardware(std::string& sHardware) { +CdmaRadio::CODE CdmaRadio::getHardware(std::string& sHardware) { printTrace("%s| Get Hardware", getName().c_str()); sHardware = VALUE_NOT_SUPPORTED; std::string sCmd("AT#HWREV"); - std::string sResult = CellularRadio::sendCommand(sCmd); + std::string sResult = sendCommand(sCmd); size_t pos = sResult.find(RSP_OK); if (pos == std::string::npos) { printWarning("%s| Unable to get hardware from radio using command [%s]", getName().c_str(), sCmd.c_str()); @@ -187,11 +187,11 @@ CellularRadio::CODE CdmaRadio::getHardware(std::string& sHardware) { return SUCCESS; } -CellularRadio::CODE CdmaRadio::getMdn(std::string& sMdn) { +CdmaRadio::CODE CdmaRadio::getMdn(std::string& sMdn) { printTrace("%s| Get MDN", getName().c_str()); sMdn = VALUE_NOT_SUPPORTED; std::string sCmd("AT+CNUM"); - std::string sResult = CellularRadio::sendCommand(sCmd); + std::string sResult = sendCommand(sCmd); size_t end = sResult.find(RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get MDN from radio using command [%s]", getName().c_str(), sCmd.c_str()); @@ -213,7 +213,7 @@ CellularRadio::CODE CdmaRadio::getMdn(std::string& sMdn) { return SUCCESS; } -CellularRadio::CODE CdmaRadio::validateMsl(const Json::Value& jArgs) { +CdmaRadio::CODE CdmaRadio::validateMsl(const Json::Value& jArgs) { printTrace("%s| Validate MSL", getName().c_str()); if(!jArgs["msl"].isString()) { @@ -239,7 +239,7 @@ CellularRadio::CODE CdmaRadio::validateMsl(const Json::Value& jArgs) { return setMdn(jMdn); } -CellularRadio::CODE CdmaRadio::setMdn(const Json::Value& jArgs) { +CdmaRadio::CODE CdmaRadio::setMdn(const Json::Value& jArgs) { printTrace("%s| Set MDN", getName().c_str()); if(!jArgs["mdn"].isString()) { @@ -283,7 +283,7 @@ CellularRadio::CODE CdmaRadio::setMdn(const Json::Value& jArgs) { return SUCCESS; } -CellularRadio::CODE CdmaRadio::setMsid(const Json::Value& jArgs) { +CdmaRadio::CODE CdmaRadio::setMsid(const Json::Value& jArgs) { printTrace("%s| Set MSID", getName().c_str()); if(!jArgs["msid"].isString()) { printError("%s| Arguments missing \"msid\"", getName().c_str()); @@ -318,7 +318,7 @@ CellularRadio::CODE CdmaRadio::setMsid(const Json::Value& jArgs) { return SUCCESS; } -CellularRadio::CODE CdmaRadio::getMipProfile(Json::Value& jMipProfile) { +CdmaRadio::CODE CdmaRadio::getMipProfile(Json::Value& jMipProfile) { printTrace("%s| Get MIP Active Profile", getName().c_str()); initMipProfile(jMipProfile); @@ -406,7 +406,7 @@ CellularRadio::CODE CdmaRadio::getMipProfile(Json::Value& jMipProfile) { } -CellularRadio::CODE CdmaRadio::setMipActiveProfile(const Json::Value& jArgs) { +CdmaRadio::CODE CdmaRadio::setMipActiveProfile(const Json::Value& jArgs) { printTrace("%s| Set MIP Active Profile", getName().c_str()); if(!jArgs["activeProfile"].isString()) { @@ -426,7 +426,7 @@ CellularRadio::CODE CdmaRadio::setMipActiveProfile(const Json::Value& jArgs) { return SUCCESS; } -CellularRadio::CODE CdmaRadio::setMipNai(const Json::Value& jArgs) { +CdmaRadio::CODE CdmaRadio::setMipNai(const Json::Value& jArgs) { printTrace("%s| Set MIP NAI", getName().c_str()); if(!jArgs["nai"].isString()) { @@ -446,7 +446,7 @@ CellularRadio::CODE CdmaRadio::setMipNai(const Json::Value& jArgs) { return SUCCESS; } -CellularRadio::CODE CdmaRadio::setMipHomeIp(const Json::Value& jArgs) { +CdmaRadio::CODE CdmaRadio::setMipHomeIp(const Json::Value& jArgs) { printTrace("%s| Set MIP Home IP", getName().c_str()); if(!jArgs["homeIp"].isString()) { @@ -466,7 +466,7 @@ CellularRadio::CODE CdmaRadio::setMipHomeIp(const Json::Value& jArgs) { return SUCCESS; } -CellularRadio::CODE CdmaRadio::setMipPrimaryHa(const Json::Value& jArgs) { +CdmaRadio::CODE CdmaRadio::setMipPrimaryHa(const Json::Value& jArgs) { printTrace("%s| Set MIP Primary HA", getName().c_str()); if(!jArgs["primaryHa"].isString()) { @@ -486,7 +486,7 @@ CellularRadio::CODE CdmaRadio::setMipPrimaryHa(const Json::Value& jArgs) { return SUCCESS; } -CellularRadio::CODE CdmaRadio::setMipSecondaryHa(const Json::Value& jArgs) { +CdmaRadio::CODE CdmaRadio::setMipSecondaryHa(const Json::Value& jArgs) { printTrace("%s| Set MIP Secondary HA", getName().c_str()); if(!jArgs["secondaryHa"].isString()) { @@ -506,7 +506,7 @@ CellularRadio::CODE CdmaRadio::setMipSecondaryHa(const Json::Value& jArgs) { return SUCCESS; } -CellularRadio::CODE CdmaRadio::setMipMnAaaSpi(const Json::Value& jArgs) { +CdmaRadio::CODE CdmaRadio::setMipMnAaaSpi(const Json::Value& jArgs) { printTrace("%s| Set MIP MN-AAA SPI", getName().c_str()); if(!jArgs["mnAaaSpi"].isString()) { @@ -526,7 +526,7 @@ CellularRadio::CODE CdmaRadio::setMipMnAaaSpi(const Json::Value& jArgs) { return SUCCESS; } -CellularRadio::CODE CdmaRadio::setMipMnHaSpi(const Json::Value& jArgs) { +CdmaRadio::CODE CdmaRadio::setMipMnHaSpi(const Json::Value& jArgs) { printTrace("%s| Set MIP MN-HA SPI", getName().c_str()); if(!jArgs["mnHaSpi"].isString()) { @@ -546,7 +546,7 @@ CellularRadio::CODE CdmaRadio::setMipMnHaSpi(const Json::Value& jArgs) { return SUCCESS; } -CellularRadio::CODE CdmaRadio::setMipRevTun(const Json::Value& jArgs) { +CdmaRadio::CODE CdmaRadio::setMipRevTun(const Json::Value& jArgs) { printTrace("%s| Set MIP Rev Tun", getName().c_str()); if(!jArgs["revTun"].isString()) { @@ -566,7 +566,7 @@ CellularRadio::CODE CdmaRadio::setMipRevTun(const Json::Value& jArgs) { return SUCCESS; } -CellularRadio::CODE CdmaRadio::setMipMnAaaSs(const Json::Value& jArgs) { +CdmaRadio::CODE CdmaRadio::setMipMnAaaSs(const Json::Value& jArgs) { printTrace("%s| Set MIP MN-AAA SS", getName().c_str()); if(!jArgs["mnAaaSs"].isString()) { @@ -586,7 +586,7 @@ CellularRadio::CODE CdmaRadio::setMipMnAaaSs(const Json::Value& jArgs) { return SUCCESS; } -CellularRadio::CODE CdmaRadio::setMipMnHaSs(const Json::Value& jArgs) { +CdmaRadio::CODE CdmaRadio::setMipMnHaSs(const Json::Value& jArgs) { printTrace("%s| Set MIP MN-HA SS", getName().c_str()); if(!jArgs["mnHaSs"].isString()) { @@ -606,7 +606,7 @@ CellularRadio::CODE CdmaRadio::setMipMnHaSs(const Json::Value& jArgs) { return SUCCESS; } -CellularRadio::CODE CdmaRadio::updateDc(const Json::Value& jArgs, UpdateCb& stepCb) { +CdmaRadio::CODE CdmaRadio::updateDc(const Json::Value& jArgs, UpdateCb& stepCb) { printTrace("%s| Update Device Configuration", getName().c_str()); std::string sCarrier; @@ -616,7 +616,7 @@ CellularRadio::CODE CdmaRadio::updateDc(const Json::Value& jArgs, UpdateCb& step return NOT_APPLICABLE; } - CellularRadio::CODE result = FAILURE; + CODE result = FAILURE; std::size_t pos = 0; std::size_t end = 0; @@ -703,7 +703,7 @@ CellularRadio::CODE CdmaRadio::updateDc(const Json::Value& jArgs, UpdateCb& step return result; } -CellularRadio::CODE CdmaRadio::updatePrl(const Json::Value& jArgs, UpdateCb& stepCb) { +CdmaRadio::CODE CdmaRadio::updatePrl(const Json::Value& jArgs, UpdateCb& stepCb) { printTrace("%s| Update Preferred Roaming List", getName().c_str()); std::string sCarrier; @@ -713,7 +713,7 @@ CellularRadio::CODE CdmaRadio::updatePrl(const Json::Value& jArgs, UpdateCb& ste return NOT_APPLICABLE; } - CellularRadio::CODE result = FAILURE; + CODE result = FAILURE; std::size_t pos = 0; std::size_t end = 0; @@ -800,7 +800,7 @@ CellularRadio::CODE CdmaRadio::updatePrl(const Json::Value& jArgs, UpdateCb& ste return result; } -CellularRadio::CODE CdmaRadio::updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) { +CdmaRadio::CODE CdmaRadio::updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) { printTrace("%s| Update Firmware Update Management Object", getName().c_str()); std::string sCarrier; @@ -810,7 +810,7 @@ CellularRadio::CODE CdmaRadio::updateFumo(const Json::Value& jArgs, UpdateCb& st return NOT_APPLICABLE; } - CellularRadio::CODE result = FAILURE; + CODE result = FAILURE; std::size_t pos = 0; std::size_t end = 0; @@ -957,7 +957,7 @@ CellularRadio::CODE CdmaRadio::updateFumo(const Json::Value& jArgs, UpdateCb& st return result; } -CellularRadio::CODE CdmaRadio::resetHfa(const Json::Value& jArgs, UpdateCb& stepCb) { +CdmaRadio::CODE CdmaRadio::resetHfa(const Json::Value& jArgs, UpdateCb& stepCb) { printTrace("%s| HFA Reset (after device reboot HFA will occur)", getName().c_str()); std::string sCarrier; @@ -971,7 +971,7 @@ CellularRadio::CODE CdmaRadio::resetHfa(const Json::Value& jArgs, UpdateCb& step return INVALID_ARGS; } - CellularRadio::CODE result = FAILURE; + CODE result = FAILURE; std::size_t pos = 0; std::size_t end = 0; @@ -1075,7 +1075,7 @@ CellularRadio::CODE CdmaRadio::resetHfa(const Json::Value& jArgs, UpdateCb& step return result; } -CellularRadio::CODE CdmaRadio::activate(const Json::Value& jArgs, UpdateCb& stepCb) { +CdmaRadio::CODE CdmaRadio::activate(const Json::Value& jArgs, UpdateCb& stepCb) { printTrace("%s| Activation", getName().c_str()); std::string sActivationCmd; @@ -1107,7 +1107,7 @@ CellularRadio::CODE CdmaRadio::activate(const Json::Value& jArgs, UpdateCb& step } //Set MDN & MSID - CellularRadio::CODE code; + CODE code; code = setMdn(jArgs); if(code != SUCCESS) { return code; @@ -1130,7 +1130,7 @@ CellularRadio::CODE CdmaRadio::activate(const Json::Value& jArgs, UpdateCb& step return NOT_APPLICABLE; } - CellularRadio::CODE result = FAILURE; + CODE result = FAILURE; std::size_t pos = 0; std::size_t end = 0; @@ -1214,7 +1214,7 @@ CellularRadio::CODE CdmaRadio::activate(const Json::Value& jArgs, UpdateCb& step return result; } -CellularRadio::CODE CdmaRadio::getNetworkStatus(Json::Value& jData) { +CdmaRadio::CODE CdmaRadio::getNetworkStatus(Json::Value& jData) { printTrace("%s| Get Network Status", getName().c_str()); getCommonNetworkStats(jData); diff --git a/src/MTS_IO_DE910Radio.cpp b/src/MTS_IO_DE910Radio.cpp index eccb3eb..8749da6 100644 --- a/src/MTS_IO_DE910Radio.cpp +++ b/src/MTS_IO_DE910Radio.cpp @@ -39,7 +39,7 @@ DE910Radio::DE910Radio(const std::string& sPort) } -CellularRadio::CODE DE910Radio::setRxDiversity(const Json::Value& jArgs) { +DE910Radio::CODE DE910Radio::setRxDiversity(const Json::Value& jArgs) { /* Command string for EV3 radios: AT#CRXD= */ if (jArgs["enabled"].asString() != "1" && jArgs["enabled"].asString() != "0") { diff --git a/src/MTS_IO_GE910Radio.cpp b/src/MTS_IO_GE910Radio.cpp index e402b13..f31f4fc 100644 --- a/src/MTS_IO_GE910Radio.cpp +++ b/src/MTS_IO_GE910Radio.cpp @@ -39,7 +39,7 @@ GE910Radio::GE910Radio(const std::string& sPort) } -CellularRadio::CODE GE910Radio::setRxDiversity(const Json::Value& jArgs) { +GE910Radio::CODE GE910Radio::setRxDiversity(const Json::Value& jArgs) { /* Command string for GE radios: N/A */ return FAILURE; } diff --git a/src/MTS_IO_HE910Radio.cpp b/src/MTS_IO_HE910Radio.cpp index bc08932..0178c9d 100644 --- a/src/MTS_IO_HE910Radio.cpp +++ b/src/MTS_IO_HE910Radio.cpp @@ -37,7 +37,7 @@ HE910Radio::HE910Radio(const std::string& sHE910Model, const std::string& sPort) } -CellularRadio::CODE HE910Radio::setRxDiversity(const Json::Value& jArgs) { +HE910Radio::CODE HE910Radio::setRxDiversity(const Json::Value& jArgs) { /* Command string for H5 radios: "AT#RXDIV" */ if (jArgs["enabled"].asString() != "1" && jArgs["enabled"].asString() != "0") { diff --git a/src/MTS_IO_LE910C1APRadio.cpp b/src/MTS_IO_LE910C1APRadio.cpp index 3a560fa..befb809 100644 --- a/src/MTS_IO_LE910C1APRadio.cpp +++ b/src/MTS_IO_LE910C1APRadio.cpp @@ -30,7 +30,7 @@ LE910C1APRadio::LE910C1APRadio(const std::string& sPort) } -CellularRadio::CODE LE910C1APRadio::getCarrier(std::string& sCarrier) { +LE910C1APRadio::CODE LE910C1APRadio::getCarrier(std::string& sCarrier) { sCarrier = "Sprint"; return SUCCESS; } diff --git a/src/MTS_IO_LE910C1NSRadio.cpp b/src/MTS_IO_LE910C1NSRadio.cpp index 6c403a0..425ab93 100644 --- a/src/MTS_IO_LE910C1NSRadio.cpp +++ b/src/MTS_IO_LE910C1NSRadio.cpp @@ -39,7 +39,7 @@ LE910C1NSRadio::LE910C1NSRadio(const std::string& sPort) } -CellularRadio::CODE LE910C1NSRadio::getCarrier(std::string& sCarrier) { +LE910C1NSRadio::CODE LE910C1NSRadio::getCarrier(std::string& sCarrier) { sCarrier = "Sprint"; return SUCCESS; } diff --git a/src/MTS_IO_LE910NA1Radio.cpp b/src/MTS_IO_LE910NA1Radio.cpp index 64583b4..382432b 100644 --- a/src/MTS_IO_LE910NA1Radio.cpp +++ b/src/MTS_IO_LE910NA1Radio.cpp @@ -38,8 +38,8 @@ LE910NA1Radio::LE910NA1Radio(const std::string& sPort) } -CellularRadio::CODE LE910NA1Radio::setActiveFirmware(const Json::Value& jArgs) { - CellularRadio::CODE rc; +LE910NA1Radio::CODE LE910NA1Radio::setActiveFirmware(const Json::Value& jArgs) { + CODE rc; // Set command allows enabling a specific firmware image on products // embedding 2 different firmware images: @@ -82,9 +82,9 @@ CellularRadio::CODE LE910NA1Radio::setActiveFirmware(const Json::Value& jArgs) { return sendBasicCommand(sCmd, 5000); } -CellularRadio::CODE LE910NA1Radio::getActiveFirmware(std::string& sFwId) { +LE910NA1Radio::CODE LE910NA1Radio::getActiveFirmware(std::string& sFwId) { std::string sCmd; - CellularRadio::CODE rc; + CODE rc; // // Read command reports the current active firmware image: // AT#FWSWITCH? diff --git a/src/MTS_IO_LE910Radio.cpp b/src/MTS_IO_LE910Radio.cpp index 76ccae2..f383b68 100644 --- a/src/MTS_IO_LE910Radio.cpp +++ b/src/MTS_IO_LE910Radio.cpp @@ -38,7 +38,7 @@ LE910Radio::LE910Radio(const std::string& sLE910Model, const std::string& sPort) } -CellularRadio::CODE LE910Radio::setRxDiversity(const Json::Value& jArgs) { +LE910Radio::CODE LE910Radio::setRxDiversity(const Json::Value& jArgs) { /* Command string for LAT1,LVW2,LEU1 radios: "AT#RXDIV=" */ /* Setting needs to append ",1" to the 0/1 value */ if (jArgs["enabled"].asString() != "1" && jArgs["enabled"].asString() != "0") @@ -49,10 +49,10 @@ CellularRadio::CODE LE910Radio::setRxDiversity(const Json::Value& jArgs) { sCmd += jArgs["enabled"].asString(); sCmd += ",1"; - return CellularRadio::sendBasicCommand(sCmd); + return sendBasicCommand(sCmd); } -CellularRadio::CODE LE910Radio::getModemLocation(std::string& sLocation) { +LE910Radio::CODE LE910Radio::getModemLocation(std::string& sLocation) { const std::string& whitespace = " \t"; printTrace("LE910Radio getModemLocation"); std::string sCmd("AT$GPSACP"); diff --git a/src/MTS_IO_LE910SVGRadio.cpp b/src/MTS_IO_LE910SVGRadio.cpp index 692350d..e0afd67 100644 --- a/src/MTS_IO_LE910SVGRadio.cpp +++ b/src/MTS_IO_LE910SVGRadio.cpp @@ -39,7 +39,7 @@ LE910SVGRadio::LE910SVGRadio(const std::string& sPort) } -CellularRadio::CODE LE910SVGRadio::getCarrier(std::string& sCarrier) { +LE910SVGRadio::CODE LE910SVGRadio::getCarrier(std::string& sCarrier) { sCarrier = "Verizon"; return SUCCESS; } diff --git a/src/MTS_IO_ME910C1NVRadio.cpp b/src/MTS_IO_ME910C1NVRadio.cpp index e9a4874..08c18e9 100644 --- a/src/MTS_IO_ME910C1NVRadio.cpp +++ b/src/MTS_IO_ME910C1NVRadio.cpp @@ -53,13 +53,13 @@ ME910C1NVRadio::ME910C1NVRadio(const std::string& sPort) } -CellularRadio::CODE ME910C1NVRadio::getCarrier(std::string& sCarrier) { +ME910C1NVRadio::CODE ME910C1NVRadio::getCarrier(std::string& sCarrier) { sCarrier = "Verizon"; return SUCCESS; } -CellularRadio::CODE ME910C1NVRadio::doGetFirmwareNumbers(std::string &sFirmware, std::string &sFirmwareBuild) { - CellularRadio::CODE rc = FAILURE; +ME910C1NVRadio::CODE ME910C1NVRadio::doGetFirmwareNumbers(std::string &sFirmware, std::string &sFirmwareBuild) { + CODE rc = FAILURE; rc = getFirmware(sFirmware); if (rc != SUCCESS){ @@ -74,9 +74,9 @@ CellularRadio::CODE ME910C1NVRadio::doGetFirmwareNumbers(std::string &sFirmware, return rc; } -CellularRadio::CODE ME910C1NVRadio::doFumoReadConfig(const Json::Value& jArgs, Json::Value &jConfig) +ME910C1NVRadio::CODE ME910C1NVRadio::doFumoReadConfig(const Json::Value& jArgs, Json::Value &jConfig) { - CellularRadio::CODE rc = INVALID_ARGS; + CODE rc = INVALID_ARGS; std::string sPath; do @@ -196,9 +196,9 @@ CellularRadio::CODE ME910C1NVRadio::doFumoReadConfig(const Json::Value& jArgs, J return rc; } -CellularRadio::CODE ME910C1NVRadio::doFumoSetup(const Json::Value &jConfig, UpdateCb& stepCb) +ME910C1NVRadio::CODE ME910C1NVRadio::doFumoSetup(const Json::Value &jConfig, UpdateCb& stepCb) { - CellularRadio::CODE rc = FAILURE; + CODE rc = FAILURE; std::string sCmd; std::string sContextId = jConfig[KEY_FUMO_PDPID].asString(); @@ -215,7 +215,7 @@ CellularRadio::CODE ME910C1NVRadio::doFumoSetup(const Json::Value &jConfig, Upda // AT#SGACT=,[,,] // sCmd = "AT#SGACT=" + sContextId + ",0"; - rc = CellularRadio::sendBasicCommand(sCmd); + rc = sendBasicCommand(sCmd); if (rc != SUCCESS) { if(stepCb) { stepCb(Json::Value("FUMO Error: Failed to deactivate PDP context")); @@ -244,7 +244,7 @@ CellularRadio::CODE ME910C1NVRadio::doFumoSetup(const Json::Value &jConfig, Upda if (!sApn.empty()) { sCmd += ",\"" + sApn + "\""; } - rc = CellularRadio::sendBasicCommand(sCmd, 1000); + rc = sendBasicCommand(sCmd, 1000); if (rc != SUCCESS) { if(stepCb) { stepCb(Json::Value("FUMO Error: Failed to setup PDP context")); @@ -267,7 +267,7 @@ CellularRadio::CODE ME910C1NVRadio::doFumoSetup(const Json::Value &jConfig, Upda // less than max packet size (timeout value in hundreds of milliseconds). // sCmd = "AT#SCFG=1," + sContextId + ",300,90,600,50"; - rc = CellularRadio::sendBasicCommand(sCmd); + rc = sendBasicCommand(sCmd); if (rc != SUCCESS) { if(stepCb) { stepCb(Json::Value("FUMO Error: Failed to set connection configuration parameters")); @@ -279,7 +279,7 @@ CellularRadio::CODE ME910C1NVRadio::doFumoSetup(const Json::Value &jConfig, Upda // Activate PDP context // sCmd = "AT#SGACT=" + sContextId + ",1"; - rc = CellularRadio::sendBasicCommand(sCmd, 60 * 1000); + rc = sendBasicCommand(sCmd, 60 * 1000); if (rc != SUCCESS) { if(stepCb) { stepCb(Json::Value("FUMO Error: Failed to activate PDP context")); @@ -292,9 +292,9 @@ CellularRadio::CODE ME910C1NVRadio::doFumoSetup(const Json::Value &jConfig, Upda return rc; } -CellularRadio::CODE ME910C1NVRadio::doFumoFtp(const Json::Value &jConfig, UpdateCb& stepCb) +ME910C1NVRadio::CODE ME910C1NVRadio::doFumoFtp(const Json::Value &jConfig, UpdateCb& stepCb) { - CellularRadio::CODE rc = FAILURE; + CODE rc = FAILURE; std::string sCmd; std::string sResult; @@ -305,7 +305,7 @@ CellularRadio::CODE ME910C1NVRadio::doFumoFtp(const Json::Value &jConfig, Update // AT#FTPTO= [] // - time-out in 100 ms units // - rc = CellularRadio::sendBasicCommand("AT#FTPTO=2400"); + rc = sendBasicCommand("AT#FTPTO=2400"); if (rc != SUCCESS) { if(stepCb) { stepCb(Json::Value("FUMO Error: Failed to setup connection timeout")); @@ -322,7 +322,7 @@ CellularRadio::CODE ME910C1NVRadio::doFumoFtp(const Json::Value &jConfig, Update sCmd += "\"" + jConfig[KEY_FUMO_ADDRESS].asString() + "\","; sCmd += "\"" + jConfig[KEY_FUMO_USER].asString() + "\","; sCmd += "\"" + jConfig[KEY_FUMO_PASSWORD].asString() + "\",1"; - rc = CellularRadio::sendBasicCommand(sCmd, 60 * 1000); + rc = sendBasicCommand(sCmd, 60 * 1000); if (rc != SUCCESS) { if(stepCb) { stepCb(Json::Value("FUMO Error: Failed to open connection")); @@ -344,7 +344,7 @@ CellularRadio::CODE ME910C1NVRadio::doFumoFtp(const Json::Value &jConfig, Update // 0 - binary // 1 - ascii // - rc = CellularRadio::sendBasicCommand("AT#FTPTYPE=0", 1000); + rc = sendBasicCommand("AT#FTPTYPE=0", 1000); if (rc != SUCCESS) { if(stepCb) { stepCb(Json::Value("FUMO Error: failed to set file transfer type")); @@ -363,7 +363,7 @@ CellularRadio::CODE ME910C1NVRadio::doFumoFtp(const Json::Value &jConfig, Update sCmd += jConfig[KEY_FUMO_DIR].asString() + "/"; } sCmd += "\""; - rc = CellularRadio::sendBasicCommand(sCmd, 60 * 1000); + rc = sendBasicCommand(sCmd, 60 * 1000); if (rc != SUCCESS) { if(stepCb) { stepCb(Json::Value("FUMO Error: failed to change working directory on the server")); @@ -380,7 +380,7 @@ CellularRadio::CODE ME910C1NVRadio::doFumoFtp(const Json::Value &jConfig, Update // sCmd = "AT#FTPGETOTA="; sCmd += "\"" + jConfig[KEY_FUMO_FILE].asString() + "\",1,1"; - CellularRadio::sendBasicCommand(sCmd); + sendBasicCommand(sCmd); // // Noticed that after successful AT#FTPGETOTA the radio resets the connection. @@ -396,12 +396,12 @@ CellularRadio::CODE ME910C1NVRadio::doFumoFtp(const Json::Value &jConfig, Update { MTS::Thread::sleep(5000); - rc = CellularRadio::sendBasicCommand("AT"); + rc = sendBasicCommand("AT"); if (rc == SUCCESS) { break; } - CellularRadio::resetConnection(1); + resetConnection(1); } oTimer.stop(); @@ -450,7 +450,7 @@ CellularRadio::CODE ME910C1NVRadio::doFumoFtp(const Json::Value &jConfig, Update // // AT#FTPCLOSE // - CellularRadio::CODE rcclose = CellularRadio::sendBasicCommand("AT#FTPCLOSE", 60 * 1000); + CODE rcclose = sendBasicCommand("AT#FTPCLOSE", 60 * 1000); if (rcclose != SUCCESS && rc == SUCCESS) { if(stepCb) { // Only one "FUMO Error" message should be sent @@ -468,9 +468,9 @@ CellularRadio::CODE ME910C1NVRadio::doFumoFtp(const Json::Value &jConfig, Update return rc; } -CellularRadio::CODE ME910C1NVRadio::doFumoCleanup(const Json::Value &jConfig, UpdateCb& stepCb) +ME910C1NVRadio::CODE ME910C1NVRadio::doFumoCleanup(const Json::Value &jConfig, UpdateCb& stepCb) { - CellularRadio::CODE rc = FAILURE; + CODE rc = FAILURE; std::string sCmd; std::string sContextId = jConfig[KEY_FUMO_PDPID].asString(); @@ -479,7 +479,7 @@ CellularRadio::CODE ME910C1NVRadio::doFumoCleanup(const Json::Value &jConfig, Up // Deactivate PDP context // sCmd = "AT#SGACT=" + sContextId + ",0"; - rc = CellularRadio::sendBasicCommand(sCmd, 10000); + rc = sendBasicCommand(sCmd, 10000); if (rc != SUCCESS) { if(stepCb) { stepCb(Json::Value("FUMO Error: Failed to deactivate PDP context")); @@ -488,9 +488,9 @@ CellularRadio::CODE ME910C1NVRadio::doFumoCleanup(const Json::Value &jConfig, Up return rc; } -CellularRadio::CODE ME910C1NVRadio::doFumoApplyFirmware(const Json::Value &jConfig, UpdateCb& stepCb) +ME910C1NVRadio::CODE ME910C1NVRadio::doFumoApplyFirmware(const Json::Value &jConfig, UpdateCb& stepCb) { - CellularRadio::CODE rc = FAILURE; + CODE rc = FAILURE; if (jConfig.isMember(KEY_FUMO_DRYRUN)) { if(stepCb) { @@ -499,7 +499,7 @@ CellularRadio::CODE ME910C1NVRadio::doFumoApplyFirmware(const Json::Value &jConf return SUCCESS; } - rc = CellularRadio::sendBasicCommand("AT#OTAUP=0", 10000); + rc = sendBasicCommand("AT#OTAUP=0", 10000); if (rc != SUCCESS) { if(stepCb) { stepCb(Json::Value("FUMO Error: failed to apply the firmware")); @@ -514,11 +514,11 @@ CellularRadio::CODE ME910C1NVRadio::doFumoApplyFirmware(const Json::Value &jConf return rc; } -CellularRadio::CODE ME910C1NVRadio::doFumoWaitNewFirmware(const Json::Value &jConfig, UpdateCb& stepCb) +ME910C1NVRadio::CODE ME910C1NVRadio::doFumoWaitNewFirmware(const Json::Value &jConfig, UpdateCb& stepCb) { std::string sFirmware; std::string sFirmwareBuild; - CellularRadio::CODE rc = FAILURE; + CODE rc = FAILURE; if (jConfig.isMember(KEY_FUMO_DRYRUN)) { if(stepCb) { @@ -539,7 +539,7 @@ CellularRadio::CODE ME910C1NVRadio::doFumoWaitNewFirmware(const Json::Value &jCo if (doGetFirmwareNumbers(sFirmware, sFirmwareBuild) != SUCCESS) { // The radio is probably unavailable - CellularRadio::resetConnection(100); + resetConnection(100); continue; } @@ -570,9 +570,9 @@ CellularRadio::CODE ME910C1NVRadio::doFumoWaitNewFirmware(const Json::Value &jCo } -CellularRadio::CODE ME910C1NVRadio::doFumoPerform(const Json::Value &jConfig, UpdateCb& stepCb) +ME910C1NVRadio::CODE ME910C1NVRadio::doFumoPerform(const Json::Value &jConfig, UpdateCb& stepCb) { - CellularRadio::CODE rc = FAILURE; + CODE rc = FAILURE; UpdateCb dummyCb; @@ -606,10 +606,10 @@ CellularRadio::CODE ME910C1NVRadio::doFumoPerform(const Json::Value &jConfig, Up return rc; } -CellularRadio::CODE ME910C1NVRadio::updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) +ME910C1NVRadio::CODE ME910C1NVRadio::updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) { Json::Value jConfig(Json::objectValue); - CellularRadio::CODE rc = FAILURE; + CODE rc = FAILURE; rc = doFumoReadConfig(jArgs, jConfig); if (rc != SUCCESS) { diff --git a/src/MTS_IO_ME910C1WWRadio.cpp b/src/MTS_IO_ME910C1WWRadio.cpp index d26749a..2bc86a1 100644 --- a/src/MTS_IO_ME910C1WWRadio.cpp +++ b/src/MTS_IO_ME910C1WWRadio.cpp @@ -32,8 +32,8 @@ ME910C1WWRadio::ME910C1WWRadio(const std::string& sPort) } -CellularRadio::CODE ME910C1WWRadio::setActiveFirmware(const Json::Value& jArgs) { - CellularRadio::CODE rc; +ME910C1WWRadio::CODE ME910C1WWRadio::setActiveFirmware(const Json::Value& jArgs) { + CODE rc; // Set command allows enabling a specific firmware image on products // embedding 2 different firmware images: @@ -76,9 +76,9 @@ CellularRadio::CODE ME910C1WWRadio::setActiveFirmware(const Json::Value& jArgs) return sendBasicCommand(sCmd, 5000); } -CellularRadio::CODE ME910C1WWRadio::getActiveFirmware(std::string& sFwId) { +ME910C1WWRadio::CODE ME910C1WWRadio::getActiveFirmware(std::string& sFwId) { std::string sCmd; - CellularRadio::CODE rc; + CODE rc; // // Read command reports the current active firmware image: // AT#FWSWITCH? diff --git a/src/MTS_IO_ME910Radio.cpp b/src/MTS_IO_ME910Radio.cpp index 42796e9..590a883 100644 --- a/src/MTS_IO_ME910Radio.cpp +++ b/src/MTS_IO_ME910Radio.cpp @@ -30,12 +30,12 @@ ME910Radio::ME910Radio(const std::string& sME910Model, const std::string& sPort) } -CellularRadio::CODE ME910Radio::setRxDiversity(const Json::Value& jArgs) { +ME910Radio::CODE ME910Radio::setRxDiversity(const Json::Value& jArgs) { return FAILURE; } -CellularRadio::CODE ME910Radio::getFirmwareBuild(std::string& sFirmwareBuild) { +ME910Radio::CODE ME910Radio::getFirmwareBuild(std::string& sFirmwareBuild) { std::string sCmd("AT#CFVR"); std::string sResult = sendCommand(sCmd); -- cgit v1.2.3 From da563a985ccb0b5f316b44e35aabd511687ff4bf Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Thu, 6 Jun 2019 16:03:44 +0300 Subject: [MTS-MTQ] refactoring: added quectel empty classes, CellularRadio moved to TelitRadio --- include/mts/MTS_IO_CdmaRadio.h | 4 +- include/mts/MTS_IO_CellularRadio.h | 501 +------- include/mts/MTS_IO_CellularRadioFactory.h | 42 +- include/mts/MTS_IO_EG95Radio.h | 15 + include/mts/MTS_IO_GE910Radio.h | 4 +- include/mts/MTS_IO_HE910Radio.h | 4 +- include/mts/MTS_IO_ICellularRadio.h | 399 +++++++ include/mts/MTS_IO_LE866Radio.h | 4 +- include/mts/MTS_IO_LE910Radio.h | 4 +- include/mts/MTS_IO_ME910Radio.h | 4 +- include/mts/MTS_IO_QuectelRadio.h | 15 + include/mts/MTS_IO_TelitRadio.h | 496 ++++++++ src/MTS_IO_CdmaRadio.cpp | 2 +- src/MTS_IO_CellularRadio.cpp | 1818 +--------------------------- src/MTS_IO_CellularRadioFactory.cpp | 12 +- src/MTS_IO_EG95Radio.cpp | 1 + src/MTS_IO_GE910Radio.cpp | 2 +- src/MTS_IO_HE910Radio.cpp | 2 +- src/MTS_IO_LE866Radio.cpp | 2 +- src/MTS_IO_LE910Radio.cpp | 2 +- src/MTS_IO_ME910Radio.cpp | 2 +- src/MTS_IO_QuectelRadio.cpp | 1 + src/MTS_IO_TelitRadio.cpp | 1838 +++++++++++++++++++++++++++++ 23 files changed, 2813 insertions(+), 2361 deletions(-) create mode 100644 include/mts/MTS_IO_EG95Radio.h create mode 100644 include/mts/MTS_IO_ICellularRadio.h create mode 100644 include/mts/MTS_IO_QuectelRadio.h create mode 100644 include/mts/MTS_IO_TelitRadio.h create mode 100644 src/MTS_IO_EG95Radio.cpp create mode 100644 src/MTS_IO_QuectelRadio.cpp create mode 100644 src/MTS_IO_TelitRadio.cpp diff --git a/include/mts/MTS_IO_CdmaRadio.h b/include/mts/MTS_IO_CdmaRadio.h index 448cdc7..7cdba02 100644 --- a/include/mts/MTS_IO_CdmaRadio.h +++ b/include/mts/MTS_IO_CdmaRadio.h @@ -29,12 +29,12 @@ #ifndef MTS_IO_CDMARADIO_H_ #define MTS_IO_CDMARADIO_H_ -#include +#include namespace MTS { namespace IO { - class CdmaRadio : public CellularRadio { + class CdmaRadio : public TelitRadio { public: virtual ~CdmaRadio(); diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index 007c130..1378612 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -29,510 +29,13 @@ #ifndef MTS_IO_CELLULARRADIO_H_ #define MTS_IO_CELLULARRADIO_H_ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -typedef struct -{ - const char *name; - int32_t low; - int32_t high; -} *pNameRangeMap, nameRangeMap; - -static const unsigned int NUM_GSM_BANDS = 7; -static const unsigned int NUM_WCDMA_BANDS = 6; -static const unsigned int NUM_LTE_BANDS = 42; - -// http://niviuk.free.fr/gsm_band.php -static const nameRangeMap GSMband[] = -{ - {"GSM 450", 259, 293}, {"GSM 480", 306, 340}, - {"GSM 750", 438, 511}, {"GSM 850", 128, 251}, - {"GSM 900 P", 1, 124}, {"GSM 900 E/R", 955, 1023}, - {"GSM DCS 1800/1900", 512, 885}, - -}; - -// http://niviuk.free.fr/umts_band.php -static const nameRangeMap WCDMAband[] = -{ - {"BAND I", 10592, 10838}, {"BAND II", 9662, 9938}, - {"BAND III", 1162, 1513}, {"BAND IV", 1537, 1738}, - {"BAND V", 4357, 4458}, {"BAND VI", 4387, 4413} -}; - -// http://niviuk.free.fr/lte_band.php -static const nameRangeMap EULTRAband[] = -{ - {"EUTRAN BAND1", 0, 599}, {"EUTRAN BAND2", 600, 1199}, - {"EUTRAN BAND3", 1200, 1949}, {"EUTRAN BAND4", 1950, 2399}, - {"EUTRAN BAND5", 2400, 2649}, {"EUTRAN BAND6", 2650, 2749}, - {"EUTRAN BAND7", 2750, 3449}, {"EUTRAN BAND8", 3450, 3799}, - {"EUTRAN BAND9", 3800, 4149}, {"EUTRAN BAND10", 4150, 4749}, - {"EUTRAN BAND11", 4750, 4999}, {"EUTRAN BAND12", 5000, 5179}, - {"EUTRAN BAND13", 5180, 5279}, {"EUTRAN BAND14", 5280, 5379}, - {"EUTRAN BAND17", 5730, 5849}, {"EUTRAN BAND18", 5850, 5999}, - {"EUTRAN BAND19", 6000, 6149}, {"EUTRAN BAND20", 6150, 6449}, - {"EUTRAN BAND21", 6450, 6525}, {"EUTRAN BAND22", 6600, 7399}, - {"EUTRAN BAND23", 7500, 7699}, {"EUTRAN BAND24", 7700, 8039}, - {"EUTRAN BAND25", 8040, 8689}, {"EUTRAN BAND26", 8690, 9039}, - {"EUTRAN BAND27", 9040, 9209}, {"EUTRAN BAND28", 9210, 9659}, - {"EUTRAN BAND29", 9660, 9769}, {"EUTRAN BAND30", 9770, 9869}, - {"EUTRAN BAND31", 9870, 9919}, {"EUTRAN BAND32", 9920, 10359}, - {"EUTRAN BAND33", 36000, 36199}, {"EUTRAN BAND34", 36200, 36349}, - {"EUTRAN BAND35", 36350, 36949}, {"EUTRAN BAND36", 36950, 37549}, - {"EUTRAN BAND37", 37550, 37749}, {"EUTRAN BAND38", 37750, 38249}, - {"EUTRAN BAND39", 38250, 38649}, {"EUTRAN BAND40", 38650, 39649}, - {"EUTRAN BAND41", 39650, 41589}, {"EUTRAN BAND42", 41590, 43589}, - {"EUTRAN BAND43", 43590, 45589}, {"EUTRAN BAND44", 45590, 46589} -}; +#include namespace MTS { namespace IO { - class CellularRadio : NonCopyable { - - public: - static const std::string DEFAULT_RADIO_PORT; - static const std::string DEFAULT_RADIO_DIR; - - static const std::string VALUE_UNKNOWN; - static const std::string VALUE_UNAVAILABLE; - static const std::string VALUE_NOT_SUPPORTED; - - //Special Payload Characters - static const char ETX; //Ends socket connection - static const char DLE; //Escapes ETX and DLE within Payload - static const char CR; - static const char NL; - static const char CTRL_Z; - - static const std::string RSP_OK; - static const std::string RSP_ERROR; - - //Registration Values - enum REGISTRATION : uint8_t { - NOT_REGISTERED = 0, - REGISTERED = 1, - SEARCHING=2, - DENIED=3, - UNKNOWN=4, - ROAMING=5 - }; - - enum SERVICEDOMAIN : uint8_t { - NO_SERVICE = 0, - CS_ONLY = 1, - PS_ONLY = 2, - CSPS = 3 - }; - - enum ACTIVEBAND : uint8_t { - GSM_850 = 0, - GSM_900 = 1, - DCS_1800 = 2, - PCS_1900 = 3 - }; - - enum CODE : uint8_t { - SUCCESS = 0, - ERROR, - FAILURE, - NO_RESPONSE, - NOT_APPLICABLE, - INVALID_ARGS - }; - - enum SIMSTATUS : uint8_t { - READY = 0, - LOCKED, - BLOCKED, - NOT_INSERTED - }; - - static const std::string VALUE_NOT_REGISTERED; - static const std::string VALUE_REGISTERED; - static const std::string VALUE_SEARCHING; - static const std::string VALUE_DENIED; - static const std::string VALUE_ROAMING; - - //Static Data - static const std::string KEY_TYPE; //!< GSM or CDMA - static const std::string KEY_CODE; //!< Product Code : H5, H6, C2, EV3, G3 - static const std::string KEY_MODEL; //!< Model : HE910, CE910, DE910, GE910 - static const std::string KEY_MANUFACTURER; //!< Manufacturer: Telit - static const std::string KEY_HARDWARE; //!< Radio Hardware Version - static const std::string KEY_FIRMWARE; //!< Radio Firmware Version - static const std::string KEY_FIRMWARE_BUILD;//!< Radio Firmware Build - static const std::string KEY_IMEI; //!< International Mobile Station Equipment Identity - static const std::string KEY_MEID; //!< Mobile Equipment Identifier - static const std::string KEY_IMSI; //!< International Mobile Subscriber Identity - static const std::string KEY_MSID; //!< Mobil Station ID (MSID) aka MIN aka MSIN aka Last few digits of IMSI - static const std::string KEY_MDN; //!< Mobile Directory Number : Actual phone number dialed to reach radio - static const std::string KEY_CARRIER; //!< Cellular Service Provider (Home Network) - static const std::string KEY_ICCID; //!< Integrated Circuit Card Identifier - static const std::string KEY_MSL; //!< Master Subsidy Lock - - - //Network Status Data - static const std::string KEY_ROAMING; //!< Indicates whether or not using Home Network - static const std::string KEY_DATETIME; //!< Date and Time from tower - static const std::string KEY_SERVICE; //!< Service Connection Type [GPRS, EGPRS, WCDMA, HSDPA, 1xRTT, EVDO] - static const std::string KEY_NETWORK; //!< Cellular Service Provider - static const std::string KEY_NETWORK_REG; //!< Network Registration - static const std::string KEY_CID; //!< Cellular ID (Tower) in HEX - static const std::string KEY_LAC; //!< Location Area Code in HEX - static const std::string KEY_RAC; //!< Routing Area Code in HEX - static const std::string KEY_RSSI; //!< Received Signal Strength Indication - static const std::string KEY_RSSIDBM; //!< Received Signal Strength Indication in dBm - static const std::string KEY_MCC; //!< Mobile Country Code - static const std::string KEY_MNC; //!< Mobile Network (Operator) Code - static const std::string KEY_CHANNEL; //!< ARFCN or UARFCN Assigned Radio Channel - static const std::string KEY_TXPWR; //!< Transmit Power - static const std::string KEY_PSC; //!< Active Primary Synchronization Code (PSC) - static const std::string KEY_ECIO; //!< Active Ec/Io (chip energy per total wideband power in dBm) - static const std::string KEY_RSCP; //!< Active RSCP (Received Signal Code Power in dBm) - static const std::string KEY_DRX; //!< Discontinuous reception cycle length (ms) - static const std::string KEY_MM; //!< Mobility Management State - static const std::string KEY_RR; //!< Radio Resource State - static const std::string KEY_NOM; //!< Network Operator Mode - static const std::string KEY_ABND; //!< Active Band - static const std::string KEY_BLER; //!< Block Error Rate (percentage) - static const std::string KEY_SD; //!< Service Domain - static const std::string KEY_DEBUG; //!< Debug Information - - static const std::string KEY_MIP; //!< Mobile IP Information - static const std::string KEY_MIP_ID; //!< MIP Profile ID - static const std::string KEY_MIP_ENABLED; //!< MIP Profile Enabled/Disabled - static const std::string KEY_MIP_NAI; //!< Network Access Identifier - static const std::string KEY_MIP_HOMEADDRESS; //!< Home Address - static const std::string KEY_MIP_PRIMARYHA; //!< Primary Home Agent - static const std::string KEY_MIP_SECONDARYHA; //!< Secondary Home Agent - static const std::string KEY_MIP_MNAAASPI; //!< Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index - static const std::string KEY_MIP_MNHASPI; //!< Mobile Node Home Agent Security Server Parameter Index - static const std::string KEY_MIP_REVTUN; //!< Reverse Tunneling Enabled - static const std::string KEY_MIP_MNAAASS; //!< Mobile Node Authentication, Authorization, and Accounting Server Shared Secret - static const std::string KEY_MIP_MNHASS; //!< Mobile Node Home Agent Shared Secret - - - //Values - Type - static const std::string VALUE_TYPE_LTE; - static const std::string VALUE_TYPE_GSM; - static const std::string VALUE_TYPE_CDMA; - - //Values - Carrier - static const std::string VALUE_CARRIER_VERIZON; - static const std::string VALUE_CARRIER_AERIS; - static const std::string VALUE_CARRIER_SPRINT; - static const std::string VALUE_CARRIER_USCELLULAR; - static const std::string VALUE_CARRIER_ATT; - static const std::string VALUE_CARRIER_TMOBILE; - - static const std::string VALUE_SD_NO_SERVICE; - static const std::string VALUE_SD_CS_ONLY; - static const std::string VALUE_SD_PS_ONLY; - static const std::string VALUE_SD_CSPS; - - static const std::string VALUE_ABND_GSM_850; - static const std::string VALUE_ABND_GSM_900; - static const std::string VALUE_ABND_DCS_1800; - static const std::string VALUE_ABND_PCS_1900; - - static const std::vector DEFAULT_BAIL_STRINGS; - - typedef std::function IsNeedMoreData; - typedef std::function UpdateCb; - - virtual ~CellularRadio(); - - virtual bool initialize(uint32_t iTimeoutMillis = 5000); - virtual bool resetRadio(uint32_t iTimeoutMillis = 5000); - virtual bool resetConnection(uint32_t iTimeoutMillis = 5000); - virtual void shutdown(); - - const std::string& getName() const; - - virtual CODE getModel(std::string& sModel); - static CODE convertModelToType(const std::string& sModel, std::string& sType); - static CODE convertModelToMtsShortCode(const std::string& sModel, std::string& sCode, CellularRadio *radioObj = NULL); - static CODE convertServiceDomainToString(SERVICEDOMAIN eSd, std::string& sSd); - static CODE convertActiveBandToString(ACTIVEBAND eBand, std::string& sBand); - - virtual CODE getFirmware(std::string& sFirmware); - virtual CODE getFirmwareBuild(std::string& sFirmwareBuild); - virtual CODE getHardware(std::string& sHardware); - virtual CODE getManufacturer(std::string& sManufacturer); - virtual CODE getImei(std::string& sImei); - virtual CODE getMeid(std::string& sMeid); - virtual CODE getImsi(std::string& sImsi); - virtual CODE getSimStatus(std::string& sSimStatus); - virtual CODE getIccid(std::string& sIccid); - virtual CODE getService(std::string& sService); - virtual CODE getLac(std::string& sLac); - virtual CODE getMdn(std::string& sMdn); - virtual CODE getMsid(std::string& sMsid); - virtual CODE getType(std::string& sType); - virtual CODE getCarrier(std::string& sCarrier); - virtual CODE getNetwork(std::string& sNetwork); - virtual CODE getTower(std::string& sTower); - virtual CODE getTime(std::string& sDate, std::string& sTime, std::string& sTimeZone); - virtual CODE getRoaming(bool& bRoaming); - - virtual CODE getSignalStrength(int32_t& iRssi); - virtual CODE getModemLocation(std::string& sLocation); - virtual CODE convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& dBm); - virtual CODE convertdBmToSignalStrength(const int32_t& dBm, int32_t& iRssi); - - virtual CODE getRegistration(REGISTRATION& eRegistration); - virtual CODE convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration); - - //! Gather details of the radio's Mobile IP Profile - /*! - \param Json::Value object that will be populated with MIP data - \return Returns result code of gathering MIP - */ - virtual CODE getMipProfile(Json::Value& jMipProfile); - - /* - * jArgs = { - * "msl" : "Master Subsidy Lock (Aeris, Sprint): STRING" - * } - */ - virtual CODE validateMsl(const Json::Value& jArgs); - - /* - * jArgs = { - * "mdn" : "Mobile Directory Number : STRING", - * "msl" : "[OPTIONAL] Master Subsidy Lock (Aeris, Sprint): STRING" - * } - */ - virtual CODE setMdn(const Json::Value& jArgs); - - /* - * jArgs = { - * "msid" : "Mobil Station ID (MSID) aka MIN aka MSIN : STRING", - * "msl" : "[OPTIONAL] Master Subsidy Lock (Aeris, Sprint): STRING" - * } - */ - virtual CODE setMsid(const Json::Value& jArgs); - - /* - * jArgs = { - * "activeProfile" : "Set active profile: STRING" - * } - */ - virtual CODE setMipActiveProfile(const Json::Value& jArgs); - - /* - * jArgs = { - * "nai" : "Network Access Identifier : STRING" - * } - */ - virtual CODE setMipNai(const Json::Value& jArgs); - - /* - * jArgs = { - * "homeIp" : "Home Address : STRING" - * } - */ - virtual CODE setMipHomeIp(const Json::Value& jArgs); - - /* - * jArgs = { - * "primaryHa" : "Primary Home Agent : STRING" - * } - */ - virtual CODE setMipPrimaryHa(const Json::Value& jArgs); - - /* - * jArgs = { - * "secondaryHa" : "Secondary Home Agent : STRING" - * } - */ - virtual CODE setMipSecondaryHa(const Json::Value& jArgs); - - /* - * jArgs = { - * "mnAaaSpi" : "Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index : STRING" - * } - */ - virtual CODE setMipMnAaaSpi(const Json::Value& jArgs); - - /* - * jArgs = { - * "mnHaSpi" : "Mobile Node Home Agent Security Server Parameter Index : STRING" - * } - */ - virtual CODE setMipMnHaSpi(const Json::Value& jArgs); - - /* - * jArgs = { - * "revTun" : "[DESCRIPTION] : STRING" - * } - */ - virtual CODE setMipRevTun(const Json::Value& jArgs); - - /* - * jArgs = { - * "mnAaaSs" : "Mobile Node Authentication, Authorization, and Accounting Server Shared Secret : STRING" - * } - */ - virtual CODE setMipMnAaaSs(const Json::Value& jArgs); - - /* - * jArgs = { - * "mnHaSs" : "Mobile Node Home Agent Shared Secret : STRING" - * } - */ - virtual CODE setMipMnHaSs(const Json::Value& jArgs); - - /* - * jArgs = null - */ - virtual CODE updateDc(const Json::Value& jArgs, UpdateCb& stepCb); - - /* - * jArgs = null - */ - virtual CODE updatePrl(const Json::Value& jArgs, UpdateCb& stepCb); - - /* - * jArgs = null - */ - virtual CODE updateFumo(const Json::Value& jArgs, UpdateCb& stepCb); - - /* - * jArgs = { - * "msl" : "Master Subsidy Lock (Sprint): STRING" - * } - */ - virtual CODE resetHfa(const Json::Value& jArgs, UpdateCb& stepCb); - - /* - * jArgs = { - * "mdn" : "Mobile Directory Number (Aeris): STRING" - * "msid" : "Mobile Station ID (Aeris): STRING" - * } - */ - virtual CODE activate(const Json::Value& jArgs, UpdateCb& stepCb); - - /* - * jArgs = { - * "enabled" : "RX Diversity Enabled ("0" or "1"): STRING" - * } - */ - virtual CODE setRxDiversity(const Json::Value& jArgs)=0; - /* - * jArgs = { - * "fwid" : "Firmware Image To Be Enabled: STRING" - * } - */ - virtual CODE setActiveFirmware(const Json::Value& jArgs); - virtual CODE getActiveFirmware(std::string& sFwId); - - virtual CODE getEcho(bool& bEnabled); - virtual CODE setEcho(bool bEnabled = true); - - virtual CODE getStaticInformation(Json::Value& jData); - virtual CODE getNetworkStatus(Json::Value& jData); - - virtual CODE sendBasicCommand(const std::string& sCmd, int32_t timeoutMillis = 100, const char& ESC = CR); - - virtual std::string sendCommand(const std::string& sCmd, - const std::vector& vBail = DEFAULT_BAIL_STRINGS, - int32_t timeoutMillis = 100, - const char& ESC = CR); - - - static std::string sendCommand(MTS::AutoPtr& apIo, - const std::string& sCmd, - const std::vector& vBail = DEFAULT_BAIL_STRINGS, - int32_t timeoutMillis = 100, - const char& ESC = CR); - - virtual std::string sendCommand(const std::string& sCmd, - IsNeedMoreData& isNeedMoreData, - int32_t timeoutMillis = 100, - const char& ESC = CR); - - static std::string sendCommand(MTS::AutoPtr& apIo, - const std::string& sCmd, - IsNeedMoreData& isNeedMoreData, - int32_t timeoutMillis = 100, - const char& ESC = CR); - - static CODE test(MTS::AutoPtr& apIo, uint32_t timeoutSeconds = 30); - - static std::string extractModelFromResult(const std::string& sResult); - static std::string getCodeAsString(CODE code); - - protected: - - CellularRadio(const std::string& sName, const std::string& sRadioPort); - - virtual bool getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier); - virtual bool getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware); - - virtual void getCommonNetworkStats(Json::Value& jData); - - void initMipProfile(Json::Value& jData); - - bool splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType = Json::ValueType::stringValue); - - - - private: - class RadioBandMap : NonCopyable { - public: - RadioBandMap() - { - m_sChannel = CellularRadio::VALUE_UNKNOWN; - m_iChannel = 0; - m_sRadioType = CellularRadio::VALUE_UNKNOWN; - } - - RadioBandMap(const std::string &channel, const std::string &radioType) : - m_sChannel(channel), - m_sRadioType(radioType) - { - m_iChannel = strtol(m_sChannel.c_str(), NULL, 10); - } - - virtual ~RadioBandMap() {} - - const char *getRadioBandName(); - const char *getRadioBandName(const std::string &channel, const std::string &radioType); - - private: - - const char *getLTEBand(const int channel); - const char *getCDMABand(const int channel); - const char *getGSMBand(const int channel); - - std::string m_sChannel; - int m_iChannel; - std::string m_sRadioType; - }; - - std::string m_sName; - std::string m_sRadioPort; - std::string m_sFirmware; - std::string m_sCarrier; - MTS::AutoPtr m_apIo; - - bool m_bEchoEnabled; - bool m_bEnableEchoOnClose; + class CellularRadio : public ICellularRadio { - std::string queryLteLac(); - std::string queryCGREGstring(); - void setCGREG(std::string value); }; } } diff --git a/include/mts/MTS_IO_CellularRadioFactory.h b/include/mts/MTS_IO_CellularRadioFactory.h index 49f63bd..501f314 100644 --- a/include/mts/MTS_IO_CellularRadioFactory.h +++ b/include/mts/MTS_IO_CellularRadioFactory.h @@ -21,7 +21,7 @@ #ifndef MTS_IO_CELLULARRADIOFACTORY_H_ #define MTS_IO_CELLULARRADIOFACTORY_H_ -#include +#include #include #include @@ -39,26 +39,26 @@ namespace MTS { CellularRadioFactory(); virtual ~CellularRadioFactory() {}; - virtual CellularRadio* create(const std::string& sModel, const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); - - virtual CellularRadio* createHE910D(const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createHE910EUD(const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE910NAG(const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE910C4NF(const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE910NA1(const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE910SVG(const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE910EUG(const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE910C4EU(const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE910EU1(const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE910C1NS(const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE910C1AP(const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createME910C1NA(const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createME910C1NV(const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createME910C1WW(const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createGE910(const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createDE910(const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createCE910(const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE866A1JS(const std::string& sPort = CellularRadio::DEFAULT_RADIO_PORT); + virtual CellularRadio* create(const std::string& sModel, const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + + virtual CellularRadio* createHE910D(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + virtual CellularRadio* createHE910EUD(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + virtual CellularRadio* createLE910NAG(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + virtual CellularRadio* createLE910C4NF(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + virtual CellularRadio* createLE910NA1(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + virtual CellularRadio* createLE910SVG(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + virtual CellularRadio* createLE910EUG(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + virtual CellularRadio* createLE910C4EU(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + virtual CellularRadio* createLE910EU1(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + virtual CellularRadio* createLE910C1NS(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + virtual CellularRadio* createLE910C1AP(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + virtual CellularRadio* createME910C1NA(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + virtual CellularRadio* createME910C1NV(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + virtual CellularRadio* createME910C1WW(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + virtual CellularRadio* createGE910(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + virtual CellularRadio* createDE910(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + virtual CellularRadio* createCE910(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + virtual CellularRadio* createLE866A1JS(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); protected: typedef MTS::IO::CellularRadio* (CellularRadioFactory::*CREATEFUNCPTR)(const std::string& sPort); diff --git a/include/mts/MTS_IO_EG95Radio.h b/include/mts/MTS_IO_EG95Radio.h new file mode 100644 index 0000000..07db773 --- /dev/null +++ b/include/mts/MTS_IO_EG95Radio.h @@ -0,0 +1,15 @@ +#ifndef MTS_IO_EG95RADIO_H +#define MTS_IO_EG95RADIO_H + +#include "mts/MTS_IO_QuectelRadio.h" + +namespace MTS { + namespace IO { + class EG95Radio : public QuectelRadio + { + + }; + } +} + +#endif diff --git a/include/mts/MTS_IO_GE910Radio.h b/include/mts/MTS_IO_GE910Radio.h index 27efbac..4904ea7 100644 --- a/include/mts/MTS_IO_GE910Radio.h +++ b/include/mts/MTS_IO_GE910Radio.h @@ -29,12 +29,12 @@ #ifndef MTS_IO_GE910RADIO_H_ #define MTS_IO_GE910RADIO_H_ -#include +#include namespace MTS { namespace IO { - class GE910Radio : public CellularRadio { + class GE910Radio : public TelitRadio { public: static const std::string MODEL_NAME; diff --git a/include/mts/MTS_IO_HE910Radio.h b/include/mts/MTS_IO_HE910Radio.h index e6fc73c..c8700da 100644 --- a/include/mts/MTS_IO_HE910Radio.h +++ b/include/mts/MTS_IO_HE910Radio.h @@ -29,12 +29,12 @@ #ifndef MTS_IO_HE910RADIO_H_ #define MTS_IO_HE910RADIO_H_ -#include +#include namespace MTS { namespace IO { - class HE910Radio : public CellularRadio { + class HE910Radio : public TelitRadio { public: diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h new file mode 100644 index 0000000..da86946 --- /dev/null +++ b/include/mts/MTS_IO_ICellularRadio.h @@ -0,0 +1,399 @@ +#ifndef MTS_IO_ICELLULARRADIO_H +#define MTS_IO_ICELLULARRADIO_H + +#include +#include +#include + +#include + +#include +#include + +namespace MTS { + namespace IO { + class ICellularRadio; + namespace { + + static const std::string DEFAULT_RADIO_PORT; + static const std::string DEFAULT_RADIO_DIR; + + static const std::string VALUE_UNKNOWN; + static const std::string VALUE_UNAVAILABLE; + static const std::string VALUE_NOT_SUPPORTED; + + //Special Payload Characters + static const char ETX = 0; //Ends socket connection + static const char DLE = 0; //Escapes ETX and DLE within Payload + static const char CR = 0; + static const char NL = 0; + static const char CTRL_Z = 0; + + static const std::string RSP_OK; + static const std::string RSP_ERROR; + + static const std::string VALUE_NOT_REGISTERED; + static const std::string VALUE_REGISTERED; + static const std::string VALUE_SEARCHING; + static const std::string VALUE_DENIED; + static const std::string VALUE_ROAMING; + + //Static Data + static const std::string KEY_TYPE; //!< GSM or CDMA + static const std::string KEY_CODE; //!< Product Code : H5, H6, C2, EV3, G3 + static const std::string KEY_MODEL; //!< Model : HE910, CE910, DE910, GE910 + static const std::string KEY_MANUFACTURER; //!< Manufacturer: Telit + static const std::string KEY_HARDWARE; //!< Radio Hardware Version + static const std::string KEY_FIRMWARE; //!< Radio Firmware Version + static const std::string KEY_FIRMWARE_BUILD;//!< Radio Firmware Build + static const std::string KEY_IMEI; //!< International Mobile Station Equipment Identity + static const std::string KEY_MEID; //!< Mobile Equipment Identifier + static const std::string KEY_IMSI; //!< International Mobile Subscriber Identity + static const std::string KEY_MSID; //!< Mobil Station ID (MSID) aka MIN aka MSIN aka Last few digits of IMSI + static const std::string KEY_MDN; //!< Mobile Directory Number : Actual phone number dialed to reach radio + static const std::string KEY_CARRIER; //!< Cellular Service Provider (Home Network) + static const std::string KEY_ICCID; //!< Integrated Circuit Card Identifier + static const std::string KEY_MSL; //!< Master Subsidy Lock + + + //Network Status Data + static const std::string KEY_ROAMING; //!< Indicates whether or not using Home Network + static const std::string KEY_DATETIME; //!< Date and Time from tower + static const std::string KEY_SERVICE; //!< Service Connection Type [GPRS, EGPRS, WCDMA, HSDPA, 1xRTT, EVDO] + static const std::string KEY_NETWORK; //!< Cellular Service Provider + static const std::string KEY_NETWORK_REG; //!< Network Registration + static const std::string KEY_CID; //!< Cellular ID (Tower) in HEX + static const std::string KEY_LAC; //!< Location Area Code in HEX + static const std::string KEY_RAC; //!< Routing Area Code in HEX + static const std::string KEY_RSSI; //!< Received Signal Strength Indication + static const std::string KEY_RSSIDBM; //!< Received Signal Strength Indication in dBm + static const std::string KEY_MCC; //!< Mobile Country Code + static const std::string KEY_MNC; //!< Mobile Network (Operator) Code + static const std::string KEY_CHANNEL; //!< ARFCN or UARFCN Assigned Radio Channel + static const std::string KEY_TXPWR; //!< Transmit Power + static const std::string KEY_PSC; //!< Active Primary Synchronization Code (PSC) + static const std::string KEY_ECIO; //!< Active Ec/Io (chip energy per total wideband power in dBm) + static const std::string KEY_RSCP; //!< Active RSCP (Received Signal Code Power in dBm) + static const std::string KEY_DRX; //!< Discontinuous reception cycle length (ms) + static const std::string KEY_MM; //!< Mobility Management State + static const std::string KEY_RR; //!< Radio Resource State + static const std::string KEY_NOM; //!< Network Operator Mode + static const std::string KEY_ABND; //!< Active Band + static const std::string KEY_BLER; //!< Block Error Rate (percentage) + static const std::string KEY_SD; //!< Service Domain + static const std::string KEY_DEBUG; //!< Debug Information + + static const std::string KEY_MIP; //!< Mobile IP Information + static const std::string KEY_MIP_ID; //!< MIP Profile ID + static const std::string KEY_MIP_ENABLED; //!< MIP Profile Enabled/Disabled + static const std::string KEY_MIP_NAI; //!< Network Access Identifier + static const std::string KEY_MIP_HOMEADDRESS; //!< Home Address + static const std::string KEY_MIP_PRIMARYHA; //!< Primary Home Agent + static const std::string KEY_MIP_SECONDARYHA; //!< Secondary Home Agent + static const std::string KEY_MIP_MNAAASPI; //!< Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index + static const std::string KEY_MIP_MNHASPI; //!< Mobile Node Home Agent Security Server Parameter Index + static const std::string KEY_MIP_REVTUN; //!< Reverse Tunneling Enabled + static const std::string KEY_MIP_MNAAASS; //!< Mobile Node Authentication, Authorization, and Accounting Server Shared Secret + static const std::string KEY_MIP_MNHASS; //!< Mobile Node Home Agent Shared Secret + + + //Values - Type + static const std::string VALUE_TYPE_LTE; + static const std::string VALUE_TYPE_GSM; + static const std::string VALUE_TYPE_CDMA; + + //Values - Carrier + static const std::string VALUE_CARRIER_VERIZON; + static const std::string VALUE_CARRIER_AERIS; + static const std::string VALUE_CARRIER_SPRINT; + static const std::string VALUE_CARRIER_USCELLULAR; + static const std::string VALUE_CARRIER_ATT; + static const std::string VALUE_CARRIER_TMOBILE; + + static const std::string VALUE_SD_NO_SERVICE; + static const std::string VALUE_SD_CS_ONLY; + static const std::string VALUE_SD_PS_ONLY; + static const std::string VALUE_SD_CSPS; + + static const std::string VALUE_ABND_GSM_850; + static const std::string VALUE_ABND_GSM_900; + static const std::string VALUE_ABND_DCS_1800; + static const std::string VALUE_ABND_PCS_1900; + + static const std::vector DEFAULT_BAIL_STRINGS; + + typedef std::function IsNeedMoreData; + typedef std::function UpdateCb; + + /* + CODE convertModelToType(const std::string& sModel, std::string& sType); + CODE convertModelToMtsShortCode(const std::string& sModel, std::string& sCode, ICellularRadio *radioObj = NULL); + CODE convertServiceDomainToString(SERVICEDOMAIN eSd, std::string& sSd); + CODE convertActiveBandToString(ACTIVEBAND eBand, std::string& sBand); + + std::string sendCommand(MTS::AutoPtr& apIo, + const std::string& sCmd, + IsNeedMoreData& isNeedMoreData, + int32_t timeoutMillis = 100, + const char& ESC = CR); + + std::string sendCommand(MTS::AutoPtr& apIo, + const std::string& sCmd, + const std::vector& vBail = DEFAULT_BAIL_STRINGS, + int32_t timeoutMillis = 100, + const char& ESC = CR); + CODE test(MTS::AutoPtr& apIo, uint32_t timeoutSeconds = 30); + + std::string extractModelFromResult(const std::string& sResult); + std::string getCodeAsString(CODE code); + */ + + } + class ICellularRadio + { + public: + //Registration Values + enum REGISTRATION : uint8_t { + NOT_REGISTERED = 0, + REGISTERED = 1, + SEARCHING=2, + DENIED=3, + UNKNOWN=4, + ROAMING=5 + }; + + enum SERVICEDOMAIN : uint8_t { + NO_SERVICE = 0, + CS_ONLY = 1, + PS_ONLY = 2, + CSPS = 3 + }; + + enum ACTIVEBAND : uint8_t { + GSM_850 = 0, + GSM_900 = 1, + DCS_1800 = 2, + PCS_1900 = 3 + }; + + enum CODE : uint8_t { + SUCCESS = 0, + ERROR, + FAILURE, + NO_RESPONSE, + NOT_APPLICABLE, + INVALID_ARGS + }; + + enum SIMSTATUS : uint8_t { + READY = 0, + LOCKED, + BLOCKED, + NOT_INSERTED + }; + virtual ~ICellularRadio() = 0; + + virtual bool initialize(uint32_t iTimeoutMillis = 5000) = 0; + virtual bool resetRadio(uint32_t iTimeoutMillis = 5000) = 0; + virtual bool resetConnection(uint32_t iTimeoutMillis = 5000) = 0; + virtual void shutdown() = 0; + + virtual const std::string& getName() const = 0; + + virtual CODE getModel(std::string& sModel) = 0; + + virtual CODE getFirmware(std::string& sFirmware) = 0; + virtual CODE getFirmwareBuild(std::string& sFirmwareBuild) = 0; + virtual CODE getHardware(std::string& sHardware) = 0; + virtual CODE getManufacturer(std::string& sManufacturer) = 0; + virtual CODE getImei(std::string& sImei) = 0; + virtual CODE getMeid(std::string& sMeid) = 0; + virtual CODE getImsi(std::string& sImsi) = 0; + virtual CODE getSimStatus(std::string& sSimStatus) = 0; + virtual CODE getIccid(std::string& sIccid) = 0; + virtual CODE getService(std::string& sService) = 0; + virtual CODE getLac(std::string& sLac) = 0; + virtual CODE getMdn(std::string& sMdn) = 0; + virtual CODE getMsid(std::string& sMsid) = 0; + virtual CODE getType(std::string& sType) = 0; + virtual CODE getCarrier(std::string& sCarrier) = 0; + virtual CODE getNetwork(std::string& sNetwork) = 0; + virtual CODE getTower(std::string& sTower) = 0; + virtual CODE getTime(std::string& sDate, std::string& sTime, std::string& sTimeZone) = 0; + virtual CODE getRoaming(bool& bRoaming) = 0; + + virtual CODE getSignalStrength(int32_t& iRssi) = 0; + virtual CODE getModemLocation(std::string& sLocation) = 0; + virtual CODE convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& dBm) = 0; + virtual CODE convertdBmToSignalStrength(const int32_t& dBm, int32_t& iRssi) = 0; + + virtual CODE getRegistration(REGISTRATION& eRegistration) = 0; + virtual CODE convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration) = 0; + + //! Gather details of the radio's Mobile IP Profile + /*! + \param Json::Value object that will be populated with MIP data + \return Returns result code of gathering MIP + */ + virtual CODE getMipProfile(Json::Value& jMipProfile) = 0; + + /* + * jArgs = { + * "msl" : "Master Subsidy Lock (Aeris, Sprint): STRING" + * } + */ + virtual CODE validateMsl(const Json::Value& jArgs) = 0; + + /* + * jArgs = { + * "mdn" : "Mobile Directory Number : STRING", + * "msl" : "[OPTIONAL] Master Subsidy Lock (Aeris, Sprint): STRING" + * } + */ + virtual CODE setMdn(const Json::Value& jArgs) = 0; + + /* + * jArgs = { + * "msid" : "Mobil Station ID (MSID) aka MIN aka MSIN : STRING", + * "msl" : "[OPTIONAL] Master Subsidy Lock (Aeris, Sprint): STRING" + * } + */ + virtual CODE setMsid(const Json::Value& jArgs) = 0; + + /* + * jArgs = { + * "activeProfile" : "Set active profile: STRING" + * } + */ + virtual CODE setMipActiveProfile(const Json::Value& jArgs) = 0; + + /* + * jArgs = { + * "nai" : "Network Access Identifier : STRING" + * } + */ + virtual CODE setMipNai(const Json::Value& jArgs) = 0; + + /* + * jArgs = { + * "homeIp" : "Home Address : STRING" + * } + */ + virtual CODE setMipHomeIp(const Json::Value& jArgs) = 0; + + /* + * jArgs = { + * "primaryHa" : "Primary Home Agent : STRING" + * } + */ + virtual CODE setMipPrimaryHa(const Json::Value& jArgs) = 0; + + /* + * jArgs = { + * "secondaryHa" : "Secondary Home Agent : STRING" + * } + */ + virtual CODE setMipSecondaryHa(const Json::Value& jArgs) = 0; + + /* + * jArgs = { + * "mnAaaSpi" : "Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index : STRING" + * } + */ + virtual CODE setMipMnAaaSpi(const Json::Value& jArgs) = 0; + + /* + * jArgs = { + * "mnHaSpi" : "Mobile Node Home Agent Security Server Parameter Index : STRING" + * } + */ + virtual CODE setMipMnHaSpi(const Json::Value& jArgs) = 0; + + /* + * jArgs = { + * "revTun" : "[DESCRIPTION] : STRING" + * } + */ + virtual CODE setMipRevTun(const Json::Value& jArgs) = 0; + + /* + * jArgs = { + * "mnAaaSs" : "Mobile Node Authentication, Authorization, and Accounting Server Shared Secret : STRING" + * } + */ + virtual CODE setMipMnAaaSs(const Json::Value& jArgs) = 0; + + /* + * jArgs = { + * "mnHaSs" : "Mobile Node Home Agent Shared Secret : STRING" + * } + */ + virtual CODE setMipMnHaSs(const Json::Value& jArgs) = 0; + + /* + * jArgs = null + */ + virtual CODE updateDc(const Json::Value& jArgs, UpdateCb& stepCb) = 0; + + /* + * jArgs = null + */ + virtual CODE updatePrl(const Json::Value& jArgs, UpdateCb& stepCb) = 0; + + /* + * jArgs = null + */ + virtual CODE updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) = 0; + + /* + * jArgs = { + * "msl" : "Master Subsidy Lock (Sprint): STRING" + * } + */ + virtual CODE resetHfa(const Json::Value& jArgs, UpdateCb& stepCb) = 0; + + /* + * jArgs = { + * "mdn" : "Mobile Directory Number (Aeris): STRING" + * "msid" : "Mobile Station ID (Aeris): STRING" + * } + */ + virtual CODE activate(const Json::Value& jArgs, UpdateCb& stepCb) = 0; + + /* + * jArgs = { + * "enabled" : "RX Diversity Enabled ("0" or "1"): STRING" + * } + */ + virtual CODE setRxDiversity(const Json::Value& jArgs) = 0; + /* + * jArgs = { + * "fwid" : "Firmware Image To Be Enabled: STRING" + * } + */ + virtual CODE setActiveFirmware(const Json::Value& jArgs) = 0; + virtual CODE getActiveFirmware(std::string& sFwId) = 0; + + virtual CODE getEcho(bool& bEnabled) = 0; + virtual CODE setEcho(bool bEnabled = true) = 0; + + virtual CODE getStaticInformation(Json::Value& jData) = 0; + virtual CODE getNetworkStatus(Json::Value& jData) = 0; + + virtual CODE sendBasicCommand(const std::string& sCmd, int32_t timeoutMillis = 100, const char& ESC = CR) = 0; + + virtual std::string sendCommand(const std::string& sCmd, + const std::vector& vBail = DEFAULT_BAIL_STRINGS, + int32_t timeoutMillis = 100, + const char& ESC = CR) = 0; + + virtual std::string sendCommand(const std::string& sCmd, + IsNeedMoreData& isNeedMoreData, + int32_t timeoutMillis = 100, + const char& ESC = CR) = 0; + + }; + } +} + +#endif diff --git a/include/mts/MTS_IO_LE866Radio.h b/include/mts/MTS_IO_LE866Radio.h index c11c5b4..2775e4d 100644 --- a/include/mts/MTS_IO_LE866Radio.h +++ b/include/mts/MTS_IO_LE866Radio.h @@ -35,12 +35,12 @@ A more elaborate description */ -#include +#include namespace MTS { namespace IO { - class LE866Radio : public CellularRadio { + class LE866Radio : public TelitRadio { public: static const std::string MODEL_NAME; diff --git a/include/mts/MTS_IO_LE910Radio.h b/include/mts/MTS_IO_LE910Radio.h index e8ac21f..35e704d 100644 --- a/include/mts/MTS_IO_LE910Radio.h +++ b/include/mts/MTS_IO_LE910Radio.h @@ -29,12 +29,12 @@ #ifndef MTS_IO_LE910RADIO_H_ #define MTS_IO_LE910RADIO_H_ -#include +#include namespace MTS { namespace IO { - class LE910Radio : public CellularRadio { + class LE910Radio : public TelitRadio { public: static const std::string MODEL_NAME; diff --git a/include/mts/MTS_IO_ME910Radio.h b/include/mts/MTS_IO_ME910Radio.h index 91cdfc6..09e8ede 100644 --- a/include/mts/MTS_IO_ME910Radio.h +++ b/include/mts/MTS_IO_ME910Radio.h @@ -21,12 +21,12 @@ #ifndef MTS_IO_ME910RADIO_H_ #define MTS_IO_ME910RADIO_H_ -#include +#include namespace MTS { namespace IO { - class ME910Radio : public CellularRadio { + class ME910Radio : public TelitRadio { public: static const std::string MODEL_NAME; diff --git a/include/mts/MTS_IO_QuectelRadio.h b/include/mts/MTS_IO_QuectelRadio.h new file mode 100644 index 0000000..55eac60 --- /dev/null +++ b/include/mts/MTS_IO_QuectelRadio.h @@ -0,0 +1,15 @@ +#ifndef MTS_IO_QUECTELRADIO_H +#define MTS_IO_QUECTELRADIO_H + +#include + +namespace MTS { + namespace IO { + class QuectelRadio : public CellularRadio + { + + }; + } +} + +#endif diff --git a/include/mts/MTS_IO_TelitRadio.h b/include/mts/MTS_IO_TelitRadio.h new file mode 100644 index 0000000..f8fce6a --- /dev/null +++ b/include/mts/MTS_IO_TelitRadio.h @@ -0,0 +1,496 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts-io. + * + * libmts-io is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts-io is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts-io. If not, see . + * + */ + +#ifndef MTS_IO_TELITRADIO_H_ +#define MTS_IO_TELITRADIO_H_ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef struct +{ + const char *name; + int32_t low; + int32_t high; +} *pNameRangeMap, nameRangeMap; + +static const unsigned int NUM_GSM_BANDS = 7; +static const unsigned int NUM_WCDMA_BANDS = 6; +static const unsigned int NUM_LTE_BANDS = 42; + +// http://niviuk.free.fr/gsm_band.php +static const nameRangeMap GSMband[] = +{ + {"GSM 450", 259, 293}, {"GSM 480", 306, 340}, + {"GSM 750", 438, 511}, {"GSM 850", 128, 251}, + {"GSM 900 P", 1, 124}, {"GSM 900 E/R", 955, 1023}, + {"GSM DCS 1800/1900", 512, 885}, + +}; + +// http://niviuk.free.fr/umts_band.php +static const nameRangeMap WCDMAband[] = +{ + {"BAND I", 10592, 10838}, {"BAND II", 9662, 9938}, + {"BAND III", 1162, 1513}, {"BAND IV", 1537, 1738}, + {"BAND V", 4357, 4458}, {"BAND VI", 4387, 4413} +}; + +// http://niviuk.free.fr/lte_band.php +static const nameRangeMap EULTRAband[] = +{ + {"EUTRAN BAND1", 0, 599}, {"EUTRAN BAND2", 600, 1199}, + {"EUTRAN BAND3", 1200, 1949}, {"EUTRAN BAND4", 1950, 2399}, + {"EUTRAN BAND5", 2400, 2649}, {"EUTRAN BAND6", 2650, 2749}, + {"EUTRAN BAND7", 2750, 3449}, {"EUTRAN BAND8", 3450, 3799}, + {"EUTRAN BAND9", 3800, 4149}, {"EUTRAN BAND10", 4150, 4749}, + {"EUTRAN BAND11", 4750, 4999}, {"EUTRAN BAND12", 5000, 5179}, + {"EUTRAN BAND13", 5180, 5279}, {"EUTRAN BAND14", 5280, 5379}, + {"EUTRAN BAND17", 5730, 5849}, {"EUTRAN BAND18", 5850, 5999}, + {"EUTRAN BAND19", 6000, 6149}, {"EUTRAN BAND20", 6150, 6449}, + {"EUTRAN BAND21", 6450, 6525}, {"EUTRAN BAND22", 6600, 7399}, + {"EUTRAN BAND23", 7500, 7699}, {"EUTRAN BAND24", 7700, 8039}, + {"EUTRAN BAND25", 8040, 8689}, {"EUTRAN BAND26", 8690, 9039}, + {"EUTRAN BAND27", 9040, 9209}, {"EUTRAN BAND28", 9210, 9659}, + {"EUTRAN BAND29", 9660, 9769}, {"EUTRAN BAND30", 9770, 9869}, + {"EUTRAN BAND31", 9870, 9919}, {"EUTRAN BAND32", 9920, 10359}, + {"EUTRAN BAND33", 36000, 36199}, {"EUTRAN BAND34", 36200, 36349}, + {"EUTRAN BAND35", 36350, 36949}, {"EUTRAN BAND36", 36950, 37549}, + {"EUTRAN BAND37", 37550, 37749}, {"EUTRAN BAND38", 37750, 38249}, + {"EUTRAN BAND39", 38250, 38649}, {"EUTRAN BAND40", 38650, 39649}, + {"EUTRAN BAND41", 39650, 41589}, {"EUTRAN BAND42", 41590, 43589}, + {"EUTRAN BAND43", 43590, 45589}, {"EUTRAN BAND44", 45590, 46589} +}; + +namespace MTS { + namespace IO { + + class TelitRadio : public CellularRadio { + + public: + static const std::string DEFAULT_RADIO_PORT; + static const std::string DEFAULT_RADIO_DIR; + + static const std::string VALUE_UNKNOWN; + static const std::string VALUE_UNAVAILABLE; + static const std::string VALUE_NOT_SUPPORTED; + + //Special Payload Characters + static const char ETX; //Ends socket connection + static const char DLE; //Escapes ETX and DLE within Payload + static const char CR; + static const char NL; + static const char CTRL_Z; + + static const std::string RSP_OK; + static const std::string RSP_ERROR; + + static const std::string VALUE_NOT_REGISTERED; + static const std::string VALUE_REGISTERED; + static const std::string VALUE_SEARCHING; + static const std::string VALUE_DENIED; + static const std::string VALUE_ROAMING; + + //Static Data + static const std::string KEY_TYPE; //!< GSM or CDMA + static const std::string KEY_CODE; //!< Product Code : H5, H6, C2, EV3, G3 + static const std::string KEY_MODEL; //!< Model : HE910, CE910, DE910, GE910 + static const std::string KEY_MANUFACTURER; //!< Manufacturer: Telit + static const std::string KEY_HARDWARE; //!< Radio Hardware Version + static const std::string KEY_FIRMWARE; //!< Radio Firmware Version + static const std::string KEY_FIRMWARE_BUILD;//!< Radio Firmware Build + static const std::string KEY_IMEI; //!< International Mobile Station Equipment Identity + static const std::string KEY_MEID; //!< Mobile Equipment Identifier + static const std::string KEY_IMSI; //!< International Mobile Subscriber Identity + static const std::string KEY_MSID; //!< Mobil Station ID (MSID) aka MIN aka MSIN aka Last few digits of IMSI + static const std::string KEY_MDN; //!< Mobile Directory Number : Actual phone number dialed to reach radio + static const std::string KEY_CARRIER; //!< Cellular Service Provider (Home Network) + static const std::string KEY_ICCID; //!< Integrated Circuit Card Identifier + static const std::string KEY_MSL; //!< Master Subsidy Lock + + + //Network Status Data + static const std::string KEY_ROAMING; //!< Indicates whether or not using Home Network + static const std::string KEY_DATETIME; //!< Date and Time from tower + static const std::string KEY_SERVICE; //!< Service Connection Type [GPRS, EGPRS, WCDMA, HSDPA, 1xRTT, EVDO] + static const std::string KEY_NETWORK; //!< Cellular Service Provider + static const std::string KEY_NETWORK_REG; //!< Network Registration + static const std::string KEY_CID; //!< Cellular ID (Tower) in HEX + static const std::string KEY_LAC; //!< Location Area Code in HEX + static const std::string KEY_RAC; //!< Routing Area Code in HEX + static const std::string KEY_RSSI; //!< Received Signal Strength Indication + static const std::string KEY_RSSIDBM; //!< Received Signal Strength Indication in dBm + static const std::string KEY_MCC; //!< Mobile Country Code + static const std::string KEY_MNC; //!< Mobile Network (Operator) Code + static const std::string KEY_CHANNEL; //!< ARFCN or UARFCN Assigned Radio Channel + static const std::string KEY_TXPWR; //!< Transmit Power + static const std::string KEY_PSC; //!< Active Primary Synchronization Code (PSC) + static const std::string KEY_ECIO; //!< Active Ec/Io (chip energy per total wideband power in dBm) + static const std::string KEY_RSCP; //!< Active RSCP (Received Signal Code Power in dBm) + static const std::string KEY_DRX; //!< Discontinuous reception cycle length (ms) + static const std::string KEY_MM; //!< Mobility Management State + static const std::string KEY_RR; //!< Radio Resource State + static const std::string KEY_NOM; //!< Network Operator Mode + static const std::string KEY_ABND; //!< Active Band + static const std::string KEY_BLER; //!< Block Error Rate (percentage) + static const std::string KEY_SD; //!< Service Domain + static const std::string KEY_DEBUG; //!< Debug Information + + static const std::string KEY_MIP; //!< Mobile IP Information + static const std::string KEY_MIP_ID; //!< MIP Profile ID + static const std::string KEY_MIP_ENABLED; //!< MIP Profile Enabled/Disabled + static const std::string KEY_MIP_NAI; //!< Network Access Identifier + static const std::string KEY_MIP_HOMEADDRESS; //!< Home Address + static const std::string KEY_MIP_PRIMARYHA; //!< Primary Home Agent + static const std::string KEY_MIP_SECONDARYHA; //!< Secondary Home Agent + static const std::string KEY_MIP_MNAAASPI; //!< Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index + static const std::string KEY_MIP_MNHASPI; //!< Mobile Node Home Agent Security Server Parameter Index + static const std::string KEY_MIP_REVTUN; //!< Reverse Tunneling Enabled + static const std::string KEY_MIP_MNAAASS; //!< Mobile Node Authentication, Authorization, and Accounting Server Shared Secret + static const std::string KEY_MIP_MNHASS; //!< Mobile Node Home Agent Shared Secret + + + //Values - Type + static const std::string VALUE_TYPE_LTE; + static const std::string VALUE_TYPE_GSM; + static const std::string VALUE_TYPE_CDMA; + + //Values - Carrier + static const std::string VALUE_CARRIER_VERIZON; + static const std::string VALUE_CARRIER_AERIS; + static const std::string VALUE_CARRIER_SPRINT; + static const std::string VALUE_CARRIER_USCELLULAR; + static const std::string VALUE_CARRIER_ATT; + static const std::string VALUE_CARRIER_TMOBILE; + + static const std::string VALUE_SD_NO_SERVICE; + static const std::string VALUE_SD_CS_ONLY; + static const std::string VALUE_SD_PS_ONLY; + static const std::string VALUE_SD_CSPS; + + static const std::string VALUE_ABND_GSM_850; + static const std::string VALUE_ABND_GSM_900; + static const std::string VALUE_ABND_DCS_1800; + static const std::string VALUE_ABND_PCS_1900; + + static const std::vector DEFAULT_BAIL_STRINGS; + + typedef std::function IsNeedMoreData; + typedef std::function UpdateCb; + + virtual ~TelitRadio(); + + virtual bool initialize(uint32_t iTimeoutMillis = 5000); + virtual bool resetRadio(uint32_t iTimeoutMillis = 5000); + virtual bool resetConnection(uint32_t iTimeoutMillis = 5000); + virtual void shutdown(); + + const std::string& getName() const; + + virtual CODE getModel(std::string& sModel); + static CODE convertModelToType(const std::string& sModel, std::string& sType); + static CODE convertModelToMtsShortCode(const std::string& sModel, std::string& sCode, TelitRadio *radioObj = NULL); + static CODE convertServiceDomainToString(SERVICEDOMAIN eSd, std::string& sSd); + static CODE convertActiveBandToString(ACTIVEBAND eBand, std::string& sBand); + + virtual CODE getFirmware(std::string& sFirmware); + virtual CODE getFirmwareBuild(std::string& sFirmwareBuild); + virtual CODE getHardware(std::string& sHardware); + virtual CODE getManufacturer(std::string& sManufacturer); + virtual CODE getImei(std::string& sImei); + virtual CODE getMeid(std::string& sMeid); + virtual CODE getImsi(std::string& sImsi); + virtual CODE getSimStatus(std::string& sSimStatus); + virtual CODE getIccid(std::string& sIccid); + virtual CODE getService(std::string& sService); + virtual CODE getLac(std::string& sLac); + virtual CODE getMdn(std::string& sMdn); + virtual CODE getMsid(std::string& sMsid); + virtual CODE getType(std::string& sType); + virtual CODE getCarrier(std::string& sCarrier); + virtual CODE getNetwork(std::string& sNetwork); + virtual CODE getTower(std::string& sTower); + virtual CODE getTime(std::string& sDate, std::string& sTime, std::string& sTimeZone); + virtual CODE getRoaming(bool& bRoaming); + + virtual CODE getSignalStrength(int32_t& iRssi); + virtual CODE getModemLocation(std::string& sLocation); + virtual CODE convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& dBm); + virtual CODE convertdBmToSignalStrength(const int32_t& dBm, int32_t& iRssi); + + virtual CODE getRegistration(REGISTRATION& eRegistration); + virtual CODE convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration); + + //! Gather details of the radio's Mobile IP Profile + /*! + \param Json::Value object that will be populated with MIP data + \return Returns result code of gathering MIP + */ + virtual CODE getMipProfile(Json::Value& jMipProfile); + + /* + * jArgs = { + * "msl" : "Master Subsidy Lock (Aeris, Sprint): STRING" + * } + */ + virtual CODE validateMsl(const Json::Value& jArgs); + + /* + * jArgs = { + * "mdn" : "Mobile Directory Number : STRING", + * "msl" : "[OPTIONAL] Master Subsidy Lock (Aeris, Sprint): STRING" + * } + */ + virtual CODE setMdn(const Json::Value& jArgs); + + /* + * jArgs = { + * "msid" : "Mobil Station ID (MSID) aka MIN aka MSIN : STRING", + * "msl" : "[OPTIONAL] Master Subsidy Lock (Aeris, Sprint): STRING" + * } + */ + virtual CODE setMsid(const Json::Value& jArgs); + + /* + * jArgs = { + * "activeProfile" : "Set active profile: STRING" + * } + */ + virtual CODE setMipActiveProfile(const Json::Value& jArgs); + + /* + * jArgs = { + * "nai" : "Network Access Identifier : STRING" + * } + */ + virtual CODE setMipNai(const Json::Value& jArgs); + + /* + * jArgs = { + * "homeIp" : "Home Address : STRING" + * } + */ + virtual CODE setMipHomeIp(const Json::Value& jArgs); + + /* + * jArgs = { + * "primaryHa" : "Primary Home Agent : STRING" + * } + */ + virtual CODE setMipPrimaryHa(const Json::Value& jArgs); + + /* + * jArgs = { + * "secondaryHa" : "Secondary Home Agent : STRING" + * } + */ + virtual CODE setMipSecondaryHa(const Json::Value& jArgs); + + /* + * jArgs = { + * "mnAaaSpi" : "Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index : STRING" + * } + */ + virtual CODE setMipMnAaaSpi(const Json::Value& jArgs); + + /* + * jArgs = { + * "mnHaSpi" : "Mobile Node Home Agent Security Server Parameter Index : STRING" + * } + */ + virtual CODE setMipMnHaSpi(const Json::Value& jArgs); + + /* + * jArgs = { + * "revTun" : "[DESCRIPTION] : STRING" + * } + */ + virtual CODE setMipRevTun(const Json::Value& jArgs); + + /* + * jArgs = { + * "mnAaaSs" : "Mobile Node Authentication, Authorization, and Accounting Server Shared Secret : STRING" + * } + */ + virtual CODE setMipMnAaaSs(const Json::Value& jArgs); + + /* + * jArgs = { + * "mnHaSs" : "Mobile Node Home Agent Shared Secret : STRING" + * } + */ + virtual CODE setMipMnHaSs(const Json::Value& jArgs); + + /* + * jArgs = null + */ + virtual CODE updateDc(const Json::Value& jArgs, UpdateCb& stepCb); + + /* + * jArgs = null + */ + virtual CODE updatePrl(const Json::Value& jArgs, UpdateCb& stepCb); + + /* + * jArgs = null + */ + virtual CODE updateFumo(const Json::Value& jArgs, UpdateCb& stepCb); + + /* + * jArgs = { + * "msl" : "Master Subsidy Lock (Sprint): STRING" + * } + */ + virtual CODE resetHfa(const Json::Value& jArgs, UpdateCb& stepCb); + + /* + * jArgs = { + * "mdn" : "Mobile Directory Number (Aeris): STRING" + * "msid" : "Mobile Station ID (Aeris): STRING" + * } + */ + virtual CODE activate(const Json::Value& jArgs, UpdateCb& stepCb); + + /* + * jArgs = { + * "enabled" : "RX Diversity Enabled ("0" or "1"): STRING" + * } + */ + virtual CODE setRxDiversity(const Json::Value& jArgs)=0; + /* + * jArgs = { + * "fwid" : "Firmware Image To Be Enabled: STRING" + * } + */ + virtual CODE setActiveFirmware(const Json::Value& jArgs); + virtual CODE getActiveFirmware(std::string& sFwId); + + virtual CODE getEcho(bool& bEnabled); + virtual CODE setEcho(bool bEnabled = true); + + virtual CODE getStaticInformation(Json::Value& jData); + virtual CODE getNetworkStatus(Json::Value& jData); + + virtual CODE sendBasicCommand(const std::string& sCmd, int32_t timeoutMillis = 100, const char& ESC = CR); + + virtual std::string sendCommand(const std::string& sCmd, + const std::vector& vBail = DEFAULT_BAIL_STRINGS, + int32_t timeoutMillis = 100, + const char& ESC = CR); + + + static std::string sendCommand(MTS::AutoPtr& apIo, + const std::string& sCmd, + const std::vector& vBail = DEFAULT_BAIL_STRINGS, + int32_t timeoutMillis = 100, + const char& ESC = CR); + + virtual std::string sendCommand(const std::string& sCmd, + IsNeedMoreData& isNeedMoreData, + int32_t timeoutMillis = 100, + const char& ESC = CR); + + static std::string sendCommand(MTS::AutoPtr& apIo, + const std::string& sCmd, + IsNeedMoreData& isNeedMoreData, + int32_t timeoutMillis = 100, + const char& ESC = CR); + + static CODE test(MTS::AutoPtr& apIo, uint32_t timeoutSeconds = 30); + + static std::string extractModelFromResult(const std::string& sResult); + static std::string getCodeAsString(CODE code); + + protected: + + TelitRadio(const std::string& sName, const std::string& sRadioPort); + + virtual bool getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier); + virtual bool getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware); + + virtual void getCommonNetworkStats(Json::Value& jData); + + void initMipProfile(Json::Value& jData); + + bool splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType = Json::ValueType::stringValue); + + + + private: + class RadioBandMap { + public: + RadioBandMap() + { + m_sChannel = TelitRadio::VALUE_UNKNOWN; + m_iChannel = 0; + m_sRadioType = TelitRadio::VALUE_UNKNOWN; + } + + RadioBandMap(const std::string &channel, const std::string &radioType) : + m_sChannel(channel), + m_sRadioType(radioType) + { + m_iChannel = strtol(m_sChannel.c_str(), NULL, 10); + } + + virtual ~RadioBandMap() {} + + const char *getRadioBandName(); + const char *getRadioBandName(const std::string &channel, const std::string &radioType); + + private: + + const char *getLTEBand(const int channel); + const char *getCDMABand(const int channel); + const char *getGSMBand(const int channel); + + std::string m_sChannel; + int m_iChannel; + std::string m_sRadioType; + }; + + std::string m_sName; + std::string m_sRadioPort; + std::string m_sFirmware; + std::string m_sCarrier; + MTS::AutoPtr m_apIo; + + bool m_bEchoEnabled; + bool m_bEnableEchoOnClose; + + std::string queryLteLac(); + std::string queryCGREGstring(); + void setCGREG(std::string value); + }; + } +} + + + +#endif diff --git a/src/MTS_IO_CdmaRadio.cpp b/src/MTS_IO_CdmaRadio.cpp index 8057650..4ff5d63 100644 --- a/src/MTS_IO_CdmaRadio.cpp +++ b/src/MTS_IO_CdmaRadio.cpp @@ -35,7 +35,7 @@ using namespace MTS::IO; CdmaRadio::CdmaRadio(const std::string& sName, const std::string& sPort) -: CellularRadio(sName, sPort) +: TelitRadio(sName, sPort) { } diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index f89e673..a29d14f 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -18,1820 +18,4 @@ * */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -using namespace MTS::IO; - -const char CellularRadio::ETX = 0x03; //Ends socket connection -const char CellularRadio::DLE = 0x10; //Escapes ETX and DLE within Payload -const char CellularRadio::CR = 0x0D; -const char CellularRadio::NL = 0x0A; -const char CellularRadio::CTRL_Z = 0x1A; - -const std::string CellularRadio::RSP_ERROR("ERROR"); -const std::string CellularRadio::RSP_OK("OK"); - - -const std::string CellularRadio::DEFAULT_RADIO_PORT("/dev/modem_at1"); -const std::string CellularRadio::DEFAULT_RADIO_DIR("/var/run/radio/"); -const std::string CellularRadio::VALUE_UNKNOWN("Unknown"); -const std::string CellularRadio::VALUE_UNAVAILABLE("Unavailable"); -const std::string CellularRadio::VALUE_NOT_SUPPORTED("Not Supported"); - -const std::string CellularRadio::VALUE_NOT_REGISTERED("NOT REGISTERED"); -const std::string CellularRadio::VALUE_REGISTERED("REGISTERED"); -const std::string CellularRadio::VALUE_SEARCHING("SEARCHING"); -const std::string CellularRadio::VALUE_DENIED("DENIED"); -const std::string CellularRadio::VALUE_ROAMING("ROAMING"); - -//Static Data -const std::string CellularRadio::KEY_TYPE("type"); //!< GSM or CDMA -const std::string CellularRadio::KEY_CODE("code"); //!< Product Code : H5, H6, C2, EV3, G3 -const std::string CellularRadio::KEY_MODEL("model"); //!< Model : HE910, LE910, CE910, DE910, GE910 -const std::string CellularRadio::KEY_MANUFACTURER("manufacturer"); //!< Manufacturer: Telit -const std::string CellularRadio::KEY_HARDWARE("hardware"); //!< Radio Hardware Version -const std::string CellularRadio::KEY_FIRMWARE("firmware"); //!< Radio Firmware Version -const std::string CellularRadio::KEY_FIRMWARE_BUILD("firmwarebuild"); //!< Radio Firmware Build - -const std::string CellularRadio::KEY_CARRIER("carrier"); //!< Cellular Service Provider (Home Network) -const std::string CellularRadio::VALUE_CARRIER_VERIZON("Verizon"); -const std::string CellularRadio::VALUE_CARRIER_AERIS("Aeris"); -const std::string CellularRadio::VALUE_CARRIER_SPRINT("Sprint"); -const std::string CellularRadio::VALUE_CARRIER_USCELLULAR("U.S. Cellular"); -const std::string CellularRadio::VALUE_CARRIER_ATT("AT&T"); -const std::string CellularRadio::VALUE_CARRIER_TMOBILE("T-Mobile"); - -const std::string CellularRadio::KEY_IMEI("imei"); //!< International Mobile Station Equipment Identity -const std::string CellularRadio::KEY_MEID("meid"); //!< Mobile Equipment Identifier -const std::string CellularRadio::KEY_IMSI("imsi"); //!< International Mobile Subscriber Identity -const std::string CellularRadio::KEY_MSID("msid"); //!< Mobil Station ID / Mobile Identification Number (MSID/MIN) (CDMA-Only) -const std::string CellularRadio::KEY_MDN("mdn"); //!< Mobile Directory Number : Actual phone number dialed to reach radio -const std::string CellularRadio::KEY_ICCID("iccid"); //!< Integrated Circuit Card Identifier -const std::string CellularRadio::KEY_MSL("msl"); //!< Master Subsidy Lock - -//Dynamic Data -const std::string CellularRadio::KEY_ROAMING("roaming"); //!< Indicates whether or not using Home Network -const std::string CellularRadio::KEY_DATETIME("datetime"); //!< Date and Time from tower -const std::string CellularRadio::KEY_SERVICE("service"); //!< Service Connection Type [GPRS, EGPRS, WCDMA, HSDPA, 1xRTT, EVDO] -const std::string CellularRadio::KEY_NETWORK("network"); //!< Cellular Service Provider -const std::string CellularRadio::KEY_NETWORK_REG("netreg"); //!< Network Registration -const std::string CellularRadio::KEY_CID("cid"); //!< Cellular ID (Tower) in HEX -const std::string CellularRadio::KEY_LAC("lac"); //!< Location Area Code in HEX -const std::string CellularRadio::KEY_RAC("rac"); //!< Routing Area Code in HEX -const std::string CellularRadio::KEY_RSSI("rssi"); //!< Signal Strength -const std::string CellularRadio::KEY_RSSIDBM("rssidBm"); //!< Signal Strength in dBm -const std::string CellularRadio::KEY_MCC("mcc"); //!< Country Code -const std::string CellularRadio::KEY_MNC("mnc"); //!< Operator Code -const std::string CellularRadio::KEY_CHANNEL("channel"); //!< ARFCN or UARFCN Assigned Radio Channel -const std::string CellularRadio::KEY_TXPWR("txpwr"); //!< Transmit Power -const std::string CellularRadio::KEY_PSC("psc"); //!< Active Primary Synchronization Code (PSC) -const std::string CellularRadio::KEY_ECIO("ecio"); //!< Active Ec/Io (chip energy per total wideband power in dBm) -const std::string CellularRadio::KEY_RSCP("rscp"); //!< Active RSCP (Received Signal Code Power in dBm) -const std::string CellularRadio::KEY_DRX("drx"); //!< Discontinuous reception cycle length (ms) -const std::string CellularRadio::KEY_MM("mm"); //!< Mobility Management State -const std::string CellularRadio::KEY_RR("rr"); //!< Radio Resource State -const std::string CellularRadio::KEY_NOM("nom"); //!< Network Operator Mode -const std::string CellularRadio::KEY_ABND("abnd"); //!< Active Band -const std::string CellularRadio::KEY_BLER("bler"); //!< Block Error Rate (percentage) -const std::string CellularRadio::KEY_SD("sd"); //!< Service Domain -const std::string CellularRadio::KEY_DEBUG("debug"); //!< Debug Information - -const std::string CellularRadio::KEY_MIP("mipProfile"); //!< Mobile IP Information -const std::string CellularRadio::KEY_MIP_ID("id"); //!< Mobile IP ID -const std::string CellularRadio::KEY_MIP_ENABLED("enabled"); //!< Mobile IP Enabled/Disabled -const std::string CellularRadio::KEY_MIP_NAI("nai"); //!< Network Access Identifier -const std::string CellularRadio::KEY_MIP_HOMEADDRESS("homeAddress"); //!< Home Address -const std::string CellularRadio::KEY_MIP_PRIMARYHA("primaryAddress"); //!< Primary Home Agent -const std::string CellularRadio::KEY_MIP_SECONDARYHA("secondaryAddress"); //!< Secondary Home Agent -const std::string CellularRadio::KEY_MIP_MNAAASPI("mnAaaSpi"); //!< Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index -const std::string CellularRadio::KEY_MIP_MNHASPI("mnHaSpi"); //!< Mobile Node Home Agent Security Server Parameter Index -const std::string CellularRadio::KEY_MIP_REVTUN("revTun"); //!< Reverse Tunneling Enabled -const std::string CellularRadio::KEY_MIP_MNAAASS("mnAaaSs"); //!< Mobile Node Authentication, Authorization, and Accounting Server Shared Secret -const std::string CellularRadio::KEY_MIP_MNHASS("mnHaSs"); //!< Mobile Node Home Agent Shared Secret - -const std::string CellularRadio::VALUE_TYPE_GSM("GSM"); -const std::string CellularRadio::VALUE_TYPE_LTE("LTE"); -const std::string CellularRadio::VALUE_TYPE_CDMA("CDMA"); - -const std::string CellularRadio::VALUE_SD_NO_SERVICE("NO SERVICE"); -const std::string CellularRadio::VALUE_SD_CS_ONLY("CS ONLY"); -const std::string CellularRadio::VALUE_SD_PS_ONLY("PS ONLY"); -const std::string CellularRadio::VALUE_SD_CSPS("CS+PS"); - -const std::string CellularRadio::VALUE_ABND_GSM_850("GSM 850"); -const std::string CellularRadio::VALUE_ABND_GSM_900("GSM 900"); -const std::string CellularRadio::VALUE_ABND_DCS_1800("DCS 1800"); -const std::string CellularRadio::VALUE_ABND_PCS_1900("PCS 1900"); - -const std::vector CellularRadio::DEFAULT_BAIL_STRINGS = { CellularRadio::RSP_OK, CellularRadio::RSP_ERROR }; - -CellularRadio::CellularRadio(const std::string& sName, const std::string& sRadioPort) -: m_sName(sName) -, m_sRadioPort(sRadioPort) -, m_bEchoEnabled(false) -, m_bEnableEchoOnClose(false) -{ - m_apIo.reset(new MTS::IO::SerialConnection( - MTS::IO::SerialConnection::Builder(m_sRadioPort) - .baudRate(115200) - .useLockFile() - .build())); -} - - -CellularRadio::~CellularRadio() { - shutdown(); - m_apIo.reset(); -} - -bool CellularRadio::initialize(uint32_t iTimeoutMillis) { - if(!m_apIo->open(iTimeoutMillis)) { - printError("%s| Failed to open radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str()); - return false; - } - - bool bEnabled; - CODE eCode = getEcho(bEnabled); - if(eCode == SUCCESS && bEnabled) { - printDebug("%s| Disabling 'echo'", m_sName.c_str()); - setEcho(false); - m_bEnableEchoOnClose = true; - } - - return true; -} - -bool CellularRadio::resetRadio(uint32_t iTimeoutMillis) { - - printInfo("%s| Rebooting radio", m_sName.c_str()); - if(sendBasicCommand("AT#REBOOT") == SUCCESS) { - if(iTimeoutMillis > 5000) { - MTS::Thread::sleep(5000); - iTimeoutMillis -= 5000; - } - return resetConnection(iTimeoutMillis); - } - - return false; -} - -bool CellularRadio::resetConnection(uint32_t iTimeoutMillis) { - //Close Current Connection - if(!m_apIo.isNull()) { - m_apIo->close(); - } - - m_apIo.reset(new MTS::IO::SerialConnection( - MTS::IO::SerialConnection::Builder(m_sRadioPort) - .baudRate(115200) - .useLockFile() - .build())); - - //Try to obtain the device port over the given period of time - MTS::Timer oTimer; - oTimer.start(); - uint64_t iCurrentTime = 0; - while(iCurrentTime < iTimeoutMillis) { - - if(!m_apIo->open(iTimeoutMillis - iCurrentTime)) { - printWarning("%s| Failed to re-open radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str()); - } else { - printInfo("%s| Successfully re-opened radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str()); - printDebug("%s| Recovering 'echo' after connection reset", m_sName.c_str()); // see CellularRadio::initialize - setEcho(m_bEchoEnabled); - break; - } - - ::usleep(500000); //500 millis - iCurrentTime = oTimer.getMillis(); - } - oTimer.stop(); - return !m_apIo->isClosed(); -} - -void CellularRadio::shutdown() { - - if(!m_apIo.isNull()) { - if(m_bEnableEchoOnClose) { - printDebug("%s| Enabling 'echo'", m_sName.c_str()); - setEcho(true); - m_bEnableEchoOnClose = false; - } - m_apIo->close(); - } -} - -const std::string& CellularRadio::getName() const { - return m_sName; -} - - -CellularRadio::CODE CellularRadio::getModel(std::string& sModel) { - printTrace("%s| Get Model", m_sName.c_str()); - //Always returns SUCCESS because the model should be m_sName - sModel = m_sName; - std::string sCmd("ATI4"); - std::string sResult = CellularRadio::sendCommand(m_apIo, sCmd); - if (sResult.find("OK") == std::string::npos) { - printWarning("%s| Unable to get model from radio. Returning [%s]", m_sName.c_str(), m_sName.c_str()); - return SUCCESS; - } else { - sModel = CellularRadio::extractModelFromResult(sResult); - if(sModel.size() == 0) { - printWarning("%s| Unable to get model from radio. Returning [%s]", m_sName.c_str(), m_sName.c_str()); - return SUCCESS; - } - } - - printDebug("%s| Extracted [%s] from [%s] query", m_sName.c_str(), sModel.c_str(), sCmd.c_str()); - if(sModel != m_sName) { - printWarning("%s| Model identified [%s] does not match expected [%s]. Returning [%s]", - m_sName.c_str(), sModel.c_str(), m_sName.c_str(), sModel.c_str()); - } - - return SUCCESS; -} - -CellularRadio::CODE CellularRadio::convertModelToMtsShortCode(const std::string& sModel, std::string& sCode, CellularRadio *radioObject) { - CODE eCode = FAILURE; - - if(sModel.find("HE910-D") == 0) { - sCode = "H5"; - eCode = SUCCESS; - } else if (sModel.find("HE910-EUD") == 0) { - sCode = "H6"; - eCode = SUCCESS; - } else if (sModel.find("LE910-JN1") == 0) { - sCode = "LDC3"; - eCode = SUCCESS; - } else if (sModel.find("LE866A1-JS") == 0) { - sCode = "LSB3"; - eCode = SUCCESS; - } else if (sModel.find("LE910-NAG") == 0) { - sCode = "LAT1"; - eCode = SUCCESS; - } else if (sModel.find("LE910C4-NF") == 0) { - sCode = "L4N1"; - eCode = SUCCESS; - } else if (sModel.find("LE910-NA1") == 0) { - if (NULL == radioObject) { - sCode = VALUE_NOT_SUPPORTED; - eCode = ERROR; - } else { - std::string sValue; - eCode = radioObject->getActiveFirmware(sValue); - if (eCode == SUCCESS) { - sCode = "LNA3"; - } else { - sCode = "LAT3"; - } - } - eCode = SUCCESS; - } else if (sModel.find("LE910-SVG") == 0) { - sCode = "LVW2"; - eCode = SUCCESS; - } else if (sModel.find("LE910C1-NS") == 0) { - sCode = "LSP3"; - eCode = SUCCESS; - } else if (sModel.find("LE910C1-AP") == 0) { - sCode = "LAP3"; - eCode = SUCCESS; - } else if (sModel.find("ME910C1-NA") == 0) { - sCode = "MAT1"; - eCode = SUCCESS; - } else if (sModel.find("ME910C1-NV") == 0) { - sCode = "MVW1"; - eCode = SUCCESS; - } else if (sModel.find("ME910C1-WW") == 0) { - sCode = "MNG2"; - eCode = SUCCESS; - } else if (sModel.find("LE910-EUG") == 0) { - sCode = "LEU1"; - eCode = SUCCESS; - } else if (sModel.find("LE910C4-EU") == 0) { - sCode = "L4E1"; - eCode = SUCCESS; - } else if (sModel.find("LE910-EU1") == 0) { - sCode = "LEU3"; - eCode = SUCCESS; - } else if (sModel.find("GE910") == 0) { - sCode = "G3"; - eCode = SUCCESS; - } else if (sModel.find("CE910") == 0) { - sCode = "C2"; - eCode = SUCCESS; - } else if (sModel.find("DE910") == 0) { - sCode = "EV3"; - eCode = SUCCESS; - } else { - sCode = VALUE_NOT_SUPPORTED; - printError("RADIO| Could not identify MTS short code from model. [%s]", sModel.c_str()); - eCode = ERROR; - } - return eCode; -} - -CellularRadio::CODE CellularRadio::convertServiceDomainToString(SERVICEDOMAIN eSd, std::string& sSd) { - CODE eCode = FAILURE; - switch(eSd) { - case NO_SERVICE: sSd = VALUE_SD_NO_SERVICE; eCode = SUCCESS; break; - case CS_ONLY: sSd = VALUE_SD_CS_ONLY; eCode = SUCCESS; break; - case PS_ONLY: sSd = VALUE_SD_PS_ONLY; eCode = SUCCESS; break; - case CSPS: sSd = VALUE_SD_CSPS; eCode = SUCCESS; break; - default: sSd = VALUE_UNKNOWN; eCode = FAILURE; break; - } - return eCode; -} - -CellularRadio::CODE CellularRadio::convertActiveBandToString(ACTIVEBAND eBand, std::string& sBand) { - CODE eCode = FAILURE; - switch(eBand) { - case GSM_850: sBand = VALUE_ABND_GSM_850; eCode = SUCCESS; break; - case GSM_900: sBand = VALUE_ABND_GSM_900; eCode = SUCCESS; break; - case DCS_1800: sBand = VALUE_ABND_DCS_1800; eCode = SUCCESS; break; - case PCS_1900: sBand = VALUE_ABND_PCS_1900; eCode = SUCCESS; break; - default: sBand = VALUE_UNKNOWN; eCode = FAILURE; break; - } - return eCode; -} - -CellularRadio::CODE CellularRadio::convertModelToType(const std::string& sModel, std::string& sType) { - CODE eCode = FAILURE; - sType = VALUE_NOT_SUPPORTED; - - if(sModel.find("HE910-D") == 0) { - sType = VALUE_TYPE_GSM; - eCode = SUCCESS; - } else if (sModel.find("HE910-EUD") == 0) { - sType = VALUE_TYPE_GSM; - eCode = SUCCESS; - } else if (sModel.find("LE910-JN1") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE866A1-JS") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE910-NAG") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE910C4-NF") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE910-NA1") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE910-SVG") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE910-EUG") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE910C4-EU") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE910-EU1") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE910C1-NS") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE910C1-AP") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("ME910C1-NA") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("ME910C1-NV") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("ME910C1-WW") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("GE910") == 0) { - sType = VALUE_TYPE_GSM; - eCode = SUCCESS; - } else if (sModel.find("CE910") == 0) { - sType = VALUE_TYPE_CDMA; - eCode = SUCCESS; - } else if (sModel.find("DE910") == 0) { - sType = VALUE_TYPE_CDMA; - eCode = SUCCESS; - } else { - sType = VALUE_TYPE_GSM; - eCode = ERROR; - printError("RADIO| Could not identify type from model. [%s]. Assuming [%s]", sModel.c_str(), sType.c_str()); - } - return eCode; -} - -CellularRadio::CODE CellularRadio::getFirmware(std::string& sFirmware) { - printTrace("%s| Get Firmware", m_sName.c_str()); - sFirmware = VALUE_NOT_SUPPORTED; - std::string sCmd("AT+CGMR"); - std::string sResult = CellularRadio::sendCommand(sCmd); - size_t pos = sResult.find(RSP_OK); - if (pos == std::string::npos) { - printWarning("%s| Unable to get firmware from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - sFirmware = MTS::Text::trim(sResult.substr(0, pos)); - if(sFirmware.size() == 0) { - printWarning("%s| Unable to get firmware from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - m_sFirmware = sFirmware; - - return SUCCESS; -} - -CellularRadio::CODE CellularRadio::getFirmwareBuild(std::string& sFirmwareBuild) { - sFirmwareBuild = VALUE_NOT_SUPPORTED; - return FAILURE; -} - -CellularRadio::CODE CellularRadio::getHardware(std::string& sHardware) { - printTrace("%s| Get Hardware", m_sName.c_str()); - sHardware = VALUE_NOT_SUPPORTED; - - if(m_sFirmware.size() == 0) { - getFirmware(m_sFirmware); - } - - if(getHardwareVersionFromFirmware(m_sFirmware, sHardware)) { - return SUCCESS; - } - return FAILURE; -} - -CellularRadio::CODE CellularRadio::getManufacturer(std::string& sManufacturer) { - printTrace("%s| Get Manufacturer", m_sName.c_str()); - sManufacturer = VALUE_NOT_SUPPORTED; - std::string sCmd("AT+GMI"); - std::string sResult = CellularRadio::sendCommand(sCmd); - size_t pos = sResult.find(RSP_OK); - if (pos == std::string::npos) { - printWarning("%s| Unable to get manufacturer from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - sManufacturer = MTS::Text::trim(sResult.substr(0, pos)); - if(sManufacturer.size() == 0) { - printWarning("%s| Unable to get manufacturer from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - return SUCCESS; -} - -CellularRadio::CODE CellularRadio::getImei(std::string& sImei) { - printTrace("%s| Get IMEI", m_sName.c_str()); - sImei = VALUE_NOT_SUPPORTED; - std::string sCmd("AT+CGSN"); - std::string sResult = CellularRadio::sendCommand(sCmd); - size_t pos = sResult.find(RSP_OK); - if (pos == std::string::npos) { - printWarning("%s| Unable to get IMEI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - sImei = MTS::Text::trim(sResult.substr(0, pos)); - if(sImei.size() == 0) { - printWarning("%s| Unable to get IMEI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - return SUCCESS; -} - -CellularRadio::CODE CellularRadio::getMeid(std::string& sMeid) { - printTrace("%s| Get MEID", m_sName.c_str()); - return getImei(sMeid); -} - -CellularRadio::CODE CellularRadio::getImsi(std::string& sImsi) { - printTrace("%s| Get IMSI", m_sName.c_str()); - sImsi = VALUE_NOT_SUPPORTED; - std::string sCmd("AT+CIMI"); - std::string sResult = CellularRadio::sendCommand(sCmd); - size_t pos = sResult.find(RSP_OK); - if (pos == std::string::npos) { - printWarning("%s| Unable to get IMSI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - sImsi = MTS::Text::trim(sResult.substr(0, pos)); - if(sImsi.size() == 0) { - printWarning("%s| Unable to get IMSI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - return SUCCESS; -} - -CellularRadio::CODE CellularRadio::getSimStatus(std::string& sSimStatus) { - printTrace("%s| Get SIM Status", getName().c_str()); - sSimStatus = VALUE_UNKNOWN; - return FAILURE; -} - -CellularRadio::CODE CellularRadio::getIccid(std::string& sIccid) { - printTrace("%s| Get ICCID", m_sName.c_str()); - sIccid = VALUE_NOT_SUPPORTED; - std::string sCmd("AT#CCID"); - std::string sResult = CellularRadio::sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); - if (end == std::string::npos) { - printWarning("%s| Unable to get ICCID from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - size_t start = sResult.find("#CCID:"); - if(start != std::string::npos) { - start += sizeof("#CCID:"); - sIccid = MTS::Text::trim(sResult.substr(start, end-start)); - if(sIccid.size() == 0) { - printWarning("%s| Unable to get ICCID from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - } - return SUCCESS; -} - -CellularRadio::CODE CellularRadio::getService(std::string& sService) { - printTrace("%s| Get Service", m_sName.c_str()); - sService = VALUE_NOT_SUPPORTED; - std::string sCmd("AT#PSNT?"); - std::string sResult = CellularRadio::sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); - if (end == std::string::npos) { - printWarning("%s| Unable to get Service from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - size_t start = sResult.find(","); - if(start != std::string::npos) { - start += 1; //comma - std::string sPsnt = MTS::Text::trim(sResult.substr(start, end-start)); - int32_t iService; - sscanf(sPsnt.c_str(), "%d", &iService); - - switch(iService) { - case 0: sService = "GPRS"; break; - case 1: sService = "EGPRS"; break; - case 2: sService = "WCDMA"; break; - case 3: sService = "HSDPA"; break; - case 4: sService = "LTE"; break; - default: sService = VALUE_UNKNOWN; break; - } - - printDebug("%s| Service ID: [%d][%s]", m_sName.c_str(), iService, sService.c_str()); - } - return SUCCESS; -} - -CellularRadio::CODE CellularRadio::getLac(std::string& sLac) { - Json::Value jData; - - printTrace("%s| Get LAC", m_sName.c_str()); - sLac = VALUE_NOT_SUPPORTED; - - if(getNetworkStatus(jData) == SUCCESS) { - if(jData.isMember(KEY_LAC)) { - sLac = jData[KEY_LAC].asString(); - return SUCCESS; - } - } - - return FAILURE; -} - -CellularRadio::CODE CellularRadio::getMdn(std::string& sMdn) { - printTrace("%s| Get MDN", m_sName.c_str()); - sMdn = VALUE_NOT_SUPPORTED; - std::string sCmd("AT+CNUM"); - std::string sResult = CellularRadio::sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); - if (end == std::string::npos) { - printWarning("%s| Unable to get MDN from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - size_t start = sResult.find("CNUM:"); - if(start != std::string::npos) { - start += sizeof("CNUM:"); - std::vector vParts = MTS::Text::split(sResult.substr(start, end - start), ','); - if(vParts.size() < 3) { - printWarning("%s| Unable to parse MDN from response [%s]", m_sName.c_str(), sResult.c_str()); - return FAILURE; - } - sMdn = MTS::Text::strip(vParts[1], '"'); - if(sMdn.size() == 0) { - printWarning("%s| Unable to get MDN from radio using command [%s]. MDN may not be set.", m_sName.c_str(), sCmd.c_str()); - } - } else { - sMdn = ""; - printWarning("%s| Unable to get MDN from radio using command [%s]. MDN may not be set.", m_sName.c_str(), sCmd.c_str()); - } - - return SUCCESS; -} - -CellularRadio::CODE CellularRadio::getMsid(std::string& sMsid) { - printTrace("%s| Get MSID", m_sName.c_str()); - sMsid = ""; - - std::string sImsi; - if(getImsi(sImsi) == SUCCESS) { - if(sImsi.size() >= 10) { - sMsid = sImsi.substr(sImsi.size() - 10); - printTrace("IMSI: [%s] MEID [%s]", sImsi.c_str(), sMsid.c_str()); - return SUCCESS; - } - } - printWarning("%s| Unable to get MSID from radio", m_sName.c_str()); - return FAILURE; -} - -CellularRadio::CODE CellularRadio::getType(std::string& sType) { - printTrace("%s| Get Type", m_sName.c_str()); - sType = VALUE_NOT_SUPPORTED; - return FAILURE; -} - -CellularRadio::CODE CellularRadio::getCarrier(std::string& sCarrier) { - printTrace("%s| Get Carrier", m_sName.c_str()); - if(m_sCarrier == "") { - Json::Value jData; - if(getNetworkStatus(jData) == SUCCESS) { - if(jData.isMember(KEY_MCC) && jData.isMember(KEY_MNC)) { - std::string sMcc = jData[KEY_MCC].asString(); - std::string sMnc = jData[KEY_MNC].asString(); - Json::Value jLookup = MccMncTable::getInstance()->lookup(sMcc, sMnc); - printTrace("%s| MCC-MNC Lookup: [%s][%s][%s]", m_sName.c_str(), - sMcc.c_str(), sMnc.c_str(), jLookup.toStyledString().c_str()); - if(jLookup.isMember(KEY_CARRIER)) { - m_sCarrier = jLookup[KEY_CARRIER].asString(); - } else { - printWarning("%s| MCC-MNC Lookup did not contain carrier", m_sName.c_str()); - return FAILURE; - } - } else { - printWarning("%s| Network Status did no contain MCC or MNC", m_sName.c_str()); - return FAILURE; - } - } else { - return FAILURE; - } - } - - sCarrier = m_sCarrier; - return SUCCESS; -} - -CellularRadio::CODE CellularRadio::getTower(std::string& sTower) { - Json::Value jData; - - printTrace("%s| Get Tower", m_sName.c_str()); - sTower = VALUE_NOT_SUPPORTED; - - if(getNetworkStatus(jData) == SUCCESS) { - if(jData.isMember(KEY_CID)) { - sTower = jData[KEY_CID].asString(); - return SUCCESS; - } - } - return FAILURE; -} - -CellularRadio::CODE CellularRadio::getTime(std::string& sDate, std::string& sTime, std::string& sTimeZone) { - Json::Value jData; - - printTrace("%s| Get Time", m_sName.c_str()); - sDate = ""; - sTime = ""; - sTimeZone = ""; - - std::string sCmd("AT+CCLK?"); - std::string sResult = CellularRadio::sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); - if (end == std::string::npos) { - printWarning("%s| Unable to get Time from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - size_t start = sResult.find("CCLK: "); - if(start != std::string::npos) { - start += sizeof("CCLK: "); - std::string sValue = MTS::Text::trim(sResult.substr(start, end - start)); - sValue = MTS::Text::strip(sValue, '"'); - - std::vector vParts = MTS::Text::split(sValue, ','); - if(vParts.size() != 2) { - printWarning("%s| Unable to parse Date from response [%s]", m_sName.c_str(), sResult.c_str()); - return FAILURE; - } - - - std::vector vDateParts = MTS::Text::split(vParts[0], '/'); - if(vDateParts.size() != 3) { - printWarning("%s| Unable to parse Date from response [%s]", m_sName.c_str(), sResult.c_str()); - return FAILURE; - } - - //The Date format is YY/MM/DD -> Change to MM/DD/YY - sDate = vDateParts[1] + "/" + vDateParts[2] + "/" + vDateParts[0]; - - vParts = MTS::Text::split(vParts[1], '-'); - if(vParts.size() != 2) { - printWarning("%s| Unable to parse Time from response [%s]", m_sName.c_str(), sResult.c_str()); - return FAILURE; - } - sTime = vParts[0]; - - int32_t iZoneUnits; //the difference, expressed in quarters of an hour, between the local time and GMT - if(!MTS::Text::parse(iZoneUnits, MTS::Text::strip(vParts[1], '+'))) { - printWarning("%s| Unable to parse Time Zone from response [%s]", m_sName.c_str(), sResult.c_str()); - return FAILURE; - } - - int32_t iZone = iZoneUnits/4; //Divide by 4 to get hours difference - int32_t iZonePartial = (iZoneUnits % 4) * 15; //Remainder in minutes - std::string sPlusSign = "+"; - if(iZonePartial < 0) { - //Remove negative sign from partial and clear plus sign component - iZonePartial *= -1; - sPlusSign = ""; - } - std::stringstream ss; - ss << sPlusSign << iZone; - if(iZonePartial != 0) { - ss << ":" << iZonePartial; - } - - sTimeZone = ss.str(); - return SUCCESS; - - } else { - printWarning("%s| Unable to get Time from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - } - - return FAILURE; -} - -CellularRadio::CODE CellularRadio::getRoaming(bool& bRoaming) { - Json::Value jData; - - printTrace("%s| Get Roaming", m_sName.c_str()); - bRoaming = false; - - REGISTRATION eReg; - if(getRegistration(eReg) == SUCCESS) { - bRoaming = (eReg == ROAMING); - return SUCCESS; - } - return FAILURE; -} - -CellularRadio::CODE CellularRadio::getNetwork(std::string& sNetwork) { - Json::Value jData; - - printTrace("%s| Get Network", m_sName.c_str()); - sNetwork = VALUE_NOT_SUPPORTED; - - if(getNetworkStatus(jData) == SUCCESS) { - if(jData.isMember(KEY_NETWORK)) { - sNetwork = jData[KEY_NETWORK].asString(); - return SUCCESS; - } - } - return FAILURE; -} - -CellularRadio::CODE CellularRadio::getSignalStrength(int32_t& rssi) { - printTrace("%s| Get Signal Strength", m_sName.c_str()); - std::string sCmd("AT+CSQ"); - std::string sResult = sendCommand(sCmd); - if (sResult.find("+CSQ: ") == std::string::npos) { - printDebug("%s| Signal Strength 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); - if(start == std::string::npos || stop == std::string::npos) { - printDebug("%s| Signal Strength command returned malformed response: [%s]", m_sName.c_str(), sResult.c_str()); - return FAILURE; - } - std::string signal = sResult.substr(start + 2, stop - start - 2); - - sscanf(signal.c_str(), "%d", &rssi); - printDebug("%s| Signal Strength: [%d]", m_sName.c_str(), rssi); - - return SUCCESS; -} - -CellularRadio::CODE CellularRadio::getModemLocation(std::string& sLocation) { - printTrace("%s|CellularRadio getModemLocation - not supported", m_sName.c_str()); - return FAILURE; -} - -CellularRadio::CODE CellularRadio::convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& iDbm) { - - //Telit Conversion - if(iRssi < 0 || iRssi == 99) { - return FAILURE; - } - - if(iRssi == 0) { - iDbm = -113; - } else if(iRssi == 1) { - iDbm = -111; - } else if(iRssi <= 30) { - //28 steps between 2 and 30 - //54 dbm between 53 and 109 - float stepSize = 54.0 / 28.0; - iDbm = -109 + (int)(stepSize * (iRssi-2)); - } else { - iDbm = -51; - } - - return SUCCESS; -} - -CellularRadio::CODE CellularRadio::convertdBmToSignalStrength(const int32_t& iDBm, int32_t& iRssi) { - //Telit Conversion - if(iDBm <= -113) { - iRssi = 0; - } else if(iDBm <= -111) { - iRssi = 1; - } else if(iDBm <= -53) { - //54 dbm between -109 and -53 - //28 steps between 2 and 30 - float stepSize = 28.0/54.0; - iRssi = ((iDBm + 109)*stepSize) + 2; - } else { - iRssi = 31; - } - - return SUCCESS; -} - -CellularRadio::CODE CellularRadio::getEcho(bool& bEnabled) { - printTrace("%s| Echo Test", m_sName.c_str()); - std::string sResult = sendCommand("AT"); - if(sResult.size() == 0) { - return NO_RESPONSE; - } - - if(sResult.find("AT") != std::string::npos) { - bEnabled = true; - } else { - bEnabled = false; - } - m_bEchoEnabled = bEnabled; - return SUCCESS; -} - -CellularRadio::CODE CellularRadio::setEcho(bool bEnabled) { - CODE eCode = FAILURE; - if(bEnabled) { - eCode = sendBasicCommand("ATE1"); - m_bEchoEnabled = (eCode == SUCCESS ) ? true : m_bEchoEnabled; - } else { - eCode = sendBasicCommand("ATE0"); - m_bEchoEnabled = (eCode == SUCCESS ) ? false : m_bEchoEnabled; - } - - return eCode; -} - -CellularRadio::CODE CellularRadio::getStaticInformation(Json::Value& jData) { - printTrace("%s| Get Static Information", m_sName.c_str()); - - printTrace("%s| Static Information:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); - - return FAILURE; -} - -/* AT#RFSTS - NETWORK STATUS - - (GSM network) - #RFSTS:,,,,,,,,,,,,, - Where: - - Country code and operator code(MCC, MNC) - - GSM Assigned Radio Channel - - Received Signal Strength Indication - - Localization Area Code - - Routing Area Code - - Tx Power - - Mobility Management state - - Radio Resource state - - Network Operator Mode - - Cell ID - - International Mobile Subscriber Identity - - Operator name - - Service Domain - 0 - No Service - 1 - CS only - 2 - PS only - 3 - CS+PS - - Active Band - 1 - GSM 850 - 2 - GSM 900 - 3 - DCS 1800 - 4 - PCS 1900 - - - (WCDMA network) - #RFSTS: - ,,,,, RSSI>,,,,,,,,,,, - ,,[,,] - Where: - - Country code and operator code(MCC, MNC) - - UMTS Assigned Radio Channel - - Active PSC(Primary Synchronization Code) - - Active Ec/Io(chip energy per total wideband power in dBm) - - Active RSCP (Received Signal Code Power in dBm) - - Received Signal Strength Indication - - Localization Area Code - - Routing Area Code - - Tx Power - - Discontinuous reception cycle Length (cycle length in ms) - - Mobility Management state - - Radio Resource state - - Network Operator Mode - - Block Error Rate (e.g., 005 means 0.5 %) - - Cell ID - - International Mobile Station ID - - Operator name - - Service Domain (see above) - - Number of Active Set (Maximum 6) - UARFCN of n th active set - PSC of n th active set - Ec/Io of n th active Set - - (LTE Network) - #RFSTS: - - - - - - - - - - - - - [] - - - - - - - - - - - - [] - - - - - -*/ -CellularRadio::CODE CellularRadio::getNetworkStatus(Json::Value& jData) { - int32_t iValue; - std::string sValue; - const uint32_t GSM_NETWORK_FORMAT = 14; - const uint32_t WCDMA_NETWORK_FORMAT = 19; - const uint32_t LTE_NETWORK_FORMAT = 16; - - printTrace("%s| Get Network Status", m_sName.c_str()); - - //Always get common network stats because this should never fail - //This way the basic stats are always returned even if AT#RFSTS fails below - getCommonNetworkStats(jData); - - std::string sCmd; - std::string sResult; - // LE910 radios have a bug where issuing AT#RFSTS with a locked SIM - // will cause the radio to stop responding until a radio power cycle - // Telit Support Portal Case #5069697 - // LE910C1-NS is an LE910, so we stop the scan after the 0. - if (m_sName.find("LE910") != std::string::npos) { - sCmd = "AT+CPIN?"; - sResult = sendCommand(sCmd); - if (sResult.find("+CPIN:") == std::string::npos) { - printDebug("%s| AT+CPIN? returned unexpected response: [%s][%s]", m_sName.c_str(), sCmd.c_str(), sResult.c_str()); - printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); - return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function - } - if (sResult.find("SIM PIN") != std::string::npos) { - printError("%s| The SIM is locked and must first be unlocked", m_sName.c_str()); - printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); - return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function - } - } - - sCmd = "AT#RFSTS"; - sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 200); - if (sResult.find("#RFSTS:") == std::string::npos) { - //On LTE radios without signal, this case will run because AT#RFSTS just returns "OK" - printDebug("%s| Network Status command returned unexpected response: [%s][%s]", m_sName.c_str(), sCmd.c_str(), sResult.c_str()); - printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); - return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function - } - - size_t start = sResult.find(":") + 1; //Position right after "#RFSTS:" - std::vector vParts = MTS::Text::split(MTS::Text::trim(sResult.substr(start)), ","); - - if (vParts.size() < 3) { - printDebug("%s| Network Status command reponse is an unknown format: [%s][%s]", m_sName.c_str(), sCmd.c_str(), sResult.c_str()); - printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); - return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function - } else { - //Country Code and Operator Code - std::vector vPLMN = MTS::Text::split(vParts[0], ' '); - if(vPLMN.size() == 2) { - jData[KEY_MCC] = MTS::Text::strip(vPLMN[0], '"'); - jData[KEY_MNC] = MTS::Text::strip(vPLMN[1], '"'); - } - - jData[KEY_CHANNEL] = vParts[1]; - } - - if (vParts.size() == GSM_NETWORK_FORMAT ) { - //Parse as GSM Network Format - jData[KEY_RSSIDBM] = vParts[2]; - jData[KEY_LAC] = vParts[3]; - jData[KEY_RAC] = vParts[4]; - jData[KEY_TXPWR] = vParts[5]; - jData[KEY_MM] = vParts[6]; - jData[KEY_RR] = vParts[7]; - jData[KEY_NOM] = vParts[8]; - jData[KEY_CID] = vParts[9]; - jData[KEY_IMSI] = MTS::Text::strip(vParts[10], '"'); - jData[KEY_NETWORK] = MTS::Text::strip(vParts[11], '"'); - if(MTS::Text::parse(iValue, vParts[12]) && convertServiceDomainToString((SERVICEDOMAIN)iValue, sValue) == SUCCESS) { - jData[KEY_SD] = sValue; - } - if(MTS::Text::parse(iValue, vParts[13]) && convertActiveBandToString((ACTIVEBAND)iValue, sValue) == SUCCESS) { - jData[KEY_ABND] = sValue; - } - // IN003567 ME910C1 radios have some odd behavior with regards to WCDMA. The ordering of the fields from #RFSTS are - // the same as LTE up to the 16th field (for ME901C1-WW anyway). Drop into LTE parsing for ME910C1-WW. - } else if((vParts.size() >= WCDMA_NETWORK_FORMAT) && (m_sName.find("ME910C1-WW") == std::string::npos)) { - Json::Value jDebug; - - //Parse as WCDMA Network Format - - jDebug[KEY_PSC] = vParts[2]; - jDebug[KEY_ECIO] = vParts[3]; - jDebug[KEY_RSCP] = vParts[4]; - - jData[KEY_RSSIDBM] = vParts[5]; - jData[KEY_LAC] = vParts[6]; - jData[KEY_RAC] = vParts[7]; - - jDebug[KEY_TXPWR] = vParts[8]; - jDebug[KEY_DRX] = vParts[9]; - jDebug[KEY_MM] = vParts[10]; - jDebug[KEY_RR] = vParts[11]; - jDebug[KEY_NOM] = vParts[12]; - - if(vParts[13].size() != 0) { - jDebug[KEY_BLER] = vParts[13]; - } else { - jDebug[KEY_BLER] = "000"; - } - - jData[KEY_CID] = vParts[14]; - jData[KEY_IMSI] = MTS::Text::strip(vParts[15], '"'); - jData[KEY_NETWORK] = MTS::Text::strip(vParts[16], '"'); - - // Get the radio band given the channel (UARFCN) - RadioBandMap radioBandMap(vParts[1], CellularRadio::VALUE_TYPE_CDMA); - jData[KEY_ABND] = radioBandMap.getRadioBandName(); - - if(MTS::Text::parse(iValue, vParts[17]) && convertServiceDomainToString((SERVICEDOMAIN)iValue, sValue) == SUCCESS) { - jDebug[KEY_SD] = sValue; - } - //Ignoring Active Set Values - // - Number of Active Set (Maximum 6) - // - UARFCN of n th active set - // - PSC of n th active set - // - Ec/Io of n th active Set - - jData[KEY_DEBUG] = jDebug; - } else if(vParts.size() >= LTE_NETWORK_FORMAT) { - Json::Value jDebug; - - //Parse as LTE Network Format - - // - // MD: It is noticed that LTE Network format may vary depending on the firmware version: - // - // ,,,,,,[],,,,,,[],,, - // Ex 1: #RFSTS: "310 260",2300,-98,-63,-14,AA06,,128,19,0,0501D02,"310260754792598","T-Mobile",3,4,197 - // - // ,,,,,,,[],,,,,,[],, - // Ex 2: #RFSTS:"310 410",5780,-105,-73,-14,4603,255,,128,19,0,0000098,"310410536498694","AT&T",3,17 - // #RFSTS:"311 480",1150,-96,-66,-9.0,bf35,FF,0,0,19,1,"2ED1B0E","311480148817753","Verizon",2,2,720000,10800 - // #RFSTS:"310 410",2175,-120,-89,-17.5,4612,FF,0,0,19,1,"4E5E916","310410807276607","AT&T",3,4 - // - // Additional parameter in the second example shifts the rest of the parameters. Here we are trying to figure out - // which format is currently produced based on field position which always has double quotation marks. - // - if (vParts[13].find("\"") != std::string::npos) { - // parse the RAC and then remove it from the vector - jData[KEY_RAC] = vParts[6]; - vParts.erase(vParts.begin() + 6); - } - - jDebug["rsrp"] = vParts[2]; - jDebug[KEY_RSSIDBM] = vParts[3]; - jDebug["rsrq"] = vParts[4]; - - jData["tac"] = vParts[5]; - jDebug[KEY_TXPWR] = vParts[6]; - jData[KEY_DRX] = vParts[7]; - jDebug[KEY_MM] = vParts[8]; - jDebug["rrc"] = vParts[9]; - jData[KEY_CID] = MTS::Text::strip(vParts[10], '"'); - jData[KEY_IMSI] = MTS::Text::strip(vParts[11], '"'); - jData[KEY_NETWORK] = MTS::Text::strip(vParts[12], '"'); - - // Get the radio band given the channel (EARFCN) - RadioBandMap radioBandMap(vParts[1], CellularRadio::VALUE_TYPE_LTE); - jData[KEY_ABND] = radioBandMap.getRadioBandName(); - - jData[KEY_LAC] = queryLteLac(); - - if(MTS::Text::parse(iValue, vParts[13]) && convertServiceDomainToString((SERVICEDOMAIN)iValue, sValue) == SUCCESS) { - jDebug[KEY_SD] = sValue; - } - - jData[KEY_DEBUG] = jDebug; - } - - printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); - 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)), ","); - if(vParts.size() < 3) { - result = CellularRadio::VALUE_UNAVAILABLE; - } else { - 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; - if(getRoaming(bRoaming) == SUCCESS) { - jData[KEY_ROAMING] = bRoaming; - } - - int32_t iRssi; - if(getSignalStrength(iRssi) == SUCCESS) { - jData[KEY_RSSI] = iRssi; - int32_t dBm; - if(!jData.isMember(KEY_RSSIDBM) && convertSignalStrengthTodBm(iRssi, dBm) == SUCCESS) { - //Add RSSI in dBm format - jData[KEY_RSSIDBM] = MTS::Text::format(dBm); - } - } - - std::string sService; - if(getService(sService) == SUCCESS) { - jData[KEY_SERVICE] = sService; - } - std::string sDate, sTime, sTimeZone; - if(getTime(sDate, sTime, sTimeZone) == SUCCESS) { - jData[KEY_DATETIME] = sDate + " " + sTime + " GMT" + sTimeZone; - } - - std::string sNetworkReg; - CellularRadio::REGISTRATION eReg; - if (getRegistration(eReg) == SUCCESS) { - if (convertRegistrationToString(eReg, sNetworkReg) == SUCCESS) { - jData[CellularRadio::KEY_NETWORK_REG] = sNetworkReg; - } - } -} - -void CellularRadio::initMipProfile(Json::Value& jData) { - jData[KEY_MIP_ID] = 0; - jData[KEY_MIP_ENABLED] = false; - jData[KEY_MIP_NAI] = VALUE_UNKNOWN; - jData[KEY_MIP_HOMEADDRESS] = VALUE_UNKNOWN; - jData[KEY_MIP_PRIMARYHA] = VALUE_UNKNOWN; - jData[KEY_MIP_SECONDARYHA] = VALUE_UNKNOWN; - jData[KEY_MIP_MNAAASPI] = VALUE_UNKNOWN; - jData[KEY_MIP_MNHASPI] = VALUE_UNKNOWN; - jData[KEY_MIP_MNAAASS] = false; - jData[KEY_MIP_MNHASS] = false; -} - -CellularRadio::CODE CellularRadio::getRegistration(REGISTRATION& eRegistration) { - std::string sCmd; - std::string sResp; - - // LE910C1-NS is an LE910, so we stop the scan after the 0. - if (m_sName.find("LE910") != std::string::npos) { - // use AT+CGREG instead for LE910 models - sCmd = "AT+CGREG?"; - sResp = "+CGREG: "; - } - else { - 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: [%s]", 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; - return SUCCESS; -} - -CellularRadio::CODE CellularRadio::convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration) { - - CODE eCode = FAILURE; - switch (eRegistration) { - case NOT_REGISTERED: sRegistration = VALUE_NOT_REGISTERED; eCode = SUCCESS; break; - case REGISTERED: sRegistration = VALUE_REGISTERED; eCode = SUCCESS; break; - case SEARCHING: sRegistration = VALUE_SEARCHING; eCode = SUCCESS; break; - case DENIED: sRegistration = VALUE_DENIED; eCode = SUCCESS; break; - case UNKNOWN: sRegistration = VALUE_UNKNOWN; eCode = SUCCESS; break; - case ROAMING: sRegistration = VALUE_ROAMING; eCode = SUCCESS; break; - } - return eCode; -} - -CellularRadio::CODE CellularRadio::validateMsl(const Json::Value& jArgs) { - printTrace("%s| Validate MSL", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::setMdn(const Json::Value& jArgs) { - printTrace("%s| Set MDN", m_sName.c_str()); - - if(!jArgs["mdn"].isString()) { - return INVALID_ARGS; - } - - std::string sCmd("AT#SNUM=1,\""); - sCmd += jArgs["mdn"].asString() + "\""; - - std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 1000); - size_t end = sResult.find(RSP_OK); - if (end == std::string::npos) { - printWarning("%s| Unable to set MDN for radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - return SUCCESS; -} - -CellularRadio::CODE CellularRadio::setMsid(const Json::Value& jArgs) { - printTrace("%s| Set MSID", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::getMipProfile(Json::Value& jMipProfile) { - printTrace("%s| Get MIP Active Profile", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::setMipActiveProfile(const Json::Value& jArgs) { - printTrace("%s| Set MIP Active Profile", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::setMipNai(const Json::Value& jArgs) { - printTrace("%s| Set MIP NAI", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::setMipHomeIp(const Json::Value& jArgs) { - printTrace("%s| Set MIP Home IP", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::setMipPrimaryHa(const Json::Value& jArgs) { - printTrace("%s| Set MIP Primary HA", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::setMipSecondaryHa(const Json::Value& jArgs) { - printTrace("%s| Set MIP Secondary HA", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::setMipMnAaaSpi(const Json::Value& jArgs) { - printTrace("%s| Set MIP MN-AAA SPI", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::setMipMnHaSpi(const Json::Value& jArgs) { - printTrace("%s| Set MIP MN-HA SPI", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::setMipRevTun(const Json::Value& jArgs) { - printTrace("%s| Set MIP Rev Tun", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::setMipMnAaaSs(const Json::Value& jArgs) { - printTrace("%s| Set MIP MN-AAA SS", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::setMipMnHaSs(const Json::Value& jArgs) { - printTrace("%s| Set MIP MN-HA SS", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::updateDc(const Json::Value& jArgs, UpdateCb& stepCb) { - printTrace("%s| Update Device Configuration", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::updatePrl(const Json::Value& jArgs, UpdateCb& stepCb) { - printTrace("%s| Update Preferred Roaming List", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) { - printTrace("%s| Update Firmware Update Management Object", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::resetHfa(const Json::Value& jArgs, UpdateCb& stepCb) { - printTrace("%s| HFA Reset", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::activate(const Json::Value& jArgs, UpdateCb& stepCb) { - printTrace("%s| Activation", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::setActiveFirmware(const Json::Value& jArgs) { - printTrace("%s| Set Active Firmware Image Number: not applicable", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::getActiveFirmware(std::string& sFwId) { - printTrace("%s| Get Active Firmware Image Number: not applicable", m_sName.c_str()); - sFwId = VALUE_NOT_SUPPORTED; - - return NOT_APPLICABLE; -} - -CellularRadio::CODE CellularRadio::sendBasicCommand(const std::string& sCmd, int32_t iTimeoutMillis, const char& ESC) { - std::string response = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, iTimeoutMillis, ESC); - if (response.size() == 0) { - return NO_RESPONSE; - } else if (response.find(RSP_OK) != std::string::npos) { - return SUCCESS; - } else if (response.find(RSP_ERROR) != std::string::npos) { - return ERROR; - } else { - return FAILURE; - } -} - -std::string CellularRadio::sendCommand(const std::string& sCmd, const std::vector& vBail, int32_t timeoutMillis, const char& ESC) { - return sendCommand(m_apIo, sCmd, vBail, timeoutMillis, ESC); -} - -std::string CellularRadio::sendCommand(MTS::AutoPtr& apIo, const std::string& sCmd, - const std::vector& vBail, int32_t timeoutMillis, const char& ESC) { - IsNeedMoreData isNeedMoreData = [&vBail](const std::string& iterationData, const std::string& allData)->bool { - for(size_t i = 0; i < vBail.size(); i++) { - const std::string& sBail = vBail[i]; - if(sBail.size() > 0) { - if(allData.find(sBail) != std::string::npos) { - //Return when bail string is found - printTrace("RADIO| Found bail string [%s]", sBail.c_str()); - return false; - } - } - } - return true; - }; - - return sendCommand(apIo, sCmd, isNeedMoreData, timeoutMillis, ESC); -} - -std::string CellularRadio::sendCommand(const std::string& sCmd, MTS::IO::CellularRadio::IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis, const char& ESC) { - return sendCommand(m_apIo, sCmd, isNeedMoreData, timeoutMillis, ESC); -} - -std::string CellularRadio::sendCommand(MTS::AutoPtr& apIo, const std::string& sCmd, - IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis, const char& ESC) { - if(MTS::Logger::getPrintLevel() >= MTS::Logger::PrintLevel::TRACE_LEVEL) { - printTrace("RADIO| Sending command [%s]", sCmd.c_str()); - } - if(apIo.isNull()) { - printError("RADIO| IO is not set in sendCommand"); - return ""; - } - - int32_t iResult; - if(ESC == 0x00) { - iResult = apIo->write(sCmd.data(), sCmd.size()); - } else { - std::string sNewCmd(sCmd); - sNewCmd.push_back(ESC); - iResult = apIo->write(sNewCmd.data(), sNewCmd.size()); - } - - if(iResult == -1) { - printError("RADIO| Failed to send command to radio"); - return ""; - } - - bool done = false; - const uint32_t capacity = 1024; - char buffer[capacity]; - std::string sResult; - Timer timer; - timer.start(); - do { - int32_t iterationTimeout = 100; - int bytesRead = apIo->read((char*)buffer, capacity, iterationTimeout); - if(bytesRead == -1) { - printError("RADIO| Failed to read from radio"); - break; - } - - std::string sIteration((char*)buffer, bytesRead); - sResult += sIteration; - - if(isNeedMoreData && !isNeedMoreData(sIteration, sResult)) { - printTrace("RADIO| No more data needed"); - return sResult; - } - if(timeoutMillis >= 0) { - done = (timer.getMillis() >= (uint64_t)timeoutMillis); - } else { - //Do not stop looping until bail string is found - } - } while(!done); - - //Timed out - return sResult; -} - -CellularRadio::CODE CellularRadio::test(MTS::AutoPtr& apIo, uint32_t timeoutSeconds) { - printTrace("RADIO| Basic Test"); - uint32_t count = 0; - std::string sCmd("AT"); - do { - std::string sResult = sendCommand(apIo, sCmd); - if (sResult.find(RSP_OK) == std::string::npos) { - printTrace("RADIO| Waiting for basic radio communication [%s] ...", sResult.c_str()); - } else { - break; - } - count++; - } while (count < timeoutSeconds); - - if(count == timeoutSeconds) { - printWarning("RADIO| Basic radio communication FAILED"); - return NO_RESPONSE; - } - return SUCCESS; -} - -std::string CellularRadio::extractModelFromResult(const std::string& sResult) { - std::string sModel(CellularRadio::VALUE_NOT_SUPPORTED); - - if(sResult.find("HE910-D") != std::string::npos) { - sModel = "HE910-D"; - } else if(sResult.find("HE910-EUD") != std::string::npos) { - sModel = "HE910-EUD"; - } else if(sResult.find("LE910-JN1") != std::string::npos) { - sModel = "LE910-JN1"; - } else if(sResult.find("LE866A1-JS") != std::string::npos) { - sModel = "LE866A1-JS"; - } else if(sResult.find("LE910-NAG") != std::string::npos) { - sModel = "LE910-NAG"; - } else if(sResult.find("LE910C4-NF") != std::string::npos) { - sModel = "LE910C4-NF"; - } else if(sResult.find("LE910-NA1") != std::string::npos) { - sModel = "LE910-NA1"; - } else if(sResult.find("ME910C1-NA") != std::string::npos) { - sModel = "ME910C1-NA"; - } else if(sResult.find("ME910C1-NV") != std::string::npos) { - sModel = "ME910C1-NV"; - } else if(sResult.find("ME910C1-WW") != std::string::npos) { - sModel = "ME910C1-WW"; - } else if(sResult.find("LE910-SVG") != std::string::npos) { - sModel = "LE910-SVG"; - } else if(sResult.find("LE910-EUG") != std::string::npos) { - sModel = "LE910-EUG"; - } else if(sResult.find("LE910C4-EU") != std::string::npos) { - sModel = "LE910C4-EU"; - } else if(sResult.find("LE910-EU1") != std::string::npos) { - sModel = "LE910-EU1"; - } else if(sResult.find("LE910C1-NS") != std::string::npos) { - sModel = "LE910C1-NS"; - } else if(sResult.find("LE910C1-AP") != std::string::npos) { - sModel = "LE910C1-AP"; - } else if(sResult.find("GE910") != std::string::npos) { - sModel = "GE910"; - } else if(sResult.find("DE910-DUAL") != std::string::npos) { - sModel = "DE910-DUAL"; - } else if(sResult.find("CE910") != std::string::npos) { - sModel = "CE910"; - } - return sModel; -} - -std::string CellularRadio::getCodeAsString(CODE eCode) { - switch(eCode) { - case SUCCESS: - return "SUCCESS"; - case ERROR: - return "ERROR"; - case FAILURE: - return "FAILURE"; - case NO_RESPONSE: - return "NO RESPONSE"; - default: - return "UNKNOWN"; - } -} - -bool CellularRadio::splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType) { - - std::vector vParts = MTS::Text::split(sLine, ":", 2); - - if(vParts.size() == 2 && vParts[0] == sKey) { - if(eType == Json::ValueType::stringValue) { - jParent[sJsonKey] = MTS::Text::trim(vParts[1]); - } else if (eType == Json::ValueType::intValue || eType == Json::ValueType::uintValue) { - //TODO: - printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); - return false; - } else if(eType == Json::ValueType::realValue) { - //TODO: - printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); - return false; - } else if(eType == Json::ValueType::booleanValue) { - //TODO: - printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); - return false; - } else { - printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); - return false; - } - } else { - printWarning("%s| Unable to parse %s from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); - return false; - } - - return true; -} - -bool CellularRadio::getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier) { - // Telit Radios - // H.ab.zyx => 3 Main Components - // "H" = Hardware -> 15 = DE910 family, 18 = CE910 family, 12 = HE910 family - // "a" = Hardware version - // "b" = Software Major Version - // "z" = is the product type, i.e. DUAL or SC - // "y" = is the carrier variant - // "x" = is the firmware version - // Telit will do their best to keep the carrier variant as "0" for Sprint, "1" for Aeris, "2" for Verizon, and "3" for U.S. Cellular. - - const uint32_t CARRIER_INDEX = 1; //y in [zyx] - - bool bResult = false; - std::vector vParts = MTS::Text::split(sFirmware, '.'); - - if(vParts.size() == 3) { - //CDMA firmware version notation - if(vParts[0] == "15" || vParts[0] == "18") { - //DE910 or CE910 -> Good good - std::string sID = vParts[2]; - if(sID.size() == 3) { - char cId = sID[CARRIER_INDEX]; - - //Good good - if(cId == '0') { - sCarrier = VALUE_CARRIER_SPRINT; - bResult = true; - } else - if(cId == '1') { - sCarrier = VALUE_CARRIER_AERIS; - bResult = true; - } else - if(cId == '2') { - sCarrier = VALUE_CARRIER_VERIZON; - bResult = true; - } else - if(cId == '3') { - sCarrier = VALUE_CARRIER_USCELLULAR; - bResult = true; - } - } - } - } - - return bResult; -} - -bool CellularRadio::getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware) { - // Telit Radios - // H.ab.zyx => 3 Main Components - // "H" = Hardware -> 15 = DE910 family, 18 = CE910 family, 12 = HE910 family - // "a" = Hardware version - // "b" = Software Major Version - // "z" = is the product type, i.e. DUAL or SC - // "y" = is the carrier variant - // "x" = is the firmware version - // Telit will do their best to keep the carrier variant as "0" for Sprint, "1" for Aeris, and "2" for Verizon. - - const uint32_t HARDWARE_INDEX = 0; //a in [ab] - - bool bResult = false; - std::vector vParts = MTS::Text::split(sFirmware, '.'); - - if(vParts.size() == 3) { - //GSM Hardware Version - if(!(vParts[0] == "15" || vParts[0] == "18")) { - //Not DE910 or CE910 -> Good good - std::string sVersion = vParts[1]; - if(sVersion.size() == 2) { - sHardware = "1."; - sHardware += sVersion[HARDWARE_INDEX]; - bResult = true; - } - } - } - - return bResult; - -} - -const char *CellularRadio::RadioBandMap::getLTEBand(const int32_t channel) -{ - for (unsigned int ii = 0; ii < NUM_LTE_BANDS; ii++) - { - if (EULTRAband[ii].low <= channel && EULTRAband[ii].high >= channel) - { - return EULTRAband[ii].name; - } - } - return VALUE_UNKNOWN.c_str(); -} - -const char *CellularRadio::RadioBandMap::getCDMABand(const int channel) -{ - for (unsigned int ii = 0; ii < NUM_WCDMA_BANDS; ii++) - { - if (WCDMAband[ii].low <= channel && WCDMAband[ii].high >= channel) - { - return WCDMAband[ii].name; - } - } - return VALUE_UNKNOWN.c_str(); -} - -const char *CellularRadio::RadioBandMap::getGSMBand(const int channel) -{ - for (unsigned int ii = 0; ii < NUM_GSM_BANDS; ii++) - { - if (GSMband[ii].low <= channel && GSMband[ii].high >= channel) - { - return GSMband[ii].name; - } - } - return VALUE_UNKNOWN.c_str(); -} - -const char *CellularRadio::RadioBandMap::getRadioBandName() -{ - const char *band = CellularRadio::VALUE_UNKNOWN.c_str(); - - if (m_sRadioType == CellularRadio::VALUE_TYPE_LTE) - { - band = getLTEBand(m_iChannel); - } - else if (m_sRadioType == CellularRadio::VALUE_TYPE_CDMA) - { - band = getCDMABand(m_iChannel); - } - else if (m_sRadioType == CellularRadio::VALUE_TYPE_GSM) - { - band = getGSMBand(m_iChannel); - } - - return band; -} - -const char *CellularRadio::RadioBandMap::getRadioBandName(const std::string &channel, const std::string &radioType) -{ - const char *band = CellularRadio::VALUE_UNKNOWN.c_str(); - int32_t chan = strtol(channel.c_str(), NULL, 10); - if (radioType == CellularRadio::VALUE_TYPE_LTE) - { - band = getLTEBand(chan); - } - else if (radioType == CellularRadio::VALUE_TYPE_CDMA) - { - band = getCDMABand(chan); - } - else if (radioType == CellularRadio::VALUE_TYPE_GSM) - { - band = getGSMBand(chan); - } - - return band; -} +#include "mts/MTS_IO_CellularRadio.h" diff --git a/src/MTS_IO_CellularRadioFactory.cpp b/src/MTS_IO_CellularRadioFactory.cpp index ef87f0e..17cbd05 100644 --- a/src/MTS_IO_CellularRadioFactory.cpp +++ b/src/MTS_IO_CellularRadioFactory.cpp @@ -87,14 +87,14 @@ std::string CellularRadioFactory::identifyRadio(const std::string& sPort) { apIo.reset(new SerialConnection(SerialConnection::Builder(sPort).baudRate(115200).useLockFile().build())); while(!apIo->open(30000)) { printError("CellularRadioFactory| Failed to open radio port [%s]", sPort.c_str()); - return CellularRadio::VALUE_UNKNOWN; + return TelitRadio::VALUE_UNKNOWN; } //Attempt basic radio communication - if(CellularRadio::test(apIo) != CellularRadio::SUCCESS) { + if(TelitRadio::test(apIo) != TelitRadio::SUCCESS) { printError("CellularRadioFactory| Failed to communicate with radio on port [%s]", sPort.c_str()); apIo->close(); - return CellularRadio::VALUE_UNKNOWN; + return TelitRadio::VALUE_UNKNOWN; } //Get model @@ -102,7 +102,7 @@ std::string CellularRadioFactory::identifyRadio(const std::string& sPort) { std::string sCmd("ATI4"); std::string sResult; do { - sResult = CellularRadio::sendCommand(apIo, sCmd, CellularRadio::DEFAULT_BAIL_STRINGS, 1000, CellularRadio::CR); + sResult = TelitRadio::sendCommand(apIo, sCmd, TelitRadio::DEFAULT_BAIL_STRINGS, 1000, TelitRadio::CR); if (sResult.find("OK") == std::string::npos) { printDebug("RADIO| Attempting to get radio model [%s] ...", sResult.c_str()); } else { @@ -114,10 +114,10 @@ std::string CellularRadioFactory::identifyRadio(const std::string& sPort) { if(count == 30) { printDebug("RADIO| Unable to get radio model"); apIo->close(); - return CellularRadio::VALUE_UNKNOWN; + return TelitRadio::VALUE_UNKNOWN; } - std::string sModel = CellularRadio::extractModelFromResult(sResult); + std::string sModel = TelitRadio::extractModelFromResult(sResult); printDebug("RADIO| Extracted [%s] from ATI4 query", sModel.c_str()); apIo->close(); return sModel; diff --git a/src/MTS_IO_EG95Radio.cpp b/src/MTS_IO_EG95Radio.cpp new file mode 100644 index 0000000..2fca48f --- /dev/null +++ b/src/MTS_IO_EG95Radio.cpp @@ -0,0 +1 @@ +#include "mts/MTS_IO_EG95Radio.h" diff --git a/src/MTS_IO_GE910Radio.cpp b/src/MTS_IO_GE910Radio.cpp index f31f4fc..c99d16c 100644 --- a/src/MTS_IO_GE910Radio.cpp +++ b/src/MTS_IO_GE910Radio.cpp @@ -34,7 +34,7 @@ using namespace MTS::IO; const std::string GE910Radio::MODEL_NAME("GE910"); GE910Radio::GE910Radio(const std::string& sPort) -: CellularRadio(MODEL_NAME, sPort) +: TelitRadio(MODEL_NAME, sPort) { } diff --git a/src/MTS_IO_HE910Radio.cpp b/src/MTS_IO_HE910Radio.cpp index 0178c9d..cc0e873 100644 --- a/src/MTS_IO_HE910Radio.cpp +++ b/src/MTS_IO_HE910Radio.cpp @@ -32,7 +32,7 @@ using namespace MTS::IO; HE910Radio::HE910Radio(const std::string& sHE910Model, const std::string& sPort) -: CellularRadio(sHE910Model, sPort) +: TelitRadio(sHE910Model, sPort) { } diff --git a/src/MTS_IO_LE866Radio.cpp b/src/MTS_IO_LE866Radio.cpp index 2e92f67..85b8dc3 100644 --- a/src/MTS_IO_LE866Radio.cpp +++ b/src/MTS_IO_LE866Radio.cpp @@ -31,7 +31,7 @@ using namespace MTS::IO; LE866Radio::LE866Radio(const std::string& sLE866Model, const std::string& sPort) -: CellularRadio(sLE866Model, sPort) +: TelitRadio(sLE866Model, sPort) { } diff --git a/src/MTS_IO_LE910Radio.cpp b/src/MTS_IO_LE910Radio.cpp index f383b68..b02c2ce 100644 --- a/src/MTS_IO_LE910Radio.cpp +++ b/src/MTS_IO_LE910Radio.cpp @@ -33,7 +33,7 @@ using namespace MTS::IO; LE910Radio::LE910Radio(const std::string& sLE910Model, const std::string& sPort) -: CellularRadio(sLE910Model, sPort) +: TelitRadio(sLE910Model, sPort) { } diff --git a/src/MTS_IO_ME910Radio.cpp b/src/MTS_IO_ME910Radio.cpp index 590a883..3ed9e50 100644 --- a/src/MTS_IO_ME910Radio.cpp +++ b/src/MTS_IO_ME910Radio.cpp @@ -25,7 +25,7 @@ using namespace MTS::IO; ME910Radio::ME910Radio(const std::string& sME910Model, const std::string& sPort) -: CellularRadio(sME910Model, sPort) +: TelitRadio(sME910Model, sPort) { } diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp new file mode 100644 index 0000000..365bbca --- /dev/null +++ b/src/MTS_IO_QuectelRadio.cpp @@ -0,0 +1 @@ +#include "mts/MTS_IO_QuectelRadio.h" diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp new file mode 100644 index 0000000..de863c3 --- /dev/null +++ b/src/MTS_IO_TelitRadio.cpp @@ -0,0 +1,1838 @@ +/* + * Copyright (C) 2019 by Multi-Tech Systems + * + * This file is part of libmts-io. + * + * libmts-io is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts-io is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts-io. If not, see . + * + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +using namespace MTS::IO; + +const char TelitRadio::ETX = 0x03; //Ends socket connection +const char TelitRadio::DLE = 0x10; //Escapes ETX and DLE within Payload +const char TelitRadio::CR = 0x0D; +const char TelitRadio::NL = 0x0A; +const char TelitRadio::CTRL_Z = 0x1A; + +const std::string TelitRadio::RSP_ERROR("ERROR"); +const std::string TelitRadio::RSP_OK("OK"); + + +const std::string TelitRadio::DEFAULT_RADIO_PORT("/dev/modem_at1"); +const std::string TelitRadio::DEFAULT_RADIO_DIR("/var/run/radio/"); +const std::string TelitRadio::VALUE_UNKNOWN("Unknown"); +const std::string TelitRadio::VALUE_UNAVAILABLE("Unavailable"); +const std::string TelitRadio::VALUE_NOT_SUPPORTED("Not Supported"); + +const std::string TelitRadio::VALUE_NOT_REGISTERED("NOT REGISTERED"); +const std::string TelitRadio::VALUE_REGISTERED("REGISTERED"); +const std::string TelitRadio::VALUE_SEARCHING("SEARCHING"); +const std::string TelitRadio::VALUE_DENIED("DENIED"); +const std::string TelitRadio::VALUE_ROAMING("ROAMING"); + +//Static Data +const std::string TelitRadio::KEY_TYPE("type"); //!< GSM or CDMA +const std::string TelitRadio::KEY_CODE("code"); //!< Product Code : H5, H6, C2, EV3, G3 +const std::string TelitRadio::KEY_MODEL("model"); //!< Model : HE910, LE910, CE910, DE910, GE910 +const std::string TelitRadio::KEY_MANUFACTURER("manufacturer"); //!< Manufacturer: Telit +const std::string TelitRadio::KEY_HARDWARE("hardware"); //!< Radio Hardware Version +const std::string TelitRadio::KEY_FIRMWARE("firmware"); //!< Radio Firmware Version +const std::string TelitRadio::KEY_FIRMWARE_BUILD("firmwarebuild"); //!< Radio Firmware Build + +const std::string TelitRadio::KEY_CARRIER("carrier"); //!< Cellular Service Provider (Home Network) +const std::string TelitRadio::VALUE_CARRIER_VERIZON("Verizon"); +const std::string TelitRadio::VALUE_CARRIER_AERIS("Aeris"); +const std::string TelitRadio::VALUE_CARRIER_SPRINT("Sprint"); +const std::string TelitRadio::VALUE_CARRIER_USCELLULAR("U.S. Cellular"); +const std::string TelitRadio::VALUE_CARRIER_ATT("AT&T"); +const std::string TelitRadio::VALUE_CARRIER_TMOBILE("T-Mobile"); + +const std::string TelitRadio::KEY_IMEI("imei"); //!< International Mobile Station Equipment Identity +const std::string TelitRadio::KEY_MEID("meid"); //!< Mobile Equipment Identifier +const std::string TelitRadio::KEY_IMSI("imsi"); //!< International Mobile Subscriber Identity +const std::string TelitRadio::KEY_MSID("msid"); //!< Mobil Station ID / Mobile Identification Number (MSID/MIN) (CDMA-Only) +const std::string TelitRadio::KEY_MDN("mdn"); //!< Mobile Directory Number : Actual phone number dialed to reach radio +const std::string TelitRadio::KEY_ICCID("iccid"); //!< Integrated Circuit Card Identifier +const std::string TelitRadio::KEY_MSL("msl"); //!< Master Subsidy Lock + +//Dynamic Data +const std::string TelitRadio::KEY_ROAMING("roaming"); //!< Indicates whether or not using Home Network +const std::string TelitRadio::KEY_DATETIME("datetime"); //!< Date and Time from tower +const std::string TelitRadio::KEY_SERVICE("service"); //!< Service Connection Type [GPRS, EGPRS, WCDMA, HSDPA, 1xRTT, EVDO] +const std::string TelitRadio::KEY_NETWORK("network"); //!< Cellular Service Provider +const std::string TelitRadio::KEY_NETWORK_REG("netreg"); //!< Network Registration +const std::string TelitRadio::KEY_CID("cid"); //!< Cellular ID (Tower) in HEX +const std::string TelitRadio::KEY_LAC("lac"); //!< Location Area Code in HEX +const std::string TelitRadio::KEY_RAC("rac"); //!< Routing Area Code in HEX +const std::string TelitRadio::KEY_RSSI("rssi"); //!< Signal Strength +const std::string TelitRadio::KEY_RSSIDBM("rssidBm"); //!< Signal Strength in dBm +const std::string TelitRadio::KEY_MCC("mcc"); //!< Country Code +const std::string TelitRadio::KEY_MNC("mnc"); //!< Operator Code +const std::string TelitRadio::KEY_CHANNEL("channel"); //!< ARFCN or UARFCN Assigned Radio Channel +const std::string TelitRadio::KEY_TXPWR("txpwr"); //!< Transmit Power +const std::string TelitRadio::KEY_PSC("psc"); //!< Active Primary Synchronization Code (PSC) +const std::string TelitRadio::KEY_ECIO("ecio"); //!< Active Ec/Io (chip energy per total wideband power in dBm) +const std::string TelitRadio::KEY_RSCP("rscp"); //!< Active RSCP (Received Signal Code Power in dBm) +const std::string TelitRadio::KEY_DRX("drx"); //!< Discontinuous reception cycle length (ms) +const std::string TelitRadio::KEY_MM("mm"); //!< Mobility Management State +const std::string TelitRadio::KEY_RR("rr"); //!< Radio Resource State +const std::string TelitRadio::KEY_NOM("nom"); //!< Network Operator Mode +const std::string TelitRadio::KEY_ABND("abnd"); //!< Active Band +const std::string TelitRadio::KEY_BLER("bler"); //!< Block Error Rate (percentage) +const std::string TelitRadio::KEY_SD("sd"); //!< Service Domain +const std::string TelitRadio::KEY_DEBUG("debug"); //!< Debug Information + +const std::string TelitRadio::KEY_MIP("mipProfile"); //!< Mobile IP Information +const std::string TelitRadio::KEY_MIP_ID("id"); //!< Mobile IP ID +const std::string TelitRadio::KEY_MIP_ENABLED("enabled"); //!< Mobile IP Enabled/Disabled +const std::string TelitRadio::KEY_MIP_NAI("nai"); //!< Network Access Identifier +const std::string TelitRadio::KEY_MIP_HOMEADDRESS("homeAddress"); //!< Home Address +const std::string TelitRadio::KEY_MIP_PRIMARYHA("primaryAddress"); //!< Primary Home Agent +const std::string TelitRadio::KEY_MIP_SECONDARYHA("secondaryAddress"); //!< Secondary Home Agent +const std::string TelitRadio::KEY_MIP_MNAAASPI("mnAaaSpi"); //!< Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index +const std::string TelitRadio::KEY_MIP_MNHASPI("mnHaSpi"); //!< Mobile Node Home Agent Security Server Parameter Index +const std::string TelitRadio::KEY_MIP_REVTUN("revTun"); //!< Reverse Tunneling Enabled +const std::string TelitRadio::KEY_MIP_MNAAASS("mnAaaSs"); //!< Mobile Node Authentication, Authorization, and Accounting Server Shared Secret +const std::string TelitRadio::KEY_MIP_MNHASS("mnHaSs"); //!< Mobile Node Home Agent Shared Secret + +const std::string TelitRadio::VALUE_TYPE_GSM("GSM"); +const std::string TelitRadio::VALUE_TYPE_LTE("LTE"); +const std::string TelitRadio::VALUE_TYPE_CDMA("CDMA"); + +const std::string TelitRadio::VALUE_SD_NO_SERVICE("NO SERVICE"); +const std::string TelitRadio::VALUE_SD_CS_ONLY("CS ONLY"); +const std::string TelitRadio::VALUE_SD_PS_ONLY("PS ONLY"); +const std::string TelitRadio::VALUE_SD_CSPS("CS+PS"); + +const std::string TelitRadio::VALUE_ABND_GSM_850("GSM 850"); +const std::string TelitRadio::VALUE_ABND_GSM_900("GSM 900"); +const std::string TelitRadio::VALUE_ABND_DCS_1800("DCS 1800"); +const std::string TelitRadio::VALUE_ABND_PCS_1900("PCS 1900"); + +const std::vector TelitRadio::DEFAULT_BAIL_STRINGS = { TelitRadio::RSP_OK, TelitRadio::RSP_ERROR }; + +TelitRadio::TelitRadio(const std::string& sName, const std::string& sRadioPort) +: m_sName(sName) +, m_sRadioPort(sRadioPort) +, m_bEchoEnabled(false) +, m_bEnableEchoOnClose(false) +{ + m_apIo.reset(new MTS::IO::SerialConnection( + MTS::IO::SerialConnection::Builder(m_sRadioPort) + .baudRate(115200) + .useLockFile() + .build())); +} + + +TelitRadio::~TelitRadio() { + shutdown(); + m_apIo.reset(); +} + +bool TelitRadio::initialize(uint32_t iTimeoutMillis) { + if(!m_apIo->open(iTimeoutMillis)) { + printError("%s| Failed to open radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str()); + return false; + } + + bool bEnabled; + CODE eCode = getEcho(bEnabled); + if(eCode == SUCCESS && bEnabled) { + printDebug("%s| Disabling 'echo'", m_sName.c_str()); + setEcho(false); + m_bEnableEchoOnClose = true; + } + + return true; +} + +bool TelitRadio::resetRadio(uint32_t iTimeoutMillis) { + + printInfo("%s| Rebooting radio", m_sName.c_str()); + if(sendBasicCommand("AT#REBOOT") == SUCCESS) { + if(iTimeoutMillis > 5000) { + MTS::Thread::sleep(5000); + iTimeoutMillis -= 5000; + } + return resetConnection(iTimeoutMillis); + } + + return false; +} + +bool TelitRadio::resetConnection(uint32_t iTimeoutMillis) { + //Close Current Connection + if(!m_apIo.isNull()) { + m_apIo->close(); + } + + m_apIo.reset(new MTS::IO::SerialConnection( + MTS::IO::SerialConnection::Builder(m_sRadioPort) + .baudRate(115200) + .useLockFile() + .build())); + + //Try to obtain the device port over the given period of time + MTS::Timer oTimer; + oTimer.start(); + uint64_t iCurrentTime = 0; + while(iCurrentTime < iTimeoutMillis) { + + if(!m_apIo->open(iTimeoutMillis - iCurrentTime)) { + printWarning("%s| Failed to re-open radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str()); + } else { + printInfo("%s| Successfully re-opened radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str()); + printDebug("%s| Recovering 'echo' after connection reset", m_sName.c_str()); // see TelitRadio::initialize + setEcho(m_bEchoEnabled); + break; + } + + ::usleep(500000); //500 millis + iCurrentTime = oTimer.getMillis(); + } + oTimer.stop(); + return !m_apIo->isClosed(); +} + +void TelitRadio::shutdown() { + + if(!m_apIo.isNull()) { + if(m_bEnableEchoOnClose) { + printDebug("%s| Enabling 'echo'", m_sName.c_str()); + setEcho(true); + m_bEnableEchoOnClose = false; + } + m_apIo->close(); + } +} + +const std::string& TelitRadio::getName() const { + return m_sName; +} + + +TelitRadio::CODE TelitRadio::getModel(std::string& sModel) { + printTrace("%s| Get Model", m_sName.c_str()); + //Always returns SUCCESS because the model should be m_sName + sModel = m_sName; + std::string sCmd("ATI4"); + std::string sResult = TelitRadio::sendCommand(m_apIo, sCmd); + if (sResult.find("OK") == std::string::npos) { + printWarning("%s| Unable to get model from radio. Returning [%s]", m_sName.c_str(), m_sName.c_str()); + return SUCCESS; + } else { + sModel = TelitRadio::extractModelFromResult(sResult); + if(sModel.size() == 0) { + printWarning("%s| Unable to get model from radio. Returning [%s]", m_sName.c_str(), m_sName.c_str()); + return SUCCESS; + } + } + + printDebug("%s| Extracted [%s] from [%s] query", m_sName.c_str(), sModel.c_str(), sCmd.c_str()); + if(sModel != m_sName) { + printWarning("%s| Model identified [%s] does not match expected [%s]. Returning [%s]", + m_sName.c_str(), sModel.c_str(), m_sName.c_str(), sModel.c_str()); + } + + return SUCCESS; +} + +TelitRadio::CODE TelitRadio::convertModelToMtsShortCode(const std::string& sModel, std::string& sCode, TelitRadio *radioObject) { + CODE eCode = FAILURE; + + if(sModel.find("HE910-D") == 0) { + sCode = "H5"; + eCode = SUCCESS; + } else if (sModel.find("HE910-EUD") == 0) { + sCode = "H6"; + eCode = SUCCESS; + } else if (sModel.find("LE910-JN1") == 0) { + sCode = "LDC3"; + eCode = SUCCESS; + } else if (sModel.find("LE866A1-JS") == 0) { + sCode = "LSB3"; + eCode = SUCCESS; + } else if (sModel.find("LE910-NAG") == 0) { + sCode = "LAT1"; + eCode = SUCCESS; + } else if (sModel.find("LE910C4-NF") == 0) { + sCode = "L4N1"; + eCode = SUCCESS; + } else if (sModel.find("LE910-NA1") == 0) { + if (NULL == radioObject) { + sCode = VALUE_NOT_SUPPORTED; + eCode = ERROR; + } else { + std::string sValue; + eCode = radioObject->getActiveFirmware(sValue); + if (eCode == SUCCESS) { + sCode = "LNA3"; + } else { + sCode = "LAT3"; + } + } + eCode = SUCCESS; + } else if (sModel.find("LE910-SVG") == 0) { + sCode = "LVW2"; + eCode = SUCCESS; + } else if (sModel.find("LE910C1-NS") == 0) { + sCode = "LSP3"; + eCode = SUCCESS; + } else if (sModel.find("LE910C1-AP") == 0) { + sCode = "LAP3"; + eCode = SUCCESS; + } else if (sModel.find("ME910C1-NA") == 0) { + sCode = "MAT1"; + eCode = SUCCESS; + } else if (sModel.find("ME910C1-NV") == 0) { + sCode = "MVW1"; + eCode = SUCCESS; + } else if (sModel.find("ME910C1-WW") == 0) { + sCode = "MNG2"; + eCode = SUCCESS; + } else if (sModel.find("LE910-EUG") == 0) { + sCode = "LEU1"; + eCode = SUCCESS; + } else if (sModel.find("LE910C4-EU") == 0) { + sCode = "L4E1"; + eCode = SUCCESS; + } else if (sModel.find("LE910-EU1") == 0) { + sCode = "LEU3"; + eCode = SUCCESS; + } else if (sModel.find("GE910") == 0) { + sCode = "G3"; + eCode = SUCCESS; + } else if (sModel.find("CE910") == 0) { + sCode = "C2"; + eCode = SUCCESS; + } else if (sModel.find("DE910") == 0) { + sCode = "EV3"; + eCode = SUCCESS; + } else { + sCode = VALUE_NOT_SUPPORTED; + printError("RADIO| Could not identify MTS short code from model. [%s]", sModel.c_str()); + eCode = ERROR; + } + return eCode; +} + +TelitRadio::CODE TelitRadio::convertServiceDomainToString(SERVICEDOMAIN eSd, std::string& sSd) { + CODE eCode = FAILURE; + switch(eSd) { + case NO_SERVICE: sSd = VALUE_SD_NO_SERVICE; eCode = SUCCESS; break; + case CS_ONLY: sSd = VALUE_SD_CS_ONLY; eCode = SUCCESS; break; + case PS_ONLY: sSd = VALUE_SD_PS_ONLY; eCode = SUCCESS; break; + case CSPS: sSd = VALUE_SD_CSPS; eCode = SUCCESS; break; + default: sSd = VALUE_UNKNOWN; eCode = FAILURE; break; + } + return eCode; +} + +TelitRadio::CODE TelitRadio::convertActiveBandToString(ACTIVEBAND eBand, std::string& sBand) { + CODE eCode = FAILURE; + switch(eBand) { + case GSM_850: sBand = VALUE_ABND_GSM_850; eCode = SUCCESS; break; + case GSM_900: sBand = VALUE_ABND_GSM_900; eCode = SUCCESS; break; + case DCS_1800: sBand = VALUE_ABND_DCS_1800; eCode = SUCCESS; break; + case PCS_1900: sBand = VALUE_ABND_PCS_1900; eCode = SUCCESS; break; + default: sBand = VALUE_UNKNOWN; eCode = FAILURE; break; + } + return eCode; +} + +TelitRadio::CODE TelitRadio::convertModelToType(const std::string& sModel, std::string& sType) { + CODE eCode = FAILURE; + sType = VALUE_NOT_SUPPORTED; + + if(sModel.find("HE910-D") == 0) { + sType = VALUE_TYPE_GSM; + eCode = SUCCESS; + } else if (sModel.find("HE910-EUD") == 0) { + sType = VALUE_TYPE_GSM; + eCode = SUCCESS; + } else if (sModel.find("LE910-JN1") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE866A1-JS") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE910-NAG") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE910C4-NF") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE910-NA1") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE910-SVG") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE910-EUG") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE910C4-EU") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE910-EU1") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE910C1-NS") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE910C1-AP") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("ME910C1-NA") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("ME910C1-NV") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("ME910C1-WW") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("GE910") == 0) { + sType = VALUE_TYPE_GSM; + eCode = SUCCESS; + } else if (sModel.find("CE910") == 0) { + sType = VALUE_TYPE_CDMA; + eCode = SUCCESS; + } else if (sModel.find("DE910") == 0) { + sType = VALUE_TYPE_CDMA; + eCode = SUCCESS; + } else { + sType = VALUE_TYPE_GSM; + eCode = ERROR; + printError("RADIO| Could not identify type from model. [%s]. Assuming [%s]", sModel.c_str(), sType.c_str()); + } + return eCode; +} + +TelitRadio::CODE TelitRadio::getFirmware(std::string& sFirmware) { + printTrace("%s| Get Firmware", m_sName.c_str()); + sFirmware = VALUE_NOT_SUPPORTED; + std::string sCmd("AT+CGMR"); + std::string sResult = TelitRadio::sendCommand(sCmd); + size_t pos = sResult.find(RSP_OK); + if (pos == std::string::npos) { + printWarning("%s| Unable to get firmware from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + sFirmware = MTS::Text::trim(sResult.substr(0, pos)); + if(sFirmware.size() == 0) { + printWarning("%s| Unable to get firmware from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + m_sFirmware = sFirmware; + + return SUCCESS; +} + +TelitRadio::CODE TelitRadio::getFirmwareBuild(std::string& sFirmwareBuild) { + sFirmwareBuild = VALUE_NOT_SUPPORTED; + return FAILURE; +} + +TelitRadio::CODE TelitRadio::getHardware(std::string& sHardware) { + printTrace("%s| Get Hardware", m_sName.c_str()); + sHardware = VALUE_NOT_SUPPORTED; + + if(m_sFirmware.size() == 0) { + getFirmware(m_sFirmware); + } + + if(getHardwareVersionFromFirmware(m_sFirmware, sHardware)) { + return SUCCESS; + } + return FAILURE; +} + +TelitRadio::CODE TelitRadio::getManufacturer(std::string& sManufacturer) { + printTrace("%s| Get Manufacturer", m_sName.c_str()); + sManufacturer = VALUE_NOT_SUPPORTED; + std::string sCmd("AT+GMI"); + std::string sResult = TelitRadio::sendCommand(sCmd); + size_t pos = sResult.find(RSP_OK); + if (pos == std::string::npos) { + printWarning("%s| Unable to get manufacturer from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + sManufacturer = MTS::Text::trim(sResult.substr(0, pos)); + if(sManufacturer.size() == 0) { + printWarning("%s| Unable to get manufacturer from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + return SUCCESS; +} + +TelitRadio::CODE TelitRadio::getImei(std::string& sImei) { + printTrace("%s| Get IMEI", m_sName.c_str()); + sImei = VALUE_NOT_SUPPORTED; + std::string sCmd("AT+CGSN"); + std::string sResult = TelitRadio::sendCommand(sCmd); + size_t pos = sResult.find(RSP_OK); + if (pos == std::string::npos) { + printWarning("%s| Unable to get IMEI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + sImei = MTS::Text::trim(sResult.substr(0, pos)); + if(sImei.size() == 0) { + printWarning("%s| Unable to get IMEI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + return SUCCESS; +} + +TelitRadio::CODE TelitRadio::getMeid(std::string& sMeid) { + printTrace("%s| Get MEID", m_sName.c_str()); + return getImei(sMeid); +} + +TelitRadio::CODE TelitRadio::getImsi(std::string& sImsi) { + printTrace("%s| Get IMSI", m_sName.c_str()); + sImsi = VALUE_NOT_SUPPORTED; + std::string sCmd("AT+CIMI"); + std::string sResult = TelitRadio::sendCommand(sCmd); + size_t pos = sResult.find(RSP_OK); + if (pos == std::string::npos) { + printWarning("%s| Unable to get IMSI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + sImsi = MTS::Text::trim(sResult.substr(0, pos)); + if(sImsi.size() == 0) { + printWarning("%s| Unable to get IMSI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + return SUCCESS; +} + +TelitRadio::CODE TelitRadio::getSimStatus(std::string& sSimStatus) { + printTrace("%s| Get SIM Status", getName().c_str()); + sSimStatus = VALUE_UNKNOWN; + return FAILURE; +} + +TelitRadio::CODE TelitRadio::getIccid(std::string& sIccid) { + printTrace("%s| Get ICCID", m_sName.c_str()); + sIccid = VALUE_NOT_SUPPORTED; + std::string sCmd("AT#CCID"); + std::string sResult = TelitRadio::sendCommand(sCmd); + size_t end = sResult.find(RSP_OK); + if (end == std::string::npos) { + printWarning("%s| Unable to get ICCID from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + size_t start = sResult.find("#CCID:"); + if(start != std::string::npos) { + start += sizeof("#CCID:"); + sIccid = MTS::Text::trim(sResult.substr(start, end-start)); + if(sIccid.size() == 0) { + printWarning("%s| Unable to get ICCID from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + } + return SUCCESS; +} + +TelitRadio::CODE TelitRadio::getService(std::string& sService) { + printTrace("%s| Get Service", m_sName.c_str()); + sService = VALUE_NOT_SUPPORTED; + std::string sCmd("AT#PSNT?"); + std::string sResult = TelitRadio::sendCommand(sCmd); + size_t end = sResult.find(RSP_OK); + if (end == std::string::npos) { + printWarning("%s| Unable to get Service from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + size_t start = sResult.find(","); + if(start != std::string::npos) { + start += 1; //comma + std::string sPsnt = MTS::Text::trim(sResult.substr(start, end-start)); + int32_t iService; + sscanf(sPsnt.c_str(), "%d", &iService); + + switch(iService) { + case 0: sService = "GPRS"; break; + case 1: sService = "EGPRS"; break; + case 2: sService = "WCDMA"; break; + case 3: sService = "HSDPA"; break; + case 4: sService = "LTE"; break; + default: sService = VALUE_UNKNOWN; break; + } + + printDebug("%s| Service ID: [%d][%s]", m_sName.c_str(), iService, sService.c_str()); + } + return SUCCESS; +} + +TelitRadio::CODE TelitRadio::getLac(std::string& sLac) { + Json::Value jData; + + printTrace("%s| Get LAC", m_sName.c_str()); + sLac = VALUE_NOT_SUPPORTED; + + if(getNetworkStatus(jData) == SUCCESS) { + if(jData.isMember(KEY_LAC)) { + sLac = jData[KEY_LAC].asString(); + return SUCCESS; + } + } + + return FAILURE; +} + +TelitRadio::CODE TelitRadio::getMdn(std::string& sMdn) { + printTrace("%s| Get MDN", m_sName.c_str()); + sMdn = VALUE_NOT_SUPPORTED; + std::string sCmd("AT+CNUM"); + std::string sResult = TelitRadio::sendCommand(sCmd); + size_t end = sResult.find(RSP_OK); + if (end == std::string::npos) { + printWarning("%s| Unable to get MDN from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + size_t start = sResult.find("CNUM:"); + if(start != std::string::npos) { + start += sizeof("CNUM:"); + std::vector vParts = MTS::Text::split(sResult.substr(start, end - start), ','); + if(vParts.size() < 3) { + printWarning("%s| Unable to parse MDN from response [%s]", m_sName.c_str(), sResult.c_str()); + return FAILURE; + } + sMdn = MTS::Text::strip(vParts[1], '"'); + if(sMdn.size() == 0) { + printWarning("%s| Unable to get MDN from radio using command [%s]. MDN may not be set.", m_sName.c_str(), sCmd.c_str()); + } + } else { + sMdn = ""; + printWarning("%s| Unable to get MDN from radio using command [%s]. MDN may not be set.", m_sName.c_str(), sCmd.c_str()); + } + + return SUCCESS; +} + +TelitRadio::CODE TelitRadio::getMsid(std::string& sMsid) { + printTrace("%s| Get MSID", m_sName.c_str()); + sMsid = ""; + + std::string sImsi; + if(getImsi(sImsi) == SUCCESS) { + if(sImsi.size() >= 10) { + sMsid = sImsi.substr(sImsi.size() - 10); + printTrace("IMSI: [%s] MEID [%s]", sImsi.c_str(), sMsid.c_str()); + return SUCCESS; + } + } + printWarning("%s| Unable to get MSID from radio", m_sName.c_str()); + return FAILURE; +} + +TelitRadio::CODE TelitRadio::getType(std::string& sType) { + printTrace("%s| Get Type", m_sName.c_str()); + sType = VALUE_NOT_SUPPORTED; + return FAILURE; +} + +TelitRadio::CODE TelitRadio::getCarrier(std::string& sCarrier) { + printTrace("%s| Get Carrier", m_sName.c_str()); + if(m_sCarrier == "") { + Json::Value jData; + if(getNetworkStatus(jData) == SUCCESS) { + if(jData.isMember(KEY_MCC) && jData.isMember(KEY_MNC)) { + std::string sMcc = jData[KEY_MCC].asString(); + std::string sMnc = jData[KEY_MNC].asString(); + Json::Value jLookup = MccMncTable::getInstance()->lookup(sMcc, sMnc); + printTrace("%s| MCC-MNC Lookup: [%s][%s][%s]", m_sName.c_str(), + sMcc.c_str(), sMnc.c_str(), jLookup.toStyledString().c_str()); + if(jLookup.isMember(KEY_CARRIER)) { + m_sCarrier = jLookup[KEY_CARRIER].asString(); + } else { + printWarning("%s| MCC-MNC Lookup did not contain carrier", m_sName.c_str()); + return FAILURE; + } + } else { + printWarning("%s| Network Status did no contain MCC or MNC", m_sName.c_str()); + return FAILURE; + } + } else { + return FAILURE; + } + } + + sCarrier = m_sCarrier; + return SUCCESS; +} + +TelitRadio::CODE TelitRadio::getTower(std::string& sTower) { + Json::Value jData; + + printTrace("%s| Get Tower", m_sName.c_str()); + sTower = VALUE_NOT_SUPPORTED; + + if(getNetworkStatus(jData) == SUCCESS) { + if(jData.isMember(KEY_CID)) { + sTower = jData[KEY_CID].asString(); + return SUCCESS; + } + } + return FAILURE; +} + +TelitRadio::CODE TelitRadio::getTime(std::string& sDate, std::string& sTime, std::string& sTimeZone) { + Json::Value jData; + + printTrace("%s| Get Time", m_sName.c_str()); + sDate = ""; + sTime = ""; + sTimeZone = ""; + + std::string sCmd("AT+CCLK?"); + std::string sResult = TelitRadio::sendCommand(sCmd); + size_t end = sResult.find(RSP_OK); + if (end == std::string::npos) { + printWarning("%s| Unable to get Time from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + size_t start = sResult.find("CCLK: "); + if(start != std::string::npos) { + start += sizeof("CCLK: "); + std::string sValue = MTS::Text::trim(sResult.substr(start, end - start)); + sValue = MTS::Text::strip(sValue, '"'); + + std::vector vParts = MTS::Text::split(sValue, ','); + if(vParts.size() != 2) { + printWarning("%s| Unable to parse Date from response [%s]", m_sName.c_str(), sResult.c_str()); + return FAILURE; + } + + + std::vector vDateParts = MTS::Text::split(vParts[0], '/'); + if(vDateParts.size() != 3) { + printWarning("%s| Unable to parse Date from response [%s]", m_sName.c_str(), sResult.c_str()); + return FAILURE; + } + + //The Date format is YY/MM/DD -> Change to MM/DD/YY + sDate = vDateParts[1] + "/" + vDateParts[2] + "/" + vDateParts[0]; + + vParts = MTS::Text::split(vParts[1], '-'); + if(vParts.size() != 2) { + printWarning("%s| Unable to parse Time from response [%s]", m_sName.c_str(), sResult.c_str()); + return FAILURE; + } + sTime = vParts[0]; + + int32_t iZoneUnits; //the difference, expressed in quarters of an hour, between the local time and GMT + if(!MTS::Text::parse(iZoneUnits, MTS::Text::strip(vParts[1], '+'))) { + printWarning("%s| Unable to parse Time Zone from response [%s]", m_sName.c_str(), sResult.c_str()); + return FAILURE; + } + + int32_t iZone = iZoneUnits/4; //Divide by 4 to get hours difference + int32_t iZonePartial = (iZoneUnits % 4) * 15; //Remainder in minutes + std::string sPlusSign = "+"; + if(iZonePartial < 0) { + //Remove negative sign from partial and clear plus sign component + iZonePartial *= -1; + sPlusSign = ""; + } + std::stringstream ss; + ss << sPlusSign << iZone; + if(iZonePartial != 0) { + ss << ":" << iZonePartial; + } + + sTimeZone = ss.str(); + return SUCCESS; + + } else { + printWarning("%s| Unable to get Time from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + } + + return FAILURE; +} + +TelitRadio::CODE TelitRadio::getRoaming(bool& bRoaming) { + Json::Value jData; + + printTrace("%s| Get Roaming", m_sName.c_str()); + bRoaming = false; + + REGISTRATION eReg; + if(getRegistration(eReg) == SUCCESS) { + bRoaming = (eReg == ROAMING); + return SUCCESS; + } + return FAILURE; +} + +TelitRadio::CODE TelitRadio::getNetwork(std::string& sNetwork) { + Json::Value jData; + + printTrace("%s| Get Network", m_sName.c_str()); + sNetwork = VALUE_NOT_SUPPORTED; + + if(getNetworkStatus(jData) == SUCCESS) { + if(jData.isMember(KEY_NETWORK)) { + sNetwork = jData[KEY_NETWORK].asString(); + return SUCCESS; + } + } + return FAILURE; +} + +TelitRadio::CODE TelitRadio::getSignalStrength(int32_t& rssi) { + printTrace("%s| Get Signal Strength", m_sName.c_str()); + std::string sCmd("AT+CSQ"); + std::string sResult = sendCommand(sCmd); + if (sResult.find("+CSQ: ") == std::string::npos) { + printDebug("%s| Signal Strength 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); + if(start == std::string::npos || stop == std::string::npos) { + printDebug("%s| Signal Strength command returned malformed response: [%s]", m_sName.c_str(), sResult.c_str()); + return FAILURE; + } + std::string signal = sResult.substr(start + 2, stop - start - 2); + + sscanf(signal.c_str(), "%d", &rssi); + printDebug("%s| Signal Strength: [%d]", m_sName.c_str(), rssi); + + return SUCCESS; +} + +TelitRadio::CODE TelitRadio::getModemLocation(std::string& sLocation) { + printTrace("%s|TelitRadio getModemLocation - not supported", m_sName.c_str()); + return FAILURE; +} + +TelitRadio::CODE TelitRadio::convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& iDbm) { + + //Telit Conversion + if(iRssi < 0 || iRssi == 99) { + return FAILURE; + } + + if(iRssi == 0) { + iDbm = -113; + } else if(iRssi == 1) { + iDbm = -111; + } else if(iRssi <= 30) { + //28 steps between 2 and 30 + //54 dbm between 53 and 109 + float stepSize = 54.0 / 28.0; + iDbm = -109 + (int)(stepSize * (iRssi-2)); + } else { + iDbm = -51; + } + + return SUCCESS; +} + +TelitRadio::CODE TelitRadio::convertdBmToSignalStrength(const int32_t& iDBm, int32_t& iRssi) { + //Telit Conversion + if(iDBm <= -113) { + iRssi = 0; + } else if(iDBm <= -111) { + iRssi = 1; + } else if(iDBm <= -53) { + //54 dbm between -109 and -53 + //28 steps between 2 and 30 + float stepSize = 28.0/54.0; + iRssi = ((iDBm + 109)*stepSize) + 2; + } else { + iRssi = 31; + } + + return SUCCESS; +} + +TelitRadio::CODE TelitRadio::getEcho(bool& bEnabled) { + printTrace("%s| Echo Test", m_sName.c_str()); + std::string sResult = sendCommand("AT"); + if(sResult.size() == 0) { + return NO_RESPONSE; + } + + if(sResult.find("AT") != std::string::npos) { + bEnabled = true; + } else { + bEnabled = false; + } + m_bEchoEnabled = bEnabled; + return SUCCESS; +} + +TelitRadio::CODE TelitRadio::setEcho(bool bEnabled) { + CODE eCode = FAILURE; + if(bEnabled) { + eCode = sendBasicCommand("ATE1"); + m_bEchoEnabled = (eCode == SUCCESS ) ? true : m_bEchoEnabled; + } else { + eCode = sendBasicCommand("ATE0"); + m_bEchoEnabled = (eCode == SUCCESS ) ? false : m_bEchoEnabled; + } + + return eCode; +} + +TelitRadio::CODE TelitRadio::getStaticInformation(Json::Value& jData) { + printTrace("%s| Get Static Information", m_sName.c_str()); + + printTrace("%s| Static Information:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); + + return FAILURE; +} + +/* AT#RFSTS - NETWORK STATUS + + (GSM network) + #RFSTS:,,,,,,,,,,,,, + Where: + - Country code and operator code(MCC, MNC) + - GSM Assigned Radio Channel + - Received Signal Strength Indication + - Localization Area Code + - Routing Area Code + - Tx Power + - Mobility Management state + - Radio Resource state + - Network Operator Mode + - Cell ID + - International Mobile Subscriber Identity + - Operator name + - Service Domain + 0 - No Service + 1 - CS only + 2 - PS only + 3 - CS+PS + - Active Band + 1 - GSM 850 + 2 - GSM 900 + 3 - DCS 1800 + 4 - PCS 1900 + + + (WCDMA network) + #RFSTS: + ,,,,, RSSI>,,,,,,,,,,, + ,,[,,] + Where: + - Country code and operator code(MCC, MNC) + - UMTS Assigned Radio Channel + - Active PSC(Primary Synchronization Code) + - Active Ec/Io(chip energy per total wideband power in dBm) + - Active RSCP (Received Signal Code Power in dBm) + - Received Signal Strength Indication + - Localization Area Code + - Routing Area Code + - Tx Power + - Discontinuous reception cycle Length (cycle length in ms) + - Mobility Management state + - Radio Resource state + - Network Operator Mode + - Block Error Rate (e.g., 005 means 0.5 %) + - Cell ID + - International Mobile Station ID + - Operator name + - Service Domain (see above) + - Number of Active Set (Maximum 6) + UARFCN of n th active set + PSC of n th active set + Ec/Io of n th active Set + + (LTE Network) + #RFSTS: + - + - + - + - + - + - + [] - + - + - + - + - + - + [] - + - + - +*/ +TelitRadio::CODE TelitRadio::getNetworkStatus(Json::Value& jData) { + int32_t iValue; + std::string sValue; + const uint32_t GSM_NETWORK_FORMAT = 14; + const uint32_t WCDMA_NETWORK_FORMAT = 19; + const uint32_t LTE_NETWORK_FORMAT = 16; + + printTrace("%s| Get Network Status", m_sName.c_str()); + + //Always get common network stats because this should never fail + //This way the basic stats are always returned even if AT#RFSTS fails below + getCommonNetworkStats(jData); + + std::string sCmd; + std::string sResult; + // LE910 radios have a bug where issuing AT#RFSTS with a locked SIM + // will cause the radio to stop responding until a radio power cycle + // Telit Support Portal Case #5069697 + // LE910C1-NS is an LE910, so we stop the scan after the 0. + if (m_sName.find("LE910") != std::string::npos) { + sCmd = "AT+CPIN?"; + sResult = sendCommand(sCmd); + if (sResult.find("+CPIN:") == std::string::npos) { + printDebug("%s| AT+CPIN? returned unexpected response: [%s][%s]", m_sName.c_str(), sCmd.c_str(), sResult.c_str()); + printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); + return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function + } + if (sResult.find("SIM PIN") != std::string::npos) { + printError("%s| The SIM is locked and must first be unlocked", m_sName.c_str()); + printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); + return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function + } + } + + sCmd = "AT#RFSTS"; + sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 200); + if (sResult.find("#RFSTS:") == std::string::npos) { + //On LTE radios without signal, this case will run because AT#RFSTS just returns "OK" + printDebug("%s| Network Status command returned unexpected response: [%s][%s]", m_sName.c_str(), sCmd.c_str(), sResult.c_str()); + printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); + return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function + } + + size_t start = sResult.find(":") + 1; //Position right after "#RFSTS:" + std::vector vParts = MTS::Text::split(MTS::Text::trim(sResult.substr(start)), ","); + + if (vParts.size() < 3) { + printDebug("%s| Network Status command reponse is an unknown format: [%s][%s]", m_sName.c_str(), sCmd.c_str(), sResult.c_str()); + printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); + return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function + } else { + //Country Code and Operator Code + std::vector vPLMN = MTS::Text::split(vParts[0], ' '); + if(vPLMN.size() == 2) { + jData[KEY_MCC] = MTS::Text::strip(vPLMN[0], '"'); + jData[KEY_MNC] = MTS::Text::strip(vPLMN[1], '"'); + } + + jData[KEY_CHANNEL] = vParts[1]; + } + + if (vParts.size() == GSM_NETWORK_FORMAT ) { + //Parse as GSM Network Format + jData[KEY_RSSIDBM] = vParts[2]; + jData[KEY_LAC] = vParts[3]; + jData[KEY_RAC] = vParts[4]; + jData[KEY_TXPWR] = vParts[5]; + jData[KEY_MM] = vParts[6]; + jData[KEY_RR] = vParts[7]; + jData[KEY_NOM] = vParts[8]; + jData[KEY_CID] = vParts[9]; + jData[KEY_IMSI] = MTS::Text::strip(vParts[10], '"'); + jData[KEY_NETWORK] = MTS::Text::strip(vParts[11], '"'); + if(MTS::Text::parse(iValue, vParts[12]) && convertServiceDomainToString((SERVICEDOMAIN)iValue, sValue) == SUCCESS) { + jData[KEY_SD] = sValue; + } + if(MTS::Text::parse(iValue, vParts[13]) && convertActiveBandToString((ACTIVEBAND)iValue, sValue) == SUCCESS) { + jData[KEY_ABND] = sValue; + } + // IN003567 ME910C1 radios have some odd behavior with regards to WCDMA. The ordering of the fields from #RFSTS are + // the same as LTE up to the 16th field (for ME901C1-WW anyway). Drop into LTE parsing for ME910C1-WW. + } else if((vParts.size() >= WCDMA_NETWORK_FORMAT) && (m_sName.find("ME910C1-WW") == std::string::npos)) { + Json::Value jDebug; + + //Parse as WCDMA Network Format + + jDebug[KEY_PSC] = vParts[2]; + jDebug[KEY_ECIO] = vParts[3]; + jDebug[KEY_RSCP] = vParts[4]; + + jData[KEY_RSSIDBM] = vParts[5]; + jData[KEY_LAC] = vParts[6]; + jData[KEY_RAC] = vParts[7]; + + jDebug[KEY_TXPWR] = vParts[8]; + jDebug[KEY_DRX] = vParts[9]; + jDebug[KEY_MM] = vParts[10]; + jDebug[KEY_RR] = vParts[11]; + jDebug[KEY_NOM] = vParts[12]; + + if(vParts[13].size() != 0) { + jDebug[KEY_BLER] = vParts[13]; + } else { + jDebug[KEY_BLER] = "000"; + } + + jData[KEY_CID] = vParts[14]; + jData[KEY_IMSI] = MTS::Text::strip(vParts[15], '"'); + jData[KEY_NETWORK] = MTS::Text::strip(vParts[16], '"'); + + // Get the radio band given the channel (UARFCN) + RadioBandMap radioBandMap(vParts[1], TelitRadio::VALUE_TYPE_CDMA); + jData[KEY_ABND] = radioBandMap.getRadioBandName(); + + if(MTS::Text::parse(iValue, vParts[17]) && convertServiceDomainToString((SERVICEDOMAIN)iValue, sValue) == SUCCESS) { + jDebug[KEY_SD] = sValue; + } + //Ignoring Active Set Values + // - Number of Active Set (Maximum 6) + // - UARFCN of n th active set + // - PSC of n th active set + // - Ec/Io of n th active Set + + jData[KEY_DEBUG] = jDebug; + } else if(vParts.size() >= LTE_NETWORK_FORMAT) { + Json::Value jDebug; + + //Parse as LTE Network Format + + // + // MD: It is noticed that LTE Network format may vary depending on the firmware version: + // + // ,,,,,,[],,,,,,[],,, + // Ex 1: #RFSTS: "310 260",2300,-98,-63,-14,AA06,,128,19,0,0501D02,"310260754792598","T-Mobile",3,4,197 + // + // ,,,,,,,[],,,,,,[],, + // Ex 2: #RFSTS:"310 410",5780,-105,-73,-14,4603,255,,128,19,0,0000098,"310410536498694","AT&T",3,17 + // #RFSTS:"311 480",1150,-96,-66,-9.0,bf35,FF,0,0,19,1,"2ED1B0E","311480148817753","Verizon",2,2,720000,10800 + // #RFSTS:"310 410",2175,-120,-89,-17.5,4612,FF,0,0,19,1,"4E5E916","310410807276607","AT&T",3,4 + // + // Additional parameter in the second example shifts the rest of the parameters. Here we are trying to figure out + // which format is currently produced based on field position which always has double quotation marks. + // + if (vParts[13].find("\"") != std::string::npos) { + // parse the RAC and then remove it from the vector + jData[KEY_RAC] = vParts[6]; + vParts.erase(vParts.begin() + 6); + } + + jDebug["rsrp"] = vParts[2]; + jDebug[KEY_RSSIDBM] = vParts[3]; + jDebug["rsrq"] = vParts[4]; + + jData["tac"] = vParts[5]; + jDebug[KEY_TXPWR] = vParts[6]; + jData[KEY_DRX] = vParts[7]; + jDebug[KEY_MM] = vParts[8]; + jDebug["rrc"] = vParts[9]; + jData[KEY_CID] = MTS::Text::strip(vParts[10], '"'); + jData[KEY_IMSI] = MTS::Text::strip(vParts[11], '"'); + jData[KEY_NETWORK] = MTS::Text::strip(vParts[12], '"'); + + // Get the radio band given the channel (EARFCN) + RadioBandMap radioBandMap(vParts[1], TelitRadio::VALUE_TYPE_LTE); + jData[KEY_ABND] = radioBandMap.getRadioBandName(); + + jData[KEY_LAC] = queryLteLac(); + + if(MTS::Text::parse(iValue, vParts[13]) && convertServiceDomainToString((SERVICEDOMAIN)iValue, sValue) == SUCCESS) { + jDebug[KEY_SD] = sValue; + } + + jData[KEY_DEBUG] = jDebug; + } + + printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); + return SUCCESS; +} + +// Get the LAC for the LTE radio that's not in the #RFSTS response +std::string TelitRadio::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 = TelitRadio::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)), ","); + if(vParts.size() < 3) { + result = TelitRadio::VALUE_UNAVAILABLE; + } else { + result = MTS::Text::strip(vParts[2], '"'); + } + } + + setCGREG(originalCGREG); + + return result; +} + +void TelitRadio::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 TelitRadio::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 TelitRadio::getCommonNetworkStats(Json::Value& jData) { + + bool bRoaming = false; + if(getRoaming(bRoaming) == SUCCESS) { + jData[KEY_ROAMING] = bRoaming; + } + + int32_t iRssi; + if(getSignalStrength(iRssi) == SUCCESS) { + jData[KEY_RSSI] = iRssi; + int32_t dBm; + if(!jData.isMember(KEY_RSSIDBM) && convertSignalStrengthTodBm(iRssi, dBm) == SUCCESS) { + //Add RSSI in dBm format + jData[KEY_RSSIDBM] = MTS::Text::format(dBm); + } + } + + std::string sService; + if(getService(sService) == SUCCESS) { + jData[KEY_SERVICE] = sService; + } + std::string sDate, sTime, sTimeZone; + if(getTime(sDate, sTime, sTimeZone) == SUCCESS) { + jData[KEY_DATETIME] = sDate + " " + sTime + " GMT" + sTimeZone; + } + + std::string sNetworkReg; + TelitRadio::REGISTRATION eReg; + if (getRegistration(eReg) == SUCCESS) { + if (convertRegistrationToString(eReg, sNetworkReg) == SUCCESS) { + jData[TelitRadio::KEY_NETWORK_REG] = sNetworkReg; + } + } +} + +void TelitRadio::initMipProfile(Json::Value& jData) { + jData[KEY_MIP_ID] = 0; + jData[KEY_MIP_ENABLED] = false; + jData[KEY_MIP_NAI] = VALUE_UNKNOWN; + jData[KEY_MIP_HOMEADDRESS] = VALUE_UNKNOWN; + jData[KEY_MIP_PRIMARYHA] = VALUE_UNKNOWN; + jData[KEY_MIP_SECONDARYHA] = VALUE_UNKNOWN; + jData[KEY_MIP_MNAAASPI] = VALUE_UNKNOWN; + jData[KEY_MIP_MNHASPI] = VALUE_UNKNOWN; + jData[KEY_MIP_MNAAASS] = false; + jData[KEY_MIP_MNHASS] = false; +} + +TelitRadio::CODE TelitRadio::getRegistration(REGISTRATION& eRegistration) { + std::string sCmd; + std::string sResp; + + // LE910C1-NS is an LE910, so we stop the scan after the 0. + if (m_sName.find("LE910") != std::string::npos) { + // use AT+CGREG instead for LE910 models + sCmd = "AT+CGREG?"; + sResp = "+CGREG: "; + } + else { + 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: [%s]", 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; + return SUCCESS; +} + +TelitRadio::CODE TelitRadio::convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration) { + + CODE eCode = FAILURE; + switch (eRegistration) { + case NOT_REGISTERED: sRegistration = VALUE_NOT_REGISTERED; eCode = SUCCESS; break; + case REGISTERED: sRegistration = VALUE_REGISTERED; eCode = SUCCESS; break; + case SEARCHING: sRegistration = VALUE_SEARCHING; eCode = SUCCESS; break; + case DENIED: sRegistration = VALUE_DENIED; eCode = SUCCESS; break; + case UNKNOWN: sRegistration = VALUE_UNKNOWN; eCode = SUCCESS; break; + case ROAMING: sRegistration = VALUE_ROAMING; eCode = SUCCESS; break; + } + return eCode; +} + +TelitRadio::CODE TelitRadio::validateMsl(const Json::Value& jArgs) { + printTrace("%s| Validate MSL", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::setMdn(const Json::Value& jArgs) { + printTrace("%s| Set MDN", m_sName.c_str()); + + if(!jArgs["mdn"].isString()) { + return INVALID_ARGS; + } + + std::string sCmd("AT#SNUM=1,\""); + sCmd += jArgs["mdn"].asString() + "\""; + + std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 1000); + size_t end = sResult.find(RSP_OK); + if (end == std::string::npos) { + printWarning("%s| Unable to set MDN for radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + return SUCCESS; +} + +TelitRadio::CODE TelitRadio::setMsid(const Json::Value& jArgs) { + printTrace("%s| Set MSID", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::getMipProfile(Json::Value& jMipProfile) { + printTrace("%s| Get MIP Active Profile", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::setMipActiveProfile(const Json::Value& jArgs) { + printTrace("%s| Set MIP Active Profile", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::setMipNai(const Json::Value& jArgs) { + printTrace("%s| Set MIP NAI", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::setMipHomeIp(const Json::Value& jArgs) { + printTrace("%s| Set MIP Home IP", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::setMipPrimaryHa(const Json::Value& jArgs) { + printTrace("%s| Set MIP Primary HA", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::setMipSecondaryHa(const Json::Value& jArgs) { + printTrace("%s| Set MIP Secondary HA", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::setMipMnAaaSpi(const Json::Value& jArgs) { + printTrace("%s| Set MIP MN-AAA SPI", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::setMipMnHaSpi(const Json::Value& jArgs) { + printTrace("%s| Set MIP MN-HA SPI", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::setMipRevTun(const Json::Value& jArgs) { + printTrace("%s| Set MIP Rev Tun", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::setMipMnAaaSs(const Json::Value& jArgs) { + printTrace("%s| Set MIP MN-AAA SS", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::setMipMnHaSs(const Json::Value& jArgs) { + printTrace("%s| Set MIP MN-HA SS", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::updateDc(const Json::Value& jArgs, UpdateCb& stepCb) { + printTrace("%s| Update Device Configuration", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::updatePrl(const Json::Value& jArgs, UpdateCb& stepCb) { + printTrace("%s| Update Preferred Roaming List", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) { + printTrace("%s| Update Firmware Update Management Object", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::resetHfa(const Json::Value& jArgs, UpdateCb& stepCb) { + printTrace("%s| HFA Reset", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::activate(const Json::Value& jArgs, UpdateCb& stepCb) { + printTrace("%s| Activation", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::setActiveFirmware(const Json::Value& jArgs) { + printTrace("%s| Set Active Firmware Image Number: not applicable", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::getActiveFirmware(std::string& sFwId) { + printTrace("%s| Get Active Firmware Image Number: not applicable", m_sName.c_str()); + sFwId = VALUE_NOT_SUPPORTED; + + return NOT_APPLICABLE; +} + +TelitRadio::CODE TelitRadio::sendBasicCommand(const std::string& sCmd, int32_t iTimeoutMillis, const char& ESC) { + std::string response = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, iTimeoutMillis, ESC); + if (response.size() == 0) { + return NO_RESPONSE; + } else if (response.find(RSP_OK) != std::string::npos) { + return SUCCESS; + } else if (response.find(RSP_ERROR) != std::string::npos) { + return ERROR; + } else { + return FAILURE; + } +} + +std::string TelitRadio::sendCommand(const std::string& sCmd, const std::vector& vBail, int32_t timeoutMillis, const char& ESC) { + return sendCommand(m_apIo, sCmd, vBail, timeoutMillis, ESC); +} + +std::string TelitRadio::sendCommand(MTS::AutoPtr& apIo, const std::string& sCmd, + const std::vector& vBail, int32_t timeoutMillis, const char& ESC) { + IsNeedMoreData isNeedMoreData = [&vBail](const std::string& iterationData, const std::string& allData)->bool { + for(size_t i = 0; i < vBail.size(); i++) { + const std::string& sBail = vBail[i]; + if(sBail.size() > 0) { + if(allData.find(sBail) != std::string::npos) { + //Return when bail string is found + printTrace("RADIO| Found bail string [%s]", sBail.c_str()); + return false; + } + } + } + return true; + }; + + return sendCommand(apIo, sCmd, isNeedMoreData, timeoutMillis, ESC); +} + +std::string TelitRadio::sendCommand(const std::string& sCmd, MTS::IO::TelitRadio::IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis, const char& ESC) { + return sendCommand(m_apIo, sCmd, isNeedMoreData, timeoutMillis, ESC); +} + +std::string TelitRadio::sendCommand(MTS::AutoPtr& apIo, const std::string& sCmd, + IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis, const char& ESC) { + if(MTS::Logger::getPrintLevel() >= MTS::Logger::PrintLevel::TRACE_LEVEL) { + printTrace("RADIO| Sending command [%s]", sCmd.c_str()); + } + if(apIo.isNull()) { + printError("RADIO| IO is not set in sendCommand"); + return ""; + } + + int32_t iResult; + if(ESC == 0x00) { + iResult = apIo->write(sCmd.data(), sCmd.size()); + } else { + std::string sNewCmd(sCmd); + sNewCmd.push_back(ESC); + iResult = apIo->write(sNewCmd.data(), sNewCmd.size()); + } + + if(iResult == -1) { + printError("RADIO| Failed to send command to radio"); + return ""; + } + + bool done = false; + const uint32_t capacity = 1024; + char buffer[capacity]; + std::string sResult; + Timer timer; + timer.start(); + do { + int32_t iterationTimeout = 100; + int bytesRead = apIo->read((char*)buffer, capacity, iterationTimeout); + if(bytesRead == -1) { + printError("RADIO| Failed to read from radio"); + break; + } + + std::string sIteration((char*)buffer, bytesRead); + sResult += sIteration; + + if(isNeedMoreData && !isNeedMoreData(sIteration, sResult)) { + printTrace("RADIO| No more data needed"); + return sResult; + } + if(timeoutMillis >= 0) { + done = (timer.getMillis() >= (uint64_t)timeoutMillis); + } else { + //Do not stop looping until bail string is found + } + } while(!done); + + //Timed out + return sResult; +} + +TelitRadio::CODE TelitRadio::test(MTS::AutoPtr& apIo, uint32_t timeoutSeconds) { + printTrace("RADIO| Basic Test"); + uint32_t count = 0; + std::string sCmd("AT"); + do { + std::string sResult = sendCommand(apIo, sCmd); + if (sResult.find(RSP_OK) == std::string::npos) { + printTrace("RADIO| Waiting for basic radio communication [%s] ...", sResult.c_str()); + } else { + break; + } + count++; + } while (count < timeoutSeconds); + + if(count == timeoutSeconds) { + printWarning("RADIO| Basic radio communication FAILED"); + return NO_RESPONSE; + } + return SUCCESS; +} + +std::string TelitRadio::extractModelFromResult(const std::string& sResult) { + std::string sModel(TelitRadio::VALUE_NOT_SUPPORTED); + + if(sResult.find("HE910-D") != std::string::npos) { + sModel = "HE910-D"; + } else if(sResult.find("HE910-EUD") != std::string::npos) { + sModel = "HE910-EUD"; + } else if(sResult.find("LE910-JN1") != std::string::npos) { + sModel = "LE910-JN1"; + } else if(sResult.find("LE866A1-JS") != std::string::npos) { + sModel = "LE866A1-JS"; + } else if(sResult.find("LE910-NAG") != std::string::npos) { + sModel = "LE910-NAG"; + } else if(sResult.find("LE910C4-NF") != std::string::npos) { + sModel = "LE910C4-NF"; + } else if(sResult.find("LE910-NA1") != std::string::npos) { + sModel = "LE910-NA1"; + } else if(sResult.find("ME910C1-NA") != std::string::npos) { + sModel = "ME910C1-NA"; + } else if(sResult.find("ME910C1-NV") != std::string::npos) { + sModel = "ME910C1-NV"; + } else if(sResult.find("ME910C1-WW") != std::string::npos) { + sModel = "ME910C1-WW"; + } else if(sResult.find("LE910-SVG") != std::string::npos) { + sModel = "LE910-SVG"; + } else if(sResult.find("LE910-EUG") != std::string::npos) { + sModel = "LE910-EUG"; + } else if(sResult.find("LE910C4-EU") != std::string::npos) { + sModel = "LE910C4-EU"; + } else if(sResult.find("LE910-EU1") != std::string::npos) { + sModel = "LE910-EU1"; + } else if(sResult.find("LE910C1-NS") != std::string::npos) { + sModel = "LE910C1-NS"; + } else if(sResult.find("LE910C1-AP") != std::string::npos) { + sModel = "LE910C1-AP"; + } else if(sResult.find("GE910") != std::string::npos) { + sModel = "GE910"; + } else if(sResult.find("DE910-DUAL") != std::string::npos) { + sModel = "DE910-DUAL"; + } else if(sResult.find("CE910") != std::string::npos) { + sModel = "CE910"; + } + return sModel; +} + +std::string TelitRadio::getCodeAsString(CODE eCode) { + switch(eCode) { + case SUCCESS: + return "SUCCESS"; + case ERROR: + return "ERROR"; + case FAILURE: + return "FAILURE"; + case NO_RESPONSE: + return "NO RESPONSE"; + default: + return "UNKNOWN"; + } +} + +bool TelitRadio::splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType) { + + std::vector vParts = MTS::Text::split(sLine, ":", 2); + + if(vParts.size() == 2 && vParts[0] == sKey) { + if(eType == Json::ValueType::stringValue) { + jParent[sJsonKey] = MTS::Text::trim(vParts[1]); + } else if (eType == Json::ValueType::intValue || eType == Json::ValueType::uintValue) { + //TODO: + printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); + return false; + } else if(eType == Json::ValueType::realValue) { + //TODO: + printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); + return false; + } else if(eType == Json::ValueType::booleanValue) { + //TODO: + printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); + return false; + } else { + printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); + return false; + } + } else { + printWarning("%s| Unable to parse %s from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); + return false; + } + + return true; +} + +bool TelitRadio::getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier) { + // Telit Radios + // H.ab.zyx => 3 Main Components + // "H" = Hardware -> 15 = DE910 family, 18 = CE910 family, 12 = HE910 family + // "a" = Hardware version + // "b" = Software Major Version + // "z" = is the product type, i.e. DUAL or SC + // "y" = is the carrier variant + // "x" = is the firmware version + // Telit will do their best to keep the carrier variant as "0" for Sprint, "1" for Aeris, "2" for Verizon, and "3" for U.S. Cellular. + + const uint32_t CARRIER_INDEX = 1; //y in [zyx] + + bool bResult = false; + std::vector vParts = MTS::Text::split(sFirmware, '.'); + + if(vParts.size() == 3) { + //CDMA firmware version notation + if(vParts[0] == "15" || vParts[0] == "18") { + //DE910 or CE910 -> Good good + std::string sID = vParts[2]; + if(sID.size() == 3) { + char cId = sID[CARRIER_INDEX]; + + //Good good + if(cId == '0') { + sCarrier = VALUE_CARRIER_SPRINT; + bResult = true; + } else + if(cId == '1') { + sCarrier = VALUE_CARRIER_AERIS; + bResult = true; + } else + if(cId == '2') { + sCarrier = VALUE_CARRIER_VERIZON; + bResult = true; + } else + if(cId == '3') { + sCarrier = VALUE_CARRIER_USCELLULAR; + bResult = true; + } + } + } + } + + return bResult; +} + +bool TelitRadio::getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware) { + // Telit Radios + // H.ab.zyx => 3 Main Components + // "H" = Hardware -> 15 = DE910 family, 18 = CE910 family, 12 = HE910 family + // "a" = Hardware version + // "b" = Software Major Version + // "z" = is the product type, i.e. DUAL or SC + // "y" = is the carrier variant + // "x" = is the firmware version + // Telit will do their best to keep the carrier variant as "0" for Sprint, "1" for Aeris, and "2" for Verizon. + + const uint32_t HARDWARE_INDEX = 0; //a in [ab] + + bool bResult = false; + std::vector vParts = MTS::Text::split(sFirmware, '.'); + + if(vParts.size() == 3) { + //GSM Hardware Version + if(!(vParts[0] == "15" || vParts[0] == "18")) { + //Not DE910 or CE910 -> Good good + std::string sVersion = vParts[1]; + if(sVersion.size() == 2) { + sHardware = "1."; + sHardware += sVersion[HARDWARE_INDEX]; + bResult = true; + } + } + } + + return bResult; + +} + +const char *TelitRadio::RadioBandMap::getLTEBand(const int32_t channel) +{ + for (unsigned int ii = 0; ii < NUM_LTE_BANDS; ii++) + { + if (EULTRAband[ii].low <= channel && EULTRAband[ii].high >= channel) + { + return EULTRAband[ii].name; + } + } + return VALUE_UNKNOWN.c_str(); +} + +const char *TelitRadio::RadioBandMap::getCDMABand(const int channel) +{ + for (unsigned int ii = 0; ii < NUM_WCDMA_BANDS; ii++) + { + if (WCDMAband[ii].low <= channel && WCDMAband[ii].high >= channel) + { + return WCDMAband[ii].name; + } + } + return VALUE_UNKNOWN.c_str(); +} + +const char *TelitRadio::RadioBandMap::getGSMBand(const int channel) +{ + for (unsigned int ii = 0; ii < NUM_GSM_BANDS; ii++) + { + if (GSMband[ii].low <= channel && GSMband[ii].high >= channel) + { + return GSMband[ii].name; + } + } + return VALUE_UNKNOWN.c_str(); +} + +const char *TelitRadio::RadioBandMap::getRadioBandName() +{ + const char *band = TelitRadio::VALUE_UNKNOWN.c_str(); + + if (m_sRadioType == TelitRadio::VALUE_TYPE_LTE) + { + band = getLTEBand(m_iChannel); + } + else if (m_sRadioType == TelitRadio::VALUE_TYPE_CDMA) + { + band = getCDMABand(m_iChannel); + } + else if (m_sRadioType == TelitRadio::VALUE_TYPE_GSM) + { + band = getGSMBand(m_iChannel); + } + + return band; +} + +const char *TelitRadio::RadioBandMap::getRadioBandName(const std::string &channel, const std::string &radioType) +{ + const char *band = TelitRadio::VALUE_UNKNOWN.c_str(); + int32_t chan = strtol(channel.c_str(), NULL, 10); + if (radioType == TelitRadio::VALUE_TYPE_LTE) + { + band = getLTEBand(chan); + } + else if (radioType == TelitRadio::VALUE_TYPE_CDMA) + { + band = getCDMABand(chan); + } + else if (radioType == TelitRadio::VALUE_TYPE_GSM) + { + band = getGSMBand(chan); + } + + return band; +} -- cgit v1.2.3 From dfdac48418b57fd5e3393d5a53dd3d9fbd16822e Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Thu, 6 Jun 2019 16:16:16 +0300 Subject: [MTS-MTQ] refactoring: Makefile --- Makefile | 140 +++++++++++++++++++++++++-------------------------------------- 1 file changed, 55 insertions(+), 85 deletions(-) diff --git a/Makefile b/Makefile index 677c34d..bfe5b12 100644 --- a/Makefile +++ b/Makefile @@ -1,104 +1,74 @@ include version -includedir ?= /usr/include +APPNAME = libmts-io libdir ?= /usr/lib OBJS += \ -MTS_IO_CdmaRadio.o \ -MTS_IO_CE910Radio.o \ -MTS_IO_CellularRadio.o \ -MTS_IO_CellularRadioFactory.o \ -MTS_IO_Connection.o \ -MTS_IO_DE910Radio.o \ -MTS_IO_GE910Radio.o \ -MTS_IO_HE910Radio.o \ -MTS_IO_HE910DRadio.o \ -MTS_IO_HE910EUDRadio.o \ -MTS_IO_LE910JN1Radio.o \ -MTS_IO_LE866Radio.o \ -MTS_IO_LE866A1JSRadio.o \ -MTS_IO_LE910Radio.o \ -MTS_IO_LE910NAGRadio.o \ -MTS_IO_LE910C4NFRadio.o \ -MTS_IO_LE910NA1Radio.o \ -MTS_IO_LE910SVGRadio.o \ -MTS_IO_LE910EUGRadio.o \ -MTS_IO_LE910C4EURadio.o \ -MTS_IO_LE910EU1Radio.o \ -MTS_IO_LE910C1NSRadio.o \ -MTS_IO_LE910C1APRadio.o \ -MTS_IO_ME910C1NARadio.o \ -MTS_IO_ME910C1NVRadio.o \ -MTS_IO_ME910C1WWRadio.o \ -MTS_IO_ME910Radio.o \ -MTS_IO_LockFile.o \ -MTS_IO_MccMncTable.o \ -MTS_IO_SerialConnection.o + src/MTS_IO_TelitRadio.o \ + src/MTS_IO_EG95Radio.o \ + src/MTS_IO_QuectelRadio.o \ + src/MTS_IO_CdmaRadio.o \ + src/MTS_IO_CE910Radio.o \ + src/MTS_IO_CellularRadio.o \ + src/MTS_IO_CellularRadioFactory.o \ + src/MTS_IO_Connection.o \ + src/MTS_IO_DE910Radio.o \ + src/MTS_IO_GE910Radio.o \ + src/MTS_IO_HE910Radio.o \ + src/MTS_IO_HE910DRadio.o \ + src/MTS_IO_HE910EUDRadio.o \ + src/MTS_IO_LE910JN1Radio.o \ + src/MTS_IO_LE866Radio.o \ + src/MTS_IO_LE866A1JSRadio.o \ + src/MTS_IO_LE910Radio.o \ + src/MTS_IO_LE910NAGRadio.o \ + src/MTS_IO_LE910C4NFRadio.o \ + src/MTS_IO_LE910NA1Radio.o \ + src/MTS_IO_LE910SVGRadio.o \ + src/MTS_IO_LE910EUGRadio.o \ + src/MTS_IO_LE910C4EURadio.o \ + src/MTS_IO_LE910EU1Radio.o \ + src/MTS_IO_LE910C1NSRadio.o \ + src/MTS_IO_LE910C1APRadio.o \ + src/MTS_IO_ME910C1NARadio.o \ + src/MTS_IO_ME910C1NVRadio.o \ + src/MTS_IO_ME910C1WWRadio.o \ + src/MTS_IO_ME910Radio.o \ + src/MTS_IO_LockFile.o \ + src/MTS_IO_MccMncTable.o \ + src/MTS_IO_SerialConnection.o -CPP_DEPS += \ -MTS_IO_CdmaRadio.d \ -MTS_IO_CE910Radio.d \ -MTS_IO_CellularRadio.d \ -MTS_IO_CellularRadioFactory.d \ -MTS_IO_Connection.d \ -MTS_IO_DE910Radio.d \ -MTS_IO_GE910Radio.d \ -MTS_IO_HE910Radio.d \ -MTS_IO_HE910DRadio.d \ -MTS_IO_HE910EUDRadio.d \ -MTS_IO_LE910JN1Radio.d \ -MTS_IO_LE866Radio.d \ -MTS_IO_LE866A1JSRadio.d \ -MTS_IO_LE910Radio.d \ -MTS_IO_LE910NAGRadio.d \ -MTS_IO_LE910C4NFRadio.d \ -MTS_IO_LE910NA1Radio.d \ -MTS_IO_LE910SVGRadio.d \ -MTS_IO_LE910EUGRadio.d \ -MTS_IO_LE910C4EURadio.d \ -MTS_IO_LE910EU1Radio.d \ -MTS_IO_LE910C1NSRadio.d \ -MTS_IO_LE910C1APRadio.d \ -MTS_IO_ME910C1NARadio.d \ -MTS_IO_ME910C1NVRadio.d \ -MTS_IO_ME910C1WWRadio.d \ -MTS_IO_ME910Radio.d \ -MTS_IO_LockFile.d \ -MTS_IO_MccMncTable.d \ -MTS_IO_SerialConnection.d +CC := $(CXX) +#-Werror +CXXFLAGS += -Wall -std=c++0x -fmessage-length=0 -fPIC +CPPFLAGS += -I=/usr/include/jsoncpp -Iinclude +LDFLAGS += -s -shared -Wl,-soname,$(APPNAME).so.0 -all: libmts-io.a libmts-io.so.0 +.PHONY: all clean install -libmts-io.a: $(OBJS) - @echo 'Building target: $@' - $(AR) -r libmts-io.a $(OBJS) - @echo 'Finished building target: $@' - @echo ' ' +all: $(APPNAME).a $(APPNAME).so.$(VERSION) -libmts-io.so.0: $(OBJS) - @echo 'Building target: $@' - $(CXX) $(LDFLAGS) -shared -Wl,-soname,$@ -o libmts-io.so.$(VERSION) $(OBJS) - @echo 'Finished building target: $@' - @echo ' ' -%.o: src/%.cpp - @echo 'Building file: $<' - $(CXX) $(CFLAGS) -I=$(includedir)/jsoncpp -Iinclude -Wall -Werror -c -fPIC -fmessage-length=0 -std=c++0x -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" - @echo 'Finished building: $<' - @echo ' ' +$(APPNAME).a: $(OBJS) + $(AR) -r $@ $? + +$(APPNAME).so.$(VERSION): $(OBJS) + $(CC) $(LDFLAGS) -o $@ $? $(LDLIBS) + +# Handle header dependencies +DEPS = $(OBJS:.o=.d) +CPPFLAGS += -MMD +-include $(DEPS) install: mkdir -p $(DESTDIR)$(libdir) mkdir -p $(DESTDIR)$(includedir)/mts - install -m 0644 libmts-io.a libmts-io.so.$(VERSION) $(DESTDIR)$(libdir)/ - ln -sf libmts-io.so.$(VERSION) $(DESTDIR)$(libdir)/libmts-io.so.0 - ln -sf libmts-io.so.0 $(DESTDIR)$(libdir)/libmts-io.so + install -m 0644 $(APPNAME).a $(APPNAME).so.$(VERSION) $(DESTDIR)$(libdir)/ + ln -sf $(APPNAME).so.$(VERSION) $(DESTDIR)$(libdir)/$(APPNAME).so.0 + ln -sf $(APPNAME).so.0 $(DESTDIR)$(libdir)/$(APPNAME).so install -m 0644 include/mts/* $(DESTDIR)$(includedir)/mts/ clean: - -$(RM) $(OBJS) $(CPP_DEPS) libmts-io.a libmts-io.so* - -@echo ' ' + $(RM) $(OBJS) $(APPNAME).a $(APPNAME).so.$(VERSION) $(DEPS) -.PHONY: all clean dependents install -.SECONDARY: -- cgit v1.2.3 From 417049f51180b3b4be84fbc0d86a3c690972fb3b Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Thu, 6 Jun 2019 18:06:43 +0300 Subject: [MTS-MTQ] refactoring: moved common consts and static methods to ICellularRadio --- Makefile | 1 + include/mts/MTS_IO_ICellularRadio.h | 257 ++++++++++++++++----------------- include/mts/MTS_IO_TelitRadio.h | 114 --------------- src/MTS_IO_ICellularRadio.cpp | 280 ++++++++++++++++++++++++++++++++++++ src/MTS_IO_TelitRadio.cpp | 274 ----------------------------------- 5 files changed, 401 insertions(+), 525 deletions(-) create mode 100644 src/MTS_IO_ICellularRadio.cpp diff --git a/Makefile b/Makefile index bfe5b12..6c09bff 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ OBJS += \ src/MTS_IO_CdmaRadio.o \ src/MTS_IO_CE910Radio.o \ src/MTS_IO_CellularRadio.o \ + src/MTS_IO_ICellularRadio.o \ src/MTS_IO_CellularRadioFactory.o \ src/MTS_IO_Connection.o \ src/MTS_IO_DE910Radio.o \ diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h index da86946..257ed00 100644 --- a/include/mts/MTS_IO_ICellularRadio.h +++ b/include/mts/MTS_IO_ICellularRadio.h @@ -12,146 +12,12 @@ namespace MTS { namespace IO { - class ICellularRadio; - namespace { - - static const std::string DEFAULT_RADIO_PORT; - static const std::string DEFAULT_RADIO_DIR; - - static const std::string VALUE_UNKNOWN; - static const std::string VALUE_UNAVAILABLE; - static const std::string VALUE_NOT_SUPPORTED; - - //Special Payload Characters - static const char ETX = 0; //Ends socket connection - static const char DLE = 0; //Escapes ETX and DLE within Payload - static const char CR = 0; - static const char NL = 0; - static const char CTRL_Z = 0; - - static const std::string RSP_OK; - static const std::string RSP_ERROR; - - static const std::string VALUE_NOT_REGISTERED; - static const std::string VALUE_REGISTERED; - static const std::string VALUE_SEARCHING; - static const std::string VALUE_DENIED; - static const std::string VALUE_ROAMING; - - //Static Data - static const std::string KEY_TYPE; //!< GSM or CDMA - static const std::string KEY_CODE; //!< Product Code : H5, H6, C2, EV3, G3 - static const std::string KEY_MODEL; //!< Model : HE910, CE910, DE910, GE910 - static const std::string KEY_MANUFACTURER; //!< Manufacturer: Telit - static const std::string KEY_HARDWARE; //!< Radio Hardware Version - static const std::string KEY_FIRMWARE; //!< Radio Firmware Version - static const std::string KEY_FIRMWARE_BUILD;//!< Radio Firmware Build - static const std::string KEY_IMEI; //!< International Mobile Station Equipment Identity - static const std::string KEY_MEID; //!< Mobile Equipment Identifier - static const std::string KEY_IMSI; //!< International Mobile Subscriber Identity - static const std::string KEY_MSID; //!< Mobil Station ID (MSID) aka MIN aka MSIN aka Last few digits of IMSI - static const std::string KEY_MDN; //!< Mobile Directory Number : Actual phone number dialed to reach radio - static const std::string KEY_CARRIER; //!< Cellular Service Provider (Home Network) - static const std::string KEY_ICCID; //!< Integrated Circuit Card Identifier - static const std::string KEY_MSL; //!< Master Subsidy Lock - - - //Network Status Data - static const std::string KEY_ROAMING; //!< Indicates whether or not using Home Network - static const std::string KEY_DATETIME; //!< Date and Time from tower - static const std::string KEY_SERVICE; //!< Service Connection Type [GPRS, EGPRS, WCDMA, HSDPA, 1xRTT, EVDO] - static const std::string KEY_NETWORK; //!< Cellular Service Provider - static const std::string KEY_NETWORK_REG; //!< Network Registration - static const std::string KEY_CID; //!< Cellular ID (Tower) in HEX - static const std::string KEY_LAC; //!< Location Area Code in HEX - static const std::string KEY_RAC; //!< Routing Area Code in HEX - static const std::string KEY_RSSI; //!< Received Signal Strength Indication - static const std::string KEY_RSSIDBM; //!< Received Signal Strength Indication in dBm - static const std::string KEY_MCC; //!< Mobile Country Code - static const std::string KEY_MNC; //!< Mobile Network (Operator) Code - static const std::string KEY_CHANNEL; //!< ARFCN or UARFCN Assigned Radio Channel - static const std::string KEY_TXPWR; //!< Transmit Power - static const std::string KEY_PSC; //!< Active Primary Synchronization Code (PSC) - static const std::string KEY_ECIO; //!< Active Ec/Io (chip energy per total wideband power in dBm) - static const std::string KEY_RSCP; //!< Active RSCP (Received Signal Code Power in dBm) - static const std::string KEY_DRX; //!< Discontinuous reception cycle length (ms) - static const std::string KEY_MM; //!< Mobility Management State - static const std::string KEY_RR; //!< Radio Resource State - static const std::string KEY_NOM; //!< Network Operator Mode - static const std::string KEY_ABND; //!< Active Band - static const std::string KEY_BLER; //!< Block Error Rate (percentage) - static const std::string KEY_SD; //!< Service Domain - static const std::string KEY_DEBUG; //!< Debug Information - - static const std::string KEY_MIP; //!< Mobile IP Information - static const std::string KEY_MIP_ID; //!< MIP Profile ID - static const std::string KEY_MIP_ENABLED; //!< MIP Profile Enabled/Disabled - static const std::string KEY_MIP_NAI; //!< Network Access Identifier - static const std::string KEY_MIP_HOMEADDRESS; //!< Home Address - static const std::string KEY_MIP_PRIMARYHA; //!< Primary Home Agent - static const std::string KEY_MIP_SECONDARYHA; //!< Secondary Home Agent - static const std::string KEY_MIP_MNAAASPI; //!< Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index - static const std::string KEY_MIP_MNHASPI; //!< Mobile Node Home Agent Security Server Parameter Index - static const std::string KEY_MIP_REVTUN; //!< Reverse Tunneling Enabled - static const std::string KEY_MIP_MNAAASS; //!< Mobile Node Authentication, Authorization, and Accounting Server Shared Secret - static const std::string KEY_MIP_MNHASS; //!< Mobile Node Home Agent Shared Secret - - - //Values - Type - static const std::string VALUE_TYPE_LTE; - static const std::string VALUE_TYPE_GSM; - static const std::string VALUE_TYPE_CDMA; - - //Values - Carrier - static const std::string VALUE_CARRIER_VERIZON; - static const std::string VALUE_CARRIER_AERIS; - static const std::string VALUE_CARRIER_SPRINT; - static const std::string VALUE_CARRIER_USCELLULAR; - static const std::string VALUE_CARRIER_ATT; - static const std::string VALUE_CARRIER_TMOBILE; - - static const std::string VALUE_SD_NO_SERVICE; - static const std::string VALUE_SD_CS_ONLY; - static const std::string VALUE_SD_PS_ONLY; - static const std::string VALUE_SD_CSPS; - - static const std::string VALUE_ABND_GSM_850; - static const std::string VALUE_ABND_GSM_900; - static const std::string VALUE_ABND_DCS_1800; - static const std::string VALUE_ABND_PCS_1900; - - static const std::vector DEFAULT_BAIL_STRINGS; - - typedef std::function IsNeedMoreData; - typedef std::function UpdateCb; - - /* - CODE convertModelToType(const std::string& sModel, std::string& sType); - CODE convertModelToMtsShortCode(const std::string& sModel, std::string& sCode, ICellularRadio *radioObj = NULL); - CODE convertServiceDomainToString(SERVICEDOMAIN eSd, std::string& sSd); - CODE convertActiveBandToString(ACTIVEBAND eBand, std::string& sBand); - - std::string sendCommand(MTS::AutoPtr& apIo, - const std::string& sCmd, - IsNeedMoreData& isNeedMoreData, - int32_t timeoutMillis = 100, - const char& ESC = CR); - - std::string sendCommand(MTS::AutoPtr& apIo, - const std::string& sCmd, - const std::vector& vBail = DEFAULT_BAIL_STRINGS, - int32_t timeoutMillis = 100, - const char& ESC = CR); - CODE test(MTS::AutoPtr& apIo, uint32_t timeoutSeconds = 30); - - std::string extractModelFromResult(const std::string& sResult); - std::string getCodeAsString(CODE code); - */ - - } class ICellularRadio { public: + typedef std::function IsNeedMoreData; + typedef std::function UpdateCb; + //Registration Values enum REGISTRATION : uint8_t { NOT_REGISTERED = 0, @@ -191,6 +57,121 @@ namespace MTS { BLOCKED, NOT_INSERTED }; + + // TODO: convert functions + static CODE convertModelToType(const std::string& sModel, std::string& sType); + static CODE convertModelToMtsShortCode(const std::string& sModel, std::string& sCode, ICellularRadio *radioObj = NULL); + static CODE convertServiceDomainToString(SERVICEDOMAIN eSd, std::string& sSd); + static CODE convertActiveBandToString(ACTIVEBAND eBand, std::string& sBand); + // XXX + + static const std::string DEFAULT_RADIO_PORT; + static const std::string DEFAULT_RADIO_DIR; + + static const std::string VALUE_UNKNOWN; + static const std::string VALUE_UNAVAILABLE; + static const std::string VALUE_NOT_SUPPORTED; + + //Special Payload Characters + static const char ETX; //Ends socket connection + static const char DLE; //Escapes ETX and DLE within Payload + static const char CR; + static const char NL; + static const char CTRL_Z; + + static const std::string RSP_OK; + static const std::string RSP_ERROR; + + static const std::string VALUE_NOT_REGISTERED; + static const std::string VALUE_REGISTERED; + static const std::string VALUE_SEARCHING; + static const std::string VALUE_DENIED; + static const std::string VALUE_ROAMING; + + //Static Data + static const std::string KEY_TYPE; //!< GSM or CDMA + static const std::string KEY_CODE; //!< Product Code : H5, H6, C2, EV3, G3 + static const std::string KEY_MODEL; //!< Model : HE910, CE910, DE910, GE910 + static const std::string KEY_MANUFACTURER; //!< Manufacturer: Telit + static const std::string KEY_HARDWARE; //!< Radio Hardware Version + static const std::string KEY_FIRMWARE; //!< Radio Firmware Version + static const std::string KEY_FIRMWARE_BUILD;//!< Radio Firmware Build + static const std::string KEY_IMEI; //!< International Mobile Station Equipment Identity + static const std::string KEY_MEID; //!< Mobile Equipment Identifier + static const std::string KEY_IMSI; //!< International Mobile Subscriber Identity + static const std::string KEY_MSID; //!< Mobil Station ID (MSID) aka MIN aka MSIN aka Last few digits of IMSI + static const std::string KEY_MDN; //!< Mobile Directory Number : Actual phone number dialed to reach radio + static const std::string KEY_CARRIER; //!< Cellular Service Provider (Home Network) + static const std::string KEY_ICCID; //!< Integrated Circuit Card Identifier + static const std::string KEY_MSL; //!< Master Subsidy Lock + + + //Network Status Data + static const std::string KEY_ROAMING; //!< Indicates whether or not using Home Network + static const std::string KEY_DATETIME; //!< Date and Time from tower + static const std::string KEY_SERVICE; //!< Service Connection Type [GPRS, EGPRS, WCDMA, HSDPA, 1xRTT, EVDO] + static const std::string KEY_NETWORK; //!< Cellular Service Provider + static const std::string KEY_NETWORK_REG; //!< Network Registration + static const std::string KEY_CID; //!< Cellular ID (Tower) in HEX + static const std::string KEY_LAC; //!< Location Area Code in HEX + static const std::string KEY_RAC; //!< Routing Area Code in HEX + static const std::string KEY_RSSI; //!< Received Signal Strength Indication + static const std::string KEY_RSSIDBM; //!< Received Signal Strength Indication in dBm + static const std::string KEY_MCC; //!< Mobile Country Code + static const std::string KEY_MNC; //!< Mobile Network (Operator) Code + static const std::string KEY_CHANNEL; //!< ARFCN or UARFCN Assigned Radio Channel + static const std::string KEY_TXPWR; //!< Transmit Power + static const std::string KEY_PSC; //!< Active Primary Synchronization Code (PSC) + static const std::string KEY_ECIO; //!< Active Ec/Io (chip energy per total wideband power in dBm) + static const std::string KEY_RSCP; //!< Active RSCP (Received Signal Code Power in dBm) + static const std::string KEY_DRX; //!< Discontinuous reception cycle length (ms) + static const std::string KEY_MM; //!< Mobility Management State + static const std::string KEY_RR; //!< Radio Resource State + static const std::string KEY_NOM; //!< Network Operator Mode + static const std::string KEY_ABND; //!< Active Band + static const std::string KEY_BLER; //!< Block Error Rate (percentage) + static const std::string KEY_SD; //!< Service Domain + static const std::string KEY_DEBUG; //!< Debug Information + + static const std::string KEY_MIP; //!< Mobile IP Information + static const std::string KEY_MIP_ID; //!< MIP Profile ID + static const std::string KEY_MIP_ENABLED; //!< MIP Profile Enabled/Disabled + static const std::string KEY_MIP_NAI; //!< Network Access Identifier + static const std::string KEY_MIP_HOMEADDRESS; //!< Home Address + static const std::string KEY_MIP_PRIMARYHA; //!< Primary Home Agent + static const std::string KEY_MIP_SECONDARYHA; //!< Secondary Home Agent + static const std::string KEY_MIP_MNAAASPI; //!< Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index + static const std::string KEY_MIP_MNHASPI; //!< Mobile Node Home Agent Security Server Parameter Index + static const std::string KEY_MIP_REVTUN; //!< Reverse Tunneling Enabled + static const std::string KEY_MIP_MNAAASS; //!< Mobile Node Authentication, Authorization, and Accounting Server Shared Secret + static const std::string KEY_MIP_MNHASS; //!< Mobile Node Home Agent Shared Secret + + + //Values - Type + static const std::string VALUE_TYPE_LTE; + static const std::string VALUE_TYPE_GSM; + static const std::string VALUE_TYPE_CDMA; + + //Values - Carrier + static const std::string VALUE_CARRIER_VERIZON; + static const std::string VALUE_CARRIER_AERIS; + static const std::string VALUE_CARRIER_SPRINT; + static const std::string VALUE_CARRIER_USCELLULAR; + static const std::string VALUE_CARRIER_ATT; + static const std::string VALUE_CARRIER_TMOBILE; + + static const std::string VALUE_SD_NO_SERVICE; + static const std::string VALUE_SD_CS_ONLY; + static const std::string VALUE_SD_PS_ONLY; + static const std::string VALUE_SD_CSPS; + + static const std::string VALUE_ABND_GSM_850; + static const std::string VALUE_ABND_GSM_900; + static const std::string VALUE_ABND_DCS_1800; + static const std::string VALUE_ABND_PCS_1900; + + static const std::vector DEFAULT_BAIL_STRINGS; + virtual ~ICellularRadio() = 0; virtual bool initialize(uint32_t iTimeoutMillis = 5000) = 0; @@ -380,6 +361,7 @@ namespace MTS { virtual CODE getStaticInformation(Json::Value& jData) = 0; virtual CODE getNetworkStatus(Json::Value& jData) = 0; + /* virtual CODE sendBasicCommand(const std::string& sCmd, int32_t timeoutMillis = 100, const char& ESC = CR) = 0; virtual std::string sendCommand(const std::string& sCmd, @@ -391,6 +373,7 @@ namespace MTS { IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis = 100, const char& ESC = CR) = 0; + */ }; } diff --git a/include/mts/MTS_IO_TelitRadio.h b/include/mts/MTS_IO_TelitRadio.h index f8fce6a..0fdad6b 100644 --- a/include/mts/MTS_IO_TelitRadio.h +++ b/include/mts/MTS_IO_TelitRadio.h @@ -94,116 +94,6 @@ namespace MTS { class TelitRadio : public CellularRadio { public: - static const std::string DEFAULT_RADIO_PORT; - static const std::string DEFAULT_RADIO_DIR; - - static const std::string VALUE_UNKNOWN; - static const std::string VALUE_UNAVAILABLE; - static const std::string VALUE_NOT_SUPPORTED; - - //Special Payload Characters - static const char ETX; //Ends socket connection - static const char DLE; //Escapes ETX and DLE within Payload - static const char CR; - static const char NL; - static const char CTRL_Z; - - static const std::string RSP_OK; - static const std::string RSP_ERROR; - - static const std::string VALUE_NOT_REGISTERED; - static const std::string VALUE_REGISTERED; - static const std::string VALUE_SEARCHING; - static const std::string VALUE_DENIED; - static const std::string VALUE_ROAMING; - - //Static Data - static const std::string KEY_TYPE; //!< GSM or CDMA - static const std::string KEY_CODE; //!< Product Code : H5, H6, C2, EV3, G3 - static const std::string KEY_MODEL; //!< Model : HE910, CE910, DE910, GE910 - static const std::string KEY_MANUFACTURER; //!< Manufacturer: Telit - static const std::string KEY_HARDWARE; //!< Radio Hardware Version - static const std::string KEY_FIRMWARE; //!< Radio Firmware Version - static const std::string KEY_FIRMWARE_BUILD;//!< Radio Firmware Build - static const std::string KEY_IMEI; //!< International Mobile Station Equipment Identity - static const std::string KEY_MEID; //!< Mobile Equipment Identifier - static const std::string KEY_IMSI; //!< International Mobile Subscriber Identity - static const std::string KEY_MSID; //!< Mobil Station ID (MSID) aka MIN aka MSIN aka Last few digits of IMSI - static const std::string KEY_MDN; //!< Mobile Directory Number : Actual phone number dialed to reach radio - static const std::string KEY_CARRIER; //!< Cellular Service Provider (Home Network) - static const std::string KEY_ICCID; //!< Integrated Circuit Card Identifier - static const std::string KEY_MSL; //!< Master Subsidy Lock - - - //Network Status Data - static const std::string KEY_ROAMING; //!< Indicates whether or not using Home Network - static const std::string KEY_DATETIME; //!< Date and Time from tower - static const std::string KEY_SERVICE; //!< Service Connection Type [GPRS, EGPRS, WCDMA, HSDPA, 1xRTT, EVDO] - static const std::string KEY_NETWORK; //!< Cellular Service Provider - static const std::string KEY_NETWORK_REG; //!< Network Registration - static const std::string KEY_CID; //!< Cellular ID (Tower) in HEX - static const std::string KEY_LAC; //!< Location Area Code in HEX - static const std::string KEY_RAC; //!< Routing Area Code in HEX - static const std::string KEY_RSSI; //!< Received Signal Strength Indication - static const std::string KEY_RSSIDBM; //!< Received Signal Strength Indication in dBm - static const std::string KEY_MCC; //!< Mobile Country Code - static const std::string KEY_MNC; //!< Mobile Network (Operator) Code - static const std::string KEY_CHANNEL; //!< ARFCN or UARFCN Assigned Radio Channel - static const std::string KEY_TXPWR; //!< Transmit Power - static const std::string KEY_PSC; //!< Active Primary Synchronization Code (PSC) - static const std::string KEY_ECIO; //!< Active Ec/Io (chip energy per total wideband power in dBm) - static const std::string KEY_RSCP; //!< Active RSCP (Received Signal Code Power in dBm) - static const std::string KEY_DRX; //!< Discontinuous reception cycle length (ms) - static const std::string KEY_MM; //!< Mobility Management State - static const std::string KEY_RR; //!< Radio Resource State - static const std::string KEY_NOM; //!< Network Operator Mode - static const std::string KEY_ABND; //!< Active Band - static const std::string KEY_BLER; //!< Block Error Rate (percentage) - static const std::string KEY_SD; //!< Service Domain - static const std::string KEY_DEBUG; //!< Debug Information - - static const std::string KEY_MIP; //!< Mobile IP Information - static const std::string KEY_MIP_ID; //!< MIP Profile ID - static const std::string KEY_MIP_ENABLED; //!< MIP Profile Enabled/Disabled - static const std::string KEY_MIP_NAI; //!< Network Access Identifier - static const std::string KEY_MIP_HOMEADDRESS; //!< Home Address - static const std::string KEY_MIP_PRIMARYHA; //!< Primary Home Agent - static const std::string KEY_MIP_SECONDARYHA; //!< Secondary Home Agent - static const std::string KEY_MIP_MNAAASPI; //!< Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index - static const std::string KEY_MIP_MNHASPI; //!< Mobile Node Home Agent Security Server Parameter Index - static const std::string KEY_MIP_REVTUN; //!< Reverse Tunneling Enabled - static const std::string KEY_MIP_MNAAASS; //!< Mobile Node Authentication, Authorization, and Accounting Server Shared Secret - static const std::string KEY_MIP_MNHASS; //!< Mobile Node Home Agent Shared Secret - - - //Values - Type - static const std::string VALUE_TYPE_LTE; - static const std::string VALUE_TYPE_GSM; - static const std::string VALUE_TYPE_CDMA; - - //Values - Carrier - static const std::string VALUE_CARRIER_VERIZON; - static const std::string VALUE_CARRIER_AERIS; - static const std::string VALUE_CARRIER_SPRINT; - static const std::string VALUE_CARRIER_USCELLULAR; - static const std::string VALUE_CARRIER_ATT; - static const std::string VALUE_CARRIER_TMOBILE; - - static const std::string VALUE_SD_NO_SERVICE; - static const std::string VALUE_SD_CS_ONLY; - static const std::string VALUE_SD_PS_ONLY; - static const std::string VALUE_SD_CSPS; - - static const std::string VALUE_ABND_GSM_850; - static const std::string VALUE_ABND_GSM_900; - static const std::string VALUE_ABND_DCS_1800; - static const std::string VALUE_ABND_PCS_1900; - - static const std::vector DEFAULT_BAIL_STRINGS; - - typedef std::function IsNeedMoreData; - typedef std::function UpdateCb; - virtual ~TelitRadio(); virtual bool initialize(uint32_t iTimeoutMillis = 5000); @@ -214,10 +104,6 @@ namespace MTS { const std::string& getName() const; virtual CODE getModel(std::string& sModel); - static CODE convertModelToType(const std::string& sModel, std::string& sType); - static CODE convertModelToMtsShortCode(const std::string& sModel, std::string& sCode, TelitRadio *radioObj = NULL); - static CODE convertServiceDomainToString(SERVICEDOMAIN eSd, std::string& sSd); - static CODE convertActiveBandToString(ACTIVEBAND eBand, std::string& sBand); virtual CODE getFirmware(std::string& sFirmware); virtual CODE getFirmwareBuild(std::string& sFirmwareBuild); diff --git a/src/MTS_IO_ICellularRadio.cpp b/src/MTS_IO_ICellularRadio.cpp new file mode 100644 index 0000000..343480a --- /dev/null +++ b/src/MTS_IO_ICellularRadio.cpp @@ -0,0 +1,280 @@ +#include "mts/MTS_IO_ICellularRadio.h" + +const char MTS::IO::ICellularRadio::ETX = 0x03; //Ends socket connection +const char MTS::IO::ICellularRadio::DLE = 0x10; //Escapes ETX and DLE within Payload +const char MTS::IO::ICellularRadio::CR = 0x0D; +const char MTS::IO::ICellularRadio::NL = 0x0A; +const char MTS::IO::ICellularRadio::CTRL_Z = 0x1A; + +const std::string MTS::IO::ICellularRadio::RSP_ERROR("ERROR"); +const std::string MTS::IO::ICellularRadio::RSP_OK("OK"); + + +const std::string MTS::IO::ICellularRadio::DEFAULT_RADIO_PORT("/dev/modem_at1"); +const std::string MTS::IO::ICellularRadio::DEFAULT_RADIO_DIR("/var/run/radio/"); +const std::string MTS::IO::ICellularRadio::VALUE_UNKNOWN("Unknown"); +const std::string MTS::IO::ICellularRadio::VALUE_UNAVAILABLE("Unavailable"); +const std::string MTS::IO::ICellularRadio::VALUE_NOT_SUPPORTED("Not Supported"); + +const std::string MTS::IO::ICellularRadio::VALUE_NOT_REGISTERED("NOT REGISTERED"); +const std::string MTS::IO::ICellularRadio::VALUE_REGISTERED("REGISTERED"); +const std::string MTS::IO::ICellularRadio::VALUE_SEARCHING("SEARCHING"); +const std::string MTS::IO::ICellularRadio::VALUE_DENIED("DENIED"); +const std::string MTS::IO::ICellularRadio::VALUE_ROAMING("ROAMING"); + +//Static Data +const std::string MTS::IO::ICellularRadio::KEY_TYPE("type"); //!< GSM or CDMA +const std::string MTS::IO::ICellularRadio::KEY_CODE("code"); //!< Product Code : H5, H6, C2, EV3, G3 +const std::string MTS::IO::ICellularRadio::KEY_MODEL("model"); //!< Model : HE910, LE910, CE910, DE910, GE910 +const std::string MTS::IO::ICellularRadio::KEY_MANUFACTURER("manufacturer"); //!< Manufacturer: Telit +const std::string MTS::IO::ICellularRadio::KEY_HARDWARE("hardware"); //!< Radio Hardware Version +const std::string MTS::IO::ICellularRadio::KEY_FIRMWARE("firmware"); //!< Radio Firmware Version +const std::string MTS::IO::ICellularRadio::KEY_FIRMWARE_BUILD("firmwarebuild"); //!< Radio Firmware Build + +const std::string MTS::IO::ICellularRadio::KEY_CARRIER("carrier"); //!< Cellular Service Provider (Home Network) +const std::string MTS::IO::ICellularRadio::VALUE_CARRIER_VERIZON("Verizon"); +const std::string MTS::IO::ICellularRadio::VALUE_CARRIER_AERIS("Aeris"); +const std::string MTS::IO::ICellularRadio::VALUE_CARRIER_SPRINT("Sprint"); +const std::string MTS::IO::ICellularRadio::VALUE_CARRIER_USCELLULAR("U.S. Cellular"); +const std::string MTS::IO::ICellularRadio::VALUE_CARRIER_ATT("AT&T"); +const std::string MTS::IO::ICellularRadio::VALUE_CARRIER_TMOBILE("T-Mobile"); + +const std::string MTS::IO::ICellularRadio::KEY_IMEI("imei"); //!< International Mobile Station Equipment Identity +const std::string MTS::IO::ICellularRadio::KEY_MEID("meid"); //!< Mobile Equipment Identifier +const std::string MTS::IO::ICellularRadio::KEY_IMSI("imsi"); //!< International Mobile Subscriber Identity +const std::string MTS::IO::ICellularRadio::KEY_MSID("msid"); //!< Mobil Station ID / Mobile Identification Number (MSID/MIN) (CDMA-Only) +const std::string MTS::IO::ICellularRadio::KEY_MDN("mdn"); //!< Mobile Directory Number : Actual phone number dialed to reach radio +const std::string MTS::IO::ICellularRadio::KEY_ICCID("iccid"); //!< Integrated Circuit Card Identifier +const std::string MTS::IO::ICellularRadio::KEY_MSL("msl"); //!< Master Subsidy Lock + +//Dynamic Data +const std::string MTS::IO::ICellularRadio::KEY_ROAMING("roaming"); //!< Indicates whether or not using Home Network +const std::string MTS::IO::ICellularRadio::KEY_DATETIME("datetime"); //!< Date and Time from tower +const std::string MTS::IO::ICellularRadio::KEY_SERVICE("service"); //!< Service Connection Type [GPRS, EGPRS, WCDMA, HSDPA, 1xRTT, EVDO] +const std::string MTS::IO::ICellularRadio::KEY_NETWORK("network"); //!< Cellular Service Provider +const std::string MTS::IO::ICellularRadio::KEY_NETWORK_REG("netreg"); //!< Network Registration +const std::string MTS::IO::ICellularRadio::KEY_CID("cid"); //!< Cellular ID (Tower) in HEX +const std::string MTS::IO::ICellularRadio::KEY_LAC("lac"); //!< Location Area Code in HEX +const std::string MTS::IO::ICellularRadio::KEY_RAC("rac"); //!< Routing Area Code in HEX +const std::string MTS::IO::ICellularRadio::KEY_RSSI("rssi"); //!< Signal Strength +const std::string MTS::IO::ICellularRadio::KEY_RSSIDBM("rssidBm"); //!< Signal Strength in dBm +const std::string MTS::IO::ICellularRadio::KEY_MCC("mcc"); //!< Country Code +const std::string MTS::IO::ICellularRadio::KEY_MNC("mnc"); //!< Operator Code +const std::string MTS::IO::ICellularRadio::KEY_CHANNEL("channel"); //!< ARFCN or UARFCN Assigned Radio Channel +const std::string MTS::IO::ICellularRadio::KEY_TXPWR("txpwr"); //!< Transmit Power +const std::string MTS::IO::ICellularRadio::KEY_PSC("psc"); //!< Active Primary Synchronization Code (PSC) +const std::string MTS::IO::ICellularRadio::KEY_ECIO("ecio"); //!< Active Ec/Io (chip energy per total wideband power in dBm) +const std::string MTS::IO::ICellularRadio::KEY_RSCP("rscp"); //!< Active RSCP (Received Signal Code Power in dBm) +const std::string MTS::IO::ICellularRadio::KEY_DRX("drx"); //!< Discontinuous reception cycle length (ms) +const std::string MTS::IO::ICellularRadio::KEY_MM("mm"); //!< Mobility Management State +const std::string MTS::IO::ICellularRadio::KEY_RR("rr"); //!< Radio Resource State +const std::string MTS::IO::ICellularRadio::KEY_NOM("nom"); //!< Network Operator Mode +const std::string MTS::IO::ICellularRadio::KEY_ABND("abnd"); //!< Active Band +const std::string MTS::IO::ICellularRadio::KEY_BLER("bler"); //!< Block Error Rate (percentage) +const std::string MTS::IO::ICellularRadio::KEY_SD("sd"); //!< Service Domain +const std::string MTS::IO::ICellularRadio::KEY_DEBUG("debug"); //!< Debug Information + +const std::string MTS::IO::ICellularRadio::KEY_MIP("mipProfile"); //!< Mobile IP Information +const std::string MTS::IO::ICellularRadio::KEY_MIP_ID("id"); //!< Mobile IP ID +const std::string MTS::IO::ICellularRadio::KEY_MIP_ENABLED("enabled"); //!< Mobile IP Enabled/Disabled +const std::string MTS::IO::ICellularRadio::KEY_MIP_NAI("nai"); //!< Network Access Identifier +const std::string MTS::IO::ICellularRadio::KEY_MIP_HOMEADDRESS("homeAddress"); //!< Home Address +const std::string MTS::IO::ICellularRadio::KEY_MIP_PRIMARYHA("primaryAddress"); //!< Primary Home Agent +const std::string MTS::IO::ICellularRadio::KEY_MIP_SECONDARYHA("secondaryAddress"); //!< Secondary Home Agent +const std::string MTS::IO::ICellularRadio::KEY_MIP_MNAAASPI("mnAaaSpi"); //!< Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index +const std::string MTS::IO::ICellularRadio::KEY_MIP_MNHASPI("mnHaSpi"); //!< Mobile Node Home Agent Security Server Parameter Index +const std::string MTS::IO::ICellularRadio::KEY_MIP_REVTUN("revTun"); //!< Reverse Tunneling Enabled +const std::string MTS::IO::ICellularRadio::KEY_MIP_MNAAASS("mnAaaSs"); //!< Mobile Node Authentication, Authorization, and Accounting Server Shared Secret +const std::string MTS::IO::ICellularRadio::KEY_MIP_MNHASS("mnHaSs"); //!< Mobile Node Home Agent Shared Secret + +const std::string MTS::IO::ICellularRadio::VALUE_TYPE_GSM("GSM"); +const std::string MTS::IO::ICellularRadio::VALUE_TYPE_LTE("LTE"); +const std::string MTS::IO::ICellularRadio::VALUE_TYPE_CDMA("CDMA"); + +const std::string MTS::IO::ICellularRadio::VALUE_SD_NO_SERVICE("NO SERVICE"); +const std::string MTS::IO::ICellularRadio::VALUE_SD_CS_ONLY("CS ONLY"); +const std::string MTS::IO::ICellularRadio::VALUE_SD_PS_ONLY("PS ONLY"); +const std::string MTS::IO::ICellularRadio::VALUE_SD_CSPS("CS+PS"); + +const std::string MTS::IO::ICellularRadio::VALUE_ABND_GSM_850("GSM 850"); +const std::string MTS::IO::ICellularRadio::VALUE_ABND_GSM_900("GSM 900"); +const std::string MTS::IO::ICellularRadio::VALUE_ABND_DCS_1800("DCS 1800"); +const std::string MTS::IO::ICellularRadio::VALUE_ABND_PCS_1900("PCS 1900"); + +const std::vector MTS::IO::ICellularRadio::DEFAULT_BAIL_STRINGS = { MTS::IO::ICellularRadio::RSP_OK, MTS::IO::ICellularRadio::RSP_ERROR }; + +MTS::IO::ICellularRadio::~ICellularRadio() +{ +} + +MTS::IO::ICellularRadio::CODE MTS::IO::ICellularRadio::convertModelToMtsShortCode(const std::string& sModel, std::string& sCode, MTS::IO::ICellularRadio *radioObject) { + CODE eCode = FAILURE; + + if(sModel.find("HE910-D") == 0) { + sCode = "H5"; + eCode = SUCCESS; + } else if (sModel.find("HE910-EUD") == 0) { + sCode = "H6"; + eCode = SUCCESS; + } else if (sModel.find("LE910-JN1") == 0) { + sCode = "LDC3"; + eCode = SUCCESS; + } else if (sModel.find("LE866A1-JS") == 0) { + sCode = "LSB3"; + eCode = SUCCESS; + } else if (sModel.find("LE910-NAG") == 0) { + sCode = "LAT1"; + eCode = SUCCESS; + } else if (sModel.find("LE910C4-NF") == 0) { + sCode = "L4N1"; + eCode = SUCCESS; + } else if (sModel.find("LE910-NA1") == 0) { + if (NULL == radioObject) { + sCode = VALUE_NOT_SUPPORTED; + eCode = ERROR; + } else { + std::string sValue; + eCode = radioObject->getActiveFirmware(sValue); + if (eCode == SUCCESS) { + sCode = "LNA3"; + } else { + sCode = "LAT3"; + } + } + eCode = SUCCESS; + } else if (sModel.find("LE910-SVG") == 0) { + sCode = "LVW2"; + eCode = SUCCESS; + } else if (sModel.find("LE910C1-NS") == 0) { + sCode = "LSP3"; + eCode = SUCCESS; + } else if (sModel.find("LE910C1-AP") == 0) { + sCode = "LAP3"; + eCode = SUCCESS; + } else if (sModel.find("ME910C1-NA") == 0) { + sCode = "MAT1"; + eCode = SUCCESS; + } else if (sModel.find("ME910C1-NV") == 0) { + sCode = "MVW1"; + eCode = SUCCESS; + } else if (sModel.find("ME910C1-WW") == 0) { + sCode = "MNG2"; + eCode = SUCCESS; + } else if (sModel.find("LE910-EUG") == 0) { + sCode = "LEU1"; + eCode = SUCCESS; + } else if (sModel.find("LE910C4-EU") == 0) { + sCode = "L4E1"; + eCode = SUCCESS; + } else if (sModel.find("LE910-EU1") == 0) { + sCode = "LEU3"; + eCode = SUCCESS; + } else if (sModel.find("GE910") == 0) { + sCode = "G3"; + eCode = SUCCESS; + } else if (sModel.find("CE910") == 0) { + sCode = "C2"; + eCode = SUCCESS; + } else if (sModel.find("DE910") == 0) { + sCode = "EV3"; + eCode = SUCCESS; + } else { + sCode = VALUE_NOT_SUPPORTED; + //printError("RADIO| Could not identify MTS short code from model. [%s]", sModel.c_str()); + eCode = ERROR; + } + return eCode; +} + +MTS::IO::ICellularRadio::CODE MTS::IO::ICellularRadio::convertServiceDomainToString(SERVICEDOMAIN eSd, std::string& sSd) { + CODE eCode = FAILURE; + switch(eSd) { + case NO_SERVICE: sSd = VALUE_SD_NO_SERVICE; eCode = SUCCESS; break; + case CS_ONLY: sSd = VALUE_SD_CS_ONLY; eCode = SUCCESS; break; + case PS_ONLY: sSd = VALUE_SD_PS_ONLY; eCode = SUCCESS; break; + case CSPS: sSd = VALUE_SD_CSPS; eCode = SUCCESS; break; + default: sSd = VALUE_UNKNOWN; eCode = FAILURE; break; + } + return eCode; +} + +MTS::IO::ICellularRadio::CODE MTS::IO::ICellularRadio::convertActiveBandToString(ACTIVEBAND eBand, std::string& sBand) { + CODE eCode = FAILURE; + switch(eBand) { + case GSM_850: sBand = VALUE_ABND_GSM_850; eCode = SUCCESS; break; + case GSM_900: sBand = VALUE_ABND_GSM_900; eCode = SUCCESS; break; + case DCS_1800: sBand = VALUE_ABND_DCS_1800; eCode = SUCCESS; break; + case PCS_1900: sBand = VALUE_ABND_PCS_1900; eCode = SUCCESS; break; + default: sBand = VALUE_UNKNOWN; eCode = FAILURE; break; + } + return eCode; +} + +MTS::IO::ICellularRadio::CODE MTS::IO::ICellularRadio::convertModelToType(const std::string& sModel, std::string& sType) { + CODE eCode = FAILURE; + sType = VALUE_NOT_SUPPORTED; + + if(sModel.find("HE910-D") == 0) { + sType = VALUE_TYPE_GSM; + eCode = SUCCESS; + } else if (sModel.find("HE910-EUD") == 0) { + sType = VALUE_TYPE_GSM; + eCode = SUCCESS; + } else if (sModel.find("LE910-JN1") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE866A1-JS") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE910-NAG") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE910C4-NF") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE910-NA1") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE910-SVG") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE910-EUG") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE910C4-EU") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE910-EU1") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE910C1-NS") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("LE910C1-AP") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("ME910C1-NA") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("ME910C1-NV") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("ME910C1-WW") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; + } else if (sModel.find("GE910") == 0) { + sType = VALUE_TYPE_GSM; + eCode = SUCCESS; + } else if (sModel.find("CE910") == 0) { + sType = VALUE_TYPE_CDMA; + eCode = SUCCESS; + } else if (sModel.find("DE910") == 0) { + sType = VALUE_TYPE_CDMA; + eCode = SUCCESS; + } else { + sType = VALUE_TYPE_GSM; + eCode = ERROR; + //printError("RADIO| Could not identify type from model. [%s]. Assuming [%s]", sModel.c_str(), sType.c_str()); + } + return eCode; +} diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp index de863c3..8209d0f 100644 --- a/src/MTS_IO_TelitRadio.cpp +++ b/src/MTS_IO_TelitRadio.cpp @@ -36,108 +36,6 @@ using namespace MTS::IO; -const char TelitRadio::ETX = 0x03; //Ends socket connection -const char TelitRadio::DLE = 0x10; //Escapes ETX and DLE within Payload -const char TelitRadio::CR = 0x0D; -const char TelitRadio::NL = 0x0A; -const char TelitRadio::CTRL_Z = 0x1A; - -const std::string TelitRadio::RSP_ERROR("ERROR"); -const std::string TelitRadio::RSP_OK("OK"); - - -const std::string TelitRadio::DEFAULT_RADIO_PORT("/dev/modem_at1"); -const std::string TelitRadio::DEFAULT_RADIO_DIR("/var/run/radio/"); -const std::string TelitRadio::VALUE_UNKNOWN("Unknown"); -const std::string TelitRadio::VALUE_UNAVAILABLE("Unavailable"); -const std::string TelitRadio::VALUE_NOT_SUPPORTED("Not Supported"); - -const std::string TelitRadio::VALUE_NOT_REGISTERED("NOT REGISTERED"); -const std::string TelitRadio::VALUE_REGISTERED("REGISTERED"); -const std::string TelitRadio::VALUE_SEARCHING("SEARCHING"); -const std::string TelitRadio::VALUE_DENIED("DENIED"); -const std::string TelitRadio::VALUE_ROAMING("ROAMING"); - -//Static Data -const std::string TelitRadio::KEY_TYPE("type"); //!< GSM or CDMA -const std::string TelitRadio::KEY_CODE("code"); //!< Product Code : H5, H6, C2, EV3, G3 -const std::string TelitRadio::KEY_MODEL("model"); //!< Model : HE910, LE910, CE910, DE910, GE910 -const std::string TelitRadio::KEY_MANUFACTURER("manufacturer"); //!< Manufacturer: Telit -const std::string TelitRadio::KEY_HARDWARE("hardware"); //!< Radio Hardware Version -const std::string TelitRadio::KEY_FIRMWARE("firmware"); //!< Radio Firmware Version -const std::string TelitRadio::KEY_FIRMWARE_BUILD("firmwarebuild"); //!< Radio Firmware Build - -const std::string TelitRadio::KEY_CARRIER("carrier"); //!< Cellular Service Provider (Home Network) -const std::string TelitRadio::VALUE_CARRIER_VERIZON("Verizon"); -const std::string TelitRadio::VALUE_CARRIER_AERIS("Aeris"); -const std::string TelitRadio::VALUE_CARRIER_SPRINT("Sprint"); -const std::string TelitRadio::VALUE_CARRIER_USCELLULAR("U.S. Cellular"); -const std::string TelitRadio::VALUE_CARRIER_ATT("AT&T"); -const std::string TelitRadio::VALUE_CARRIER_TMOBILE("T-Mobile"); - -const std::string TelitRadio::KEY_IMEI("imei"); //!< International Mobile Station Equipment Identity -const std::string TelitRadio::KEY_MEID("meid"); //!< Mobile Equipment Identifier -const std::string TelitRadio::KEY_IMSI("imsi"); //!< International Mobile Subscriber Identity -const std::string TelitRadio::KEY_MSID("msid"); //!< Mobil Station ID / Mobile Identification Number (MSID/MIN) (CDMA-Only) -const std::string TelitRadio::KEY_MDN("mdn"); //!< Mobile Directory Number : Actual phone number dialed to reach radio -const std::string TelitRadio::KEY_ICCID("iccid"); //!< Integrated Circuit Card Identifier -const std::string TelitRadio::KEY_MSL("msl"); //!< Master Subsidy Lock - -//Dynamic Data -const std::string TelitRadio::KEY_ROAMING("roaming"); //!< Indicates whether or not using Home Network -const std::string TelitRadio::KEY_DATETIME("datetime"); //!< Date and Time from tower -const std::string TelitRadio::KEY_SERVICE("service"); //!< Service Connection Type [GPRS, EGPRS, WCDMA, HSDPA, 1xRTT, EVDO] -const std::string TelitRadio::KEY_NETWORK("network"); //!< Cellular Service Provider -const std::string TelitRadio::KEY_NETWORK_REG("netreg"); //!< Network Registration -const std::string TelitRadio::KEY_CID("cid"); //!< Cellular ID (Tower) in HEX -const std::string TelitRadio::KEY_LAC("lac"); //!< Location Area Code in HEX -const std::string TelitRadio::KEY_RAC("rac"); //!< Routing Area Code in HEX -const std::string TelitRadio::KEY_RSSI("rssi"); //!< Signal Strength -const std::string TelitRadio::KEY_RSSIDBM("rssidBm"); //!< Signal Strength in dBm -const std::string TelitRadio::KEY_MCC("mcc"); //!< Country Code -const std::string TelitRadio::KEY_MNC("mnc"); //!< Operator Code -const std::string TelitRadio::KEY_CHANNEL("channel"); //!< ARFCN or UARFCN Assigned Radio Channel -const std::string TelitRadio::KEY_TXPWR("txpwr"); //!< Transmit Power -const std::string TelitRadio::KEY_PSC("psc"); //!< Active Primary Synchronization Code (PSC) -const std::string TelitRadio::KEY_ECIO("ecio"); //!< Active Ec/Io (chip energy per total wideband power in dBm) -const std::string TelitRadio::KEY_RSCP("rscp"); //!< Active RSCP (Received Signal Code Power in dBm) -const std::string TelitRadio::KEY_DRX("drx"); //!< Discontinuous reception cycle length (ms) -const std::string TelitRadio::KEY_MM("mm"); //!< Mobility Management State -const std::string TelitRadio::KEY_RR("rr"); //!< Radio Resource State -const std::string TelitRadio::KEY_NOM("nom"); //!< Network Operator Mode -const std::string TelitRadio::KEY_ABND("abnd"); //!< Active Band -const std::string TelitRadio::KEY_BLER("bler"); //!< Block Error Rate (percentage) -const std::string TelitRadio::KEY_SD("sd"); //!< Service Domain -const std::string TelitRadio::KEY_DEBUG("debug"); //!< Debug Information - -const std::string TelitRadio::KEY_MIP("mipProfile"); //!< Mobile IP Information -const std::string TelitRadio::KEY_MIP_ID("id"); //!< Mobile IP ID -const std::string TelitRadio::KEY_MIP_ENABLED("enabled"); //!< Mobile IP Enabled/Disabled -const std::string TelitRadio::KEY_MIP_NAI("nai"); //!< Network Access Identifier -const std::string TelitRadio::KEY_MIP_HOMEADDRESS("homeAddress"); //!< Home Address -const std::string TelitRadio::KEY_MIP_PRIMARYHA("primaryAddress"); //!< Primary Home Agent -const std::string TelitRadio::KEY_MIP_SECONDARYHA("secondaryAddress"); //!< Secondary Home Agent -const std::string TelitRadio::KEY_MIP_MNAAASPI("mnAaaSpi"); //!< Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index -const std::string TelitRadio::KEY_MIP_MNHASPI("mnHaSpi"); //!< Mobile Node Home Agent Security Server Parameter Index -const std::string TelitRadio::KEY_MIP_REVTUN("revTun"); //!< Reverse Tunneling Enabled -const std::string TelitRadio::KEY_MIP_MNAAASS("mnAaaSs"); //!< Mobile Node Authentication, Authorization, and Accounting Server Shared Secret -const std::string TelitRadio::KEY_MIP_MNHASS("mnHaSs"); //!< Mobile Node Home Agent Shared Secret - -const std::string TelitRadio::VALUE_TYPE_GSM("GSM"); -const std::string TelitRadio::VALUE_TYPE_LTE("LTE"); -const std::string TelitRadio::VALUE_TYPE_CDMA("CDMA"); - -const std::string TelitRadio::VALUE_SD_NO_SERVICE("NO SERVICE"); -const std::string TelitRadio::VALUE_SD_CS_ONLY("CS ONLY"); -const std::string TelitRadio::VALUE_SD_PS_ONLY("PS ONLY"); -const std::string TelitRadio::VALUE_SD_CSPS("CS+PS"); - -const std::string TelitRadio::VALUE_ABND_GSM_850("GSM 850"); -const std::string TelitRadio::VALUE_ABND_GSM_900("GSM 900"); -const std::string TelitRadio::VALUE_ABND_DCS_1800("DCS 1800"); -const std::string TelitRadio::VALUE_ABND_PCS_1900("PCS 1900"); - -const std::vector TelitRadio::DEFAULT_BAIL_STRINGS = { TelitRadio::RSP_OK, TelitRadio::RSP_ERROR }; TelitRadio::TelitRadio(const std::string& sName, const std::string& sRadioPort) : m_sName(sName) @@ -266,178 +164,6 @@ TelitRadio::CODE TelitRadio::getModel(std::string& sModel) { return SUCCESS; } -TelitRadio::CODE TelitRadio::convertModelToMtsShortCode(const std::string& sModel, std::string& sCode, TelitRadio *radioObject) { - CODE eCode = FAILURE; - - if(sModel.find("HE910-D") == 0) { - sCode = "H5"; - eCode = SUCCESS; - } else if (sModel.find("HE910-EUD") == 0) { - sCode = "H6"; - eCode = SUCCESS; - } else if (sModel.find("LE910-JN1") == 0) { - sCode = "LDC3"; - eCode = SUCCESS; - } else if (sModel.find("LE866A1-JS") == 0) { - sCode = "LSB3"; - eCode = SUCCESS; - } else if (sModel.find("LE910-NAG") == 0) { - sCode = "LAT1"; - eCode = SUCCESS; - } else if (sModel.find("LE910C4-NF") == 0) { - sCode = "L4N1"; - eCode = SUCCESS; - } else if (sModel.find("LE910-NA1") == 0) { - if (NULL == radioObject) { - sCode = VALUE_NOT_SUPPORTED; - eCode = ERROR; - } else { - std::string sValue; - eCode = radioObject->getActiveFirmware(sValue); - if (eCode == SUCCESS) { - sCode = "LNA3"; - } else { - sCode = "LAT3"; - } - } - eCode = SUCCESS; - } else if (sModel.find("LE910-SVG") == 0) { - sCode = "LVW2"; - eCode = SUCCESS; - } else if (sModel.find("LE910C1-NS") == 0) { - sCode = "LSP3"; - eCode = SUCCESS; - } else if (sModel.find("LE910C1-AP") == 0) { - sCode = "LAP3"; - eCode = SUCCESS; - } else if (sModel.find("ME910C1-NA") == 0) { - sCode = "MAT1"; - eCode = SUCCESS; - } else if (sModel.find("ME910C1-NV") == 0) { - sCode = "MVW1"; - eCode = SUCCESS; - } else if (sModel.find("ME910C1-WW") == 0) { - sCode = "MNG2"; - eCode = SUCCESS; - } else if (sModel.find("LE910-EUG") == 0) { - sCode = "LEU1"; - eCode = SUCCESS; - } else if (sModel.find("LE910C4-EU") == 0) { - sCode = "L4E1"; - eCode = SUCCESS; - } else if (sModel.find("LE910-EU1") == 0) { - sCode = "LEU3"; - eCode = SUCCESS; - } else if (sModel.find("GE910") == 0) { - sCode = "G3"; - eCode = SUCCESS; - } else if (sModel.find("CE910") == 0) { - sCode = "C2"; - eCode = SUCCESS; - } else if (sModel.find("DE910") == 0) { - sCode = "EV3"; - eCode = SUCCESS; - } else { - sCode = VALUE_NOT_SUPPORTED; - printError("RADIO| Could not identify MTS short code from model. [%s]", sModel.c_str()); - eCode = ERROR; - } - return eCode; -} - -TelitRadio::CODE TelitRadio::convertServiceDomainToString(SERVICEDOMAIN eSd, std::string& sSd) { - CODE eCode = FAILURE; - switch(eSd) { - case NO_SERVICE: sSd = VALUE_SD_NO_SERVICE; eCode = SUCCESS; break; - case CS_ONLY: sSd = VALUE_SD_CS_ONLY; eCode = SUCCESS; break; - case PS_ONLY: sSd = VALUE_SD_PS_ONLY; eCode = SUCCESS; break; - case CSPS: sSd = VALUE_SD_CSPS; eCode = SUCCESS; break; - default: sSd = VALUE_UNKNOWN; eCode = FAILURE; break; - } - return eCode; -} - -TelitRadio::CODE TelitRadio::convertActiveBandToString(ACTIVEBAND eBand, std::string& sBand) { - CODE eCode = FAILURE; - switch(eBand) { - case GSM_850: sBand = VALUE_ABND_GSM_850; eCode = SUCCESS; break; - case GSM_900: sBand = VALUE_ABND_GSM_900; eCode = SUCCESS; break; - case DCS_1800: sBand = VALUE_ABND_DCS_1800; eCode = SUCCESS; break; - case PCS_1900: sBand = VALUE_ABND_PCS_1900; eCode = SUCCESS; break; - default: sBand = VALUE_UNKNOWN; eCode = FAILURE; break; - } - return eCode; -} - -TelitRadio::CODE TelitRadio::convertModelToType(const std::string& sModel, std::string& sType) { - CODE eCode = FAILURE; - sType = VALUE_NOT_SUPPORTED; - - if(sModel.find("HE910-D") == 0) { - sType = VALUE_TYPE_GSM; - eCode = SUCCESS; - } else if (sModel.find("HE910-EUD") == 0) { - sType = VALUE_TYPE_GSM; - eCode = SUCCESS; - } else if (sModel.find("LE910-JN1") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE866A1-JS") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE910-NAG") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE910C4-NF") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE910-NA1") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE910-SVG") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE910-EUG") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE910C4-EU") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE910-EU1") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE910C1-NS") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("LE910C1-AP") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("ME910C1-NA") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("ME910C1-NV") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("ME910C1-WW") == 0) { - sType = VALUE_TYPE_LTE; - eCode = SUCCESS; - } else if (sModel.find("GE910") == 0) { - sType = VALUE_TYPE_GSM; - eCode = SUCCESS; - } else if (sModel.find("CE910") == 0) { - sType = VALUE_TYPE_CDMA; - eCode = SUCCESS; - } else if (sModel.find("DE910") == 0) { - sType = VALUE_TYPE_CDMA; - eCode = SUCCESS; - } else { - sType = VALUE_TYPE_GSM; - eCode = ERROR; - printError("RADIO| Could not identify type from model. [%s]. Assuming [%s]", sModel.c_str(), sType.c_str()); - } - return eCode; -} - TelitRadio::CODE TelitRadio::getFirmware(std::string& sFirmware) { printTrace("%s| Get Firmware", m_sName.c_str()); sFirmware = VALUE_NOT_SUPPORTED; -- cgit v1.2.3 From 936d8d57853e1ffbe1f46874b7ba9194e26cccb9 Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Fri, 7 Jun 2019 12:35:49 +0300 Subject: [MTS-MTQ] refactoring makefile: so name fix for dynamic linking --- Makefile | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 6c09bff..ddc7a7a 100644 --- a/Makefile +++ b/Makefile @@ -47,13 +47,12 @@ LDFLAGS += -s -shared -Wl,-soname,$(APPNAME).so.0 .PHONY: all clean install -all: $(APPNAME).a $(APPNAME).so.$(VERSION) - +all: $(APPNAME).a $(APPNAME).so $(APPNAME).a: $(OBJS) $(AR) -r $@ $? -$(APPNAME).so.$(VERSION): $(OBJS) +$(APPNAME).so: $(OBJS) $(CC) $(LDFLAGS) -o $@ $? $(LDLIBS) # Handle header dependencies @@ -64,12 +63,10 @@ CPPFLAGS += -MMD install: mkdir -p $(DESTDIR)$(libdir) mkdir -p $(DESTDIR)$(includedir)/mts - install -m 0644 $(APPNAME).a $(APPNAME).so.$(VERSION) $(DESTDIR)$(libdir)/ - ln -sf $(APPNAME).so.$(VERSION) $(DESTDIR)$(libdir)/$(APPNAME).so.0 + install -m 0644 $(APPNAME).a $(APPNAME).so $(DESTDIR)$(libdir)/ + ln -sf $(APPNAME).so $(DESTDIR)$(libdir)/$(APPNAME).so.0 ln -sf $(APPNAME).so.0 $(DESTDIR)$(libdir)/$(APPNAME).so install -m 0644 include/mts/* $(DESTDIR)$(includedir)/mts/ clean: - $(RM) $(OBJS) $(APPNAME).a $(APPNAME).so.$(VERSION) $(DEPS) - - + $(RM) $(OBJS) $(APPNAME).a $(APPNAME).so $(DEPS) -- cgit v1.2.3 From 55c18e47596b6be9f19b33deb6c5cd0e798decd8 Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Fri, 7 Jun 2019 12:38:11 +0300 Subject: [MTS-MTQ] refactoring: public symbols visibility Make exported ICellularRadio and CellularRadioFactory only --- Makefile | 2 +- include/mts/MTS_IO_CellularRadioFactory.h | 3 ++- include/mts/MTS_IO_ICellularRadio.h | 5 ++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index ddc7a7a..2fdaf04 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ OBJS += \ CC := $(CXX) #-Werror -CXXFLAGS += -Wall -std=c++0x -fmessage-length=0 -fPIC +CXXFLAGS += -Wall -std=c++0x -fmessage-length=0 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden CPPFLAGS += -I=/usr/include/jsoncpp -Iinclude LDFLAGS += -s -shared -Wl,-soname,$(APPNAME).so.0 diff --git a/include/mts/MTS_IO_CellularRadioFactory.h b/include/mts/MTS_IO_CellularRadioFactory.h index 501f314..540ed29 100644 --- a/include/mts/MTS_IO_CellularRadioFactory.h +++ b/include/mts/MTS_IO_CellularRadioFactory.h @@ -21,6 +21,7 @@ #ifndef MTS_IO_CELLULARRADIOFACTORY_H_ #define MTS_IO_CELLULARRADIOFACTORY_H_ +#include #include #include #include @@ -32,7 +33,7 @@ namespace MTS { class GE910Radio; class DE910Radio; class CE910Radio; - class CellularRadioFactory { + class EXPORT CellularRadioFactory { public: diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h index 257ed00..d954a24 100644 --- a/include/mts/MTS_IO_ICellularRadio.h +++ b/include/mts/MTS_IO_ICellularRadio.h @@ -7,12 +7,11 @@ #include -#include -#include +#define EXPORT __attribute__((visibility("default"))) namespace MTS { namespace IO { - class ICellularRadio + class EXPORT ICellularRadio { public: typedef std::function IsNeedMoreData; -- cgit v1.2.3 From 402354f2410917888a7d4b04a2cbc3a76a321549 Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Fri, 7 Jun 2019 13:56:26 +0300 Subject: [MTS-MTQ] refactoring: factory interface --- include/mts/MTS_IO_CellularRadioFactory.h | 51 ++++++++++++++----------------- src/MTS_IO_CellularRadioFactory.cpp | 38 +++++++++++------------ 2 files changed, 42 insertions(+), 47 deletions(-) diff --git a/include/mts/MTS_IO_CellularRadioFactory.h b/include/mts/MTS_IO_CellularRadioFactory.h index 540ed29..c26e642 100644 --- a/include/mts/MTS_IO_CellularRadioFactory.h +++ b/include/mts/MTS_IO_CellularRadioFactory.h @@ -21,18 +21,13 @@ #ifndef MTS_IO_CELLULARRADIOFACTORY_H_ #define MTS_IO_CELLULARRADIOFACTORY_H_ -#include -#include #include #include +#include + namespace MTS { namespace IO { - - class HE910Radio; - class GE910Radio; - class DE910Radio; - class CE910Radio; class EXPORT CellularRadioFactory { public: @@ -40,29 +35,29 @@ namespace MTS { CellularRadioFactory(); virtual ~CellularRadioFactory() {}; - virtual CellularRadio* create(const std::string& sModel, const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); - - virtual CellularRadio* createHE910D(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createHE910EUD(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE910NAG(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE910C4NF(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE910NA1(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE910SVG(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE910EUG(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE910C4EU(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE910EU1(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE910C1NS(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE910C1AP(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createME910C1NA(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createME910C1NV(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createME910C1WW(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createGE910(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createDE910(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createCE910(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); - virtual CellularRadio* createLE866A1JS(const std::string& sPort = TelitRadio::DEFAULT_RADIO_PORT); + virtual ICellularRadio* create(const std::string& sModel, const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + + virtual ICellularRadio* createHE910D(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + virtual ICellularRadio* createHE910EUD(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + virtual ICellularRadio* createLE910NAG(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + virtual ICellularRadio* createLE910C4NF(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + virtual ICellularRadio* createLE910NA1(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + virtual ICellularRadio* createLE910SVG(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + virtual ICellularRadio* createLE910EUG(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + virtual ICellularRadio* createLE910C4EU(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + virtual ICellularRadio* createLE910EU1(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + virtual ICellularRadio* createLE910C1NS(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + virtual ICellularRadio* createLE910C1AP(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + virtual ICellularRadio* createME910C1NA(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + virtual ICellularRadio* createME910C1NV(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + virtual ICellularRadio* createME910C1WW(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + virtual ICellularRadio* createGE910(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + virtual ICellularRadio* createDE910(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + virtual ICellularRadio* createCE910(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + virtual ICellularRadio* createLE866A1JS(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); protected: - typedef MTS::IO::CellularRadio* (CellularRadioFactory::*CREATEFUNCPTR)(const std::string& sPort); + typedef MTS::IO::ICellularRadio* (CellularRadioFactory::*CREATEFUNCPTR)(const std::string& sPort); std::map< std::string, CREATEFUNCPTR > m_mCreationMap; virtual std::string identifyRadio(const std::string& sPort); diff --git a/src/MTS_IO_CellularRadioFactory.cpp b/src/MTS_IO_CellularRadioFactory.cpp index 17cbd05..130d3ed 100644 --- a/src/MTS_IO_CellularRadioFactory.cpp +++ b/src/MTS_IO_CellularRadioFactory.cpp @@ -62,7 +62,7 @@ CellularRadioFactory::CellularRadioFactory() { m_mCreationMap[LE866A1JSRadio::MODEL_NAME] = &CellularRadioFactory::createLE866A1JS; } -MTS::IO::CellularRadio* CellularRadioFactory::create(const std::string& sModel, const std::string& sPort) { +ICellularRadio* CellularRadioFactory::create(const std::string& sModel, const std::string& sPort) { std::string model(sModel); @@ -123,74 +123,74 @@ std::string CellularRadioFactory::identifyRadio(const std::string& sPort) { return sModel; } -CellularRadio* CellularRadioFactory::createHE910D(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createHE910D(const std::string& sPort) { return new HE910DRadio(sPort); } -CellularRadio* CellularRadioFactory::createHE910EUD(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createHE910EUD(const std::string& sPort) { return new HE910EUDRadio(sPort); } -CellularRadio* CellularRadioFactory::createLE910NAG(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createLE910NAG(const std::string& sPort) { return new LE910NAGRadio(sPort); } -CellularRadio* CellularRadioFactory::createLE910C4NF(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createLE910C4NF(const std::string& sPort) { return new LE910C4NFRadio(sPort); } -CellularRadio* CellularRadioFactory::createLE910NA1(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createLE910NA1(const std::string& sPort) { return new LE910NA1Radio(sPort); } -CellularRadio* CellularRadioFactory::createLE910SVG(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createLE910SVG(const std::string& sPort) { return new LE910SVGRadio(sPort); } -CellularRadio* CellularRadioFactory::createLE910EUG(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createLE910EUG(const std::string& sPort) { return new LE910EUGRadio(sPort); } -CellularRadio* CellularRadioFactory::createLE910C4EU(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createLE910C4EU(const std::string& sPort) { return new LE910C4EURadio(sPort); } -CellularRadio* CellularRadioFactory::createLE910EU1(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createLE910EU1(const std::string& sPort) { return new LE910EU1Radio(sPort); } -CellularRadio* CellularRadioFactory::createLE910C1NS(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createLE910C1NS(const std::string& sPort) { return new LE910C1NSRadio(sPort); } -CellularRadio* CellularRadioFactory::createLE910C1AP(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createLE910C1AP(const std::string& sPort) { return new LE910C1APRadio(sPort); } -CellularRadio* CellularRadioFactory::createME910C1NA(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createME910C1NA(const std::string& sPort) { return new ME910C1NARadio(sPort); } -CellularRadio* CellularRadioFactory::createME910C1NV(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createME910C1NV(const std::string& sPort) { return new ME910C1NVRadio(sPort); } -CellularRadio* CellularRadioFactory::createME910C1WW(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createME910C1WW(const std::string& sPort) { return new ME910C1WWRadio(sPort); } -CellularRadio* CellularRadioFactory::createGE910(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createGE910(const std::string& sPort) { return new GE910Radio(sPort); } -CellularRadio* CellularRadioFactory::createDE910(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createDE910(const std::string& sPort) { return new DE910Radio(sPort); } -CellularRadio* CellularRadioFactory::createCE910(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createCE910(const std::string& sPort) { return new CE910Radio(sPort); } -CellularRadio* CellularRadioFactory::createLE866A1JS(const std::string &sPort) { +ICellularRadio* CellularRadioFactory::createLE866A1JS(const std::string &sPort) { return new LE866A1JSRadio(sPort); } -- cgit v1.2.3 From 9f1b5b16547536196dde8e9296debbae924bfb2c Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Fri, 7 Jun 2019 14:41:03 +0300 Subject: [MTS-MTQ] refactoring: telit radio headers and internal data structures --- include/mts/MTS_IO_TelitRadio.h | 69 ++++------------------------------------- src/MTS_IO_TelitRadio.cpp | 66 ++++++++++++++++++++++++++++++++++----- 2 files changed, 64 insertions(+), 71 deletions(-) diff --git a/include/mts/MTS_IO_TelitRadio.h b/include/mts/MTS_IO_TelitRadio.h index 0fdad6b..621bfb4 100644 --- a/include/mts/MTS_IO_TelitRadio.h +++ b/include/mts/MTS_IO_TelitRadio.h @@ -21,76 +21,19 @@ #ifndef MTS_IO_TELITRADIO_H_ #define MTS_IO_TELITRADIO_H_ -#include +#include +#include + +#include +#include #include #include #include -#include #include -#include -#include -#include -#include - -typedef struct -{ - const char *name; - int32_t low; - int32_t high; -} *pNameRangeMap, nameRangeMap; - -static const unsigned int NUM_GSM_BANDS = 7; -static const unsigned int NUM_WCDMA_BANDS = 6; -static const unsigned int NUM_LTE_BANDS = 42; - -// http://niviuk.free.fr/gsm_band.php -static const nameRangeMap GSMband[] = -{ - {"GSM 450", 259, 293}, {"GSM 480", 306, 340}, - {"GSM 750", 438, 511}, {"GSM 850", 128, 251}, - {"GSM 900 P", 1, 124}, {"GSM 900 E/R", 955, 1023}, - {"GSM DCS 1800/1900", 512, 885}, - -}; - -// http://niviuk.free.fr/umts_band.php -static const nameRangeMap WCDMAband[] = -{ - {"BAND I", 10592, 10838}, {"BAND II", 9662, 9938}, - {"BAND III", 1162, 1513}, {"BAND IV", 1537, 1738}, - {"BAND V", 4357, 4458}, {"BAND VI", 4387, 4413} -}; - -// http://niviuk.free.fr/lte_band.php -static const nameRangeMap EULTRAband[] = -{ - {"EUTRAN BAND1", 0, 599}, {"EUTRAN BAND2", 600, 1199}, - {"EUTRAN BAND3", 1200, 1949}, {"EUTRAN BAND4", 1950, 2399}, - {"EUTRAN BAND5", 2400, 2649}, {"EUTRAN BAND6", 2650, 2749}, - {"EUTRAN BAND7", 2750, 3449}, {"EUTRAN BAND8", 3450, 3799}, - {"EUTRAN BAND9", 3800, 4149}, {"EUTRAN BAND10", 4150, 4749}, - {"EUTRAN BAND11", 4750, 4999}, {"EUTRAN BAND12", 5000, 5179}, - {"EUTRAN BAND13", 5180, 5279}, {"EUTRAN BAND14", 5280, 5379}, - {"EUTRAN BAND17", 5730, 5849}, {"EUTRAN BAND18", 5850, 5999}, - {"EUTRAN BAND19", 6000, 6149}, {"EUTRAN BAND20", 6150, 6449}, - {"EUTRAN BAND21", 6450, 6525}, {"EUTRAN BAND22", 6600, 7399}, - {"EUTRAN BAND23", 7500, 7699}, {"EUTRAN BAND24", 7700, 8039}, - {"EUTRAN BAND25", 8040, 8689}, {"EUTRAN BAND26", 8690, 9039}, - {"EUTRAN BAND27", 9040, 9209}, {"EUTRAN BAND28", 9210, 9659}, - {"EUTRAN BAND29", 9660, 9769}, {"EUTRAN BAND30", 9770, 9869}, - {"EUTRAN BAND31", 9870, 9919}, {"EUTRAN BAND32", 9920, 10359}, - {"EUTRAN BAND33", 36000, 36199}, {"EUTRAN BAND34", 36200, 36349}, - {"EUTRAN BAND35", 36350, 36949}, {"EUTRAN BAND36", 36950, 37549}, - {"EUTRAN BAND37", 37550, 37749}, {"EUTRAN BAND38", 37750, 38249}, - {"EUTRAN BAND39", 38250, 38649}, {"EUTRAN BAND40", 38650, 39649}, - {"EUTRAN BAND41", 39650, 41589}, {"EUTRAN BAND42", 41590, 43589}, - {"EUTRAN BAND43", 43590, 45589}, {"EUTRAN BAND44", 45590, 46589} -}; namespace MTS { namespace IO { - class TelitRadio : public CellularRadio { public: @@ -329,7 +272,7 @@ namespace MTS { private: - class RadioBandMap { + class RadioBandMap : public MTS::NonCopyable { public: RadioBandMap() { diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp index 8209d0f..65d0941 100644 --- a/src/MTS_IO_TelitRadio.cpp +++ b/src/MTS_IO_TelitRadio.cpp @@ -20,22 +20,72 @@ #include +#include + #include #include #include #include #include -#include -#include -#include -#include -#include -#include -#include - using namespace MTS::IO; +namespace { + typedef struct + { + const char *name; + int32_t low; + int32_t high; + } *pNameRangeMap, nameRangeMap; + + const unsigned int NUM_GSM_BANDS = 7; + const unsigned int NUM_WCDMA_BANDS = 6; + const unsigned int NUM_LTE_BANDS = 42; + + // http://niviuk.free.fr/gsm_band.php + const nameRangeMap GSMband[] = + { + {"GSM 450", 259, 293}, {"GSM 480", 306, 340}, + {"GSM 750", 438, 511}, {"GSM 850", 128, 251}, + {"GSM 900 P", 1, 124}, {"GSM 900 E/R", 955, 1023}, + {"GSM DCS 1800/1900", 512, 885}, + + }; + + // http://niviuk.free.fr/umts_band.php + const nameRangeMap WCDMAband[] = + { + {"BAND I", 10592, 10838}, {"BAND II", 9662, 9938}, + {"BAND III", 1162, 1513}, {"BAND IV", 1537, 1738}, + {"BAND V", 4357, 4458}, {"BAND VI", 4387, 4413} + }; + + // http://niviuk.free.fr/lte_band.php + const nameRangeMap EULTRAband[] = + { + {"EUTRAN BAND1", 0, 599}, {"EUTRAN BAND2", 600, 1199}, + {"EUTRAN BAND3", 1200, 1949}, {"EUTRAN BAND4", 1950, 2399}, + {"EUTRAN BAND5", 2400, 2649}, {"EUTRAN BAND6", 2650, 2749}, + {"EUTRAN BAND7", 2750, 3449}, {"EUTRAN BAND8", 3450, 3799}, + {"EUTRAN BAND9", 3800, 4149}, {"EUTRAN BAND10", 4150, 4749}, + {"EUTRAN BAND11", 4750, 4999}, {"EUTRAN BAND12", 5000, 5179}, + {"EUTRAN BAND13", 5180, 5279}, {"EUTRAN BAND14", 5280, 5379}, + {"EUTRAN BAND17", 5730, 5849}, {"EUTRAN BAND18", 5850, 5999}, + {"EUTRAN BAND19", 6000, 6149}, {"EUTRAN BAND20", 6150, 6449}, + {"EUTRAN BAND21", 6450, 6525}, {"EUTRAN BAND22", 6600, 7399}, + {"EUTRAN BAND23", 7500, 7699}, {"EUTRAN BAND24", 7700, 8039}, + {"EUTRAN BAND25", 8040, 8689}, {"EUTRAN BAND26", 8690, 9039}, + {"EUTRAN BAND27", 9040, 9209}, {"EUTRAN BAND28", 9210, 9659}, + {"EUTRAN BAND29", 9660, 9769}, {"EUTRAN BAND30", 9770, 9869}, + {"EUTRAN BAND31", 9870, 9919}, {"EUTRAN BAND32", 9920, 10359}, + {"EUTRAN BAND33", 36000, 36199}, {"EUTRAN BAND34", 36200, 36349}, + {"EUTRAN BAND35", 36350, 36949}, {"EUTRAN BAND36", 36950, 37549}, + {"EUTRAN BAND37", 37550, 37749}, {"EUTRAN BAND38", 37750, 38249}, + {"EUTRAN BAND39", 38250, 38649}, {"EUTRAN BAND40", 38650, 39649}, + {"EUTRAN BAND41", 39650, 41589}, {"EUTRAN BAND42", 41590, 43589}, + {"EUTRAN BAND43", 43590, 45589}, {"EUTRAN BAND44", 45590, 46589} + }; +} TelitRadio::TelitRadio(const std::string& sName, const std::string& sRadioPort) : m_sName(sName) -- cgit v1.2.3 From 596f8f8393bf837d73e0a62c87d52557d9191f96 Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Sat, 8 Jun 2019 00:23:57 +0300 Subject: [MTS-MTQ] refactoring: telit radio implementation leave telit specific code in telit class. move common code to cellular radio class. --- include/mts/MTS_IO_CellularRadio.h | 154 ++++- include/mts/MTS_IO_ICellularRadio.h | 2 - include/mts/MTS_IO_TelitRadio.h | 290 +------- src/MTS_IO_CellularRadio.cpp | 1299 +++++++++++++++++++++++++++++++++++ src/MTS_IO_TelitRadio.cpp | 1170 ++----------------------------- 5 files changed, 1504 insertions(+), 1411 deletions(-) diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index 1378612..e79e6d1 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -29,17 +29,165 @@ #ifndef MTS_IO_CELLULARRADIO_H_ #define MTS_IO_CELLULARRADIO_H_ +#include +#include + +#include + #include +#include +#include +#include +#include namespace MTS { namespace IO { - class CellularRadio : public ICellularRadio { + public: + const std::string& getName() const override; + + ~CellularRadio() override; + + bool initialize(uint32_t iTimeoutMillis = 5000) override; + bool resetConnection(uint32_t iTimeoutMillis = 5000) override; + void shutdown() override; + + CODE getFirmware(std::string& sFirmware) override; + CODE getFirmwareBuild(std::string& sFirmwareBuild) override; + CODE getHardware(std::string& sHardware) override; + CODE getManufacturer(std::string& sManufacturer) override; + CODE getImei(std::string& sImei) override; + CODE getMeid(std::string& sMeid) override; + CODE getImsi(std::string& sImsi) override; + CODE getSimStatus(std::string& sSimStatus) override; + CODE getLac(std::string& sLac) override; + CODE getMdn(std::string& sMdn) override; + CODE getMsid(std::string& sMsid) override; + CODE getType(std::string& sType) override; + CODE getCarrier(std::string& sCarrier) override; + CODE getNetwork(std::string& sNetwork) override; + CODE getTower(std::string& sTower) override; + CODE getTime(std::string& sDate, std::string& sTime, std::string& sTimeZone) override; + CODE getRoaming(bool& bRoaming) override; + + CODE getSignalStrength(int32_t& iRssi) override; + CODE getModemLocation(std::string& sLocation) override; + CODE convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& dBm) override; + CODE convertdBmToSignalStrength(const int32_t& dBm, int32_t& iRssi) override; + + CODE getRegistration(REGISTRATION& eRegistration) override; + CODE convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration) override; + CODE getMipProfile(Json::Value& jMipProfile) override; + CODE validateMsl(const Json::Value& jArgs) override; + CODE setMsid(const Json::Value& jArgs) override; + CODE setMipActiveProfile(const Json::Value& jArgs) override; + CODE setMipNai(const Json::Value& jArgs) override; + CODE setMipHomeIp(const Json::Value& jArgs) override; + CODE setMipPrimaryHa(const Json::Value& jArgs) override; + CODE setMipSecondaryHa(const Json::Value& jArgs) override; + CODE setMipMnAaaSpi(const Json::Value& jArgs) override; + CODE setMipMnHaSpi(const Json::Value& jArgs) override; + CODE setMipRevTun(const Json::Value& jArgs) override; + CODE setMipMnAaaSs(const Json::Value& jArgs) override; + CODE setMipMnHaSs(const Json::Value& jArgs) override; + CODE updateDc(const Json::Value& jArgs, UpdateCb& stepCb) override; + CODE updatePrl(const Json::Value& jArgs, UpdateCb& stepCb) override; + CODE updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) override; + CODE resetHfa(const Json::Value& jArgs, UpdateCb& stepCb) override; + CODE activate(const Json::Value& jArgs, UpdateCb& stepCb) override; + CODE setActiveFirmware(const Json::Value& jArgs) override; + CODE getActiveFirmware(std::string& sFwId) override; + CODE getEcho(bool& bEnabled) override; + CODE setEcho(bool bEnabled = true) override; + CODE getStaticInformation(Json::Value& jData) override; + CODE sendBasicCommand(const std::string& sCmd, int32_t timeoutMillis = 100, const char& ESC = CR) override; + + std::string sendCommand(const std::string& sCmd, + const std::vector& vBail = DEFAULT_BAIL_STRINGS, + int32_t timeoutMillis = 100, + const char& ESC = CR) override; + + + static std::string sendCommand(MTS::AutoPtr& apIo, + const std::string& sCmd, + const std::vector& vBail = DEFAULT_BAIL_STRINGS, + int32_t timeoutMillis = 100, + const char& ESC = CR); + + std::string sendCommand(const std::string& sCmd, + IsNeedMoreData& isNeedMoreData, + int32_t timeoutMillis = 100, + const char& ESC = CR) override; + + static std::string sendCommand(MTS::AutoPtr& apIo, + const std::string& sCmd, + IsNeedMoreData& isNeedMoreData, + int32_t timeoutMillis = 100, + const char& ESC = CR); + + static CODE test(MTS::AutoPtr& apIo, uint32_t timeoutSeconds = 30); + + static std::string extractModelFromResult(const std::string& sResult); + static std::string getCodeAsString(CODE code); + + protected: + + CellularRadio(const std::string& sName, const std::string& sRadioPort); + + virtual bool getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier); + virtual bool getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware); + virtual void getCommonNetworkStats(Json::Value& jData); + void initMipProfile(Json::Value& jData); + bool splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType = Json::ValueType::stringValue); + + class RadioBandMap : public MTS::NonCopyable { + public: + RadioBandMap() + { + m_sChannel = CellularRadio::VALUE_UNKNOWN; + m_iChannel = 0; + m_sRadioType = CellularRadio::VALUE_UNKNOWN; + } + + RadioBandMap(const std::string &channel, const std::string &radioType) : + m_sChannel(channel), + m_sRadioType(radioType) + { + m_iChannel = strtol(m_sChannel.c_str(), NULL, 10); + } + + virtual ~RadioBandMap() {} + + const char *getRadioBandName(); + const char *getRadioBandName(const std::string &channel, const std::string &radioType); + + private: + + const char *getLTEBand(const int channel); + const char *getCDMABand(const int channel); + const char *getGSMBand(const int channel); + + std::string m_sChannel; + int m_iChannel; + std::string m_sRadioType; + }; + + private: + std::string m_sName; + std::string m_sRadioPort; + std::string m_sFirmware; + std::string m_sCarrier; + MTS::AutoPtr m_apIo; + + bool m_bEchoEnabled; + bool m_bEnableEchoOnClose; + + std::string queryLteLac(); + std::string queryCGREGstring(); + void setCGREG(std::string value); }; } } - - #endif /* MTS_IO_CELLULARRADIO_H_ */ diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h index d954a24..ff8383c 100644 --- a/include/mts/MTS_IO_ICellularRadio.h +++ b/include/mts/MTS_IO_ICellularRadio.h @@ -360,7 +360,6 @@ namespace MTS { virtual CODE getStaticInformation(Json::Value& jData) = 0; virtual CODE getNetworkStatus(Json::Value& jData) = 0; - /* virtual CODE sendBasicCommand(const std::string& sCmd, int32_t timeoutMillis = 100, const char& ESC = CR) = 0; virtual std::string sendCommand(const std::string& sCmd, @@ -372,7 +371,6 @@ namespace MTS { IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis = 100, const char& ESC = CR) = 0; - */ }; } diff --git a/include/mts/MTS_IO_TelitRadio.h b/include/mts/MTS_IO_TelitRadio.h index 621bfb4..0c95f98 100644 --- a/include/mts/MTS_IO_TelitRadio.h +++ b/include/mts/MTS_IO_TelitRadio.h @@ -21,305 +21,31 @@ #ifndef MTS_IO_TELITRADIO_H_ #define MTS_IO_TELITRADIO_H_ -#include -#include - -#include - #include -#include -#include -#include -#include namespace MTS { namespace IO { class TelitRadio : public CellularRadio { - public: - virtual ~TelitRadio(); - - virtual bool initialize(uint32_t iTimeoutMillis = 5000); - virtual bool resetRadio(uint32_t iTimeoutMillis = 5000); - virtual bool resetConnection(uint32_t iTimeoutMillis = 5000); - virtual void shutdown(); - - const std::string& getName() const; - - virtual CODE getModel(std::string& sModel); - - virtual CODE getFirmware(std::string& sFirmware); - virtual CODE getFirmwareBuild(std::string& sFirmwareBuild); - virtual CODE getHardware(std::string& sHardware); - virtual CODE getManufacturer(std::string& sManufacturer); - virtual CODE getImei(std::string& sImei); - virtual CODE getMeid(std::string& sMeid); - virtual CODE getImsi(std::string& sImsi); - virtual CODE getSimStatus(std::string& sSimStatus); - virtual CODE getIccid(std::string& sIccid); - virtual CODE getService(std::string& sService); - virtual CODE getLac(std::string& sLac); - virtual CODE getMdn(std::string& sMdn); - virtual CODE getMsid(std::string& sMsid); - virtual CODE getType(std::string& sType); - virtual CODE getCarrier(std::string& sCarrier); - virtual CODE getNetwork(std::string& sNetwork); - virtual CODE getTower(std::string& sTower); - virtual CODE getTime(std::string& sDate, std::string& sTime, std::string& sTimeZone); - virtual CODE getRoaming(bool& bRoaming); - - virtual CODE getSignalStrength(int32_t& iRssi); - virtual CODE getModemLocation(std::string& sLocation); - virtual CODE convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& dBm); - virtual CODE convertdBmToSignalStrength(const int32_t& dBm, int32_t& iRssi); - - virtual CODE getRegistration(REGISTRATION& eRegistration); - virtual CODE convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration); - - //! Gather details of the radio's Mobile IP Profile - /*! - \param Json::Value object that will be populated with MIP data - \return Returns result code of gathering MIP - */ - virtual CODE getMipProfile(Json::Value& jMipProfile); - - /* - * jArgs = { - * "msl" : "Master Subsidy Lock (Aeris, Sprint): STRING" - * } - */ - virtual CODE validateMsl(const Json::Value& jArgs); - - /* - * jArgs = { - * "mdn" : "Mobile Directory Number : STRING", - * "msl" : "[OPTIONAL] Master Subsidy Lock (Aeris, Sprint): STRING" - * } - */ - virtual CODE setMdn(const Json::Value& jArgs); - - /* - * jArgs = { - * "msid" : "Mobil Station ID (MSID) aka MIN aka MSIN : STRING", - * "msl" : "[OPTIONAL] Master Subsidy Lock (Aeris, Sprint): STRING" - * } - */ - virtual CODE setMsid(const Json::Value& jArgs); - - /* - * jArgs = { - * "activeProfile" : "Set active profile: STRING" - * } - */ - virtual CODE setMipActiveProfile(const Json::Value& jArgs); - - /* - * jArgs = { - * "nai" : "Network Access Identifier : STRING" - * } - */ - virtual CODE setMipNai(const Json::Value& jArgs); - - /* - * jArgs = { - * "homeIp" : "Home Address : STRING" - * } - */ - virtual CODE setMipHomeIp(const Json::Value& jArgs); - - /* - * jArgs = { - * "primaryHa" : "Primary Home Agent : STRING" - * } - */ - virtual CODE setMipPrimaryHa(const Json::Value& jArgs); - - /* - * jArgs = { - * "secondaryHa" : "Secondary Home Agent : STRING" - * } - */ - virtual CODE setMipSecondaryHa(const Json::Value& jArgs); - - /* - * jArgs = { - * "mnAaaSpi" : "Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index : STRING" - * } - */ - virtual CODE setMipMnAaaSpi(const Json::Value& jArgs); - - /* - * jArgs = { - * "mnHaSpi" : "Mobile Node Home Agent Security Server Parameter Index : STRING" - * } - */ - virtual CODE setMipMnHaSpi(const Json::Value& jArgs); - - /* - * jArgs = { - * "revTun" : "[DESCRIPTION] : STRING" - * } - */ - virtual CODE setMipRevTun(const Json::Value& jArgs); - - /* - * jArgs = { - * "mnAaaSs" : "Mobile Node Authentication, Authorization, and Accounting Server Shared Secret : STRING" - * } - */ - virtual CODE setMipMnAaaSs(const Json::Value& jArgs); - - /* - * jArgs = { - * "mnHaSs" : "Mobile Node Home Agent Shared Secret : STRING" - * } - */ - virtual CODE setMipMnHaSs(const Json::Value& jArgs); - - /* - * jArgs = null - */ - virtual CODE updateDc(const Json::Value& jArgs, UpdateCb& stepCb); - - /* - * jArgs = null - */ - virtual CODE updatePrl(const Json::Value& jArgs, UpdateCb& stepCb); - - /* - * jArgs = null - */ - virtual CODE updateFumo(const Json::Value& jArgs, UpdateCb& stepCb); - - /* - * jArgs = { - * "msl" : "Master Subsidy Lock (Sprint): STRING" - * } - */ - virtual CODE resetHfa(const Json::Value& jArgs, UpdateCb& stepCb); - - /* - * jArgs = { - * "mdn" : "Mobile Directory Number (Aeris): STRING" - * "msid" : "Mobile Station ID (Aeris): STRING" - * } - */ - virtual CODE activate(const Json::Value& jArgs, UpdateCb& stepCb); + bool resetRadio(uint32_t iTimeoutMillis = 5000) override; - /* - * jArgs = { - * "enabled" : "RX Diversity Enabled ("0" or "1"): STRING" - * } - */ - virtual CODE setRxDiversity(const Json::Value& jArgs)=0; - /* - * jArgs = { - * "fwid" : "Firmware Image To Be Enabled: STRING" - * } - */ - virtual CODE setActiveFirmware(const Json::Value& jArgs); - virtual CODE getActiveFirmware(std::string& sFwId); - - virtual CODE getEcho(bool& bEnabled); - virtual CODE setEcho(bool bEnabled = true); - - virtual CODE getStaticInformation(Json::Value& jData); - virtual CODE getNetworkStatus(Json::Value& jData); - - virtual CODE sendBasicCommand(const std::string& sCmd, int32_t timeoutMillis = 100, const char& ESC = CR); - - virtual std::string sendCommand(const std::string& sCmd, - const std::vector& vBail = DEFAULT_BAIL_STRINGS, - int32_t timeoutMillis = 100, - const char& ESC = CR); - - - static std::string sendCommand(MTS::AutoPtr& apIo, - const std::string& sCmd, - const std::vector& vBail = DEFAULT_BAIL_STRINGS, - int32_t timeoutMillis = 100, - const char& ESC = CR); - - virtual std::string sendCommand(const std::string& sCmd, - IsNeedMoreData& isNeedMoreData, - int32_t timeoutMillis = 100, - const char& ESC = CR); - - static std::string sendCommand(MTS::AutoPtr& apIo, - const std::string& sCmd, - IsNeedMoreData& isNeedMoreData, - int32_t timeoutMillis = 100, - const char& ESC = CR); - - static CODE test(MTS::AutoPtr& apIo, uint32_t timeoutSeconds = 30); - - static std::string extractModelFromResult(const std::string& sResult); - static std::string getCodeAsString(CODE code); + CODE getModel(std::string& sModel) override; + CODE getIccid(std::string& sIccid) override; + CODE getService(std::string& sService) override; + CODE getNetworkStatus(Json::Value& jData) override; + CODE setMdn(const Json::Value& jArgs) override; protected: - TelitRadio(const std::string& sName, const std::string& sRadioPort); - virtual bool getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier); - virtual bool getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware); - - virtual void getCommonNetworkStats(Json::Value& jData); - - void initMipProfile(Json::Value& jData); - - bool splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType = Json::ValueType::stringValue); - - + bool getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier) override; + bool getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware) override; private: - class RadioBandMap : public MTS::NonCopyable { - public: - RadioBandMap() - { - m_sChannel = TelitRadio::VALUE_UNKNOWN; - m_iChannel = 0; - m_sRadioType = TelitRadio::VALUE_UNKNOWN; - } - - RadioBandMap(const std::string &channel, const std::string &radioType) : - m_sChannel(channel), - m_sRadioType(radioType) - { - m_iChannel = strtol(m_sChannel.c_str(), NULL, 10); - } - - virtual ~RadioBandMap() {} - - const char *getRadioBandName(); - const char *getRadioBandName(const std::string &channel, const std::string &radioType); - - private: - - const char *getLTEBand(const int channel); - const char *getCDMABand(const int channel); - const char *getGSMBand(const int channel); - - std::string m_sChannel; - int m_iChannel; - std::string m_sRadioType; - }; - - std::string m_sName; - std::string m_sRadioPort; - std::string m_sFirmware; - std::string m_sCarrier; - MTS::AutoPtr m_apIo; - - bool m_bEchoEnabled; - bool m_bEnableEchoOnClose; - std::string queryLteLac(); std::string queryCGREGstring(); void setCGREG(std::string value); }; } } - - - #endif diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index a29d14f..840132f 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -19,3 +19,1302 @@ */ #include "mts/MTS_IO_CellularRadio.h" + +#include + +#include +#include +#include +#include +#include + +using namespace MTS::IO; + +namespace { + typedef struct + { + const char *name; + int32_t low; + int32_t high; + } *pNameRangeMap, nameRangeMap; + + const unsigned int NUM_GSM_BANDS = 7; + const unsigned int NUM_WCDMA_BANDS = 6; + const unsigned int NUM_LTE_BANDS = 42; + + // http://niviuk.free.fr/gsm_band.php + const nameRangeMap GSMband[] = + { + {"GSM 450", 259, 293}, {"GSM 480", 306, 340}, + {"GSM 750", 438, 511}, {"GSM 850", 128, 251}, + {"GSM 900 P", 1, 124}, {"GSM 900 E/R", 955, 1023}, + {"GSM DCS 1800/1900", 512, 885}, + + }; + + // http://niviuk.free.fr/umts_band.php + const nameRangeMap WCDMAband[] = + { + {"BAND I", 10592, 10838}, {"BAND II", 9662, 9938}, + {"BAND III", 1162, 1513}, {"BAND IV", 1537, 1738}, + {"BAND V", 4357, 4458}, {"BAND VI", 4387, 4413} + }; + + // http://niviuk.free.fr/lte_band.php + const nameRangeMap EULTRAband[] = + { + {"EUTRAN BAND1", 0, 599}, {"EUTRAN BAND2", 600, 1199}, + {"EUTRAN BAND3", 1200, 1949}, {"EUTRAN BAND4", 1950, 2399}, + {"EUTRAN BAND5", 2400, 2649}, {"EUTRAN BAND6", 2650, 2749}, + {"EUTRAN BAND7", 2750, 3449}, {"EUTRAN BAND8", 3450, 3799}, + {"EUTRAN BAND9", 3800, 4149}, {"EUTRAN BAND10", 4150, 4749}, + {"EUTRAN BAND11", 4750, 4999}, {"EUTRAN BAND12", 5000, 5179}, + {"EUTRAN BAND13", 5180, 5279}, {"EUTRAN BAND14", 5280, 5379}, + {"EUTRAN BAND17", 5730, 5849}, {"EUTRAN BAND18", 5850, 5999}, + {"EUTRAN BAND19", 6000, 6149}, {"EUTRAN BAND20", 6150, 6449}, + {"EUTRAN BAND21", 6450, 6525}, {"EUTRAN BAND22", 6600, 7399}, + {"EUTRAN BAND23", 7500, 7699}, {"EUTRAN BAND24", 7700, 8039}, + {"EUTRAN BAND25", 8040, 8689}, {"EUTRAN BAND26", 8690, 9039}, + {"EUTRAN BAND27", 9040, 9209}, {"EUTRAN BAND28", 9210, 9659}, + {"EUTRAN BAND29", 9660, 9769}, {"EUTRAN BAND30", 9770, 9869}, + {"EUTRAN BAND31", 9870, 9919}, {"EUTRAN BAND32", 9920, 10359}, + {"EUTRAN BAND33", 36000, 36199}, {"EUTRAN BAND34", 36200, 36349}, + {"EUTRAN BAND35", 36350, 36949}, {"EUTRAN BAND36", 36950, 37549}, + {"EUTRAN BAND37", 37550, 37749}, {"EUTRAN BAND38", 37750, 38249}, + {"EUTRAN BAND39", 38250, 38649}, {"EUTRAN BAND40", 38650, 39649}, + {"EUTRAN BAND41", 39650, 41589}, {"EUTRAN BAND42", 41590, 43589}, + {"EUTRAN BAND43", 43590, 45589}, {"EUTRAN BAND44", 45590, 46589} + }; +} + +CellularRadio::CellularRadio(const std::string& sName, const std::string& sRadioPort) +: m_sName(sName) +, m_sRadioPort(sRadioPort) +, m_bEchoEnabled(false) +, m_bEnableEchoOnClose(false) +{ + m_apIo.reset(new MTS::IO::SerialConnection( + MTS::IO::SerialConnection::Builder(m_sRadioPort) + .baudRate(115200) + .useLockFile() + .build())); +} + + +CellularRadio::~CellularRadio() { + shutdown(); + m_apIo.reset(); +} + +bool CellularRadio::initialize(uint32_t iTimeoutMillis) { + if(!m_apIo->open(iTimeoutMillis)) { + printError("%s| Failed to open radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str()); + return false; + } + + bool bEnabled; + CODE eCode = getEcho(bEnabled); + if(eCode == SUCCESS && bEnabled) { + printDebug("%s| Disabling 'echo'", m_sName.c_str()); + setEcho(false); + m_bEnableEchoOnClose = true; + } + + return true; +} + +bool CellularRadio::resetConnection(uint32_t iTimeoutMillis) { + //Close Current Connection + if(!m_apIo.isNull()) { + m_apIo->close(); + } + + m_apIo.reset(new MTS::IO::SerialConnection( + MTS::IO::SerialConnection::Builder(m_sRadioPort) + .baudRate(115200) + .useLockFile() + .build())); + + //Try to obtain the device port over the given period of time + MTS::Timer oTimer; + oTimer.start(); + uint64_t iCurrentTime = 0; + while(iCurrentTime < iTimeoutMillis) { + + if(!m_apIo->open(iTimeoutMillis - iCurrentTime)) { + printWarning("%s| Failed to re-open radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str()); + } else { + printInfo("%s| Successfully re-opened radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str()); + printDebug("%s| Recovering 'echo' after connection reset", m_sName.c_str()); // see CellularRadio::initialize + setEcho(m_bEchoEnabled); + break; + } + + ::usleep(500000); //500 millis + iCurrentTime = oTimer.getMillis(); + } + oTimer.stop(); + return !m_apIo->isClosed(); +} + +void CellularRadio::shutdown() { + + if(!m_apIo.isNull()) { + if(m_bEnableEchoOnClose) { + printDebug("%s| Enabling 'echo'", m_sName.c_str()); + setEcho(true); + m_bEnableEchoOnClose = false; + } + m_apIo->close(); + } +} + +const std::string& CellularRadio::getName() const { + return m_sName; +} + +CellularRadio::CODE CellularRadio::getFirmware(std::string& sFirmware) { + printTrace("%s| Get Firmware", m_sName.c_str()); + sFirmware = VALUE_NOT_SUPPORTED; + std::string sCmd("AT+CGMR"); + std::string sResult = sendCommand(sCmd); + size_t pos = sResult.find(RSP_OK); + if (pos == std::string::npos) { + printWarning("%s| Unable to get firmware from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + sFirmware = MTS::Text::trim(sResult.substr(0, pos)); + if(sFirmware.size() == 0) { + printWarning("%s| Unable to get firmware from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + m_sFirmware = sFirmware; + + return SUCCESS; +} + +CellularRadio::CODE CellularRadio::getFirmwareBuild(std::string& sFirmwareBuild) { + sFirmwareBuild = VALUE_NOT_SUPPORTED; + return FAILURE; +} + +CellularRadio::CODE CellularRadio::getHardware(std::string& sHardware) { + printTrace("%s| Get Hardware", m_sName.c_str()); + sHardware = VALUE_NOT_SUPPORTED; + + if(m_sFirmware.size() == 0) { + getFirmware(m_sFirmware); + } + + if(getHardwareVersionFromFirmware(m_sFirmware, sHardware)) { + return SUCCESS; + } + return FAILURE; +} + +CellularRadio::CODE CellularRadio::getManufacturer(std::string& sManufacturer) { + printTrace("%s| Get Manufacturer", m_sName.c_str()); + sManufacturer = VALUE_NOT_SUPPORTED; + std::string sCmd("AT+GMI"); + std::string sResult = sendCommand(sCmd); + size_t pos = sResult.find(RSP_OK); + if (pos == std::string::npos) { + printWarning("%s| Unable to get manufacturer from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + sManufacturer = MTS::Text::trim(sResult.substr(0, pos)); + if(sManufacturer.size() == 0) { + printWarning("%s| Unable to get manufacturer from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + return SUCCESS; +} + +CellularRadio::CODE CellularRadio::getImei(std::string& sImei) { + printTrace("%s| Get IMEI", m_sName.c_str()); + sImei = VALUE_NOT_SUPPORTED; + std::string sCmd("AT+CGSN"); + std::string sResult = sendCommand(sCmd); + size_t pos = sResult.find(RSP_OK); + if (pos == std::string::npos) { + printWarning("%s| Unable to get IMEI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + sImei = MTS::Text::trim(sResult.substr(0, pos)); + if(sImei.size() == 0) { + printWarning("%s| Unable to get IMEI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + return SUCCESS; +} + +CellularRadio::CODE CellularRadio::getMeid(std::string& sMeid) { + printTrace("%s| Get MEID", m_sName.c_str()); + return getImei(sMeid); +} + +CellularRadio::CODE CellularRadio::getImsi(std::string& sImsi) { + printTrace("%s| Get IMSI", m_sName.c_str()); + sImsi = VALUE_NOT_SUPPORTED; + std::string sCmd("AT+CIMI"); + std::string sResult = sendCommand(sCmd); + size_t pos = sResult.find(RSP_OK); + if (pos == std::string::npos) { + printWarning("%s| Unable to get IMSI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + sImsi = MTS::Text::trim(sResult.substr(0, pos)); + if(sImsi.size() == 0) { + printWarning("%s| Unable to get IMSI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + return SUCCESS; +} + +CellularRadio::CODE CellularRadio::getSimStatus(std::string& sSimStatus) { + printTrace("%s| Get SIM Status", getName().c_str()); + sSimStatus = VALUE_UNKNOWN; + return FAILURE; +} + +CellularRadio::CODE CellularRadio::getLac(std::string& sLac) { + Json::Value jData; + + printTrace("%s| Get LAC", m_sName.c_str()); + sLac = VALUE_NOT_SUPPORTED; + + if(getNetworkStatus(jData) == SUCCESS) { + if(jData.isMember(KEY_LAC)) { + sLac = jData[KEY_LAC].asString(); + return SUCCESS; + } + } + + return FAILURE; +} + +CellularRadio::CODE CellularRadio::getMdn(std::string& sMdn) { + printTrace("%s| Get MDN", m_sName.c_str()); + sMdn = VALUE_NOT_SUPPORTED; + std::string sCmd("AT+CNUM"); + std::string sResult = sendCommand(sCmd); + size_t end = sResult.find(RSP_OK); + if (end == std::string::npos) { + printWarning("%s| Unable to get MDN from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + size_t start = sResult.find("CNUM:"); + if(start != std::string::npos) { + start += sizeof("CNUM:"); + std::vector vParts = MTS::Text::split(sResult.substr(start, end - start), ','); + if(vParts.size() < 3) { + printWarning("%s| Unable to parse MDN from response [%s]", m_sName.c_str(), sResult.c_str()); + return FAILURE; + } + sMdn = MTS::Text::strip(vParts[1], '"'); + if(sMdn.size() == 0) { + printWarning("%s| Unable to get MDN from radio using command [%s]. MDN may not be set.", m_sName.c_str(), sCmd.c_str()); + } + } else { + sMdn = ""; + printWarning("%s| Unable to get MDN from radio using command [%s]. MDN may not be set.", m_sName.c_str(), sCmd.c_str()); + } + + return SUCCESS; +} + +CellularRadio::CODE CellularRadio::getMsid(std::string& sMsid) { + printTrace("%s| Get MSID", m_sName.c_str()); + sMsid = ""; + + std::string sImsi; + if(getImsi(sImsi) == SUCCESS) { + if(sImsi.size() >= 10) { + sMsid = sImsi.substr(sImsi.size() - 10); + printTrace("IMSI: [%s] MEID [%s]", sImsi.c_str(), sMsid.c_str()); + return SUCCESS; + } + } + printWarning("%s| Unable to get MSID from radio", m_sName.c_str()); + return FAILURE; +} + +CellularRadio::CODE CellularRadio::getType(std::string& sType) { + printTrace("%s| Get Type", m_sName.c_str()); + sType = VALUE_NOT_SUPPORTED; + return FAILURE; +} + +CellularRadio::CODE CellularRadio::getCarrier(std::string& sCarrier) { + printTrace("%s| Get Carrier", m_sName.c_str()); + if(m_sCarrier == "") { + Json::Value jData; + if(getNetworkStatus(jData) == SUCCESS) { + if(jData.isMember(KEY_MCC) && jData.isMember(KEY_MNC)) { + std::string sMcc = jData[KEY_MCC].asString(); + std::string sMnc = jData[KEY_MNC].asString(); + Json::Value jLookup = MccMncTable::getInstance()->lookup(sMcc, sMnc); + printTrace("%s| MCC-MNC Lookup: [%s][%s][%s]", m_sName.c_str(), + sMcc.c_str(), sMnc.c_str(), jLookup.toStyledString().c_str()); + if(jLookup.isMember(KEY_CARRIER)) { + m_sCarrier = jLookup[KEY_CARRIER].asString(); + } else { + printWarning("%s| MCC-MNC Lookup did not contain carrier", m_sName.c_str()); + return FAILURE; + } + } else { + printWarning("%s| Network Status did no contain MCC or MNC", m_sName.c_str()); + return FAILURE; + } + } else { + return FAILURE; + } + } + + sCarrier = m_sCarrier; + return SUCCESS; +} + +CellularRadio::CODE CellularRadio::getTower(std::string& sTower) { + Json::Value jData; + + printTrace("%s| Get Tower", m_sName.c_str()); + sTower = VALUE_NOT_SUPPORTED; + + if(getNetworkStatus(jData) == SUCCESS) { + if(jData.isMember(KEY_CID)) { + sTower = jData[KEY_CID].asString(); + return SUCCESS; + } + } + return FAILURE; +} + +CellularRadio::CODE CellularRadio::getTime(std::string& sDate, std::string& sTime, std::string& sTimeZone) { + Json::Value jData; + + printTrace("%s| Get Time", m_sName.c_str()); + sDate = ""; + sTime = ""; + sTimeZone = ""; + + std::string sCmd("AT+CCLK?"); + std::string sResult = sendCommand(sCmd); + size_t end = sResult.find(RSP_OK); + if (end == std::string::npos) { + printWarning("%s| Unable to get Time from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + size_t start = sResult.find("CCLK: "); + if(start != std::string::npos) { + start += sizeof("CCLK: "); + std::string sValue = MTS::Text::trim(sResult.substr(start, end - start)); + sValue = MTS::Text::strip(sValue, '"'); + + std::vector vParts = MTS::Text::split(sValue, ','); + if(vParts.size() != 2) { + printWarning("%s| Unable to parse Date from response [%s]", m_sName.c_str(), sResult.c_str()); + return FAILURE; + } + + + std::vector vDateParts = MTS::Text::split(vParts[0], '/'); + if(vDateParts.size() != 3) { + printWarning("%s| Unable to parse Date from response [%s]", m_sName.c_str(), sResult.c_str()); + return FAILURE; + } + + //The Date format is YY/MM/DD -> Change to MM/DD/YY + sDate = vDateParts[1] + "/" + vDateParts[2] + "/" + vDateParts[0]; + + vParts = MTS::Text::split(vParts[1], '-'); + if(vParts.size() != 2) { + printWarning("%s| Unable to parse Time from response [%s]", m_sName.c_str(), sResult.c_str()); + return FAILURE; + } + sTime = vParts[0]; + + int32_t iZoneUnits; //the difference, expressed in quarters of an hour, between the local time and GMT + if(!MTS::Text::parse(iZoneUnits, MTS::Text::strip(vParts[1], '+'))) { + printWarning("%s| Unable to parse Time Zone from response [%s]", m_sName.c_str(), sResult.c_str()); + return FAILURE; + } + + int32_t iZone = iZoneUnits/4; //Divide by 4 to get hours difference + int32_t iZonePartial = (iZoneUnits % 4) * 15; //Remainder in minutes + std::string sPlusSign = "+"; + if(iZonePartial < 0) { + //Remove negative sign from partial and clear plus sign component + iZonePartial *= -1; + sPlusSign = ""; + } + std::stringstream ss; + ss << sPlusSign << iZone; + if(iZonePartial != 0) { + ss << ":" << iZonePartial; + } + + sTimeZone = ss.str(); + return SUCCESS; + + } else { + printWarning("%s| Unable to get Time from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + } + + return FAILURE; +} + +CellularRadio::CODE CellularRadio::getRoaming(bool& bRoaming) { + Json::Value jData; + + printTrace("%s| Get Roaming", m_sName.c_str()); + bRoaming = false; + + REGISTRATION eReg; + if(getRegistration(eReg) == SUCCESS) { + bRoaming = (eReg == ROAMING); + return SUCCESS; + } + return FAILURE; +} + +CellularRadio::CODE CellularRadio::getNetwork(std::string& sNetwork) { + Json::Value jData; + + printTrace("%s| Get Network", m_sName.c_str()); + sNetwork = VALUE_NOT_SUPPORTED; + + if(getNetworkStatus(jData) == SUCCESS) { + if(jData.isMember(KEY_NETWORK)) { + sNetwork = jData[KEY_NETWORK].asString(); + return SUCCESS; + } + } + return FAILURE; +} + +CellularRadio::CODE CellularRadio::getSignalStrength(int32_t& rssi) { + printTrace("%s| Get Signal Strength", m_sName.c_str()); + std::string sCmd("AT+CSQ"); + std::string sResult = sendCommand(sCmd); + if (sResult.find("+CSQ: ") == std::string::npos) { + printDebug("%s| Signal Strength 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); + if(start == std::string::npos || stop == std::string::npos) { + printDebug("%s| Signal Strength command returned malformed response: [%s]", m_sName.c_str(), sResult.c_str()); + return FAILURE; + } + std::string signal = sResult.substr(start + 2, stop - start - 2); + + sscanf(signal.c_str(), "%d", &rssi); + printDebug("%s| Signal Strength: [%d]", m_sName.c_str(), rssi); + + return SUCCESS; +} + +CellularRadio::CODE CellularRadio::getModemLocation(std::string&) { + printTrace("%s|CellularRadio getModemLocation - not supported", m_sName.c_str()); + return FAILURE; +} + +CellularRadio::CODE CellularRadio::convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& iDbm) { + + //Telit Conversion + if(iRssi < 0 || iRssi == 99) { + return FAILURE; + } + + if(iRssi == 0) { + iDbm = -113; + } else if(iRssi == 1) { + iDbm = -111; + } else if(iRssi <= 30) { + //28 steps between 2 and 30 + //54 dbm between 53 and 109 + float stepSize = 54.0 / 28.0; + iDbm = -109 + (int)(stepSize * (iRssi-2)); + } else { + iDbm = -51; + } + + return SUCCESS; +} + +CellularRadio::CODE CellularRadio::convertdBmToSignalStrength(const int32_t& iDBm, int32_t& iRssi) { + //Telit Conversion + if(iDBm <= -113) { + iRssi = 0; + } else if(iDBm <= -111) { + iRssi = 1; + } else if(iDBm <= -53) { + //54 dbm between -109 and -53 + //28 steps between 2 and 30 + float stepSize = 28.0/54.0; + iRssi = ((iDBm + 109)*stepSize) + 2; + } else { + iRssi = 31; + } + + return SUCCESS; +} + +CellularRadio::CODE CellularRadio::getEcho(bool& bEnabled) { + printTrace("%s| Echo Test", m_sName.c_str()); + std::string sResult = sendCommand("AT"); + if(sResult.size() == 0) { + return NO_RESPONSE; + } + + if(sResult.find("AT") != std::string::npos) { + bEnabled = true; + } else { + bEnabled = false; + } + m_bEchoEnabled = bEnabled; + return SUCCESS; +} + +CellularRadio::CODE CellularRadio::setEcho(bool bEnabled) { + CODE eCode = FAILURE; + if(bEnabled) { + eCode = sendBasicCommand("ATE1"); + m_bEchoEnabled = (eCode == SUCCESS ) ? true : m_bEchoEnabled; + } else { + eCode = sendBasicCommand("ATE0"); + m_bEchoEnabled = (eCode == SUCCESS ) ? false : m_bEchoEnabled; + } + + return eCode; +} + +CellularRadio::CODE CellularRadio::getStaticInformation(Json::Value& jData) { + printTrace("%s| Get Static Information", m_sName.c_str()); + + printTrace("%s| Static Information:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); + + return FAILURE; +} + +/* AT#RFSTS - NETWORK STATUS + + (GSM network) + #RFSTS:,,,,,,,,,,,,, + Where: + - Country code and operator code(MCC, MNC) + - GSM Assigned Radio Channel + - Received Signal Strength Indication + - Localization Area Code + - Routing Area Code + - Tx Power + - Mobility Management state + - Radio Resource state + - Network Operator Mode + - Cell ID + - International Mobile Subscriber Identity + - Operator name + - Service Domain + 0 - No Service + 1 - CS only + 2 - PS only + 3 - CS+PS + - Active Band + 1 - GSM 850 + 2 - GSM 900 + 3 - DCS 1800 + 4 - PCS 1900 + + + (WCDMA network) + #RFSTS: + ,,,,, RSSI>,,,,,,,,,,, + ,,[,,] + Where: + - Country code and operator code(MCC, MNC) + - UMTS Assigned Radio Channel + - Active PSC(Primary Synchronization Code) + - Active Ec/Io(chip energy per total wideband power in dBm) + - Active RSCP (Received Signal Code Power in dBm) + - Received Signal Strength Indication + - Localization Area Code + - Routing Area Code + - Tx Power + - Discontinuous reception cycle Length (cycle length in ms) + - Mobility Management state + - Radio Resource state + - Network Operator Mode + - Block Error Rate (e.g., 005 means 0.5 %) + - Cell ID + - International Mobile Station ID + - Operator name + - Service Domain (see above) + - Number of Active Set (Maximum 6) + UARFCN of n th active set + PSC of n th active set + Ec/Io of n th active Set + + (LTE Network) + #RFSTS: + - + - + - + - + - + - + [] - + - + - + - + - + - + [] - + - + - +*/ + +// 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 = 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)), ","); + if(vParts.size() < 3) { + result = VALUE_UNAVAILABLE; + } else { + 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; + if(getRoaming(bRoaming) == SUCCESS) { + jData[KEY_ROAMING] = bRoaming; + } + + int32_t iRssi; + if(getSignalStrength(iRssi) == SUCCESS) { + jData[KEY_RSSI] = iRssi; + int32_t dBm; + if(!jData.isMember(KEY_RSSIDBM) && convertSignalStrengthTodBm(iRssi, dBm) == SUCCESS) { + //Add RSSI in dBm format + jData[KEY_RSSIDBM] = MTS::Text::format(dBm); + } + } + + std::string sService; + if(getService(sService) == SUCCESS) { + jData[KEY_SERVICE] = sService; + } + std::string sDate, sTime, sTimeZone; + if(getTime(sDate, sTime, sTimeZone) == SUCCESS) { + jData[KEY_DATETIME] = sDate + " " + sTime + " GMT" + sTimeZone; + } + + std::string sNetworkReg; + REGISTRATION eReg; + if (getRegistration(eReg) == SUCCESS) { + if (convertRegistrationToString(eReg, sNetworkReg) == SUCCESS) { + jData[KEY_NETWORK_REG] = sNetworkReg; + } + } +} + +void CellularRadio::initMipProfile(Json::Value& jData) { + jData[KEY_MIP_ID] = 0; + jData[KEY_MIP_ENABLED] = false; + jData[KEY_MIP_NAI] = VALUE_UNKNOWN; + jData[KEY_MIP_HOMEADDRESS] = VALUE_UNKNOWN; + jData[KEY_MIP_PRIMARYHA] = VALUE_UNKNOWN; + jData[KEY_MIP_SECONDARYHA] = VALUE_UNKNOWN; + jData[KEY_MIP_MNAAASPI] = VALUE_UNKNOWN; + jData[KEY_MIP_MNHASPI] = VALUE_UNKNOWN; + jData[KEY_MIP_MNAAASS] = false; + jData[KEY_MIP_MNHASS] = false; +} + +CellularRadio::CODE CellularRadio::getRegistration(REGISTRATION& eRegistration) { + std::string sCmd; + std::string sResp; + + // LE910C1-NS is an LE910, so we stop the scan after the 0. + if (m_sName.find("LE910") != std::string::npos) { + // use AT+CGREG instead for LE910 models + sCmd = "AT+CGREG?"; + sResp = "+CGREG: "; + } + else { + 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: [%s]", 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; + return SUCCESS; +} + +CellularRadio::CODE CellularRadio::convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration) { + + CODE eCode = FAILURE; + switch (eRegistration) { + case NOT_REGISTERED: sRegistration = VALUE_NOT_REGISTERED; eCode = SUCCESS; break; + case REGISTERED: sRegistration = VALUE_REGISTERED; eCode = SUCCESS; break; + case SEARCHING: sRegistration = VALUE_SEARCHING; eCode = SUCCESS; break; + case DENIED: sRegistration = VALUE_DENIED; eCode = SUCCESS; break; + case UNKNOWN: sRegistration = VALUE_UNKNOWN; eCode = SUCCESS; break; + case ROAMING: sRegistration = VALUE_ROAMING; eCode = SUCCESS; break; + } + return eCode; +} + +CellularRadio::CODE CellularRadio::validateMsl(const Json::Value&) { + printTrace("%s| Validate MSL", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::setMsid(const Json::Value&) { + printTrace("%s| Set MSID", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::getMipProfile(Json::Value&) { + printTrace("%s| Get MIP Active Profile", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::setMipActiveProfile(const Json::Value&) { + printTrace("%s| Set MIP Active Profile", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::setMipNai(const Json::Value&) { + printTrace("%s| Set MIP NAI", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::setMipHomeIp(const Json::Value&) { + printTrace("%s| Set MIP Home IP", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::setMipPrimaryHa(const Json::Value&) { + printTrace("%s| Set MIP Primary HA", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::setMipSecondaryHa(const Json::Value&) { + printTrace("%s| Set MIP Secondary HA", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::setMipMnAaaSpi(const Json::Value&) { + printTrace("%s| Set MIP MN-AAA SPI", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::setMipMnHaSpi(const Json::Value&) { + printTrace("%s| Set MIP MN-HA SPI", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::setMipRevTun(const Json::Value&) { + printTrace("%s| Set MIP Rev Tun", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::setMipMnAaaSs(const Json::Value&) { + printTrace("%s| Set MIP MN-AAA SS", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::setMipMnHaSs(const Json::Value&) { + printTrace("%s| Set MIP MN-HA SS", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::updateDc(const Json::Value&, UpdateCb&) { + printTrace("%s| Update Device Configuration", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::updatePrl(const Json::Value&, UpdateCb&) { + printTrace("%s| Update Preferred Roaming List", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::updateFumo(const Json::Value&, UpdateCb&) { + printTrace("%s| Update Firmware Update Management Object", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::resetHfa(const Json::Value&, UpdateCb&) { + printTrace("%s| HFA Reset", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::activate(const Json::Value&, UpdateCb&) { + printTrace("%s| Activation", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::setActiveFirmware(const Json::Value&) { + printTrace("%s| Set Active Firmware Image Number: not applicable", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::getActiveFirmware(std::string& sFwId) { + printTrace("%s| Get Active Firmware Image Number: not applicable", m_sName.c_str()); + sFwId = VALUE_NOT_SUPPORTED; + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::sendBasicCommand(const std::string& sCmd, int32_t iTimeoutMillis, const char& ESC) { + std::string response = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, iTimeoutMillis, ESC); + if (response.size() == 0) { + return NO_RESPONSE; + } else if (response.find(RSP_OK) != std::string::npos) { + return SUCCESS; + } else if (response.find(RSP_ERROR) != std::string::npos) { + return ERROR; + } else { + return FAILURE; + } +} + +std::string CellularRadio::sendCommand(const std::string& sCmd, const std::vector& vBail, int32_t timeoutMillis, const char& ESC) { + return sendCommand(m_apIo, sCmd, vBail, timeoutMillis, ESC); +} + +std::string CellularRadio::sendCommand(MTS::AutoPtr& apIo, const std::string& sCmd, + const std::vector& vBail, int32_t timeoutMillis, const char& ESC) { + IsNeedMoreData isNeedMoreData = [&vBail](const std::string&, const std::string& allData)->bool { + for(size_t i = 0; i < vBail.size(); i++) { + const std::string& sBail = vBail[i]; + if(sBail.size() > 0) { + if(allData.find(sBail) != std::string::npos) { + //Return when bail string is found + printTrace("RADIO| Found bail string [%s]", sBail.c_str()); + return false; + } + } + } + return true; + }; + + return sendCommand(apIo, sCmd, isNeedMoreData, timeoutMillis, ESC); +} + +std::string CellularRadio::sendCommand(const std::string& sCmd, MTS::IO::CellularRadio::IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis, const char& ESC) { + return sendCommand(m_apIo, sCmd, isNeedMoreData, timeoutMillis, ESC); +} + +std::string CellularRadio::sendCommand(MTS::AutoPtr& apIo, const std::string& sCmd, + IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis, const char& ESC) { + if(MTS::Logger::getPrintLevel() >= MTS::Logger::PrintLevel::TRACE_LEVEL) { + printTrace("RADIO| Sending command [%s]", sCmd.c_str()); + } + if(apIo.isNull()) { + printError("RADIO| IO is not set in sendCommand"); + return ""; + } + + int32_t iResult; + if(ESC == 0x00) { + iResult = apIo->write(sCmd.data(), sCmd.size()); + } else { + std::string sNewCmd(sCmd); + sNewCmd.push_back(ESC); + iResult = apIo->write(sNewCmd.data(), sNewCmd.size()); + } + + if(iResult == -1) { + printError("RADIO| Failed to send command to radio"); + return ""; + } + + bool done = false; + const uint32_t capacity = 1024; + char buffer[capacity]; + std::string sResult; + Timer timer; + timer.start(); + do { + int32_t iterationTimeout = 100; + int bytesRead = apIo->read((char*)buffer, capacity, iterationTimeout); + if(bytesRead == -1) { + printError("RADIO| Failed to read from radio"); + break; + } + + std::string sIteration((char*)buffer, bytesRead); + sResult += sIteration; + + if(isNeedMoreData && !isNeedMoreData(sIteration, sResult)) { + printTrace("RADIO| No more data needed"); + return sResult; + } + if(timeoutMillis >= 0) { + done = (timer.getMillis() >= (uint64_t)timeoutMillis); + } else { + //Do not stop looping until bail string is found + } + } while(!done); + + //Timed out + return sResult; +} + +CellularRadio::CODE CellularRadio::test(MTS::AutoPtr& apIo, uint32_t timeoutSeconds) { + printTrace("RADIO| Basic Test"); + uint32_t count = 0; + std::string sCmd("AT"); + do { + std::string sResult = sendCommand(apIo, sCmd); + if (sResult.find(RSP_OK) == std::string::npos) { + printTrace("RADIO| Waiting for basic radio communication [%s] ...", sResult.c_str()); + } else { + break; + } + count++; + } while (count < timeoutSeconds); + + if(count == timeoutSeconds) { + printWarning("RADIO| Basic radio communication FAILED"); + return NO_RESPONSE; + } + return SUCCESS; +} + +std::string CellularRadio::extractModelFromResult(const std::string& sResult) { + std::string sModel(VALUE_NOT_SUPPORTED); + + if(sResult.find("HE910-D") != std::string::npos) { + sModel = "HE910-D"; + } else if(sResult.find("HE910-EUD") != std::string::npos) { + sModel = "HE910-EUD"; + } else if(sResult.find("LE910-JN1") != std::string::npos) { + sModel = "LE910-JN1"; + } else if(sResult.find("LE866A1-JS") != std::string::npos) { + sModel = "LE866A1-JS"; + } else if(sResult.find("LE910-NAG") != std::string::npos) { + sModel = "LE910-NAG"; + } else if(sResult.find("LE910C4-NF") != std::string::npos) { + sModel = "LE910C4-NF"; + } else if(sResult.find("LE910-NA1") != std::string::npos) { + sModel = "LE910-NA1"; + } else if(sResult.find("ME910C1-NA") != std::string::npos) { + sModel = "ME910C1-NA"; + } else if(sResult.find("ME910C1-NV") != std::string::npos) { + sModel = "ME910C1-NV"; + } else if(sResult.find("ME910C1-WW") != std::string::npos) { + sModel = "ME910C1-WW"; + } else if(sResult.find("LE910-SVG") != std::string::npos) { + sModel = "LE910-SVG"; + } else if(sResult.find("LE910-EUG") != std::string::npos) { + sModel = "LE910-EUG"; + } else if(sResult.find("LE910C4-EU") != std::string::npos) { + sModel = "LE910C4-EU"; + } else if(sResult.find("LE910-EU1") != std::string::npos) { + sModel = "LE910-EU1"; + } else if(sResult.find("LE910C1-NS") != std::string::npos) { + sModel = "LE910C1-NS"; + } else if(sResult.find("LE910C1-AP") != std::string::npos) { + sModel = "LE910C1-AP"; + } else if(sResult.find("GE910") != std::string::npos) { + sModel = "GE910"; + } else if(sResult.find("DE910-DUAL") != std::string::npos) { + sModel = "DE910-DUAL"; + } else if(sResult.find("CE910") != std::string::npos) { + sModel = "CE910"; + } + return sModel; +} + +std::string CellularRadio::getCodeAsString(CODE eCode) { + switch(eCode) { + case SUCCESS: + return "SUCCESS"; + case ERROR: + return "ERROR"; + case FAILURE: + return "FAILURE"; + case NO_RESPONSE: + return "NO RESPONSE"; + default: + return "UNKNOWN"; + } +} + +bool CellularRadio::splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType) { + + std::vector vParts = MTS::Text::split(sLine, ":", 2); + + if(vParts.size() == 2 && vParts[0] == sKey) { + if(eType == Json::ValueType::stringValue) { + jParent[sJsonKey] = MTS::Text::trim(vParts[1]); + } else if (eType == Json::ValueType::intValue || eType == Json::ValueType::uintValue) { + //TODO: + printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); + return false; + } else if(eType == Json::ValueType::realValue) { + //TODO: + printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); + return false; + } else if(eType == Json::ValueType::booleanValue) { + //TODO: + printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); + return false; + } else { + printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); + return false; + } + } else { + printWarning("%s| Unable to parse %s from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); + return false; + } + + return true; +} + +bool CellularRadio::getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier) { + // Telit Radios + // H.ab.zyx => 3 Main Components + // "H" = Hardware -> 15 = DE910 family, 18 = CE910 family, 12 = HE910 family + // "a" = Hardware version + // "b" = Software Major Version + // "z" = is the product type, i.e. DUAL or SC + // "y" = is the carrier variant + // "x" = is the firmware version + // Telit will do their best to keep the carrier variant as "0" for Sprint, "1" for Aeris, "2" for Verizon, and "3" for U.S. Cellular. + + const uint32_t CARRIER_INDEX = 1; //y in [zyx] + + bool bResult = false; + std::vector vParts = MTS::Text::split(sFirmware, '.'); + + if(vParts.size() == 3) { + //CDMA firmware version notation + if(vParts[0] == "15" || vParts[0] == "18") { + //DE910 or CE910 -> Good good + std::string sID = vParts[2]; + if(sID.size() == 3) { + char cId = sID[CARRIER_INDEX]; + + //Good good + if(cId == '0') { + sCarrier = VALUE_CARRIER_SPRINT; + bResult = true; + } else + if(cId == '1') { + sCarrier = VALUE_CARRIER_AERIS; + bResult = true; + } else + if(cId == '2') { + sCarrier = VALUE_CARRIER_VERIZON; + bResult = true; + } else + if(cId == '3') { + sCarrier = VALUE_CARRIER_USCELLULAR; + bResult = true; + } + } + } + } + + return bResult; +} + +bool CellularRadio::getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware) { + // Telit Radios + // H.ab.zyx => 3 Main Components + // "H" = Hardware -> 15 = DE910 family, 18 = CE910 family, 12 = HE910 family + // "a" = Hardware version + // "b" = Software Major Version + // "z" = is the product type, i.e. DUAL or SC + // "y" = is the carrier variant + // "x" = is the firmware version + // Telit will do their best to keep the carrier variant as "0" for Sprint, "1" for Aeris, and "2" for Verizon. + + const uint32_t HARDWARE_INDEX = 0; //a in [ab] + + bool bResult = false; + std::vector vParts = MTS::Text::split(sFirmware, '.'); + + if(vParts.size() == 3) { + //GSM Hardware Version + if(!(vParts[0] == "15" || vParts[0] == "18")) { + //Not DE910 or CE910 -> Good good + std::string sVersion = vParts[1]; + if(sVersion.size() == 2) { + sHardware = "1."; + sHardware += sVersion[HARDWARE_INDEX]; + bResult = true; + } + } + } + + return bResult; + +} + +const char *CellularRadio::RadioBandMap::getLTEBand(const int32_t channel) +{ + for (unsigned int ii = 0; ii < NUM_LTE_BANDS; ii++) + { + if (EULTRAband[ii].low <= channel && EULTRAband[ii].high >= channel) + { + return EULTRAband[ii].name; + } + } + return VALUE_UNKNOWN.c_str(); +} + +const char *CellularRadio::RadioBandMap::getCDMABand(const int channel) +{ + for (unsigned int ii = 0; ii < NUM_WCDMA_BANDS; ii++) + { + if (WCDMAband[ii].low <= channel && WCDMAband[ii].high >= channel) + { + return WCDMAband[ii].name; + } + } + return VALUE_UNKNOWN.c_str(); +} + +const char *CellularRadio::RadioBandMap::getGSMBand(const int channel) +{ + for (unsigned int ii = 0; ii < NUM_GSM_BANDS; ii++) + { + if (GSMband[ii].low <= channel && GSMband[ii].high >= channel) + { + return GSMband[ii].name; + } + } + return VALUE_UNKNOWN.c_str(); +} + +const char *CellularRadio::RadioBandMap::getRadioBandName() +{ + const char *band = CellularRadio::VALUE_UNKNOWN.c_str(); + + if (m_sRadioType == VALUE_TYPE_LTE) + { + band = getLTEBand(m_iChannel); + } + else if (m_sRadioType == VALUE_TYPE_CDMA) + { + band = getCDMABand(m_iChannel); + } + else if (m_sRadioType == VALUE_TYPE_GSM) + { + band = getGSMBand(m_iChannel); + } + + return band; +} + +const char *CellularRadio::RadioBandMap::getRadioBandName(const std::string &channel, const std::string &radioType) +{ + const char *band = VALUE_UNKNOWN.c_str(); + int32_t chan = strtol(channel.c_str(), NULL, 10); + if (radioType == VALUE_TYPE_LTE) + { + band = getLTEBand(chan); + } + else if (radioType == VALUE_TYPE_CDMA) + { + band = getCDMABand(chan); + } + else if (radioType == VALUE_TYPE_GSM) + { + band = getGSMBand(chan); + } + + return band; +} diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp index 65d0941..6ce240e 100644 --- a/src/MTS_IO_TelitRadio.cpp +++ b/src/MTS_IO_TelitRadio.cpp @@ -20,112 +20,20 @@ #include -#include - -#include -#include -#include #include +#include #include using namespace MTS::IO; -namespace { - typedef struct - { - const char *name; - int32_t low; - int32_t high; - } *pNameRangeMap, nameRangeMap; - - const unsigned int NUM_GSM_BANDS = 7; - const unsigned int NUM_WCDMA_BANDS = 6; - const unsigned int NUM_LTE_BANDS = 42; - - // http://niviuk.free.fr/gsm_band.php - const nameRangeMap GSMband[] = - { - {"GSM 450", 259, 293}, {"GSM 480", 306, 340}, - {"GSM 750", 438, 511}, {"GSM 850", 128, 251}, - {"GSM 900 P", 1, 124}, {"GSM 900 E/R", 955, 1023}, - {"GSM DCS 1800/1900", 512, 885}, - - }; - - // http://niviuk.free.fr/umts_band.php - const nameRangeMap WCDMAband[] = - { - {"BAND I", 10592, 10838}, {"BAND II", 9662, 9938}, - {"BAND III", 1162, 1513}, {"BAND IV", 1537, 1738}, - {"BAND V", 4357, 4458}, {"BAND VI", 4387, 4413} - }; - - // http://niviuk.free.fr/lte_band.php - const nameRangeMap EULTRAband[] = - { - {"EUTRAN BAND1", 0, 599}, {"EUTRAN BAND2", 600, 1199}, - {"EUTRAN BAND3", 1200, 1949}, {"EUTRAN BAND4", 1950, 2399}, - {"EUTRAN BAND5", 2400, 2649}, {"EUTRAN BAND6", 2650, 2749}, - {"EUTRAN BAND7", 2750, 3449}, {"EUTRAN BAND8", 3450, 3799}, - {"EUTRAN BAND9", 3800, 4149}, {"EUTRAN BAND10", 4150, 4749}, - {"EUTRAN BAND11", 4750, 4999}, {"EUTRAN BAND12", 5000, 5179}, - {"EUTRAN BAND13", 5180, 5279}, {"EUTRAN BAND14", 5280, 5379}, - {"EUTRAN BAND17", 5730, 5849}, {"EUTRAN BAND18", 5850, 5999}, - {"EUTRAN BAND19", 6000, 6149}, {"EUTRAN BAND20", 6150, 6449}, - {"EUTRAN BAND21", 6450, 6525}, {"EUTRAN BAND22", 6600, 7399}, - {"EUTRAN BAND23", 7500, 7699}, {"EUTRAN BAND24", 7700, 8039}, - {"EUTRAN BAND25", 8040, 8689}, {"EUTRAN BAND26", 8690, 9039}, - {"EUTRAN BAND27", 9040, 9209}, {"EUTRAN BAND28", 9210, 9659}, - {"EUTRAN BAND29", 9660, 9769}, {"EUTRAN BAND30", 9770, 9869}, - {"EUTRAN BAND31", 9870, 9919}, {"EUTRAN BAND32", 9920, 10359}, - {"EUTRAN BAND33", 36000, 36199}, {"EUTRAN BAND34", 36200, 36349}, - {"EUTRAN BAND35", 36350, 36949}, {"EUTRAN BAND36", 36950, 37549}, - {"EUTRAN BAND37", 37550, 37749}, {"EUTRAN BAND38", 37750, 38249}, - {"EUTRAN BAND39", 38250, 38649}, {"EUTRAN BAND40", 38650, 39649}, - {"EUTRAN BAND41", 39650, 41589}, {"EUTRAN BAND42", 41590, 43589}, - {"EUTRAN BAND43", 43590, 45589}, {"EUTRAN BAND44", 45590, 46589} - }; -} - TelitRadio::TelitRadio(const std::string& sName, const std::string& sRadioPort) -: m_sName(sName) -, m_sRadioPort(sRadioPort) -, m_bEchoEnabled(false) -, m_bEnableEchoOnClose(false) +: CellularRadio(sName, sRadioPort) { - m_apIo.reset(new MTS::IO::SerialConnection( - MTS::IO::SerialConnection::Builder(m_sRadioPort) - .baudRate(115200) - .useLockFile() - .build())); -} - - -TelitRadio::~TelitRadio() { - shutdown(); - m_apIo.reset(); -} - -bool TelitRadio::initialize(uint32_t iTimeoutMillis) { - if(!m_apIo->open(iTimeoutMillis)) { - printError("%s| Failed to open radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str()); - return false; - } - - bool bEnabled; - CODE eCode = getEcho(bEnabled); - if(eCode == SUCCESS && bEnabled) { - printDebug("%s| Disabling 'echo'", m_sName.c_str()); - setEcho(false); - m_bEnableEchoOnClose = true; - } - - return true; } bool TelitRadio::resetRadio(uint32_t iTimeoutMillis) { - printInfo("%s| Rebooting radio", m_sName.c_str()); + printInfo("%s| Rebooting radio", getName().c_str()); if(sendBasicCommand("AT#REBOOT") == SUCCESS) { if(iTimeoutMillis > 5000) { MTS::Thread::sleep(5000); @@ -137,203 +45,41 @@ bool TelitRadio::resetRadio(uint32_t iTimeoutMillis) { return false; } -bool TelitRadio::resetConnection(uint32_t iTimeoutMillis) { - //Close Current Connection - if(!m_apIo.isNull()) { - m_apIo->close(); - } - - m_apIo.reset(new MTS::IO::SerialConnection( - MTS::IO::SerialConnection::Builder(m_sRadioPort) - .baudRate(115200) - .useLockFile() - .build())); - - //Try to obtain the device port over the given period of time - MTS::Timer oTimer; - oTimer.start(); - uint64_t iCurrentTime = 0; - while(iCurrentTime < iTimeoutMillis) { - - if(!m_apIo->open(iTimeoutMillis - iCurrentTime)) { - printWarning("%s| Failed to re-open radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str()); - } else { - printInfo("%s| Successfully re-opened radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str()); - printDebug("%s| Recovering 'echo' after connection reset", m_sName.c_str()); // see TelitRadio::initialize - setEcho(m_bEchoEnabled); - break; - } - - ::usleep(500000); //500 millis - iCurrentTime = oTimer.getMillis(); - } - oTimer.stop(); - return !m_apIo->isClosed(); -} - -void TelitRadio::shutdown() { - - if(!m_apIo.isNull()) { - if(m_bEnableEchoOnClose) { - printDebug("%s| Enabling 'echo'", m_sName.c_str()); - setEcho(true); - m_bEnableEchoOnClose = false; - } - m_apIo->close(); - } -} - -const std::string& TelitRadio::getName() const { - return m_sName; -} - -TelitRadio::CODE TelitRadio::getModel(std::string& sModel) { - printTrace("%s| Get Model", m_sName.c_str()); +CellularRadio::CODE TelitRadio::getModel(std::string& sModel) { + printTrace("%s| Get Model", getName().c_str()); //Always returns SUCCESS because the model should be m_sName - sModel = m_sName; + sModel = getName(); std::string sCmd("ATI4"); - std::string sResult = TelitRadio::sendCommand(m_apIo, sCmd); + std::string sResult = sendCommand(sCmd); if (sResult.find("OK") == std::string::npos) { - printWarning("%s| Unable to get model from radio. Returning [%s]", m_sName.c_str(), m_sName.c_str()); + printWarning("%s| Unable to get model from radio. Returning [%s]", getName().c_str(), getName().c_str()); return SUCCESS; } else { - sModel = TelitRadio::extractModelFromResult(sResult); + sModel = CellularRadio::extractModelFromResult(sResult); if(sModel.size() == 0) { - printWarning("%s| Unable to get model from radio. Returning [%s]", m_sName.c_str(), m_sName.c_str()); + printWarning("%s| Unable to get model from radio. Returning [%s]", getName().c_str(), getName().c_str()); return SUCCESS; } } - printDebug("%s| Extracted [%s] from [%s] query", m_sName.c_str(), sModel.c_str(), sCmd.c_str()); - if(sModel != m_sName) { + printDebug("%s| Extracted [%s] from [%s] query", getName().c_str(), sModel.c_str(), sCmd.c_str()); + if(sModel != getName()) { printWarning("%s| Model identified [%s] does not match expected [%s]. Returning [%s]", - m_sName.c_str(), sModel.c_str(), m_sName.c_str(), sModel.c_str()); - } - - return SUCCESS; -} - -TelitRadio::CODE TelitRadio::getFirmware(std::string& sFirmware) { - printTrace("%s| Get Firmware", m_sName.c_str()); - sFirmware = VALUE_NOT_SUPPORTED; - std::string sCmd("AT+CGMR"); - std::string sResult = TelitRadio::sendCommand(sCmd); - size_t pos = sResult.find(RSP_OK); - if (pos == std::string::npos) { - printWarning("%s| Unable to get firmware from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - sFirmware = MTS::Text::trim(sResult.substr(0, pos)); - if(sFirmware.size() == 0) { - printWarning("%s| Unable to get firmware from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - m_sFirmware = sFirmware; - - return SUCCESS; -} - -TelitRadio::CODE TelitRadio::getFirmwareBuild(std::string& sFirmwareBuild) { - sFirmwareBuild = VALUE_NOT_SUPPORTED; - return FAILURE; -} - -TelitRadio::CODE TelitRadio::getHardware(std::string& sHardware) { - printTrace("%s| Get Hardware", m_sName.c_str()); - sHardware = VALUE_NOT_SUPPORTED; - - if(m_sFirmware.size() == 0) { - getFirmware(m_sFirmware); - } - - if(getHardwareVersionFromFirmware(m_sFirmware, sHardware)) { - return SUCCESS; - } - return FAILURE; -} - -TelitRadio::CODE TelitRadio::getManufacturer(std::string& sManufacturer) { - printTrace("%s| Get Manufacturer", m_sName.c_str()); - sManufacturer = VALUE_NOT_SUPPORTED; - std::string sCmd("AT+GMI"); - std::string sResult = TelitRadio::sendCommand(sCmd); - size_t pos = sResult.find(RSP_OK); - if (pos == std::string::npos) { - printWarning("%s| Unable to get manufacturer from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - sManufacturer = MTS::Text::trim(sResult.substr(0, pos)); - if(sManufacturer.size() == 0) { - printWarning("%s| Unable to get manufacturer from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - return SUCCESS; -} - -TelitRadio::CODE TelitRadio::getImei(std::string& sImei) { - printTrace("%s| Get IMEI", m_sName.c_str()); - sImei = VALUE_NOT_SUPPORTED; - std::string sCmd("AT+CGSN"); - std::string sResult = TelitRadio::sendCommand(sCmd); - size_t pos = sResult.find(RSP_OK); - if (pos == std::string::npos) { - printWarning("%s| Unable to get IMEI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - sImei = MTS::Text::trim(sResult.substr(0, pos)); - if(sImei.size() == 0) { - printWarning("%s| Unable to get IMEI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - return SUCCESS; -} - -TelitRadio::CODE TelitRadio::getMeid(std::string& sMeid) { - printTrace("%s| Get MEID", m_sName.c_str()); - return getImei(sMeid); -} - -TelitRadio::CODE TelitRadio::getImsi(std::string& sImsi) { - printTrace("%s| Get IMSI", m_sName.c_str()); - sImsi = VALUE_NOT_SUPPORTED; - std::string sCmd("AT+CIMI"); - std::string sResult = TelitRadio::sendCommand(sCmd); - size_t pos = sResult.find(RSP_OK); - if (pos == std::string::npos) { - printWarning("%s| Unable to get IMSI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - sImsi = MTS::Text::trim(sResult.substr(0, pos)); - if(sImsi.size() == 0) { - printWarning("%s| Unable to get IMSI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; + getName().c_str(), sModel.c_str(), getName().c_str(), sModel.c_str()); } return SUCCESS; } -TelitRadio::CODE TelitRadio::getSimStatus(std::string& sSimStatus) { - printTrace("%s| Get SIM Status", getName().c_str()); - sSimStatus = VALUE_UNKNOWN; - return FAILURE; -} - -TelitRadio::CODE TelitRadio::getIccid(std::string& sIccid) { - printTrace("%s| Get ICCID", m_sName.c_str()); +CellularRadio::CODE TelitRadio::getIccid(std::string& sIccid) { + printTrace("%s| Get ICCID", getName().c_str()); sIccid = VALUE_NOT_SUPPORTED; std::string sCmd("AT#CCID"); - std::string sResult = TelitRadio::sendCommand(sCmd); + std::string sResult = CellularRadio::sendCommand(sCmd); size_t end = sResult.find(RSP_OK); if (end == std::string::npos) { - printWarning("%s| Unable to get ICCID from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + printWarning("%s| Unable to get ICCID from radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; } @@ -342,21 +88,21 @@ TelitRadio::CODE TelitRadio::getIccid(std::string& sIccid) { start += sizeof("#CCID:"); sIccid = MTS::Text::trim(sResult.substr(start, end-start)); if(sIccid.size() == 0) { - printWarning("%s| Unable to get ICCID from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + printWarning("%s| Unable to get ICCID from radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; } } return SUCCESS; } -TelitRadio::CODE TelitRadio::getService(std::string& sService) { - printTrace("%s| Get Service", m_sName.c_str()); +CellularRadio::CODE TelitRadio::getService(std::string& sService) { + printTrace("%s| Get Service", getName().c_str()); sService = VALUE_NOT_SUPPORTED; std::string sCmd("AT#PSNT?"); - std::string sResult = TelitRadio::sendCommand(sCmd); + std::string sResult = CellularRadio::sendCommand(sCmd); size_t end = sResult.find(RSP_OK); if (end == std::string::npos) { - printWarning("%s| Unable to get Service from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + printWarning("%s| Unable to get Service from radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; } @@ -376,335 +122,11 @@ TelitRadio::CODE TelitRadio::getService(std::string& sService) { default: sService = VALUE_UNKNOWN; break; } - printDebug("%s| Service ID: [%d][%s]", m_sName.c_str(), iService, sService.c_str()); - } - return SUCCESS; -} - -TelitRadio::CODE TelitRadio::getLac(std::string& sLac) { - Json::Value jData; - - printTrace("%s| Get LAC", m_sName.c_str()); - sLac = VALUE_NOT_SUPPORTED; - - if(getNetworkStatus(jData) == SUCCESS) { - if(jData.isMember(KEY_LAC)) { - sLac = jData[KEY_LAC].asString(); - return SUCCESS; - } - } - - return FAILURE; -} - -TelitRadio::CODE TelitRadio::getMdn(std::string& sMdn) { - printTrace("%s| Get MDN", m_sName.c_str()); - sMdn = VALUE_NOT_SUPPORTED; - std::string sCmd("AT+CNUM"); - std::string sResult = TelitRadio::sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); - if (end == std::string::npos) { - printWarning("%s| Unable to get MDN from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - size_t start = sResult.find("CNUM:"); - if(start != std::string::npos) { - start += sizeof("CNUM:"); - std::vector vParts = MTS::Text::split(sResult.substr(start, end - start), ','); - if(vParts.size() < 3) { - printWarning("%s| Unable to parse MDN from response [%s]", m_sName.c_str(), sResult.c_str()); - return FAILURE; - } - sMdn = MTS::Text::strip(vParts[1], '"'); - if(sMdn.size() == 0) { - printWarning("%s| Unable to get MDN from radio using command [%s]. MDN may not be set.", m_sName.c_str(), sCmd.c_str()); - } - } else { - sMdn = ""; - printWarning("%s| Unable to get MDN from radio using command [%s]. MDN may not be set.", m_sName.c_str(), sCmd.c_str()); - } - - return SUCCESS; -} - -TelitRadio::CODE TelitRadio::getMsid(std::string& sMsid) { - printTrace("%s| Get MSID", m_sName.c_str()); - sMsid = ""; - - std::string sImsi; - if(getImsi(sImsi) == SUCCESS) { - if(sImsi.size() >= 10) { - sMsid = sImsi.substr(sImsi.size() - 10); - printTrace("IMSI: [%s] MEID [%s]", sImsi.c_str(), sMsid.c_str()); - return SUCCESS; - } - } - printWarning("%s| Unable to get MSID from radio", m_sName.c_str()); - return FAILURE; -} - -TelitRadio::CODE TelitRadio::getType(std::string& sType) { - printTrace("%s| Get Type", m_sName.c_str()); - sType = VALUE_NOT_SUPPORTED; - return FAILURE; -} - -TelitRadio::CODE TelitRadio::getCarrier(std::string& sCarrier) { - printTrace("%s| Get Carrier", m_sName.c_str()); - if(m_sCarrier == "") { - Json::Value jData; - if(getNetworkStatus(jData) == SUCCESS) { - if(jData.isMember(KEY_MCC) && jData.isMember(KEY_MNC)) { - std::string sMcc = jData[KEY_MCC].asString(); - std::string sMnc = jData[KEY_MNC].asString(); - Json::Value jLookup = MccMncTable::getInstance()->lookup(sMcc, sMnc); - printTrace("%s| MCC-MNC Lookup: [%s][%s][%s]", m_sName.c_str(), - sMcc.c_str(), sMnc.c_str(), jLookup.toStyledString().c_str()); - if(jLookup.isMember(KEY_CARRIER)) { - m_sCarrier = jLookup[KEY_CARRIER].asString(); - } else { - printWarning("%s| MCC-MNC Lookup did not contain carrier", m_sName.c_str()); - return FAILURE; - } - } else { - printWarning("%s| Network Status did no contain MCC or MNC", m_sName.c_str()); - return FAILURE; - } - } else { - return FAILURE; - } - } - - sCarrier = m_sCarrier; - return SUCCESS; -} - -TelitRadio::CODE TelitRadio::getTower(std::string& sTower) { - Json::Value jData; - - printTrace("%s| Get Tower", m_sName.c_str()); - sTower = VALUE_NOT_SUPPORTED; - - if(getNetworkStatus(jData) == SUCCESS) { - if(jData.isMember(KEY_CID)) { - sTower = jData[KEY_CID].asString(); - return SUCCESS; - } - } - return FAILURE; -} - -TelitRadio::CODE TelitRadio::getTime(std::string& sDate, std::string& sTime, std::string& sTimeZone) { - Json::Value jData; - - printTrace("%s| Get Time", m_sName.c_str()); - sDate = ""; - sTime = ""; - sTimeZone = ""; - - std::string sCmd("AT+CCLK?"); - std::string sResult = TelitRadio::sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); - if (end == std::string::npos) { - printWarning("%s| Unable to get Time from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - return FAILURE; - } - - size_t start = sResult.find("CCLK: "); - if(start != std::string::npos) { - start += sizeof("CCLK: "); - std::string sValue = MTS::Text::trim(sResult.substr(start, end - start)); - sValue = MTS::Text::strip(sValue, '"'); - - std::vector vParts = MTS::Text::split(sValue, ','); - if(vParts.size() != 2) { - printWarning("%s| Unable to parse Date from response [%s]", m_sName.c_str(), sResult.c_str()); - return FAILURE; - } - - - std::vector vDateParts = MTS::Text::split(vParts[0], '/'); - if(vDateParts.size() != 3) { - printWarning("%s| Unable to parse Date from response [%s]", m_sName.c_str(), sResult.c_str()); - return FAILURE; - } - - //The Date format is YY/MM/DD -> Change to MM/DD/YY - sDate = vDateParts[1] + "/" + vDateParts[2] + "/" + vDateParts[0]; - - vParts = MTS::Text::split(vParts[1], '-'); - if(vParts.size() != 2) { - printWarning("%s| Unable to parse Time from response [%s]", m_sName.c_str(), sResult.c_str()); - return FAILURE; - } - sTime = vParts[0]; - - int32_t iZoneUnits; //the difference, expressed in quarters of an hour, between the local time and GMT - if(!MTS::Text::parse(iZoneUnits, MTS::Text::strip(vParts[1], '+'))) { - printWarning("%s| Unable to parse Time Zone from response [%s]", m_sName.c_str(), sResult.c_str()); - return FAILURE; - } - - int32_t iZone = iZoneUnits/4; //Divide by 4 to get hours difference - int32_t iZonePartial = (iZoneUnits % 4) * 15; //Remainder in minutes - std::string sPlusSign = "+"; - if(iZonePartial < 0) { - //Remove negative sign from partial and clear plus sign component - iZonePartial *= -1; - sPlusSign = ""; - } - std::stringstream ss; - ss << sPlusSign << iZone; - if(iZonePartial != 0) { - ss << ":" << iZonePartial; - } - - sTimeZone = ss.str(); - return SUCCESS; - - } else { - printWarning("%s| Unable to get Time from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); - } - - return FAILURE; -} - -TelitRadio::CODE TelitRadio::getRoaming(bool& bRoaming) { - Json::Value jData; - - printTrace("%s| Get Roaming", m_sName.c_str()); - bRoaming = false; - - REGISTRATION eReg; - if(getRegistration(eReg) == SUCCESS) { - bRoaming = (eReg == ROAMING); - return SUCCESS; - } - return FAILURE; -} - -TelitRadio::CODE TelitRadio::getNetwork(std::string& sNetwork) { - Json::Value jData; - - printTrace("%s| Get Network", m_sName.c_str()); - sNetwork = VALUE_NOT_SUPPORTED; - - if(getNetworkStatus(jData) == SUCCESS) { - if(jData.isMember(KEY_NETWORK)) { - sNetwork = jData[KEY_NETWORK].asString(); - return SUCCESS; - } - } - return FAILURE; -} - -TelitRadio::CODE TelitRadio::getSignalStrength(int32_t& rssi) { - printTrace("%s| Get Signal Strength", m_sName.c_str()); - std::string sCmd("AT+CSQ"); - std::string sResult = sendCommand(sCmd); - if (sResult.find("+CSQ: ") == std::string::npos) { - printDebug("%s| Signal Strength 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); - if(start == std::string::npos || stop == std::string::npos) { - printDebug("%s| Signal Strength command returned malformed response: [%s]", m_sName.c_str(), sResult.c_str()); - return FAILURE; + printDebug("%s| Service ID: [%d][%s]", getName().c_str(), iService, sService.c_str()); } - std::string signal = sResult.substr(start + 2, stop - start - 2); - - sscanf(signal.c_str(), "%d", &rssi); - printDebug("%s| Signal Strength: [%d]", m_sName.c_str(), rssi); - - return SUCCESS; -} - -TelitRadio::CODE TelitRadio::getModemLocation(std::string& sLocation) { - printTrace("%s|TelitRadio getModemLocation - not supported", m_sName.c_str()); - return FAILURE; -} - -TelitRadio::CODE TelitRadio::convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& iDbm) { - - //Telit Conversion - if(iRssi < 0 || iRssi == 99) { - return FAILURE; - } - - if(iRssi == 0) { - iDbm = -113; - } else if(iRssi == 1) { - iDbm = -111; - } else if(iRssi <= 30) { - //28 steps between 2 and 30 - //54 dbm between 53 and 109 - float stepSize = 54.0 / 28.0; - iDbm = -109 + (int)(stepSize * (iRssi-2)); - } else { - iDbm = -51; - } - return SUCCESS; } -TelitRadio::CODE TelitRadio::convertdBmToSignalStrength(const int32_t& iDBm, int32_t& iRssi) { - //Telit Conversion - if(iDBm <= -113) { - iRssi = 0; - } else if(iDBm <= -111) { - iRssi = 1; - } else if(iDBm <= -53) { - //54 dbm between -109 and -53 - //28 steps between 2 and 30 - float stepSize = 28.0/54.0; - iRssi = ((iDBm + 109)*stepSize) + 2; - } else { - iRssi = 31; - } - - return SUCCESS; -} - -TelitRadio::CODE TelitRadio::getEcho(bool& bEnabled) { - printTrace("%s| Echo Test", m_sName.c_str()); - std::string sResult = sendCommand("AT"); - if(sResult.size() == 0) { - return NO_RESPONSE; - } - - if(sResult.find("AT") != std::string::npos) { - bEnabled = true; - } else { - bEnabled = false; - } - m_bEchoEnabled = bEnabled; - return SUCCESS; -} - -TelitRadio::CODE TelitRadio::setEcho(bool bEnabled) { - CODE eCode = FAILURE; - if(bEnabled) { - eCode = sendBasicCommand("ATE1"); - m_bEchoEnabled = (eCode == SUCCESS ) ? true : m_bEchoEnabled; - } else { - eCode = sendBasicCommand("ATE0"); - m_bEchoEnabled = (eCode == SUCCESS ) ? false : m_bEchoEnabled; - } - - return eCode; -} - -TelitRadio::CODE TelitRadio::getStaticInformation(Json::Value& jData) { - printTrace("%s| Get Static Information", m_sName.c_str()); - - printTrace("%s| Static Information:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); - - return FAILURE; -} - /* AT#RFSTS - NETWORK STATUS (GSM network) @@ -780,14 +202,14 @@ TelitRadio::CODE TelitRadio::getStaticInformation(Json::Value& jData) { - - */ -TelitRadio::CODE TelitRadio::getNetworkStatus(Json::Value& jData) { +CellularRadio::CODE TelitRadio::getNetworkStatus(Json::Value& jData) { int32_t iValue; std::string sValue; const uint32_t GSM_NETWORK_FORMAT = 14; const uint32_t WCDMA_NETWORK_FORMAT = 19; const uint32_t LTE_NETWORK_FORMAT = 16; - printTrace("%s| Get Network Status", m_sName.c_str()); + printTrace("%s| Get Network Status", getName().c_str()); //Always get common network stats because this should never fail //This way the basic stats are always returned even if AT#RFSTS fails below @@ -799,17 +221,17 @@ TelitRadio::CODE TelitRadio::getNetworkStatus(Json::Value& jData) { // will cause the radio to stop responding until a radio power cycle // Telit Support Portal Case #5069697 // LE910C1-NS is an LE910, so we stop the scan after the 0. - if (m_sName.find("LE910") != std::string::npos) { + if (getName().find("LE910") != std::string::npos) { sCmd = "AT+CPIN?"; sResult = sendCommand(sCmd); if (sResult.find("+CPIN:") == std::string::npos) { - printDebug("%s| AT+CPIN? returned unexpected response: [%s][%s]", m_sName.c_str(), sCmd.c_str(), sResult.c_str()); - printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); + printDebug("%s| AT+CPIN? returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), sResult.c_str()); + printTrace("%s| Network Status:\n%s\n", getName().c_str(), jData.toStyledString().c_str()); return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function } if (sResult.find("SIM PIN") != std::string::npos) { - printError("%s| The SIM is locked and must first be unlocked", m_sName.c_str()); - printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); + printError("%s| The SIM is locked and must first be unlocked", getName().c_str()); + printTrace("%s| Network Status:\n%s\n", getName().c_str(), jData.toStyledString().c_str()); return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function } } @@ -818,8 +240,8 @@ TelitRadio::CODE TelitRadio::getNetworkStatus(Json::Value& jData) { sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 200); if (sResult.find("#RFSTS:") == std::string::npos) { //On LTE radios without signal, this case will run because AT#RFSTS just returns "OK" - printDebug("%s| Network Status command returned unexpected response: [%s][%s]", m_sName.c_str(), sCmd.c_str(), sResult.c_str()); - printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); + printDebug("%s| Network Status command returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), sResult.c_str()); + printTrace("%s| Network Status:\n%s\n", getName().c_str(), jData.toStyledString().c_str()); return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function } @@ -827,8 +249,8 @@ TelitRadio::CODE TelitRadio::getNetworkStatus(Json::Value& jData) { std::vector vParts = MTS::Text::split(MTS::Text::trim(sResult.substr(start)), ","); if (vParts.size() < 3) { - printDebug("%s| Network Status command reponse is an unknown format: [%s][%s]", m_sName.c_str(), sCmd.c_str(), sResult.c_str()); - printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); + printDebug("%s| Network Status command reponse is an unknown format: [%s][%s]", getName().c_str(), sCmd.c_str(), sResult.c_str()); + printTrace("%s| Network Status:\n%s\n", getName().c_str(), jData.toStyledString().c_str()); return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function } else { //Country Code and Operator Code @@ -861,7 +283,7 @@ TelitRadio::CODE TelitRadio::getNetworkStatus(Json::Value& jData) { } // IN003567 ME910C1 radios have some odd behavior with regards to WCDMA. The ordering of the fields from #RFSTS are // the same as LTE up to the 16th field (for ME901C1-WW anyway). Drop into LTE parsing for ME910C1-WW. - } else if((vParts.size() >= WCDMA_NETWORK_FORMAT) && (m_sName.find("ME910C1-WW") == std::string::npos)) { + } else if((vParts.size() >= WCDMA_NETWORK_FORMAT) && (getName().find("ME910C1-WW") == std::string::npos)) { Json::Value jDebug; //Parse as WCDMA Network Format @@ -891,7 +313,7 @@ TelitRadio::CODE TelitRadio::getNetworkStatus(Json::Value& jData) { jData[KEY_NETWORK] = MTS::Text::strip(vParts[16], '"'); // Get the radio band given the channel (UARFCN) - RadioBandMap radioBandMap(vParts[1], TelitRadio::VALUE_TYPE_CDMA); + RadioBandMap radioBandMap(vParts[1], CellularRadio::VALUE_TYPE_CDMA); jData[KEY_ABND] = radioBandMap.getRadioBandName(); if(MTS::Text::parse(iValue, vParts[17]) && convertServiceDomainToString((SERVICEDOMAIN)iValue, sValue) == SUCCESS) { @@ -943,7 +365,7 @@ TelitRadio::CODE TelitRadio::getNetworkStatus(Json::Value& jData) { jData[KEY_NETWORK] = MTS::Text::strip(vParts[12], '"'); // Get the radio band given the channel (EARFCN) - RadioBandMap radioBandMap(vParts[1], TelitRadio::VALUE_TYPE_LTE); + RadioBandMap radioBandMap(vParts[1], CellularRadio::VALUE_TYPE_LTE); jData[KEY_ABND] = radioBandMap.getRadioBandName(); jData[KEY_LAC] = queryLteLac(); @@ -955,10 +377,11 @@ TelitRadio::CODE TelitRadio::getNetworkStatus(Json::Value& jData) { jData[KEY_DEBUG] = jDebug; } - printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); + printTrace("%s| Network Status:\n%s\n", getName().c_str(), jData.toStyledString().c_str()); return SUCCESS; } + // Get the LAC for the LTE radio that's not in the #RFSTS response std::string TelitRadio::queryLteLac() { std::string CGREGstring; @@ -977,12 +400,12 @@ std::string TelitRadio::queryLteLac() { CGREGstring = queryCGREGstring(); if (CGREGstring == RSP_ERROR) { - result = TelitRadio::VALUE_UNKNOWN; + 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)), ","); if(vParts.size() < 3) { - result = TelitRadio::VALUE_UNAVAILABLE; + result = CellularRadio::VALUE_UNAVAILABLE; } else { result = MTS::Text::strip(vParts[2], '"'); } @@ -997,7 +420,7 @@ void TelitRadio::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()); + printDebug("%s| AT#CGREG=%s returned unexpected response: [%s][%s]", getName().c_str(), value.c_str(), sCmd.c_str(), cmdResult.c_str()); } } @@ -1005,116 +428,14 @@ std::string TelitRadio::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()); + printDebug("%s| AT#CGREG? returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), cmdResult.c_str()); return RSP_ERROR; } return cmdResult; } -void TelitRadio::getCommonNetworkStats(Json::Value& jData) { - - bool bRoaming = false; - if(getRoaming(bRoaming) == SUCCESS) { - jData[KEY_ROAMING] = bRoaming; - } - - int32_t iRssi; - if(getSignalStrength(iRssi) == SUCCESS) { - jData[KEY_RSSI] = iRssi; - int32_t dBm; - if(!jData.isMember(KEY_RSSIDBM) && convertSignalStrengthTodBm(iRssi, dBm) == SUCCESS) { - //Add RSSI in dBm format - jData[KEY_RSSIDBM] = MTS::Text::format(dBm); - } - } - - std::string sService; - if(getService(sService) == SUCCESS) { - jData[KEY_SERVICE] = sService; - } - std::string sDate, sTime, sTimeZone; - if(getTime(sDate, sTime, sTimeZone) == SUCCESS) { - jData[KEY_DATETIME] = sDate + " " + sTime + " GMT" + sTimeZone; - } - - std::string sNetworkReg; - TelitRadio::REGISTRATION eReg; - if (getRegistration(eReg) == SUCCESS) { - if (convertRegistrationToString(eReg, sNetworkReg) == SUCCESS) { - jData[TelitRadio::KEY_NETWORK_REG] = sNetworkReg; - } - } -} - -void TelitRadio::initMipProfile(Json::Value& jData) { - jData[KEY_MIP_ID] = 0; - jData[KEY_MIP_ENABLED] = false; - jData[KEY_MIP_NAI] = VALUE_UNKNOWN; - jData[KEY_MIP_HOMEADDRESS] = VALUE_UNKNOWN; - jData[KEY_MIP_PRIMARYHA] = VALUE_UNKNOWN; - jData[KEY_MIP_SECONDARYHA] = VALUE_UNKNOWN; - jData[KEY_MIP_MNAAASPI] = VALUE_UNKNOWN; - jData[KEY_MIP_MNHASPI] = VALUE_UNKNOWN; - jData[KEY_MIP_MNAAASS] = false; - jData[KEY_MIP_MNHASS] = false; -} - -TelitRadio::CODE TelitRadio::getRegistration(REGISTRATION& eRegistration) { - std::string sCmd; - std::string sResp; - - // LE910C1-NS is an LE910, so we stop the scan after the 0. - if (m_sName.find("LE910") != std::string::npos) { - // use AT+CGREG instead for LE910 models - sCmd = "AT+CGREG?"; - sResp = "+CGREG: "; - } - else { - 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: [%s]", 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; - return SUCCESS; -} - -TelitRadio::CODE TelitRadio::convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration) { - - CODE eCode = FAILURE; - switch (eRegistration) { - case NOT_REGISTERED: sRegistration = VALUE_NOT_REGISTERED; eCode = SUCCESS; break; - case REGISTERED: sRegistration = VALUE_REGISTERED; eCode = SUCCESS; break; - case SEARCHING: sRegistration = VALUE_SEARCHING; eCode = SUCCESS; break; - case DENIED: sRegistration = VALUE_DENIED; eCode = SUCCESS; break; - case UNKNOWN: sRegistration = VALUE_UNKNOWN; eCode = SUCCESS; break; - case ROAMING: sRegistration = VALUE_ROAMING; eCode = SUCCESS; break; - } - return eCode; -} - -TelitRadio::CODE TelitRadio::validateMsl(const Json::Value& jArgs) { - printTrace("%s| Validate MSL", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::setMdn(const Json::Value& jArgs) { - printTrace("%s| Set MDN", m_sName.c_str()); +CellularRadio::CODE TelitRadio::setMdn(const Json::Value& jArgs) { + printTrace("%s| Set MDN", getName().c_str()); if(!jArgs["mdn"].isString()) { return INVALID_ARGS; @@ -1126,336 +447,13 @@ TelitRadio::CODE TelitRadio::setMdn(const Json::Value& jArgs) { std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 1000); size_t end = sResult.find(RSP_OK); if (end == std::string::npos) { - printWarning("%s| Unable to set MDN for radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + printWarning("%s| Unable to set MDN for radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; } return SUCCESS; } -TelitRadio::CODE TelitRadio::setMsid(const Json::Value& jArgs) { - printTrace("%s| Set MSID", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::getMipProfile(Json::Value& jMipProfile) { - printTrace("%s| Get MIP Active Profile", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::setMipActiveProfile(const Json::Value& jArgs) { - printTrace("%s| Set MIP Active Profile", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::setMipNai(const Json::Value& jArgs) { - printTrace("%s| Set MIP NAI", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::setMipHomeIp(const Json::Value& jArgs) { - printTrace("%s| Set MIP Home IP", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::setMipPrimaryHa(const Json::Value& jArgs) { - printTrace("%s| Set MIP Primary HA", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::setMipSecondaryHa(const Json::Value& jArgs) { - printTrace("%s| Set MIP Secondary HA", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::setMipMnAaaSpi(const Json::Value& jArgs) { - printTrace("%s| Set MIP MN-AAA SPI", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::setMipMnHaSpi(const Json::Value& jArgs) { - printTrace("%s| Set MIP MN-HA SPI", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::setMipRevTun(const Json::Value& jArgs) { - printTrace("%s| Set MIP Rev Tun", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::setMipMnAaaSs(const Json::Value& jArgs) { - printTrace("%s| Set MIP MN-AAA SS", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::setMipMnHaSs(const Json::Value& jArgs) { - printTrace("%s| Set MIP MN-HA SS", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::updateDc(const Json::Value& jArgs, UpdateCb& stepCb) { - printTrace("%s| Update Device Configuration", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::updatePrl(const Json::Value& jArgs, UpdateCb& stepCb) { - printTrace("%s| Update Preferred Roaming List", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) { - printTrace("%s| Update Firmware Update Management Object", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::resetHfa(const Json::Value& jArgs, UpdateCb& stepCb) { - printTrace("%s| HFA Reset", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::activate(const Json::Value& jArgs, UpdateCb& stepCb) { - printTrace("%s| Activation", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::setActiveFirmware(const Json::Value& jArgs) { - printTrace("%s| Set Active Firmware Image Number: not applicable", m_sName.c_str()); - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::getActiveFirmware(std::string& sFwId) { - printTrace("%s| Get Active Firmware Image Number: not applicable", m_sName.c_str()); - sFwId = VALUE_NOT_SUPPORTED; - - return NOT_APPLICABLE; -} - -TelitRadio::CODE TelitRadio::sendBasicCommand(const std::string& sCmd, int32_t iTimeoutMillis, const char& ESC) { - std::string response = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, iTimeoutMillis, ESC); - if (response.size() == 0) { - return NO_RESPONSE; - } else if (response.find(RSP_OK) != std::string::npos) { - return SUCCESS; - } else if (response.find(RSP_ERROR) != std::string::npos) { - return ERROR; - } else { - return FAILURE; - } -} - -std::string TelitRadio::sendCommand(const std::string& sCmd, const std::vector& vBail, int32_t timeoutMillis, const char& ESC) { - return sendCommand(m_apIo, sCmd, vBail, timeoutMillis, ESC); -} - -std::string TelitRadio::sendCommand(MTS::AutoPtr& apIo, const std::string& sCmd, - const std::vector& vBail, int32_t timeoutMillis, const char& ESC) { - IsNeedMoreData isNeedMoreData = [&vBail](const std::string& iterationData, const std::string& allData)->bool { - for(size_t i = 0; i < vBail.size(); i++) { - const std::string& sBail = vBail[i]; - if(sBail.size() > 0) { - if(allData.find(sBail) != std::string::npos) { - //Return when bail string is found - printTrace("RADIO| Found bail string [%s]", sBail.c_str()); - return false; - } - } - } - return true; - }; - - return sendCommand(apIo, sCmd, isNeedMoreData, timeoutMillis, ESC); -} - -std::string TelitRadio::sendCommand(const std::string& sCmd, MTS::IO::TelitRadio::IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis, const char& ESC) { - return sendCommand(m_apIo, sCmd, isNeedMoreData, timeoutMillis, ESC); -} - -std::string TelitRadio::sendCommand(MTS::AutoPtr& apIo, const std::string& sCmd, - IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis, const char& ESC) { - if(MTS::Logger::getPrintLevel() >= MTS::Logger::PrintLevel::TRACE_LEVEL) { - printTrace("RADIO| Sending command [%s]", sCmd.c_str()); - } - if(apIo.isNull()) { - printError("RADIO| IO is not set in sendCommand"); - return ""; - } - - int32_t iResult; - if(ESC == 0x00) { - iResult = apIo->write(sCmd.data(), sCmd.size()); - } else { - std::string sNewCmd(sCmd); - sNewCmd.push_back(ESC); - iResult = apIo->write(sNewCmd.data(), sNewCmd.size()); - } - - if(iResult == -1) { - printError("RADIO| Failed to send command to radio"); - return ""; - } - - bool done = false; - const uint32_t capacity = 1024; - char buffer[capacity]; - std::string sResult; - Timer timer; - timer.start(); - do { - int32_t iterationTimeout = 100; - int bytesRead = apIo->read((char*)buffer, capacity, iterationTimeout); - if(bytesRead == -1) { - printError("RADIO| Failed to read from radio"); - break; - } - - std::string sIteration((char*)buffer, bytesRead); - sResult += sIteration; - - if(isNeedMoreData && !isNeedMoreData(sIteration, sResult)) { - printTrace("RADIO| No more data needed"); - return sResult; - } - if(timeoutMillis >= 0) { - done = (timer.getMillis() >= (uint64_t)timeoutMillis); - } else { - //Do not stop looping until bail string is found - } - } while(!done); - - //Timed out - return sResult; -} - -TelitRadio::CODE TelitRadio::test(MTS::AutoPtr& apIo, uint32_t timeoutSeconds) { - printTrace("RADIO| Basic Test"); - uint32_t count = 0; - std::string sCmd("AT"); - do { - std::string sResult = sendCommand(apIo, sCmd); - if (sResult.find(RSP_OK) == std::string::npos) { - printTrace("RADIO| Waiting for basic radio communication [%s] ...", sResult.c_str()); - } else { - break; - } - count++; - } while (count < timeoutSeconds); - - if(count == timeoutSeconds) { - printWarning("RADIO| Basic radio communication FAILED"); - return NO_RESPONSE; - } - return SUCCESS; -} - -std::string TelitRadio::extractModelFromResult(const std::string& sResult) { - std::string sModel(TelitRadio::VALUE_NOT_SUPPORTED); - - if(sResult.find("HE910-D") != std::string::npos) { - sModel = "HE910-D"; - } else if(sResult.find("HE910-EUD") != std::string::npos) { - sModel = "HE910-EUD"; - } else if(sResult.find("LE910-JN1") != std::string::npos) { - sModel = "LE910-JN1"; - } else if(sResult.find("LE866A1-JS") != std::string::npos) { - sModel = "LE866A1-JS"; - } else if(sResult.find("LE910-NAG") != std::string::npos) { - sModel = "LE910-NAG"; - } else if(sResult.find("LE910C4-NF") != std::string::npos) { - sModel = "LE910C4-NF"; - } else if(sResult.find("LE910-NA1") != std::string::npos) { - sModel = "LE910-NA1"; - } else if(sResult.find("ME910C1-NA") != std::string::npos) { - sModel = "ME910C1-NA"; - } else if(sResult.find("ME910C1-NV") != std::string::npos) { - sModel = "ME910C1-NV"; - } else if(sResult.find("ME910C1-WW") != std::string::npos) { - sModel = "ME910C1-WW"; - } else if(sResult.find("LE910-SVG") != std::string::npos) { - sModel = "LE910-SVG"; - } else if(sResult.find("LE910-EUG") != std::string::npos) { - sModel = "LE910-EUG"; - } else if(sResult.find("LE910C4-EU") != std::string::npos) { - sModel = "LE910C4-EU"; - } else if(sResult.find("LE910-EU1") != std::string::npos) { - sModel = "LE910-EU1"; - } else if(sResult.find("LE910C1-NS") != std::string::npos) { - sModel = "LE910C1-NS"; - } else if(sResult.find("LE910C1-AP") != std::string::npos) { - sModel = "LE910C1-AP"; - } else if(sResult.find("GE910") != std::string::npos) { - sModel = "GE910"; - } else if(sResult.find("DE910-DUAL") != std::string::npos) { - sModel = "DE910-DUAL"; - } else if(sResult.find("CE910") != std::string::npos) { - sModel = "CE910"; - } - return sModel; -} - -std::string TelitRadio::getCodeAsString(CODE eCode) { - switch(eCode) { - case SUCCESS: - return "SUCCESS"; - case ERROR: - return "ERROR"; - case FAILURE: - return "FAILURE"; - case NO_RESPONSE: - return "NO RESPONSE"; - default: - return "UNKNOWN"; - } -} - -bool TelitRadio::splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType) { - - std::vector vParts = MTS::Text::split(sLine, ":", 2); - - if(vParts.size() == 2 && vParts[0] == sKey) { - if(eType == Json::ValueType::stringValue) { - jParent[sJsonKey] = MTS::Text::trim(vParts[1]); - } else if (eType == Json::ValueType::intValue || eType == Json::ValueType::uintValue) { - //TODO: - printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); - return false; - } else if(eType == Json::ValueType::realValue) { - //TODO: - printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); - return false; - } else if(eType == Json::ValueType::booleanValue) { - //TODO: - printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); - return false; - } else { - printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); - return false; - } - } else { - printWarning("%s| Unable to parse %s from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str()); - return false; - } - - return true; -} - bool TelitRadio::getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier) { // Telit Radios // H.ab.zyx => 3 Main Components @@ -1536,79 +534,3 @@ bool TelitRadio::getHardwareVersionFromFirmware(const std::string& sFirmware, st return bResult; } - -const char *TelitRadio::RadioBandMap::getLTEBand(const int32_t channel) -{ - for (unsigned int ii = 0; ii < NUM_LTE_BANDS; ii++) - { - if (EULTRAband[ii].low <= channel && EULTRAband[ii].high >= channel) - { - return EULTRAband[ii].name; - } - } - return VALUE_UNKNOWN.c_str(); -} - -const char *TelitRadio::RadioBandMap::getCDMABand(const int channel) -{ - for (unsigned int ii = 0; ii < NUM_WCDMA_BANDS; ii++) - { - if (WCDMAband[ii].low <= channel && WCDMAband[ii].high >= channel) - { - return WCDMAband[ii].name; - } - } - return VALUE_UNKNOWN.c_str(); -} - -const char *TelitRadio::RadioBandMap::getGSMBand(const int channel) -{ - for (unsigned int ii = 0; ii < NUM_GSM_BANDS; ii++) - { - if (GSMband[ii].low <= channel && GSMband[ii].high >= channel) - { - return GSMband[ii].name; - } - } - return VALUE_UNKNOWN.c_str(); -} - -const char *TelitRadio::RadioBandMap::getRadioBandName() -{ - const char *band = TelitRadio::VALUE_UNKNOWN.c_str(); - - if (m_sRadioType == TelitRadio::VALUE_TYPE_LTE) - { - band = getLTEBand(m_iChannel); - } - else if (m_sRadioType == TelitRadio::VALUE_TYPE_CDMA) - { - band = getCDMABand(m_iChannel); - } - else if (m_sRadioType == TelitRadio::VALUE_TYPE_GSM) - { - band = getGSMBand(m_iChannel); - } - - return band; -} - -const char *TelitRadio::RadioBandMap::getRadioBandName(const std::string &channel, const std::string &radioType) -{ - const char *band = TelitRadio::VALUE_UNKNOWN.c_str(); - int32_t chan = strtol(channel.c_str(), NULL, 10); - if (radioType == TelitRadio::VALUE_TYPE_LTE) - { - band = getLTEBand(chan); - } - else if (radioType == TelitRadio::VALUE_TYPE_CDMA) - { - band = getCDMABand(chan); - } - else if (radioType == TelitRadio::VALUE_TYPE_GSM) - { - band = getGSMBand(chan); - } - - return band; -} -- cgit v1.2.3 From 5a7d8772ea898b3567685431b5a6be13015e5887 Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Mon, 10 Jun 2019 11:27:27 +0300 Subject: [MTS-MTQ] refactoring: static function moved to ICellularRadio --- include/mts/MTS_IO_CellularRadio.h | 15 ---- include/mts/MTS_IO_ICellularRadio.h | 17 ++++ src/MTS_IO_CellularRadio.cpp | 160 +---------------------------------- src/MTS_IO_CellularRadioFactory.cpp | 2 +- src/MTS_IO_ICellularRadio.cpp | 164 +++++++++++++++++++++++++++++++++++- 5 files changed, 182 insertions(+), 176 deletions(-) diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index e79e6d1..0410e0d 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -109,27 +109,12 @@ namespace MTS { const char& ESC = CR) override; - static std::string sendCommand(MTS::AutoPtr& apIo, - const std::string& sCmd, - const std::vector& vBail = DEFAULT_BAIL_STRINGS, - int32_t timeoutMillis = 100, - const char& ESC = CR); std::string sendCommand(const std::string& sCmd, IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis = 100, const char& ESC = CR) override; - static std::string sendCommand(MTS::AutoPtr& apIo, - const std::string& sCmd, - IsNeedMoreData& isNeedMoreData, - int32_t timeoutMillis = 100, - const char& ESC = CR); - - static CODE test(MTS::AutoPtr& apIo, uint32_t timeoutSeconds = 30); - - static std::string extractModelFromResult(const std::string& sResult); - static std::string getCodeAsString(CODE code); protected: diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h index ff8383c..3ab8b7e 100644 --- a/include/mts/MTS_IO_ICellularRadio.h +++ b/include/mts/MTS_IO_ICellularRadio.h @@ -7,6 +7,9 @@ #include +#include +#include + #define EXPORT __attribute__((visibility("default"))) namespace MTS { @@ -62,6 +65,20 @@ namespace MTS { static CODE convertModelToMtsShortCode(const std::string& sModel, std::string& sCode, ICellularRadio *radioObj = NULL); static CODE convertServiceDomainToString(SERVICEDOMAIN eSd, std::string& sSd); static CODE convertActiveBandToString(ACTIVEBAND eBand, std::string& sBand); + + static std::string sendCommand(MTS::AutoPtr& apIo, + const std::string& sCmd, + IsNeedMoreData& isNeedMoreData, + int32_t timeoutMillis = 100, + const char& ESC = CR); + static std::string sendCommand(MTS::AutoPtr& apIo, + const std::string& sCmd, + const std::vector& vBail = DEFAULT_BAIL_STRINGS, + int32_t timeoutMillis = 100, + const char& ESC = CR); + static CODE test(MTS::AutoPtr& apIo, uint32_t timeoutSeconds = 30); + static std::string extractModelFromResult(const std::string& sResult); + static std::string getCodeAsString(CODE code); // XXX static const std::string DEFAULT_RADIO_PORT; diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index 840132f..f106b4c 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -968,167 +968,11 @@ CellularRadio::CODE CellularRadio::sendBasicCommand(const std::string& sCmd, int } std::string CellularRadio::sendCommand(const std::string& sCmd, const std::vector& vBail, int32_t timeoutMillis, const char& ESC) { - return sendCommand(m_apIo, sCmd, vBail, timeoutMillis, ESC); -} - -std::string CellularRadio::sendCommand(MTS::AutoPtr& apIo, const std::string& sCmd, - const std::vector& vBail, int32_t timeoutMillis, const char& ESC) { - IsNeedMoreData isNeedMoreData = [&vBail](const std::string&, const std::string& allData)->bool { - for(size_t i = 0; i < vBail.size(); i++) { - const std::string& sBail = vBail[i]; - if(sBail.size() > 0) { - if(allData.find(sBail) != std::string::npos) { - //Return when bail string is found - printTrace("RADIO| Found bail string [%s]", sBail.c_str()); - return false; - } - } - } - return true; - }; - - return sendCommand(apIo, sCmd, isNeedMoreData, timeoutMillis, ESC); + return ICellularRadio::sendCommand(m_apIo, sCmd, vBail, timeoutMillis, ESC); } std::string CellularRadio::sendCommand(const std::string& sCmd, MTS::IO::CellularRadio::IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis, const char& ESC) { - return sendCommand(m_apIo, sCmd, isNeedMoreData, timeoutMillis, ESC); -} - -std::string CellularRadio::sendCommand(MTS::AutoPtr& apIo, const std::string& sCmd, - IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis, const char& ESC) { - if(MTS::Logger::getPrintLevel() >= MTS::Logger::PrintLevel::TRACE_LEVEL) { - printTrace("RADIO| Sending command [%s]", sCmd.c_str()); - } - if(apIo.isNull()) { - printError("RADIO| IO is not set in sendCommand"); - return ""; - } - - int32_t iResult; - if(ESC == 0x00) { - iResult = apIo->write(sCmd.data(), sCmd.size()); - } else { - std::string sNewCmd(sCmd); - sNewCmd.push_back(ESC); - iResult = apIo->write(sNewCmd.data(), sNewCmd.size()); - } - - if(iResult == -1) { - printError("RADIO| Failed to send command to radio"); - return ""; - } - - bool done = false; - const uint32_t capacity = 1024; - char buffer[capacity]; - std::string sResult; - Timer timer; - timer.start(); - do { - int32_t iterationTimeout = 100; - int bytesRead = apIo->read((char*)buffer, capacity, iterationTimeout); - if(bytesRead == -1) { - printError("RADIO| Failed to read from radio"); - break; - } - - std::string sIteration((char*)buffer, bytesRead); - sResult += sIteration; - - if(isNeedMoreData && !isNeedMoreData(sIteration, sResult)) { - printTrace("RADIO| No more data needed"); - return sResult; - } - if(timeoutMillis >= 0) { - done = (timer.getMillis() >= (uint64_t)timeoutMillis); - } else { - //Do not stop looping until bail string is found - } - } while(!done); - - //Timed out - return sResult; -} - -CellularRadio::CODE CellularRadio::test(MTS::AutoPtr& apIo, uint32_t timeoutSeconds) { - printTrace("RADIO| Basic Test"); - uint32_t count = 0; - std::string sCmd("AT"); - do { - std::string sResult = sendCommand(apIo, sCmd); - if (sResult.find(RSP_OK) == std::string::npos) { - printTrace("RADIO| Waiting for basic radio communication [%s] ...", sResult.c_str()); - } else { - break; - } - count++; - } while (count < timeoutSeconds); - - if(count == timeoutSeconds) { - printWarning("RADIO| Basic radio communication FAILED"); - return NO_RESPONSE; - } - return SUCCESS; -} - -std::string CellularRadio::extractModelFromResult(const std::string& sResult) { - std::string sModel(VALUE_NOT_SUPPORTED); - - if(sResult.find("HE910-D") != std::string::npos) { - sModel = "HE910-D"; - } else if(sResult.find("HE910-EUD") != std::string::npos) { - sModel = "HE910-EUD"; - } else if(sResult.find("LE910-JN1") != std::string::npos) { - sModel = "LE910-JN1"; - } else if(sResult.find("LE866A1-JS") != std::string::npos) { - sModel = "LE866A1-JS"; - } else if(sResult.find("LE910-NAG") != std::string::npos) { - sModel = "LE910-NAG"; - } else if(sResult.find("LE910C4-NF") != std::string::npos) { - sModel = "LE910C4-NF"; - } else if(sResult.find("LE910-NA1") != std::string::npos) { - sModel = "LE910-NA1"; - } else if(sResult.find("ME910C1-NA") != std::string::npos) { - sModel = "ME910C1-NA"; - } else if(sResult.find("ME910C1-NV") != std::string::npos) { - sModel = "ME910C1-NV"; - } else if(sResult.find("ME910C1-WW") != std::string::npos) { - sModel = "ME910C1-WW"; - } else if(sResult.find("LE910-SVG") != std::string::npos) { - sModel = "LE910-SVG"; - } else if(sResult.find("LE910-EUG") != std::string::npos) { - sModel = "LE910-EUG"; - } else if(sResult.find("LE910C4-EU") != std::string::npos) { - sModel = "LE910C4-EU"; - } else if(sResult.find("LE910-EU1") != std::string::npos) { - sModel = "LE910-EU1"; - } else if(sResult.find("LE910C1-NS") != std::string::npos) { - sModel = "LE910C1-NS"; - } else if(sResult.find("LE910C1-AP") != std::string::npos) { - sModel = "LE910C1-AP"; - } else if(sResult.find("GE910") != std::string::npos) { - sModel = "GE910"; - } else if(sResult.find("DE910-DUAL") != std::string::npos) { - sModel = "DE910-DUAL"; - } else if(sResult.find("CE910") != std::string::npos) { - sModel = "CE910"; - } - return sModel; -} - -std::string CellularRadio::getCodeAsString(CODE eCode) { - switch(eCode) { - case SUCCESS: - return "SUCCESS"; - case ERROR: - return "ERROR"; - case FAILURE: - return "FAILURE"; - case NO_RESPONSE: - return "NO RESPONSE"; - default: - return "UNKNOWN"; - } + return ICellularRadio::sendCommand(m_apIo, sCmd, isNeedMoreData, timeoutMillis, ESC); } bool CellularRadio::splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType) { diff --git a/src/MTS_IO_CellularRadioFactory.cpp b/src/MTS_IO_CellularRadioFactory.cpp index 130d3ed..0c64221 100644 --- a/src/MTS_IO_CellularRadioFactory.cpp +++ b/src/MTS_IO_CellularRadioFactory.cpp @@ -102,7 +102,7 @@ std::string CellularRadioFactory::identifyRadio(const std::string& sPort) { std::string sCmd("ATI4"); std::string sResult; do { - sResult = TelitRadio::sendCommand(apIo, sCmd, TelitRadio::DEFAULT_BAIL_STRINGS, 1000, TelitRadio::CR); + sResult = ICellularRadio::sendCommand(apIo, sCmd, TelitRadio::DEFAULT_BAIL_STRINGS, 1000, TelitRadio::CR); if (sResult.find("OK") == std::string::npos) { printDebug("RADIO| Attempting to get radio model [%s] ...", sResult.c_str()); } else { diff --git a/src/MTS_IO_ICellularRadio.cpp b/src/MTS_IO_ICellularRadio.cpp index 343480a..e206a59 100644 --- a/src/MTS_IO_ICellularRadio.cpp +++ b/src/MTS_IO_ICellularRadio.cpp @@ -1,5 +1,8 @@ #include "mts/MTS_IO_ICellularRadio.h" +#include +#include + const char MTS::IO::ICellularRadio::ETX = 0x03; //Ends socket connection const char MTS::IO::ICellularRadio::DLE = 0x10; //Escapes ETX and DLE within Payload const char MTS::IO::ICellularRadio::CR = 0x0D; @@ -180,7 +183,7 @@ MTS::IO::ICellularRadio::CODE MTS::IO::ICellularRadio::convertModelToMtsShortCod eCode = SUCCESS; } else { sCode = VALUE_NOT_SUPPORTED; - //printError("RADIO| Could not identify MTS short code from model. [%s]", sModel.c_str()); + printError("RADIO| Could not identify MTS short code from model. [%s]", sModel.c_str()); eCode = ERROR; } return eCode; @@ -274,7 +277,164 @@ MTS::IO::ICellularRadio::CODE MTS::IO::ICellularRadio::convertModelToType(const } else { sType = VALUE_TYPE_GSM; eCode = ERROR; - //printError("RADIO| Could not identify type from model. [%s]. Assuming [%s]", sModel.c_str(), sType.c_str()); + printError("RADIO| Could not identify type from model. [%s]. Assuming [%s]", sModel.c_str(), sType.c_str()); } return eCode; } + +std::string MTS::IO::ICellularRadio::sendCommand(MTS::AutoPtr& apIo, const std::string& sCmd, + const std::vector& vBail, int32_t timeoutMillis, const char& ESC) { + IsNeedMoreData isNeedMoreData = [&vBail](const std::string&, const std::string& allData)->bool { + for(size_t i = 0; i < vBail.size(); i++) { + const std::string& sBail = vBail[i]; + if(sBail.size() > 0) { + if(allData.find(sBail) != std::string::npos) { + //Return when bail string is found + printTrace("RADIO| Found bail string [%s]", sBail.c_str()); + return false; + } + } + } + return true; + }; + + return sendCommand(apIo, sCmd, isNeedMoreData, timeoutMillis, ESC); +} + +std::string MTS::IO::ICellularRadio::sendCommand(MTS::AutoPtr& apIo, const std::string& sCmd, + IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis, const char& ESC) { + if(MTS::Logger::getPrintLevel() >= MTS::Logger::PrintLevel::TRACE_LEVEL) { + printTrace("RADIO| Sending command [%s]", sCmd.c_str()); + } + if(apIo.isNull()) { + printError("RADIO| IO is not set in sendCommand"); + return ""; + } + + int32_t iResult; + if(ESC == 0x00) { + iResult = apIo->write(sCmd.data(), sCmd.size()); + } else { + std::string sNewCmd(sCmd); + sNewCmd.push_back(ESC); + iResult = apIo->write(sNewCmd.data(), sNewCmd.size()); + } + + if(iResult == -1) { + printError("RADIO| Failed to send command to radio"); + return ""; + } + + bool done = false; + const uint32_t capacity = 1024; + char buffer[capacity]; + std::string sResult; + Timer timer; + timer.start(); + do { + int32_t iterationTimeout = 100; + int bytesRead = apIo->read((char*)buffer, capacity, iterationTimeout); + if(bytesRead == -1) { + printError("RADIO| Failed to read from radio"); + break; + } + + std::string sIteration((char*)buffer, bytesRead); + sResult += sIteration; + + if(isNeedMoreData && !isNeedMoreData(sIteration, sResult)) { + printTrace("RADIO| No more data needed"); + return sResult; + } + if(timeoutMillis >= 0) { + done = (timer.getMillis() >= (uint64_t)timeoutMillis); + } else { + //Do not stop looping until bail string is found + } + } while(!done); + + //Timed out + return sResult; +} + +MTS::IO::ICellularRadio::CODE MTS::IO::ICellularRadio::test(MTS::AutoPtr& apIo, uint32_t timeoutSeconds) { + printTrace("RADIO| Basic Test"); + uint32_t count = 0; + std::string sCmd("AT"); + do { + std::string sResult = sendCommand(apIo, sCmd); + if (sResult.find(RSP_OK) == std::string::npos) { + printTrace("RADIO| Waiting for basic radio communication [%s] ...", sResult.c_str()); + } else { + break; + } + count++; + } while (count < timeoutSeconds); + + if(count == timeoutSeconds) { + printWarning("RADIO| Basic radio communication FAILED"); + return NO_RESPONSE; + } + return SUCCESS; +} + +std::string MTS::IO::ICellularRadio::extractModelFromResult(const std::string& sResult) { + std::string sModel(VALUE_NOT_SUPPORTED); + + if(sResult.find("HE910-D") != std::string::npos) { + sModel = "HE910-D"; + } else if(sResult.find("HE910-EUD") != std::string::npos) { + sModel = "HE910-EUD"; + } else if(sResult.find("LE910-JN1") != std::string::npos) { + sModel = "LE910-JN1"; + } else if(sResult.find("LE866A1-JS") != std::string::npos) { + sModel = "LE866A1-JS"; + } else if(sResult.find("LE910-NAG") != std::string::npos) { + sModel = "LE910-NAG"; + } else if(sResult.find("LE910C4-NF") != std::string::npos) { + sModel = "LE910C4-NF"; + } else if(sResult.find("LE910-NA1") != std::string::npos) { + sModel = "LE910-NA1"; + } else if(sResult.find("ME910C1-NA") != std::string::npos) { + sModel = "ME910C1-NA"; + } else if(sResult.find("ME910C1-NV") != std::string::npos) { + sModel = "ME910C1-NV"; + } else if(sResult.find("ME910C1-WW") != std::string::npos) { + sModel = "ME910C1-WW"; + } else if(sResult.find("LE910-SVG") != std::string::npos) { + sModel = "LE910-SVG"; + } else if(sResult.find("LE910-EUG") != std::string::npos) { + sModel = "LE910-EUG"; + } else if(sResult.find("LE910C4-EU") != std::string::npos) { + sModel = "LE910C4-EU"; + } else if(sResult.find("LE910-EU1") != std::string::npos) { + sModel = "LE910-EU1"; + } else if(sResult.find("LE910C1-NS") != std::string::npos) { + sModel = "LE910C1-NS"; + } else if(sResult.find("LE910C1-AP") != std::string::npos) { + sModel = "LE910C1-AP"; + } else if(sResult.find("GE910") != std::string::npos) { + sModel = "GE910"; + } else if(sResult.find("DE910-DUAL") != std::string::npos) { + sModel = "DE910-DUAL"; + } else if(sResult.find("CE910") != std::string::npos) { + sModel = "CE910"; + } + return sModel; +} + +std::string MTS::IO::ICellularRadio::getCodeAsString(CODE eCode) { + switch(eCode) { + case SUCCESS: + return "SUCCESS"; + case ERROR: + return "ERROR"; + case FAILURE: + return "FAILURE"; + case NO_RESPONSE: + return "NO RESPONSE"; + default: + return "UNKNOWN"; + } +} + -- cgit v1.2.3 From 00f886a2eb636a9e44eca0ab47d4125db3e9300a Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Mon, 10 Jun 2019 15:02:59 +0300 Subject: [MTS-MTQ] refactoring: soname links --- Makefile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 2fdaf04..e49f5cc 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ include version APPNAME = libmts-io +SONAME = $(APPNAME).so.$(VERSION) libdir ?= /usr/lib OBJS += \ @@ -47,12 +48,12 @@ LDFLAGS += -s -shared -Wl,-soname,$(APPNAME).so.0 .PHONY: all clean install -all: $(APPNAME).a $(APPNAME).so +all: $(APPNAME).a $(SONAME) $(APPNAME).a: $(OBJS) $(AR) -r $@ $? -$(APPNAME).so: $(OBJS) +$(SONAME): $(OBJS) $(CC) $(LDFLAGS) -o $@ $? $(LDLIBS) # Handle header dependencies @@ -63,9 +64,9 @@ CPPFLAGS += -MMD install: mkdir -p $(DESTDIR)$(libdir) mkdir -p $(DESTDIR)$(includedir)/mts - install -m 0644 $(APPNAME).a $(APPNAME).so $(DESTDIR)$(libdir)/ - ln -sf $(APPNAME).so $(DESTDIR)$(libdir)/$(APPNAME).so.0 - ln -sf $(APPNAME).so.0 $(DESTDIR)$(libdir)/$(APPNAME).so + install -m 0644 $(APPNAME).a $(SONAME) $(DESTDIR)$(libdir)/ + ln -sf $(SONAME) $(DESTDIR)$(libdir)/$(APPNAME).so.0 + ln -sf $(SONAME) $(DESTDIR)$(libdir)/$(APPNAME).so install -m 0644 include/mts/* $(DESTDIR)$(includedir)/mts/ clean: -- cgit v1.2.3 From 07b7b63b15bf5f7cb94f32a5fb45acdf1cb3edfc Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Tue, 11 Jun 2019 11:20:50 +0300 Subject: [MTS-MTQ] refactoring: performance optimization strings replaced by const-char pointer --- include/mts/MTS_IO_ICellularRadio.h | 168 +++++++++++++++++----------------- src/MTS_IO_CellularRadio.cpp | 10 +-- src/MTS_IO_ICellularRadio.cpp | 174 ++++++++++++++++++------------------ 3 files changed, 176 insertions(+), 176 deletions(-) diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h index 3ab8b7e..11ad193 100644 --- a/include/mts/MTS_IO_ICellularRadio.h +++ b/include/mts/MTS_IO_ICellularRadio.h @@ -81,12 +81,12 @@ namespace MTS { static std::string getCodeAsString(CODE code); // XXX - static const std::string DEFAULT_RADIO_PORT; - static const std::string DEFAULT_RADIO_DIR; + static const char *DEFAULT_RADIO_PORT; + static const char *DEFAULT_RADIO_DIR; - static const std::string VALUE_UNKNOWN; - static const std::string VALUE_UNAVAILABLE; - static const std::string VALUE_NOT_SUPPORTED; + static const char *VALUE_UNKNOWN; + static const char *VALUE_UNAVAILABLE; + static const char *VALUE_NOT_SUPPORTED; //Special Payload Characters static const char ETX; //Ends socket connection @@ -95,96 +95,96 @@ namespace MTS { static const char NL; static const char CTRL_Z; - static const std::string RSP_OK; - static const std::string RSP_ERROR; + static const char *RSP_OK; + static const char *RSP_ERROR; - static const std::string VALUE_NOT_REGISTERED; - static const std::string VALUE_REGISTERED; - static const std::string VALUE_SEARCHING; - static const std::string VALUE_DENIED; - static const std::string VALUE_ROAMING; + static const char *VALUE_NOT_REGISTERED; + static const char *VALUE_REGISTERED; + static const char *VALUE_SEARCHING; + static const char *VALUE_DENIED; + static const char *VALUE_ROAMING; //Static Data - static const std::string KEY_TYPE; //!< GSM or CDMA - static const std::string KEY_CODE; //!< Product Code : H5, H6, C2, EV3, G3 - static const std::string KEY_MODEL; //!< Model : HE910, CE910, DE910, GE910 - static const std::string KEY_MANUFACTURER; //!< Manufacturer: Telit - static const std::string KEY_HARDWARE; //!< Radio Hardware Version - static const std::string KEY_FIRMWARE; //!< Radio Firmware Version - static const std::string KEY_FIRMWARE_BUILD;//!< Radio Firmware Build - static const std::string KEY_IMEI; //!< International Mobile Station Equipment Identity - static const std::string KEY_MEID; //!< Mobile Equipment Identifier - static const std::string KEY_IMSI; //!< International Mobile Subscriber Identity - static const std::string KEY_MSID; //!< Mobil Station ID (MSID) aka MIN aka MSIN aka Last few digits of IMSI - static const std::string KEY_MDN; //!< Mobile Directory Number : Actual phone number dialed to reach radio - static const std::string KEY_CARRIER; //!< Cellular Service Provider (Home Network) - static const std::string KEY_ICCID; //!< Integrated Circuit Card Identifier - static const std::string KEY_MSL; //!< Master Subsidy Lock + static const char *KEY_TYPE; //!< GSM or CDMA + static const char *KEY_CODE; //!< Product Code : H5, H6, C2, EV3, G3 + static const char *KEY_MODEL; //!< Model : HE910, CE910, DE910, GE910 + static const char *KEY_MANUFACTURER; //!< Manufacturer: Telit + static const char *KEY_HARDWARE; //!< Radio Hardware Version + static const char *KEY_FIRMWARE; //!< Radio Firmware Version + static const char *KEY_FIRMWARE_BUILD;//!< Radio Firmware Build + static const char *KEY_IMEI; //!< International Mobile Station Equipment Identity + static const char *KEY_MEID; //!< Mobile Equipment Identifier + static const char *KEY_IMSI; //!< International Mobile Subscriber Identity + static const char *KEY_MSID; //!< Mobil Station ID (MSID) aka MIN aka MSIN aka Last few digits of IMSI + static const char *KEY_MDN; //!< Mobile Directory Number : Actual phone number dialed to reach radio + static const char *KEY_CARRIER; //!< Cellular Service Provider (Home Network) + static const char *KEY_ICCID; //!< Integrated Circuit Card Identifier + static const char *KEY_MSL; //!< Master Subsidy Lock //Network Status Data - static const std::string KEY_ROAMING; //!< Indicates whether or not using Home Network - static const std::string KEY_DATETIME; //!< Date and Time from tower - static const std::string KEY_SERVICE; //!< Service Connection Type [GPRS, EGPRS, WCDMA, HSDPA, 1xRTT, EVDO] - static const std::string KEY_NETWORK; //!< Cellular Service Provider - static const std::string KEY_NETWORK_REG; //!< Network Registration - static const std::string KEY_CID; //!< Cellular ID (Tower) in HEX - static const std::string KEY_LAC; //!< Location Area Code in HEX - static const std::string KEY_RAC; //!< Routing Area Code in HEX - static const std::string KEY_RSSI; //!< Received Signal Strength Indication - static const std::string KEY_RSSIDBM; //!< Received Signal Strength Indication in dBm - static const std::string KEY_MCC; //!< Mobile Country Code - static const std::string KEY_MNC; //!< Mobile Network (Operator) Code - static const std::string KEY_CHANNEL; //!< ARFCN or UARFCN Assigned Radio Channel - static const std::string KEY_TXPWR; //!< Transmit Power - static const std::string KEY_PSC; //!< Active Primary Synchronization Code (PSC) - static const std::string KEY_ECIO; //!< Active Ec/Io (chip energy per total wideband power in dBm) - static const std::string KEY_RSCP; //!< Active RSCP (Received Signal Code Power in dBm) - static const std::string KEY_DRX; //!< Discontinuous reception cycle length (ms) - static const std::string KEY_MM; //!< Mobility Management State - static const std::string KEY_RR; //!< Radio Resource State - static const std::string KEY_NOM; //!< Network Operator Mode - static const std::string KEY_ABND; //!< Active Band - static const std::string KEY_BLER; //!< Block Error Rate (percentage) - static const std::string KEY_SD; //!< Service Domain - static const std::string KEY_DEBUG; //!< Debug Information - - static const std::string KEY_MIP; //!< Mobile IP Information - static const std::string KEY_MIP_ID; //!< MIP Profile ID - static const std::string KEY_MIP_ENABLED; //!< MIP Profile Enabled/Disabled - static const std::string KEY_MIP_NAI; //!< Network Access Identifier - static const std::string KEY_MIP_HOMEADDRESS; //!< Home Address - static const std::string KEY_MIP_PRIMARYHA; //!< Primary Home Agent - static const std::string KEY_MIP_SECONDARYHA; //!< Secondary Home Agent - static const std::string KEY_MIP_MNAAASPI; //!< Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index - static const std::string KEY_MIP_MNHASPI; //!< Mobile Node Home Agent Security Server Parameter Index - static const std::string KEY_MIP_REVTUN; //!< Reverse Tunneling Enabled - static const std::string KEY_MIP_MNAAASS; //!< Mobile Node Authentication, Authorization, and Accounting Server Shared Secret - static const std::string KEY_MIP_MNHASS; //!< Mobile Node Home Agent Shared Secret + static const char *KEY_ROAMING; //!< Indicates whether or not using Home Network + static const char *KEY_DATETIME; //!< Date and Time from tower + static const char *KEY_SERVICE; //!< Service Connection Type [GPRS, EGPRS, WCDMA, HSDPA, 1xRTT, EVDO] + static const char *KEY_NETWORK; //!< Cellular Service Provider + static const char *KEY_NETWORK_REG; //!< Network Registration + static const char *KEY_CID; //!< Cellular ID (Tower) in HEX + static const char *KEY_LAC; //!< Location Area Code in HEX + static const char *KEY_RAC; //!< Routing Area Code in HEX + static const char *KEY_RSSI; //!< Received Signal Strength Indication + static const char *KEY_RSSIDBM; //!< Received Signal Strength Indication in dBm + static const char *KEY_MCC; //!< Mobile Country Code + static const char *KEY_MNC; //!< Mobile Network (Operator) Code + static const char *KEY_CHANNEL; //!< ARFCN or UARFCN Assigned Radio Channel + static const char *KEY_TXPWR; //!< Transmit Power + static const char *KEY_PSC; //!< Active Primary Synchronization Code (PSC) + static const char *KEY_ECIO; //!< Active Ec/Io (chip energy per total wideband power in dBm) + static const char *KEY_RSCP; //!< Active RSCP (Received Signal Code Power in dBm) + static const char *KEY_DRX; //!< Discontinuous reception cycle length (ms) + static const char *KEY_MM; //!< Mobility Management State + static const char *KEY_RR; //!< Radio Resource State + static const char *KEY_NOM; //!< Network Operator Mode + static const char *KEY_ABND; //!< Active Band + static const char *KEY_BLER; //!< Block Error Rate (percentage) + static const char *KEY_SD; //!< Service Domain + static const char *KEY_DEBUG; //!< Debug Information + + static const char *KEY_MIP; //!< Mobile IP Information + static const char *KEY_MIP_ID; //!< MIP Profile ID + static const char *KEY_MIP_ENABLED; //!< MIP Profile Enabled/Disabled + static const char *KEY_MIP_NAI; //!< Network Access Identifier + static const char *KEY_MIP_HOMEADDRESS; //!< Home Address + static const char *KEY_MIP_PRIMARYHA; //!< Primary Home Agent + static const char *KEY_MIP_SECONDARYHA; //!< Secondary Home Agent + static const char *KEY_MIP_MNAAASPI; //!< Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index + static const char *KEY_MIP_MNHASPI; //!< Mobile Node Home Agent Security Server Parameter Index + static const char *KEY_MIP_REVTUN; //!< Reverse Tunneling Enabled + static const char *KEY_MIP_MNAAASS; //!< Mobile Node Authentication, Authorization, and Accounting Server Shared Secret + static const char *KEY_MIP_MNHASS; //!< Mobile Node Home Agent Shared Secret //Values - Type - static const std::string VALUE_TYPE_LTE; - static const std::string VALUE_TYPE_GSM; - static const std::string VALUE_TYPE_CDMA; + static const char *VALUE_TYPE_LTE; + static const char *VALUE_TYPE_GSM; + static const char *VALUE_TYPE_CDMA; //Values - Carrier - static const std::string VALUE_CARRIER_VERIZON; - static const std::string VALUE_CARRIER_AERIS; - static const std::string VALUE_CARRIER_SPRINT; - static const std::string VALUE_CARRIER_USCELLULAR; - static const std::string VALUE_CARRIER_ATT; - static const std::string VALUE_CARRIER_TMOBILE; - - static const std::string VALUE_SD_NO_SERVICE; - static const std::string VALUE_SD_CS_ONLY; - static const std::string VALUE_SD_PS_ONLY; - static const std::string VALUE_SD_CSPS; - - static const std::string VALUE_ABND_GSM_850; - static const std::string VALUE_ABND_GSM_900; - static const std::string VALUE_ABND_DCS_1800; - static const std::string VALUE_ABND_PCS_1900; + static const char *VALUE_CARRIER_VERIZON; + static const char *VALUE_CARRIER_AERIS; + static const char *VALUE_CARRIER_SPRINT; + static const char *VALUE_CARRIER_USCELLULAR; + static const char *VALUE_CARRIER_ATT; + static const char *VALUE_CARRIER_TMOBILE; + + static const char *VALUE_SD_NO_SERVICE; + static const char *VALUE_SD_CS_ONLY; + static const char *VALUE_SD_PS_ONLY; + static const char *VALUE_SD_CSPS; + + static const char *VALUE_ABND_GSM_850; + static const char *VALUE_ABND_GSM_900; + static const char *VALUE_ABND_DCS_1800; + static const char *VALUE_ABND_PCS_1900; static const std::vector DEFAULT_BAIL_STRINGS; diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index f106b4c..66d44a0 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -1096,7 +1096,7 @@ const char *CellularRadio::RadioBandMap::getLTEBand(const int32_t channel) return EULTRAband[ii].name; } } - return VALUE_UNKNOWN.c_str(); + return VALUE_UNKNOWN; } const char *CellularRadio::RadioBandMap::getCDMABand(const int channel) @@ -1108,7 +1108,7 @@ const char *CellularRadio::RadioBandMap::getCDMABand(const int channel) return WCDMAband[ii].name; } } - return VALUE_UNKNOWN.c_str(); + return VALUE_UNKNOWN; } const char *CellularRadio::RadioBandMap::getGSMBand(const int channel) @@ -1120,12 +1120,12 @@ const char *CellularRadio::RadioBandMap::getGSMBand(const int channel) return GSMband[ii].name; } } - return VALUE_UNKNOWN.c_str(); + return VALUE_UNKNOWN; } const char *CellularRadio::RadioBandMap::getRadioBandName() { - const char *band = CellularRadio::VALUE_UNKNOWN.c_str(); + const char *band = CellularRadio::VALUE_UNKNOWN; if (m_sRadioType == VALUE_TYPE_LTE) { @@ -1145,7 +1145,7 @@ const char *CellularRadio::RadioBandMap::getRadioBandName() const char *CellularRadio::RadioBandMap::getRadioBandName(const std::string &channel, const std::string &radioType) { - const char *band = VALUE_UNKNOWN.c_str(); + const char *band = VALUE_UNKNOWN; int32_t chan = strtol(channel.c_str(), NULL, 10); if (radioType == VALUE_TYPE_LTE) { diff --git a/src/MTS_IO_ICellularRadio.cpp b/src/MTS_IO_ICellularRadio.cpp index e206a59..58ccb2b 100644 --- a/src/MTS_IO_ICellularRadio.cpp +++ b/src/MTS_IO_ICellularRadio.cpp @@ -9,100 +9,100 @@ const char MTS::IO::ICellularRadio::CR = 0x0D; const char MTS::IO::ICellularRadio::NL = 0x0A; const char MTS::IO::ICellularRadio::CTRL_Z = 0x1A; -const std::string MTS::IO::ICellularRadio::RSP_ERROR("ERROR"); -const std::string MTS::IO::ICellularRadio::RSP_OK("OK"); +const char *MTS::IO::ICellularRadio::RSP_ERROR = "ERROR"; +const char *MTS::IO::ICellularRadio::RSP_OK = "OK"; -const std::string MTS::IO::ICellularRadio::DEFAULT_RADIO_PORT("/dev/modem_at1"); -const std::string MTS::IO::ICellularRadio::DEFAULT_RADIO_DIR("/var/run/radio/"); -const std::string MTS::IO::ICellularRadio::VALUE_UNKNOWN("Unknown"); -const std::string MTS::IO::ICellularRadio::VALUE_UNAVAILABLE("Unavailable"); -const std::string MTS::IO::ICellularRadio::VALUE_NOT_SUPPORTED("Not Supported"); +const char *MTS::IO::ICellularRadio::DEFAULT_RADIO_PORT = "/dev/modem_at1"; +const char *MTS::IO::ICellularRadio::DEFAULT_RADIO_DIR = "/var/run/radio/"; +const char *MTS::IO::ICellularRadio::VALUE_UNKNOWN = "Unknown"; +const char *MTS::IO::ICellularRadio::VALUE_UNAVAILABLE = "Unavailable"; +const char *MTS::IO::ICellularRadio::VALUE_NOT_SUPPORTED = "Not Supported"; -const std::string MTS::IO::ICellularRadio::VALUE_NOT_REGISTERED("NOT REGISTERED"); -const std::string MTS::IO::ICellularRadio::VALUE_REGISTERED("REGISTERED"); -const std::string MTS::IO::ICellularRadio::VALUE_SEARCHING("SEARCHING"); -const std::string MTS::IO::ICellularRadio::VALUE_DENIED("DENIED"); -const std::string MTS::IO::ICellularRadio::VALUE_ROAMING("ROAMING"); +const char *MTS::IO::ICellularRadio::VALUE_NOT_REGISTERED = "NOT REGISTERED"; +const char *MTS::IO::ICellularRadio::VALUE_REGISTERED = "REGISTERED"; +const char *MTS::IO::ICellularRadio::VALUE_SEARCHING = "SEARCHING"; +const char *MTS::IO::ICellularRadio::VALUE_DENIED = "DENIED"; +const char *MTS::IO::ICellularRadio::VALUE_ROAMING = "ROAMING"; //Static Data -const std::string MTS::IO::ICellularRadio::KEY_TYPE("type"); //!< GSM or CDMA -const std::string MTS::IO::ICellularRadio::KEY_CODE("code"); //!< Product Code : H5, H6, C2, EV3, G3 -const std::string MTS::IO::ICellularRadio::KEY_MODEL("model"); //!< Model : HE910, LE910, CE910, DE910, GE910 -const std::string MTS::IO::ICellularRadio::KEY_MANUFACTURER("manufacturer"); //!< Manufacturer: Telit -const std::string MTS::IO::ICellularRadio::KEY_HARDWARE("hardware"); //!< Radio Hardware Version -const std::string MTS::IO::ICellularRadio::KEY_FIRMWARE("firmware"); //!< Radio Firmware Version -const std::string MTS::IO::ICellularRadio::KEY_FIRMWARE_BUILD("firmwarebuild"); //!< Radio Firmware Build - -const std::string MTS::IO::ICellularRadio::KEY_CARRIER("carrier"); //!< Cellular Service Provider (Home Network) -const std::string MTS::IO::ICellularRadio::VALUE_CARRIER_VERIZON("Verizon"); -const std::string MTS::IO::ICellularRadio::VALUE_CARRIER_AERIS("Aeris"); -const std::string MTS::IO::ICellularRadio::VALUE_CARRIER_SPRINT("Sprint"); -const std::string MTS::IO::ICellularRadio::VALUE_CARRIER_USCELLULAR("U.S. Cellular"); -const std::string MTS::IO::ICellularRadio::VALUE_CARRIER_ATT("AT&T"); -const std::string MTS::IO::ICellularRadio::VALUE_CARRIER_TMOBILE("T-Mobile"); - -const std::string MTS::IO::ICellularRadio::KEY_IMEI("imei"); //!< International Mobile Station Equipment Identity -const std::string MTS::IO::ICellularRadio::KEY_MEID("meid"); //!< Mobile Equipment Identifier -const std::string MTS::IO::ICellularRadio::KEY_IMSI("imsi"); //!< International Mobile Subscriber Identity -const std::string MTS::IO::ICellularRadio::KEY_MSID("msid"); //!< Mobil Station ID / Mobile Identification Number (MSID/MIN) (CDMA-Only) -const std::string MTS::IO::ICellularRadio::KEY_MDN("mdn"); //!< Mobile Directory Number : Actual phone number dialed to reach radio -const std::string MTS::IO::ICellularRadio::KEY_ICCID("iccid"); //!< Integrated Circuit Card Identifier -const std::string MTS::IO::ICellularRadio::KEY_MSL("msl"); //!< Master Subsidy Lock +const char *MTS::IO::ICellularRadio::KEY_TYPE = "type"; //!< GSM or CDMA +const char *MTS::IO::ICellularRadio::KEY_CODE = "code"; //!< Product Code : H5, H6, C2, EV3, G3 +const char *MTS::IO::ICellularRadio::KEY_MODEL = "model"; //!< Model : HE910, LE910, CE910, DE910, GE910 +const char *MTS::IO::ICellularRadio::KEY_MANUFACTURER = "manufacturer"; //!< Manufacturer: Telit +const char *MTS::IO::ICellularRadio::KEY_HARDWARE = "hardware"; //!< Radio Hardware Version +const char *MTS::IO::ICellularRadio::KEY_FIRMWARE = "firmware"; //!< Radio Firmware Version +const char *MTS::IO::ICellularRadio::KEY_FIRMWARE_BUILD = "firmwarebuild"; //!< Radio Firmware Build + +const char *MTS::IO::ICellularRadio::KEY_CARRIER = "carrier"; //!< Cellular Service Provider = Home Network +const char *MTS::IO::ICellularRadio::VALUE_CARRIER_VERIZON = "Verizon"; +const char *MTS::IO::ICellularRadio::VALUE_CARRIER_AERIS = "Aeris"; +const char *MTS::IO::ICellularRadio::VALUE_CARRIER_SPRINT = "Sprint"; +const char *MTS::IO::ICellularRadio::VALUE_CARRIER_USCELLULAR = "U.S. Cellular"; +const char *MTS::IO::ICellularRadio::VALUE_CARRIER_ATT = "AT&T"; +const char *MTS::IO::ICellularRadio::VALUE_CARRIER_TMOBILE = "T-Mobile"; + +const char *MTS::IO::ICellularRadio::KEY_IMEI = "imei"; //!< International Mobile Station Equipment Identity +const char *MTS::IO::ICellularRadio::KEY_MEID = "meid"; //!< Mobile Equipment Identifier +const char *MTS::IO::ICellularRadio::KEY_IMSI = "imsi"; //!< International Mobile Subscriber Identity +const char *MTS::IO::ICellularRadio::KEY_MSID = "msid"; //!< Mobil Station ID / Mobile Identification Number = MSID/MIN = CDMA-Only +const char *MTS::IO::ICellularRadio::KEY_MDN = "mdn"; //!< Mobile Directory Number : Actual phone number dialed to reach radio +const char *MTS::IO::ICellularRadio::KEY_ICCID = "iccid"; //!< Integrated Circuit Card Identifier +const char *MTS::IO::ICellularRadio::KEY_MSL = "msl"; //!< Master Subsidy Lock //Dynamic Data -const std::string MTS::IO::ICellularRadio::KEY_ROAMING("roaming"); //!< Indicates whether or not using Home Network -const std::string MTS::IO::ICellularRadio::KEY_DATETIME("datetime"); //!< Date and Time from tower -const std::string MTS::IO::ICellularRadio::KEY_SERVICE("service"); //!< Service Connection Type [GPRS, EGPRS, WCDMA, HSDPA, 1xRTT, EVDO] -const std::string MTS::IO::ICellularRadio::KEY_NETWORK("network"); //!< Cellular Service Provider -const std::string MTS::IO::ICellularRadio::KEY_NETWORK_REG("netreg"); //!< Network Registration -const std::string MTS::IO::ICellularRadio::KEY_CID("cid"); //!< Cellular ID (Tower) in HEX -const std::string MTS::IO::ICellularRadio::KEY_LAC("lac"); //!< Location Area Code in HEX -const std::string MTS::IO::ICellularRadio::KEY_RAC("rac"); //!< Routing Area Code in HEX -const std::string MTS::IO::ICellularRadio::KEY_RSSI("rssi"); //!< Signal Strength -const std::string MTS::IO::ICellularRadio::KEY_RSSIDBM("rssidBm"); //!< Signal Strength in dBm -const std::string MTS::IO::ICellularRadio::KEY_MCC("mcc"); //!< Country Code -const std::string MTS::IO::ICellularRadio::KEY_MNC("mnc"); //!< Operator Code -const std::string MTS::IO::ICellularRadio::KEY_CHANNEL("channel"); //!< ARFCN or UARFCN Assigned Radio Channel -const std::string MTS::IO::ICellularRadio::KEY_TXPWR("txpwr"); //!< Transmit Power -const std::string MTS::IO::ICellularRadio::KEY_PSC("psc"); //!< Active Primary Synchronization Code (PSC) -const std::string MTS::IO::ICellularRadio::KEY_ECIO("ecio"); //!< Active Ec/Io (chip energy per total wideband power in dBm) -const std::string MTS::IO::ICellularRadio::KEY_RSCP("rscp"); //!< Active RSCP (Received Signal Code Power in dBm) -const std::string MTS::IO::ICellularRadio::KEY_DRX("drx"); //!< Discontinuous reception cycle length (ms) -const std::string MTS::IO::ICellularRadio::KEY_MM("mm"); //!< Mobility Management State -const std::string MTS::IO::ICellularRadio::KEY_RR("rr"); //!< Radio Resource State -const std::string MTS::IO::ICellularRadio::KEY_NOM("nom"); //!< Network Operator Mode -const std::string MTS::IO::ICellularRadio::KEY_ABND("abnd"); //!< Active Band -const std::string MTS::IO::ICellularRadio::KEY_BLER("bler"); //!< Block Error Rate (percentage) -const std::string MTS::IO::ICellularRadio::KEY_SD("sd"); //!< Service Domain -const std::string MTS::IO::ICellularRadio::KEY_DEBUG("debug"); //!< Debug Information - -const std::string MTS::IO::ICellularRadio::KEY_MIP("mipProfile"); //!< Mobile IP Information -const std::string MTS::IO::ICellularRadio::KEY_MIP_ID("id"); //!< Mobile IP ID -const std::string MTS::IO::ICellularRadio::KEY_MIP_ENABLED("enabled"); //!< Mobile IP Enabled/Disabled -const std::string MTS::IO::ICellularRadio::KEY_MIP_NAI("nai"); //!< Network Access Identifier -const std::string MTS::IO::ICellularRadio::KEY_MIP_HOMEADDRESS("homeAddress"); //!< Home Address -const std::string MTS::IO::ICellularRadio::KEY_MIP_PRIMARYHA("primaryAddress"); //!< Primary Home Agent -const std::string MTS::IO::ICellularRadio::KEY_MIP_SECONDARYHA("secondaryAddress"); //!< Secondary Home Agent -const std::string MTS::IO::ICellularRadio::KEY_MIP_MNAAASPI("mnAaaSpi"); //!< Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index -const std::string MTS::IO::ICellularRadio::KEY_MIP_MNHASPI("mnHaSpi"); //!< Mobile Node Home Agent Security Server Parameter Index -const std::string MTS::IO::ICellularRadio::KEY_MIP_REVTUN("revTun"); //!< Reverse Tunneling Enabled -const std::string MTS::IO::ICellularRadio::KEY_MIP_MNAAASS("mnAaaSs"); //!< Mobile Node Authentication, Authorization, and Accounting Server Shared Secret -const std::string MTS::IO::ICellularRadio::KEY_MIP_MNHASS("mnHaSs"); //!< Mobile Node Home Agent Shared Secret - -const std::string MTS::IO::ICellularRadio::VALUE_TYPE_GSM("GSM"); -const std::string MTS::IO::ICellularRadio::VALUE_TYPE_LTE("LTE"); -const std::string MTS::IO::ICellularRadio::VALUE_TYPE_CDMA("CDMA"); - -const std::string MTS::IO::ICellularRadio::VALUE_SD_NO_SERVICE("NO SERVICE"); -const std::string MTS::IO::ICellularRadio::VALUE_SD_CS_ONLY("CS ONLY"); -const std::string MTS::IO::ICellularRadio::VALUE_SD_PS_ONLY("PS ONLY"); -const std::string MTS::IO::ICellularRadio::VALUE_SD_CSPS("CS+PS"); - -const std::string MTS::IO::ICellularRadio::VALUE_ABND_GSM_850("GSM 850"); -const std::string MTS::IO::ICellularRadio::VALUE_ABND_GSM_900("GSM 900"); -const std::string MTS::IO::ICellularRadio::VALUE_ABND_DCS_1800("DCS 1800"); -const std::string MTS::IO::ICellularRadio::VALUE_ABND_PCS_1900("PCS 1900"); +const char *MTS::IO::ICellularRadio::KEY_ROAMING = "roaming"; //!< Indicates whether or not using Home Network +const char *MTS::IO::ICellularRadio::KEY_DATETIME = "datetime"; //!< Date and Time from tower +const char *MTS::IO::ICellularRadio::KEY_SERVICE = "service"; //!< Service Connection Type [GPRS, EGPRS, WCDMA, HSDPA, 1xRTT, EVDO] +const char *MTS::IO::ICellularRadio::KEY_NETWORK = "network"; //!< Cellular Service Provider +const char *MTS::IO::ICellularRadio::KEY_NETWORK_REG = "netreg"; //!< Network Registration +const char *MTS::IO::ICellularRadio::KEY_CID = "cid"; //!< Cellular ID = Tower in HEX +const char *MTS::IO::ICellularRadio::KEY_LAC = "lac"; //!< Location Area Code in HEX +const char *MTS::IO::ICellularRadio::KEY_RAC = "rac"; //!< Routing Area Code in HEX +const char *MTS::IO::ICellularRadio::KEY_RSSI = "rssi"; //!< Signal Strength +const char *MTS::IO::ICellularRadio::KEY_RSSIDBM = "rssidBm"; //!< Signal Strength in dBm +const char *MTS::IO::ICellularRadio::KEY_MCC = "mcc"; //!< Country Code +const char *MTS::IO::ICellularRadio::KEY_MNC = "mnc"; //!< Operator Code +const char *MTS::IO::ICellularRadio::KEY_CHANNEL = "channel"; //!< ARFCN or UARFCN Assigned Radio Channel +const char *MTS::IO::ICellularRadio::KEY_TXPWR = "txpwr"; //!< Transmit Power +const char *MTS::IO::ICellularRadio::KEY_PSC = "psc"; //!< Active Primary Synchronization Code = PSC +const char *MTS::IO::ICellularRadio::KEY_ECIO = "ecio"; //!< Active Ec/Io = chip energy per total wideband power in dBm +const char *MTS::IO::ICellularRadio::KEY_RSCP = "rscp"; //!< Active RSCP = Received Signal Code Power in dBm +const char *MTS::IO::ICellularRadio::KEY_DRX = "drx"; //!< Discontinuous reception cycle length = ms +const char *MTS::IO::ICellularRadio::KEY_MM = "mm"; //!< Mobility Management State +const char *MTS::IO::ICellularRadio::KEY_RR = "rr"; //!< Radio Resource State +const char *MTS::IO::ICellularRadio::KEY_NOM = "nom"; //!< Network Operator Mode +const char *MTS::IO::ICellularRadio::KEY_ABND = "abnd"; //!< Active Band +const char *MTS::IO::ICellularRadio::KEY_BLER = "bler"; //!< Block Error Rate = percentage +const char *MTS::IO::ICellularRadio::KEY_SD = "sd"; //!< Service Domain +const char *MTS::IO::ICellularRadio::KEY_DEBUG = "debug"; //!< Debug Information + +const char *MTS::IO::ICellularRadio::KEY_MIP = "mipProfile"; //!< Mobile IP Information +const char *MTS::IO::ICellularRadio::KEY_MIP_ID = "id"; //!< Mobile IP ID +const char *MTS::IO::ICellularRadio::KEY_MIP_ENABLED = "enabled"; //!< Mobile IP Enabled/Disabled +const char *MTS::IO::ICellularRadio::KEY_MIP_NAI = "nai"; //!< Network Access Identifier +const char *MTS::IO::ICellularRadio::KEY_MIP_HOMEADDRESS = "homeAddress"; //!< Home Address +const char *MTS::IO::ICellularRadio::KEY_MIP_PRIMARYHA = "primaryAddress"; //!< Primary Home Agent +const char *MTS::IO::ICellularRadio::KEY_MIP_SECONDARYHA = "secondaryAddress"; //!< Secondary Home Agent +const char *MTS::IO::ICellularRadio::KEY_MIP_MNAAASPI = "mnAaaSpi"; //!< Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index +const char *MTS::IO::ICellularRadio::KEY_MIP_MNHASPI = "mnHaSpi"; //!< Mobile Node Home Agent Security Server Parameter Index +const char *MTS::IO::ICellularRadio::KEY_MIP_REVTUN = "revTun"; //!< Reverse Tunneling Enabled +const char *MTS::IO::ICellularRadio::KEY_MIP_MNAAASS = "mnAaaSs"; //!< Mobile Node Authentication, Authorization, and Accounting Server Shared Secret +const char *MTS::IO::ICellularRadio::KEY_MIP_MNHASS = "mnHaSs"; //!< Mobile Node Home Agent Shared Secret + +const char *MTS::IO::ICellularRadio::VALUE_TYPE_GSM = "GSM"; +const char *MTS::IO::ICellularRadio::VALUE_TYPE_LTE = "LTE"; +const char *MTS::IO::ICellularRadio::VALUE_TYPE_CDMA = "CDMA"; + +const char *MTS::IO::ICellularRadio::VALUE_SD_NO_SERVICE = "NO SERVICE"; +const char *MTS::IO::ICellularRadio::VALUE_SD_CS_ONLY = "CS ONLY"; +const char *MTS::IO::ICellularRadio::VALUE_SD_PS_ONLY = "PS ONLY"; +const char *MTS::IO::ICellularRadio::VALUE_SD_CSPS = "CS+PS"; + +const char *MTS::IO::ICellularRadio::VALUE_ABND_GSM_850 = "GSM 850"; +const char *MTS::IO::ICellularRadio::VALUE_ABND_GSM_900 = "GSM 900"; +const char *MTS::IO::ICellularRadio::VALUE_ABND_DCS_1800 = "DCS 1800"; +const char *MTS::IO::ICellularRadio::VALUE_ABND_PCS_1900 = "PCS 1900"; const std::vector MTS::IO::ICellularRadio::DEFAULT_BAIL_STRINGS = { MTS::IO::ICellularRadio::RSP_OK, MTS::IO::ICellularRadio::RSP_ERROR }; -- cgit v1.2.3 From 6848f0470159df2318c2377a08766a3bb9dcb4c3 Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Tue, 11 Jun 2019 11:28:39 +0300 Subject: [MTS-MTQ] refactoring: makefile clean target fix --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e49f5cc..3ace73f 100644 --- a/Makefile +++ b/Makefile @@ -70,4 +70,4 @@ install: install -m 0644 include/mts/* $(DESTDIR)$(includedir)/mts/ clean: - $(RM) $(OBJS) $(APPNAME).a $(APPNAME).so $(DEPS) + $(RM) $(OBJS) $(APPNAME).a $(SONAME) $(DEPS) -- cgit v1.2.3 From f335cec14c262b22f8d9f84e528917d7b1a53fa5 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Tue, 11 Jun 2019 15:52:53 +0300 Subject: [MTS-MTQ] QuectelRadio implementation Moved CellularRadio::getNetwork implementation to the TelitRadio::getNetwork as Quectel radio doesn't have a AT#RFSTS command that returns the needed field. --- include/mts/MTS_IO_CellularRadio.h | 1 - include/mts/MTS_IO_TelitRadio.h | 1 + src/MTS_IO_CellularRadio.cpp | 15 --------------- src/MTS_IO_TelitRadio.cpp | 15 +++++++++++++++ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index 0410e0d..1576588 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -66,7 +66,6 @@ namespace MTS { CODE getMsid(std::string& sMsid) override; CODE getType(std::string& sType) override; CODE getCarrier(std::string& sCarrier) override; - CODE getNetwork(std::string& sNetwork) override; CODE getTower(std::string& sTower) override; CODE getTime(std::string& sDate, std::string& sTime, std::string& sTimeZone) override; CODE getRoaming(bool& bRoaming) override; diff --git a/include/mts/MTS_IO_TelitRadio.h b/include/mts/MTS_IO_TelitRadio.h index 0c95f98..7a44529 100644 --- a/include/mts/MTS_IO_TelitRadio.h +++ b/include/mts/MTS_IO_TelitRadio.h @@ -32,6 +32,7 @@ namespace MTS { CODE getModel(std::string& sModel) override; CODE getIccid(std::string& sIccid) override; CODE getService(std::string& sService) override; + CODE getNetwork(std::string& sNetwork) override; CODE getNetworkStatus(Json::Value& jData) override; CODE setMdn(const Json::Value& jArgs) override; diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index 66d44a0..e3927ea 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -488,21 +488,6 @@ CellularRadio::CODE CellularRadio::getRoaming(bool& bRoaming) { return FAILURE; } -CellularRadio::CODE CellularRadio::getNetwork(std::string& sNetwork) { - Json::Value jData; - - printTrace("%s| Get Network", m_sName.c_str()); - sNetwork = VALUE_NOT_SUPPORTED; - - if(getNetworkStatus(jData) == SUCCESS) { - if(jData.isMember(KEY_NETWORK)) { - sNetwork = jData[KEY_NETWORK].asString(); - return SUCCESS; - } - } - return FAILURE; -} - CellularRadio::CODE CellularRadio::getSignalStrength(int32_t& rssi) { printTrace("%s| Get Signal Strength", m_sName.c_str()); std::string sCmd("AT+CSQ"); diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp index 6ce240e..7f9de63 100644 --- a/src/MTS_IO_TelitRadio.cpp +++ b/src/MTS_IO_TelitRadio.cpp @@ -127,6 +127,21 @@ CellularRadio::CODE TelitRadio::getService(std::string& sService) { return SUCCESS; } +CellularRadio::CODE TelitRadio::getNetwork(std::string& sNetwork) { + Json::Value jData; + + printTrace("%s| Get Network", getName().c_str()); + sNetwork = VALUE_NOT_SUPPORTED; + + if(getNetworkStatus(jData) == SUCCESS) { + if(jData.isMember(KEY_NETWORK)) { + sNetwork = jData[KEY_NETWORK].asString(); + return SUCCESS; + } + } + return FAILURE; +} + /* AT#RFSTS - NETWORK STATUS (GSM network) -- cgit v1.2.3 From 16c34c61203dee01c8091b92df1bdf0a399af32f Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Tue, 11 Jun 2019 15:59:49 +0300 Subject: [MTS-MTQ] QuectelRadio implementation Removed Telit-specific implementation of the getCarrierFromFirmware and getHardwareVersionFromFirmware out of the QuectelRadio class. BTW, it's still present in the TelitRadio class. --- include/mts/MTS_IO_CellularRadio.h | 6 ++- src/MTS_IO_CellularRadio.cpp | 81 -------------------------------------- 2 files changed, 4 insertions(+), 83 deletions(-) diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index 1576588..c4e5b86 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -119,9 +119,11 @@ namespace MTS { CellularRadio(const std::string& sName, const std::string& sRadioPort); - virtual bool getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier); - virtual bool getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware); + virtual bool getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier) = 0; + virtual bool getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware) = 0; + virtual void getCommonNetworkStats(Json::Value& jData); + void initMipProfile(Json::Value& jData); bool splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType = Json::ValueType::stringValue); diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index e3927ea..092da35 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -991,87 +991,6 @@ bool CellularRadio::splitAndAssign(const std::string& sLine, const std::string& return true; } -bool CellularRadio::getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier) { - // Telit Radios - // H.ab.zyx => 3 Main Components - // "H" = Hardware -> 15 = DE910 family, 18 = CE910 family, 12 = HE910 family - // "a" = Hardware version - // "b" = Software Major Version - // "z" = is the product type, i.e. DUAL or SC - // "y" = is the carrier variant - // "x" = is the firmware version - // Telit will do their best to keep the carrier variant as "0" for Sprint, "1" for Aeris, "2" for Verizon, and "3" for U.S. Cellular. - - const uint32_t CARRIER_INDEX = 1; //y in [zyx] - - bool bResult = false; - std::vector vParts = MTS::Text::split(sFirmware, '.'); - - if(vParts.size() == 3) { - //CDMA firmware version notation - if(vParts[0] == "15" || vParts[0] == "18") { - //DE910 or CE910 -> Good good - std::string sID = vParts[2]; - if(sID.size() == 3) { - char cId = sID[CARRIER_INDEX]; - - //Good good - if(cId == '0') { - sCarrier = VALUE_CARRIER_SPRINT; - bResult = true; - } else - if(cId == '1') { - sCarrier = VALUE_CARRIER_AERIS; - bResult = true; - } else - if(cId == '2') { - sCarrier = VALUE_CARRIER_VERIZON; - bResult = true; - } else - if(cId == '3') { - sCarrier = VALUE_CARRIER_USCELLULAR; - bResult = true; - } - } - } - } - - return bResult; -} - -bool CellularRadio::getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware) { - // Telit Radios - // H.ab.zyx => 3 Main Components - // "H" = Hardware -> 15 = DE910 family, 18 = CE910 family, 12 = HE910 family - // "a" = Hardware version - // "b" = Software Major Version - // "z" = is the product type, i.e. DUAL or SC - // "y" = is the carrier variant - // "x" = is the firmware version - // Telit will do their best to keep the carrier variant as "0" for Sprint, "1" for Aeris, and "2" for Verizon. - - const uint32_t HARDWARE_INDEX = 0; //a in [ab] - - bool bResult = false; - std::vector vParts = MTS::Text::split(sFirmware, '.'); - - if(vParts.size() == 3) { - //GSM Hardware Version - if(!(vParts[0] == "15" || vParts[0] == "18")) { - //Not DE910 or CE910 -> Good good - std::string sVersion = vParts[1]; - if(sVersion.size() == 2) { - sHardware = "1."; - sHardware += sVersion[HARDWARE_INDEX]; - bResult = true; - } - } - } - - return bResult; - -} - const char *CellularRadio::RadioBandMap::getLTEBand(const int32_t channel) { for (unsigned int ii = 0; ii < NUM_LTE_BANDS; ii++) -- cgit v1.2.3 From ea4e0213f94a1014a0b4f0e0e43c3222eddc177a Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Tue, 11 Jun 2019 16:11:14 +0300 Subject: [MTS-MTQ] QuectelRadio implementation Converted the following functions to protected virtual functions: - CellularRadio::queryLteLac - CellularRadio::setCGREG - CellularRadio::queryCGREGstring Those functions are handy to fetch LAC in LTE mode for both Quectel and Telit radios. Also fixed comments and debug messages for the mentioned functions. --- include/mts/MTS_IO_CellularRadio.h | 8 ++++---- src/MTS_IO_CellularRadio.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index c4e5b86..1572ac8 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -127,6 +127,10 @@ namespace MTS { void initMipProfile(Json::Value& jData); bool splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType = Json::ValueType::stringValue); + virtual std::string queryLteLac(); + virtual std::string queryCGREGstring(); + virtual void setCGREG(std::string value); + class RadioBandMap : public MTS::NonCopyable { public: RadioBandMap() @@ -168,10 +172,6 @@ namespace MTS { bool m_bEchoEnabled; bool m_bEnableEchoOnClose; - - std::string queryLteLac(); - std::string queryCGREGstring(); - void setCGREG(std::string value); }; } } diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index 092da35..ee4e9ec 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -670,7 +670,7 @@ CellularRadio::CODE CellularRadio::getStaticInformation(Json::Value& jData) { - */ -// Get the LAC for the LTE radio that's not in the #RFSTS response +// Get the LAC for the LTE radio that's not in the #RFSTS or +QENG response std::string CellularRadio::queryLteLac() { std::string CGREGstring; std::string originalCGREG; @@ -690,7 +690,7 @@ std::string CellularRadio::queryLteLac() { if (CGREGstring == RSP_ERROR) { result = VALUE_UNKNOWN; } else { - size_t start = CGREGstring.find(":") + 1; //Position right after "#RFSTS:" + size_t start = CGREGstring.find(":") + 1; //Position right after "+CGREG:" std::vector vParts = MTS::Text::split(MTS::Text::trim(CGREGstring.substr(start)), ","); if(vParts.size() < 3) { result = VALUE_UNAVAILABLE; @@ -708,7 +708,7 @@ 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()); + printDebug("%s| AT+CGREG=%s returned unexpected response: [%s][%s]", m_sName.c_str(), value.c_str(), sCmd.c_str(), cmdResult.c_str()); } } @@ -716,7 +716,7 @@ 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()); + printDebug("%s| AT+CGREG? returned unexpected response: [%s][%s]", m_sName.c_str(), sCmd.c_str(), cmdResult.c_str()); return RSP_ERROR; } return cmdResult; -- cgit v1.2.3 From bce73d000b64fc8ecaf7a25041e97a1ef57a848e Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Tue, 11 Jun 2019 16:30:23 +0300 Subject: [MTS-MTQ] QuectelRadio implementation Moved Telit-specific conversion between RSSI and dBm into the TelitRadio class. Quectel has MOSTLY the same conversion logic but in the case of TD-SCDMA the RSSI values may be uncompatible. --- include/mts/MTS_IO_CellularRadio.h | 2 -- include/mts/MTS_IO_TelitRadio.h | 4 ++++ src/MTS_IO_CellularRadio.cpp | 41 -------------------------------------- src/MTS_IO_TelitRadio.cpp | 41 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 43 deletions(-) diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index 1572ac8..8e9201f 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -72,8 +72,6 @@ namespace MTS { CODE getSignalStrength(int32_t& iRssi) override; CODE getModemLocation(std::string& sLocation) override; - CODE convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& dBm) override; - CODE convertdBmToSignalStrength(const int32_t& dBm, int32_t& iRssi) override; CODE getRegistration(REGISTRATION& eRegistration) override; CODE convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration) override; diff --git a/include/mts/MTS_IO_TelitRadio.h b/include/mts/MTS_IO_TelitRadio.h index 7a44529..7162dfb 100644 --- a/include/mts/MTS_IO_TelitRadio.h +++ b/include/mts/MTS_IO_TelitRadio.h @@ -34,6 +34,10 @@ namespace MTS { CODE getService(std::string& sService) override; CODE getNetwork(std::string& sNetwork) override; CODE getNetworkStatus(Json::Value& jData) override; + + CODE convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& dBm) override; + CODE convertdBmToSignalStrength(const int32_t& dBm, int32_t& iRssi) override; + CODE setMdn(const Json::Value& jArgs) override; protected: diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index ee4e9ec..c6ff5af 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -516,47 +516,6 @@ CellularRadio::CODE CellularRadio::getModemLocation(std::string&) { return FAILURE; } -CellularRadio::CODE CellularRadio::convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& iDbm) { - - //Telit Conversion - if(iRssi < 0 || iRssi == 99) { - return FAILURE; - } - - if(iRssi == 0) { - iDbm = -113; - } else if(iRssi == 1) { - iDbm = -111; - } else if(iRssi <= 30) { - //28 steps between 2 and 30 - //54 dbm between 53 and 109 - float stepSize = 54.0 / 28.0; - iDbm = -109 + (int)(stepSize * (iRssi-2)); - } else { - iDbm = -51; - } - - return SUCCESS; -} - -CellularRadio::CODE CellularRadio::convertdBmToSignalStrength(const int32_t& iDBm, int32_t& iRssi) { - //Telit Conversion - if(iDBm <= -113) { - iRssi = 0; - } else if(iDBm <= -111) { - iRssi = 1; - } else if(iDBm <= -53) { - //54 dbm between -109 and -53 - //28 steps between 2 and 30 - float stepSize = 28.0/54.0; - iRssi = ((iDBm + 109)*stepSize) + 2; - } else { - iRssi = 31; - } - - return SUCCESS; -} - CellularRadio::CODE CellularRadio::getEcho(bool& bEnabled) { printTrace("%s| Echo Test", m_sName.c_str()); std::string sResult = sendCommand("AT"); diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp index 7f9de63..bfcb42e 100644 --- a/src/MTS_IO_TelitRadio.cpp +++ b/src/MTS_IO_TelitRadio.cpp @@ -449,6 +449,47 @@ std::string TelitRadio::queryCGREGstring() { return cmdResult; } +CellularRadio::CODE TelitRadio::convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& iDbm) { + + //Telit Conversion + if(iRssi < 0 || iRssi == 99) { + return FAILURE; + } + + if(iRssi == 0) { + iDbm = -113; + } else if(iRssi == 1) { + iDbm = -111; + } else if(iRssi <= 30) { + //28 steps between 2 and 30 + //54 dbm between 53 and 109 + float stepSize = 54.0 / 28.0; + iDbm = -109 + (int)(stepSize * (iRssi-2)); + } else { + iDbm = -51; + } + + return SUCCESS; +} + +CellularRadio::CODE TelitRadio::convertdBmToSignalStrength(const int32_t& iDBm, int32_t& iRssi) { + //Telit Conversion + if(iDBm <= -113) { + iRssi = 0; + } else if(iDBm <= -111) { + iRssi = 1; + } else if(iDBm <= -53) { + //54 dbm between -109 and -53 + //28 steps between 2 and 30 + float stepSize = 28.0/54.0; + iRssi = ((iDBm + 109)*stepSize) + 2; + } else { + iRssi = 31; + } + + return SUCCESS; +} + CellularRadio::CODE TelitRadio::setMdn(const Json::Value& jArgs) { printTrace("%s| Set MDN", getName().c_str()); -- cgit v1.2.3 From fe1c1e2e87da96fbbc432a35a903fff40f52713a Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Tue, 11 Jun 2019 16:47:11 +0300 Subject: [MTS-MTQ] refactoring: cellular factory namespaces --- include/mts/MTS_IO_ICellularRadio.h | 2 -- src/MTS_IO_CellularRadioFactory.cpp | 12 ++++++------ src/MTS_IO_TelitRadio.cpp | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h index 11ad193..d74ad15 100644 --- a/include/mts/MTS_IO_ICellularRadio.h +++ b/include/mts/MTS_IO_ICellularRadio.h @@ -60,7 +60,6 @@ namespace MTS { NOT_INSERTED }; - // TODO: convert functions static CODE convertModelToType(const std::string& sModel, std::string& sType); static CODE convertModelToMtsShortCode(const std::string& sModel, std::string& sCode, ICellularRadio *radioObj = NULL); static CODE convertServiceDomainToString(SERVICEDOMAIN eSd, std::string& sSd); @@ -79,7 +78,6 @@ namespace MTS { static CODE test(MTS::AutoPtr& apIo, uint32_t timeoutSeconds = 30); static std::string extractModelFromResult(const std::string& sResult); static std::string getCodeAsString(CODE code); - // XXX static const char *DEFAULT_RADIO_PORT; static const char *DEFAULT_RADIO_DIR; diff --git a/src/MTS_IO_CellularRadioFactory.cpp b/src/MTS_IO_CellularRadioFactory.cpp index 0c64221..146b112 100644 --- a/src/MTS_IO_CellularRadioFactory.cpp +++ b/src/MTS_IO_CellularRadioFactory.cpp @@ -87,14 +87,14 @@ std::string CellularRadioFactory::identifyRadio(const std::string& sPort) { apIo.reset(new SerialConnection(SerialConnection::Builder(sPort).baudRate(115200).useLockFile().build())); while(!apIo->open(30000)) { printError("CellularRadioFactory| Failed to open radio port [%s]", sPort.c_str()); - return TelitRadio::VALUE_UNKNOWN; + return ICellularRadio::VALUE_UNKNOWN; } //Attempt basic radio communication - if(TelitRadio::test(apIo) != TelitRadio::SUCCESS) { + if(ICellularRadio::test(apIo) != ICellularRadio::SUCCESS) { printError("CellularRadioFactory| Failed to communicate with radio on port [%s]", sPort.c_str()); apIo->close(); - return TelitRadio::VALUE_UNKNOWN; + return ICellularRadio::VALUE_UNKNOWN; } //Get model @@ -102,7 +102,7 @@ std::string CellularRadioFactory::identifyRadio(const std::string& sPort) { std::string sCmd("ATI4"); std::string sResult; do { - sResult = ICellularRadio::sendCommand(apIo, sCmd, TelitRadio::DEFAULT_BAIL_STRINGS, 1000, TelitRadio::CR); + sResult = ICellularRadio::sendCommand(apIo, sCmd, ICellularRadio::DEFAULT_BAIL_STRINGS, 1000, ICellularRadio::CR); if (sResult.find("OK") == std::string::npos) { printDebug("RADIO| Attempting to get radio model [%s] ...", sResult.c_str()); } else { @@ -114,10 +114,10 @@ std::string CellularRadioFactory::identifyRadio(const std::string& sPort) { if(count == 30) { printDebug("RADIO| Unable to get radio model"); apIo->close(); - return TelitRadio::VALUE_UNKNOWN; + return ICellularRadio::VALUE_UNKNOWN; } - std::string sModel = TelitRadio::extractModelFromResult(sResult); + std::string sModel = ICellularRadio::extractModelFromResult(sResult); printDebug("RADIO| Extracted [%s] from ATI4 query", sModel.c_str()); apIo->close(); return sModel; diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp index 6ce240e..ee96ff2 100644 --- a/src/MTS_IO_TelitRadio.cpp +++ b/src/MTS_IO_TelitRadio.cpp @@ -56,7 +56,7 @@ CellularRadio::CODE TelitRadio::getModel(std::string& sModel) { printWarning("%s| Unable to get model from radio. Returning [%s]", getName().c_str(), getName().c_str()); return SUCCESS; } else { - sModel = CellularRadio::extractModelFromResult(sResult); + sModel = extractModelFromResult(sResult); if(sModel.size() == 0) { printWarning("%s| Unable to get model from radio. Returning [%s]", getName().c_str(), getName().c_str()); return SUCCESS; -- cgit v1.2.3 From 2fe0784ab57aa5571e5cd70c1776eecda635b3c0 Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Tue, 11 Jun 2019 16:49:09 +0300 Subject: [MTS-MTQ] cellular factory: quectel eg95 instance creation --- include/mts/MTS_IO_CellularRadioFactory.h | 1 + include/mts/MTS_IO_EG95Radio.h | 2 ++ src/MTS_IO_CellularRadioFactory.cpp | 9 +++++++++ src/MTS_IO_EG95Radio.cpp | 4 ++++ src/MTS_IO_ICellularRadio.cpp | 2 ++ 5 files changed, 18 insertions(+) diff --git a/include/mts/MTS_IO_CellularRadioFactory.h b/include/mts/MTS_IO_CellularRadioFactory.h index c26e642..bd5db43 100644 --- a/include/mts/MTS_IO_CellularRadioFactory.h +++ b/include/mts/MTS_IO_CellularRadioFactory.h @@ -55,6 +55,7 @@ namespace MTS { virtual ICellularRadio* createDE910(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); virtual ICellularRadio* createCE910(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); virtual ICellularRadio* createLE866A1JS(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + ICellularRadio* createEG95Radio(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); protected: typedef MTS::IO::ICellularRadio* (CellularRadioFactory::*CREATEFUNCPTR)(const std::string& sPort); diff --git a/include/mts/MTS_IO_EG95Radio.h b/include/mts/MTS_IO_EG95Radio.h index 07db773..206d15d 100644 --- a/include/mts/MTS_IO_EG95Radio.h +++ b/include/mts/MTS_IO_EG95Radio.h @@ -7,6 +7,8 @@ namespace MTS { namespace IO { class EG95Radio : public QuectelRadio { + public: + static const std::string MODEL_NAME; }; } diff --git a/src/MTS_IO_CellularRadioFactory.cpp b/src/MTS_IO_CellularRadioFactory.cpp index 146b112..8b2353a 100644 --- a/src/MTS_IO_CellularRadioFactory.cpp +++ b/src/MTS_IO_CellularRadioFactory.cpp @@ -37,6 +37,7 @@ #include #include #include +#include "mts/MTS_IO_EG95Radio.h" #include using namespace MTS::IO; @@ -60,6 +61,7 @@ CellularRadioFactory::CellularRadioFactory() { m_mCreationMap[DE910Radio::MODEL_NAME] = &CellularRadioFactory::createDE910; m_mCreationMap[CE910Radio::MODEL_NAME] = &CellularRadioFactory::createCE910; m_mCreationMap[LE866A1JSRadio::MODEL_NAME] = &CellularRadioFactory::createLE866A1JS; + m_mCreationMap[EG95Radio::MODEL_NAME] = &CellularRadioFactory::createEG95Radio; } ICellularRadio* CellularRadioFactory::create(const std::string& sModel, const std::string& sPort) { @@ -194,3 +196,10 @@ ICellularRadio* CellularRadioFactory::createCE910(const std::string& sPort) { ICellularRadio* CellularRadioFactory::createLE866A1JS(const std::string &sPort) { return new LE866A1JSRadio(sPort); } + +ICellularRadio* CellularRadioFactory::createEG95Radio(const std::string& sPort) +{ + // TODO: return new EG95Radio(sPort); + printError("TODO: EG95Radio"); + return new HE910DRadio(sPort); +} diff --git a/src/MTS_IO_EG95Radio.cpp b/src/MTS_IO_EG95Radio.cpp index 2fca48f..6feee41 100644 --- a/src/MTS_IO_EG95Radio.cpp +++ b/src/MTS_IO_EG95Radio.cpp @@ -1 +1,5 @@ #include "mts/MTS_IO_EG95Radio.h" + +using namespace MTS::IO; + +const std::string EG95Radio::MODEL_NAME("EG95"); diff --git a/src/MTS_IO_ICellularRadio.cpp b/src/MTS_IO_ICellularRadio.cpp index 58ccb2b..2f19f3a 100644 --- a/src/MTS_IO_ICellularRadio.cpp +++ b/src/MTS_IO_ICellularRadio.cpp @@ -419,6 +419,8 @@ std::string MTS::IO::ICellularRadio::extractModelFromResult(const std::string& s sModel = "DE910-DUAL"; } else if(sResult.find("CE910") != std::string::npos) { sModel = "CE910"; + } else if(sResult.find("EG95") != std::string::npos) { + sModel = "EG95"; } return sModel; } -- cgit v1.2.3 From 1dae6b4045d1683c4410d5a2b0c315574ece7d01 Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Tue, 11 Jun 2019 16:53:40 +0300 Subject: [MTS-MTQ] cellular factory: radio identification by AT+GMM --- src/MTS_IO_CellularRadioFactory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MTS_IO_CellularRadioFactory.cpp b/src/MTS_IO_CellularRadioFactory.cpp index 8b2353a..47367eb 100644 --- a/src/MTS_IO_CellularRadioFactory.cpp +++ b/src/MTS_IO_CellularRadioFactory.cpp @@ -101,7 +101,7 @@ std::string CellularRadioFactory::identifyRadio(const std::string& sPort) { //Get model int count = 0; - std::string sCmd("ATI4"); + std::string sCmd("AT+GMM"); std::string sResult; do { sResult = ICellularRadio::sendCommand(apIo, sCmd, ICellularRadio::DEFAULT_BAIL_STRINGS, 1000, ICellularRadio::CR); @@ -120,7 +120,7 @@ std::string CellularRadioFactory::identifyRadio(const std::string& sPort) { } std::string sModel = ICellularRadio::extractModelFromResult(sResult); - printDebug("RADIO| Extracted [%s] from ATI4 query", sModel.c_str()); + printDebug("RADIO| Extracted [%s] from AT+GMM query", sModel.c_str()); apIo->close(); return sModel; } -- cgit v1.2.3 From 5c8318bea803966f5b883c986919787e77e514a5 Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Tue, 11 Jun 2019 16:55:28 +0300 Subject: [MTS-MTQ] refactoring cellular factory: non interface class shouldn't have such virtual methods --- include/mts/MTS_IO_CellularRadioFactory.h | 44 +++++++++++++++---------------- src/MTS_IO_CellularRadioFactory.cpp | 38 +++++++++++++------------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/include/mts/MTS_IO_CellularRadioFactory.h b/include/mts/MTS_IO_CellularRadioFactory.h index bd5db43..c9cb56f 100644 --- a/include/mts/MTS_IO_CellularRadioFactory.h +++ b/include/mts/MTS_IO_CellularRadioFactory.h @@ -35,30 +35,30 @@ namespace MTS { CellularRadioFactory(); virtual ~CellularRadioFactory() {}; - virtual ICellularRadio* create(const std::string& sModel, const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - - virtual ICellularRadio* createHE910D(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - virtual ICellularRadio* createHE910EUD(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - virtual ICellularRadio* createLE910NAG(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - virtual ICellularRadio* createLE910C4NF(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - virtual ICellularRadio* createLE910NA1(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - virtual ICellularRadio* createLE910SVG(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - virtual ICellularRadio* createLE910EUG(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - virtual ICellularRadio* createLE910C4EU(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - virtual ICellularRadio* createLE910EU1(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - virtual ICellularRadio* createLE910C1NS(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - virtual ICellularRadio* createLE910C1AP(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - virtual ICellularRadio* createME910C1NA(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - virtual ICellularRadio* createME910C1NV(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - virtual ICellularRadio* createME910C1WW(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - virtual ICellularRadio* createGE910(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - virtual ICellularRadio* createDE910(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - virtual ICellularRadio* createCE910(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - virtual ICellularRadio* createLE866A1JS(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); - ICellularRadio* createEG95Radio(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + ICellularRadio* create(const std::string& sModel, const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT); + + ICellularRadio* createHE910D(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createHE910EUD(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createLE910NAG(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createLE910C4NF(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createLE910NA1(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createLE910SVG(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createLE910EUG(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createLE910C4EU(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createLE910EU1(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createLE910C1NS(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createLE910C1AP(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createME910C1NA(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createME910C1NV(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createME910C1WW(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createGE910(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createDE910(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createCE910(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createLE866A1JS(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createEG95Radio(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; protected: - typedef MTS::IO::ICellularRadio* (CellularRadioFactory::*CREATEFUNCPTR)(const std::string& sPort); + typedef MTS::IO::ICellularRadio* (CellularRadioFactory::*CREATEFUNCPTR)(const std::string& sPort) const; std::map< std::string, CREATEFUNCPTR > m_mCreationMap; virtual std::string identifyRadio(const std::string& sPort); diff --git a/src/MTS_IO_CellularRadioFactory.cpp b/src/MTS_IO_CellularRadioFactory.cpp index 47367eb..8ebd8dc 100644 --- a/src/MTS_IO_CellularRadioFactory.cpp +++ b/src/MTS_IO_CellularRadioFactory.cpp @@ -125,79 +125,79 @@ std::string CellularRadioFactory::identifyRadio(const std::string& sPort) { return sModel; } -ICellularRadio* CellularRadioFactory::createHE910D(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createHE910D(const std::string& sPort) const { return new HE910DRadio(sPort); } -ICellularRadio* CellularRadioFactory::createHE910EUD(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createHE910EUD(const std::string& sPort) const { return new HE910EUDRadio(sPort); } -ICellularRadio* CellularRadioFactory::createLE910NAG(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createLE910NAG(const std::string& sPort) const { return new LE910NAGRadio(sPort); } -ICellularRadio* CellularRadioFactory::createLE910C4NF(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createLE910C4NF(const std::string& sPort) const { return new LE910C4NFRadio(sPort); } -ICellularRadio* CellularRadioFactory::createLE910NA1(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createLE910NA1(const std::string& sPort) const { return new LE910NA1Radio(sPort); } -ICellularRadio* CellularRadioFactory::createLE910SVG(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createLE910SVG(const std::string& sPort) const { return new LE910SVGRadio(sPort); } -ICellularRadio* CellularRadioFactory::createLE910EUG(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createLE910EUG(const std::string& sPort) const { return new LE910EUGRadio(sPort); } -ICellularRadio* CellularRadioFactory::createLE910C4EU(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createLE910C4EU(const std::string& sPort) const { return new LE910C4EURadio(sPort); } -ICellularRadio* CellularRadioFactory::createLE910EU1(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createLE910EU1(const std::string& sPort) const { return new LE910EU1Radio(sPort); } -ICellularRadio* CellularRadioFactory::createLE910C1NS(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createLE910C1NS(const std::string& sPort) const { return new LE910C1NSRadio(sPort); } -ICellularRadio* CellularRadioFactory::createLE910C1AP(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createLE910C1AP(const std::string& sPort) const { return new LE910C1APRadio(sPort); } -ICellularRadio* CellularRadioFactory::createME910C1NA(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createME910C1NA(const std::string& sPort) const { return new ME910C1NARadio(sPort); } -ICellularRadio* CellularRadioFactory::createME910C1NV(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createME910C1NV(const std::string& sPort) const { return new ME910C1NVRadio(sPort); } -ICellularRadio* CellularRadioFactory::createME910C1WW(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createME910C1WW(const std::string& sPort) const { return new ME910C1WWRadio(sPort); } -ICellularRadio* CellularRadioFactory::createGE910(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createGE910(const std::string& sPort) const { return new GE910Radio(sPort); } -ICellularRadio* CellularRadioFactory::createDE910(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createDE910(const std::string& sPort) const { return new DE910Radio(sPort); } -ICellularRadio* CellularRadioFactory::createCE910(const std::string& sPort) { +ICellularRadio* CellularRadioFactory::createCE910(const std::string& sPort) const { return new CE910Radio(sPort); } -ICellularRadio* CellularRadioFactory::createLE866A1JS(const std::string &sPort) { +ICellularRadio* CellularRadioFactory::createLE866A1JS(const std::string &sPort) const { return new LE866A1JSRadio(sPort); } -ICellularRadio* CellularRadioFactory::createEG95Radio(const std::string& sPort) +ICellularRadio* CellularRadioFactory::createEG95Radio(const std::string& sPort) const { // TODO: return new EG95Radio(sPort); printError("TODO: EG95Radio"); -- cgit v1.2.3 From 38039fe0c4fcc44bdf2534f1f8f4b95de54e14a4 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Tue, 11 Jun 2019 16:57:22 +0300 Subject: [MTS-MTQ] QuectelRadio implementation Removed copies of the following functions: - TelitRadio::queryLteLac - TelitRadio::setCGREG - TelitRadio::queryCGREGstring Those functions are already implemented in the CellularRadio class. Their implementation is common for both Telit and Quectel. There is no need to override them in TelitRadio. --- include/mts/MTS_IO_TelitRadio.h | 6 ++--- src/MTS_IO_TelitRadio.cpp | 53 ----------------------------------------- 2 files changed, 2 insertions(+), 57 deletions(-) diff --git a/include/mts/MTS_IO_TelitRadio.h b/include/mts/MTS_IO_TelitRadio.h index 7162dfb..70ff8a9 100644 --- a/include/mts/MTS_IO_TelitRadio.h +++ b/include/mts/MTS_IO_TelitRadio.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 by Multi-Tech Systems + * Copyright (C) 2019 by Multi-Tech Systems * * This file is part of libmts-io. * @@ -47,9 +47,7 @@ namespace MTS { bool getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware) override; private: - std::string queryLteLac(); - std::string queryCGREGstring(); - void setCGREG(std::string value); + }; } } diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp index bfcb42e..8f747f8 100644 --- a/src/MTS_IO_TelitRadio.cpp +++ b/src/MTS_IO_TelitRadio.cpp @@ -396,59 +396,6 @@ CellularRadio::CODE TelitRadio::getNetworkStatus(Json::Value& jData) { return SUCCESS; } - -// Get the LAC for the LTE radio that's not in the #RFSTS response -std::string TelitRadio::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)), ","); - if(vParts.size() < 3) { - result = CellularRadio::VALUE_UNAVAILABLE; - } else { - result = MTS::Text::strip(vParts[2], '"'); - } - } - - setCGREG(originalCGREG); - - return result; -} - -void TelitRadio::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]", getName().c_str(), value.c_str(), sCmd.c_str(), cmdResult.c_str()); - } -} - -std::string TelitRadio::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]", getName().c_str(), sCmd.c_str(), cmdResult.c_str()); - return RSP_ERROR; - } - return cmdResult; -} - CellularRadio::CODE TelitRadio::convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& iDbm) { //Telit Conversion -- cgit v1.2.3 From 20471af5d887ab2255716c734661abb95953676c Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Tue, 11 Jun 2019 18:19:36 +0300 Subject: [MTS-MTQ] QuectelRadio implementation Added the full implementation of QuectelRadio class. Ported the changes from a local branch to the new libmts-io architecture. --- include/mts/MTS_IO_QuectelRadio.h | 55 ++++- src/MTS_IO_QuectelRadio.cpp | 442 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 492 insertions(+), 5 deletions(-) diff --git a/include/mts/MTS_IO_QuectelRadio.h b/include/mts/MTS_IO_QuectelRadio.h index 55eac60..b486323 100644 --- a/include/mts/MTS_IO_QuectelRadio.h +++ b/include/mts/MTS_IO_QuectelRadio.h @@ -1,15 +1,60 @@ -#ifndef MTS_IO_QUECTELRADIO_H -#define MTS_IO_QUECTELRADIO_H +/* + * Copyright (C) 2019 by Multi-Tech Systems + * + * This file is part of libmts-io. + * + * libmts-io is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts-io is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts-io. If not, see . + * + */ + +#ifndef MTS_IO_QUECTELRADIO_H_ +#define MTS_IO_QUECTELRADIO_H_ #include namespace MTS { namespace IO { - class QuectelRadio : public CellularRadio - { + + class QuectelRadio : public CellularRadio { + + public: + bool resetRadio(uint32_t iTimeoutMillis = 5000) override; + + CODE getModel(std::string& sModel) override; + CODE getIccid(std::string& sIccid) override; + CODE getService(std::string& sService) override; + CODE getNetwork(std::string& sNetwork) override; + CODE getNetworkStatus(Json::Value& jData) override; + + CODE convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& dBm) override; + CODE convertdBmToSignalStrength(const int32_t& dBm, int32_t& iRssi) override; + + CODE setMdn(const Json::Value& jArgs) override; + + protected: + QuectelRadio(const std::string& sName, const std::string& sRadioPort); + + bool getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier) override; + bool getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware) override; + + virtual CODE getServiceDomain(SERVICEDOMAIN& sd); + virtual CODE convertToActiveBand(const std::string& sQuectelBand, ACTIVEBAND& band); + + private: }; } } -#endif +#endif /* MTS_IO_QUECTELRADIO_H_ */ diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 365bbca..597bdac 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -1 +1,443 @@ +/* + * Copyright (C) 2019 by Multi-Tech Systems + * + * This file is part of libmts-io. + * + * libmts-io is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts-io is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts-io. If not, see . + * + */ + #include "mts/MTS_IO_QuectelRadio.h" + +#include +#include +#include + +using namespace MTS::IO; + +QuectelRadio::QuectelRadio(const std::string& sName, const std::string& sRadioPort) +: CellularRadio (sName, sRadioPort) +{ +} + +bool QuectelRadio::resetRadio(uint32_t iTimeoutMillis) { + printInfo("%s| Rebooting radio", getName().c_str()); + if(sendBasicCommand("AT+CFUN=1,1") == SUCCESS) { + if(iTimeoutMillis > 5000) { + MTS::Thread::sleep(5000); + iTimeoutMillis -= 5000; + } + return resetConnection(iTimeoutMillis); + } + + return false; +} + +CellularRadio::CODE QuectelRadio::getModel(std::string& sModel) { + printTrace("%s| Get Model", getName().c_str()); + //Always returns SUCCESS because the model should be m_sName + sModel = getName(); + std::string sCmd("AT+GMM"); + std::string sResult = sendCommand(sCmd); + if (sResult.find("OK") == std::string::npos) { + printWarning("%s| Unable to get model from radio. Returning [%s]", getName().c_str(), getName().c_str()); + return SUCCESS; + } else { + sModel = extractModelFromResult(sResult); + if(sModel.size() == 0) { + printWarning("%s| Unable to get model from radio. Returning [%s]", getName().c_str(), getName().c_str()); + return SUCCESS; + } + } + + printDebug("%s| Extracted [%s] from [%s] query", getName().c_str(), sModel.c_str(), sCmd.c_str()); + if(sModel != getName()) { + printWarning("%s| Model identified [%s] does not match expected [%s]. Returning [%s]", + getName().c_str(), sModel.c_str(), getName().c_str(), sModel.c_str()); + } + + return SUCCESS; +} + +CellularRadio::CODE QuectelRadio::getIccid(std::string& sIccid) { + printTrace("%s| Get ICCID", getName().c_str()); + sIccid = VALUE_NOT_SUPPORTED; + std::string sCmd("AT+QCCID"); + std::string sResult = CellularRadio::sendCommand(sCmd); + size_t end = sResult.find(RSP_OK); + if (end == std::string::npos) { + printWarning("%s| Unable to get ICCID from radio using command [%s]", getName().c_str(), sCmd.c_str()); + return FAILURE; + } + + size_t start = sResult.find("+QCCID:"); + if(start != std::string::npos) { + start += sizeof("+QCCID:"); + sIccid = MTS::Text::trim(sResult.substr(start, end-start)); + if(sIccid.size() == 0) { + printWarning("%s| Unable to get ICCID from radio using command [%s]", getName().c_str(), sCmd.c_str()); + return FAILURE; + } + } + return SUCCESS; +} + +CellularRadio::CODE QuectelRadio::getService(std::string& sService) { + printTrace("%s| Get Service", getName().c_str()); + sService = VALUE_NOT_SUPPORTED; + std::string sCmd("AT+COPS?"); + std::string sResult = CellularRadio::sendCommand(sCmd); + size_t end = sResult.find(RSP_OK); + if (end == std::string::npos) { + printWarning("%s| Unable to get Service from radio using command [%s]", getName().c_str(), sCmd.c_str()); + return FAILURE; + } + + // +COPS: [,[,][,]] + int32_t iAccessTechnology = -1; + sscanf(sResult.c_str(), "%*d,%*d,%*s,%d", &iAccessTechnology); + + switch(iAccessTechnology) { + case 0 : sService = "GPRS" ; break; // GSM + case 2 : sService = "WCDMA" ; break; // UTRAN + case 3 : sService = "EGPRS" ; break; // GSM W/EGPRS + case 4 : sService = "HSDPA" ; break; // UTRAN W/HSDPA + case 5 : sService = "WCDMA" ; break; // UTRAN W/HSUPA + case 6 : sService = "HSDPA" ; break; // UTRAN W/HSDPA and HSUPA + case 7 : sService = "LTE" ; break; // E-UTRAN + case 100 : sService = "CDMA" ; break; // CDMA + + default: sService = VALUE_UNKNOWN; break; + } + + printDebug("%s| Service ID: [%d][%s]", getName().c_str(), iAccessTechnology, sService.c_str()); + + return SUCCESS; +} + +CellularRadio::CODE QuectelRadio::getNetwork(std::string& sNetwork) { + /* + * TODO: Refactor using MccMncTable once it'll be corrected. + * + * The proper way to determine the current network is to do that + * by MCC and MNC fetched from the `getNetworkStatus` and `AT+QENG` command. + * By using MCC and MNC from `AT+QENG` we can fetch the name of the network + * reported by a currently connected base station even if the SIM card is + * not installed or if we are currently working is a roaming mode. + * + * Until MccMncTable implementation is not fixed, we are using the name + * of a currently selected operator (AT+COPS). + */ + printTrace("%s| Get Network", getName().c_str()); + sNetwork = VALUE_NOT_SUPPORTED; + std::string sCmd("AT+COPS?"); + std::string sResult = CellularRadio::sendCommand(sCmd); + size_t end = sResult.find(RSP_OK); + + if (end == std::string::npos) { + printWarning("%s| Unable to get network name from radio using command [%s]", getName().c_str(), sCmd.c_str()); + return FAILURE; + } + + // +COPS: [, , ,] + // +COPS: vParts[0],vParts[1],vParts[2],vParts[3] + size_t start = sResult.find(":") + 1; //Position right after "+COPS:" + std::vector vParts = MTS::Text::split(MTS::Text::trim(sResult.substr(start)), ","); + + if(vParts.size() > 3) { + sNetwork = vParts[2]; + } else { + sNetwork = ""; // Not connected to any network + } + + return SUCCESS; +} + +/* AT+QENG="servingcell" - Query the information of serving cells + + (GSM network) + +QENG:"servingscell",,"GSM",,,,,,,,,,,,,,,,,,,,,,,, + + (WCDMA network) + +QENG:"servingcell",,"WCDMA",,,,,,,,,,,,,, + + (LTE Network) + +QENG:"servingcell",,"LTE",,,,,,,,,,,,,,, + + The following modes are NOT currently handled: + - TD-SCDMA mode; + - CDMA mode; + - HDR mode; + - SRLTE mode. + + In the case of TD-SCDMA mode: + +QENG:"servingscell",,"TDSCDMA",,,,,,,, + + In the case of CDMA mode or CDMA+HDR mode: + +QENG:"servingscell",,"CDMA",,,,,,,, + [+QENG:"servingscell",,"HDR",,,,,,,,] + + In the case of SRLTE mode: + +QENG:"servingscell",,"CDMA",,,,,,,, + +QENG:"servingcell",,"LTE",,,,,,,,,,,,,, +*/ +CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { + int32_t iValue; + ACTIVEBAND abnd; + SERVICEDOMAIN sd; + std::string sValue; + const uint32_t GSM_NETWORK_FORMAT = 27; + const uint32_t WCDMA_NETWORK_FORMAT = 17; + const uint32_t LTE_NETWORK_FORMAT = 18; + + printTrace("%s| Get Network Status", getName().c_str()); + + //Always get common network stats because this should never fail + //This way the basic stats are always returned even if AT+QENG fails below + getCommonNetworkStats(jData); + + // IMSI is not provided by AT+QENG. Fetch it separately to keep the same interface + if (getImsi(sValue) == SUCCESS) { + jData[KEY_IMSI] = sValue; + } + + // Network Name is not explicitly provided by AT+QENG. Fetch it separately to keep the same interface + // TODO: Replace with lookup by MCC and MNC once MccMncTable is fixed. + if (getNetwork(sValue) == SUCCESS) { + jData[KEY_NETWORK] = sValue; + } + + // Service Domain is not provided by AT+QENG. Fetch it separately to keep the same interface + if (getServiceDomain(sd) == SUCCESS && convertServiceDomainToString(sd, sValue) == SUCCESS) { + jData[KEY_SD] = sValue; + } + + std::string sCmd; + std::string sResult; + + sCmd = "AT+QENG=\"servingcell\""; + sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 200); + if (sResult.find("+QENG:\"servingscell\"") == std::string::npos) { + printDebug("%s| Network Status command returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), sResult.c_str()); + printTrace("%s| Network Status:\n%s\n", getName().c_str(), jData.toStyledString().c_str()); + return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function + } + + size_t start = sResult.find(":") + 1; //Position right after "+QENG:" + std::vector vParts = MTS::Text::split(MTS::Text::trim(sResult.substr(start)), ","); + Json::Value jDebug; + + if (vParts.size() < 3) { + printDebug("%s| Network Status command reponse is an unknown format: [%s][%s]", getName().c_str(), sCmd.c_str(), sResult.c_str()); + printTrace("%s| Network Status:\n%s\n", getName().c_str(), jData.toStyledString().c_str()); + return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function + } + + // +QENG:"servingscell",,"GSM",,,,,,,,,,,,,,,,,,,,,,,, + // +QENG: [0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13],[14],[15], [16], [17],[18],[19], [20], [21], [22], [23], [24], [25], [26] + if (vParts.size() == GSM_NETWORK_FORMAT ) { + //Parse as GSM Network Format + jData[KEY_MCC] = vParts[3]; + jData[KEY_MNC] = vParts[4]; + jData[KEY_LAC] = vParts[5]; + jData[KEY_CID] = vParts[6]; + jData[KEY_CHANNEL] = vParts[8]; + + if (convertToActiveBand(vParts[9], abnd) == SUCCESS && convertActiveBandToString(abnd, sValue) == SUCCESS) { + jData[KEY_ABND] = sValue; + } + + if (MTS::Text::parse(iValue, vParts[10])) { + // Number format. RX level value for base station selection in dB (see 3GPP 25.304). + // Range: 0-63. Subtracting 111 from the RX level value, a dBm value will be got. + int rssi = iValue - 111; + jData[KEY_RSSIDBM] = MTS::Text::format(rssi); + } + + jData[KEY_TXPWR] = vParts[11]; + + // The following fields can NOT be fetched for Quectel in GSM mode: RAC, MM, RR, NOM + + jData[KEY_DEBUG] = jDebug; + } + + // +QENG:"servingcell",,"WCDMA",,,,,,,,,,,,,, + // +QENG: [0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12],[13], [14], [15], [16] + else if((vParts.size() == WCDMA_NETWORK_FORMAT)) { + //Parse as WCDMA Network Format + jData[KEY_MCC] = vParts[3]; + jData[KEY_MNC] = vParts[4]; + jData[KEY_LAC] = vParts[5]; + jData[KEY_CID] = vParts[6]; + jData[KEY_CHANNEL] = vParts[7]; + jDebug[KEY_PSC] = vParts[8]; + jData[KEY_RAC] = vParts[9]; + jDebug[KEY_RSCP] = vParts[10]; + jDebug[KEY_ECIO] = vParts[11]; + + // The following fields can NOT be fetched for Quectel in WCDMA mode: TXPWR, DRX, MM, RR, NOM, BLER + + // RSSI is not provided by AT+QENG in WCDMA mode. It was filled above by the getCommonNetworkStats + + // BLER is not provided by AT+QENG. Set to constant + jDebug[KEY_BLER] = "000"; + + // Get the radio band given the channel (UARFCN) + RadioBandMap radioBandMap(vParts[7], CellularRadio::VALUE_TYPE_CDMA); + jData[KEY_ABND] = radioBandMap.getRadioBandName(); + + jData[KEY_DEBUG] = jDebug; + } + + // +QENG:"servingcell",,"LTE",,,,,,,,,,,,,,, + // +QENG: [0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17] + else if(vParts.size() == LTE_NETWORK_FORMAT) { + //Parse as LTE Network Format + jData[KEY_MCC] = vParts[4]; + jData[KEY_MNC] = vParts[5]; + jData[KEY_CID] = vParts[6]; + jData[KEY_CHANNEL] = vParts[8]; + jData["tac"] = vParts[12]; + jDebug["rsrp"] = vParts[13]; + jDebug["rsrq"] = vParts[14]; + jData[KEY_RSSIDBM] = vParts[15]; + + // Get the radio band given the channel (EARFCN) + RadioBandMap radioBandMap(vParts[8], CellularRadio::VALUE_TYPE_LTE); + jData[KEY_ABND] = radioBandMap.getRadioBandName(); + + // LAC is not provided by AT+QENG in WCDMA mode. Use another command instead + jData[KEY_LAC] = queryLteLac(); + + jData[KEY_DEBUG] = jDebug; + } + + printTrace("%s| Network Status:\n%s\n", getName().c_str(), jData.toStyledString().c_str()); + return SUCCESS; +} + +CellularRadio::CODE QuectelRadio::convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& iDbm) { + int dbmSteps, minValue, maxValue, rssiOffset; + int rawDbm; + + if(iRssi >= 0 && iRssi < 99) { + // normal scaling + dbmSteps = 2; + minValue = -113; + maxValue = -51; + rssiOffset = 0; + } else if(iRssi >= 100 && iRssi < 199) { + // TD-SCDMA scaling + dbmSteps = 1; + minValue = -116; + maxValue = -25; + rssiOffset = 100; + } else { + return FAILURE; // invalid, not known or not detectable + } + + rawDbm = minValue + ((iRssi - rssiOffset) * dbmSteps); + iDbm = std::min(maxValue, rawDbm); + + return SUCCESS; +} + +CellularRadio::CODE QuectelRadio::convertdBmToSignalStrength(const int32_t& iDBm, int32_t& iRssi) { + //Quectel Conversion FOR NORMAL SCALING + const int dbmSteps = 2; + const int minValue = -113; + const int rssiOffset = 0; + + if (iDBm < -113) { + iRssi = 0; + } else if (iDBm > -51) { + iRssi = 31; + } else { + iRssi = ((iDBm - minValue) / dbmSteps) + rssiOffset; + } + + return SUCCESS; +} + +CellularRadio::CODE QuectelRadio::setMdn(const Json::Value& jArgs) { + printTrace("%s| Set MDN", getName().c_str()); + return NOT_APPLICABLE; +} + +CellularRadio::CODE QuectelRadio::getServiceDomain(CellularRadio::SERVICEDOMAIN& sd) { + printTrace("%s| Get Service Domain", getName().c_str()); + + std::string sCmd("AT+QCFG=\"servicedomain\""); + std::string sResult = CellularRadio::sendCommand(sCmd); + size_t end = sResult.find(RSP_OK); + + if (end == std::string::npos) { + printWarning("%s| Unable to get service domain using command [%s]", getName().c_str(), sCmd.c_str()); + return FAILURE; + } + + // +QCFG: "servicedomain", + size_t start = sResult.find(",") + 1; // Position right after comma + std::string sServiceDomain = MTS::Text::trim(sResult.substr(start, end)); + int iValue = -1; + + if (!MTS::Text::parse(iValue, sServiceDomain)) { + printWarning("%s| Failed to parse service domain from command output [%s]", getName().c_str(), sCmd.c_str()); + return FAILURE; + } + + switch (iValue) { + case 0: sd = SERVICEDOMAIN::CS_ONLY; break; + case 1: sd = SERVICEDOMAIN::PS_ONLY; break; + case 2: sd = SERVICEDOMAIN::CSPS; break; + + default: return FAILURE; // Unknown + } + + return SUCCESS; +} + +bool QuectelRadio::getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier) { + // TODO: Implement properly if needed + // This function is used only in CdmaRadio implementation but was defined in + // the CellularRadio class before refactoring. + + // Find out if and how we can determine the operator by firmware version. + + return false; +} + +bool QuectelRadio::getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware) { + // TODO: Implement properly + // Find out if and how we can extract the hardware version from firmware version on Quectel devices + + return false; +} + +CellularRadio::CODE QuectelRadio::convertToActiveBand(const std::string& sQuectelBand, CellularRadio::ACTIVEBAND& band) { + int iQuectelBand = -1; + + if (!MTS::Text::parse(iQuectelBand, sQuectelBand)) { + return FAILURE; // probably "-", other band + } + + switch (iQuectelBand) { + case 0: band = ACTIVEBAND::DCS_1800; break; + case 1: band = ACTIVEBAND::PCS_1900; break; + + default: return FAILURE; // actually, this case should never happen + } + + return SUCCESS; +} -- cgit v1.2.3 From 2dad34c7a24430ed8c55079405e2988d5a35cd87 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Tue, 11 Jun 2019 18:24:23 +0300 Subject: [MTS-MTQ] QuectelRadio implementation Modified QuectelRadio::getNetworkStatus to populate Quectel-specific debug information. Added as a separate commit for simple reverts --- src/MTS_IO_QuectelRadio.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 597bdac..3f108e6 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -237,11 +237,16 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { size_t start = sResult.find(":") + 1; //Position right after "+QENG:" std::vector vParts = MTS::Text::split(MTS::Text::trim(sResult.substr(start)), ","); Json::Value jDebug; + Json::Value jQuectelDebug; if (vParts.size() < 3) { printDebug("%s| Network Status command reponse is an unknown format: [%s][%s]", getName().c_str(), sCmd.c_str(), sResult.c_str()); printTrace("%s| Network Status:\n%s\n", getName().c_str(), jData.toStyledString().c_str()); return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function + } else { + // UE state and Access technology, Quectel-specific information + jQuectelDebug["state"] = vParts[1]; + jQuectelDebug["rat"] = vParts[2]; } // +QENG:"servingscell",,"GSM",,,,,,,,,,,,,,,,,,,,,,,, @@ -252,6 +257,7 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { jData[KEY_MNC] = vParts[4]; jData[KEY_LAC] = vParts[5]; jData[KEY_CID] = vParts[6]; + jQuectelDebug["bsic"] = vParts[7]; jData[KEY_CHANNEL] = vParts[8]; if (convertToActiveBand(vParts[9], abnd) == SUCCESS && convertActiveBandToString(abnd, sValue) == SUCCESS) { @@ -266,9 +272,25 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { } jData[KEY_TXPWR] = vParts[11]; + jQuectelDebug["rla"] = vParts[12]; + jQuectelDebug["drx"] = vParts[13]; + jQuectelDebug["c1"] = vParts[14]; + jQuectelDebug["c2"] = vParts[15]; + jQuectelDebug["gprs"] = vParts[16]; + jQuectelDebug["tch"] = vParts[17]; + jQuectelDebug["ts"] = vParts[18]; + jQuectelDebug["ta"] = vParts[19]; + jQuectelDebug["maio"] = vParts[20]; + jQuectelDebug["hsn"] = vParts[21]; + jQuectelDebug["rxlevsub"] = vParts[22]; + jQuectelDebug["rxlevfull"] = vParts[23]; + jQuectelDebug["rxqualsub"] = vParts[24]; + jQuectelDebug["rxqualfull"] = vParts[25]; + jQuectelDebug["voicecodec"] = vParts[26]; // The following fields can NOT be fetched for Quectel in GSM mode: RAC, MM, RR, NOM + jData["quectelDebug"] = jQuectelDebug; jData[KEY_DEBUG] = jDebug; } @@ -285,6 +307,11 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { jData[KEY_RAC] = vParts[9]; jDebug[KEY_RSCP] = vParts[10]; jDebug[KEY_ECIO] = vParts[11]; + jQuectelDebug["phych"] = vParts[12]; + jQuectelDebug["sf"] = vParts[13]; + jQuectelDebug["slot"] = vParts[14]; + jQuectelDebug["speechCode"] = vParts[15]; + jQuectelDebug["comMod"] = vParts[16]; // The following fields can NOT be fetched for Quectel in WCDMA mode: TXPWR, DRX, MM, RR, NOM, BLER @@ -297,6 +324,7 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { RadioBandMap radioBandMap(vParts[7], CellularRadio::VALUE_TYPE_CDMA); jData[KEY_ABND] = radioBandMap.getRadioBandName(); + jData["quectelDebug"] = jQuectelDebug; jData[KEY_DEBUG] = jDebug; } @@ -304,14 +332,21 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { // +QENG: [0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17] else if(vParts.size() == LTE_NETWORK_FORMAT) { //Parse as LTE Network Format + jQuectelDebug["isTdd"] = vParts[3]; jData[KEY_MCC] = vParts[4]; jData[KEY_MNC] = vParts[5]; jData[KEY_CID] = vParts[6]; + jQuectelDebug["pcid"] = vParts[7]; jData[KEY_CHANNEL] = vParts[8]; + jQuectelDebug["freqBandInd"] = vParts[9]; + jQuectelDebug["ulBandwidth"] = vParts[10]; + jQuectelDebug["dlBandwidth"] = vParts[11]; jData["tac"] = vParts[12]; jDebug["rsrp"] = vParts[13]; jDebug["rsrq"] = vParts[14]; jData[KEY_RSSIDBM] = vParts[15]; + jQuectelDebug["sinr"] = vParts[16]; + jQuectelDebug["srxlev"] = vParts[17]; // Get the radio band given the channel (EARFCN) RadioBandMap radioBandMap(vParts[8], CellularRadio::VALUE_TYPE_LTE); @@ -320,6 +355,7 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { // LAC is not provided by AT+QENG in WCDMA mode. Use another command instead jData[KEY_LAC] = queryLteLac(); + jData["quectelDebug"] = jQuectelDebug; jData[KEY_DEBUG] = jDebug; } -- cgit v1.2.3 From c316cdffa1749a17b7f106ea526ac2288074920b Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Wed, 12 Jun 2019 09:42:22 +0300 Subject: [MTS-MTQ] QuectelRadio implementation Added a proper implementation of the EG95Radio class --- include/mts/MTS_IO_EG95Radio.h | 44 +++++++++++++++++++++++++++++++++++------- src/MTS_IO_EG95Radio.cpp | 44 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 8 deletions(-) diff --git a/include/mts/MTS_IO_EG95Radio.h b/include/mts/MTS_IO_EG95Radio.h index 206d15d..f3021cc 100644 --- a/include/mts/MTS_IO_EG95Radio.h +++ b/include/mts/MTS_IO_EG95Radio.h @@ -1,17 +1,47 @@ -#ifndef MTS_IO_EG95RADIO_H -#define MTS_IO_EG95RADIO_H +/* + * Copyright (C) 2019 by Multi-Tech Systems + * + * This file is part of libmts-io. + * + * libmts-io is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts-io is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts-io. If not, see . + * + */ + + +#ifndef MTS_IO_EG95RADIO_H_ +#define MTS_IO_EG95RADIO_H_ #include "mts/MTS_IO_QuectelRadio.h" namespace MTS { namespace IO { - class EG95Radio : public QuectelRadio - { - public: - static const std::string MODEL_NAME; + + class EG95Radio : public QuectelRadio { + + public: + static const std::string MODEL_NAME; + + EG95Radio(const std::string& sPort); + virtual ~EG95Radio(); + CODE setRxDiversity(const Json::Value& jArgs); + + protected: + + private: }; } } -#endif +#endif /* MTS_IO_EG95RADIO_H_ */ diff --git a/src/MTS_IO_EG95Radio.cpp b/src/MTS_IO_EG95Radio.cpp index 6feee41..8469454 100644 --- a/src/MTS_IO_EG95Radio.cpp +++ b/src/MTS_IO_EG95Radio.cpp @@ -1,5 +1,47 @@ -#include "mts/MTS_IO_EG95Radio.h" +/* + * Copyright (C) 2019 by Multi-Tech Systems + * + * This file is part of libmts-io. + * + * libmts-io is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts-io is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts-io. If not, see . + * + */ + + +#include using namespace MTS::IO; const std::string EG95Radio::MODEL_NAME("EG95"); + +EG95Radio::EG95Radio(const std::string& sPort) +: QuectelRadio(MODEL_NAME, sPort) +{ + +} + +EG95Radio::~EG95Radio() { + +} + +EG95Radio::CODE EG95Radio::setRxDiversity(const Json::Value& jArgs) { + /* Command string for EG95 radios: AT+QCFG="diversity",(0-1) */ + if (jArgs["enabled"].asString() != "1" && jArgs["enabled"].asString() != "0") { + return FAILURE; + } + std::string sCmd = "AT+QCFG=\"diversity\","; + sCmd += jArgs["enabled"].asString(); + + return sendBasicCommand(sCmd); +} -- cgit v1.2.3 From 5649cebb23edc7ef20456e76b959e4a217a08594 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Wed, 12 Jun 2019 09:51:50 +0300 Subject: [MTS-MTQ] QuectelRadio implementation Updated the following functions to support Quectel radios: - CellularRadioFactory::createEG95Radio - fixed to build a EG95Radio instance; - ICellularRadio::extractModelFromResult - returning EG95 for EG95 radios; - ICellularRadio::convertModelToType - returning VALUE_TYPE_LTE for EG95. --- src/MTS_IO_CellularRadioFactory.cpp | 4 +--- src/MTS_IO_ICellularRadio.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/MTS_IO_CellularRadioFactory.cpp b/src/MTS_IO_CellularRadioFactory.cpp index 8ebd8dc..4ee8756 100644 --- a/src/MTS_IO_CellularRadioFactory.cpp +++ b/src/MTS_IO_CellularRadioFactory.cpp @@ -199,7 +199,5 @@ ICellularRadio* CellularRadioFactory::createLE866A1JS(const std::string &sPort) ICellularRadio* CellularRadioFactory::createEG95Radio(const std::string& sPort) const { - // TODO: return new EG95Radio(sPort); - printError("TODO: EG95Radio"); - return new HE910DRadio(sPort); + return new EG95Radio(sPort); } diff --git a/src/MTS_IO_ICellularRadio.cpp b/src/MTS_IO_ICellularRadio.cpp index 2f19f3a..7f216d0 100644 --- a/src/MTS_IO_ICellularRadio.cpp +++ b/src/MTS_IO_ICellularRadio.cpp @@ -181,6 +181,27 @@ MTS::IO::ICellularRadio::CODE MTS::IO::ICellularRadio::convertModelToMtsShortCod } else if (sModel.find("DE910") == 0) { sCode = "EV3"; eCode = SUCCESS; + } else if (sModel.find("EG95") == 0) { + if (NULL == radioObject) { + sCode = VALUE_NOT_SUPPORTED; + eCode = ERROR; + } else { + std::string sValue; + eCode = radioObject->getFirmware(sValue); + if (eCode != SUCCESS) { + sCode = VALUE_NOT_SUPPORTED; + eCode = ERROR; + } else if (sValue.find("EG95E") != std::string::npos) { + sCode = "LEU7"; + eCode = SUCCESS; + } else if (sValue.find("EG95NA") != std::string::npos) { + sCode = "LNA7"; + eCode = SUCCESS; + } else { + sCode = VALUE_NOT_SUPPORTED; + eCode = ERROR; + } + } } else { sCode = VALUE_NOT_SUPPORTED; printError("RADIO| Could not identify MTS short code from model. [%s]", sModel.c_str()); @@ -274,6 +295,9 @@ MTS::IO::ICellularRadio::CODE MTS::IO::ICellularRadio::convertModelToType(const } else if (sModel.find("DE910") == 0) { sType = VALUE_TYPE_CDMA; eCode = SUCCESS; + } else if (sModel.find("EG95") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; } else { sType = VALUE_TYPE_GSM; eCode = ERROR; -- cgit v1.2.3 From 2f451104dc4a5b3459ecf4ffade49efa55e2c454 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Wed, 12 Jun 2019 13:37:45 +0300 Subject: [MTS-MTQ] QuectelRadio implementation Corrected the check for QENG="servingcell" prefix --- src/MTS_IO_QuectelRadio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 3f108e6..414cd98 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -228,7 +228,7 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { sCmd = "AT+QENG=\"servingcell\""; sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 200); - if (sResult.find("+QENG:\"servingscell\"") == std::string::npos) { + if (sResult.find("+QENG: \"servingcell\"") == std::string::npos) { printDebug("%s| Network Status command returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), sResult.c_str()); printTrace("%s| Network Status:\n%s\n", getName().c_str(), jData.toStyledString().c_str()); return SUCCESS; //return SUCCESS because getCommonNetworkStats() succeeded at top of this function -- cgit v1.2.3 From 123aed7c4be0b88a4726cae5d722d74ebdf93782 Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Wed, 12 Jun 2019 15:22:41 +0300 Subject: [MTS-MTQ] refactoring: using full qualified names for consts --- include/mts/MTS_IO_CellularRadio.h | 10 +-- src/MTS_IO_CdmaRadio.cpp | 128 +++++++++++++++---------------- src/MTS_IO_CellularRadio.cpp | 150 ++++++++++++++++++------------------- src/MTS_IO_LE910NA1Radio.cpp | 2 +- src/MTS_IO_ME910C1NVRadio.cpp | 2 +- src/MTS_IO_ME910C1WWRadio.cpp | 2 +- src/MTS_IO_ME910Radio.cpp | 2 +- src/MTS_IO_TelitRadio.cpp | 126 +++++++++++++++---------------- 8 files changed, 211 insertions(+), 211 deletions(-) diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index 0410e0d..acb235b 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -101,19 +101,19 @@ namespace MTS { CODE getEcho(bool& bEnabled) override; CODE setEcho(bool bEnabled = true) override; CODE getStaticInformation(Json::Value& jData) override; - CODE sendBasicCommand(const std::string& sCmd, int32_t timeoutMillis = 100, const char& ESC = CR) override; + CODE sendBasicCommand(const std::string& sCmd, int32_t timeoutMillis = 100, const char& ESC = ICellularRadio::CR) override; std::string sendCommand(const std::string& sCmd, const std::vector& vBail = DEFAULT_BAIL_STRINGS, int32_t timeoutMillis = 100, - const char& ESC = CR) override; + const char& ESC = ICellularRadio::CR) override; std::string sendCommand(const std::string& sCmd, IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis = 100, - const char& ESC = CR) override; + const char& ESC = ICellularRadio::CR) override; protected: @@ -130,9 +130,9 @@ namespace MTS { public: RadioBandMap() { - m_sChannel = CellularRadio::VALUE_UNKNOWN; + m_sChannel = ICellularRadio::VALUE_UNKNOWN; m_iChannel = 0; - m_sRadioType = CellularRadio::VALUE_UNKNOWN; + m_sRadioType = ICellularRadio::VALUE_UNKNOWN; } RadioBandMap(const std::string &channel, const std::string &radioType) : diff --git a/src/MTS_IO_CdmaRadio.cpp b/src/MTS_IO_CdmaRadio.cpp index 4ff5d63..09db89b 100644 --- a/src/MTS_IO_CdmaRadio.cpp +++ b/src/MTS_IO_CdmaRadio.cpp @@ -51,10 +51,10 @@ CdmaRadio::CODE CdmaRadio::getImei(std::string& sImei) { CdmaRadio::CODE CdmaRadio::getMeid(std::string& sMeid) { printTrace("%s| Get MEID", getName().c_str()); - sMeid = VALUE_NOT_SUPPORTED; + sMeid = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT#MEIDESN?"); std::string sResult = sendCommand(sCmd); - size_t pos = sResult.find(RSP_OK); + size_t pos = sResult.find(ICellularRadio::RSP_OK); if (pos == std::string::npos) { printWarning("%s| Unable to get MEID from radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -74,10 +74,10 @@ CdmaRadio::CODE CdmaRadio::getMeid(std::string& sMeid) { CdmaRadio::CODE CdmaRadio::getMsid(std::string& sMsid) { printTrace("%s| Get MSID", getName().c_str()); - sMsid = VALUE_NOT_SUPPORTED; + sMsid = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT$MSID?"); std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get MSID from radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -119,28 +119,28 @@ CdmaRadio::CODE CdmaRadio::getNetwork(std::string& sNetwork) { CdmaRadio::CODE CdmaRadio::getSimStatus(std::string& sSimStatus) { printTrace("%s| Get SIM Status", getName().c_str()); - sSimStatus = VALUE_NOT_SUPPORTED; + sSimStatus = ICellularRadio::VALUE_NOT_SUPPORTED; return NOT_APPLICABLE; } CdmaRadio::CODE CdmaRadio::getIccid(std::string& sIccid) { printTrace("%s| Get ICCID", getName().c_str()); - sIccid = VALUE_NOT_SUPPORTED; + sIccid = ICellularRadio::VALUE_NOT_SUPPORTED; return NOT_APPLICABLE; } CdmaRadio::CODE CdmaRadio::getLac(std::string& sLac) { printTrace("%s| Get LAC", getName().c_str()); - sLac = VALUE_NOT_SUPPORTED; + sLac = ICellularRadio::VALUE_NOT_SUPPORTED; return NOT_APPLICABLE; } CdmaRadio::CODE CdmaRadio::getService(std::string& sService) { printTrace("%s| Get Service", getName().c_str()); - sService = VALUE_NOT_SUPPORTED; + sService = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT+SERVICE?"); std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get Service from radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -159,7 +159,7 @@ CdmaRadio::CODE CdmaRadio::getService(std::string& sService) { case 2: sService = "EVDO"; break; //Release 0 case 3: sService = "EVDO"; break; //Release A case 4: sService = "GPRS"; break; - default: sService = VALUE_UNKNOWN; break; + default: sService = ICellularRadio::VALUE_UNKNOWN; break; } printDebug("%s| Service ID: [%d][%s]", getName().c_str(), iService, sService.c_str()); @@ -169,10 +169,10 @@ CdmaRadio::CODE CdmaRadio::getService(std::string& sService) { CdmaRadio::CODE CdmaRadio::getHardware(std::string& sHardware) { printTrace("%s| Get Hardware", getName().c_str()); - sHardware = VALUE_NOT_SUPPORTED; + sHardware = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT#HWREV"); std::string sResult = sendCommand(sCmd); - size_t pos = sResult.find(RSP_OK); + size_t pos = sResult.find(ICellularRadio::RSP_OK); if (pos == std::string::npos) { printWarning("%s| Unable to get hardware from radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -189,10 +189,10 @@ CdmaRadio::CODE CdmaRadio::getHardware(std::string& sHardware) { CdmaRadio::CODE CdmaRadio::getMdn(std::string& sMdn) { printTrace("%s| Get MDN", getName().c_str()); - sMdn = VALUE_NOT_SUPPORTED; + sMdn = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT+CNUM"); std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get MDN from radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -274,7 +274,7 @@ CdmaRadio::CODE CdmaRadio::setMdn(const Json::Value& jArgs) { sCmd += sMdn; std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to set MDN for radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -309,7 +309,7 @@ CdmaRadio::CODE CdmaRadio::setMsid(const Json::Value& jArgs) { sCmd += jArgs["msid"].asString(); std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to set MSID for radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -329,7 +329,7 @@ CdmaRadio::CODE CdmaRadio::getMipProfile(Json::Value& jMipProfile) { if(sCarrier == "Aeris" || sCarrier == "Sprint") { std::string sCmd("AT$QCMIPGETP"); std::string sResult = MTS::Text::trim(sendCommand(sCmd)); - if (sResult.find(RSP_OK) == std::string::npos) { + if (sResult.find(ICellularRadio::RSP_OK) == std::string::npos) { printWarning("%s| Unable to get active MIP profile for radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; } @@ -341,34 +341,34 @@ CdmaRadio::CODE CdmaRadio::getMipProfile(Json::Value& jMipProfile) { std::vector vParts = MTS::Text::split(sLine, ':', 2); if(vParts.size() == 2 && vParts[0] == "Profile") { if(vParts[1].find("Enabled") != std::string::npos) { - jMipProfile[KEY_MIP_ENABLED] = true; + jMipProfile[ICellularRadio::KEY_MIP_ENABLED] = true; } else { - jMipProfile[KEY_MIP_ENABLED] = false; + jMipProfile[ICellularRadio::KEY_MIP_ENABLED] = false; } int32_t id; sscanf(vParts[1].c_str(), "%d", &id); - jMipProfile[KEY_MIP_ID] = id; + jMipProfile[ICellularRadio::KEY_MIP_ID] = id; } else { printWarning("%s| Unable to parse active MIP profile from line [%s]", getName().c_str(), sLine.c_str()); } - splitAndAssign(vLine[1], "NAI", jMipProfile, KEY_MIP_NAI); - splitAndAssign(vLine[2], "Home Addr", jMipProfile, KEY_MIP_HOMEADDRESS); - splitAndAssign(vLine[3], "Primary HA", jMipProfile, KEY_MIP_PRIMARYHA); - splitAndAssign(vLine[4], "Secondary HA", jMipProfile, KEY_MIP_SECONDARYHA); - splitAndAssign(vLine[5], "MN-AAA SPI", jMipProfile, KEY_MIP_MNAAASPI); - splitAndAssign(vLine[6], "MN-HA SPI", jMipProfile, KEY_MIP_MNHASPI); + splitAndAssign(vLine[1], "NAI", jMipProfile, ICellularRadio::KEY_MIP_NAI); + splitAndAssign(vLine[2], "Home Addr", jMipProfile, ICellularRadio::KEY_MIP_HOMEADDRESS); + splitAndAssign(vLine[3], "Primary HA", jMipProfile, ICellularRadio::KEY_MIP_PRIMARYHA); + splitAndAssign(vLine[4], "Secondary HA", jMipProfile, ICellularRadio::KEY_MIP_SECONDARYHA); + splitAndAssign(vLine[5], "MN-AAA SPI", jMipProfile, ICellularRadio::KEY_MIP_MNAAASPI); + splitAndAssign(vLine[6], "MN-HA SPI", jMipProfile, ICellularRadio::KEY_MIP_MNHASPI); //Reverse Tunneling sLine = vLine[7]; vParts = MTS::Text::split(sLine, ':', 2); if(vParts.size() == 2 && vParts[0] == "Rev Tun") { if(vParts[1] == "1") { - jMipProfile[KEY_MIP_REVTUN] = true; + jMipProfile[ICellularRadio::KEY_MIP_REVTUN] = true; } else { - jMipProfile[KEY_MIP_REVTUN] = false; + jMipProfile[ICellularRadio::KEY_MIP_REVTUN] = false; } } else { printWarning("%s| Unable to parse Reverse Tunneling from line [%s]", getName().c_str(), sLine.c_str()); @@ -379,9 +379,9 @@ CdmaRadio::CODE CdmaRadio::getMipProfile(Json::Value& jMipProfile) { vParts = MTS::Text::split(sLine, ':', 2); if(vParts.size() == 2 && vParts[0] == "MN-AAA SS") { if(vParts[1] == "Set") { - jMipProfile[KEY_MIP_MNAAASS] = true; + jMipProfile[ICellularRadio::KEY_MIP_MNAAASS] = true; } else { - jMipProfile[KEY_MIP_MNAAASS] = false; + jMipProfile[ICellularRadio::KEY_MIP_MNAAASS] = false; } } else { printWarning("%s| Unable to parse MN-AAA SS from line [%s]", getName().c_str(), sLine.c_str()); @@ -392,9 +392,9 @@ CdmaRadio::CODE CdmaRadio::getMipProfile(Json::Value& jMipProfile) { vParts = MTS::Text::split(sLine, ':', 2); if(vParts.size() == 2 && vParts[0] == "MN-HA SS") { if(vParts[1] == "Set") { - jMipProfile[KEY_MIP_MNHASS] = true; + jMipProfile[ICellularRadio::KEY_MIP_MNHASS] = true; } else { - jMipProfile[KEY_MIP_MNHASS] = false; + jMipProfile[ICellularRadio::KEY_MIP_MNHASS] = false; } } else { printWarning("%s| Unable to parse MN-HA SS from line [%s]", getName().c_str(), sLine.c_str()); @@ -417,7 +417,7 @@ CdmaRadio::CODE CdmaRadio::setMipActiveProfile(const Json::Value& jArgs) { sCmd += jArgs["activeProfile"].asString(); std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to set Active profile for radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -437,7 +437,7 @@ CdmaRadio::CODE CdmaRadio::setMipNai(const Json::Value& jArgs) { sCmd += jArgs["nai"].asString() + ",1"; std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to set NAI for radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -457,7 +457,7 @@ CdmaRadio::CODE CdmaRadio::setMipHomeIp(const Json::Value& jArgs) { sCmd += jArgs["homeIp"].asString() + ",1"; std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to set Home IP profile for radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -477,7 +477,7 @@ CdmaRadio::CODE CdmaRadio::setMipPrimaryHa(const Json::Value& jArgs) { sCmd += jArgs["primaryHa"].asString() + ",1"; std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to set Primary HA for radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -497,7 +497,7 @@ CdmaRadio::CODE CdmaRadio::setMipSecondaryHa(const Json::Value& jArgs) { sCmd += jArgs["secondaryHa"].asString() + ",1"; std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to set Secondary HA for radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -517,7 +517,7 @@ CdmaRadio::CODE CdmaRadio::setMipMnAaaSpi(const Json::Value& jArgs) { sCmd += jArgs["mnAaaSpi"].asString() + ",1"; std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to set MN-AAA SPI for radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -537,7 +537,7 @@ CdmaRadio::CODE CdmaRadio::setMipMnHaSpi(const Json::Value& jArgs) { sCmd += jArgs["mnHaSpi"].asString() + ",1"; std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to set MN-HA SPI for radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -557,7 +557,7 @@ CdmaRadio::CODE CdmaRadio::setMipRevTun(const Json::Value& jArgs) { sCmd += jArgs["revTun"].asString() + ",1"; std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to set Rev Tun for radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -577,7 +577,7 @@ CdmaRadio::CODE CdmaRadio::setMipMnAaaSs(const Json::Value& jArgs) { sCmd += jArgs["mnAaaSs"].asString() + ",1"; std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to set MN-AAA SS for radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -597,7 +597,7 @@ CdmaRadio::CODE CdmaRadio::setMipMnHaSs(const Json::Value& jArgs) { sCmd += jArgs["mnHaSs"].asString() + ",1"; std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to set MN-HA SS for radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -627,7 +627,7 @@ CdmaRadio::CODE CdmaRadio::updateDc(const Json::Value& jArgs, UpdateCb& stepCb) return true; } - end = allData.find(NL, pos); + end = allData.find(ICellularRadio::NL, pos); printTrace("%s| Update DC Callback Started", this->getName().c_str()); while(end != std::string::npos) { @@ -683,7 +683,7 @@ CdmaRadio::CODE CdmaRadio::updateDc(const Json::Value& jArgs, UpdateCb& stepCb) stepCb(Json::Value("DC Error: update fails with other reasons")); } return false; - }else if(sLine == RSP_ERROR) { + }else if(sLine == ICellularRadio::RSP_ERROR) { result = ERROR; return false; } @@ -692,7 +692,7 @@ CdmaRadio::CODE CdmaRadio::updateDc(const Json::Value& jArgs, UpdateCb& stepCb) if(next != std::string::npos) { pos = next; } - end = allData.find(NL, pos); + end = allData.find(ICellularRadio::NL, pos); } printTrace("%s| Update DC Callback Finished", this->getName().c_str()); @@ -724,7 +724,7 @@ CdmaRadio::CODE CdmaRadio::updatePrl(const Json::Value& jArgs, UpdateCb& stepCb) return true; } - end = allData.find(NL, pos); + end = allData.find(ICellularRadio::NL, pos); printTrace("%s| Update PRL Callback Started", this->getName().c_str()); while(end != std::string::npos) { @@ -780,7 +780,7 @@ CdmaRadio::CODE CdmaRadio::updatePrl(const Json::Value& jArgs, UpdateCb& stepCb) stepCb(Json::Value("PRL Error: update fails with other reasons")); } return false; - } else if(sLine == RSP_ERROR) { + } else if(sLine == ICellularRadio::RSP_ERROR) { result = ERROR; return false; } @@ -789,7 +789,7 @@ CdmaRadio::CODE CdmaRadio::updatePrl(const Json::Value& jArgs, UpdateCb& stepCb) if(next != std::string::npos) { pos = next; } - end = allData.find(NL, pos); + end = allData.find(ICellularRadio::NL, pos); } printTrace("%s| Update PRL Callback Finished", this->getName().c_str()); @@ -821,7 +821,7 @@ CdmaRadio::CODE CdmaRadio::updateFumo(const Json::Value& jArgs, UpdateCb& stepCb return true; } - end = allData.find(NL, pos); + end = allData.find(ICellularRadio::NL, pos); printTrace("%s| Update FUMO Callback Started", this->getName().c_str()); while(end != std::string::npos) { @@ -937,7 +937,7 @@ CdmaRadio::CODE CdmaRadio::updateFumo(const Json::Value& jArgs, UpdateCb& stepCb if(stepCb) { stepCb(Json::Value("FUMO Info: reporting of firmware update result to server")); } - } else if(sLine == RSP_ERROR) { + } else if(sLine == ICellularRadio::RSP_ERROR) { result = ERROR; return false; } @@ -946,7 +946,7 @@ CdmaRadio::CODE CdmaRadio::updateFumo(const Json::Value& jArgs, UpdateCb& stepCb if(next != std::string::npos) { pos = next; } - end = allData.find(NL, pos); + end = allData.find(ICellularRadio::NL, pos); } printTrace("%s| Update FUMO Callback Finished", this->getName().c_str()); @@ -992,7 +992,7 @@ CdmaRadio::CODE CdmaRadio::resetHfa(const Json::Value& jArgs, UpdateCb& stepCb) return true; } - end = allData.find(NL, pos); + end = allData.find(ICellularRadio::NL, pos); printTrace("%s| HFA Reset Callback Started", this->getName().c_str()); while(end != std::string::npos) { @@ -1032,10 +1032,10 @@ CdmaRadio::CODE CdmaRadio::resetHfa(const Json::Value& jArgs, UpdateCb& stepCb) stepCb(Json::Value("RTN Done: Firmware DM - Session Completed Successfully")); } return false; - } else if(sLine == RSP_ERROR) { + } else if(sLine == ICellularRadio::RSP_ERROR) { result = ERROR; return false; - } else if(sLine == RSP_OK) { + } else if(sLine == ICellularRadio::RSP_OK) { //The Device will reboot now, so reset the connection if(stepCb) { stepCb(Json::Value("RTN Info: Resetting Radio")); @@ -1062,7 +1062,7 @@ CdmaRadio::CODE CdmaRadio::resetHfa(const Json::Value& jArgs, UpdateCb& stepCb) if(next != std::string::npos) { pos = next; } - end = allData.find(NL, pos); + end = allData.find(ICellularRadio::NL, pos); } printTrace("%s| HFA Reset Callback Finished", this->getName().c_str()); @@ -1082,7 +1082,7 @@ CdmaRadio::CODE CdmaRadio::activate(const Json::Value& jArgs, UpdateCb& stepCb) std::string sCarrier; getCarrier(sCarrier); - if(sCarrier == VALUE_CARRIER_AERIS) { + if(sCarrier == ICellularRadio::VALUE_CARRIER_AERIS) { if(!jArgs["msid"].isString()) { printError("%s| Arguments missing \"msid\"", getName().c_str()); @@ -1122,9 +1122,9 @@ CdmaRadio::CODE CdmaRadio::activate(const Json::Value& jArgs, UpdateCb& stepCb) return SUCCESS; - } else if(sCarrier == VALUE_CARRIER_VERIZON) { + } else if(sCarrier == ICellularRadio::VALUE_CARRIER_VERIZON) { sActivationCmd = "AT+CDV*22899\r"; - } else if(sCarrier == VALUE_CARRIER_USCELLULAR) { + } else if(sCarrier == ICellularRadio::VALUE_CARRIER_USCELLULAR) { sActivationCmd = "AT+CDV*228\r"; } else { return NOT_APPLICABLE; @@ -1153,7 +1153,7 @@ CdmaRadio::CODE CdmaRadio::activate(const Json::Value& jArgs, UpdateCb& stepCb) return true; } - end = allData.find(NL, pos); + end = allData.find(ICellularRadio::NL, pos); printTrace("%s| Activation Reset Callback Started", this->getName().c_str()); while(end != std::string::npos) { @@ -1162,7 +1162,7 @@ CdmaRadio::CODE CdmaRadio::activate(const Json::Value& jArgs, UpdateCb& stepCb) printTrace("%s| Line: [%s]", this->getName().c_str(), sLine.c_str()); - if(sLine == RSP_OK) { + if(sLine == ICellularRadio::RSP_OK) { if(stepCb) { stepCb(Json::Value("Activation Info: Over-the-Air Programming in Process")); } @@ -1194,7 +1194,7 @@ CdmaRadio::CODE CdmaRadio::activate(const Json::Value& jArgs, UpdateCb& stepCb) } result = ERROR; return false; - } else if(sLine == RSP_ERROR) { + } else if(sLine == ICellularRadio::RSP_ERROR) { result = ERROR; return false; } @@ -1203,7 +1203,7 @@ CdmaRadio::CODE CdmaRadio::activate(const Json::Value& jArgs, UpdateCb& stepCb) if(next != std::string::npos) { pos = next; } - end = allData.find(NL, pos); + end = allData.find(ICellularRadio::NL, pos); } printTrace("%s| Activation Callback Finished", this->getName().c_str()); @@ -1222,11 +1222,11 @@ CdmaRadio::CODE CdmaRadio::getNetworkStatus(Json::Value& jData) { std::string sCarrier; getCarrier(sCarrier); - if(sCarrier == VALUE_CARRIER_SPRINT) { + if(sCarrier == ICellularRadio::VALUE_CARRIER_SPRINT) { Json::Value& jDebug = jData["debug"]; std::string sCmd("AT$DEBUG?"); std::string sResult = MTS::Text::trim(sendCommand(sCmd)); - if (sResult.find(RSP_OK) != std::string::npos) { + if (sResult.find(ICellularRadio::RSP_OK) != std::string::npos) { std::vector vCategories = MTS::Text::split(sResult, "\r\n\r\n"); for(size_t i = 0 ; i < vCategories.size(); i++) { std::vector vLine = MTS::Text::split(vCategories[i], "\r\n"); diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index 66d44a0..20cb93a 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -175,10 +175,10 @@ const std::string& CellularRadio::getName() const { CellularRadio::CODE CellularRadio::getFirmware(std::string& sFirmware) { printTrace("%s| Get Firmware", m_sName.c_str()); - sFirmware = VALUE_NOT_SUPPORTED; + sFirmware = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT+CGMR"); std::string sResult = sendCommand(sCmd); - size_t pos = sResult.find(RSP_OK); + size_t pos = sResult.find(ICellularRadio::RSP_OK); if (pos == std::string::npos) { printWarning("%s| Unable to get firmware from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); return FAILURE; @@ -196,13 +196,13 @@ CellularRadio::CODE CellularRadio::getFirmware(std::string& sFirmware) { } CellularRadio::CODE CellularRadio::getFirmwareBuild(std::string& sFirmwareBuild) { - sFirmwareBuild = VALUE_NOT_SUPPORTED; + sFirmwareBuild = ICellularRadio::VALUE_NOT_SUPPORTED; return FAILURE; } CellularRadio::CODE CellularRadio::getHardware(std::string& sHardware) { printTrace("%s| Get Hardware", m_sName.c_str()); - sHardware = VALUE_NOT_SUPPORTED; + sHardware = ICellularRadio::VALUE_NOT_SUPPORTED; if(m_sFirmware.size() == 0) { getFirmware(m_sFirmware); @@ -216,10 +216,10 @@ CellularRadio::CODE CellularRadio::getHardware(std::string& sHardware) { CellularRadio::CODE CellularRadio::getManufacturer(std::string& sManufacturer) { printTrace("%s| Get Manufacturer", m_sName.c_str()); - sManufacturer = VALUE_NOT_SUPPORTED; + sManufacturer = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT+GMI"); std::string sResult = sendCommand(sCmd); - size_t pos = sResult.find(RSP_OK); + size_t pos = sResult.find(ICellularRadio::RSP_OK); if (pos == std::string::npos) { printWarning("%s| Unable to get manufacturer from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); return FAILURE; @@ -236,10 +236,10 @@ CellularRadio::CODE CellularRadio::getManufacturer(std::string& sManufacturer) { CellularRadio::CODE CellularRadio::getImei(std::string& sImei) { printTrace("%s| Get IMEI", m_sName.c_str()); - sImei = VALUE_NOT_SUPPORTED; + sImei = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT+CGSN"); std::string sResult = sendCommand(sCmd); - size_t pos = sResult.find(RSP_OK); + size_t pos = sResult.find(ICellularRadio::RSP_OK); if (pos == std::string::npos) { printWarning("%s| Unable to get IMEI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); return FAILURE; @@ -261,10 +261,10 @@ CellularRadio::CODE CellularRadio::getMeid(std::string& sMeid) { CellularRadio::CODE CellularRadio::getImsi(std::string& sImsi) { printTrace("%s| Get IMSI", m_sName.c_str()); - sImsi = VALUE_NOT_SUPPORTED; + sImsi = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT+CIMI"); std::string sResult = sendCommand(sCmd); - size_t pos = sResult.find(RSP_OK); + size_t pos = sResult.find(ICellularRadio::RSP_OK); if (pos == std::string::npos) { printWarning("%s| Unable to get IMSI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); return FAILURE; @@ -281,7 +281,7 @@ CellularRadio::CODE CellularRadio::getImsi(std::string& sImsi) { CellularRadio::CODE CellularRadio::getSimStatus(std::string& sSimStatus) { printTrace("%s| Get SIM Status", getName().c_str()); - sSimStatus = VALUE_UNKNOWN; + sSimStatus = ICellularRadio::VALUE_UNKNOWN; return FAILURE; } @@ -289,11 +289,11 @@ CellularRadio::CODE CellularRadio::getLac(std::string& sLac) { Json::Value jData; printTrace("%s| Get LAC", m_sName.c_str()); - sLac = VALUE_NOT_SUPPORTED; + sLac = ICellularRadio::VALUE_NOT_SUPPORTED; if(getNetworkStatus(jData) == SUCCESS) { - if(jData.isMember(KEY_LAC)) { - sLac = jData[KEY_LAC].asString(); + if(jData.isMember(ICellularRadio::KEY_LAC)) { + sLac = jData[ICellularRadio::KEY_LAC].asString(); return SUCCESS; } } @@ -303,10 +303,10 @@ CellularRadio::CODE CellularRadio::getLac(std::string& sLac) { CellularRadio::CODE CellularRadio::getMdn(std::string& sMdn) { printTrace("%s| Get MDN", m_sName.c_str()); - sMdn = VALUE_NOT_SUPPORTED; + sMdn = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT+CNUM"); std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get MDN from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); return FAILURE; @@ -350,7 +350,7 @@ CellularRadio::CODE CellularRadio::getMsid(std::string& sMsid) { CellularRadio::CODE CellularRadio::getType(std::string& sType) { printTrace("%s| Get Type", m_sName.c_str()); - sType = VALUE_NOT_SUPPORTED; + sType = ICellularRadio::VALUE_NOT_SUPPORTED; return FAILURE; } @@ -359,14 +359,14 @@ CellularRadio::CODE CellularRadio::getCarrier(std::string& sCarrier) { if(m_sCarrier == "") { Json::Value jData; if(getNetworkStatus(jData) == SUCCESS) { - if(jData.isMember(KEY_MCC) && jData.isMember(KEY_MNC)) { - std::string sMcc = jData[KEY_MCC].asString(); - std::string sMnc = jData[KEY_MNC].asString(); + if(jData.isMember(ICellularRadio::KEY_MCC) && jData.isMember(ICellularRadio::KEY_MNC)) { + std::string sMcc = jData[ICellularRadio::KEY_MCC].asString(); + std::string sMnc = jData[ICellularRadio::KEY_MNC].asString(); Json::Value jLookup = MccMncTable::getInstance()->lookup(sMcc, sMnc); printTrace("%s| MCC-MNC Lookup: [%s][%s][%s]", m_sName.c_str(), sMcc.c_str(), sMnc.c_str(), jLookup.toStyledString().c_str()); - if(jLookup.isMember(KEY_CARRIER)) { - m_sCarrier = jLookup[KEY_CARRIER].asString(); + if(jLookup.isMember(ICellularRadio::KEY_CARRIER)) { + m_sCarrier = jLookup[ICellularRadio::KEY_CARRIER].asString(); } else { printWarning("%s| MCC-MNC Lookup did not contain carrier", m_sName.c_str()); return FAILURE; @@ -388,11 +388,11 @@ CellularRadio::CODE CellularRadio::getTower(std::string& sTower) { Json::Value jData; printTrace("%s| Get Tower", m_sName.c_str()); - sTower = VALUE_NOT_SUPPORTED; + sTower = ICellularRadio::VALUE_NOT_SUPPORTED; if(getNetworkStatus(jData) == SUCCESS) { - if(jData.isMember(KEY_CID)) { - sTower = jData[KEY_CID].asString(); + if(jData.isMember(ICellularRadio::KEY_CID)) { + sTower = jData[ICellularRadio::KEY_CID].asString(); return SUCCESS; } } @@ -409,7 +409,7 @@ CellularRadio::CODE CellularRadio::getTime(std::string& sDate, std::string& sTim std::string sCmd("AT+CCLK?"); std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get Time from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); return FAILURE; @@ -492,11 +492,11 @@ CellularRadio::CODE CellularRadio::getNetwork(std::string& sNetwork) { Json::Value jData; printTrace("%s| Get Network", m_sName.c_str()); - sNetwork = VALUE_NOT_SUPPORTED; + sNetwork = ICellularRadio::VALUE_NOT_SUPPORTED; if(getNetworkStatus(jData) == SUCCESS) { - if(jData.isMember(KEY_NETWORK)) { - sNetwork = jData[KEY_NETWORK].asString(); + if(jData.isMember(ICellularRadio::KEY_NETWORK)) { + sNetwork = jData[ICellularRadio::KEY_NETWORK].asString(); return SUCCESS; } } @@ -692,7 +692,7 @@ std::string CellularRadio::queryLteLac() { std::string result; CGREGstring = queryCGREGstring(); - if (CGREGstring == RSP_ERROR) { + if (CGREGstring == ICellularRadio::RSP_ERROR) { originalCGREG = "0"; } else { originalCGREG = CGREGstring.at(CGREGstring.find(",") - 1); //Position right before first comma ("+CGREG: 0,1") @@ -702,13 +702,13 @@ std::string CellularRadio::queryLteLac() { setCGREG("2"); CGREGstring = queryCGREGstring(); - if (CGREGstring == RSP_ERROR) { - result = VALUE_UNKNOWN; + if (CGREGstring == ICellularRadio::RSP_ERROR) { + result = ICellularRadio::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)), ","); if(vParts.size() < 3) { - result = VALUE_UNAVAILABLE; + result = ICellularRadio::VALUE_UNAVAILABLE; } else { result = MTS::Text::strip(vParts[2], '"'); } @@ -732,7 +732,7 @@ std::string CellularRadio::queryCGREGstring() { 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 ICellularRadio::RSP_ERROR; } return cmdResult; } @@ -741,48 +741,48 @@ void CellularRadio::getCommonNetworkStats(Json::Value& jData) { bool bRoaming = false; if(getRoaming(bRoaming) == SUCCESS) { - jData[KEY_ROAMING] = bRoaming; + jData[ICellularRadio::KEY_ROAMING] = bRoaming; } int32_t iRssi; if(getSignalStrength(iRssi) == SUCCESS) { - jData[KEY_RSSI] = iRssi; + jData[ICellularRadio::KEY_RSSI] = iRssi; int32_t dBm; - if(!jData.isMember(KEY_RSSIDBM) && convertSignalStrengthTodBm(iRssi, dBm) == SUCCESS) { + if(!jData.isMember(ICellularRadio::KEY_RSSIDBM) && convertSignalStrengthTodBm(iRssi, dBm) == SUCCESS) { //Add RSSI in dBm format - jData[KEY_RSSIDBM] = MTS::Text::format(dBm); + jData[ICellularRadio::KEY_RSSIDBM] = MTS::Text::format(dBm); } } std::string sService; if(getService(sService) == SUCCESS) { - jData[KEY_SERVICE] = sService; + jData[ICellularRadio::KEY_SERVICE] = sService; } std::string sDate, sTime, sTimeZone; if(getTime(sDate, sTime, sTimeZone) == SUCCESS) { - jData[KEY_DATETIME] = sDate + " " + sTime + " GMT" + sTimeZone; + jData[ICellularRadio::KEY_DATETIME] = sDate + " " + sTime + " GMT" + sTimeZone; } std::string sNetworkReg; REGISTRATION eReg; if (getRegistration(eReg) == SUCCESS) { if (convertRegistrationToString(eReg, sNetworkReg) == SUCCESS) { - jData[KEY_NETWORK_REG] = sNetworkReg; + jData[ICellularRadio::KEY_NETWORK_REG] = sNetworkReg; } } } void CellularRadio::initMipProfile(Json::Value& jData) { - jData[KEY_MIP_ID] = 0; - jData[KEY_MIP_ENABLED] = false; - jData[KEY_MIP_NAI] = VALUE_UNKNOWN; - jData[KEY_MIP_HOMEADDRESS] = VALUE_UNKNOWN; - jData[KEY_MIP_PRIMARYHA] = VALUE_UNKNOWN; - jData[KEY_MIP_SECONDARYHA] = VALUE_UNKNOWN; - jData[KEY_MIP_MNAAASPI] = VALUE_UNKNOWN; - jData[KEY_MIP_MNHASPI] = VALUE_UNKNOWN; - jData[KEY_MIP_MNAAASS] = false; - jData[KEY_MIP_MNHASS] = false; + jData[ICellularRadio::KEY_MIP_ID] = 0; + jData[ICellularRadio::KEY_MIP_ENABLED] = false; + jData[ICellularRadio::KEY_MIP_NAI] = ICellularRadio::VALUE_UNKNOWN; + jData[ICellularRadio::KEY_MIP_HOMEADDRESS] = ICellularRadio::VALUE_UNKNOWN; + jData[ICellularRadio::KEY_MIP_PRIMARYHA] = ICellularRadio::VALUE_UNKNOWN; + jData[ICellularRadio::KEY_MIP_SECONDARYHA] = ICellularRadio::VALUE_UNKNOWN; + jData[ICellularRadio::KEY_MIP_MNAAASPI] = ICellularRadio::VALUE_UNKNOWN; + jData[ICellularRadio::KEY_MIP_MNHASPI] = ICellularRadio::VALUE_UNKNOWN; + jData[ICellularRadio::KEY_MIP_MNAAASS] = false; + jData[ICellularRadio::KEY_MIP_MNHASS] = false; } CellularRadio::CODE CellularRadio::getRegistration(REGISTRATION& eRegistration) { @@ -823,12 +823,12 @@ CellularRadio::CODE CellularRadio::convertRegistrationToString(REGISTRATION eReg CODE eCode = FAILURE; switch (eRegistration) { - case NOT_REGISTERED: sRegistration = VALUE_NOT_REGISTERED; eCode = SUCCESS; break; - case REGISTERED: sRegistration = VALUE_REGISTERED; eCode = SUCCESS; break; - case SEARCHING: sRegistration = VALUE_SEARCHING; eCode = SUCCESS; break; - case DENIED: sRegistration = VALUE_DENIED; eCode = SUCCESS; break; - case UNKNOWN: sRegistration = VALUE_UNKNOWN; eCode = SUCCESS; break; - case ROAMING: sRegistration = VALUE_ROAMING; eCode = SUCCESS; break; + case NOT_REGISTERED: sRegistration = ICellularRadio::VALUE_NOT_REGISTERED; eCode = SUCCESS; break; + case REGISTERED: sRegistration = ICellularRadio::VALUE_REGISTERED; eCode = SUCCESS; break; + case SEARCHING: sRegistration = ICellularRadio::VALUE_SEARCHING; eCode = SUCCESS; break; + case DENIED: sRegistration = ICellularRadio::VALUE_DENIED; eCode = SUCCESS; break; + case UNKNOWN: sRegistration = ICellularRadio::VALUE_UNKNOWN; eCode = SUCCESS; break; + case ROAMING: sRegistration = ICellularRadio::VALUE_ROAMING; eCode = SUCCESS; break; } return eCode; } @@ -949,7 +949,7 @@ CellularRadio::CODE CellularRadio::setActiveFirmware(const Json::Value&) { CellularRadio::CODE CellularRadio::getActiveFirmware(std::string& sFwId) { printTrace("%s| Get Active Firmware Image Number: not applicable", m_sName.c_str()); - sFwId = VALUE_NOT_SUPPORTED; + sFwId = ICellularRadio::VALUE_NOT_SUPPORTED; return NOT_APPLICABLE; } @@ -958,9 +958,9 @@ CellularRadio::CODE CellularRadio::sendBasicCommand(const std::string& sCmd, int std::string response = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, iTimeoutMillis, ESC); if (response.size() == 0) { return NO_RESPONSE; - } else if (response.find(RSP_OK) != std::string::npos) { + } else if (response.find(ICellularRadio::RSP_OK) != std::string::npos) { return SUCCESS; - } else if (response.find(RSP_ERROR) != std::string::npos) { + } else if (response.find(ICellularRadio::RSP_ERROR) != std::string::npos) { return ERROR; } else { return FAILURE; @@ -1032,19 +1032,19 @@ bool CellularRadio::getCarrierFromFirmware(const std::string& sFirmware, std::st //Good good if(cId == '0') { - sCarrier = VALUE_CARRIER_SPRINT; + sCarrier = ICellularRadio::VALUE_CARRIER_SPRINT; bResult = true; } else if(cId == '1') { - sCarrier = VALUE_CARRIER_AERIS; + sCarrier = ICellularRadio::VALUE_CARRIER_AERIS; bResult = true; } else if(cId == '2') { - sCarrier = VALUE_CARRIER_VERIZON; + sCarrier = ICellularRadio::VALUE_CARRIER_VERIZON; bResult = true; } else if(cId == '3') { - sCarrier = VALUE_CARRIER_USCELLULAR; + sCarrier = ICellularRadio::VALUE_CARRIER_USCELLULAR; bResult = true; } } @@ -1096,7 +1096,7 @@ const char *CellularRadio::RadioBandMap::getLTEBand(const int32_t channel) return EULTRAband[ii].name; } } - return VALUE_UNKNOWN; + return ICellularRadio::VALUE_UNKNOWN; } const char *CellularRadio::RadioBandMap::getCDMABand(const int channel) @@ -1108,7 +1108,7 @@ const char *CellularRadio::RadioBandMap::getCDMABand(const int channel) return WCDMAband[ii].name; } } - return VALUE_UNKNOWN; + return ICellularRadio::VALUE_UNKNOWN; } const char *CellularRadio::RadioBandMap::getGSMBand(const int channel) @@ -1120,22 +1120,22 @@ const char *CellularRadio::RadioBandMap::getGSMBand(const int channel) return GSMband[ii].name; } } - return VALUE_UNKNOWN; + return ICellularRadio::VALUE_UNKNOWN; } const char *CellularRadio::RadioBandMap::getRadioBandName() { - const char *band = CellularRadio::VALUE_UNKNOWN; + const char *band = ICellularRadio::VALUE_UNKNOWN; - if (m_sRadioType == VALUE_TYPE_LTE) + if (m_sRadioType == ICellularRadio::VALUE_TYPE_LTE) { band = getLTEBand(m_iChannel); } - else if (m_sRadioType == VALUE_TYPE_CDMA) + else if (m_sRadioType == ICellularRadio::VALUE_TYPE_CDMA) { band = getCDMABand(m_iChannel); } - else if (m_sRadioType == VALUE_TYPE_GSM) + else if (m_sRadioType == ICellularRadio::VALUE_TYPE_GSM) { band = getGSMBand(m_iChannel); } @@ -1145,17 +1145,17 @@ const char *CellularRadio::RadioBandMap::getRadioBandName() const char *CellularRadio::RadioBandMap::getRadioBandName(const std::string &channel, const std::string &radioType) { - const char *band = VALUE_UNKNOWN; + const char *band = ICellularRadio::VALUE_UNKNOWN; int32_t chan = strtol(channel.c_str(), NULL, 10); - if (radioType == VALUE_TYPE_LTE) + if (radioType == ICellularRadio::VALUE_TYPE_LTE) { band = getLTEBand(chan); } - else if (radioType == VALUE_TYPE_CDMA) + else if (radioType == ICellularRadio::VALUE_TYPE_CDMA) { band = getCDMABand(chan); } - else if (radioType == VALUE_TYPE_GSM) + else if (radioType == ICellularRadio::VALUE_TYPE_GSM) { band = getGSMBand(chan); } diff --git a/src/MTS_IO_LE910NA1Radio.cpp b/src/MTS_IO_LE910NA1Radio.cpp index 382432b..8ae15ad 100644 --- a/src/MTS_IO_LE910NA1Radio.cpp +++ b/src/MTS_IO_LE910NA1Radio.cpp @@ -108,7 +108,7 @@ LE910NA1Radio::CODE LE910NA1Radio::getActiveFirmware(std::string& sFwId) { sCmd = "AT#FWSWITCH?"; std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get active image number from radio using command [%s]", getName().c_str(), diff --git a/src/MTS_IO_ME910C1NVRadio.cpp b/src/MTS_IO_ME910C1NVRadio.cpp index 08c18e9..c7aae7b 100644 --- a/src/MTS_IO_ME910C1NVRadio.cpp +++ b/src/MTS_IO_ME910C1NVRadio.cpp @@ -419,7 +419,7 @@ ME910C1NVRadio::CODE ME910C1NVRadio::doFumoFtp(const Json::Value &jConfig, Updat printTrace("RADIO| AT#FTPMSG result [%s]", sResult.c_str()); - if (sResult.find(RSP_OK) == std::string::npos) { + if (sResult.find(ICellularRadio::RSP_OK) == std::string::npos) { rc = FAILURE; if(stepCb) { stepCb(Json::Value("FUMO Error: failed to download the firmware file")); diff --git a/src/MTS_IO_ME910C1WWRadio.cpp b/src/MTS_IO_ME910C1WWRadio.cpp index 2bc86a1..0228eda 100644 --- a/src/MTS_IO_ME910C1WWRadio.cpp +++ b/src/MTS_IO_ME910C1WWRadio.cpp @@ -101,7 +101,7 @@ ME910C1WWRadio::CODE ME910C1WWRadio::getActiveFirmware(std::string& sFwId) { sCmd = "AT#FWSWITCH?"; std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get active image number from radio using command [%s]", getName().c_str(), diff --git a/src/MTS_IO_ME910Radio.cpp b/src/MTS_IO_ME910Radio.cpp index 3ed9e50..4ae8a75 100644 --- a/src/MTS_IO_ME910Radio.cpp +++ b/src/MTS_IO_ME910Radio.cpp @@ -40,7 +40,7 @@ ME910Radio::CODE ME910Radio::getFirmwareBuild(std::string& sFirmwareBuild) { std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get firmware build number [%s]", getName().c_str(), diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp index ee96ff2..a2ade7c 100644 --- a/src/MTS_IO_TelitRadio.cpp +++ b/src/MTS_IO_TelitRadio.cpp @@ -74,10 +74,10 @@ CellularRadio::CODE TelitRadio::getModel(std::string& sModel) { CellularRadio::CODE TelitRadio::getIccid(std::string& sIccid) { printTrace("%s| Get ICCID", getName().c_str()); - sIccid = VALUE_NOT_SUPPORTED; + sIccid = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT#CCID"); std::string sResult = CellularRadio::sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get ICCID from radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -97,10 +97,10 @@ CellularRadio::CODE TelitRadio::getIccid(std::string& sIccid) { CellularRadio::CODE TelitRadio::getService(std::string& sService) { printTrace("%s| Get Service", getName().c_str()); - sService = VALUE_NOT_SUPPORTED; + sService = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT#PSNT?"); std::string sResult = CellularRadio::sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get Service from radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -119,7 +119,7 @@ CellularRadio::CODE TelitRadio::getService(std::string& sService) { case 2: sService = "WCDMA"; break; case 3: sService = "HSDPA"; break; case 4: sService = "LTE"; break; - default: sService = VALUE_UNKNOWN; break; + default: sService = ICellularRadio::VALUE_UNKNOWN; break; } printDebug("%s| Service ID: [%d][%s]", getName().c_str(), iService, sService.c_str()); @@ -256,30 +256,30 @@ CellularRadio::CODE TelitRadio::getNetworkStatus(Json::Value& jData) { //Country Code and Operator Code std::vector vPLMN = MTS::Text::split(vParts[0], ' '); if(vPLMN.size() == 2) { - jData[KEY_MCC] = MTS::Text::strip(vPLMN[0], '"'); - jData[KEY_MNC] = MTS::Text::strip(vPLMN[1], '"'); + jData[ICellularRadio::KEY_MCC] = MTS::Text::strip(vPLMN[0], '"'); + jData[ICellularRadio::KEY_MNC] = MTS::Text::strip(vPLMN[1], '"'); } - jData[KEY_CHANNEL] = vParts[1]; + jData[ICellularRadio::KEY_CHANNEL] = vParts[1]; } if (vParts.size() == GSM_NETWORK_FORMAT ) { //Parse as GSM Network Format - jData[KEY_RSSIDBM] = vParts[2]; - jData[KEY_LAC] = vParts[3]; - jData[KEY_RAC] = vParts[4]; - jData[KEY_TXPWR] = vParts[5]; - jData[KEY_MM] = vParts[6]; - jData[KEY_RR] = vParts[7]; - jData[KEY_NOM] = vParts[8]; - jData[KEY_CID] = vParts[9]; - jData[KEY_IMSI] = MTS::Text::strip(vParts[10], '"'); - jData[KEY_NETWORK] = MTS::Text::strip(vParts[11], '"'); + jData[ICellularRadio::KEY_RSSIDBM] = vParts[2]; + jData[ICellularRadio::KEY_LAC] = vParts[3]; + jData[ICellularRadio::KEY_RAC] = vParts[4]; + jData[ICellularRadio::KEY_TXPWR] = vParts[5]; + jData[ICellularRadio::KEY_MM] = vParts[6]; + jData[ICellularRadio::KEY_RR] = vParts[7]; + jData[ICellularRadio::KEY_NOM] = vParts[8]; + jData[ICellularRadio::KEY_CID] = vParts[9]; + jData[ICellularRadio::KEY_IMSI] = MTS::Text::strip(vParts[10], '"'); + jData[ICellularRadio::KEY_NETWORK] = MTS::Text::strip(vParts[11], '"'); if(MTS::Text::parse(iValue, vParts[12]) && convertServiceDomainToString((SERVICEDOMAIN)iValue, sValue) == SUCCESS) { - jData[KEY_SD] = sValue; + jData[ICellularRadio::KEY_SD] = sValue; } if(MTS::Text::parse(iValue, vParts[13]) && convertActiveBandToString((ACTIVEBAND)iValue, sValue) == SUCCESS) { - jData[KEY_ABND] = sValue; + jData[ICellularRadio::KEY_ABND] = sValue; } // IN003567 ME910C1 radios have some odd behavior with regards to WCDMA. The ordering of the fields from #RFSTS are // the same as LTE up to the 16th field (for ME901C1-WW anyway). Drop into LTE parsing for ME910C1-WW. @@ -288,36 +288,36 @@ CellularRadio::CODE TelitRadio::getNetworkStatus(Json::Value& jData) { //Parse as WCDMA Network Format - jDebug[KEY_PSC] = vParts[2]; - jDebug[KEY_ECIO] = vParts[3]; - jDebug[KEY_RSCP] = vParts[4]; + jDebug[ICellularRadio::KEY_PSC] = vParts[2]; + jDebug[ICellularRadio::KEY_ECIO] = vParts[3]; + jDebug[ICellularRadio::KEY_RSCP] = vParts[4]; - jData[KEY_RSSIDBM] = vParts[5]; - jData[KEY_LAC] = vParts[6]; - jData[KEY_RAC] = vParts[7]; + jData[ICellularRadio::KEY_RSSIDBM] = vParts[5]; + jData[ICellularRadio::KEY_LAC] = vParts[6]; + jData[ICellularRadio::KEY_RAC] = vParts[7]; - jDebug[KEY_TXPWR] = vParts[8]; - jDebug[KEY_DRX] = vParts[9]; - jDebug[KEY_MM] = vParts[10]; - jDebug[KEY_RR] = vParts[11]; - jDebug[KEY_NOM] = vParts[12]; + jDebug[ICellularRadio::KEY_TXPWR] = vParts[8]; + jDebug[ICellularRadio::KEY_DRX] = vParts[9]; + jDebug[ICellularRadio::KEY_MM] = vParts[10]; + jDebug[ICellularRadio::KEY_RR] = vParts[11]; + jDebug[ICellularRadio::KEY_NOM] = vParts[12]; if(vParts[13].size() != 0) { - jDebug[KEY_BLER] = vParts[13]; + jDebug[ICellularRadio::KEY_BLER] = vParts[13]; } else { - jDebug[KEY_BLER] = "000"; + jDebug[ICellularRadio::KEY_BLER] = "000"; } - jData[KEY_CID] = vParts[14]; - jData[KEY_IMSI] = MTS::Text::strip(vParts[15], '"'); - jData[KEY_NETWORK] = MTS::Text::strip(vParts[16], '"'); + jData[ICellularRadio::KEY_CID] = vParts[14]; + jData[ICellularRadio::KEY_IMSI] = MTS::Text::strip(vParts[15], '"'); + jData[ICellularRadio::KEY_NETWORK] = MTS::Text::strip(vParts[16], '"'); // Get the radio band given the channel (UARFCN) - RadioBandMap radioBandMap(vParts[1], CellularRadio::VALUE_TYPE_CDMA); - jData[KEY_ABND] = radioBandMap.getRadioBandName(); + RadioBandMap radioBandMap(vParts[1], CellularRadio::ICellularRadio::VALUE_TYPE_CDMA); + jData[ICellularRadio::KEY_ABND] = radioBandMap.getRadioBandName(); if(MTS::Text::parse(iValue, vParts[17]) && convertServiceDomainToString((SERVICEDOMAIN)iValue, sValue) == SUCCESS) { - jDebug[KEY_SD] = sValue; + jDebug[ICellularRadio::KEY_SD] = sValue; } //Ignoring Active Set Values // - Number of Active Set (Maximum 6) @@ -325,7 +325,7 @@ CellularRadio::CODE TelitRadio::getNetworkStatus(Json::Value& jData) { // - PSC of n th active set // - Ec/Io of n th active Set - jData[KEY_DEBUG] = jDebug; + jData[ICellularRadio::KEY_DEBUG] = jDebug; } else if(vParts.size() >= LTE_NETWORK_FORMAT) { Json::Value jDebug; @@ -347,34 +347,34 @@ CellularRadio::CODE TelitRadio::getNetworkStatus(Json::Value& jData) { // if (vParts[13].find("\"") != std::string::npos) { // parse the RAC and then remove it from the vector - jData[KEY_RAC] = vParts[6]; + jData[ICellularRadio::KEY_RAC] = vParts[6]; vParts.erase(vParts.begin() + 6); } jDebug["rsrp"] = vParts[2]; - jDebug[KEY_RSSIDBM] = vParts[3]; + jDebug[ICellularRadio::KEY_RSSIDBM] = vParts[3]; jDebug["rsrq"] = vParts[4]; jData["tac"] = vParts[5]; - jDebug[KEY_TXPWR] = vParts[6]; - jData[KEY_DRX] = vParts[7]; - jDebug[KEY_MM] = vParts[8]; + jDebug[ICellularRadio::KEY_TXPWR] = vParts[6]; + jData[ICellularRadio::KEY_DRX] = vParts[7]; + jDebug[ICellularRadio::KEY_MM] = vParts[8]; jDebug["rrc"] = vParts[9]; - jData[KEY_CID] = MTS::Text::strip(vParts[10], '"'); - jData[KEY_IMSI] = MTS::Text::strip(vParts[11], '"'); - jData[KEY_NETWORK] = MTS::Text::strip(vParts[12], '"'); + jData[ICellularRadio::KEY_CID] = MTS::Text::strip(vParts[10], '"'); + jData[ICellularRadio::KEY_IMSI] = MTS::Text::strip(vParts[11], '"'); + jData[ICellularRadio::KEY_NETWORK] = MTS::Text::strip(vParts[12], '"'); // Get the radio band given the channel (EARFCN) - RadioBandMap radioBandMap(vParts[1], CellularRadio::VALUE_TYPE_LTE); - jData[KEY_ABND] = radioBandMap.getRadioBandName(); + RadioBandMap radioBandMap(vParts[1], ICellularRadio::VALUE_TYPE_LTE); + jData[ICellularRadio::KEY_ABND] = radioBandMap.getRadioBandName(); - jData[KEY_LAC] = queryLteLac(); + jData[ICellularRadio::KEY_LAC] = queryLteLac(); if(MTS::Text::parse(iValue, vParts[13]) && convertServiceDomainToString((SERVICEDOMAIN)iValue, sValue) == SUCCESS) { - jDebug[KEY_SD] = sValue; + jDebug[ICellularRadio::KEY_SD] = sValue; } - jData[KEY_DEBUG] = jDebug; + jData[ICellularRadio::KEY_DEBUG] = jDebug; } printTrace("%s| Network Status:\n%s\n", getName().c_str(), jData.toStyledString().c_str()); @@ -389,7 +389,7 @@ std::string TelitRadio::queryLteLac() { std::string result; CGREGstring = queryCGREGstring(); - if (CGREGstring == RSP_ERROR) { + if (CGREGstring == ICellularRadio::RSP_ERROR) { originalCGREG = "0"; } else { originalCGREG = CGREGstring.at(CGREGstring.find(",") - 1); //Position right before first comma ("+CGREG: 0,1") @@ -399,13 +399,13 @@ std::string TelitRadio::queryLteLac() { setCGREG("2"); CGREGstring = queryCGREGstring(); - if (CGREGstring == RSP_ERROR) { - result = CellularRadio::VALUE_UNKNOWN; + if (CGREGstring == ICellularRadio::RSP_ERROR) { + result = ICellularRadio::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)), ","); if(vParts.size() < 3) { - result = CellularRadio::VALUE_UNAVAILABLE; + result = ICellularRadio::VALUE_UNAVAILABLE; } else { result = MTS::Text::strip(vParts[2], '"'); } @@ -429,7 +429,7 @@ std::string TelitRadio::queryCGREGstring() { std::string cmdResult(sendCommand(sCmd)); if (cmdResult.find("+CGREG:") == std::string::npos) { printDebug("%s| AT#CGREG? returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), cmdResult.c_str()); - return RSP_ERROR; + return ICellularRadio::RSP_ERROR; } return cmdResult; } @@ -445,7 +445,7 @@ CellularRadio::CODE TelitRadio::setMdn(const Json::Value& jArgs) { sCmd += jArgs["mdn"].asString() + "\""; std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 1000); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to set MDN for radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -480,19 +480,19 @@ bool TelitRadio::getCarrierFromFirmware(const std::string& sFirmware, std::strin //Good good if(cId == '0') { - sCarrier = VALUE_CARRIER_SPRINT; + sCarrier = ICellularRadio::VALUE_CARRIER_SPRINT; bResult = true; } else if(cId == '1') { - sCarrier = VALUE_CARRIER_AERIS; + sCarrier = ICellularRadio::VALUE_CARRIER_AERIS; bResult = true; } else if(cId == '2') { - sCarrier = VALUE_CARRIER_VERIZON; + sCarrier = ICellularRadio::VALUE_CARRIER_VERIZON; bResult = true; } else if(cId == '3') { - sCarrier = VALUE_CARRIER_USCELLULAR; + sCarrier = ICellularRadio::VALUE_CARRIER_USCELLULAR; bResult = true; } } -- cgit v1.2.3 From 6647e6fbb8f742727229309c9372d6c66291f805 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Wed, 12 Jun 2019 13:45:44 +0300 Subject: [MTS-MTQ] QuectelRadio implementation Fixes and improvements - Corrected the format of getNetwork output - Fixed pasrsing for the trailing values in QuectelRadio::getNetworkStatus (removed extra characters) - Removed empty "debug" field from QuectelRadio::getNetworkStatus output in GSM mode - Corrected parsing in the QuectelRadio::getServiceDomain - Corrected parsing in the QuectelRadio::getService - Corrected target fields for Service Domain value in QuectelRadio::getNetworkStatus --- src/MTS_IO_QuectelRadio.cpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 414cd98..6c6ab4b 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -105,8 +105,9 @@ CellularRadio::CODE QuectelRadio::getService(std::string& sService) { } // +COPS: [,[,][,]] + // %*[^,] in scanf - ignore all symbols until next comma int32_t iAccessTechnology = -1; - sscanf(sResult.c_str(), "%*d,%*d,%*s,%d", &iAccessTechnology); + sscanf(sResult.c_str(), "+COPS: %*d,%*d,%*[^,],%d", &iAccessTechnology); switch(iAccessTechnology) { case 0 : sService = "GPRS" ; break; // GSM @@ -156,7 +157,13 @@ CellularRadio::CODE QuectelRadio::getNetwork(std::string& sNetwork) { std::vector vParts = MTS::Text::split(MTS::Text::trim(sResult.substr(start)), ","); if(vParts.size() > 3) { - sNetwork = vParts[2]; + const std::string sValue = vParts[2]; + + // +COPS: 0,0,"CHN-UNICOM UNICOM",7 + // ^start ^end + size_t start = sValue.find("\"") + 1; + size_t end = sValue.find(" ", start); + sNetwork = sValue.substr(start, end-start); } else { sNetwork = ""; // Not connected to any network } @@ -218,11 +225,6 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { jData[KEY_NETWORK] = sValue; } - // Service Domain is not provided by AT+QENG. Fetch it separately to keep the same interface - if (getServiceDomain(sd) == SUCCESS && convertServiceDomainToString(sd, sValue) == SUCCESS) { - jData[KEY_SD] = sValue; - } - std::string sCmd; std::string sResult; @@ -235,7 +237,8 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { } size_t start = sResult.find(":") + 1; //Position right after "+QENG:" - std::vector vParts = MTS::Text::split(MTS::Text::trim(sResult.substr(start)), ","); + size_t end = sResult.rfind(RSP_OK); + std::vector vParts = MTS::Text::split(MTS::Text::trim(sResult.substr(start, end-start)), ","); Json::Value jDebug; Json::Value jQuectelDebug; @@ -288,10 +291,14 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { jQuectelDebug["rxqualfull"] = vParts[25]; jQuectelDebug["voicecodec"] = vParts[26]; + // Service Domain is not provided by AT+QENG. Fetch it separately to keep the same interface + if (getServiceDomain(sd) == SUCCESS && convertServiceDomainToString(sd, sValue) == SUCCESS) { + jData[KEY_SD] = sValue; + } + // The following fields can NOT be fetched for Quectel in GSM mode: RAC, MM, RR, NOM jData["quectelDebug"] = jQuectelDebug; - jData[KEY_DEBUG] = jDebug; } // +QENG:"servingcell",,"WCDMA",,,,,,,,,,,,,, @@ -317,6 +324,11 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { // RSSI is not provided by AT+QENG in WCDMA mode. It was filled above by the getCommonNetworkStats + // Service Domain is not provided by AT+QENG. Fetch it separately to keep the same interface + if (getServiceDomain(sd) == SUCCESS && convertServiceDomainToString(sd, sValue) == SUCCESS) { + jDebug[KEY_SD] = sValue; + } + // BLER is not provided by AT+QENG. Set to constant jDebug[KEY_BLER] = "000"; @@ -352,6 +364,11 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { RadioBandMap radioBandMap(vParts[8], CellularRadio::VALUE_TYPE_LTE); jData[KEY_ABND] = radioBandMap.getRadioBandName(); + // Service Domain is not provided by AT+QENG. Fetch it separately to keep the same interface + if (getServiceDomain(sd) == SUCCESS && convertServiceDomainToString(sd, sValue) == SUCCESS) { + jDebug[KEY_SD] = sValue; + } + // LAC is not provided by AT+QENG in WCDMA mode. Use another command instead jData[KEY_LAC] = queryLteLac(); @@ -425,7 +442,7 @@ CellularRadio::CODE QuectelRadio::getServiceDomain(CellularRadio::SERVICEDOMAIN& // +QCFG: "servicedomain", size_t start = sResult.find(",") + 1; // Position right after comma - std::string sServiceDomain = MTS::Text::trim(sResult.substr(start, end)); + std::string sServiceDomain = MTS::Text::trim(sResult.substr(start, end-start)); int iValue = -1; if (!MTS::Text::parse(iValue, sServiceDomain)) { -- cgit v1.2.3 From d388f51c9611d0f5009abf105aba44c85fcee4b0 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Wed, 12 Jun 2019 16:30:46 +0300 Subject: [MTS-MTQ] QuectelRadio implementation Changed implementation of the QuectelRadio::getService - Replaced sscanf with functions from MTS::Text - Emulated the behaviour of TelitRadio::getService - return FAILURE when is not available The TelitRadio::getService returns FAILURE when device stays without a SIM card (probably, until it will be registered to the network) --- src/MTS_IO_QuectelRadio.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 6c6ab4b..20a2a21 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -104,10 +104,16 @@ CellularRadio::CODE QuectelRadio::getService(std::string& sService) { return FAILURE; } + size_t start = sResult.find(":") + 1; //Position right after "+COPS:" + std::vector vParts = MTS::Text::split(MTS::Text::trim(sResult.substr(start, end-start)), ','); + + int32_t iAccessTechnology; + // +COPS: [,[,][,]] - // %*[^,] in scanf - ignore all symbols until next comma - int32_t iAccessTechnology = -1; - sscanf(sResult.c_str(), "+COPS: %*d,%*d,%*[^,],%d", &iAccessTechnology); + if (vParts.size() < 4 || !MTS::Text::parse(iAccessTechnology, vParts[3])) { + printWarning("%s| Unable to get Service from radio using command [%s]", getName().c_str(), sCmd.c_str()); + return FAILURE; + } switch(iAccessTechnology) { case 0 : sService = "GPRS" ; break; // GSM -- cgit v1.2.3 From acb40ca0033a48cedfeb118dcc216f60e4dd8c45 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Wed, 12 Jun 2019 17:23:03 +0300 Subject: [MTS-MTQ] QuectelRadio implementation Fixed parsing of RSSI dBm in QuectelRadio::getNetworkStatus for GSM mode. As stated in the datasheet[1], we should substract "111" from the value in field in order to get a proper value in dBm. The thing is that the values returned by a real device are already out of the "0-63" range stated in a datasheet. And looks like those values are already in a dBm scale. [2] This commit removes additional substraction and saves the value of field directly without any modifications. Sources: - [1] QuectelEC2x26EG9x26EM05QuecCellATCommandsManualV10.929966385.pdf, page 9, field description. - [2] +QENG: "servingcell","NOCONN","GSM",REDACTED,REDACTED,REFACTED,REDACTED,8,522,0,-66,255,255,0,41,41,1,-,-,-,-,-,-,-,-,-,"" --- src/MTS_IO_QuectelRadio.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 20a2a21..af7fc7c 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -273,13 +273,7 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { jData[KEY_ABND] = sValue; } - if (MTS::Text::parse(iValue, vParts[10])) { - // Number format. RX level value for base station selection in dB (see 3GPP 25.304). - // Range: 0-63. Subtracting 111 from the RX level value, a dBm value will be got. - int rssi = iValue - 111; - jData[KEY_RSSIDBM] = MTS::Text::format(rssi); - } - + jData[KEY_RSSIDBM] = vParts[10]; // Values already negative. No need to substract 111 as stated in a datasheet jData[KEY_TXPWR] = vParts[11]; jQuectelDebug["rla"] = vParts[12]; jQuectelDebug["drx"] = vParts[13]; -- cgit v1.2.3 From 4220543c5e64d36eb94b8137f46079d1a2cb1d28 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Thu, 13 Jun 2019 10:47:10 +0300 Subject: [MTS-MTQ] refactoring: using full qualified names for consts [2] Made the same changes for QuectelRadio as for the whole project --- src/MTS_IO_QuectelRadio.cpp | 98 ++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index af7fc7c..5c7ceb7 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -72,10 +72,10 @@ CellularRadio::CODE QuectelRadio::getModel(std::string& sModel) { CellularRadio::CODE QuectelRadio::getIccid(std::string& sIccid) { printTrace("%s| Get ICCID", getName().c_str()); - sIccid = VALUE_NOT_SUPPORTED; + sIccid = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT+QCCID"); - std::string sResult = CellularRadio::sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + std::string sResult = sendCommand(sCmd); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get ICCID from radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -95,10 +95,10 @@ CellularRadio::CODE QuectelRadio::getIccid(std::string& sIccid) { CellularRadio::CODE QuectelRadio::getService(std::string& sService) { printTrace("%s| Get Service", getName().c_str()); - sService = VALUE_NOT_SUPPORTED; + sService = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT+COPS?"); - std::string sResult = CellularRadio::sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + std::string sResult = sendCommand(sCmd); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get Service from radio using command [%s]", getName().c_str(), sCmd.c_str()); return FAILURE; @@ -125,7 +125,7 @@ CellularRadio::CODE QuectelRadio::getService(std::string& sService) { case 7 : sService = "LTE" ; break; // E-UTRAN case 100 : sService = "CDMA" ; break; // CDMA - default: sService = VALUE_UNKNOWN; break; + default: sService = ICellularRadio::VALUE_UNKNOWN; break; } printDebug("%s| Service ID: [%d][%s]", getName().c_str(), iAccessTechnology, sService.c_str()); @@ -147,10 +147,10 @@ CellularRadio::CODE QuectelRadio::getNetwork(std::string& sNetwork) { * of a currently selected operator (AT+COPS). */ printTrace("%s| Get Network", getName().c_str()); - sNetwork = VALUE_NOT_SUPPORTED; + sNetwork = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT+COPS?"); - std::string sResult = CellularRadio::sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + std::string sResult = sendCommand(sCmd); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get network name from radio using command [%s]", getName().c_str(), sCmd.c_str()); @@ -222,13 +222,13 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { // IMSI is not provided by AT+QENG. Fetch it separately to keep the same interface if (getImsi(sValue) == SUCCESS) { - jData[KEY_IMSI] = sValue; + jData[ICellularRadio::KEY_IMSI] = sValue; } // Network Name is not explicitly provided by AT+QENG. Fetch it separately to keep the same interface // TODO: Replace with lookup by MCC and MNC once MccMncTable is fixed. if (getNetwork(sValue) == SUCCESS) { - jData[KEY_NETWORK] = sValue; + jData[ICellularRadio::KEY_NETWORK] = sValue; } std::string sCmd; @@ -243,7 +243,7 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { } size_t start = sResult.find(":") + 1; //Position right after "+QENG:" - size_t end = sResult.rfind(RSP_OK); + size_t end = sResult.rfind(ICellularRadio::RSP_OK); std::vector vParts = MTS::Text::split(MTS::Text::trim(sResult.substr(start, end-start)), ","); Json::Value jDebug; Json::Value jQuectelDebug; @@ -262,19 +262,19 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { // +QENG: [0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13],[14],[15], [16], [17],[18],[19], [20], [21], [22], [23], [24], [25], [26] if (vParts.size() == GSM_NETWORK_FORMAT ) { //Parse as GSM Network Format - jData[KEY_MCC] = vParts[3]; - jData[KEY_MNC] = vParts[4]; - jData[KEY_LAC] = vParts[5]; - jData[KEY_CID] = vParts[6]; + jData[ICellularRadio::KEY_MCC] = vParts[3]; + jData[ICellularRadio::KEY_MNC] = vParts[4]; + jData[ICellularRadio::KEY_LAC] = vParts[5]; + jData[ICellularRadio::KEY_CID] = vParts[6]; jQuectelDebug["bsic"] = vParts[7]; - jData[KEY_CHANNEL] = vParts[8]; + jData[ICellularRadio::KEY_CHANNEL] = vParts[8]; if (convertToActiveBand(vParts[9], abnd) == SUCCESS && convertActiveBandToString(abnd, sValue) == SUCCESS) { - jData[KEY_ABND] = sValue; + jData[ICellularRadio::KEY_ABND] = sValue; } - jData[KEY_RSSIDBM] = vParts[10]; // Values already negative. No need to substract 111 as stated in a datasheet - jData[KEY_TXPWR] = vParts[11]; + jData[ICellularRadio::KEY_RSSIDBM] = vParts[10]; // Values already negative. No need to substract 111 as stated in a datasheet + jData[ICellularRadio::KEY_TXPWR] = vParts[11]; jQuectelDebug["rla"] = vParts[12]; jQuectelDebug["drx"] = vParts[13]; jQuectelDebug["c1"] = vParts[14]; @@ -293,7 +293,7 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { // Service Domain is not provided by AT+QENG. Fetch it separately to keep the same interface if (getServiceDomain(sd) == SUCCESS && convertServiceDomainToString(sd, sValue) == SUCCESS) { - jData[KEY_SD] = sValue; + jData[ICellularRadio::KEY_SD] = sValue; } // The following fields can NOT be fetched for Quectel in GSM mode: RAC, MM, RR, NOM @@ -305,15 +305,15 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { // +QENG: [0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12],[13], [14], [15], [16] else if((vParts.size() == WCDMA_NETWORK_FORMAT)) { //Parse as WCDMA Network Format - jData[KEY_MCC] = vParts[3]; - jData[KEY_MNC] = vParts[4]; - jData[KEY_LAC] = vParts[5]; - jData[KEY_CID] = vParts[6]; - jData[KEY_CHANNEL] = vParts[7]; - jDebug[KEY_PSC] = vParts[8]; - jData[KEY_RAC] = vParts[9]; - jDebug[KEY_RSCP] = vParts[10]; - jDebug[KEY_ECIO] = vParts[11]; + jData[ICellularRadio::KEY_MCC] = vParts[3]; + jData[ICellularRadio::KEY_MNC] = vParts[4]; + jData[ICellularRadio::KEY_LAC] = vParts[5]; + jData[ICellularRadio::KEY_CID] = vParts[6]; + jData[ICellularRadio::KEY_CHANNEL] = vParts[7]; + jDebug[ICellularRadio::KEY_PSC] = vParts[8]; + jData[ICellularRadio::KEY_RAC] = vParts[9]; + jDebug[ICellularRadio::KEY_RSCP] = vParts[10]; + jDebug[ICellularRadio::KEY_ECIO] = vParts[11]; jQuectelDebug["phych"] = vParts[12]; jQuectelDebug["sf"] = vParts[13]; jQuectelDebug["slot"] = vParts[14]; @@ -326,18 +326,18 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { // Service Domain is not provided by AT+QENG. Fetch it separately to keep the same interface if (getServiceDomain(sd) == SUCCESS && convertServiceDomainToString(sd, sValue) == SUCCESS) { - jDebug[KEY_SD] = sValue; + jDebug[ICellularRadio::KEY_SD] = sValue; } // BLER is not provided by AT+QENG. Set to constant - jDebug[KEY_BLER] = "000"; + jDebug[ICellularRadio::KEY_BLER] = "000"; // Get the radio band given the channel (UARFCN) - RadioBandMap radioBandMap(vParts[7], CellularRadio::VALUE_TYPE_CDMA); - jData[KEY_ABND] = radioBandMap.getRadioBandName(); + RadioBandMap radioBandMap(vParts[7], ICellularRadio::VALUE_TYPE_CDMA); + jData[ICellularRadio::KEY_ABND] = radioBandMap.getRadioBandName(); jData["quectelDebug"] = jQuectelDebug; - jData[KEY_DEBUG] = jDebug; + jData[ICellularRadio::KEY_DEBUG] = jDebug; } // +QENG:"servingcell",,"LTE",,,,,,,,,,,,,,, @@ -345,35 +345,35 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { else if(vParts.size() == LTE_NETWORK_FORMAT) { //Parse as LTE Network Format jQuectelDebug["isTdd"] = vParts[3]; - jData[KEY_MCC] = vParts[4]; - jData[KEY_MNC] = vParts[5]; - jData[KEY_CID] = vParts[6]; + jData[ICellularRadio::KEY_MCC] = vParts[4]; + jData[ICellularRadio::KEY_MNC] = vParts[5]; + jData[ICellularRadio::KEY_CID] = vParts[6]; jQuectelDebug["pcid"] = vParts[7]; - jData[KEY_CHANNEL] = vParts[8]; + jData[ICellularRadio::KEY_CHANNEL] = vParts[8]; jQuectelDebug["freqBandInd"] = vParts[9]; jQuectelDebug["ulBandwidth"] = vParts[10]; jQuectelDebug["dlBandwidth"] = vParts[11]; jData["tac"] = vParts[12]; jDebug["rsrp"] = vParts[13]; jDebug["rsrq"] = vParts[14]; - jData[KEY_RSSIDBM] = vParts[15]; + jData[ICellularRadio::KEY_RSSIDBM] = vParts[15]; jQuectelDebug["sinr"] = vParts[16]; jQuectelDebug["srxlev"] = vParts[17]; // Get the radio band given the channel (EARFCN) - RadioBandMap radioBandMap(vParts[8], CellularRadio::VALUE_TYPE_LTE); - jData[KEY_ABND] = radioBandMap.getRadioBandName(); + RadioBandMap radioBandMap(vParts[8], ICellularRadio::VALUE_TYPE_LTE); + jData[ICellularRadio::KEY_ABND] = radioBandMap.getRadioBandName(); // Service Domain is not provided by AT+QENG. Fetch it separately to keep the same interface if (getServiceDomain(sd) == SUCCESS && convertServiceDomainToString(sd, sValue) == SUCCESS) { - jDebug[KEY_SD] = sValue; + jDebug[ICellularRadio::KEY_SD] = sValue; } // LAC is not provided by AT+QENG in WCDMA mode. Use another command instead - jData[KEY_LAC] = queryLteLac(); + jData[ICellularRadio::KEY_LAC] = queryLteLac(); jData["quectelDebug"] = jQuectelDebug; - jData[KEY_DEBUG] = jDebug; + jData[ICellularRadio::KEY_DEBUG] = jDebug; } printTrace("%s| Network Status:\n%s\n", getName().c_str(), jData.toStyledString().c_str()); @@ -428,11 +428,11 @@ CellularRadio::CODE QuectelRadio::setMdn(const Json::Value& jArgs) { return NOT_APPLICABLE; } -CellularRadio::CODE QuectelRadio::getServiceDomain(CellularRadio::SERVICEDOMAIN& sd) { +CellularRadio::CODE QuectelRadio::getServiceDomain(ICellularRadio::SERVICEDOMAIN& sd) { printTrace("%s| Get Service Domain", getName().c_str()); std::string sCmd("AT+QCFG=\"servicedomain\""); - std::string sResult = CellularRadio::sendCommand(sCmd); + std::string sResult = sendCommand(sCmd); size_t end = sResult.find(RSP_OK); if (end == std::string::npos) { @@ -478,7 +478,7 @@ bool QuectelRadio::getHardwareVersionFromFirmware(const std::string& sFirmware, return false; } -CellularRadio::CODE QuectelRadio::convertToActiveBand(const std::string& sQuectelBand, CellularRadio::ACTIVEBAND& band) { +CellularRadio::CODE QuectelRadio::convertToActiveBand(const std::string& sQuectelBand, ICellularRadio::ACTIVEBAND& band) { int iQuectelBand = -1; if (!MTS::Text::parse(iQuectelBand, sQuectelBand)) { -- cgit v1.2.3 From d3ab74f3f8957696077efbac756b52fbbbe49548 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Fri, 14 Jun 2019 18:02:17 +0300 Subject: [MTS-MTQ] QuectelRadio implementation Fixed a tiny difference between RSSI placement in TelitRadio and QuectelRadio implementation --- src/MTS_IO_QuectelRadio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 5c7ceb7..2f3c9b5 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -356,7 +356,7 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { jData["tac"] = vParts[12]; jDebug["rsrp"] = vParts[13]; jDebug["rsrq"] = vParts[14]; - jData[ICellularRadio::KEY_RSSIDBM] = vParts[15]; + jDebug[ICellularRadio::KEY_RSSIDBM] = vParts[15]; jQuectelDebug["sinr"] = vParts[16]; jQuectelDebug["srxlev"] = vParts[17]; -- cgit v1.2.3 From 3b542d1fea82726842e6bfe03ddcbf86345c5b9d Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Fri, 21 Jun 2019 16:47:05 +0300 Subject: [MTS-MTQ] refactoring: Makefile build static library option fix Generate index to archive. instead of ranlib. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3ace73f..8472075 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ LDFLAGS += -s -shared -Wl,-soname,$(APPNAME).so.0 all: $(APPNAME).a $(SONAME) $(APPNAME).a: $(OBJS) - $(AR) -r $@ $? + $(AR) -rs $@ $? $(SONAME): $(OBJS) $(CC) $(LDFLAGS) -o $@ $? $(LDLIBS) -- cgit v1.2.3 From 143feb6a4587817d28c77e4df3a1b594b855f5e5 Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Fri, 21 Jun 2019 17:19:09 +0300 Subject: [MTS-MTQ] RAT mode switch: implementation for telit and quectel RAT - Radio Access Technology --- include/mts/MTS_IO_ICellularRadio.h | 11 +++++++++++ include/mts/MTS_IO_QuectelRadio.h | 2 ++ include/mts/MTS_IO_TelitRadio.h | 2 ++ src/MTS_IO_QuectelRadio.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/MTS_IO_TelitRadio.cpp | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 87 insertions(+) diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h index d74ad15..1b95a0d 100644 --- a/include/mts/MTS_IO_ICellularRadio.h +++ b/include/mts/MTS_IO_ICellularRadio.h @@ -60,6 +60,14 @@ namespace MTS { NOT_INSERTED }; + enum RADIOMODE : uint8_t { + RADIOMODE_UNKNOWN = 0, + RADIOMODE_AUTO, + RADIOMODE_GSM_ONLY, + RADIOMODE_UMTS_ONLY, + RADIOMODE_LTE_ONLY + }; + static CODE convertModelToType(const std::string& sModel, std::string& sType); static CODE convertModelToMtsShortCode(const std::string& sModel, std::string& sCode, ICellularRadio *radioObj = NULL); static CODE convertServiceDomainToString(SERVICEDOMAIN eSd, std::string& sSd); @@ -225,6 +233,9 @@ namespace MTS { virtual CODE getRegistration(REGISTRATION& eRegistration) = 0; virtual CODE convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration) = 0; + virtual CODE getRadioMode(RADIOMODE &mode) = 0; + virtual CODE setRadioMode(RADIOMODE mode) = 0; + //! Gather details of the radio's Mobile IP Profile /*! \param Json::Value object that will be populated with MIP data diff --git a/include/mts/MTS_IO_QuectelRadio.h b/include/mts/MTS_IO_QuectelRadio.h index b486323..0ca7f3b 100644 --- a/include/mts/MTS_IO_QuectelRadio.h +++ b/include/mts/MTS_IO_QuectelRadio.h @@ -41,6 +41,8 @@ namespace MTS { CODE convertdBmToSignalStrength(const int32_t& dBm, int32_t& iRssi) override; CODE setMdn(const Json::Value& jArgs) override; + CODE getRadioMode(RADIOMODE &mode) override; + CODE setRadioMode(RADIOMODE mode) override; protected: QuectelRadio(const std::string& sName, const std::string& sRadioPort); diff --git a/include/mts/MTS_IO_TelitRadio.h b/include/mts/MTS_IO_TelitRadio.h index 70ff8a9..47d6cf6 100644 --- a/include/mts/MTS_IO_TelitRadio.h +++ b/include/mts/MTS_IO_TelitRadio.h @@ -39,6 +39,8 @@ namespace MTS { CODE convertdBmToSignalStrength(const int32_t& dBm, int32_t& iRssi) override; CODE setMdn(const Json::Value& jArgs) override; + CODE getRadioMode(RADIOMODE &mode) override; + CODE setRadioMode(RADIOMODE mode) override; protected: TelitRadio(const std::string& sName, const std::string& sRadioPort); diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 2f3c9b5..50185b3 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -494,3 +494,39 @@ CellularRadio::CODE QuectelRadio::convertToActiveBand(const std::string& sQuecte return SUCCESS; } + +ICellularRadio::CODE QuectelRadio::getRadioMode(RADIOMODE &mode) +{ + std::string sCmd("AT+QCFG=\"nwscanmode\""); + std::string cmdResult = sendCommand(sCmd); + if (cmdResult.find(ICellularRadio::RSP_OK) == std::string::npos) { + printDebug("%s| AT+QCFG? returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), cmdResult.c_str()); + return FAILURE; + } + switch (stoi(MTS::Text::split(cmdResult, ',')[1])) { + case 1: mode = ICellularRadio::RADIOMODE_GSM_ONLY; break; + case 5: mode = ICellularRadio::RADIOMODE_UMTS_ONLY; break; + case 0: mode = ICellularRadio::RADIOMODE_AUTO; break; + default: mode = ICellularRadio::RADIOMODE_UNKNOWN; break; + } + return SUCCESS; +} + +ICellularRadio::CODE QuectelRadio::setRadioMode(RADIOMODE mode) +{ + std::string value; + switch (mode) { + case ICellularRadio::RADIOMODE_GSM_ONLY: value = "1"; break; + case ICellularRadio::RADIOMODE_UMTS_ONLY: value = "5"; break; + case ICellularRadio::RADIOMODE_AUTO: value = "0"; break; + default: return FAILURE; + } + std::string sCmd("AT+QCFG=\"nwscanmode\","); + sCmd += value; + std::string cmdResult = sendCommand(sCmd); + if (cmdResult.find(ICellularRadio::RSP_OK) == std::string::npos) { + printDebug("%s| AT+QCFG? returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), cmdResult.c_str()); + return FAILURE; + } + return SUCCESS; +} diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp index 4fcf836..7b5b18b 100644 --- a/src/MTS_IO_TelitRadio.cpp +++ b/src/MTS_IO_TelitRadio.cpp @@ -537,3 +537,39 @@ bool TelitRadio::getHardwareVersionFromFirmware(const std::string& sFirmware, st return bResult; } + +ICellularRadio::CODE TelitRadio::getRadioMode(RADIOMODE &mode) +{ + std::string sCmd("AT+WS46?"); + std::string cmdResult = sendCommand(sCmd); + if (cmdResult.find("+WS46:") == std::string::npos) { + printDebug("%s| AT+WS46? returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), cmdResult.c_str()); + return FAILURE; + } + switch (stoi(MTS::Text::split(cmdResult, ':')[1])) { + case 12: mode = ICellularRadio::RADIOMODE_GSM_ONLY; break; + case 22: mode = ICellularRadio::RADIOMODE_UMTS_ONLY; break; + case 25: mode = ICellularRadio::RADIOMODE_AUTO; break; + default: mode = ICellularRadio::RADIOMODE_UNKNOWN; break; + } + return SUCCESS; +} + +ICellularRadio::CODE TelitRadio::setRadioMode(RADIOMODE mode) +{ + std::string value; + switch (mode) { + case ICellularRadio::RADIOMODE_GSM_ONLY: value = "12"; break; + case ICellularRadio::RADIOMODE_UMTS_ONLY: value = "22"; break; + case ICellularRadio::RADIOMODE_AUTO: value = "25"; break; + default: return FAILURE; + } + std::string sCmd("AT+WS46="); + sCmd += value; + std::string cmdResult = sendCommand(sCmd); + if (cmdResult.find(ICellularRadio::RSP_OK) == std::string::npos) { + printDebug("%s| AT+WS46? returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), cmdResult.c_str()); + return FAILURE; + } + return SUCCESS; +} -- cgit v1.2.3 From 482f5c42c4e0a03b7474d369250121005bc94f3f Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Fri, 21 Jun 2019 18:11:11 +0300 Subject: [MTS-MTQ] SIM status and PIN unlock procedures Declared the interface for SIM status and PIN-related methods --- include/mts/MTS_IO_ICellularRadio.h | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h index d74ad15..5d2295b 100644 --- a/include/mts/MTS_IO_ICellularRadio.h +++ b/include/mts/MTS_IO_ICellularRadio.h @@ -205,6 +205,29 @@ namespace MTS { virtual CODE getMeid(std::string& sMeid) = 0; virtual CODE getImsi(std::string& sImsi) = 0; virtual CODE getSimStatus(std::string& sSimStatus) = 0; + + /** + * @brief getSimStatusSummary - get summary on the SIM card status + * (if there is a SIM card inserted, is it locked, etc). + * See below for the full list of returned fields. + * + * - `isSimInserted` - bool, is the SIM card installed or not; + * - `isSimLocked` - bool, is the SIM card blocked with PIN/PUK or not (or is READY); + * - `lockStatus` - string, either "READY", "SIM PUK", "SIM PIN" or other status as + * returned by "AT+CPIN?" AT command; + * - `attemptsPin` - integer, the number of attempts lef to enter a PIN code; + * - `attemptsPuk` - integer, the number of attempts lef to enter a PUK code. + * + * **Only `isSimInserted` is always present.** All other fields are omitted if + * the SIM card is removed. + * + * @param jData - an object to be filled with data + * @return CODE::SUCCESS on success, + * CODE::NOT_APPLICABLE if not supported by this radio + * and CODE::ERROR otherwise + */ + virtual CODE getSimStatusSummary(Json::Value& jData) = 0; + virtual CODE getIccid(std::string& sIccid) = 0; virtual CODE getService(std::string& sService) = 0; virtual CODE getLac(std::string& sLac) = 0; @@ -225,6 +248,26 @@ namespace MTS { virtual CODE getRegistration(REGISTRATION& eRegistration) = 0; virtual CODE convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration) = 0; + /** + * @brief unlockSimCard - unlock the SIM card using PIN code provided + * + * This command does not peform any checks on the number of attempts left. + * Use with caution, verify the SIM status manually before execution. + * + * @param jArgs - a JSON object with the following format: + * + * jArgs = { + * "pin" : "A correct PIN code to unlock the SIM card: STRING" + * } + * + * @return CODE::SUCCESS when SIM card was succeffully unlocked, + * CODE::INVALID_ARGS when passed arguments are invalid, + * CODE::ERROR otherwise (i.e. when modem is not responding, + * when SIM card is removed, when PIN code is not correct + * or on any other error). + */ + virtual CODE unlockSimCard(const Json::Value& jArgs) = 0; + //! Gather details of the radio's Mobile IP Profile /*! \param Json::Value object that will be populated with MIP data -- cgit v1.2.3 From 07d0ee6ea892dea71911478fad2c530de41e059b Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Sat, 22 Jun 2019 10:17:30 +0300 Subject: [MTS-MTQ] SIM status and PIN unlock procedures Defined common protected utility methods for the CellularRadio class: - getIsSimInserted - getSimLockStatus - getSimLockAttempts --- include/mts/MTS_IO_CellularRadio.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index 899ceeb..e23cbc9 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -122,6 +122,40 @@ namespace MTS { virtual void getCommonNetworkStats(Json::Value& jData); + /** + * @brief getIsSimInserted - returns if the SIM card is inserted / installed or not. + * + * @param bData - an object to be filled with the SIM card insertion status. + * `true` when SIM card is inserted / installed / present, + * `false` otherwise. + * @return CODE::SUCCESS when SIM insertion status is fetched successfully, + * CODE::NOT_APPLICABLE when the modem doesn't support this feature, + * CODE::ERROR otherwise (when modem is inaccessible or in other cases). + */ + virtual CODE getIsSimInserted(bool& bData) = 0; + + /** + * @brief getSimLockStatus - return the SIM lock status as defined by AT+CPIN? command. + * Returns "READY", "SIM PIN", "SIM PUK" or other SIM status. + * + * @param sData - an object to be filled with the SIM lock status + * @return CODE::SUCCESS when SIM status is fetched successfully, + * CODE::NOT_APPLICABLE when the modem doesn't support this feature, + * CODE::ERROR otherwise (SIM card removed, modem is inaccessible, etc). + */ + virtual CODE getSimLockStatus(std::string& sData) = 0; + + /** + * @brief getSimLockAttempts - get the number of SIM unlock attempts left. + * + * @param iAttemptsPin - the number of attempts left to enter a PIN code. + * @param iAttemptsPuk - the number of attempts left to enter a PUK code. + * @return CODE::SUCCESS when both numbers are fetched successfully, + * CODE::NOT_APPLICABLE when the modem doesn't support this feature, + * CODE::ERROR otherwise (SIM card removed, modem is inaccessible, etc). + */ + virtual CODE getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk) = 0; + void initMipProfile(Json::Value& jData); bool splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType = Json::ValueType::stringValue); -- cgit v1.2.3 From da53c2f6955e748862066f727997965f7b9c6849 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Sat, 22 Jun 2019 10:51:06 +0300 Subject: [MTS-MTQ] SIM status and PIN unlock procedures Defined the JSON object fields for SIM Status Summary data --- include/mts/MTS_IO_ICellularRadio.h | 6 ++++++ src/MTS_IO_ICellularRadio.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h index 5d2295b..531e0e0 100644 --- a/include/mts/MTS_IO_ICellularRadio.h +++ b/include/mts/MTS_IO_ICellularRadio.h @@ -160,6 +160,12 @@ namespace MTS { static const char *KEY_MIP_MNAAASS; //!< Mobile Node Authentication, Authorization, and Accounting Server Shared Secret static const char *KEY_MIP_MNHASS; //!< Mobile Node Home Agent Shared Secret + //SIM Status Summary data + static const char *KEY_IS_SIM_INSERTED; //!< SIM card insertion indicator. True when a SIM card is inserted + static const char *KEY_IS_SIM_LOCKED; //!< SIM card lock status indicator. True when a SIM card is locked by PIN / PUK / other code + static const char *KEY_SIM_LOCK_STATUS; //!< SIM card lock status string. Either "READY", "SIM PIN", "SIM PUK" or other state + static const char *KEY_ATTEMPTS_PIN; //!< The number of attempts left to unlock the SIM card using PIN code + static const char *KEY_ATTEMPTS_PUK; //!< The number of attempts left to unlock the SIM card using PUK code //Values - Type static const char *VALUE_TYPE_LTE; diff --git a/src/MTS_IO_ICellularRadio.cpp b/src/MTS_IO_ICellularRadio.cpp index 7f216d0..4e7809e 100644 --- a/src/MTS_IO_ICellularRadio.cpp +++ b/src/MTS_IO_ICellularRadio.cpp @@ -94,6 +94,12 @@ const char *MTS::IO::ICellularRadio::VALUE_TYPE_GSM = "GSM"; const char *MTS::IO::ICellularRadio::VALUE_TYPE_LTE = "LTE"; const char *MTS::IO::ICellularRadio::VALUE_TYPE_CDMA = "CDMA"; +const char *MTS::IO::ICellularRadio::KEY_IS_SIM_INSERTED = "isSimInserted"; //!< SIM card insertion indicator. True when a SIM card is inserted +const char *MTS::IO::ICellularRadio::KEY_IS_SIM_LOCKED = "isSimLocked"; //!< SIM card lock status indicator. True when a SIM card is locked by PIN / PUK / other code +const char *MTS::IO::ICellularRadio::KEY_SIM_LOCK_STATUS = "lockStatus"; //!< SIM card lock status string. Either "READY", "SIM PIN", "SIM PUK" or other state +const char *MTS::IO::ICellularRadio::KEY_ATTEMPTS_PIN = "attemptsPin"; //!< The number of attempts left to unlock the SIM card using PIN code +const char *MTS::IO::ICellularRadio::KEY_ATTEMPTS_PUK = "attemptsPuk"; //!< The number of attempts left to unlock the SIM card using PUK code + const char *MTS::IO::ICellularRadio::VALUE_SD_NO_SERVICE = "NO SERVICE"; const char *MTS::IO::ICellularRadio::VALUE_SD_CS_ONLY = "CS ONLY"; const char *MTS::IO::ICellularRadio::VALUE_SD_PS_ONLY = "PS ONLY"; -- cgit v1.2.3 From a7673be0a434243c2011d809cc0a3a01441470fb Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Sat, 22 Jun 2019 10:57:44 +0300 Subject: [MTS-MTQ] SIM status and PIN unlock procedures Added a common implementation for the CellularRadio::getSimStatusSummary method --- include/mts/MTS_IO_CellularRadio.h | 1 + src/MTS_IO_CellularRadio.cpp | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index e23cbc9..5ca9f9a 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -61,6 +61,7 @@ namespace MTS { CODE getMeid(std::string& sMeid) override; CODE getImsi(std::string& sImsi) override; CODE getSimStatus(std::string& sSimStatus) override; + CODE getSimStatusSummary(Json::Value& jData) override; CODE getLac(std::string& sLac) override; CODE getMdn(std::string& sMdn) override; CODE getMsid(std::string& sMsid) override; diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index dbb64a5..8c4c75b 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -285,6 +285,50 @@ CellularRadio::CODE CellularRadio::getSimStatus(std::string& sSimStatus) { return FAILURE; } +CellularRadio::CODE CellularRadio::getSimStatusSummary(Json::Value& jData) { + bool bIsSimInserted = false; + bool bIsSimLocked = true; + int iAttemptsPin = 0; + int iAttemptsPuk = 0; + std::string sSimLockStatus; + CODE retCode; + + do { + retCode = getIsSimInserted(bIsSimInserted); + if (retCode != SUCCESS) { + break; + } + + if (!bIsSimInserted) { + // There is no left much to do. Return one field only. + jData[KEY_IS_SIM_INSERTED] = bIsSimInserted; + break; + } + + // The following code assumes that the SIM card is inserted + retCode = getSimLockStatus(sSimLockStatus); + if (retCode != SUCCESS) { + break; + } + + bIsSimLocked = (sSimLockStatus != "READY"); // SIM PIN, SIM PUK or other values + + retCode = getSimLockAttempts(iAttemptsPin, iAttemptsPuk); + if (retCode != SUCCESS) { + break; + } + + // Everything fetched successfully. Populate the jData object + jData[KEY_IS_SIM_INSERTED] = bIsSimInserted; + jData[KEY_IS_SIM_LOCKED] = bIsSimLocked; + jData[KEY_SIM_LOCK_STATUS] = sSimLockStatus; + jData[KEY_ATTEMPTS_PIN] = iAttemptsPin; + jData[KEY_ATTEMPTS_PUK] = iAttemptsPuk; + } while (false); + + return retCode; +} + CellularRadio::CODE CellularRadio::getLac(std::string& sLac) { Json::Value jData; -- cgit v1.2.3 From d9024556c684f2c157d472eee814e01ff2496ff9 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Sat, 22 Jun 2019 11:24:51 +0300 Subject: [MTS-MTQ] SIM status and PIN unlock procedures Added common implementations for CellularRadio::unlockSimCard and CellularRadio::getSimLockStatus --- include/mts/MTS_IO_CellularRadio.h | 5 ++++- src/MTS_IO_CellularRadio.cpp | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index 5ca9f9a..9866d73 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -76,6 +76,9 @@ namespace MTS { CODE getRegistration(REGISTRATION& eRegistration) override; CODE convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration) override; + + CODE unlockSimCard(const Json::Value& jArgs) override; + CODE getMipProfile(Json::Value& jMipProfile) override; CODE validateMsl(const Json::Value& jArgs) override; CODE setMsid(const Json::Value& jArgs) override; @@ -144,7 +147,7 @@ namespace MTS { * CODE::NOT_APPLICABLE when the modem doesn't support this feature, * CODE::ERROR otherwise (SIM card removed, modem is inaccessible, etc). */ - virtual CODE getSimLockStatus(std::string& sData) = 0; + virtual CODE getSimLockStatus(std::string& sData); /** * @brief getSimLockAttempts - get the number of SIM unlock attempts left. diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index 8c4c75b..df1303c 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -760,6 +760,31 @@ void CellularRadio::getCommonNetworkStats(Json::Value& jData) { } } +CellularRadio::CODE CellularRadio::getSimLockStatus(std::string& sData) +{ + printTrace("%s| Get SIM lock status", m_sName.c_str()); + std::string sCmd("AT+CPIN?"); + std::string sResult = sendCommand(sCmd); + + const std::string sPrefix = "+CPIN: "; + size_t start = sResult.find(sPrefix); + size_t end = sResult.rfind(ICellularRadio::RSP_OK); + + if (start == std::string::npos || end == std::string::npos) { + printWarning("%s| Unable to get SIM lock status from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + start += sPrefix.size(); + sData = MTS::Text::trim(sResult.substr(start, end-start)); + if(sData.size() == 0) { + printWarning("%s| Unable to get SIM lock status from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + return SUCCESS; +} + void CellularRadio::initMipProfile(Json::Value& jData) { jData[ICellularRadio::KEY_MIP_ID] = 0; jData[ICellularRadio::KEY_MIP_ENABLED] = false; @@ -821,6 +846,25 @@ CellularRadio::CODE CellularRadio::convertRegistrationToString(REGISTRATION eReg return eCode; } +CellularRadio::CODE CellularRadio::unlockSimCard(const Json::Value& jArgs) { + printTrace("%s| Unlock the SIM card using PIN code", m_sName.c_str()); + + if(!jArgs["pin"].isString()) { + return INVALID_ARGS; + } + + std::string sCmd = "AT+CPIN=" + jArgs["pin"].asString(); + std::string sResult = sendCommand(sCmd); + + size_t pos = sResult.find(ICellularRadio::RSP_OK); + if (pos == std::string::npos) { + printWarning("%s| Failed to unlock the SIM card using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + return SUCCESS; +} + CellularRadio::CODE CellularRadio::validateMsl(const Json::Value&) { printTrace("%s| Validate MSL", m_sName.c_str()); -- cgit v1.2.3 From 25bbcb7482dbbb93c9edfc3e1de415cfa4c260d0 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Sat, 22 Jun 2019 12:03:17 +0300 Subject: [MTS-MTQ] SIM status and PIN unlock procedures Added Telit-specific implementation of the CellularRadio::getIsSimInserted and CellularRadio::getSimLockAttempts utility methods --- include/mts/MTS_IO_TelitRadio.h | 4 ++ src/MTS_IO_TelitRadio.cpp | 91 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/include/mts/MTS_IO_TelitRadio.h b/include/mts/MTS_IO_TelitRadio.h index 70ff8a9..65ca56e 100644 --- a/include/mts/MTS_IO_TelitRadio.h +++ b/include/mts/MTS_IO_TelitRadio.h @@ -46,7 +46,11 @@ 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; + private: + virtual CODE getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk, const std::string& sLockStatus); }; } diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp index 4fcf836..8a21b46 100644 --- a/src/MTS_IO_TelitRadio.cpp +++ b/src/MTS_IO_TelitRadio.cpp @@ -537,3 +537,94 @@ bool TelitRadio::getHardwareVersionFromFirmware(const std::string& sFirmware, st return bResult; } + +CellularRadio::CODE TelitRadio::getIsSimInserted(bool& bData) { + printTrace("%s| Get SIM insertion status", getName().c_str()); + std::string sCmd("AT#SIMDET?"); + std::string sResult = sendCommand(sCmd); + + const std::string sPrefix = "#SIMDET: "; + 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#SIMDET? returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), sResult.c_str()); + return FAILURE; + } + + // #SIMDET: , + start += sPrefix.size(); + std::vector 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") { // + bData = true; + } else { + bData = false; + } + + return SUCCESS; +} + +CellularRadio::CODE TelitRadio::getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk) { + std::string sLockStatus; + CODE retCode; + + retCode = getSimLockStatus(sLockStatus); + if (retCode != SUCCESS) { + printWarning("%s| Unable determine the number of SIM unlock attempts: SIM lock status is unavailable [%s]", getName().c_str(), sLockStatus.c_str()); + return retCode; + } + + return getSimLockAttempts(iAttemptsPin, iAttemptsPuk, sLockStatus); +} + +CellularRadio::CODE TelitRadio::getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk, const std::string& sLockStatus) { + printTrace("%s| Get SIM unlock attempts left", getName().c_str()); + std::string sCmd("AT#PCT?"); + std::string sResult = sendCommand(sCmd); + std::string sValue; + int iValue; + + const std::string sPrefix = "#PCT: "; + 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#PCT? returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), sResult.c_str()); + return FAILURE; + } + + // #PCT: + start += sPrefix.size(); + sValue = MTS::Text::trim(sResult.substr(start, end-start)); + + if (!MTS::Text::parse(iValue, sValue)) { + printWarning("%s| Unable to parse SIM unlock attempts from response [%s]", getName().c_str(), sResult.c_str()); + return FAILURE; + } + + if (sLockStatus == "READY" || sLockStatus == "SIM PIN") { + iAttemptsPin = iValue; // Some PIN attempts left, maximum PUK attempts left + iAttemptsPuk = 10; + } else { + iAttemptsPin = 0; // No PIN attempts left + iAttemptsPuk = iValue; + } + + return SUCCESS; +} -- cgit v1.2.3 From 1cb0265df2b2e2171a874a52a782de3ecc6620fa Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Sat, 22 Jun 2019 12:03:17 +0300 Subject: [MTS-MTQ] SIM status and PIN unlock procedures Added Quectel-specific implementation of the CellularRadio::getIsSimInserted and CellularRadio::getSimLockAttempts utility methods --- include/mts/MTS_IO_QuectelRadio.h | 3 ++ src/MTS_IO_QuectelRadio.cpp | 79 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) 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: , + start += sPrefix.size(); + std::vector 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: ,, + // [x] ,[0] ,[1] + start += sPrefix.size(); + std::vector 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; -- cgit v1.2.3 From 28ce5eaaa648670a2c83d583ebff2dc517af002e Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Sat, 22 Jun 2019 14:39:31 +0300 Subject: [MTS-MTQ] SIM status and PIN unlock procedures Fixed a tiny issue with Telit implementation of CellularRadio::getSimLockAttempts --- src/MTS_IO_TelitRadio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp index 8a21b46..ae885e9 100644 --- a/src/MTS_IO_TelitRadio.cpp +++ b/src/MTS_IO_TelitRadio.cpp @@ -590,7 +590,7 @@ CellularRadio::CODE TelitRadio::getSimLockAttempts(int& iAttemptsPin, int& iAtte CellularRadio::CODE TelitRadio::getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk, const std::string& sLockStatus) { printTrace("%s| Get SIM unlock attempts left", getName().c_str()); - std::string sCmd("AT#PCT?"); + std::string sCmd("AT#PCT"); std::string sResult = sendCommand(sCmd); std::string sValue; int iValue; -- cgit v1.2.3 From 49429a4f10d9e40d3c2bcba2d9c8fc0d5a9bc830 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Wed, 26 Jun 2019 09:03:38 +0300 Subject: [MTS-MTQ] QuectelRadio implementation A small fix for the QuectelRadio::getNetwork - removed extra `"` character when only short / long operator name is returned by +COPS? --- src/MTS_IO_QuectelRadio.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 8ac9bac..472255f 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -167,8 +167,10 @@ CellularRadio::CODE QuectelRadio::getNetwork(std::string& sNetwork) { // +COPS: 0,0,"CHN-UNICOM UNICOM",7 // ^start ^end + // +COPS: 0,0,"AT&T",7 + // ^st ^end size_t start = sValue.find("\"") + 1; - size_t end = sValue.find(" ", start); + size_t end = sValue.find_first_of(" \"", start); sNetwork = sValue.substr(start, end-start); } else { sNetwork = ""; // Not connected to any network -- cgit v1.2.3 From 4ef332ec707946a3cf2a55473d05dfc9af3d4b11 Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Wed, 26 Jun 2019 13:05:32 +0300 Subject: [MTS-MTQ] network radio mode switch: refactoring method name --- include/mts/MTS_IO_ICellularRadio.h | 16 ++++++++-------- include/mts/MTS_IO_QuectelRadio.h | 4 ++-- include/mts/MTS_IO_TelitRadio.h | 4 ++-- src/MTS_IO_QuectelRadio.cpp | 18 +++++++++--------- src/MTS_IO_TelitRadio.cpp | 18 +++++++++--------- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h index 2d47fcf..e2bf652 100644 --- a/include/mts/MTS_IO_ICellularRadio.h +++ b/include/mts/MTS_IO_ICellularRadio.h @@ -60,12 +60,12 @@ namespace MTS { NOT_INSERTED }; - enum RADIOMODE : uint8_t { - RADIOMODE_UNKNOWN = 0, - RADIOMODE_AUTO, - RADIOMODE_GSM_ONLY, - RADIOMODE_UMTS_ONLY, - RADIOMODE_LTE_ONLY + enum RADIO_NETWORK_MODE : uint8_t { + RADIO_NETWORK_MODE_UNKNOWN = 0, + RADIO_NETWORK_MODE_AUTO, + RADIO_NETWORK_MODE_GSM_ONLY, + RADIO_NETWORK_MODE_UMTS_ONLY, + RADIO_NETWORK_MODE_LTE_ONLY }; static CODE convertModelToType(const std::string& sModel, std::string& sType); @@ -262,8 +262,6 @@ namespace MTS { virtual CODE getRegistration(REGISTRATION& eRegistration) = 0; virtual CODE convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration) = 0; - virtual CODE getRadioMode(RADIOMODE &mode) = 0; - virtual CODE setRadioMode(RADIOMODE mode) = 0; /** * @brief unlockSimCard - unlock the SIM card using PIN code provided * @@ -283,6 +281,8 @@ namespace MTS { * or on any other error). */ virtual CODE unlockSimCard(const Json::Value& jArgs) = 0; + virtual CODE getRadioNetworkMode(RADIO_NETWORK_MODE &mode) = 0; + virtual CODE setRadioNetworkMode(RADIO_NETWORK_MODE mode) = 0; //! Gather details of the radio's Mobile IP Profile /*! diff --git a/include/mts/MTS_IO_QuectelRadio.h b/include/mts/MTS_IO_QuectelRadio.h index 3e5886c..557fd82 100644 --- a/include/mts/MTS_IO_QuectelRadio.h +++ b/include/mts/MTS_IO_QuectelRadio.h @@ -41,8 +41,8 @@ namespace MTS { CODE convertdBmToSignalStrength(const int32_t& dBm, int32_t& iRssi) override; CODE setMdn(const Json::Value& jArgs) override; - CODE getRadioMode(RADIOMODE &mode) override; - CODE setRadioMode(RADIOMODE mode) override; + CODE getRadioNetworkMode(RADIO_NETWORK_MODE &mode) override; + CODE setRadioNetworkMode(RADIO_NETWORK_MODE mode) override; protected: QuectelRadio(const std::string& sName, const std::string& sRadioPort); diff --git a/include/mts/MTS_IO_TelitRadio.h b/include/mts/MTS_IO_TelitRadio.h index 08b144c..6382696 100644 --- a/include/mts/MTS_IO_TelitRadio.h +++ b/include/mts/MTS_IO_TelitRadio.h @@ -39,8 +39,8 @@ namespace MTS { CODE convertdBmToSignalStrength(const int32_t& dBm, int32_t& iRssi) override; CODE setMdn(const Json::Value& jArgs) override; - CODE getRadioMode(RADIOMODE &mode) override; - CODE setRadioMode(RADIOMODE mode) override; + CODE getRadioNetworkMode(RADIO_NETWORK_MODE &mode) override; + CODE setRadioNetworkMode(RADIO_NETWORK_MODE mode) override; protected: TelitRadio(const std::string& sName, const std::string& sRadioPort); diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 472255f..6f97989 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -576,7 +576,7 @@ CellularRadio::CODE QuectelRadio::convertToActiveBand(const std::string& sQuecte return SUCCESS; } -ICellularRadio::CODE QuectelRadio::getRadioMode(RADIOMODE &mode) +ICellularRadio::CODE QuectelRadio::getRadioNetworkMode(RADIO_NETWORK_MODE &mode) { std::string sCmd("AT+QCFG=\"nwscanmode\""); std::string cmdResult = sendCommand(sCmd); @@ -585,21 +585,21 @@ ICellularRadio::CODE QuectelRadio::getRadioMode(RADIOMODE &mode) return FAILURE; } switch (stoi(MTS::Text::split(cmdResult, ',')[1])) { - case 1: mode = ICellularRadio::RADIOMODE_GSM_ONLY; break; - case 5: mode = ICellularRadio::RADIOMODE_UMTS_ONLY; break; - case 0: mode = ICellularRadio::RADIOMODE_AUTO; break; - default: mode = ICellularRadio::RADIOMODE_UNKNOWN; break; + case 1: mode = ICellularRadio::RADIO_NETWORK_MODE_GSM_ONLY; break; + case 5: mode = ICellularRadio::RADIO_NETWORK_MODE_UMTS_ONLY; break; + case 0: mode = ICellularRadio::RADIO_NETWORK_MODE_AUTO; break; + default: mode = ICellularRadio::RADIO_NETWORK_MODE_UNKNOWN; break; } return SUCCESS; } -ICellularRadio::CODE QuectelRadio::setRadioMode(RADIOMODE mode) +ICellularRadio::CODE QuectelRadio::setRadioNetworkMode(RADIO_NETWORK_MODE mode) { std::string value; switch (mode) { - case ICellularRadio::RADIOMODE_GSM_ONLY: value = "1"; break; - case ICellularRadio::RADIOMODE_UMTS_ONLY: value = "5"; break; - case ICellularRadio::RADIOMODE_AUTO: value = "0"; break; + case ICellularRadio::RADIO_NETWORK_MODE_GSM_ONLY: value = "1"; break; + case ICellularRadio::RADIO_NETWORK_MODE_UMTS_ONLY: value = "5"; break; + case ICellularRadio::RADIO_NETWORK_MODE_AUTO: value = "0"; break; default: return FAILURE; } std::string sCmd("AT+QCFG=\"nwscanmode\","); diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp index 2d0422d..bafbd35 100644 --- a/src/MTS_IO_TelitRadio.cpp +++ b/src/MTS_IO_TelitRadio.cpp @@ -538,7 +538,7 @@ bool TelitRadio::getHardwareVersionFromFirmware(const std::string& sFirmware, st } -ICellularRadio::CODE TelitRadio::getRadioMode(RADIOMODE &mode) +ICellularRadio::CODE TelitRadio::getRadioNetworkMode(RADIO_NETWORK_MODE &mode) { std::string sCmd("AT+WS46?"); std::string cmdResult = sendCommand(sCmd); @@ -547,21 +547,21 @@ ICellularRadio::CODE TelitRadio::getRadioMode(RADIOMODE &mode) return FAILURE; } switch (stoi(MTS::Text::split(cmdResult, ':')[1])) { - case 12: mode = ICellularRadio::RADIOMODE_GSM_ONLY; break; - case 22: mode = ICellularRadio::RADIOMODE_UMTS_ONLY; break; - case 25: mode = ICellularRadio::RADIOMODE_AUTO; break; - default: mode = ICellularRadio::RADIOMODE_UNKNOWN; break; + case 12: mode = ICellularRadio::RADIO_NETWORK_MODE_GSM_ONLY; break; + case 22: mode = ICellularRadio::RADIO_NETWORK_MODE_UMTS_ONLY; break; + case 25: mode = ICellularRadio::RADIO_NETWORK_MODE_AUTO; break; + default: mode = ICellularRadio::RADIO_NETWORK_MODE_UNKNOWN; break; } return SUCCESS; } -ICellularRadio::CODE TelitRadio::setRadioMode(RADIOMODE mode) +ICellularRadio::CODE TelitRadio::setRadioNetworkMode(RADIO_NETWORK_MODE mode) { std::string value; switch (mode) { - case ICellularRadio::RADIOMODE_GSM_ONLY: value = "12"; break; - case ICellularRadio::RADIOMODE_UMTS_ONLY: value = "22"; break; - case ICellularRadio::RADIOMODE_AUTO: value = "25"; break; + case ICellularRadio::RADIO_NETWORK_MODE_GSM_ONLY: value = "12"; break; + case ICellularRadio::RADIO_NETWORK_MODE_UMTS_ONLY: value = "22"; break; + case ICellularRadio::RADIO_NETWORK_MODE_AUTO: value = "25"; break; default: return FAILURE; } std::string sCmd("AT+WS46="); -- cgit v1.2.3 From 0de89b68bd4471df424eca976d60ae98dea309df Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Fri, 5 Jul 2019 12:53:11 +0300 Subject: [MTX-2886] MTR_MTQ - radio-cmd shows invalid message on valid SIM PIN Added a timeout of 5 seconds for the SIM PIN unlock command --- src/MTS_IO_CellularRadio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index df1303c..500f352 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -854,7 +854,7 @@ CellularRadio::CODE CellularRadio::unlockSimCard(const Json::Value& jArgs) { } std::string sCmd = "AT+CPIN=" + jArgs["pin"].asString(); - std::string sResult = sendCommand(sCmd); + std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 5000); size_t pos = sResult.find(ICellularRadio::RSP_OK); if (pos == std::string::npos) { -- cgit v1.2.3 From 6042426e8d21b9b92f7078f64f4b50c2f1b8bc8d Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Mon, 15 Jul 2019 17:10:08 +0300 Subject: [MTX-2886] MTR_MTQ - radio-cmd shows invalid message on valid SIM PIN Fixed the timeouts for several AT commands, including SIM-related commands --- src/MTS_IO_CellularRadio.cpp | 24 +++++++++++++++++++----- src/MTS_IO_QuectelRadio.cpp | 22 +++++++++++++++++----- src/MTS_IO_TelitRadio.cpp | 2 +- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index 500f352..195ba4f 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -237,8 +237,11 @@ CellularRadio::CODE CellularRadio::getManufacturer(std::string& sManufacturer) { CellularRadio::CODE CellularRadio::getImei(std::string& sImei) { printTrace("%s| Get IMEI", m_sName.c_str()); sImei = ICellularRadio::VALUE_NOT_SUPPORTED; + + // AT+CGSN execution can take up to 300ms according to the Quectel datasheet. Setting timeout to 500ms just for sure. std::string sCmd("AT+CGSN"); - std::string sResult = sendCommand(sCmd); + std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 500); + size_t pos = sResult.find(ICellularRadio::RSP_OK); if (pos == std::string::npos) { printWarning("%s| Unable to get IMEI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); @@ -262,8 +265,11 @@ CellularRadio::CODE CellularRadio::getMeid(std::string& sMeid) { CellularRadio::CODE CellularRadio::getImsi(std::string& sImsi) { printTrace("%s| Get IMSI", m_sName.c_str()); sImsi = ICellularRadio::VALUE_NOT_SUPPORTED; + + // AT+CIMI execution can take up to 300ms according to the Quectel datasheet. Setting timeout to 500ms just for sure. std::string sCmd("AT+CIMI"); - std::string sResult = sendCommand(sCmd); + std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 500); + size_t pos = sResult.find(ICellularRadio::RSP_OK); if (pos == std::string::npos) { printWarning("%s| Unable to get IMSI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); @@ -348,8 +354,11 @@ CellularRadio::CODE CellularRadio::getLac(std::string& sLac) { CellularRadio::CODE CellularRadio::getMdn(std::string& sMdn) { printTrace("%s| Get MDN", m_sName.c_str()); sMdn = ICellularRadio::VALUE_NOT_SUPPORTED; + + // AT+CNUM execution can take up to 300ms according to the Quectel datasheet. Setting timeout to 500ms just for sure. std::string sCmd("AT+CNUM"); - std::string sResult = sendCommand(sCmd); + std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 500); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get MDN from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); @@ -534,8 +543,11 @@ CellularRadio::CODE CellularRadio::getRoaming(bool& bRoaming) { CellularRadio::CODE CellularRadio::getSignalStrength(int32_t& rssi) { printTrace("%s| Get Signal Strength", m_sName.c_str()); + + // AT+CSQ execution can take up to 300ms according to the Quectel datasheet. Setting timeout to 500ms just for sure. std::string sCmd("AT+CSQ"); - std::string sResult = sendCommand(sCmd); + std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 500); + if (sResult.find("+CSQ: ") == std::string::npos) { printDebug("%s| Signal Strength command returned unexpected response: [%s]", m_sName.c_str(), sResult.c_str()); return FAILURE; @@ -763,8 +775,10 @@ void CellularRadio::getCommonNetworkStats(Json::Value& jData) { CellularRadio::CODE CellularRadio::getSimLockStatus(std::string& sData) { printTrace("%s| Get SIM lock status", m_sName.c_str()); + + // SIM card may introduce a delay to AT+CPIN? execution. Setting timeout to 1s as set in PPP chat patches. std::string sCmd("AT+CPIN?"); - std::string sResult = sendCommand(sCmd); + std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 1000); const std::string sPrefix = "+CPIN: "; size_t start = sResult.find(sPrefix); diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 6f97989..b8c781f 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -73,8 +73,11 @@ CellularRadio::CODE QuectelRadio::getModel(std::string& sModel) { CellularRadio::CODE QuectelRadio::getIccid(std::string& sIccid) { printTrace("%s| Get ICCID", getName().c_str()); sIccid = ICellularRadio::VALUE_NOT_SUPPORTED; + + // AT+QCCID execution can take up to 300ms according to the datasheet. Setting timeout to 500ms just for sure. std::string sCmd("AT+QCCID"); - std::string sResult = sendCommand(sCmd); + std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 500); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get ICCID from radio using command [%s]", getName().c_str(), sCmd.c_str()); @@ -482,8 +485,10 @@ bool QuectelRadio::getHardwareVersionFromFirmware(const std::string& sFirmware, CellularRadio::CODE QuectelRadio::getIsSimInserted(bool& bData) { printTrace("%s| Get SIM insertion status", getName().c_str()); + + // AT+QSIMSTAT? execution can take up to 300ms according to the datasheet. Setting timeout to 500ms just for sure. std::string sCmd("AT+QSIMSTAT?"); - std::string sResult = sendCommand(sCmd); + std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 500); const std::string sPrefix = "+QSIMSTAT: "; size_t start = sResult.find(sPrefix); @@ -519,8 +524,10 @@ CellularRadio::CODE QuectelRadio::getIsSimInserted(bool& bData) { CellularRadio::CODE QuectelRadio::getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk) { printTrace("%s| Get SIM unlock attempts left", getName().c_str()); + + // AT+QPINC execution can take up to 300ms according to the datasheet. Setting timeout to 500ms just for sure. std::string sCmd("AT+QPINC=\"SC\""); - std::string sResult = sendCommand(sCmd); + std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 500); const std::string sPrefix = "+QPINC: \"SC\","; size_t start = sResult.find(sPrefix); @@ -578,8 +585,10 @@ CellularRadio::CODE QuectelRadio::convertToActiveBand(const std::string& sQuecte ICellularRadio::CODE QuectelRadio::getRadioNetworkMode(RADIO_NETWORK_MODE &mode) { + // AT+QCFG="nwscanmode" execution can take up to 300ms according to the datasheet. Setting timeout to 500ms just for sure. std::string sCmd("AT+QCFG=\"nwscanmode\""); - std::string cmdResult = sendCommand(sCmd); + std::string cmdResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 500); + if (cmdResult.find(ICellularRadio::RSP_OK) == std::string::npos) { printDebug("%s| AT+QCFG? returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), cmdResult.c_str()); return FAILURE; @@ -604,7 +613,10 @@ ICellularRadio::CODE QuectelRadio::setRadioNetworkMode(RADIO_NETWORK_MODE mode) } std::string sCmd("AT+QCFG=\"nwscanmode\","); sCmd += value; - std::string cmdResult = sendCommand(sCmd); + + // AT+QCFG="nwscanmode" execution can take up to 300ms according to the datasheet. Setting timeout to 500ms just for sure. + std::string cmdResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 500); + if (cmdResult.find(ICellularRadio::RSP_OK) == std::string::npos) { printDebug("%s| AT+QCFG? returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), cmdResult.c_str()); return FAILURE; diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp index bafbd35..c8448e2 100644 --- a/src/MTS_IO_TelitRadio.cpp +++ b/src/MTS_IO_TelitRadio.cpp @@ -627,7 +627,7 @@ CellularRadio::CODE TelitRadio::getSimLockAttempts(int& iAttemptsPin, int& iAtte CellularRadio::CODE TelitRadio::getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk, const std::string& sLockStatus) { printTrace("%s| Get SIM unlock attempts left", getName().c_str()); std::string sCmd("AT#PCT"); - std::string sResult = sendCommand(sCmd); + std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 500); std::string sValue; int iValue; -- cgit v1.2.3 From 05628f9b5868c60d68aa750f547b010d22ac27b4 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Mon, 15 Jul 2019 17:12:17 +0300 Subject: [MTS-MTQ] QuectelRadio implementation Cleanup: Removed a comment for a function whose implementation was moved to the radio-specific classes --- src/MTS_IO_CellularRadio.cpp | 76 -------------------------------------------- 1 file changed, 76 deletions(-) diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index 195ba4f..4dcea7d 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -609,82 +609,6 @@ CellularRadio::CODE CellularRadio::getStaticInformation(Json::Value& jData) { return FAILURE; } -/* AT#RFSTS - NETWORK STATUS - - (GSM network) - #RFSTS:,,,,,,,,,,,,, - Where: - - Country code and operator code(MCC, MNC) - - GSM Assigned Radio Channel - - Received Signal Strength Indication - - Localization Area Code - - Routing Area Code - - Tx Power - - Mobility Management state - - Radio Resource state - - Network Operator Mode - - Cell ID - - International Mobile Subscriber Identity - - Operator name - - Service Domain - 0 - No Service - 1 - CS only - 2 - PS only - 3 - CS+PS - - Active Band - 1 - GSM 850 - 2 - GSM 900 - 3 - DCS 1800 - 4 - PCS 1900 - - - (WCDMA network) - #RFSTS: - ,,,,, RSSI>,,,,,,,,,,, - ,,[,,] - Where: - - Country code and operator code(MCC, MNC) - - UMTS Assigned Radio Channel - - Active PSC(Primary Synchronization Code) - - Active Ec/Io(chip energy per total wideband power in dBm) - - Active RSCP (Received Signal Code Power in dBm) - - Received Signal Strength Indication - - Localization Area Code - - Routing Area Code - - Tx Power - - Discontinuous reception cycle Length (cycle length in ms) - - Mobility Management state - - Radio Resource state - - Network Operator Mode - - Block Error Rate (e.g., 005 means 0.5 %) - - Cell ID - - International Mobile Station ID - - Operator name - - Service Domain (see above) - - Number of Active Set (Maximum 6) - UARFCN of n th active set - PSC of n th active set - Ec/Io of n th active Set - - (LTE Network) - #RFSTS: - - - - - - - - - - - - - [] - - - - - - - - - - - - [] - - - - - -*/ - // Get the LAC for the LTE radio that's not in the #RFSTS or +QENG response std::string CellularRadio::queryLteLac() { std::string CGREGstring; -- cgit v1.2.3 From 60f4460b88b7c72f738dba47843961076c21ab9a Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Mon, 15 Jul 2019 17:46:22 +0300 Subject: [MTS-MTQ] SIM status and PIN unlock procedures Increased timeout for the AT+QPINC="SC" command up to 2 seconds as the modem fails to respond in the current 500ms time limit while executing several successive commands. --- src/MTS_IO_QuectelRadio.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index b8c781f..a9f9721 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -525,9 +525,9 @@ CellularRadio::CODE QuectelRadio::getIsSimInserted(bool& bData) { CellularRadio::CODE QuectelRadio::getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk) { printTrace("%s| Get SIM unlock attempts left", getName().c_str()); - // AT+QPINC execution can take up to 300ms according to the datasheet. Setting timeout to 500ms just for sure. + // AT+QPINC execution can take more time that expected. Set timeout to 2s just to be sure. std::string sCmd("AT+QPINC=\"SC\""); - std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 500); + std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 2000); const std::string sPrefix = "+QPINC: \"SC\","; size_t start = sResult.find(sPrefix); -- cgit v1.2.3 From ebfa95037a98d785029dc9afe8e4aafd8c81b843 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Thu, 18 Jul 2019 11:59:02 +0300 Subject: [MTS-MTQ] QuectelRadio implementation Now using "" field instead on number of fields returned in "AT+QENG" result for the QuectelRadio::getNetworkStatus implementation. This change was implemented after a code review. --- src/MTS_IO_QuectelRadio.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index a9f9721..4d13e7b 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -211,13 +211,15 @@ CellularRadio::CODE QuectelRadio::getNetwork(std::string& sNetwork) { +QENG:"servingcell",,"LTE",,,,,,,,,,,,,, */ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { + const std::string RAT_GSM = "GSM"; + const std::string RAT_WCDMA = "WCDMA"; + const std::string RAT_LTE = "LTE"; + int32_t iValue; ACTIVEBAND abnd; SERVICEDOMAIN sd; std::string sValue; - const uint32_t GSM_NETWORK_FORMAT = 27; - const uint32_t WCDMA_NETWORK_FORMAT = 17; - const uint32_t LTE_NETWORK_FORMAT = 18; + std::string sRat; // Radio Access Technology which is currently used printTrace("%s| Get Network Status", getName().c_str()); @@ -260,12 +262,14 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { } else { // UE state and Access technology, Quectel-specific information jQuectelDebug["state"] = vParts[1]; - jQuectelDebug["rat"] = vParts[2]; + + sRat = MTS::Text::trim(vParts[2], '"'); + jQuectelDebug["rat"] = sRat; } // +QENG:"servingscell",,"GSM",,,,,,,,,,,,,,,,,,,,,,,, // +QENG: [0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13],[14],[15], [16], [17],[18],[19], [20], [21], [22], [23], [24], [25], [26] - if (vParts.size() == GSM_NETWORK_FORMAT ) { + if (sRat == RAT_GSM) { //Parse as GSM Network Format jData[ICellularRadio::KEY_MCC] = vParts[3]; jData[ICellularRadio::KEY_MNC] = vParts[4]; @@ -308,7 +312,7 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { // +QENG:"servingcell",,"WCDMA",,,,,,,,,,,,,, // +QENG: [0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12],[13], [14], [15], [16] - else if((vParts.size() == WCDMA_NETWORK_FORMAT)) { + else if(sRat == RAT_WCDMA) { //Parse as WCDMA Network Format jData[ICellularRadio::KEY_MCC] = vParts[3]; jData[ICellularRadio::KEY_MNC] = vParts[4]; @@ -347,7 +351,7 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { // +QENG:"servingcell",,"LTE",,,,,,,,,,,,,,, // +QENG: [0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17] - else if(vParts.size() == LTE_NETWORK_FORMAT) { + else if(sRat == RAT_LTE) { //Parse as LTE Network Format jQuectelDebug["isTdd"] = vParts[3]; jData[ICellularRadio::KEY_MCC] = vParts[4]; -- cgit v1.2.3 From fe970f5bb77354b7507e230b1465e9178c80ee7a Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Thu, 18 Jul 2019 11:59:02 +0300 Subject: [MTS-MTQ] QuectelRadio implementation Refactored the CellularRadio class to include base stub implementation for the "CellularRadio::getCarrierFromFirmware" and "CellularRadio::getHardwareVersionFromFirmware" methods. From now assuming that those two possibilities are not supported by the modem until otherwise specified (i.e. until the method implementation was overridden in derived class). This change was implemented after a code review. --- include/mts/MTS_IO_CellularRadio.h | 4 ++-- include/mts/MTS_IO_QuectelRadio.h | 3 --- src/MTS_IO_CellularRadio.cpp | 12 ++++++++++++ src/MTS_IO_QuectelRadio.cpp | 17 ----------------- 4 files changed, 14 insertions(+), 22 deletions(-) diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index 9866d73..eecefee 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -121,8 +121,8 @@ namespace MTS { CellularRadio(const std::string& sName, const std::string& sRadioPort); - virtual bool getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier) = 0; - virtual bool getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware) = 0; + virtual bool getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier); + virtual bool getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware); virtual void getCommonNetworkStats(Json::Value& jData); diff --git a/include/mts/MTS_IO_QuectelRadio.h b/include/mts/MTS_IO_QuectelRadio.h index 557fd82..3b1ba5a 100644 --- a/include/mts/MTS_IO_QuectelRadio.h +++ b/include/mts/MTS_IO_QuectelRadio.h @@ -47,9 +47,6 @@ namespace MTS { protected: QuectelRadio(const std::string& sName, const std::string& sRadioPort); - 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; diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index 4dcea7d..feccd3c 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -976,6 +976,18 @@ bool CellularRadio::splitAndAssign(const std::string& sLine, const std::string& return true; } +bool CellularRadio::getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier) { + // Assuming that this function is not supported by the modem until overriden. + + return false; +} + +bool CellularRadio::getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware) { + // Assuming that this function is not supported by the modem until overriden. + + return false; +} + const char *CellularRadio::RadioBandMap::getLTEBand(const int32_t channel) { for (unsigned int ii = 0; ii < NUM_LTE_BANDS; ii++) diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 4d13e7b..0712788 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -470,23 +470,6 @@ CellularRadio::CODE QuectelRadio::getServiceDomain(ICellularRadio::SERVICEDOMAIN return SUCCESS; } -bool QuectelRadio::getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier) { - // TODO: Implement properly if needed - // This function is used only in CdmaRadio implementation but was defined in - // the CellularRadio class before refactoring. - - // Find out if and how we can determine the operator by firmware version. - - return false; -} - -bool QuectelRadio::getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware) { - // TODO: Implement properly - // Find out if and how we can extract the hardware version from firmware version on Quectel devices - - return false; -} - CellularRadio::CODE QuectelRadio::getIsSimInserted(bool& bData) { printTrace("%s| Get SIM insertion status", getName().c_str()); -- cgit v1.2.3 From 0330513b8913d1d7bf14bad99d64ab002b770b7c Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Thu, 18 Jul 2019 11:41:24 +0300 Subject: [MTR-MTQ] Namespace-related usage improvements Restored full qualification of the ICellularRadio::CODE object type for all files that used full qualification before (effectively, for all source files and only one header file). This commit partially reverses 53efcef2e2f521135b323e194c45f1d9fa7b5d5d. --- include/mts/MTS_IO_ME910C1WWRadio.h | 4 +- src/MTS_IO_CE910Radio.cpp | 2 +- src/MTS_IO_CdmaRadio.cpp | 76 +++++++++++++-------------- src/MTS_IO_CellularRadio.cpp | 102 ++++++++++++++++++------------------ src/MTS_IO_DE910Radio.cpp | 2 +- src/MTS_IO_EG95Radio.cpp | 2 +- src/MTS_IO_GE910Radio.cpp | 2 +- src/MTS_IO_HE910Radio.cpp | 2 +- src/MTS_IO_LE910C1APRadio.cpp | 2 +- src/MTS_IO_LE910C1NSRadio.cpp | 2 +- src/MTS_IO_LE910NA1Radio.cpp | 8 +-- src/MTS_IO_LE910Radio.cpp | 4 +- src/MTS_IO_LE910SVGRadio.cpp | 2 +- src/MTS_IO_ME910C1NVRadio.cpp | 40 +++++++------- src/MTS_IO_ME910C1WWRadio.cpp | 8 +-- src/MTS_IO_ME910Radio.cpp | 4 +- src/MTS_IO_QuectelRadio.cpp | 24 ++++----- src/MTS_IO_TelitRadio.cpp | 24 ++++----- 18 files changed, 155 insertions(+), 155 deletions(-) diff --git a/include/mts/MTS_IO_ME910C1WWRadio.h b/include/mts/MTS_IO_ME910C1WWRadio.h index 6612d83..d45d86a 100644 --- a/include/mts/MTS_IO_ME910C1WWRadio.h +++ b/include/mts/MTS_IO_ME910C1WWRadio.h @@ -33,8 +33,8 @@ namespace MTS { ME910C1WWRadio(const std::string& sPort); virtual ~ME910C1WWRadio(){}; - CODE setActiveFirmware(const Json::Value& jArgs); - CODE getActiveFirmware(std::string& sFwId); + ICellularRadio::CODE setActiveFirmware(const Json::Value& jArgs); + ICellularRadio::CODE getActiveFirmware(std::string& sFwId); protected: diff --git a/src/MTS_IO_CE910Radio.cpp b/src/MTS_IO_CE910Radio.cpp index fc6cfd4..d1cad9b 100644 --- a/src/MTS_IO_CE910Radio.cpp +++ b/src/MTS_IO_CE910Radio.cpp @@ -39,7 +39,7 @@ CE910Radio::CE910Radio(const std::string& sPort) } -CE910Radio::CODE CE910Radio::setRxDiversity(const Json::Value& jArgs) { +ICellularRadio::CODE CE910Radio::setRxDiversity(const Json::Value& jArgs) { /* Command string for CE radios: N/A */ return FAILURE; } diff --git a/src/MTS_IO_CdmaRadio.cpp b/src/MTS_IO_CdmaRadio.cpp index 09db89b..f84fd34 100644 --- a/src/MTS_IO_CdmaRadio.cpp +++ b/src/MTS_IO_CdmaRadio.cpp @@ -44,12 +44,12 @@ CdmaRadio::~CdmaRadio() { } -CdmaRadio::CODE CdmaRadio::getImei(std::string& sImei) { +ICellularRadio::CODE CdmaRadio::getImei(std::string& sImei) { printTrace("%s| Get IMEI", getName().c_str()); return getMeid(sImei); } -CdmaRadio::CODE CdmaRadio::getMeid(std::string& sMeid) { +ICellularRadio::CODE CdmaRadio::getMeid(std::string& sMeid) { printTrace("%s| Get MEID", getName().c_str()); sMeid = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT#MEIDESN?"); @@ -72,7 +72,7 @@ CdmaRadio::CODE CdmaRadio::getMeid(std::string& sMeid) { return SUCCESS; } -CdmaRadio::CODE CdmaRadio::getMsid(std::string& sMsid) { +ICellularRadio::CODE CdmaRadio::getMsid(std::string& sMsid) { printTrace("%s| Get MSID", getName().c_str()); sMsid = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT$MSID?"); @@ -92,14 +92,14 @@ CdmaRadio::CODE CdmaRadio::getMsid(std::string& sMsid) { return SUCCESS; } -CdmaRadio::CODE CdmaRadio::getCarrier(std::string& sCarrier) { +ICellularRadio::CODE CdmaRadio::getCarrier(std::string& sCarrier) { if(m_sCarrier != "") { sCarrier = m_sCarrier; return SUCCESS; } std::string sFirmware; - CODE code = getFirmware(sFirmware); + ICellularRadio::CODE code = getFirmware(sFirmware); if(code != SUCCESS) { return code; } @@ -113,29 +113,29 @@ CdmaRadio::CODE CdmaRadio::getCarrier(std::string& sCarrier) { return SUCCESS; } -CdmaRadio::CODE CdmaRadio::getNetwork(std::string& sNetwork) { +ICellularRadio::CODE CdmaRadio::getNetwork(std::string& sNetwork) { return getCarrier(sNetwork); } -CdmaRadio::CODE CdmaRadio::getSimStatus(std::string& sSimStatus) { +ICellularRadio::CODE CdmaRadio::getSimStatus(std::string& sSimStatus) { printTrace("%s| Get SIM Status", getName().c_str()); sSimStatus = ICellularRadio::VALUE_NOT_SUPPORTED; return NOT_APPLICABLE; } -CdmaRadio::CODE CdmaRadio::getIccid(std::string& sIccid) { +ICellularRadio::CODE CdmaRadio::getIccid(std::string& sIccid) { printTrace("%s| Get ICCID", getName().c_str()); sIccid = ICellularRadio::VALUE_NOT_SUPPORTED; return NOT_APPLICABLE; } -CdmaRadio::CODE CdmaRadio::getLac(std::string& sLac) { +ICellularRadio::CODE CdmaRadio::getLac(std::string& sLac) { printTrace("%s| Get LAC", getName().c_str()); sLac = ICellularRadio::VALUE_NOT_SUPPORTED; return NOT_APPLICABLE; } -CdmaRadio::CODE CdmaRadio::getService(std::string& sService) { +ICellularRadio::CODE CdmaRadio::getService(std::string& sService) { printTrace("%s| Get Service", getName().c_str()); sService = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT+SERVICE?"); @@ -167,7 +167,7 @@ CdmaRadio::CODE CdmaRadio::getService(std::string& sService) { return SUCCESS; } -CdmaRadio::CODE CdmaRadio::getHardware(std::string& sHardware) { +ICellularRadio::CODE CdmaRadio::getHardware(std::string& sHardware) { printTrace("%s| Get Hardware", getName().c_str()); sHardware = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT#HWREV"); @@ -187,7 +187,7 @@ CdmaRadio::CODE CdmaRadio::getHardware(std::string& sHardware) { return SUCCESS; } -CdmaRadio::CODE CdmaRadio::getMdn(std::string& sMdn) { +ICellularRadio::CODE CdmaRadio::getMdn(std::string& sMdn) { printTrace("%s| Get MDN", getName().c_str()); sMdn = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT+CNUM"); @@ -213,7 +213,7 @@ CdmaRadio::CODE CdmaRadio::getMdn(std::string& sMdn) { return SUCCESS; } -CdmaRadio::CODE CdmaRadio::validateMsl(const Json::Value& jArgs) { +ICellularRadio::CODE CdmaRadio::validateMsl(const Json::Value& jArgs) { printTrace("%s| Validate MSL", getName().c_str()); if(!jArgs["msl"].isString()) { @@ -239,7 +239,7 @@ CdmaRadio::CODE CdmaRadio::validateMsl(const Json::Value& jArgs) { return setMdn(jMdn); } -CdmaRadio::CODE CdmaRadio::setMdn(const Json::Value& jArgs) { +ICellularRadio::CODE CdmaRadio::setMdn(const Json::Value& jArgs) { printTrace("%s| Set MDN", getName().c_str()); if(!jArgs["mdn"].isString()) { @@ -283,7 +283,7 @@ CdmaRadio::CODE CdmaRadio::setMdn(const Json::Value& jArgs) { return SUCCESS; } -CdmaRadio::CODE CdmaRadio::setMsid(const Json::Value& jArgs) { +ICellularRadio::CODE CdmaRadio::setMsid(const Json::Value& jArgs) { printTrace("%s| Set MSID", getName().c_str()); if(!jArgs["msid"].isString()) { printError("%s| Arguments missing \"msid\"", getName().c_str()); @@ -318,7 +318,7 @@ CdmaRadio::CODE CdmaRadio::setMsid(const Json::Value& jArgs) { return SUCCESS; } -CdmaRadio::CODE CdmaRadio::getMipProfile(Json::Value& jMipProfile) { +ICellularRadio::CODE CdmaRadio::getMipProfile(Json::Value& jMipProfile) { printTrace("%s| Get MIP Active Profile", getName().c_str()); initMipProfile(jMipProfile); @@ -406,7 +406,7 @@ CdmaRadio::CODE CdmaRadio::getMipProfile(Json::Value& jMipProfile) { } -CdmaRadio::CODE CdmaRadio::setMipActiveProfile(const Json::Value& jArgs) { +ICellularRadio::CODE CdmaRadio::setMipActiveProfile(const Json::Value& jArgs) { printTrace("%s| Set MIP Active Profile", getName().c_str()); if(!jArgs["activeProfile"].isString()) { @@ -426,7 +426,7 @@ CdmaRadio::CODE CdmaRadio::setMipActiveProfile(const Json::Value& jArgs) { return SUCCESS; } -CdmaRadio::CODE CdmaRadio::setMipNai(const Json::Value& jArgs) { +ICellularRadio::CODE CdmaRadio::setMipNai(const Json::Value& jArgs) { printTrace("%s| Set MIP NAI", getName().c_str()); if(!jArgs["nai"].isString()) { @@ -446,7 +446,7 @@ CdmaRadio::CODE CdmaRadio::setMipNai(const Json::Value& jArgs) { return SUCCESS; } -CdmaRadio::CODE CdmaRadio::setMipHomeIp(const Json::Value& jArgs) { +ICellularRadio::CODE CdmaRadio::setMipHomeIp(const Json::Value& jArgs) { printTrace("%s| Set MIP Home IP", getName().c_str()); if(!jArgs["homeIp"].isString()) { @@ -466,7 +466,7 @@ CdmaRadio::CODE CdmaRadio::setMipHomeIp(const Json::Value& jArgs) { return SUCCESS; } -CdmaRadio::CODE CdmaRadio::setMipPrimaryHa(const Json::Value& jArgs) { +ICellularRadio::CODE CdmaRadio::setMipPrimaryHa(const Json::Value& jArgs) { printTrace("%s| Set MIP Primary HA", getName().c_str()); if(!jArgs["primaryHa"].isString()) { @@ -486,7 +486,7 @@ CdmaRadio::CODE CdmaRadio::setMipPrimaryHa(const Json::Value& jArgs) { return SUCCESS; } -CdmaRadio::CODE CdmaRadio::setMipSecondaryHa(const Json::Value& jArgs) { +ICellularRadio::CODE CdmaRadio::setMipSecondaryHa(const Json::Value& jArgs) { printTrace("%s| Set MIP Secondary HA", getName().c_str()); if(!jArgs["secondaryHa"].isString()) { @@ -506,7 +506,7 @@ CdmaRadio::CODE CdmaRadio::setMipSecondaryHa(const Json::Value& jArgs) { return SUCCESS; } -CdmaRadio::CODE CdmaRadio::setMipMnAaaSpi(const Json::Value& jArgs) { +ICellularRadio::CODE CdmaRadio::setMipMnAaaSpi(const Json::Value& jArgs) { printTrace("%s| Set MIP MN-AAA SPI", getName().c_str()); if(!jArgs["mnAaaSpi"].isString()) { @@ -526,7 +526,7 @@ CdmaRadio::CODE CdmaRadio::setMipMnAaaSpi(const Json::Value& jArgs) { return SUCCESS; } -CdmaRadio::CODE CdmaRadio::setMipMnHaSpi(const Json::Value& jArgs) { +ICellularRadio::CODE CdmaRadio::setMipMnHaSpi(const Json::Value& jArgs) { printTrace("%s| Set MIP MN-HA SPI", getName().c_str()); if(!jArgs["mnHaSpi"].isString()) { @@ -546,7 +546,7 @@ CdmaRadio::CODE CdmaRadio::setMipMnHaSpi(const Json::Value& jArgs) { return SUCCESS; } -CdmaRadio::CODE CdmaRadio::setMipRevTun(const Json::Value& jArgs) { +ICellularRadio::CODE CdmaRadio::setMipRevTun(const Json::Value& jArgs) { printTrace("%s| Set MIP Rev Tun", getName().c_str()); if(!jArgs["revTun"].isString()) { @@ -566,7 +566,7 @@ CdmaRadio::CODE CdmaRadio::setMipRevTun(const Json::Value& jArgs) { return SUCCESS; } -CdmaRadio::CODE CdmaRadio::setMipMnAaaSs(const Json::Value& jArgs) { +ICellularRadio::CODE CdmaRadio::setMipMnAaaSs(const Json::Value& jArgs) { printTrace("%s| Set MIP MN-AAA SS", getName().c_str()); if(!jArgs["mnAaaSs"].isString()) { @@ -586,7 +586,7 @@ CdmaRadio::CODE CdmaRadio::setMipMnAaaSs(const Json::Value& jArgs) { return SUCCESS; } -CdmaRadio::CODE CdmaRadio::setMipMnHaSs(const Json::Value& jArgs) { +ICellularRadio::CODE CdmaRadio::setMipMnHaSs(const Json::Value& jArgs) { printTrace("%s| Set MIP MN-HA SS", getName().c_str()); if(!jArgs["mnHaSs"].isString()) { @@ -606,7 +606,7 @@ CdmaRadio::CODE CdmaRadio::setMipMnHaSs(const Json::Value& jArgs) { return SUCCESS; } -CdmaRadio::CODE CdmaRadio::updateDc(const Json::Value& jArgs, UpdateCb& stepCb) { +ICellularRadio::CODE CdmaRadio::updateDc(const Json::Value& jArgs, UpdateCb& stepCb) { printTrace("%s| Update Device Configuration", getName().c_str()); std::string sCarrier; @@ -616,7 +616,7 @@ CdmaRadio::CODE CdmaRadio::updateDc(const Json::Value& jArgs, UpdateCb& stepCb) return NOT_APPLICABLE; } - CODE result = FAILURE; + ICellularRadio::CODE result = FAILURE; std::size_t pos = 0; std::size_t end = 0; @@ -703,7 +703,7 @@ CdmaRadio::CODE CdmaRadio::updateDc(const Json::Value& jArgs, UpdateCb& stepCb) return result; } -CdmaRadio::CODE CdmaRadio::updatePrl(const Json::Value& jArgs, UpdateCb& stepCb) { +ICellularRadio::CODE CdmaRadio::updatePrl(const Json::Value& jArgs, UpdateCb& stepCb) { printTrace("%s| Update Preferred Roaming List", getName().c_str()); std::string sCarrier; @@ -713,7 +713,7 @@ CdmaRadio::CODE CdmaRadio::updatePrl(const Json::Value& jArgs, UpdateCb& stepCb) return NOT_APPLICABLE; } - CODE result = FAILURE; + ICellularRadio::CODE result = FAILURE; std::size_t pos = 0; std::size_t end = 0; @@ -800,7 +800,7 @@ CdmaRadio::CODE CdmaRadio::updatePrl(const Json::Value& jArgs, UpdateCb& stepCb) return result; } -CdmaRadio::CODE CdmaRadio::updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) { +ICellularRadio::CODE CdmaRadio::updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) { printTrace("%s| Update Firmware Update Management Object", getName().c_str()); std::string sCarrier; @@ -810,7 +810,7 @@ CdmaRadio::CODE CdmaRadio::updateFumo(const Json::Value& jArgs, UpdateCb& stepCb return NOT_APPLICABLE; } - CODE result = FAILURE; + ICellularRadio::CODE result = FAILURE; std::size_t pos = 0; std::size_t end = 0; @@ -957,7 +957,7 @@ CdmaRadio::CODE CdmaRadio::updateFumo(const Json::Value& jArgs, UpdateCb& stepCb return result; } -CdmaRadio::CODE CdmaRadio::resetHfa(const Json::Value& jArgs, UpdateCb& stepCb) { +ICellularRadio::CODE CdmaRadio::resetHfa(const Json::Value& jArgs, UpdateCb& stepCb) { printTrace("%s| HFA Reset (after device reboot HFA will occur)", getName().c_str()); std::string sCarrier; @@ -971,7 +971,7 @@ CdmaRadio::CODE CdmaRadio::resetHfa(const Json::Value& jArgs, UpdateCb& stepCb) return INVALID_ARGS; } - CODE result = FAILURE; + ICellularRadio::CODE result = FAILURE; std::size_t pos = 0; std::size_t end = 0; @@ -1075,7 +1075,7 @@ CdmaRadio::CODE CdmaRadio::resetHfa(const Json::Value& jArgs, UpdateCb& stepCb) return result; } -CdmaRadio::CODE CdmaRadio::activate(const Json::Value& jArgs, UpdateCb& stepCb) { +ICellularRadio::CODE CdmaRadio::activate(const Json::Value& jArgs, UpdateCb& stepCb) { printTrace("%s| Activation", getName().c_str()); std::string sActivationCmd; @@ -1107,7 +1107,7 @@ CdmaRadio::CODE CdmaRadio::activate(const Json::Value& jArgs, UpdateCb& stepCb) } //Set MDN & MSID - CODE code; + ICellularRadio::CODE code; code = setMdn(jArgs); if(code != SUCCESS) { return code; @@ -1130,7 +1130,7 @@ CdmaRadio::CODE CdmaRadio::activate(const Json::Value& jArgs, UpdateCb& stepCb) return NOT_APPLICABLE; } - CODE result = FAILURE; + ICellularRadio::CODE result = FAILURE; std::size_t pos = 0; std::size_t end = 0; @@ -1214,7 +1214,7 @@ CdmaRadio::CODE CdmaRadio::activate(const Json::Value& jArgs, UpdateCb& stepCb) return result; } -CdmaRadio::CODE CdmaRadio::getNetworkStatus(Json::Value& jData) { +ICellularRadio::CODE CdmaRadio::getNetworkStatus(Json::Value& jData) { printTrace("%s| Get Network Status", getName().c_str()); getCommonNetworkStats(jData); diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index feccd3c..3f0c037 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -113,7 +113,7 @@ bool CellularRadio::initialize(uint32_t iTimeoutMillis) { } bool bEnabled; - CODE eCode = getEcho(bEnabled); + ICellularRadio::CODE eCode = getEcho(bEnabled); if(eCode == SUCCESS && bEnabled) { printDebug("%s| Disabling 'echo'", m_sName.c_str()); setEcho(false); @@ -173,7 +173,7 @@ const std::string& CellularRadio::getName() const { return m_sName; } -CellularRadio::CODE CellularRadio::getFirmware(std::string& sFirmware) { +ICellularRadio::CODE CellularRadio::getFirmware(std::string& sFirmware) { printTrace("%s| Get Firmware", m_sName.c_str()); sFirmware = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT+CGMR"); @@ -195,12 +195,12 @@ CellularRadio::CODE CellularRadio::getFirmware(std::string& sFirmware) { return SUCCESS; } -CellularRadio::CODE CellularRadio::getFirmwareBuild(std::string& sFirmwareBuild) { +ICellularRadio::CODE CellularRadio::getFirmwareBuild(std::string& sFirmwareBuild) { sFirmwareBuild = ICellularRadio::VALUE_NOT_SUPPORTED; return FAILURE; } -CellularRadio::CODE CellularRadio::getHardware(std::string& sHardware) { +ICellularRadio::CODE CellularRadio::getHardware(std::string& sHardware) { printTrace("%s| Get Hardware", m_sName.c_str()); sHardware = ICellularRadio::VALUE_NOT_SUPPORTED; @@ -214,7 +214,7 @@ CellularRadio::CODE CellularRadio::getHardware(std::string& sHardware) { return FAILURE; } -CellularRadio::CODE CellularRadio::getManufacturer(std::string& sManufacturer) { +ICellularRadio::CODE CellularRadio::getManufacturer(std::string& sManufacturer) { printTrace("%s| Get Manufacturer", m_sName.c_str()); sManufacturer = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT+GMI"); @@ -234,7 +234,7 @@ CellularRadio::CODE CellularRadio::getManufacturer(std::string& sManufacturer) { return SUCCESS; } -CellularRadio::CODE CellularRadio::getImei(std::string& sImei) { +ICellularRadio::CODE CellularRadio::getImei(std::string& sImei) { printTrace("%s| Get IMEI", m_sName.c_str()); sImei = ICellularRadio::VALUE_NOT_SUPPORTED; @@ -257,12 +257,12 @@ CellularRadio::CODE CellularRadio::getImei(std::string& sImei) { return SUCCESS; } -CellularRadio::CODE CellularRadio::getMeid(std::string& sMeid) { +ICellularRadio::CODE CellularRadio::getMeid(std::string& sMeid) { printTrace("%s| Get MEID", m_sName.c_str()); return getImei(sMeid); } -CellularRadio::CODE CellularRadio::getImsi(std::string& sImsi) { +ICellularRadio::CODE CellularRadio::getImsi(std::string& sImsi) { printTrace("%s| Get IMSI", m_sName.c_str()); sImsi = ICellularRadio::VALUE_NOT_SUPPORTED; @@ -285,19 +285,19 @@ CellularRadio::CODE CellularRadio::getImsi(std::string& sImsi) { return SUCCESS; } -CellularRadio::CODE CellularRadio::getSimStatus(std::string& sSimStatus) { +ICellularRadio::CODE CellularRadio::getSimStatus(std::string& sSimStatus) { printTrace("%s| Get SIM Status", getName().c_str()); sSimStatus = ICellularRadio::VALUE_UNKNOWN; return FAILURE; } -CellularRadio::CODE CellularRadio::getSimStatusSummary(Json::Value& jData) { +ICellularRadio::CODE CellularRadio::getSimStatusSummary(Json::Value& jData) { bool bIsSimInserted = false; bool bIsSimLocked = true; int iAttemptsPin = 0; int iAttemptsPuk = 0; std::string sSimLockStatus; - CODE retCode; + ICellularRadio::CODE retCode; do { retCode = getIsSimInserted(bIsSimInserted); @@ -335,7 +335,7 @@ CellularRadio::CODE CellularRadio::getSimStatusSummary(Json::Value& jData) { return retCode; } -CellularRadio::CODE CellularRadio::getLac(std::string& sLac) { +ICellularRadio::CODE CellularRadio::getLac(std::string& sLac) { Json::Value jData; printTrace("%s| Get LAC", m_sName.c_str()); @@ -351,7 +351,7 @@ CellularRadio::CODE CellularRadio::getLac(std::string& sLac) { return FAILURE; } -CellularRadio::CODE CellularRadio::getMdn(std::string& sMdn) { +ICellularRadio::CODE CellularRadio::getMdn(std::string& sMdn) { printTrace("%s| Get MDN", m_sName.c_str()); sMdn = ICellularRadio::VALUE_NOT_SUPPORTED; @@ -385,7 +385,7 @@ CellularRadio::CODE CellularRadio::getMdn(std::string& sMdn) { return SUCCESS; } -CellularRadio::CODE CellularRadio::getMsid(std::string& sMsid) { +ICellularRadio::CODE CellularRadio::getMsid(std::string& sMsid) { printTrace("%s| Get MSID", m_sName.c_str()); sMsid = ""; @@ -401,13 +401,13 @@ CellularRadio::CODE CellularRadio::getMsid(std::string& sMsid) { return FAILURE; } -CellularRadio::CODE CellularRadio::getType(std::string& sType) { +ICellularRadio::CODE CellularRadio::getType(std::string& sType) { printTrace("%s| Get Type", m_sName.c_str()); sType = ICellularRadio::VALUE_NOT_SUPPORTED; return FAILURE; } -CellularRadio::CODE CellularRadio::getCarrier(std::string& sCarrier) { +ICellularRadio::CODE CellularRadio::getCarrier(std::string& sCarrier) { printTrace("%s| Get Carrier", m_sName.c_str()); if(m_sCarrier == "") { Json::Value jData; @@ -437,7 +437,7 @@ CellularRadio::CODE CellularRadio::getCarrier(std::string& sCarrier) { return SUCCESS; } -CellularRadio::CODE CellularRadio::getTower(std::string& sTower) { +ICellularRadio::CODE CellularRadio::getTower(std::string& sTower) { Json::Value jData; printTrace("%s| Get Tower", m_sName.c_str()); @@ -452,7 +452,7 @@ CellularRadio::CODE CellularRadio::getTower(std::string& sTower) { return FAILURE; } -CellularRadio::CODE CellularRadio::getTime(std::string& sDate, std::string& sTime, std::string& sTimeZone) { +ICellularRadio::CODE CellularRadio::getTime(std::string& sDate, std::string& sTime, std::string& sTimeZone) { Json::Value jData; printTrace("%s| Get Time", m_sName.c_str()); @@ -527,7 +527,7 @@ CellularRadio::CODE CellularRadio::getTime(std::string& sDate, std::string& sTim return FAILURE; } -CellularRadio::CODE CellularRadio::getRoaming(bool& bRoaming) { +ICellularRadio::CODE CellularRadio::getRoaming(bool& bRoaming) { Json::Value jData; printTrace("%s| Get Roaming", m_sName.c_str()); @@ -541,7 +541,7 @@ CellularRadio::CODE CellularRadio::getRoaming(bool& bRoaming) { return FAILURE; } -CellularRadio::CODE CellularRadio::getSignalStrength(int32_t& rssi) { +ICellularRadio::CODE CellularRadio::getSignalStrength(int32_t& rssi) { printTrace("%s| Get Signal Strength", m_sName.c_str()); // AT+CSQ execution can take up to 300ms according to the Quectel datasheet. Setting timeout to 500ms just for sure. @@ -567,12 +567,12 @@ CellularRadio::CODE CellularRadio::getSignalStrength(int32_t& rssi) { return SUCCESS; } -CellularRadio::CODE CellularRadio::getModemLocation(std::string&) { +ICellularRadio::CODE CellularRadio::getModemLocation(std::string&) { printTrace("%s|CellularRadio getModemLocation - not supported", m_sName.c_str()); return FAILURE; } -CellularRadio::CODE CellularRadio::getEcho(bool& bEnabled) { +ICellularRadio::CODE CellularRadio::getEcho(bool& bEnabled) { printTrace("%s| Echo Test", m_sName.c_str()); std::string sResult = sendCommand("AT"); if(sResult.size() == 0) { @@ -588,8 +588,8 @@ CellularRadio::CODE CellularRadio::getEcho(bool& bEnabled) { return SUCCESS; } -CellularRadio::CODE CellularRadio::setEcho(bool bEnabled) { - CODE eCode = FAILURE; +ICellularRadio::CODE CellularRadio::setEcho(bool bEnabled) { + ICellularRadio::CODE eCode = FAILURE; if(bEnabled) { eCode = sendBasicCommand("ATE1"); m_bEchoEnabled = (eCode == SUCCESS ) ? true : m_bEchoEnabled; @@ -601,7 +601,7 @@ CellularRadio::CODE CellularRadio::setEcho(bool bEnabled) { return eCode; } -CellularRadio::CODE CellularRadio::getStaticInformation(Json::Value& jData) { +ICellularRadio::CODE CellularRadio::getStaticInformation(Json::Value& jData) { printTrace("%s| Get Static Information", m_sName.c_str()); printTrace("%s| Static Information:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str()); @@ -696,7 +696,7 @@ void CellularRadio::getCommonNetworkStats(Json::Value& jData) { } } -CellularRadio::CODE CellularRadio::getSimLockStatus(std::string& sData) +ICellularRadio::CODE CellularRadio::getSimLockStatus(std::string& sData) { printTrace("%s| Get SIM lock status", m_sName.c_str()); @@ -736,7 +736,7 @@ void CellularRadio::initMipProfile(Json::Value& jData) { jData[ICellularRadio::KEY_MIP_MNHASS] = false; } -CellularRadio::CODE CellularRadio::getRegistration(REGISTRATION& eRegistration) { +ICellularRadio::CODE CellularRadio::getRegistration(REGISTRATION& eRegistration) { std::string sCmd; std::string sResp; @@ -770,9 +770,9 @@ CellularRadio::CODE CellularRadio::getRegistration(REGISTRATION& eRegistration) return SUCCESS; } -CellularRadio::CODE CellularRadio::convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration) { +ICellularRadio::CODE CellularRadio::convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration) { - CODE eCode = FAILURE; + ICellularRadio::CODE eCode = FAILURE; switch (eRegistration) { case NOT_REGISTERED: sRegistration = ICellularRadio::VALUE_NOT_REGISTERED; eCode = SUCCESS; break; case REGISTERED: sRegistration = ICellularRadio::VALUE_REGISTERED; eCode = SUCCESS; break; @@ -784,7 +784,7 @@ CellularRadio::CODE CellularRadio::convertRegistrationToString(REGISTRATION eReg return eCode; } -CellularRadio::CODE CellularRadio::unlockSimCard(const Json::Value& jArgs) { +ICellularRadio::CODE CellularRadio::unlockSimCard(const Json::Value& jArgs) { printTrace("%s| Unlock the SIM card using PIN code", m_sName.c_str()); if(!jArgs["pin"].isString()) { @@ -803,128 +803,128 @@ CellularRadio::CODE CellularRadio::unlockSimCard(const Json::Value& jArgs) { return SUCCESS; } -CellularRadio::CODE CellularRadio::validateMsl(const Json::Value&) { +ICellularRadio::CODE CellularRadio::validateMsl(const Json::Value&) { printTrace("%s| Validate MSL", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::setMsid(const Json::Value&) { +ICellularRadio::CODE CellularRadio::setMsid(const Json::Value&) { printTrace("%s| Set MSID", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::getMipProfile(Json::Value&) { +ICellularRadio::CODE CellularRadio::getMipProfile(Json::Value&) { printTrace("%s| Get MIP Active Profile", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::setMipActiveProfile(const Json::Value&) { +ICellularRadio::CODE CellularRadio::setMipActiveProfile(const Json::Value&) { printTrace("%s| Set MIP Active Profile", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::setMipNai(const Json::Value&) { +ICellularRadio::CODE CellularRadio::setMipNai(const Json::Value&) { printTrace("%s| Set MIP NAI", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::setMipHomeIp(const Json::Value&) { +ICellularRadio::CODE CellularRadio::setMipHomeIp(const Json::Value&) { printTrace("%s| Set MIP Home IP", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::setMipPrimaryHa(const Json::Value&) { +ICellularRadio::CODE CellularRadio::setMipPrimaryHa(const Json::Value&) { printTrace("%s| Set MIP Primary HA", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::setMipSecondaryHa(const Json::Value&) { +ICellularRadio::CODE CellularRadio::setMipSecondaryHa(const Json::Value&) { printTrace("%s| Set MIP Secondary HA", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::setMipMnAaaSpi(const Json::Value&) { +ICellularRadio::CODE CellularRadio::setMipMnAaaSpi(const Json::Value&) { printTrace("%s| Set MIP MN-AAA SPI", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::setMipMnHaSpi(const Json::Value&) { +ICellularRadio::CODE CellularRadio::setMipMnHaSpi(const Json::Value&) { printTrace("%s| Set MIP MN-HA SPI", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::setMipRevTun(const Json::Value&) { +ICellularRadio::CODE CellularRadio::setMipRevTun(const Json::Value&) { printTrace("%s| Set MIP Rev Tun", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::setMipMnAaaSs(const Json::Value&) { +ICellularRadio::CODE CellularRadio::setMipMnAaaSs(const Json::Value&) { printTrace("%s| Set MIP MN-AAA SS", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::setMipMnHaSs(const Json::Value&) { +ICellularRadio::CODE CellularRadio::setMipMnHaSs(const Json::Value&) { printTrace("%s| Set MIP MN-HA SS", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::updateDc(const Json::Value&, UpdateCb&) { +ICellularRadio::CODE CellularRadio::updateDc(const Json::Value&, UpdateCb&) { printTrace("%s| Update Device Configuration", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::updatePrl(const Json::Value&, UpdateCb&) { +ICellularRadio::CODE CellularRadio::updatePrl(const Json::Value&, UpdateCb&) { printTrace("%s| Update Preferred Roaming List", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::updateFumo(const Json::Value&, UpdateCb&) { +ICellularRadio::CODE CellularRadio::updateFumo(const Json::Value&, UpdateCb&) { printTrace("%s| Update Firmware Update Management Object", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::resetHfa(const Json::Value&, UpdateCb&) { +ICellularRadio::CODE CellularRadio::resetHfa(const Json::Value&, UpdateCb&) { printTrace("%s| HFA Reset", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::activate(const Json::Value&, UpdateCb&) { +ICellularRadio::CODE CellularRadio::activate(const Json::Value&, UpdateCb&) { printTrace("%s| Activation", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::setActiveFirmware(const Json::Value&) { +ICellularRadio::CODE CellularRadio::setActiveFirmware(const Json::Value&) { printTrace("%s| Set Active Firmware Image Number: not applicable", m_sName.c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::getActiveFirmware(std::string& sFwId) { +ICellularRadio::CODE CellularRadio::getActiveFirmware(std::string& sFwId) { printTrace("%s| Get Active Firmware Image Number: not applicable", m_sName.c_str()); sFwId = ICellularRadio::VALUE_NOT_SUPPORTED; return NOT_APPLICABLE; } -CellularRadio::CODE CellularRadio::sendBasicCommand(const std::string& sCmd, int32_t iTimeoutMillis, const char& ESC) { +ICellularRadio::CODE CellularRadio::sendBasicCommand(const std::string& sCmd, int32_t iTimeoutMillis, const char& ESC) { std::string response = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, iTimeoutMillis, ESC); if (response.size() == 0) { return NO_RESPONSE; diff --git a/src/MTS_IO_DE910Radio.cpp b/src/MTS_IO_DE910Radio.cpp index 8749da6..26668f1 100644 --- a/src/MTS_IO_DE910Radio.cpp +++ b/src/MTS_IO_DE910Radio.cpp @@ -39,7 +39,7 @@ DE910Radio::DE910Radio(const std::string& sPort) } -DE910Radio::CODE DE910Radio::setRxDiversity(const Json::Value& jArgs) { +ICellularRadio::CODE DE910Radio::setRxDiversity(const Json::Value& jArgs) { /* Command string for EV3 radios: AT#CRXD= */ if (jArgs["enabled"].asString() != "1" && jArgs["enabled"].asString() != "0") { diff --git a/src/MTS_IO_EG95Radio.cpp b/src/MTS_IO_EG95Radio.cpp index 8469454..5c9ed69 100644 --- a/src/MTS_IO_EG95Radio.cpp +++ b/src/MTS_IO_EG95Radio.cpp @@ -35,7 +35,7 @@ EG95Radio::~EG95Radio() { } -EG95Radio::CODE EG95Radio::setRxDiversity(const Json::Value& jArgs) { +ICellularRadio::CODE EG95Radio::setRxDiversity(const Json::Value& jArgs) { /* Command string for EG95 radios: AT+QCFG="diversity",(0-1) */ if (jArgs["enabled"].asString() != "1" && jArgs["enabled"].asString() != "0") { return FAILURE; diff --git a/src/MTS_IO_GE910Radio.cpp b/src/MTS_IO_GE910Radio.cpp index c99d16c..61332b5 100644 --- a/src/MTS_IO_GE910Radio.cpp +++ b/src/MTS_IO_GE910Radio.cpp @@ -39,7 +39,7 @@ GE910Radio::GE910Radio(const std::string& sPort) } -GE910Radio::CODE GE910Radio::setRxDiversity(const Json::Value& jArgs) { +ICellularRadio::CODE GE910Radio::setRxDiversity(const Json::Value& jArgs) { /* Command string for GE radios: N/A */ return FAILURE; } diff --git a/src/MTS_IO_HE910Radio.cpp b/src/MTS_IO_HE910Radio.cpp index cc0e873..4c0a759 100644 --- a/src/MTS_IO_HE910Radio.cpp +++ b/src/MTS_IO_HE910Radio.cpp @@ -37,7 +37,7 @@ HE910Radio::HE910Radio(const std::string& sHE910Model, const std::string& sPort) } -HE910Radio::CODE HE910Radio::setRxDiversity(const Json::Value& jArgs) { +ICellularRadio::CODE HE910Radio::setRxDiversity(const Json::Value& jArgs) { /* Command string for H5 radios: "AT#RXDIV" */ if (jArgs["enabled"].asString() != "1" && jArgs["enabled"].asString() != "0") { diff --git a/src/MTS_IO_LE910C1APRadio.cpp b/src/MTS_IO_LE910C1APRadio.cpp index befb809..dca5faa 100644 --- a/src/MTS_IO_LE910C1APRadio.cpp +++ b/src/MTS_IO_LE910C1APRadio.cpp @@ -30,7 +30,7 @@ LE910C1APRadio::LE910C1APRadio(const std::string& sPort) } -LE910C1APRadio::CODE LE910C1APRadio::getCarrier(std::string& sCarrier) { +ICellularRadio::CODE LE910C1APRadio::getCarrier(std::string& sCarrier) { sCarrier = "Sprint"; return SUCCESS; } diff --git a/src/MTS_IO_LE910C1NSRadio.cpp b/src/MTS_IO_LE910C1NSRadio.cpp index 425ab93..907edd7 100644 --- a/src/MTS_IO_LE910C1NSRadio.cpp +++ b/src/MTS_IO_LE910C1NSRadio.cpp @@ -39,7 +39,7 @@ LE910C1NSRadio::LE910C1NSRadio(const std::string& sPort) } -LE910C1NSRadio::CODE LE910C1NSRadio::getCarrier(std::string& sCarrier) { +ICellularRadio::CODE LE910C1NSRadio::getCarrier(std::string& sCarrier) { sCarrier = "Sprint"; return SUCCESS; } diff --git a/src/MTS_IO_LE910NA1Radio.cpp b/src/MTS_IO_LE910NA1Radio.cpp index 8ae15ad..c7341b0 100644 --- a/src/MTS_IO_LE910NA1Radio.cpp +++ b/src/MTS_IO_LE910NA1Radio.cpp @@ -38,8 +38,8 @@ LE910NA1Radio::LE910NA1Radio(const std::string& sPort) } -LE910NA1Radio::CODE LE910NA1Radio::setActiveFirmware(const Json::Value& jArgs) { - CODE rc; +ICellularRadio::CODE LE910NA1Radio::setActiveFirmware(const Json::Value& jArgs) { + ICellularRadio::CODE rc; // Set command allows enabling a specific firmware image on products // embedding 2 different firmware images: @@ -82,9 +82,9 @@ LE910NA1Radio::CODE LE910NA1Radio::setActiveFirmware(const Json::Value& jArgs) { return sendBasicCommand(sCmd, 5000); } -LE910NA1Radio::CODE LE910NA1Radio::getActiveFirmware(std::string& sFwId) { +ICellularRadio::CODE LE910NA1Radio::getActiveFirmware(std::string& sFwId) { std::string sCmd; - CODE rc; + ICellularRadio::CODE rc; // // Read command reports the current active firmware image: // AT#FWSWITCH? diff --git a/src/MTS_IO_LE910Radio.cpp b/src/MTS_IO_LE910Radio.cpp index b02c2ce..ea905a8 100644 --- a/src/MTS_IO_LE910Radio.cpp +++ b/src/MTS_IO_LE910Radio.cpp @@ -38,7 +38,7 @@ LE910Radio::LE910Radio(const std::string& sLE910Model, const std::string& sPort) } -LE910Radio::CODE LE910Radio::setRxDiversity(const Json::Value& jArgs) { +ICellularRadio::CODE LE910Radio::setRxDiversity(const Json::Value& jArgs) { /* Command string for LAT1,LVW2,LEU1 radios: "AT#RXDIV=" */ /* Setting needs to append ",1" to the 0/1 value */ if (jArgs["enabled"].asString() != "1" && jArgs["enabled"].asString() != "0") @@ -52,7 +52,7 @@ LE910Radio::CODE LE910Radio::setRxDiversity(const Json::Value& jArgs) { return sendBasicCommand(sCmd); } -LE910Radio::CODE LE910Radio::getModemLocation(std::string& sLocation) { +ICellularRadio::CODE LE910Radio::getModemLocation(std::string& sLocation) { const std::string& whitespace = " \t"; printTrace("LE910Radio getModemLocation"); std::string sCmd("AT$GPSACP"); diff --git a/src/MTS_IO_LE910SVGRadio.cpp b/src/MTS_IO_LE910SVGRadio.cpp index e0afd67..a43165a 100644 --- a/src/MTS_IO_LE910SVGRadio.cpp +++ b/src/MTS_IO_LE910SVGRadio.cpp @@ -39,7 +39,7 @@ LE910SVGRadio::LE910SVGRadio(const std::string& sPort) } -LE910SVGRadio::CODE LE910SVGRadio::getCarrier(std::string& sCarrier) { +ICellularRadio::CODE LE910SVGRadio::getCarrier(std::string& sCarrier) { sCarrier = "Verizon"; return SUCCESS; } diff --git a/src/MTS_IO_ME910C1NVRadio.cpp b/src/MTS_IO_ME910C1NVRadio.cpp index c7aae7b..0af5f24 100644 --- a/src/MTS_IO_ME910C1NVRadio.cpp +++ b/src/MTS_IO_ME910C1NVRadio.cpp @@ -53,13 +53,13 @@ ME910C1NVRadio::ME910C1NVRadio(const std::string& sPort) } -ME910C1NVRadio::CODE ME910C1NVRadio::getCarrier(std::string& sCarrier) { +ICellularRadio::CODE ME910C1NVRadio::getCarrier(std::string& sCarrier) { sCarrier = "Verizon"; return SUCCESS; } -ME910C1NVRadio::CODE ME910C1NVRadio::doGetFirmwareNumbers(std::string &sFirmware, std::string &sFirmwareBuild) { - CODE rc = FAILURE; +ICellularRadio::CODE ME910C1NVRadio::doGetFirmwareNumbers(std::string &sFirmware, std::string &sFirmwareBuild) { + ICellularRadio::CODE rc = FAILURE; rc = getFirmware(sFirmware); if (rc != SUCCESS){ @@ -74,9 +74,9 @@ ME910C1NVRadio::CODE ME910C1NVRadio::doGetFirmwareNumbers(std::string &sFirmware return rc; } -ME910C1NVRadio::CODE ME910C1NVRadio::doFumoReadConfig(const Json::Value& jArgs, Json::Value &jConfig) +ICellularRadio::CODE ME910C1NVRadio::doFumoReadConfig(const Json::Value& jArgs, Json::Value &jConfig) { - CODE rc = INVALID_ARGS; + ICellularRadio::CODE rc = INVALID_ARGS; std::string sPath; do @@ -196,9 +196,9 @@ ME910C1NVRadio::CODE ME910C1NVRadio::doFumoReadConfig(const Json::Value& jArgs, return rc; } -ME910C1NVRadio::CODE ME910C1NVRadio::doFumoSetup(const Json::Value &jConfig, UpdateCb& stepCb) +ICellularRadio::CODE ME910C1NVRadio::doFumoSetup(const Json::Value &jConfig, UpdateCb& stepCb) { - CODE rc = FAILURE; + ICellularRadio::CODE rc = FAILURE; std::string sCmd; std::string sContextId = jConfig[KEY_FUMO_PDPID].asString(); @@ -292,9 +292,9 @@ ME910C1NVRadio::CODE ME910C1NVRadio::doFumoSetup(const Json::Value &jConfig, Upd return rc; } -ME910C1NVRadio::CODE ME910C1NVRadio::doFumoFtp(const Json::Value &jConfig, UpdateCb& stepCb) +ICellularRadio::CODE ME910C1NVRadio::doFumoFtp(const Json::Value &jConfig, UpdateCb& stepCb) { - CODE rc = FAILURE; + ICellularRadio::CODE rc = FAILURE; std::string sCmd; std::string sResult; @@ -450,7 +450,7 @@ ME910C1NVRadio::CODE ME910C1NVRadio::doFumoFtp(const Json::Value &jConfig, Updat // // AT#FTPCLOSE // - CODE rcclose = sendBasicCommand("AT#FTPCLOSE", 60 * 1000); + ICellularRadio::CODE rcclose = sendBasicCommand("AT#FTPCLOSE", 60 * 1000); if (rcclose != SUCCESS && rc == SUCCESS) { if(stepCb) { // Only one "FUMO Error" message should be sent @@ -468,9 +468,9 @@ ME910C1NVRadio::CODE ME910C1NVRadio::doFumoFtp(const Json::Value &jConfig, Updat return rc; } -ME910C1NVRadio::CODE ME910C1NVRadio::doFumoCleanup(const Json::Value &jConfig, UpdateCb& stepCb) +ICellularRadio::CODE ME910C1NVRadio::doFumoCleanup(const Json::Value &jConfig, UpdateCb& stepCb) { - CODE rc = FAILURE; + ICellularRadio::CODE rc = FAILURE; std::string sCmd; std::string sContextId = jConfig[KEY_FUMO_PDPID].asString(); @@ -488,9 +488,9 @@ ME910C1NVRadio::CODE ME910C1NVRadio::doFumoCleanup(const Json::Value &jConfig, U return rc; } -ME910C1NVRadio::CODE ME910C1NVRadio::doFumoApplyFirmware(const Json::Value &jConfig, UpdateCb& stepCb) +ICellularRadio::CODE ME910C1NVRadio::doFumoApplyFirmware(const Json::Value &jConfig, UpdateCb& stepCb) { - CODE rc = FAILURE; + ICellularRadio::CODE rc = FAILURE; if (jConfig.isMember(KEY_FUMO_DRYRUN)) { if(stepCb) { @@ -514,11 +514,11 @@ ME910C1NVRadio::CODE ME910C1NVRadio::doFumoApplyFirmware(const Json::Value &jCon return rc; } -ME910C1NVRadio::CODE ME910C1NVRadio::doFumoWaitNewFirmware(const Json::Value &jConfig, UpdateCb& stepCb) +ICellularRadio::CODE ME910C1NVRadio::doFumoWaitNewFirmware(const Json::Value &jConfig, UpdateCb& stepCb) { std::string sFirmware; std::string sFirmwareBuild; - CODE rc = FAILURE; + ICellularRadio::CODE rc = FAILURE; if (jConfig.isMember(KEY_FUMO_DRYRUN)) { if(stepCb) { @@ -570,9 +570,9 @@ ME910C1NVRadio::CODE ME910C1NVRadio::doFumoWaitNewFirmware(const Json::Value &jC } -ME910C1NVRadio::CODE ME910C1NVRadio::doFumoPerform(const Json::Value &jConfig, UpdateCb& stepCb) +ICellularRadio::CODE ME910C1NVRadio::doFumoPerform(const Json::Value &jConfig, UpdateCb& stepCb) { - CODE rc = FAILURE; + ICellularRadio::CODE rc = FAILURE; UpdateCb dummyCb; @@ -606,10 +606,10 @@ ME910C1NVRadio::CODE ME910C1NVRadio::doFumoPerform(const Json::Value &jConfig, U return rc; } -ME910C1NVRadio::CODE ME910C1NVRadio::updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) +ICellularRadio::CODE ME910C1NVRadio::updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) { Json::Value jConfig(Json::objectValue); - CODE rc = FAILURE; + ICellularRadio::CODE rc = FAILURE; rc = doFumoReadConfig(jArgs, jConfig); if (rc != SUCCESS) { diff --git a/src/MTS_IO_ME910C1WWRadio.cpp b/src/MTS_IO_ME910C1WWRadio.cpp index 0228eda..0469d5d 100644 --- a/src/MTS_IO_ME910C1WWRadio.cpp +++ b/src/MTS_IO_ME910C1WWRadio.cpp @@ -32,8 +32,8 @@ ME910C1WWRadio::ME910C1WWRadio(const std::string& sPort) } -ME910C1WWRadio::CODE ME910C1WWRadio::setActiveFirmware(const Json::Value& jArgs) { - CODE rc; +ICellularRadio::CODE ME910C1WWRadio::setActiveFirmware(const Json::Value& jArgs) { + ICellularRadio::CODE rc; // Set command allows enabling a specific firmware image on products // embedding 2 different firmware images: @@ -76,9 +76,9 @@ ME910C1WWRadio::CODE ME910C1WWRadio::setActiveFirmware(const Json::Value& jArgs) return sendBasicCommand(sCmd, 5000); } -ME910C1WWRadio::CODE ME910C1WWRadio::getActiveFirmware(std::string& sFwId) { +ICellularRadio::CODE ME910C1WWRadio::getActiveFirmware(std::string& sFwId) { std::string sCmd; - CODE rc; + ICellularRadio::CODE rc; // // Read command reports the current active firmware image: // AT#FWSWITCH? diff --git a/src/MTS_IO_ME910Radio.cpp b/src/MTS_IO_ME910Radio.cpp index 4ae8a75..2b181d2 100644 --- a/src/MTS_IO_ME910Radio.cpp +++ b/src/MTS_IO_ME910Radio.cpp @@ -30,12 +30,12 @@ ME910Radio::ME910Radio(const std::string& sME910Model, const std::string& sPort) } -ME910Radio::CODE ME910Radio::setRxDiversity(const Json::Value& jArgs) { +ICellularRadio::CODE ME910Radio::setRxDiversity(const Json::Value& jArgs) { return FAILURE; } -ME910Radio::CODE ME910Radio::getFirmwareBuild(std::string& sFirmwareBuild) { +ICellularRadio::CODE ME910Radio::getFirmwareBuild(std::string& sFirmwareBuild) { std::string sCmd("AT#CFVR"); std::string sResult = sendCommand(sCmd); diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 0712788..f3227a5 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -44,7 +44,7 @@ bool QuectelRadio::resetRadio(uint32_t iTimeoutMillis) { return false; } -CellularRadio::CODE QuectelRadio::getModel(std::string& sModel) { +ICellularRadio::CODE QuectelRadio::getModel(std::string& sModel) { printTrace("%s| Get Model", getName().c_str()); //Always returns SUCCESS because the model should be m_sName sModel = getName(); @@ -70,7 +70,7 @@ CellularRadio::CODE QuectelRadio::getModel(std::string& sModel) { return SUCCESS; } -CellularRadio::CODE QuectelRadio::getIccid(std::string& sIccid) { +ICellularRadio::CODE QuectelRadio::getIccid(std::string& sIccid) { printTrace("%s| Get ICCID", getName().c_str()); sIccid = ICellularRadio::VALUE_NOT_SUPPORTED; @@ -96,7 +96,7 @@ CellularRadio::CODE QuectelRadio::getIccid(std::string& sIccid) { return SUCCESS; } -CellularRadio::CODE QuectelRadio::getService(std::string& sService) { +ICellularRadio::CODE QuectelRadio::getService(std::string& sService) { printTrace("%s| Get Service", getName().c_str()); sService = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT+COPS?"); @@ -136,7 +136,7 @@ CellularRadio::CODE QuectelRadio::getService(std::string& sService) { return SUCCESS; } -CellularRadio::CODE QuectelRadio::getNetwork(std::string& sNetwork) { +ICellularRadio::CODE QuectelRadio::getNetwork(std::string& sNetwork) { /* * TODO: Refactor using MccMncTable once it'll be corrected. * @@ -389,7 +389,7 @@ CellularRadio::CODE QuectelRadio::getNetworkStatus(Json::Value& jData) { return SUCCESS; } -CellularRadio::CODE QuectelRadio::convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& iDbm) { +ICellularRadio::CODE QuectelRadio::convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& iDbm) { int dbmSteps, minValue, maxValue, rssiOffset; int rawDbm; @@ -415,7 +415,7 @@ CellularRadio::CODE QuectelRadio::convertSignalStrengthTodBm(const int32_t& iRss return SUCCESS; } -CellularRadio::CODE QuectelRadio::convertdBmToSignalStrength(const int32_t& iDBm, int32_t& iRssi) { +ICellularRadio::CODE QuectelRadio::convertdBmToSignalStrength(const int32_t& iDBm, int32_t& iRssi) { //Quectel Conversion FOR NORMAL SCALING const int dbmSteps = 2; const int minValue = -113; @@ -432,17 +432,17 @@ CellularRadio::CODE QuectelRadio::convertdBmToSignalStrength(const int32_t& iDBm return SUCCESS; } -CellularRadio::CODE QuectelRadio::setMdn(const Json::Value& jArgs) { +ICellularRadio::CODE QuectelRadio::setMdn(const Json::Value& jArgs) { printTrace("%s| Set MDN", getName().c_str()); return NOT_APPLICABLE; } -CellularRadio::CODE QuectelRadio::getServiceDomain(ICellularRadio::SERVICEDOMAIN& sd) { +ICellularRadio::CODE QuectelRadio::getServiceDomain(ICellularRadio::SERVICEDOMAIN& sd) { printTrace("%s| Get Service Domain", getName().c_str()); std::string sCmd("AT+QCFG=\"servicedomain\""); std::string sResult = sendCommand(sCmd); - size_t end = sResult.find(RSP_OK); + size_t end = sResult.find(ICellularRadio::RSP_OK); if (end == std::string::npos) { printWarning("%s| Unable to get service domain using command [%s]", getName().c_str(), sCmd.c_str()); @@ -470,7 +470,7 @@ CellularRadio::CODE QuectelRadio::getServiceDomain(ICellularRadio::SERVICEDOMAIN return SUCCESS; } -CellularRadio::CODE QuectelRadio::getIsSimInserted(bool& bData) { +ICellularRadio::CODE QuectelRadio::getIsSimInserted(bool& bData) { printTrace("%s| Get SIM insertion status", getName().c_str()); // AT+QSIMSTAT? execution can take up to 300ms according to the datasheet. Setting timeout to 500ms just for sure. @@ -509,7 +509,7 @@ CellularRadio::CODE QuectelRadio::getIsSimInserted(bool& bData) { return SUCCESS; } -CellularRadio::CODE QuectelRadio::getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk) { +ICellularRadio::CODE QuectelRadio::getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk) { printTrace("%s| Get SIM unlock attempts left", getName().c_str()); // AT+QPINC execution can take more time that expected. Set timeout to 2s just to be sure. @@ -553,7 +553,7 @@ CellularRadio::CODE QuectelRadio::getSimLockAttempts(int& iAttemptsPin, int& iAt return SUCCESS; } -CellularRadio::CODE QuectelRadio::convertToActiveBand(const std::string& sQuectelBand, ICellularRadio::ACTIVEBAND& band) { +ICellularRadio::CODE QuectelRadio::convertToActiveBand(const std::string& sQuectelBand, ICellularRadio::ACTIVEBAND& band) { int iQuectelBand = -1; if (!MTS::Text::parse(iQuectelBand, sQuectelBand)) { diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp index c8448e2..340c0ac 100644 --- a/src/MTS_IO_TelitRadio.cpp +++ b/src/MTS_IO_TelitRadio.cpp @@ -46,7 +46,7 @@ bool TelitRadio::resetRadio(uint32_t iTimeoutMillis) { } -CellularRadio::CODE TelitRadio::getModel(std::string& sModel) { +ICellularRadio::CODE TelitRadio::getModel(std::string& sModel) { printTrace("%s| Get Model", getName().c_str()); //Always returns SUCCESS because the model should be m_sName sModel = getName(); @@ -72,7 +72,7 @@ CellularRadio::CODE TelitRadio::getModel(std::string& sModel) { return SUCCESS; } -CellularRadio::CODE TelitRadio::getIccid(std::string& sIccid) { +ICellularRadio::CODE TelitRadio::getIccid(std::string& sIccid) { printTrace("%s| Get ICCID", getName().c_str()); sIccid = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT#CCID"); @@ -95,7 +95,7 @@ CellularRadio::CODE TelitRadio::getIccid(std::string& sIccid) { return SUCCESS; } -CellularRadio::CODE TelitRadio::getService(std::string& sService) { +ICellularRadio::CODE TelitRadio::getService(std::string& sService) { printTrace("%s| Get Service", getName().c_str()); sService = ICellularRadio::VALUE_NOT_SUPPORTED; std::string sCmd("AT#PSNT?"); @@ -127,7 +127,7 @@ CellularRadio::CODE TelitRadio::getService(std::string& sService) { return SUCCESS; } -CellularRadio::CODE TelitRadio::getNetwork(std::string& sNetwork) { +ICellularRadio::CODE TelitRadio::getNetwork(std::string& sNetwork) { Json::Value jData; printTrace("%s| Get Network", getName().c_str()); @@ -217,7 +217,7 @@ CellularRadio::CODE TelitRadio::getNetwork(std::string& sNetwork) { - - */ -CellularRadio::CODE TelitRadio::getNetworkStatus(Json::Value& jData) { +ICellularRadio::CODE TelitRadio::getNetworkStatus(Json::Value& jData) { int32_t iValue; std::string sValue; const uint32_t GSM_NETWORK_FORMAT = 14; @@ -396,7 +396,7 @@ CellularRadio::CODE TelitRadio::getNetworkStatus(Json::Value& jData) { return SUCCESS; } -CellularRadio::CODE TelitRadio::convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& iDbm) { +ICellularRadio::CODE TelitRadio::convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& iDbm) { //Telit Conversion if(iRssi < 0 || iRssi == 99) { @@ -419,7 +419,7 @@ CellularRadio::CODE TelitRadio::convertSignalStrengthTodBm(const int32_t& iRssi, return SUCCESS; } -CellularRadio::CODE TelitRadio::convertdBmToSignalStrength(const int32_t& iDBm, int32_t& iRssi) { +ICellularRadio::CODE TelitRadio::convertdBmToSignalStrength(const int32_t& iDBm, int32_t& iRssi) { //Telit Conversion if(iDBm <= -113) { iRssi = 0; @@ -437,7 +437,7 @@ CellularRadio::CODE TelitRadio::convertdBmToSignalStrength(const int32_t& iDBm, return SUCCESS; } -CellularRadio::CODE TelitRadio::setMdn(const Json::Value& jArgs) { +ICellularRadio::CODE TelitRadio::setMdn(const Json::Value& jArgs) { printTrace("%s| Set MDN", getName().c_str()); if(!jArgs["mdn"].isString()) { @@ -574,7 +574,7 @@ ICellularRadio::CODE TelitRadio::setRadioNetworkMode(RADIO_NETWORK_MODE mode) return SUCCESS; } -CellularRadio::CODE TelitRadio::getIsSimInserted(bool& bData) { +ICellularRadio::CODE TelitRadio::getIsSimInserted(bool& bData) { printTrace("%s| Get SIM insertion status", getName().c_str()); std::string sCmd("AT#SIMDET?"); std::string sResult = sendCommand(sCmd); @@ -611,9 +611,9 @@ CellularRadio::CODE TelitRadio::getIsSimInserted(bool& bData) { return SUCCESS; } -CellularRadio::CODE TelitRadio::getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk) { +ICellularRadio::CODE TelitRadio::getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk) { std::string sLockStatus; - CODE retCode; + ICellularRadio::CODE retCode; retCode = getSimLockStatus(sLockStatus); if (retCode != SUCCESS) { @@ -624,7 +624,7 @@ CellularRadio::CODE TelitRadio::getSimLockAttempts(int& iAttemptsPin, int& iAtte return getSimLockAttempts(iAttemptsPin, iAttemptsPuk, sLockStatus); } -CellularRadio::CODE TelitRadio::getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk, const std::string& sLockStatus) { +ICellularRadio::CODE TelitRadio::getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk, const std::string& sLockStatus) { printTrace("%s| Get SIM unlock attempts left", getName().c_str()); std::string sCmd("AT#PCT"); std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 500); -- cgit v1.2.3