/* * 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace MTS::IO; CellularRadioFactory::CellularRadioFactory() { m_mCreationMap[HE910DRadio::MODEL_NAME] = &CellularRadioFactory::createHE910D; m_mCreationMap[HE910EUDRadio::MODEL_NAME] = &CellularRadioFactory::createHE910EUD; m_mCreationMap[LE910NAGRadio::MODEL_NAME] = &CellularRadioFactory::createLE910NAG; m_mCreationMap[LE910C4NFRadio::MODEL_NAME] = &CellularRadioFactory::createLE910C4NF; m_mCreationMap[LE910NA1Radio::MODEL_NAME] = &CellularRadioFactory::createLE910NA1; m_mCreationMap[LE910SVGRadio::MODEL_NAME] = &CellularRadioFactory::createLE910SVG; m_mCreationMap[LE910EUGRadio::MODEL_NAME] = &CellularRadioFactory::createLE910EUG; m_mCreationMap[LE910C4EURadio::MODEL_NAME] = &CellularRadioFactory::createLE910C4EU; m_mCreationMap[LE910EU1Radio::MODEL_NAME] = &CellularRadioFactory::createLE910EU1; m_mCreationMap[LE910C1NSRadio::MODEL_NAME] = &CellularRadioFactory::createLE910C1NS; m_mCreationMap[LE910C1APRadio::MODEL_NAME] = &CellularRadioFactory::createLE910C1AP; m_mCreationMap[ME910C1NARadio::MODEL_NAME] = &CellularRadioFactory::createME910C1NA; m_mCreationMap[ME910C1NVRadio::MODEL_NAME] = &CellularRadioFactory::createME910C1NV; m_mCreationMap[ME910C1WWRadio::MODEL_NAME] = &CellularRadioFactory::createME910C1WW; m_mCreationMap[GE910Radio::MODEL_NAME] = &CellularRadioFactory::createGE910; m_mCreationMap[DE910Radio::MODEL_NAME] = &CellularRadioFactory::createDE910; m_mCreationMap[CE910Radio::MODEL_NAME] = &CellularRadioFactory::createCE910; m_mCreationMap[LE866A1JSRadio::MODEL_NAME] = &CellularRadioFactory::createLE866A1JS; } MTS::IO::CellularRadio* CellularRadioFactory::create(const std::string& sModel, const std::string& sPort) { std::string model(sModel); if(model.size() == 0) { model = identifyRadio(sPort); } if(m_mCreationMap.count(model)) { //Call this object's function via a function pointer return (this->*m_mCreationMap[model])(sPort); } printWarning("[CELLULARRADIOFACTORY] Unknown radio [%s]. Attempting HE910 version.", model.c_str()); return new HE910DRadio(sPort); } std::string CellularRadioFactory::identifyRadio(const std::string& sPort) { MTS::AutoPtr apIo; //Attempt to open port to radio apIo.reset(new SerialConnection(SerialConnection::Builder(sPort).baudRate(115200).useLockFile().build())); while(!apIo->open(30000)) { printError("CellularRadioFactory| Failed to open radio port [%s]", sPort.c_str()); return CellularRadio::VALUE_UNKNOWN; } //Attempt basic radio communication if(CellularRadio::test(apIo) != CellularRadio::SUCCESS) { printError("CellularRadioFactory| Failed to communicate with radio on port [%s]", sPort.c_str()); apIo->close(); return CellularRadio::VALUE_UNKNOWN; } //Get model int count = 0; std::string sCmd("ATI4"); std::string sResult; do { sResult = CellularRadio::sendCommand(apIo, sCmd, CellularRadio::DEFAULT_BAIL_STRINGS, 1000, CellularRadio::CR); if (sResult.find("OK") == std::string::npos) { printDebug("RADIO| Attempting to get radio model [%s] ...", sResult.c_str()); } else { break; } count++; } while (count < 30); if(count == 30) { printDebug("RADIO| Unable to get radio model"); apIo->close(); return CellularRadio::VALUE_UNKNOWN; } std::string sModel = CellularRadio::extractModelFromResult(sResult); printDebug("RADIO| Extracted [%s] from ATI4 query", sModel.c_str()); apIo->close(); return sModel; } CellularRadio* CellularRadioFactory::createHE910D(const std::string& sPort) { return new HE910DRadio(sPort); } CellularRadio* CellularRadioFactory::createHE910EUD(const std::string& sPort) { return new HE910EUDRadio(sPort); } CellularRadio* CellularRadioFactory::createLE910NAG(const std::string& sPort) { return new LE910NAGRadio(sPort); } CellularRadio* CellularRadioFactory::createLE910C4NF(const std::string& sPort) { return new LE910C4NFRadio(sPort); } CellularRadio* CellularRadioFactory::createLE910NA1(const std::string& sPort) { return new LE910NA1Radio(sPort); } CellularRadio* CellularRadioFactory::createLE910SVG(const std::string& sPort) { return new LE910SVGRadio(sPort); } CellularRadio* CellularRadioFactory::createLE910EUG(const std::string& sPort) { return new LE910EUGRadio(sPort); } CellularRadio* CellularRadioFactory::createLE910C4EU(const std::string& sPort) { return new LE910C4EURadio(sPort); } CellularRadio* CellularRadioFactory::createLE910EU1(const std::string& sPort) { return new LE910EU1Radio(sPort); } CellularRadio* CellularRadioFactory::createLE910C1NS(const std::string& sPort) { return new LE910C1NSRadio(sPort); } CellularRadio* CellularRadioFactory::createLE910C1AP(const std::string& sPort) { return new LE910C1APRadio(sPort); } CellularRadio* CellularRadioFactory::createME910C1NA(const std::string& sPort) { return new ME910C1NARadio(sPort); } CellularRadio* CellularRadioFactory::createME910C1NV(const std::string& sPort) { return new ME910C1NVRadio(sPort); } CellularRadio* CellularRadioFactory::createME910C1WW(const std::string& sPort) { return new ME910C1WWRadio(sPort); } CellularRadio* CellularRadioFactory::createGE910(const std::string& sPort) { return new GE910Radio(sPort); } CellularRadio* CellularRadioFactory::createDE910(const std::string& sPort) { return new DE910Radio(sPort); } CellularRadio* CellularRadioFactory::createCE910(const std::string& sPort) { return new CE910Radio(sPort); } CellularRadio* CellularRadioFactory::createLE866A1JS(const std::string &sPort) { return new LE866A1JSRadio(sPort); }