/*
* Copyright (C) 2015 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/>.
*
*/
/*!
\file MTS_IO_CdmaRadio.cpp
\brief A brief description
\date Nov 19, 2014
\author sgodinez
A more elaborate description
*/
#include <mts/MTS_IO_CdmaRadio.h>
#include <mts/MTS_Text.h>
#include <mts/MTS_Logger.h>
#include <mts/MTS_Thread.h>
using namespace MTS::IO;
CdmaRadio::CdmaRadio(const std::string& sName, const std::string& sPort)
: TelitRadio(sName, sPort)
{
}
CdmaRadio::~CdmaRadio() {
}
ICellularRadio::CODE CdmaRadio::getImei(std::string& sImei) {
printTrace("%s| Get IMEI", getName().c_str());
return getMeid(sImei);
}
ICellularRadio::CODE CdmaRadio::getMeid(std::string& sMeid) {
printTrace("%s| Get MEID", getName().c_str());
sMeid = ICellularRadio::VALUE_NOT_SUPPORTED;
std::string sCmd("AT#MEIDESN?");
std::string sResult = sendCommand(sCmd);
size_t pos = sResult.find(ICellularRadio::RSP_OK);
if (pos == std::string::npos) {
printWarning("%s| Unable to get MEID from radio using command [%s]", getName().c_str(), sCmd.c_str());
return FAILURE;
}
size_t start = sResult.find("#MEIDESN:") + sizeof("#MEIDESN:");
size_t stop = sResult.find(",");
if(stop != std::string::npos && stop > start) {
sMeid = sResult.substr(start, stop - start);
} else {
return FAILURE;
}
return SUCCESS;
}
ICellularRadio::CODE CdmaRadio::getMsid(std::string& sMsid) {
printTrace("%s| Get MSID", getName().c_str());
sMsid = ICellularRadio::VALUE_NOT_SUPPORTED;
std::string sCmd("AT$MSID?");
std::string sResult = sendCommand(sCmd);
size_t end = sResult.find(ICellularRadio::RSP_OK);
if (end == std::string::npos) {
printWarning("%s| Unable to get MSID from radio using command [%s]", getName().c_str(), sCmd.c_str());
return FAILURE;
}
size_t start = sResult.find("$MSID:") + sizeof("$MSID:");
sMsid = MTS::Text::trim(sResult.substr(start, end-start));
if(sMsid.size() == 0) {
printWarning("%s| MSID is empty", getName().c_str());
}
return SUCCESS;
}
ICellularRadio::CODE CdmaRadio::getCarrier(std::string& sCarrier) {
if(m_sCarrier != "") {
sCarrier = m_sCarrier;
return SUCCESS;
}
std::string sFirmware;
ICellularRadio::CODE code = getFirmware(sFirmware);
if(code != SUCCESS) {
return code;
}
if(!getCarrierFromFirmware(sFirmware, sCarrier)) {
return FAILURE;
}
m_sCarrier = sCarrier;
return SUCCESS;
}
ICellularRadio::CODE CdmaRadio::getNetwork(std::string& sNetwork) {
return getCarrier(sNetwork);
}
ICellularRadio::CODE CdmaRadio::getSimStatus(std::string& sSimStatus) {
printTrace("%s| Get SIM Status", getName().c_str());
sSimStatus = ICellularRadio::VALUE_NOT_SUPPORTED;
return NOT_APPLICABLE;
}
ICellularRadio::CODE CdmaRadio::getIccid(std::string& sIccid) {
printTrace("%s| Get ICCID", getName().c_str());
sIccid = ICellularRadio::VALUE_NOT_SUPPORTED;
return NOT_APPLICABLE;
}
ICellularRadio::CODE CdmaRadio::getLac(std::string& sLac) {
printTrace("%s| Get LAC", getName().c_str());
sLac = ICellularRadio::VALUE_NOT_SUPPORTED;
return NOT_APPLICABLE;
}
ICellularRadio::CODE CdmaRadio::getService(std::string& sService) {
printTrace("%s| Get Service", getName().c_str());
sService = ICellularRadio::
|