/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#include "mts/MTS_IO_QuectelRadio.h"
#include <climits>
#include <mts/MTS_Logger.h>
#include <mts/MTS_Thread.h>
#include <mts/MTS_Text.h>
#include <mts/MTS_Timer.h>
#include <unistd.h>
using namespace MTS::IO;
const size_t QuectelRadio::FILE_CHUNK_SIZE = 2048;
const std::string QuectelRadio::CMD_ABORT_UPLOAD = "+++";
// It is strongly recommended to use DOS 8.3 file name format for <filename>.
const std::string QuectelRadio::VALUE_MTS_DELTA_NAME = "mtsdelta.zip";
const std::string QuectelRadio::VALUE_MTS_DELTA_PATH = "/data/ufs/" + QuectelRadio::VALUE_MTS_DELTA_NAME;
QuectelRadio::QuectelRadio(const std::string& sName, const std::string& sRadioPort)
: CellularRadio (sName, sRadioPort)
{
}
bool QuectelRadio::resetRadio(uint32_t iTimeoutMillis) {
printInfo("%s| Rebooting radio", getName().c_str());
if(sendBasicCommand("AT+CFUN=1,1") == SUCCESS) {
if(iTimeoutMillis > 5000) {
MTS::Thread::sleep(5000);
iTimeoutMillis -= 5000;
}
return resetConnection(iTimeoutMillis);
}
return false;
}
ICellularRadio::CODE QuectelRadio::getVendorFirmware(std::string& sVendorFirmware) {
printTrace("%s| Get Quectel-specific firmware version", getName().c_str());
sVendorFirmware = ICellularRadio::VALUE_NOT_SUPPORTED;
std::string sCmd("AT+QGMR");
std::string sResult = sendCommand(sCmd);
size_t pos = sResult.find(ICellularRadio::RSP_OK);
if (pos == std::string::npos) {
printWarning("%s| Unable to get firmware from radio using command [%s]", getName().c_str(), sCmd.c_str());
return FAILURE;
}
sVendorFirmware = MTS::Text::trim(sResult.substr(0, pos));
if(sVendorFirmware.size() == 0) {
printWarning("%s| Unable to get firmware from radio using command [%s]", getName().c_str(), sCmd.c_str());
return FAILURE;
}
return SUCCESS;
}
ICellularRadio::CODE QuectelRadio::getModel(std::string& sModel) {
printTrace("%s| Get Model", getName().c_str());
//Always returns SUCCESS because the model should be m_sName
sModel = getName();
std::string sCmd("AT+GMM");
std::string sResult = sendCommand(sCmd);
if (sResult.find("OK") == std::string::npos) {
printWarning("%s| Unable to get model from radio. Returning [%s]", getName().c_str(), getName().c_str());
return SUCCESS;
} else {
sModel = extractModelFromResult(sResult);
if(sModel.size() == 0) {
printWarning("%s| Unable to get model from radio. Returning [%s]", getName().c_str(), getName().c_str());
return SUCCESS;
}
}
printDebug("%s| Extracted [%s] from [%s] query", getName().c_str(), sModel.c_str(), sCmd.c_str());
if(sModel != getName()) {
printWarning("%s| Model identified [%s] does not match expected [%s]. Returning [%s]",
getName().c_str(), sModel.c_str(), getName().c_str(), sModel.c_str());
}
return SUCCESS;
}
ICellularRadio::CODE QuectelRadio::getIccid(std:
|