From cb427be9a092b0968aee1a42a2bc805735c9c8f2 Mon Sep 17 00:00:00 2001 From: Jeff Hatch Date: Fri, 2 Jun 2017 16:22:48 -0500 Subject: Add AT#FWSWITCH command for LNA radio support in radio-query and radio-cmd --- include/mts/MTS_IO_CellularRadio.h | 7 +++ include/mts/MTS_IO_LE910NA1Radio.h | 4 ++ include/mts/MTS_IO_LE910Radio.h | 3 +- src/MTS_IO_CellularRadio.cpp | 15 ++++++- src/MTS_IO_LE910NA1Radio.cpp | 92 +++++++++++++++++++++++++++++++++++++- 5 files changed, 117 insertions(+), 4 deletions(-) diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index 1d7491f..9d93162 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -424,6 +424,13 @@ namespace MTS { * } */ virtual CODE setRxDiversity(const Json::Value& jArgs)=0; + /* + * jArgs = { + * "fwid" : "Firmware Image To Be Enabled: STRING" + * } + */ + virtual CODE setActiveFirmware(const Json::Value& jArgs); + virtual CODE getActiveFirmware(std::string& sFwId); virtual CODE getEcho(bool& bEnabled); virtual CODE setEcho(bool bEnabled = true); diff --git a/include/mts/MTS_IO_LE910NA1Radio.h b/include/mts/MTS_IO_LE910NA1Radio.h index d9e9694..307bfe5 100644 --- a/include/mts/MTS_IO_LE910NA1Radio.h +++ b/include/mts/MTS_IO_LE910NA1Radio.h @@ -40,6 +40,10 @@ namespace MTS { LE910NA1Radio(const std::string& sPort); virtual ~LE910NA1Radio(){}; + virtual CODE setActiveFirmware(const Json::Value& jArgs); + + virtual CODE getActiveFirmware(std::string& sFwId); + protected: private: diff --git a/include/mts/MTS_IO_LE910Radio.h b/include/mts/MTS_IO_LE910Radio.h index f46094e..6b77607 100644 --- a/include/mts/MTS_IO_LE910Radio.h +++ b/include/mts/MTS_IO_LE910Radio.h @@ -41,7 +41,8 @@ namespace MTS { LE910Radio(const std::string& sLE910Model, const std::string& sPort); virtual ~LE910Radio(){}; - CODE setRxDiversity(const Json::Value& jArgs); + + CODE setRxDiversity(const Json::Value& jArgs); protected: diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index cd957a9..8f838b6 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -1378,6 +1378,19 @@ CellularRadio::CODE CellularRadio::activate(const Json::Value& jArgs, UpdateCb& return NOT_APPLICABLE; } +CellularRadio::CODE CellularRadio::setActiveFirmware(const Json::Value& jArgs) { + printTrace("%s| Set Active Firmware Image Number: not applicable", m_sName.c_str()); + + return NOT_APPLICABLE; +} + +CellularRadio::CODE CellularRadio::getActiveFirmware(std::string& sFwId) { + printTrace("%s| Get Active Firmware Image Number: not applicable", m_sName.c_str()); + sFwId = VALUE_NOT_SUPPORTED; + + return NOT_APPLICABLE; +} + CellularRadio::CODE CellularRadio::sendBasicCommand(const std::string& sCmd, int32_t iTimeoutMillis, const char& ESC) { std::string response = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, iTimeoutMillis, ESC); if (response.size() == 0) { @@ -1498,8 +1511,6 @@ CellularRadio::CODE CellularRadio::test(MTS::AutoPtr& apIo, std::string CellularRadio::extractModelFromResult(const std::string& sResult) { std::string sModel(CellularRadio::VALUE_NOT_SUPPORTED); - printWarning("MYKYTA| ATI4 result: [%s]", sResult.c_str()); - if(sResult.find("HE910-D") != std::string::npos) { sModel = "HE910-D"; } else if(sResult.find("HE910-EUD") != std::string::npos) { diff --git a/src/MTS_IO_LE910NA1Radio.cpp b/src/MTS_IO_LE910NA1Radio.cpp index d58483f..64583b4 100644 --- a/src/MTS_IO_LE910NA1Radio.cpp +++ b/src/MTS_IO_LE910NA1Radio.cpp @@ -24,7 +24,8 @@ A more elaborate description */ - +#include +#include #include using namespace MTS::IO; @@ -36,3 +37,92 @@ LE910NA1Radio::LE910NA1Radio(const std::string& sPort) { } + +CellularRadio::CODE LE910NA1Radio::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=[,]" + // - Firmware Image To Be Enabled + // 0 – Image 1 (Default) + // 1 – Image 2 + // - Setting Storage Configuration + // 0 – Save the value in RAM + // 1 – Save the value in NVM + + printTrace("%s| Set Active Firmware Image Number", getName().c_str()); + + if(!jArgs["fwid"].isString()) { + return INVALID_ARGS; + } + + if (jArgs["fwid"].asString() != "1" && jArgs["fwid"].asString() != "0") { + return INVALID_ARGS; + } + + // LE910-NA1 and LE910-NA V2 is orderable in single image or dual image (single SKU) + // configuration. So issue the test command first + 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 LE910NA1Radio::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()); + + // LE910-NA1 and LE910-NA V2 is orderable in single image or dual image (single SKU) + // configuration. So issue the test command first + 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; +} + -- cgit v1.2.3