From dde61cb74828054f00518ca3b931f0b20009cc79 Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Mon, 5 Aug 2019 19:05:47 +0300 Subject: MTX-2898 mpower 2-3-4g: quectel methods for set-cellular-mode and common methods for get-cellular-mode --- src/MTS_IO_CellularRadio.cpp | 28 ++++++++++++++++++++++++++++ src/MTS_IO_EG95Radio.cpp | 21 +++++++++++---------- src/MTS_IO_TelitRadio.cpp | 17 ----------------- 3 files changed, 39 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index 3f0c037..e171341 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -770,6 +770,34 @@ ICellularRadio::CODE CellularRadio::getRegistration(REGISTRATION& eRegistration) return SUCCESS; } +ICellularRadio::CODE CellularRadio::getCellularMode(CELLULAR_MODES &networks) { + networks = CELLULAR_MODE_NA; + std::string cmdResult = sendCommand("AT+COPS?"); + if (cmdResult.find(ICellularRadio::RSP_OK) == std::string::npos) { + printDebug("%s| AT+COPS returned unexpected response: AT+COPS? [%s]", getName().c_str(), cmdResult.c_str()); + return FAILURE; + } + + size_t cursor = 0; + const std::vector &reply = MTS::Text::split(MTS::Text::getLine(MTS::Text::trim(cmdResult), cursor, cursor), ','); + uint8_t op; + if (reply.size() < 4 || !MTS::Text::parse(op, reply[3])) { + printDebug("Error parsing reply from AT+COPS"); + return FAILURE; + } + if (op == 0) { + networks = CELLULAR_MODE_2G; + } else if (op >= 2 && op <= 6) { + networks = CELLULAR_MODE_3G; + } else if (op == 7) { + networks = CELLULAR_MODE_4G; + } else { + printDebug("Error: AT+COPS unknown Radio Access Technology"); + return FAILURE; + } + return SUCCESS; +} + ICellularRadio::CODE CellularRadio::convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration) { ICellularRadio::CODE eCode = FAILURE; diff --git a/src/MTS_IO_EG95Radio.cpp b/src/MTS_IO_EG95Radio.cpp index 501a164..f934e50 100644 --- a/src/MTS_IO_EG95Radio.cpp +++ b/src/MTS_IO_EG95Radio.cpp @@ -24,6 +24,7 @@ #include #include +#include using namespace MTS::IO; @@ -55,27 +56,27 @@ ICellularRadio::CODE EG95Radio::getSupportedCellularModes(CELLULAR_MODES &networ return SUCCESS; } -ICellularRadio::CODE EG95Radio::getCellularMode(CELLULAR_MODES&) { - return FAILURE; -} - ICellularRadio::CODE EG95Radio::setCellularMode(CELLULAR_MODES networks) { std::string prefNet; + unsigned int prefOnly = 0; for (int i = sizeof(networks)*CHAR_BIT-1; i>=0; --i){ switch (1<