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 --- src/MTS_IO_CellularRadio.cpp | 1818 +----------------------------------------- 1 file changed, 1 insertion(+), 1817 deletions(-) (limited to 'src/MTS_IO_CellularRadio.cpp') 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" -- 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. --- src/MTS_IO_CellularRadio.cpp | 1299 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1299 insertions(+) (limited to 'src/MTS_IO_CellularRadio.cpp') 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; +} -- 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 --- src/MTS_IO_CellularRadio.cpp | 160 +------------------------------------------ 1 file changed, 2 insertions(+), 158 deletions(-) (limited to 'src/MTS_IO_CellularRadio.cpp') 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) { -- 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 --- src/MTS_IO_CellularRadio.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/MTS_IO_CellularRadio.cpp') 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) { -- 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. --- src/MTS_IO_CellularRadio.cpp | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'src/MTS_IO_CellularRadio.cpp') 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"); -- 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. --- src/MTS_IO_CellularRadio.cpp | 81 -------------------------------------------- 1 file changed, 81 deletions(-) (limited to 'src/MTS_IO_CellularRadio.cpp') 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. --- src/MTS_IO_CellularRadio.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/MTS_IO_CellularRadio.cpp') 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. --- src/MTS_IO_CellularRadio.cpp | 41 ----------------------------------------- 1 file changed, 41 deletions(-) (limited to 'src/MTS_IO_CellularRadio.cpp') 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"); -- 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 --- src/MTS_IO_CellularRadio.cpp | 150 +++++++++++++++++++++---------------------- 1 file changed, 75 insertions(+), 75 deletions(-) (limited to 'src/MTS_IO_CellularRadio.cpp') 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); } -- 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 --- src/MTS_IO_CellularRadio.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/MTS_IO_CellularRadio.cpp') 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 --- src/MTS_IO_CellularRadio.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/MTS_IO_CellularRadio.cpp') 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 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(-) (limited to 'src/MTS_IO_CellularRadio.cpp') 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 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/MTS_IO_CellularRadio.cpp') 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); -- 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(-) (limited to 'src/MTS_IO_CellularRadio.cpp') 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 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. --- src/MTS_IO_CellularRadio.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/MTS_IO_CellularRadio.cpp') 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++) -- 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. --- src/MTS_IO_CellularRadio.cpp | 102 +++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 51 deletions(-) (limited to 'src/MTS_IO_CellularRadio.cpp') 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; -- cgit v1.2.3