diff options
author | sdesai <sdesai@multitech.com> | 2023-03-23 16:37:24 -0500 |
---|---|---|
committer | sdesai <sdesai@multitech.com> | 2023-03-23 16:37:24 -0500 |
commit | 91c623896442013d82f59e6e06e70523e9046b8c (patch) | |
tree | 31a26054a2da8366deede51d523d882084e3cde9 /src | |
parent | 96a6958ec2242d1ff7bc0afa83e25044e61800e1 (diff) | |
download | libmts-io-91c623896442013d82f59e6e06e70523e9046b8c.tar.gz libmts-io-91c623896442013d82f59e6e06e70523e9046b8c.tar.bz2 libmts-io-91c623896442013d82f59e6e06e70523e9046b8c.zip |
Support Portal Case #5086148: use Cellular Radio time as alternative to GPS or NTP
Diffstat (limited to 'src')
-rw-r--r-- | src/MTS_IO_CellularRadio.cpp | 29 | ||||
-rw-r--r-- | src/MTS_IO_QuectelRadio.cpp | 4 |
2 files changed, 17 insertions, 16 deletions
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<std::string> 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<std::string> 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<std::string> 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<std::string>& 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) { |