summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsdesai <sdesai@multitech.com>2023-03-02 14:20:52 -0600
committersdesai <sdesai@multitech.com>2023-03-02 14:20:52 -0600
commit289c724a4706e6f5ec2e73353502384671940c1c (patch)
tree2187e725d2df944dad29a6977fc460a59d70f45a
parent5c3e9d188bfd1309d366d755a70a37d5291d290a (diff)
downloadlibmts-io-289c724a4706e6f5ec2e73353502384671940c1c.tar.gz
libmts-io-289c724a4706e6f5ec2e73353502384671940c1c.tar.bz2
libmts-io-289c724a4706e6f5ec2e73353502384671940c1c.zip
Support Portal Case #5086148: use Cellular Radio timeas alternative to GPS or NTP
-rw-r--r--src/MTS_IO_CellularRadio.cpp29
1 files changed, 4 insertions, 25 deletions
diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp
index 3ce97ec..1c385ae 100644
--- a/src/MTS_IO_CellularRadio.cpp
+++ b/src/MTS_IO_CellularRadio.cpp
@@ -581,6 +581,7 @@ ICellularRadio::CODE CellularRadio::getTime(std::string& sDate, std::string& sTi
std::string sCmd("AT+CCLK?");
std::string sResult = sendCommand(sCmd);
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;
@@ -605,37 +606,15 @@ ICellularRadio::CODE CellularRadio::getTime(std::string& sDate, std::string& sTi
return FAILURE;
}
- //The Date format is YY/MM/DD -> Change to MM/DD/YY
- sDate = vDateParts[1] + "/" + vDateParts[2] + "/" + vDateParts[0];
+ // Append "20" to the year. format is YYYY-MM-DD
+ sDate = "20" + vDateParts[0] + "-" + vDateParts[1] + "-" + vDateParts[2];
vParts = MTS::Text::split(vParts[1], '-');
- if(vParts.size() != 2) {
+ if(vParts.size() != 1) {
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 {