summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhii Kostiuk <serhii.o.kostiuk@globallogic.com>2020-07-03 18:53:57 +0300
committerSerhii Kostiuk <serhii.o.kostiuk@globallogic.com>2020-07-03 18:56:00 +0300
commitd19829b7e9cdd3c7e3d209628044ab62cd46b907 (patch)
tree37ed66ed5179853b6fb3d7581d583b9dc2b74adf
parent2c3296b5239b5d27f5df4d61a9609ace6d70904f (diff)
downloadlibmts-io-d19829b7e9cdd3c7e3d209628044ab62cd46b907.tar.gz
libmts-io-d19829b7e9cdd3c7e3d209628044ab62cd46b907.tar.bz2
libmts-io-d19829b7e9cdd3c7e3d209628044ab62cd46b907.zip
Quectel Delta Radio Firmware Upgrade support - libmts-io implementation
Simplified usage of step callbacks in the QuectelRadio class. Refactored existing function to use a wrapper and preven repetitive checks.
-rw-r--r--include/mts/MTS_IO_QuectelRadio.h15
-rw-r--r--src/MTS_IO_QuectelRadio.cpp68
2 files changed, 36 insertions, 47 deletions
diff --git a/include/mts/MTS_IO_QuectelRadio.h b/include/mts/MTS_IO_QuectelRadio.h
index b805ed8..3751b5a 100644
--- a/include/mts/MTS_IO_QuectelRadio.h
+++ b/include/mts/MTS_IO_QuectelRadio.h
@@ -72,6 +72,9 @@ namespace MTS {
CODE startFileUpload(const std::string& sTargetFilename, size_t nBytes);
CODE abortFileUpload();
+ static inline void callNextStep(UpdateCb& stepCb, const char* csMessage);
+ static inline void callNextStep(UpdateCb& stepCb, const std::string& sMessage);
+
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);
@@ -83,6 +86,18 @@ namespace MTS {
}
}
+void MTS::IO::QuectelRadio::callNextStep(ICellularRadio::UpdateCb& stepCb, const char* csMessage) {
+ if (stepCb) {
+ stepCb(Json::Value(csMessage));
+ }
+}
+
+void MTS::IO::QuectelRadio::callNextStep(ICellularRadio::UpdateCb& stepCb, const std::string& sMessage) {
+ if (stepCb) {
+ stepCb(Json::Value(sMessage));
+ }
+}
+
void MTS::IO::QuectelRadio::updateQuectelChecksum(uint16_t& iChecksum, uint16_t iNewFragment) {
iChecksum = iChecksum ^ iNewFragment;
}
diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp
index 7b67431..cbc2cfb 100644
--- a/src/MTS_IO_QuectelRadio.cpp
+++ b/src/MTS_IO_QuectelRadio.cpp
@@ -476,9 +476,7 @@ ICellularRadio::CODE QuectelRadio::startOmaDm(ICellularRadio::UpdateCb& stepCb)
eCode = sendBasicCommand(sCmdOdmStart, iTimeoutOk);
if (eCode != SUCCESS) {
printError("%s| OMA DM procedure can not be started", getName().c_str());
- if (stepCb) {
- stepCb(Json::Value("OMA DM Error: OMA DM can not be started"));
- }
+ callNextStep(stepCb, "OMA DM Error: OMA DM can not be started");
break;
}
@@ -489,18 +487,14 @@ ICellularRadio::CODE QuectelRadio::startOmaDm(ICellularRadio::UpdateCb& stepCb)
// Received something unexpected or nothing at all?
if (sResponse.find(sOdmStarted) == std::string::npos) {
printError("%s| OMA DM procedure failed due to timeout", getName().c_str());
- if (stepCb) {
- stepCb(Json::Value("OMA DM Error: OMA DM failed due to timeout"));
- }
+ callNextStep(stepCb, "OMA DM Error: OMA DM failed due to timeout");
eCode = FAILURE;
break;
}
// Got "DM Started" message from the radio
printTrace("%s| OMA DM started", getName().c_str());
- if (stepCb) {
- stepCb(Json::Value("OMA DM Info: OMA DM started"));
- }
+ callNextStep(stepCb, "OMA DM Info: OMA DM started");
// Wait for the "End" or "Abnormal" response
sResponse = sendCommand("", vOdmFinishedStrings, iTimeoutEnd, 0x00);
@@ -509,9 +503,8 @@ ICellularRadio::CODE QuectelRadio::startOmaDm(ICellularRadio::UpdateCb& stepCb)
// Received "Abnormal"?
if (sResponse.find(sOdmAbnormal) != std::string::npos) {
printError("%s| OMA DM procedure failed due to internal error: [%s]", getName().c_str(), sResponse.c_str());
- if (stepCb) {
- stepCb(Json::Value("OMA DM Error: OMA DM failed due to internal error"));
- }
+ callNextStep(stepCb, "OMA DM Error: OMA DM failed due to internal error");
+
eCode = FAILURE;
break;
}
@@ -519,9 +512,8 @@ ICellularRadio::CODE QuectelRadio::startOmaDm(ICellularRadio::UpdateCb& stepCb)
// Received something unexpected or nothing at all?
if (sResponse.find(sOdmFinished) == std::string::npos) {
printError("%s| OMA DM procedure failed due to timeout", getName().c_str());
- if (stepCb) {
- stepCb(Json::Value("OMA DM Error: OMA DM failed due to timeout"));
- }
+ callNextStep(stepCb, "OMA DM Error: OMA DM failed due to timeout");
+
sendBasicCommand(sCmdOdmAbort, iTimeoutAbort); // abort the procedure
eCode = FAILURE;
break;
@@ -529,9 +521,7 @@ ICellularRadio::CODE QuectelRadio::startOmaDm(ICellularRadio::UpdateCb& stepCb)
// Got "DM End" message from the radio
printTrace("%s| OMA DM finished", getName().c_str());
- if (stepCb) {
- stepCb(Json::Value("OMA DM Info: OMA DM finished"));
- }
+ callNextStep(stepCb, "OMA DM Info: OMA DM finished");
eCode = SUCCESS;
@@ -602,9 +592,7 @@ ICellularRadio::CODE QuectelRadio::fumoLocalApply(ICellularRadio::UpdateCb& step
rc = sendBasicCommand(sCmd, 1000);
if (rc != SUCCESS) {
- if(stepCb) {
- stepCb(Json::Value("FUMO Error: failed to apply the firmware"));
- }
+ callNextStep(stepCb, "FUMO Error: failed to apply the firmware");
return rc;
}
@@ -615,9 +603,7 @@ ICellularRadio::CODE QuectelRadio::fumoLocalApply(ICellularRadio::UpdateCb& step
for (int i = 0; i < dMaxAttempts; i++) {
printInfo("Waiting for the radio to enter recovery mode");
- if(stepCb) {
- stepCb(Json::Value("FUMO Info: waiting for the radio to enter recovery mode"));
- }
+ callNextStep(stepCb, "FUMO Info: waiting for the radio to enter recovery mode");
// Wait for the radio to detach from the USB bus
MTS::Thread::sleep(duDetachTimeout);
@@ -626,9 +612,7 @@ ICellularRadio::CODE QuectelRadio::fumoLocalApply(ICellularRadio::UpdateCb& step
if (!resetConnection(duAttachTimeout)) {
printError("Can't connect to the radio in %d ms", (duAttachTimeout));
- if(stepCb) {
- stepCb(Json::Value("FUMO error: failed to connect to the radio in recovery mode"));
- }
+ callNextStep(stepCb, "FUMO error: failed to connect to the radio in recovery mode");
break;
}
@@ -836,9 +820,7 @@ ICellularRadio::CODE QuectelRadio::uploadFile(int fd, const std::string& sTarget
}
printTrace("File upload started.");
- if (stepCb) {
- stepCb(Json::Value("FILE info: Started file upload for " + sTargetFilename));
- }
+ callNextStep(stepCb, "FILE info: Started file upload for " + sTargetFilename);
uint16_t dChecksum = 0;
size_t nChunksPerCent = (nChunks / 100) + 1;
@@ -863,14 +845,14 @@ ICellularRadio::CODE QuectelRadio::uploadFile(int fd, const std::string& sTarget
if (stepCb && ((iChunk % nChunksPerCent) == 0)) {
size_t dPercentsCompleted = iChunk / nChunksPerCent;
- stepCb(Json::Value("FILE info: Uploaded " + MTS::Text::format(dPercentsCompleted) + "%"));
+ callNextStep(stepCb, "FILE info: Uploaded " + MTS::Text::format(dPercentsCompleted) + "%");
}
}
if (rc != SUCCESS) {
// cancel upload and terminate
- stepCb(Json::Value("FILE error: Upload failed due to internal error"));
+ callNextStep(stepCb, "FILE error: Upload failed due to internal error");
abortFileUpload();
return rc;
}
@@ -893,10 +875,10 @@ ICellularRadio::CODE QuectelRadio::uploadFile(int fd, const std::string& sTarget
rc = FAILURE;
}
- if (stepCb && rc == SUCCESS) {
- stepCb(Json::Value("FILE info: Upload finished successfully"));
- } else if (stepCb) {
- stepCb(Json::Value("FILE error: Upload failed due to internal error"));
+ if (rc == SUCCESS) {
+ callNextStep(stepCb, "FILE info: Upload finished successfully");
+ } else {
+ callNextStep(stepCb, "FILE error: Upload failed due to internal error");
}
return rc;
@@ -1042,11 +1024,7 @@ ICellularRadio::CODE QuectelRadio::fumoWaitUpgradeFinished(ICellularRadio::Updat
if (sResponse.find(sFotaUrcPrefix) == std::string::npos) {
printError("No URC messages from the radio in %d ms", duUrcTimeout);
-
- if(stepCb) {
- stepCb(Json::Value("FUMO error: timeout, radio is not responding"));
- }
-
+ callNextStep(stepCb, "FUMO error: timeout, radio is not responding");
break;
}
@@ -1112,14 +1090,10 @@ ICellularRadio::CODE QuectelRadio::fumoWaitNewFirmware(ICellularRadio::UpdateCb&
oTimer.stop();
if (rc == SUCCESS) {
- if(stepCb) {
- stepCb(Json::Value("FUMO done: radio firmware applied successfully"));
- }
+ callNextStep(stepCb, "FUMO done: radio firmware applied successfully");
}
else {
- if(stepCb) {
- stepCb(Json::Value("FUMO error: radio firmware has not been updated"));
- }
+ callNextStep(stepCb, "FUMO error: radio firmware has not been updated");
}
return rc;