diff options
author | sdesai <sdesai@multitech.com> | 2023-03-15 15:22:04 -0500 |
---|---|---|
committer | John Klug <john.klug@multitech.com> | 2023-04-26 17:29:28 -0500 |
commit | 576eb04e2d42e3b9c5fa40748d1d190a457fa1f8 (patch) | |
tree | cee3134469ec1e843dbe337dc65dda934b9728f3 /src/MTS_IO_QuectelRadio.cpp | |
parent | 0f15b7265be65cbd9f66a68f6d1685b58b13e501 (diff) | |
download | libmts-io-576eb04e2d42e3b9c5fa40748d1d190a457fa1f8.tar.gz libmts-io-576eb04e2d42e3b9c5fa40748d1d190a457fa1f8.tar.bz2 libmts-io-576eb04e2d42e3b9c5fa40748d1d190a457fa1f8.zip |
GP-139:Support Portal Case #5086148: use Cellular Radio timeas alternative to GPS or NTP
Diffstat (limited to 'src/MTS_IO_QuectelRadio.cpp')
-rw-r--r-- | src/MTS_IO_QuectelRadio.cpp | 133 |
1 files changed, 25 insertions, 108 deletions
diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index b01bbb1..655fb38 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -1629,114 +1629,6 @@ ICellularRadio::CODE QuectelRadio::setRxDiversity(const Json::Value& jArgs) { return SUCCESS; } -ICellularRadio::CODE QuectelRadio::convertStringToPdpContextType(const std::string& sStringType, std::string& sIntType) { - CODE rc = FAILURE; - - if ("IP" == sStringType) { - sIntType = "1"; - rc = SUCCESS; - } else if ("IPV6" == sStringType) { - sIntType = "2"; - rc = SUCCESS; - } else if ("IPV4V6" == sStringType) { - sIntType = "3"; - rc = SUCCESS; - } - - return rc; -} - -std::vector<std::string> QuectelRadio::getSupportedPdpContextAuthTypes() const { - return { - VALUE_PDP_CONTEXT_AUTH_TYPE_NONE, - VALUE_PDP_CONTEXT_AUTH_TYPE_PAP, - VALUE_PDP_CONTEXT_AUTH_TYPE_CHAP, - VALUE_PDP_CONTEXT_AUTH_TYPE_PAP_CHAP - }; -} - -ICellularRadio::CODE QuectelRadio::isPdpContextAuthSupported(bool& isSupported) { - std::string sCmd("AT+QICSGP=?"); - return isCommandSupported(sCmd, isSupported); -} - -ICellularRadio::CODE QuectelRadio::fillPdpContextAuthFields(Json::Value& jData) { - CODE rc; - std::string sCmd("AT+QICSGP="); - std::string sResult; - uint8_t iValue; - - // iterate over PDP contex IDs to get context settings - for (std::string & sContextId : jData.getMemberNames()) { - // +QICSGP: <context_type>,<APN>,<username>,<password>,<authentication> - // +QICSGP: 0,"","","",0 -- if the context does not exist - - rc = sendBasicQuery(sCmd+sContextId, "+QICSGP:", sResult, 300); - - if (SUCCESS != rc) { - return rc; - } - - // 1,"test","login","password",1 - // [0] [1] [2] [3] [4] - auto vAuthParams = MTS::Text::split(sResult, ","); - - if (vAuthParams.size() < 5) { - printError("%s| Failed to parse PDP context authentication string [%s]", getName().c_str(), sResult.c_str()); - return FAILURE; - } - - if (! MTS::Text::parse(iValue, vAuthParams[4])) { - printError("%s| Failed to parse PDP context authentication type [%s]", getName().c_str(), vAuthParams[4].c_str()); - return FAILURE; - } - - rc = convertPdpContextAuthTypeToString(static_cast<PDP_CONTEXT_AUTH_TYPE>(iValue), sResult); - if (SUCCESS != rc) { - return rc; - } - - jData[sContextId][KEY_PDP_CONTEXT_AUTH_TYPE] = sResult; - - if (iValue != PDP_CONTEXT_AUTH_TYPE::NONE) { - jData[sContextId][KEY_PDP_CONTEXT_AUTH_USERNAME] = MTS::Text::trim(vAuthParams[2], '"'); - jData[sContextId][KEY_PDP_CONTEXT_AUTH_PASSWORD] = MTS::Text::trim(vAuthParams[3], '"'); - } - } - - return SUCCESS; -} - -// AT+QICSGP=<contextID>[,<context_type>,<APN>[,<username>,<password>)[,<authentication>[,<cdma_pwd>]]]] -ICellularRadio::CODE QuectelRadio::setPdpContextAuth(const PdpContextInfo& pdpContext) { - printTrace("%s| Setting PDP context authentication to the radio", getName().c_str()); - - CODE rc; - std::string sContextType; - std::string sCmd = "AT+QICSGP="; - PDP_CONTEXT_AUTH_TYPE eAuthType; - - rc = convertStringToPdpContextType(pdpContext.sIpMode, sContextType); - if (SUCCESS != rc) { - return rc; - } - - rc = convertStringToPdpContextAuthType(pdpContext.sAuthType, eAuthType); - if (SUCCESS != rc) { - return rc; - } - - sCmd += pdpContext.sId + "," + sContextType + ",\"" + pdpContext.sApn + "\""; - - if (PDP_CONTEXT_AUTH_TYPE::NONE == eAuthType) { - sCmd += ",\"\",\"\"," + std::to_string(eAuthType); - } else { - sCmd += ",\"" + pdpContext.sUsername + "\",\"" + pdpContext.sPassword +"\"," + std::to_string(eAuthType); - } - - return sendBasicCommand(sCmd); -} - const std::vector<std::string>& QuectelRadio::getDiagCommands(bool) { // Declare as static to initialize only when used, but cache the results. const static std::vector<std::string> vCommands { @@ -1783,3 +1675,28 @@ const std::vector<std::string>& QuectelRadio::getDiagCommands(bool) { return vCommands; } + +ICellularRadio::CODE QuectelRadio::getTimeUTC(void) { + printTrace("%s| Get Time in UTC", getName().c_str()); + + // Set year format in YYYY first, in case it is in YY format to get accurate year + std::string sCmdCSDF("AT+CSDF=1,2"); + std::string sRes = sendCommand(sCmdCSDF); + size_t endr = sRes.find(ICellularRadio::RSP_OK); + + if (endr == std::string::npos) { + printWarning("%s| Unable to set year format for radio using command [%s]", getName().c_str(), sCmdCSDF.c_str()); + return FAILURE; + } + + // Set command enables/disables the automatic time zone update + std::string sCmdCTZU("AT+CTZU=1"); + sRes = sendCommand(sCmdCTZU); + size_t endc = sRes.find(ICellularRadio::RSP_OK); + + if (endc == std::string::npos) { + printWarning("%s| Unable to set automatic time zone update for radio using command [%s]", getName().c_str(), sCmdCTZU.c_str()); + return FAILURE; + } + return SUCCESS; +}
\ No newline at end of file |