summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsdesai <sdesai@multitech.com>2023-03-27 11:53:13 -0500
committerJohn Klug <john.klug@multitech.com>2023-04-26 17:56:00 -0500
commit40e5653006558c569bc90c247790d95b68b2f646 (patch)
tree29731b473ce80217a75abb7f5d0fc2cded68422f
parent576eb04e2d42e3b9c5fa40748d1d190a457fa1f8 (diff)
downloadlibmts-io-40e5653006558c569bc90c247790d95b68b2f646.tar.gz
libmts-io-40e5653006558c569bc90c247790d95b68b2f646.tar.bz2
libmts-io-40e5653006558c569bc90c247790d95b68b2f646.zip
Support Portal Case #5086148: use Cellular Radio time as alternative to GPS or NTP
-rw-r--r--include/mts/MTS_IO_CellularRadio.h2
-rw-r--r--include/mts/MTS_IO_ICellularRadio.h1
-rw-r--r--include/mts/MTS_IO_QuectelRadio.h4
-rw-r--r--include/mts/MTS_IO_SequansRadio.h4
-rw-r--r--include/mts/MTS_IO_TelitRadio.h4
-rw-r--r--src/MTS_IO_CellularRadio.cpp31
-rw-r--r--src/MTS_IO_QuectelRadio.cpp28
-rw-r--r--src/MTS_IO_SequansRadio.cpp28
-rw-r--r--src/MTS_IO_TelitRadio.cpp39
9 files changed, 58 insertions, 83 deletions
diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h
index 68c1394..c2aa346 100644
--- a/include/mts/MTS_IO_CellularRadio.h
+++ b/include/mts/MTS_IO_CellularRadio.h
@@ -278,6 +278,8 @@ namespace MTS {
*/
virtual const std::vector<std::string>& getDiagCommands(bool bIsSimReady = true) = 0;
+ virtual CODE setTimeFormat() = 0;
+
class RadioBandMap : public MTS::NonCopyable {
public:
RadioBandMap()
diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h
index da8e130..d5b5f18 100644
--- a/include/mts/MTS_IO_ICellularRadio.h
+++ b/include/mts/MTS_IO_ICellularRadio.h
@@ -717,7 +717,6 @@ namespace MTS {
* CODE::FAILURE otherwise.
*/
virtual CODE getDiagnostics(std::string& sDiagReport) = 0;
- virtual CODE getTimeUTC(void) = 0;
};
}
}
diff --git a/include/mts/MTS_IO_QuectelRadio.h b/include/mts/MTS_IO_QuectelRadio.h
index 7015acb..8e75c12 100644
--- a/include/mts/MTS_IO_QuectelRadio.h
+++ b/include/mts/MTS_IO_QuectelRadio.h
@@ -86,7 +86,9 @@ namespace MTS {
CODE setRxDiversity(const Json::Value& jArgs) override;
const std::vector<std::string>& getDiagCommands(bool bIsSimReady = true) override;
- CODE getTimeUTC(void) override;
+
+ CODE setTimeFormat() override;
+
private:
// private variable to save old firmware versions during FOTA
std::string m_sQuectelFirmware;
diff --git a/include/mts/MTS_IO_SequansRadio.h b/include/mts/MTS_IO_SequansRadio.h
index d61ae67..804d473 100644
--- a/include/mts/MTS_IO_SequansRadio.h
+++ b/include/mts/MTS_IO_SequansRadio.h
@@ -49,7 +49,7 @@ namespace MTS {
CODE setRxDiversity(const Json::Value& jArgs) override;
const std::vector<std::string> getRegistrationCommands() override;
- CODE getTimeUTC(void) override;
+
protected:
SequansRadio(const std::string& sName, const std::string& sRadioPort);
@@ -58,6 +58,8 @@ namespace MTS {
const std::vector<std::string>& getDiagCommands(bool bIsSimReady = true) override;
+ CODE setTimeFormat() override;
+
private:
/*
* @brief getSimLockAttemptsByType - get the number of remaining attempts to
diff --git a/include/mts/MTS_IO_TelitRadio.h b/include/mts/MTS_IO_TelitRadio.h
index 01897ac..d5e8bac 100644
--- a/include/mts/MTS_IO_TelitRadio.h
+++ b/include/mts/MTS_IO_TelitRadio.h
@@ -51,7 +51,7 @@ namespace MTS {
CODE fumoLocalApply(UpdateCb& stepCb) override;
CODE getSelectedBandsRaw(std::string& sRawBands) override;
- CODE getTimeUTC(void) override;
+
protected:
TelitRadio(const std::string& sName, const std::string& sRadioPort);
@@ -77,6 +77,8 @@ namespace MTS {
static bool isContainsSignChar(const std::string& str);
+ CODE setTimeFormat() override;
+
private:
virtual CODE getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk, const std::string& sLockStatus);
ICellularRadio::CODE wdsList(std::set<int> &wds);
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;
}
diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp
index 655fb38..c4b6ac4 100644
--- a/src/MTS_IO_QuectelRadio.cpp
+++ b/src/MTS_IO_QuectelRadio.cpp
@@ -1676,27 +1676,25 @@ const std::vector<std::string>& QuectelRadio::getDiagCommands(bool) {
return vCommands;
}
-ICellularRadio::CODE QuectelRadio::getTimeUTC(void) {
- printTrace("%s| Get Time in UTC", getName().c_str());
-
+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");
- std::string sRes = sendCommand(sCmdCSDF);
- size_t endr = sRes.find(ICellularRadio::RSP_OK);
+ rc = sendBasicCommand(sCmdCSDF);
- 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;
+ 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/disables the automatic time zone update
- std::string sCmdCTZU("AT+CTZU=1");
- sRes = sendCommand(sCmdCTZU);
- size_t endc = sRes.find(ICellularRadio::RSP_OK);
+ // Set command enables the automatic time zone update
+ std::string sCmdCTZU("AT+CTZU=3");
+ rc = sendBasicCommand(sCmdCTZU);
- 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;
+ 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 33bd068..5f85b58 100644
--- a/src/MTS_IO_SequansRadio.cpp
+++ b/src/MTS_IO_SequansRadio.cpp
@@ -569,27 +569,7 @@ 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
+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 2c50208..be307e6 100644
--- a/src/MTS_IO_TelitRadio.cpp
+++ b/src/MTS_IO_TelitRadio.cpp
@@ -1213,38 +1213,25 @@ const std::vector<std::string>& TelitRadio::getDiagCommands(bool) {
return vCommands;
}
-ICellularRadio::CODE TelitRadio::getTimeUTC(void) {
- printTrace("%s| Get Time in UTC", getName().c_str());
-
+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");
- std::string sRes = sendCommand(sCmdCSDF);
- size_t endr = sRes.find(ICellularRadio::RSP_OK);
+ rc = sendBasicCommand(sCmdCSDF);
- 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;
+ 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/disables the automatic time zone update via NITZ.
+ // Set command enables the automatic time zone update
std::string sCmdCTZU("AT+CTZU=1");
- sRes = sendCommand(sCmdCTZU);
- size_t endc = sRes.find(ICellularRadio::RSP_OK);
+ rc = sendBasicCommand(sCmdCTZU);
- 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;
+ 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
+}