/* * Copyright (C) 2019 by Multi-Tech Systems * * This file is part of libmts-io. * * libmts-io is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * libmts-io is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with libmts-io. If not, see . * */ #include #include #include using namespace MTS::IO; const std::string ME910C1WWRadio::MODEL_NAME("ME910C1-WW"); ME910C1WWRadio::ME910C1WWRadio(const std::string& sPort) : ME910Radio(MODEL_NAME, sPort) { } ME910C1WWRadio::CODE ME910C1WWRadio::setActiveFirmware(const Json::Value& jArgs) { 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; } // 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); } ME910C1WWRadio::CODE ME910C1WWRadio::getActiveFirmware(std::string& sFwId) { std::string sCmd; 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(ICellularRadio::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; }