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.cpp31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp
index 8cdaf44..f0df7fd 100644
--- a/src/MTS_IO_CellularRadio.cpp
+++ b/src/MTS_IO_CellularRadio.cpp
@@ -577,12 +577,14 @@ ICellularRadio::CODE CellularRadio::getTime(std::string& sDate, std::string& sTi
sDate = "";
sTime = "";
sTimeZone = "";
+ CODE rc;
std::vector<std::string> vTimeParts;
std::string sSign = "+";
- if(getTimeUTC() == FAILURE) {
+ rc = setTimeFormat();
+ if (rc != SUCCESS) {
printWarning("%s| Unable to set Time Parameters for radio [%s]", m_sName.c_str());
- return FAILURE;;
+ return rc;
}
std::string sCmd("AT+CCLK?");
@@ -601,13 +603,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 +624,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;
}