summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/MTS_IO_CellularRadio.cpp67
-rw-r--r--src/MTS_IO_QuectelRadio.cpp23
-rw-r--r--src/MTS_IO_SequansRadio.cpp5
-rw-r--r--src/MTS_IO_TelitRadio.cpp23
4 files changed, 94 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;
diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp
index b01bbb1..b1ac6fa 100644
--- a/src/MTS_IO_QuectelRadio.cpp
+++ b/src/MTS_IO_QuectelRadio.cpp
@@ -1783,3 +1783,26 @@ const std::vector<std::string>& QuectelRadio::getDiagCommands(bool) {
return vCommands;
}
+
+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
+ std::string sCmdCSDF("AT+CSDF=1,2");
+ rc = sendBasicCommand(sCmdCSDF);
+
+ if (rc != SUCCESS) {
+ printError("%s| Unable to set year format for radio using command [%s]", getName().c_str(), sCmdCSDF.c_str());
+ return rc;
+ }
+
+ // Set command enables the automatic time zone update
+ std::string sCmdCTZU("AT+CTZU=3");
+ rc = sendBasicCommand(sCmdCTZU);
+
+ if (rc != SUCCESS) {
+ printError("%s| Unable to set automatic time zone update for radio using command [%s]", getName().c_str(), sCmdCTZU.c_str());
+ return rc;
+ }
+ return SUCCESS;
+} \ No newline at end of file
diff --git a/src/MTS_IO_SequansRadio.cpp b/src/MTS_IO_SequansRadio.cpp
index 380dd80..3a3585c 100644
--- a/src/MTS_IO_SequansRadio.cpp
+++ b/src/MTS_IO_SequansRadio.cpp
@@ -588,3 +588,8 @@ const std::vector<std::string>& SequansRadio::getDiagCommands(bool) {
return vCommands;
}
+
+ICellularRadio::CODE SequansRadio::setTimeFormat() {
+ // AT+CSDF does not work on CB610L. Also, since CB610L does not return the correct time anyway.
+ return NOT_APPLICABLE;
+}
diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp
index 00c1686..a706069 100644
--- a/src/MTS_IO_TelitRadio.cpp
+++ b/src/MTS_IO_TelitRadio.cpp
@@ -1315,3 +1315,26 @@ const std::vector<std::string>& TelitRadio::getDiagCommands(bool) {
return vCommands;
}
+
+ICellularRadio::CODE TelitRadio::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
+ std::string sCmdCSDF("AT+CSDF=1,2");
+ rc = sendBasicCommand(sCmdCSDF);
+
+ if (rc != SUCCESS) {
+ printError("%s| Unable to set year format for radio using command [%s]", getName().c_str(), sCmdCSDF.c_str());
+ return rc;
+ }
+
+ // Set command enables the automatic time zone update
+ std::string sCmdCTZU("AT+CTZU=1");
+ rc = sendBasicCommand(sCmdCTZU);
+
+ if (rc != SUCCESS) {
+ printError("%s| Unable to set automatic time zone update for radio using command [%s]", getName().c_str(), sCmdCTZU.c_str());
+ return rc;
+ }
+ return SUCCESS;
+}