summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsdesai <sdesai@multitech.com>2023-03-15 15:22:04 -0500
committersdesai <sdesai@multitech.com>2023-03-15 15:22:04 -0500
commit050834e3cdd0f5f56ba15b09ca568ac6312c7699 (patch)
treecee3134469ec1e843dbe337dc65dda934b9728f3 /src
parent289c724a4706e6f5ec2e73353502384671940c1c (diff)
downloadlibmts-io-050834e3cdd0f5f56ba15b09ca568ac6312c7699.tar.gz
libmts-io-050834e3cdd0f5f56ba15b09ca568ac6312c7699.tar.bz2
libmts-io-050834e3cdd0f5f56ba15b09ca568ac6312c7699.zip
GP-139:Support Portal Case #5086148: use Cellular Radio timeas alternative to GPS or NTP
Diffstat (limited to 'src')
-rw-r--r--src/MTS_IO_CellularRadio.cpp57
-rw-r--r--src/MTS_IO_QuectelRadio.cpp25
-rw-r--r--src/MTS_IO_SequansRadio.cpp25
-rw-r--r--src/MTS_IO_TelitRadio.cpp36
4 files changed, 133 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;
diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp
index 0c0c8ab..655fb38 100644
--- a/src/MTS_IO_QuectelRadio.cpp
+++ b/src/MTS_IO_QuectelRadio.cpp
@@ -1675,3 +1675,28 @@ const std::vector<std::string>& QuectelRadio::getDiagCommands(bool) {
return vCommands;
}
+
+ICellularRadio::CODE QuectelRadio::getTimeUTC(void) {
+ printTrace("%s| Get Time in UTC", getName().c_str());
+
+ // Set year format in YYYY first, in case it is in YY format to get accurate year
+ std::string sCmdCSDF("AT+CSDF=1,2");
+ std::string sRes = sendCommand(sCmdCSDF);
+ size_t endr = sRes.find(ICellularRadio::RSP_OK);
+
+ if (endr == std::string::npos) {
+ printWarning("%s| Unable to set year format for radio using command [%s]", getName().c_str(), sCmdCSDF.c_str());
+ return FAILURE;
+ }
+
+ // Set command enables/disables the automatic time zone update
+ std::string sCmdCTZU("AT+CTZU=1");
+ sRes = sendCommand(sCmdCTZU);
+ size_t endc = sRes.find(ICellularRadio::RSP_OK);
+
+ if (endc == std::string::npos) {
+ printWarning("%s| Unable to set automatic time zone update for radio using command [%s]", getName().c_str(), sCmdCTZU.c_str());
+ return FAILURE;
+ }
+ return SUCCESS;
+} \ No newline at end of file
diff --git a/src/MTS_IO_SequansRadio.cpp b/src/MTS_IO_SequansRadio.cpp
index a48a309..33bd068 100644
--- a/src/MTS_IO_SequansRadio.cpp
+++ b/src/MTS_IO_SequansRadio.cpp
@@ -568,3 +568,28 @@ const std::vector<std::string>& SequansRadio::getDiagCommands(bool) {
return vCommands;
}
+
+ICellularRadio::CODE SequansRadio::getTimeUTC(void) {
+ printTrace("%s| Get Time in UTC", getName().c_str());
+
+ // Set year format in YYYY first, in case it is in YY format to get accurate year
+ std::string sCmdCSDF("AT+CSDF=1,2");
+ std::string sRes = sendCommand(sCmdCSDF);
+ size_t endr = sRes.find(ICellularRadio::RSP_OK);
+
+ if (endr == std::string::npos) {
+ printWarning("%s| Unable to set year format for radio using command [%s]", getName().c_str(), sCmdCSDF.c_str());
+ return FAILURE;
+ }
+
+ // Set year format in YYYY first, in case it is in YY format to get accurate year
+ std::string sCmdCTZU("AT+CTZU=1");
+ sRes = sendCommand(sCmdCTZU);
+ size_t endc = sRes.find(ICellularRadio::RSP_OK);
+
+ if (endc == std::string::npos) {
+ printWarning("%s| Unable to set automatic time zone update for radio using command [%s]", getName().c_str(), sCmdCTZU.c_str());
+ return FAILURE;
+ }
+ return SUCCESS;
+} \ No newline at end of file
diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp
index 21af65d..2c50208 100644
--- a/src/MTS_IO_TelitRadio.cpp
+++ b/src/MTS_IO_TelitRadio.cpp
@@ -1212,3 +1212,39 @@ const std::vector<std::string>& TelitRadio::getDiagCommands(bool) {
return vCommands;
}
+
+ICellularRadio::CODE TelitRadio::getTimeUTC(void) {
+ printTrace("%s| Get Time in UTC", getName().c_str());
+
+ // Set year format in YYYY first, in case it is in YY format to get accurate year
+ std::string sCmdCSDF("AT+CSDF=1,2");
+ std::string sRes = sendCommand(sCmdCSDF);
+ size_t endr = sRes.find(ICellularRadio::RSP_OK);
+
+ if (endr == std::string::npos) {
+ printWarning("%s| Unable to set year format for radio using command [%s]", getName().c_str(), sCmdCSDF.c_str());
+ return FAILURE;
+ }
+
+ // Set command enables/disables the automatic time zone update via NITZ.
+ std::string sCmdCTZU("AT+CTZU=1");
+ sRes = sendCommand(sCmdCTZU);
+ size_t endc = sRes.find(ICellularRadio::RSP_OK);
+
+ if (endc == std::string::npos) {
+ printWarning("%s| Unable to set year format for radio using command [%s]", getName().c_str(), sCmdCTZU.c_str());
+ return FAILURE;
+ }
+
+ //Enables/disables the automatic date/time updating and the
+ //Full Network Name applying. It enables also the #NITZ URC in the format.
+ std::string sCmdNITZ("AT#NITZ");
+ sRes = sendCommand(sCmdNITZ);
+ size_t endn = sRes.find(ICellularRadio::RSP_OK);
+
+ if (endn == std::string::npos) {
+ printWarning("%s| Unable to set automatic time zone update for radio using command [%s]", getName().c_str(), sCmdNITZ.c_str());
+ return FAILURE;
+ }
+ return SUCCESS;
+} \ No newline at end of file