/* * 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 LE910C4NFRadio::MODEL_NAME("LE910C4-NF"); LE910C4NFRadio::LE910C4NFRadio(const std::string& sPort) : LE910Radio(MODEL_NAME, sPort) { } CellularRadio::CODE LE910C4NFRadio::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" && jArgs["fwid"].asString() != "2") { 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 to make sure FWSWITCH is a valid command 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 LE910C4NFRadio::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:"); std::string sFwSwitchValue = MTS::Text::trim(sResult.substr(start, end-start)); std::vector sFwSwitchValues = Text::split(sFwSwitchValue, ',', 2); if (sFwSwitchValues.size() >= 1) { sFwId = sFwSwitchValues[0]; } if(sFwId.size() == 0) { printWarning("%s| Firmware Image Number is empty", getName().c_str()); return FAILURE; } return SUCCESS; } TelitRadio::FOTA_GROUP LE910C4NFRadio::getFotaGroup() { return VALUE_GROUP_B; } CellularRadio::CODE LE910C4NFRadio::getIsVoiceSupportConfigurable() { CellularRadio::CODE rc; const std::string sCommand = "AT#CALLDISA=?"; rc = sendBasicCommand(sCommand); if (rc == ERROR) { printTrace("%s| This radio does not support voice call enable/disable", getName().c_str()); return NOT_APPLICABLE; } return rc; } CellularRadio::CODE LE910C4NFRadio::disableVoiceSupport() { printTrace("%s| Disable Voice Support", getName().c_str()); CellularRadio::CODE rc; rc = getIsVoiceSupportConfigurable(); if (rc != SUCCESS) { return rc; } const int dTimeout = 1000; // ms const std::string sCommand = "AT#CALLDISA=1,1"; return sendBasicCommand(sCommand, dTimeout); } CellularRadio::CODE LE910C4NFRadio::getVoiceSupport(bool& bVoiceEnabled, bool& bSmsOnly) { printTrace("%s| Get Voice Support", getName().c_str()); CellularRadio::CODE rc; bVoiceEnabled = false; bSmsOnly = false; rc = getIsVoiceSupportConfigurable(); if (rc != SUCCESS) { return rc; } const int dTimeout = 1000; // ms const std::string sCommand = "AT#CALLDISA?"; const std::string sLabel = "#CALLDISA: "; std::string sResult; rc = sendBasicQuery(sCommand, sLabel, sResult, dTimeout); if (rc != SUCCESS) { return rc; } std::vector vParts = MTS::Text::split(sResult, ','); if (vParts.size() != 2) { printError("Unexpected number of parameters in response [%s]", sResult.c_str()); return FAILURE; } /* * vParts[0] - value indicating that "voice support" is enabled. * Valid parameters: * 0 - Enable voice support * 1 - Disable voice support * 2 - Disable voice support (same as 1) * * vParts[1] - value indicating that "SMS only" registration flag is enabled. * Valid parameters: * 0 - Disable "SMS only" registration flag * 1 - Enable "SMS only" registration flag */ bVoiceEnabled = (vParts[0] == "0"); bSmsOnly = (vParts[1] == "1"); return SUCCESS; }