diff options
Diffstat (limited to 'src/MTS_IO_QuectelRadio.cpp')
| -rw-r--r-- | src/MTS_IO_QuectelRadio.cpp | 121 | 
1 files changed, 59 insertions, 62 deletions
| diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 25d2a30..7b67431 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -540,7 +540,21 @@ ICellularRadio::CODE QuectelRadio::startOmaDm(ICellularRadio::UpdateCb& stepCb)      return eCode;  } -ICellularRadio::CODE QuectelRadio::uploadDeltaFirmwareFile(int fd, ICellularRadio::UpdateCb& stepCb) { +ICellularRadio::CODE QuectelRadio::updateFumoLocal(int fd, ICellularRadio::UpdateCb& stepCb) { +    CODE rc; + +    rc = fumoLocalInject(fd, stepCb); +    if (rc != SUCCESS) { +        return rc; +    } + +    rc = fumoLocalApply(stepCb); +    (void)fumoLocalCleanup();  // try to cleanup the injected file but cleanup errors are not fatal + +    return rc; +} + +ICellularRadio::CODE QuectelRadio::fumoLocalInject(int fd, ICellularRadio::UpdateCb& stepCb) {      CODE rc = FAILURE;      bool bIsFilePresent = false; @@ -552,7 +566,7 @@ ICellularRadio::CODE QuectelRadio::uploadDeltaFirmwareFile(int fd, ICellularRadi          }          if (bIsFilePresent) { -            rc = removeDeltaFirmwareFile(); +            rc = fumoLocalCleanup();          }          if (rc != SUCCESS) { @@ -571,16 +585,16 @@ ICellularRadio::CODE QuectelRadio::uploadDeltaFirmwareFile(int fd, ICellularRadi      return rc;  } -ICellularRadio::CODE QuectelRadio::removeDeltaFirmwareFile() { +ICellularRadio::CODE QuectelRadio::fumoLocalCleanup() {      printTrace("Removing the delta upgrade file: %s", VALUE_MTS_DELTA_NAME.c_str());      return removeFile(VALUE_MTS_DELTA_NAME);  } -ICellularRadio::CODE QuectelRadio::applyDeltaFirmwareFile(ICellularRadio::UpdateCb& stepCb) { +ICellularRadio::CODE QuectelRadio::fumoLocalApply(ICellularRadio::UpdateCb& stepCb) {      ICellularRadio::CODE rc;      std::string sCmd; -    // Send "AT+QFOTADL" command to start the upgrade. OK responce follows shortly. +    // Send "AT+QFOTADL" command to start the upgrade. OK response follows shortly.      sCmd  = "AT+QFOTADL=\"";      sCmd += VALUE_MTS_DELTA_PATH;      sCmd += "\""; @@ -594,16 +608,48 @@ ICellularRadio::CODE QuectelRadio::applyDeltaFirmwareFile(ICellularRadio::Update          return rc;      } -    rc = waitApplyDeltaFirmware(stepCb); -    if (rc != SUCCESS) { +    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 int dMaxAttempts = 5;  // the radio makes 5 attempts to update the firmware + +    for (int i = 0; i < dMaxAttempts; i++) { + +        printInfo("Waiting for the radio to enter recovery mode");          if(stepCb) { -            stepCb(Json::Value("FUMO Error: failed to apply the firmware")); +            stepCb(Json::Value("FUMO Info: waiting for the radio to enter recovery mode"));          } -        //return rc; -    } -    // TODO: Check the new firmware version +        // Wait for the radio to detach from the USB bus +        MTS::Thread::sleep(duDetachTimeout); + +        // It's now detached. Try to reconnect +        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")); +            } +            break; +        } + +        // It's now back on the bus. Wait for the URC messages. +        rc = fumoWaitUpgradeFinished(stepCb); +        if (rc == ERROR) { +            // unrecoverable error +            break; +        } + +        if (rc != SUCCESS) { +            // attempt failed, radio reboots and starts its next attempt +            continue; +        } + +        // attempt finished +        break; +    } +    // Wait for the radio to finish update and reboot +    rc = fumoWaitNewFirmware(stepCb);      return rc;  } @@ -979,56 +1025,7 @@ ICellularRadio::CODE QuectelRadio::readChunk(int fd, char* pChunk, size_t dChunk      return rc;  } -ICellularRadio::CODE QuectelRadio::waitApplyDeltaFirmware(ICellularRadio::UpdateCb& stepCb) { -    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 int dMaxAttempts = 5;  // the radio makes 5 attempts to update the firmware - -    CODE rc = FAILURE; -    std::string sResponse; - -    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")); -        } - -        // Wait for the radio to detach from the USB bus -        MTS::Thread::sleep(duDetachTimeout); - -        // It's now detached. Try to reconnect -        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")); -            } -            break; -        } - -        // It's now back on the bus. Wait for the URC messages. -        rc = waitFotaFinish(stepCb); -        if (rc == ERROR) { -            // unrecoverable error -            break; -        } - -        if (rc != SUCCESS) { -            // attempt failed, radio reboots and starts its next attempt -            continue; -        } - -        // attempt finished -        break; -    } - -    // Wait for the radio to finish update and reboot -    rc = waitNewFirmware(stepCb); -    return rc; -} - -ICellularRadio::CODE QuectelRadio::waitFotaFinish(ICellularRadio::UpdateCb& stepCb) { +ICellularRadio::CODE QuectelRadio::fumoWaitUpgradeFinished(ICellularRadio::UpdateCb& stepCb) {      const uint32_t duUrcTimeout = 4 * 60 * 1000;  // wait for 4 minutes for the next URC message      const std::string sFotaUrcPrefix = "+QIND: \"FOTA\"";  // prefix for the URC notification messages      const std::string sFotaUrcStart = "\"START\""; @@ -1082,7 +1079,7 @@ ICellularRadio::CODE QuectelRadio::waitFotaFinish(ICellularRadio::UpdateCb& step      return rc;  } -ICellularRadio::CODE QuectelRadio::waitNewFirmware(ICellularRadio::UpdateCb& stepCb) { +ICellularRadio::CODE QuectelRadio::fumoWaitNewFirmware(ICellularRadio::UpdateCb& stepCb) {      MTS::Timer oTimer;      oTimer.start();      std::string sFirmware; | 
