diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/MTS_IO_QuectelRadio.cpp | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 601674b..7d205e7 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -608,8 +608,12 @@ ICellularRadio::CODE QuectelRadio::fumoLocalCleanup() { } ICellularRadio::CODE QuectelRadio::fumoLocalApply(ICellularRadio::UpdateCb& stepCb) { + const std::string sFotaUrcPrefix = "+QIND: \"FOTA\""; // prefix for URC notification messages + const std::vector<std::string> vFotaBailStrings{ sFotaUrcPrefix }; + ICellularRadio::CODE rc; std::string sCmd; + std::string sResponse; rc = getVendorFirmware(m_sQuectelFirmware); if (rc != SUCCESS) { @@ -631,8 +635,8 @@ ICellularRadio::CODE QuectelRadio::fumoLocalApply(ICellularRadio::UpdateCb& step return rc; } - const uint32_t duDetachTimeout = 10000; // wait for 10 seconds for the radio to detach - const uint32_t duAttachTimeout = 30000; // wait for 30 seconds for the radio to attach + const uint32_t duDetachTimeout = 15000; // wait up to 15 seconds for the radio to detach + const uint32_t duAttachTimeout = 30000; // wait up to 30 seconds for the radio to attach const int dMaxAttempts = 5; // the radio makes 5 attempts to update the firmware for (int i = 0; i < dMaxAttempts; i++) { @@ -640,8 +644,22 @@ ICellularRadio::CODE QuectelRadio::fumoLocalApply(ICellularRadio::UpdateCb& step printInfo("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); + // Wait for new FOTA responses. Exits preliminary if radio detached. + sResponse = sendCommand("", vFotaBailStrings, duDetachTimeout, 0x00); + printTrace("Radio response: [%s]", sResponse.c_str()); + + if (i == 0 && sResponse.find(sFotaUrcPrefix) != std::string::npos) { + // FOTA responce code received before radio detach, image can't be applied. + // EG25-G radio prints a message in +QIND: "FOTA",ERR_CODE format in this case. + std::string sErrorCode = getFumoEarlyErrorCode(sResponse); + + printError("Preliminary termination of FUMO procedure: [%s]", sErrorCode.c_str()); + callNextStep(stepCb, "FUMO Error: radio returned error code " + sErrorCode); + + // We got a response from the radio but FOTA failed + rc = FAILURE; + break; + } // It's now detached. Try to reconnect if (!resetConnection(duAttachTimeout)) { @@ -1116,6 +1134,29 @@ ICellularRadio::CODE QuectelRadio::fumoWaitNewFirmware(ICellularRadio::UpdateCb& return rc; } +std::string QuectelRadio::getFumoEarlyErrorCode(const std::string& sRadioInput) { + const std::string sFotaPrefix = "+QIND: \"FOTA\","; + const char cLineEnd = ICellularRadio::CR; + + // sRadioInput may contain several lines. We need to find the line with '+QIND: "FOTA",' in it + auto pLineStart = sRadioInput.find(sFotaPrefix); + + if (pLineStart == std::string::npos) { + // FOTA line not found at all + return "-1"; + } + + // Parse the error code + auto pErrorStart = pLineStart + sFotaPrefix.length(); + auto pLineEnd = sRadioInput.find(cLineEnd, pErrorStart); + + // Filter the error code + std::string sSubString = sRadioInput.substr(pErrorStart, pLineEnd - pErrorStart); + std::string sResult = MTS::Text::trim(sSubString); + + return sResult; +} + ICellularRadio::CODE QuectelRadio::startFileUpload(const std::string& sTargetFilename, size_t nBytes) { const std::vector<std::string> vBailStrings{ ICellularRadio::RSP_CONNECT, ICellularRadio::RSP_ERROR }; const int dTimeout = 1000; //ms |