/*
* 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_CellularRadio.h"
#include <unistd.h>
#include <mts/MTS_IO_MccMncTable.h>
#include <mts/MTS_Thread.h>
#include <mts/MTS_Timer.h>
#include <mts/MTS_Logger.h>
#include <mts/MTS_Text.h>
using namespace MTS::IO;
namespace {
typedef struct
{
const char *name;
int32_t low;
int32_t high;
} *pNameRangeMap, nameRangeMap;
const unsigned int NUM_GSM_BANDS = 7;
const unsigned int NUM_WCDMA_BANDS = 6;
const unsigned int NUM_LTE_BANDS = 42;
// http://niviuk.free.fr/gsm_band.php
const nameRangeMap GSMband[] =
{
{"GSM 450", 259, 293}, {"GSM 480", 306, 340},
{"GSM 750", 438, 511}, {"GSM 850", 128, 251},
{"GSM 900 P", 1, 124}, {"GSM 900 E/R", 955, 1023},
{"GSM DCS 1800/1900", 512, 885},
};
// http://niviuk.free.fr/umts_band.php
const nameRangeMap WCDMAband[] =
{
{"BAND I", 10592, 10838}, {"BAND II", 9662, 9938},
{"BAND III", 1162, 1513}, {"BAND IV", 1537, 1738},
{"BAND V", 4357, 4458}, {"BAND VI", 4387, 4413}
};
// http://niviuk.free.fr/lte_band.php
const nameRangeMap EULTRAband[] =
{
{"EUTRAN BAND1", 0, 599}, {"EUTRAN BAND2", 600, 1199},
{"EUTRAN BAND3", 1200, 1949}, {"EUTRAN BAND4", 1950, 2399},
{"EUTRAN BAND5", 2400, 2649}, {"EUTRAN BAND6", 2650, 2749},
{"EUTRAN BAND7", 2750, 3449}, {"EUTRAN BAND8", 3450, 3799},
{"EUTRAN BAND9", 3800, 4149}, {"EUTRAN BAND10", 4150, 4749},
{"EUTRAN BAND11", 4750, 4999}, {"EUTRAN BAND12", 5000, 5179},
{"EUTRAN BAND13", 5180, 5279}, {"EUTRAN BAND14", 5280, 5379},
{"EUTRAN BAND17", 5730, 5849}, {"EUTRAN BAND18", 5850, 5999},
{"EUTRAN BAND19", 6000, 6149}, {"EUTRAN BAND20", 6150, 6449},
{"EUTRAN BAND21", 6450, 6525}, {"EUTRAN BAND22", 6600, 7399},
{"EUTRAN BAND23", 7500, 7699}, {"EUTRAN BAND24", 7700, 8039},
{"EUTRAN BAND25", 8040, 8689}, {"EUTRAN BAND26", 8690, 9039},
{"EUTRAN BAND27", 9040, 9209}, {"EUTRAN BAND28", 9210, 9659},
{"EUTRAN BAND29", 9660, 9769}, {"EUTRAN BAND30", 9770, 9869},
{"EUTRAN BAND31", 9870, 9919}, {"EUTRAN BAND32", 9920, 10359},
{"EUTRAN BAND33", 36000, 36199}, {"EUTRAN BAND34", 36200, 36349},
{"EUTRAN BAND35", 36350, 36949}, {"EUTRAN BAND36", 36950, 37549},
{"EUTRAN BAND37", 37550, 37749}, {"EUTRAN BAND38", 37750, 38249},
{"EUTRAN BAND39", 38250, 38649}, {"EUTRAN BAND40", 38650, 39649},
{"EUTRAN BAND41", 39650, 41589}, {"EUTRAN BAND42", 41590, 43589},
{"EUTRAN BAND43", 43590, 45589}, {"EUTRAN BAND44", 45590, 46589}
};
}
CellularRadio::CellularRadio(const std::string& sName, const std::string& sRadioPort)
: m_sName(sName)
, m_sRadioPort(sRadioPort)
, m_bEchoEnabled(false)
, m_bEnableEchoOnClose(false)
{
m_apIo.reset(new MTS::IO::SerialConnection(
MTS::IO::SerialConnection::Builder(m_sRadioPort)
.baudRate(115200)
.useLockFile()
.build()));
}
CellularRadio::~CellularRadio() {
shutdown();
m_apIo.reset();
}
bool CellularRadio::initialize(uint32_t iTimeoutMillis) {
if(!m_apIo->open(iTimeoutMillis)) {
printError("%s| Failed to open radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str());
return false;
}
bool bEnabled;
ICellularRadio::CODE eCode = getEcho(bEnabled);
if(eCode == SUCCESS && bEnabled) {
printDebug("%s| Disabling 'echo'", m_sName.c_str());
setEcho(false);
m_bEnableEchoOnClose = true;
}
return true;
}
bool CellularRadio::resetConnection(uint32_t iTimeoutMillis) {
//Close Current Connection
if(!m_apIo.isNull()) {
m_apIo->close();
}
m_apIo.reset(new MTS::IO::SerialConnection(
MTS::IO::SerialConnection::Builder(m_sRadioPort)
.
|