diff options
author | David Marcaccini <david.marcaccini@multitech.com> | 2019-03-15 10:52:56 -0500 |
---|---|---|
committer | David Marcaccini <david.marcaccini@multitech.com> | 2019-03-15 10:52:56 -0500 |
commit | 1b2ea34757d16fd5206c130e6269766bb80a7e13 (patch) | |
tree | 82d3cc22a9338e2aef1663ac2713f45ef323c3c0 /src | |
parent | 36d1c638d115caefc042fe7a172cc531bb9e1436 (diff) | |
download | libmts-io-1b2ea34757d16fd5206c130e6269766bb80a7e13.tar.gz libmts-io-1b2ea34757d16fd5206c130e6269766bb80a7e13.tar.bz2 libmts-io-1b2ea34757d16fd5206c130e6269766bb80a7e13.zip |
Add active firmware switch for ME910C1WW Radio1.0.16
Diffstat (limited to 'src')
-rw-r--r-- | src/MTS_IO_ME910C1WWRadio.cpp | 89 |
1 files changed, 87 insertions, 2 deletions
diff --git a/src/MTS_IO_ME910C1WWRadio.cpp b/src/MTS_IO_ME910C1WWRadio.cpp index 03cb1a4..d26749a 100644 --- a/src/MTS_IO_ME910C1WWRadio.cpp +++ b/src/MTS_IO_ME910C1WWRadio.cpp @@ -18,6 +18,8 @@ * */ +#include <mts/MTS_Text.h> +#include <mts/MTS_Logger.h> #include <mts/MTS_IO_ME910C1WWRadio.h> using namespace MTS::IO; @@ -30,7 +32,90 @@ ME910C1WWRadio::ME910C1WWRadio(const std::string& sPort) } -CellularRadio::CODE ME910C1WWRadio::getCarrier(std::string& sCarrier) { - sCarrier = "AT&T"; +CellularRadio::CODE ME910C1WWRadio::setActiveFirmware(const Json::Value& jArgs) { + CellularRadio::CODE rc; + + // Set command allows enabling a specific firmware image on products + // embedding 2 different firmware images: + // + // "AT#FWSWITCH=<image_number>[,<storage_conf>]" + // <image_number> - Firmware Image To Be Enabled + // 0 – Image 1 (Default) + // 1 – Image 2 + // <storage_conf> - Setting Storage Configuration + // 0 – Save the <image_number> value in RAM + // 1 – Save the <image_number> value in NVM + + printTrace("%s| Set Active Firmware Image Number", getName().c_str()); + + if(!jArgs["fwid"].isString()) { + return INVALID_ARGS; + } + + // ME910C1-WW uses code "2" for World-Wide mode + if (jArgs["fwid"].asString() != "2" && jArgs["fwid"].asString() != "1" && jArgs["fwid"].asString() != "0") { + return INVALID_ARGS; + } + + // Test command to check if firmware switch is supported + rc = sendBasicCommand("AT#FWSWITCH=?"); + if (rc == ERROR) { + printTrace("%s| FWSWITCH is not supported", getName().c_str()); + return NOT_APPLICABLE; + } + else if (rc != SUCCESS) { + return rc; + } + + std::string sCmd = "AT#FWSWITCH="; + sCmd += jArgs["fwid"].asString(); + sCmd += ",1"; + + printTrace("%s| Issuing %s command", getName().c_str(), sCmd.c_str()); + + return sendBasicCommand(sCmd, 5000); +} + +CellularRadio::CODE ME910C1WWRadio::getActiveFirmware(std::string& sFwId) { + std::string sCmd; + CellularRadio::CODE rc; + // + // Read command reports the current active firmware image: + // AT#FWSWITCH? + // #FWSWITCH: 1 + // + // OK + // + printTrace("%s| Get Active Firmware Image Number", getName().c_str()); + + // Test command to check if firmware switch is supported + sCmd = "AT#FWSWITCH=?"; + rc = sendBasicCommand(sCmd); + if (rc == ERROR) { + printTrace("%s| FWSWITCH is not supported", getName().c_str()); + return NOT_APPLICABLE; + } + else if (rc != SUCCESS) { + return rc; + } + + sCmd = "AT#FWSWITCH?"; + std::string sResult = sendCommand(sCmd); + size_t end = sResult.find(RSP_OK); + if (end == std::string::npos) { + printWarning("%s| Unable to get active image number from radio using command [%s]", + getName().c_str(), + sCmd.c_str()); + return FAILURE; + } + + size_t start = sResult.find("#FWSWITCH:") + sizeof("#FWSWITCH:"); + sFwId = MTS::Text::trim(sResult.substr(start, end-start)); + if(sFwId.size() == 0) { + printWarning("%s| Firmware Image Number is empty", getName().c_str()); + return FAILURE; + } + return SUCCESS; } + |