From 91c623896442013d82f59e6e06e70523e9046b8c Mon Sep 17 00:00:00 2001 From: sdesai Date: Thu, 23 Mar 2023 16:37:24 -0500 Subject: Support Portal Case #5086148: use Cellular Radio time as alternative to GPS or NTP --- include/mts/MTS_IO_CellularRadio.h | 2 +- include/mts/MTS_IO_QuectelRadio.h | 6 ++++++ include/mts/MTS_IO_SequansRadio.h | 4 +++- include/mts/MTS_IO_TelitRadio.h | 7 ++++++- src/MTS_IO_CellularRadio.cpp | 29 +++++++++++++++-------------- src/MTS_IO_QuectelRadio.cpp | 4 ++-- 6 files changed, 33 insertions(+), 19 deletions(-) diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index 0af531b..555a5a7 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -277,7 +277,7 @@ namespace MTS { * @return the list of AT commands (strings). */ virtual const std::vector& getDiagCommands(bool bIsSimReady = true) = 0; - virtual CODE setTimeFormat () = 0; + virtual CODE setTimeFormat() = 0; class RadioBandMap : public MTS::NonCopyable { public: diff --git a/include/mts/MTS_IO_QuectelRadio.h b/include/mts/MTS_IO_QuectelRadio.h index a8d37f2..5f1d70c 100644 --- a/include/mts/MTS_IO_QuectelRadio.h +++ b/include/mts/MTS_IO_QuectelRadio.h @@ -69,16 +69,21 @@ namespace MTS { QuectelRadio(const std::string& sName, const std::string& sRadioPort); CODE getIsSimInserted(bool& bData) override; + CODE getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk) override; virtual CODE getServiceDomain(SERVICEDOMAIN& sd); + virtual CODE convertToActiveBand(const std::string& sQuectelBand, ACTIVEBAND& band); virtual CODE uploadFile(int fd, const std::string& sTargetFilename, UpdateCb& stepCb); + virtual CODE removeFile(const std::string& sTargetFilename); + virtual CODE checkFile(bool& bFilePresent, const std::string& sTargetFilename); virtual CODE getUeUsageSetting(QuectelRadio::UE_USAGE_SETTING& us); + virtual CODE convertToUeUsageSetting(const std::string& sSetting, QuectelRadio::UE_USAGE_SETTING& us); static bool isContainsSignChar(const std::string& str); @@ -86,6 +91,7 @@ namespace MTS { CODE setRxDiversity(const Json::Value& jArgs) override; const std::vector& getDiagCommands(bool bIsSimReady = true) override; + CODE setTimeFormat() override; private: // private variable to save old firmware versions during FOTA diff --git a/include/mts/MTS_IO_SequansRadio.h b/include/mts/MTS_IO_SequansRadio.h index 30f4875..d3efda5 100644 --- a/include/mts/MTS_IO_SequansRadio.h +++ b/include/mts/MTS_IO_SequansRadio.h @@ -54,10 +54,12 @@ namespace MTS { SequansRadio(const std::string& sName, const std::string& sRadioPort); CODE getIsSimInserted(bool& bData) override; + CODE getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk) override; const std::vector& getDiagCommands(bool bIsSimReady = true) override; - virtual CODE setTimeFormat() override; + + CODE setTimeFormat() override; private: /* diff --git a/include/mts/MTS_IO_TelitRadio.h b/include/mts/MTS_IO_TelitRadio.h index 7011ef3..dc8ece8 100644 --- a/include/mts/MTS_IO_TelitRadio.h +++ b/include/mts/MTS_IO_TelitRadio.h @@ -55,9 +55,11 @@ namespace MTS { TelitRadio(const std::string& sName, const std::string& sRadioPort); bool getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier) override; + bool getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware) override; CODE getIsSimInserted(bool& bData) override; + CODE getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk) override; enum FOTA_GROUP : uint8_t { @@ -69,13 +71,16 @@ namespace MTS { }; virtual FOTA_GROUP getFotaGroup(); + virtual CODE fumoWriteGroupsABD(int fd, UpdateCb& stepCb); + //virtual CODE fumoWriteGroupC(int fd, UpdateCb& stepCb); const std::vector& getDiagCommands(bool bIsSimReady = true) override; static bool isContainsSignChar(const std::string& str); - virtual CODE setTimeFormat() override; + + CODE setTimeFormat() override; private: virtual CODE getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk, const std::string& sLockStatus); ICellularRadio::CODE wdsList(std::set &wds); diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index 0b90b55..bc1fee1 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -580,9 +580,9 @@ ICellularRadio::CODE CellularRadio::getTime(std::string& sDate, std::string& sTi std::vector vTimeParts; std::string sSign = "+"; - if(setTimeFormat() == FAILURE) { + if (setTimeFormat() == FAILURE) { printWarning("%s| Unable to set Time Parameters for radio [%s]", m_sName.c_str()); - return FAILURE;; + return FAILURE; } std::string sCmd("AT+CCLK?"); @@ -601,13 +601,13 @@ ICellularRadio::CODE CellularRadio::getTime(std::string& sDate, std::string& sTi sValue = MTS::Text::strip(sValue, '"'); std::vector vParts = MTS::Text::split(sValue, ','); - if(vParts.size() != 2) { + 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) { + if (vDateParts.size() != 3) { printWarning("%s| Unable to parse Date parts from response [%s]", m_sName.c_str(), sResult.c_str()); return FAILURE; } @@ -622,32 +622,33 @@ ICellularRadio::CODE CellularRadio::getTime(std::string& sDate, std::string& sTi size_t nsign = sTime.find("-"); if (psign != std::string::npos) { - vTimeParts = MTS::Text::split(vParts[1], '+'); + vTimeParts = MTS::Text::split(vParts[1], '+'); } else if (nsign != std::string::npos) { vTimeParts = MTS::Text::split(vParts[1], '-'); sSign = "-"; + } else { + sSign = ""; } - if(vTimeParts.size() != 2) { + if (vTimeParts.size() != 2) { printWarning("%s| Unable to parse Time Zone from response [%s], size %d", m_sName.c_str(), sResult.c_str(),vTimeParts.size()); return FAILURE; } - //Get just the UTC time without zone info + //Get local time sTime = (vTimeParts[0]); - int32_t iZoneUnits = stoi(vTimeParts[1]); //the difference, expressed in quarters of an hour, between the local time and GMT + int32_t iZoneUnits = 0; //the difference, expressed in quarters of an hour, between the local time and GMT + if (!MTS::Text::parse(iZoneUnits, vTimeParts[1])) { + printWarning("%s| Unable to parse Time Zone units from response [%s], size %d", m_sName.c_str(), sResult.c_str(),vTimeParts.size()); + return FAILURE; + } int32_t iZone = iZoneUnits/4; //Divide by 4 to get hours difference int32_t iZonePartial = (iZoneUnits % 4) * 15; //Remainder in minutes - if (iZonePartial < 0) { - //Remove negative sign from partial and clear sign component - iZonePartial *= -1; - sSign = ""; - } std::stringstream ss; ss << sSign << iZone; - if(iZonePartial != 0) { + if (iZonePartial != 0) { ss << ":" << iZonePartial; } diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 2bc4fb6..defe863 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -1676,7 +1676,7 @@ const std::vector& QuectelRadio::getDiagCommands(bool) { return vCommands; } -ICellularRadio::CODE QuectelRadio::setTimeFormat(void) { +ICellularRadio::CODE QuectelRadio::setTimeFormat() { printTrace("%s| Set standard time format", getName().c_str()); ICellularRadio::CODE rc; // Set year format in YYYY first, in case it is in YY format to get accurate year @@ -1689,7 +1689,7 @@ ICellularRadio::CODE QuectelRadio::setTimeFormat(void) { } // Set command enables the automatic time zone update - std::string sCmdCTZU("AT+CTZU=3"); + std::string sCmdCTZU("AT+CTZU=1"); rc = sendBasicCommand(sCmdCTZU); if (rc != SUCCESS) { -- cgit v1.2.3