summaryrefslogtreecommitdiff
path: root/src/MTS_IO_CellularRadio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/MTS_IO_CellularRadio.cpp')
-rw-r--r--src/MTS_IO_CellularRadio.cpp57
1 files changed, 47 insertions, 10 deletions
diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp
index 1c385ae..8cdaf44 100644
--- a/src/MTS_IO_CellularRadio.cpp
+++ b/src/MTS_IO_CellularRadio.cpp
@@ -577,6 +577,13 @@ ICellularRadio::CODE CellularRadio::getTime(std::string& sDate, std::string& sTi
sDate = "";
sTime = "";
sTimeZone = "";
+ std::vector<std::string> vTimeParts;
+ std::string sSign = "+";
+
+ if(getTimeUTC() == FAILURE) {
+ printWarning("%s| Unable to set Time Parameters for radio [%s]", m_sName.c_str());
+ return FAILURE;;
+ }
std::string sCmd("AT+CCLK?");
std::string sResult = sendCommand(sCmd);
@@ -588,7 +595,7 @@ ICellularRadio::CODE CellularRadio::getTime(std::string& sDate, std::string& sTi
}
size_t start = sResult.find("CCLK: ");
- if(start != std::string::npos) {
+ if (start != std::string::npos) {
start += sizeof("CCLK: ");
std::string sValue = MTS::Text::trim(sResult.substr(start, end - start));
sValue = MTS::Text::strip(sValue, '"');
@@ -599,26 +606,56 @@ ICellularRadio::CODE CellularRadio::getTime(std::string& sDate, std::string& sTi
return FAILURE;
}
-
std::vector<std::string> 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());
+ printWarning("%s| Unable to parse Date parts from response [%s]", m_sName.c_str(), sResult.c_str());
return FAILURE;
}
- // Append "20" to the year. format is YYYY-MM-DD
- sDate = "20" + vDateParts[0] + "-" + vDateParts[1] + "-" + vDateParts[2];
+ // The format is YYYY-MM-DD
+ sDate = vDateParts[0] + "-" + vDateParts[1] + "-" + vDateParts[2];
+
+ sTime = (vParts[1]);
+
+ //E.g. 20:39:34-16. Split time and zone with + or - sign.
+ size_t psign = sTime.find("+");
+ size_t nsign = sTime.find("-");
+
+ if (psign != std::string::npos) {
+ vTimeParts = MTS::Text::split(vParts[1], '+');
+ } else if (nsign != std::string::npos) {
+ vTimeParts = MTS::Text::split(vParts[1], '-');
+ sSign = "-";
+ }
- vParts = MTS::Text::split(vParts[1], '-');
- if(vParts.size() != 1) {
- printWarning("%s| Unable to parse Time from response [%s]", m_sName.c_str(), sResult.c_str());
+ 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;
}
- sTime = vParts[0];
+
+ //Get just the UTC time without zone info
+ 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 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) {
+ 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());
+ printWarning("%s| Unable to parse Time from radio using command [%s]", m_sName.c_str(), sCmd.c_str());
}
return FAILURE;