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.cpp67
1 files changed, 43 insertions, 24 deletions
diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp
index 7200658..fb1d02b 100644
--- a/src/MTS_IO_CellularRadio.cpp
+++ b/src/MTS_IO_CellularRadio.cpp
@@ -578,61 +578,80 @@ ICellularRadio::CODE CellularRadio::getTime(std::string& sDate, std::string& sTi
sDate = "";
sTime = "";
sTimeZone = "";
+ CODE rc;
+ std::vector<std::string> vTimeParts;
+ std::string sSign = "+";
+
+ rc = setTimeFormat();
+ if (rc != SUCCESS) {
+ printWarning("%s| Unable to set Time Parameters for radio [%s]", m_sName.c_str());
+ return rc;
+ }
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;
}
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, '"');
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) {
- printWarning("%s| Unable to parse Date from response [%s]", m_sName.c_str(), sResult.c_str());
+ if (vDateParts.size() != 3) {
+ printWarning("%s| Unable to parse Date parts from response [%s]", m_sName.c_str(), sResult.c_str());
return FAILURE;
}
- //The Date format is YY/MM/DD -> Change to MM/DD/YY
- sDate = vDateParts[1] + "/" + vDateParts[2] + "/" + vDateParts[0];
+ // The format is YYYY-MM-DD
+ sDate = vDateParts[0] + "-" + vDateParts[1] + "-" + vDateParts[2];
- vParts = MTS::Text::split(vParts[1], '-');
- if(vParts.size() != 2) {
- printWarning("%s| Unable to parse Time from response [%s]", m_sName.c_str(), sResult.c_str());
- return FAILURE;
+ 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 = "-";
+ } else {
+ sSign = "";
}
- 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());
+ 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 local time
+ sTime = (vTimeParts[0]);
+
+ 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
- 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 << sSign << iZone;
+ if (iZonePartial != 0) {
ss << ":" << iZonePartial;
}
@@ -640,7 +659,7 @@ ICellularRadio::CODE CellularRadio::getTime(std::string& sDate, std::string& sTi
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;