summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Hatch <jhatch@multitech.com>2020-07-24 09:03:24 -0500
committerJeff Hatch <jhatch@multitech.com>2020-07-24 09:03:24 -0500
commitb1c7aa03e55059c848b9d74a6c30f57affd32b5d (patch)
tree380b6513ab601f759d03786d30800ca19b3d2a25
parentd340135922da6eb881418824e470cbdba835b498 (diff)
parentcb4e2bf0e1902ef91fe10fe6e6aa9c91e04d7c90 (diff)
downloadlibmts-io-b1c7aa03e55059c848b9d74a6c30f57affd32b5d.tar.gz
libmts-io-b1c7aa03e55059c848b9d74a6c30f57affd32b5d.tar.bz2
libmts-io-b1c7aa03e55059c848b9d74a6c30f57affd32b5d.zip
Merge branch 'sk/quectel-delta-fwu' into 'master'
Quectel Delta Radio Firmware Upgrade support - libmts-io implementation See merge request !31
-rw-r--r--include/mts/MTS_IO_QuectelRadio.h10
-rw-r--r--src/MTS_IO_QuectelRadio.cpp69
2 files changed, 57 insertions, 22 deletions
diff --git a/include/mts/MTS_IO_QuectelRadio.h b/include/mts/MTS_IO_QuectelRadio.h
index 41c89dc..58e3d25 100644
--- a/include/mts/MTS_IO_QuectelRadio.h
+++ b/include/mts/MTS_IO_QuectelRadio.h
@@ -82,8 +82,18 @@ namespace MTS {
static uint16_t getQuectelChecksum(const void* data, size_t nBytes);
static inline void updateQuectelChecksum(uint16_t& iChecksum, uint16_t iNewFragment);
static inline uint16_t bytesToUint16(uint8_t high, uint8_t low);
+
CODE fumoWaitUpgradeFinished(UpdateCb& stepCb);
CODE fumoWaitNewFirmware(UpdateCb& stepCb);
+
+ /// Get value from container by its index, use default value if not found. Non-template version.
+ const std::string& getByIndex(const std::vector<std::string>& vector, size_t index, const std::string& defaultValue) {
+ if (index >= vector.size()) {
+ return defaultValue;
+ } else {
+ return vector[index];
+ }
+ }
};
}
}
diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp
index 39c0601..8656973 100644
--- a/src/MTS_IO_QuectelRadio.cpp
+++ b/src/MTS_IO_QuectelRadio.cpp
@@ -1001,10 +1001,11 @@ ICellularRadio::CODE QuectelRadio::fumoWaitUpgradeFinished(ICellularRadio::Updat
const std::string sFotaUrcEnd = "\"END\"";
const std::vector<std::string> vFotaBailStrings{ sFotaUrcPrefix };
+ bool bFinished = false;
CODE rc = FAILURE;
std::string sResponse;
- while (true) { // breaks on "FOTA","END"
+ while (!bFinished) { // breaks on "FOTA","END"
sResponse = sendCommand("", vFotaBailStrings, duUrcTimeout, 0x00);
printTrace("Radio response: [%s]", sResponse.c_str());
@@ -1015,30 +1016,54 @@ ICellularRadio::CODE QuectelRadio::fumoWaitUpgradeFinished(ICellularRadio::Updat
break;
}
- const auto vParts = MTS::Text::split(MTS::Text::trim(sResponse), ',', 3);
- const std::string& sStage = vParts[1];
- if (sStage == sFotaUrcEnd) {
- // FOTA finished
- printTrace("Got FOTA END message");
- const std::string& sCode = vParts[2];
+ // Occasionally sendCommand returns multiple lines in one chunk.
+ // Handle each line separately for such cases.
+ const auto vLines = MTS::Text::split(sResponse, '\r');
- if (sCode == "0") {
- // finished successfully
- rc = SUCCESS;
+ for (const auto& sLine : vLines) {
+ const auto& sTrimmedLine = MTS::Text::trim(sLine);
+
+ if (sTrimmedLine.empty()) {
+ // whitespace characters only, ignore
+ continue;
+ }
+
+ printTrace("Processing line: [%s]", sTrimmedLine.c_str());
+
+ if (sTrimmedLine.find(sFotaUrcPrefix) == std::string::npos) {
+ printDebug("URC message not found, line skipped");
+ continue;
+ }
+
+ const auto vParts = MTS::Text::split(sTrimmedLine, ',', 3);
+ const std::string& sStage = getByIndex(vParts, 1, "NOT_DEFINED");
+
+ if (sStage == sFotaUrcEnd) {
+ // FOTA finished
+ printTrace("Got FOTA END message");
+ const std::string& sCode = getByIndex(vParts, 2, "-1");
+
+ if (sCode == "0") {
+ // finished successfully
+ rc = SUCCESS;
+ bFinished = true;
+ break;
+ }
+
+ // attempt failed, the radio attempts to recover
+ callNextStep(stepCb, "FUMO Error: radio returned error code " + sCode);
+ bFinished = true;
break;
+ } else if (sStage == sFotaUrcStart) {
+ printTrace("Got FOTA START message");
+ } else if (sStage == sFotaUrcProgress) {
+ printTrace("Got FOTA progress message");
+ const std::string& sPercents = getByIndex(vParts, 2, "0");
+ printInfo("FOTA progress: [%s]", sPercents.c_str());
+ callNextStep(stepCb, "FUMO Info: firmware apply progress " + sPercents);
+ } else {
+ printInfo("FOTA unexpected URC code: [%s]", sLine.c_str());
}
- // attempt failed, the radio attempts to recover
- callNextStep(stepCb, "FUMO Error: radio returned error code " + sCode);
- break;
- } else if (sStage == sFotaUrcStart) {
- printTrace("Got FOTA START message");
- } else if (sStage == sFotaUrcProgress) {
- printTrace("Got FOTA progress message");
- const std::string& sPercents = vParts[2];
- printInfo("FOTA progress: [%s]", sPercents.c_str());
- callNextStep(stepCb, "FUMO Info: firmware apply progress " + sPercents);
- } else {
- printInfo("FOTA unexpected URC code: [%s]", sStage.c_str());
}
}