diff options
| author | Maksym Telychko <maksym.telychko@globallogic.com> | 2019-06-08 00:23:57 +0300 |
|---|---|---|
| committer | Maksym Telychko <maksym.telychko@globallogic.com> | 2019-06-08 00:23:57 +0300 |
| commit | 596f8f8393bf837d73e0a62c87d52557d9191f96 (patch) | |
| tree | 0bd5ed794ed423b18aeade28b4f3ffd13d0d0e84 | |
| parent | 9f1b5b16547536196dde8e9296debbae924bfb2c (diff) | |
| download | libmts-io-596f8f8393bf837d73e0a62c87d52557d9191f96.tar.gz libmts-io-596f8f8393bf837d73e0a62c87d52557d9191f96.tar.bz2 libmts-io-596f8f8393bf837d73e0a62c87d52557d9191f96.zip | |
[MTS-MTQ] refactoring: telit radio implementation
leave telit specific code in telit class.
move common code to cellular radio class.
| -rw-r--r-- | include/mts/MTS_IO_CellularRadio.h | 154 | ||||
| -rw-r--r-- | include/mts/MTS_IO_ICellularRadio.h | 2 | ||||
| -rw-r--r-- | include/mts/MTS_IO_TelitRadio.h | 290 | ||||
| -rw-r--r-- | src/MTS_IO_CellularRadio.cpp | 1299 | ||||
| -rw-r--r-- | src/MTS_IO_TelitRadio.cpp | 1170 |
5 files changed, 1504 insertions, 1411 deletions
diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index 1378612..e79e6d1 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -29,17 +29,165 @@ #ifndef MTS_IO_CELLULARRADIO_H_ #define MTS_IO_CELLULARRADIO_H_ +#include <string> +#include <vector> + +#include <json/json.h> + #include <mts/MTS_IO_ICellularRadio.h> +#include <mts/MTS_IO_SerialConnection.h> +#include <mts/MTS_NonCopyable.h> +#include <mts/MTS_AutoPtr.h> +#include <mts/MTS_Stdint.h> namespace MTS { namespace IO { - class CellularRadio : public ICellularRadio { + public: + const std::string& getName() const override; + + ~CellularRadio() override; + + bool initialize(uint32_t iTimeoutMillis = 5000) override; + bool resetConnection(uint32_t iTimeoutMillis = 5000) override; + void shutdown() override; + + CODE getFirmware(std::string& sFirmware) override; + CODE getFirmwareBuild(std::string& sFirmwareBuild) override; + CODE getHardware(std::string& sHardware) override; + CODE getManufacturer(std::string& sManufacturer) override; + CODE getImei(std::string& sImei) override; + CODE getMeid(std::string& sMeid) override; + CODE getImsi(std::string& sImsi) override; + CODE getSimStatus(std::string& sSimStatus) override; + CODE getLac(std::string& sLac) override; + CODE getMdn(std::string& sMdn) override; + CODE getMsid(std::string& sMsid) override; + CODE getType(std::string& sType) override; + CODE getCarrier(std::string& sCarrier) override; + CODE getNetwork(std::string& sNetwork) override; + CODE getTower(std::string& sTower) override; + CODE getTime(std::string& sDate, std::string& sTime, std::string& sTimeZone) override; + CODE getRoaming(bool& bRoaming) override; + + CODE getSignalStrength(int32_t& iRssi) override; + CODE getModemLocation(std::string& sLocation) override; + CODE convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& dBm) override; + CODE convertdBmToSignalStrength(const int32_t& dBm, int32_t& iRssi) override; + + CODE getRegistration(REGISTRATION& eRegistration) override; + CODE convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration) override; + CODE getMipProfile(Json::Value& jMipProfile) override; + CODE validateMsl(const Json::Value& jArgs) override; + CODE setMsid(const Json::Value& jArgs) override; + CODE setMipActiveProfile(const Json::Value& jArgs) override; + CODE setMipNai(const Json::Value& jArgs) override; + CODE setMipHomeIp(const Json::Value& jArgs) override; + CODE setMipPrimaryHa(const Json::Value& jArgs) override; + CODE setMipSecondaryHa(const Json::Value& jArgs) override; + CODE setMipMnAaaSpi(const Json::Value& jArgs) override; + CODE setMipMnHaSpi(const Json::Value& jArgs) override; + CODE setMipRevTun(const Json::Value& jArgs) override; + CODE setMipMnAaaSs(const Json::Value& jArgs) override; + CODE setMipMnHaSs(const Json::Value& jArgs) override; + CODE updateDc(const Json::Value& jArgs, UpdateCb& stepCb) override; + CODE updatePrl(const Json::Value& jArgs, UpdateCb& stepCb) override; + CODE updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) override; + CODE resetHfa(const Json::Value& jArgs, UpdateCb& stepCb) override; + CODE activate(const Json::Value& jArgs, UpdateCb& stepCb) override; + CODE setActiveFirmware(const Json::Value& jArgs) override; + CODE getActiveFirmware(std::string& sFwId) override; + CODE getEcho(bool& bEnabled) override; + CODE setEcho(bool bEnabled = true) override; + CODE getStaticInformation(Json::Value& jData) override; + CODE sendBasicCommand(const std::string& sCmd, int32_t timeoutMillis = 100, const char& ESC = CR) override; + + std::string sendCommand(const std::string& sCmd, + const std::vector<std::string>& vBail = DEFAULT_BAIL_STRINGS, + int32_t timeoutMillis = 100, + const char& ESC = CR) override; + + + static std::string sendCommand(MTS::AutoPtr<MTS::IO::Connection>& apIo, + const std::string& sCmd, + const std::vector<std::string>& vBail = DEFAULT_BAIL_STRINGS, + int32_t timeoutMillis = 100, + const char& ESC = CR); + + std::string sendCommand(const std::string& sCmd, + IsNeedMoreData& isNeedMoreData, + int32_t timeoutMillis = 100, + const char& ESC = CR) override; + + static std::string sendCommand(MTS::AutoPtr<MTS::IO::Connection>& apIo, + const std::string& sCmd, + IsNeedMoreData& isNeedMoreData, + int32_t timeoutMillis = 100, + const char& ESC = CR); + + static CODE test(MTS::AutoPtr<MTS::IO::Connection>& apIo, uint32_t timeoutSeconds = 30); + + static std::string extractModelFromResult(const std::string& sResult); + static std::string getCodeAsString(CODE code); + + protected: + + CellularRadio(const std::string& sName, const std::string& sRadioPort); + + virtual bool getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier); + virtual bool getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware); + virtual void getCommonNetworkStats(Json::Value& jData); + void initMipProfile(Json::Value& jData); + bool splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType = Json::ValueType::stringValue); + + class RadioBandMap : public MTS::NonCopyable { + public: + RadioBandMap() + { + m_sChannel = CellularRadio::VALUE_UNKNOWN; + m_iChannel = 0; + m_sRadioType = CellularRadio::VALUE_UNKNOWN; + } + + RadioBandMap(const std::string &channel, const std::string &radioType) : + m_sChannel(channel), + m_sRadioType(radioType) + { + m_iChannel = strtol(m_sChannel.c_str(), NULL, 10); + } + + virtual ~RadioBandMap() {} + + const char *getRadioBandName(); + const char *getRadioBandName(const std::string &channel, const std::string &radioType); + + private: + + const char *getLTEBand(const int channel); + const char *getCDMABand(const int channel); + const char *getGSMBand(const int channel); + + std::string m_sChannel; + int m_iChannel; + std::string m_sRadioType; + }; + + private: + std::string m_sName; + std::string m_sRadioPort; + std::string m_sFirmware; + std::string m_sCarrier; + MTS::AutoPtr<MTS::IO::Connection> m_apIo; + + bool m_bEchoEnabled; + bool m_bEnableEchoOnClose; + + std::string queryLteLac(); + std::string queryCGREGstring(); + void setCGREG(std::string value); }; } } - - #endif /* MTS_IO_CELLULARRADIO_H_ */ diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h index d954a24..ff8383c 100644 --- a/include/mts/MTS_IO_ICellularRadio.h +++ b/include/mts/MTS_IO_ICellularRadio.h @@ -360,7 +360,6 @@ namespace MTS { virtual CODE getStaticInformation(Json::Value& jData) = 0; virtual CODE getNetworkStatus(Json::Value& jData) = 0; - /* virtual CODE sendBasicCommand(const std::string& sCmd, int32_t timeoutMillis = 100, const char& ESC = CR) = 0; virtual std::string sendCommand(const std::string& sCmd, @@ -372,7 +371,6 @@ namespace MTS { IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis = 100, const char& ESC = CR) = 0; - */ }; } diff --git a/include/mts/MTS_IO_TelitRadio.h b/include/mts/MTS_IO_TelitRadio.h index 621bfb4..0c95f98 100644 --- a/include/mts/MTS_IO_TelitRadio.h +++ b/include/mts/MTS_IO_TelitRadio.h @@ -21,305 +21,31 @@ #ifndef MTS_IO_TELITRADIO_H_ #define MTS_IO_TELITRADIO_H_ -#include <string> -#include <vector> - -#include <json/json.h> - #include <mts/MTS_IO_CellularRadio.h> -#include <mts/MTS_IO_SerialConnection.h> -#include <mts/MTS_NonCopyable.h> -#include <mts/MTS_AutoPtr.h> -#include <mts/MTS_Stdint.h> namespace MTS { namespace IO { class TelitRadio : public CellularRadio { - public: - virtual ~TelitRadio(); - - virtual bool initialize(uint32_t iTimeoutMillis = 5000); - virtual bool resetRadio(uint32_t iTimeoutMillis = 5000); - virtual bool resetConnection(uint32_t iTimeoutMillis = 5000); - virtual void shutdown(); - - const std::string& getName() const; - - virtual CODE getModel(std::string& sModel); - - virtual CODE getFirmware(std::string& sFirmware); - virtual CODE getFirmwareBuild(std::string& sFirmwareBuild); - virtual CODE getHardware(std::string& sHardware); - virtual CODE getManufacturer(std::string& sManufacturer); - virtual CODE getImei(std::string& sImei); - virtual CODE getMeid(std::string& sMeid); - virtual CODE getImsi(std::string& sImsi); - virtual CODE getSimStatus(std::string& sSimStatus); - virtual CODE getIccid(std::string& sIccid); - virtual CODE getService(std::string& sService); - virtual CODE getLac(std::string& sLac); - virtual CODE getMdn(std::string& sMdn); - virtual CODE getMsid(std::string& sMsid); - virtual CODE getType(std::string& sType); - virtual CODE getCarrier(std::string& sCarrier); - virtual CODE getNetwork(std::string& sNetwork); - virtual CODE getTower(std::string& sTower); - virtual CODE getTime(std::string& sDate, std::string& sTime, std::string& sTimeZone); - virtual CODE getRoaming(bool& bRoaming); - - virtual CODE getSignalStrength(int32_t& iRssi); - virtual CODE getModemLocation(std::string& sLocation); - virtual CODE convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& dBm); - virtual CODE convertdBmToSignalStrength(const int32_t& dBm, int32_t& iRssi); - - virtual CODE getRegistration(REGISTRATION& eRegistration); - virtual CODE convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration); - - //! Gather details of the radio's Mobile IP Profile - /*! - \param Json::Value object that will be populated with MIP data - \return Returns result code of gathering MIP - */ - virtual CODE getMipProfile(Json::Value& jMipProfile); - - /* - * jArgs = { - * "msl" : "Master Subsidy Lock (Aeris, Sprint): STRING" - * } - */ - virtual CODE validateMsl(const Json::Value& jArgs); - - /* - * jArgs = { - * "mdn" : "Mobile Directory Number : STRING", - * "msl" : "[OPTIONAL] Master Subsidy Lock (Aeris, Sprint): STRING" - * } - */ - virtual CODE setMdn(const Json::Value& jArgs); - - /* - * jArgs = { - * "msid" : "Mobil Station ID (MSID) aka MIN aka MSIN : STRING", - * "msl" : "[OPTIONAL] Master Subsidy Lock (Aeris, Sprint): STRING" - * } - */ - virtual CODE setMsid(const Json::Value& jArgs); - - /* - * jArgs = { - * "activeProfile" : "Set active profile: STRING" - * } - */ - virtual CODE setMipActiveProfile(const Json::Value& jArgs); - - /* - * jArgs = { - * "nai" : "Network Access Identifier : STRING" - * } - */ - virtual CODE setMipNai(const Json::Value& jArgs); - - /* - * jArgs = { - * "homeIp" : "Home Address : STRING" - * } - */ - virtual CODE setMipHomeIp(const Json::Value& jArgs); - - /* - * jArgs = { - * "primaryHa" : "Primary Home Agent : STRING" - * } - */ - virtual CODE setMipPrimaryHa(const Json::Value& jArgs); - - /* - * jArgs = { - * "secondaryHa" : "Secondary Home Agent : STRING" - * } - */ - virtual CODE setMipSecondaryHa(const Json::Value& jArgs); - - /* - * jArgs = { - * "mnAaaSpi" : "Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index : STRING" - * } - */ - virtual CODE setMipMnAaaSpi(const Json::Value& jArgs); - - /* - * jArgs = { - * "mnHaSpi" : "Mobile Node Home Agent Security Server Parameter Index : STRING" - * } - */ - virtual CODE setMipMnHaSpi(const Json::Value& jArgs); - - /* - * jArgs = { - * "revTun" : "[DESCRIPTION] : STRING" - * } - */ - virtual CODE setMipRevTun(const Json::Value& jArgs); - - /* - * jArgs = { - * "mnAaaSs" : "Mobile Node Authentication, Authorization, and Accounting Server Shared Secret : STRING" - * } - */ - virtual CODE setMipMnAaaSs(const Json::Value& jArgs); - - /* - * jArgs = { - * "mnHaSs" : "Mobile Node Home Agent Shared Secret : STRING" - * } - */ - virtual CODE setMipMnHaSs(const Json::Value& jArgs); - - /* - * jArgs = null - */ - virtual CODE updateDc(const Json::Value& jArgs, UpdateCb& stepCb); - - /* - * jArgs = null - */ - virtual CODE updatePrl(const Json::Value& jArgs, UpdateCb& stepCb); - - /* - * jArgs = null - */ - virtual CODE updateFumo(const Json::Value& jArgs, UpdateCb& stepCb); - - /* - * jArgs = { - * "msl" : "Master Subsidy Lock (Sprint): STRING" - * } - */ - virtual CODE resetHfa(const Json::Value& jArgs, UpdateCb& stepCb); - - /* - * jArgs = { - * "mdn" : "Mobile Directory Number (Aeris): STRING" - * "msid" : "Mobile Station ID (Aeris): STRING" - * } - */ - virtual CODE activate(const Json::Value& jArgs, UpdateCb& stepCb); + bool resetRadio(uint32_t iTimeoutMillis = 5000) override; - /* - * jArgs = { - * "enabled" : "RX Diversity Enabled ("0" or "1"): STRING" - * } - */ - virtual CODE setRxDiversity(const Json::Value& jArgs)=0; - /* - * jArgs = { - * "fwid" : "Firmware Image To Be Enabled: STRING" - * } - */ - virtual CODE setActiveFirmware(const Json::Value& jArgs); - virtual CODE getActiveFirmware(std::string& sFwId); - - virtual CODE getEcho(bool& bEnabled); - virtual CODE setEcho(bool bEnabled = true); - - virtual CODE getStaticInformation(Json::Value& jData); - virtual CODE getNetworkStatus(Json::Value& jData); - - virtual CODE sendBasicCommand(const std::string& sCmd, int32_t timeoutMillis = 100, const char& ESC = CR); - - virtual std::string sendCommand(const std::string& sCmd, - const std::vector<std::string>& vBail = DEFAULT_BAIL_STRINGS, - int32_t timeoutMillis = 100, - const char& ESC = CR); - - - static std::string sendCommand(MTS::AutoPtr<MTS::IO::Connection>& apIo, - const std::string& sCmd, - const std::vector<std::string>& vBail = DEFAULT_BAIL_STRINGS, - int32_t timeoutMillis = 100, - const char& ESC = CR); - - virtual std::string sendCommand(const std::string& sCmd, - IsNeedMoreData& isNeedMoreData, - int32_t timeoutMillis = 100, - const char& ESC = CR); - - static std::string sendCommand(MTS::AutoPtr<MTS::IO::Connection>& apIo, - const std::string& sCmd, - IsNeedMoreData& isNeedMoreData, - int32_t timeoutMillis = 100, - const char& ESC = CR); - - static CODE test(MTS::AutoPtr<MTS::IO::Connection>& apIo, uint32_t timeoutSeconds = 30); - - static std::string extractModelFromResult(const std::string& sResult); - static std::string getCodeAsString(CODE code); + CODE getModel(std::string& sModel) override; + CODE getIccid(std::string& sIccid) override; + CODE getService(std::string& sService) override; + CODE getNetworkStatus(Json::Value& jData) override; + CODE setMdn(const Json::Value& jArgs) override; protected: - TelitRadio(const std::string& sName, const std::string& sRadioPort); - virtual bool getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier); - virtual bool getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware); - - virtual void getCommonNetworkStats(Json::Value& jData); - - void initMipProfile(Json::Value& jData); - - bool splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType = Json::ValueType::stringValue); - - + bool getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier) override; + bool getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware) override; private: - class RadioBandMap : public MTS::NonCopyable { - public: - RadioBandMap() - { - m_sChannel = TelitRadio::VALUE_UNKNOWN; - m_iChannel = 0; - m_sRadioType = TelitRadio::VALUE_UNKNOWN; - } - - RadioBandMap(const std::string &channel, const std::string &radioType) : - m_sChannel(channel), - m_sRadioType(radioType) - { - m_iChannel = strtol(m_sChannel.c_str(), NULL, 10); - } - - virtual ~RadioBandMap() {} - - const char *getRadioBandName(); - const char *getRadioBandName(const std::string &channel, const std::string &radioType); - - private: - - const char *getLTEBand(const int channel); - const char *getCDMABand(const int channel); - const char *getGSMBand(const int channel); - - std::string m_sChannel; - int m_iChannel; - std::string m_sRadioType; - }; - - std::string m_sName; - std::string m_sRadioPort; - std::string m_sFirmware; - std::string m_sCarrier; - MTS::AutoPtr<MTS::IO::Connection> m_apIo; - - bool m_bEchoEnabled; - bool m_bEnableEchoOnClose; - std::string queryLteLac(); std::string queryCGREGstring(); void setCGREG(std::string value); }; } } - - - #endif diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index a29d14f..840132f 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -19,3 +19,1302 @@ */ #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; + 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) + .baudRate(115200) + .useLockFile() + .build())); + + //Try to obtain the device port over the given period of time + MTS::Timer oTimer; + oTimer.start(); + uint64_t iCurrentTime = 0; + while(iCurrentTime < iTimeoutMillis) { + + if(!m_apIo->open(iTimeoutMillis - iCurrentTime)) { + printWarning("%s| Failed to re-open radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str()); + } else { + printInfo("%s| Successfully re-opened radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str()); + printDebug("%s| Recovering 'echo' after connection reset", m_sName.c_str()); // see CellularRadio::initialize + setEcho(m_bEchoEnabled); + break; + } + + ::usleep(500000); //500 millis + iCurrentTime = oTimer.getMillis(); + } + oTimer.stop(); + return !m_apIo->isClosed(); +} + +void CellularRadio::shutdown() { + + if(!m_apIo.isNull()) { + if(m_bEnableEchoOnClose) { + printDebug("%s| Enabling 'echo'", m_sName.c_str()); + setEcho(true); + m_bEnableEchoOnClose = false; + } + m_apIo->close(); + } +} + +const std::string& CellularRadio::getName() const { + return m_sName; +} + +CellularRadio::CODE CellularRadio::getFirmware(std::string& sFirmware) { + printTrace("%s| Get Firmware", m_sName.c_str()); + sFirmware = VALUE_NOT_SUPPORTED; + std::string sCmd("AT+CGMR"); + std::string sResult = sendCommand(sCmd); + size_t pos = sResult.find(RSP_OK); + if (pos == std::string::npos) { + printWarning("%s| Unable to get firmware from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + sFirmware = MTS::Text::trim(sResult.substr(0, pos)); + if(sFirmware.size() == 0) { + printWarning("%s| Unable to get firmware from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + m_sFirmware = sFirmware; + + return SUCCESS; +} + +CellularRadio::CODE CellularRadio::getFirmwareBuild(std::string& sFirmwareBuild) { + sFirmwareBuild = VALUE_NOT_SUPPORTED; + return FAILURE; +} + +CellularRadio::CODE CellularRadio::getHardware(std::string& sHardware) { + printTrace("%s| Get Hardware", m_sName.c_str()); + sHardware = VALUE_NOT_SUPPORTED; + + if(m_sFirmware.size() == 0) { + getFirmware(m_sFirmware); + } + + if(getHardwareVersionFromFirmware(m_sFirmware, sHardware)) { + return SUCCESS; + } + return FAILURE; +} + +CellularRadio::CODE CellularRadio::getManufacturer(std::string& sManufacturer) { + printTrace("%s| Get Manufacturer", m_sName.c_str()); + sManufacturer = VALUE_NOT_SUPPORTED; + std::string sCmd("AT+GMI"); + std::string sResult = sendCommand(sCmd); + size_t pos = sResult.find(RSP_OK); + if (pos == std::string::npos) { + printWarning("%s| Unable to get manufacturer from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + sManufacturer = MTS::Text::trim(sResult.substr(0, pos)); + if(sManufacturer.size() == 0) { + printWarning("%s| Unable to get manufacturer from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + return SUCCESS; +} + +CellularRadio::CODE CellularRadio::getImei(std::string& sImei) { + printTrace("%s| Get IMEI", m_sName.c_str()); + sImei = VALUE_NOT_SUPPORTED; + std::string sCmd("AT+CGSN"); + std::string sResult = sendCommand(sCmd); + size_t pos = sResult.find(RSP_OK); + if (pos == std::string::npos) { + printWarning("%s| Unable to get IMEI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + sImei = MTS::Text::trim(sResult.substr(0, pos)); + if(sImei.size() == 0) { + printWarning("%s| Unable to get IMEI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + return SUCCESS; +} + +CellularRadio::CODE CellularRadio::getMeid(std::string& sMeid) { + printTrace("%s| Get MEID", m_sName.c_str()); + return getImei(sMeid); +} + +CellularRadio::CODE CellularRadio::getImsi(std::string& sImsi) { + printTrace("%s| Get IMSI", m_sName.c_str()); + sImsi = VALUE_NOT_SUPPORTED; + std::string sCmd("AT+CIMI"); + std::string sResult = sendCommand(sCmd); + size_t pos = sResult.find(RSP_OK); + if (pos == std::string::npos) { + printWarning("%s| Unable to get IMSI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + sImsi = MTS::Text::trim(sResult.substr(0, pos)); + if(sImsi.size() == 0) { + printWarning("%s| Unable to get IMSI from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + return SUCCESS; +} + +CellularRadio::CODE CellularRadio::getSimStatus(std::string& sSimStatus) { + printTrace("%s| Get SIM Status", getName().c_str()); + sSimStatus = VALUE_UNKNOWN; + return FAILURE; +} + +CellularRadio::CODE CellularRadio::getLac(std::string& sLac) { + Json::Value jData; + + printTrace("%s| Get LAC", m_sName.c_str()); + sLac = VALUE_NOT_SUPPORTED; + + if(getNetworkStatus(jData) == SUCCESS) { + if(jData.isMember(KEY_LAC)) { + sLac = jData[KEY_LAC].asString(); + return SUCCESS; + } + } + + return FAILURE; +} + +CellularRadio::CODE CellularRadio::getMdn(std::string& sMdn) { + printTrace("%s| Get MDN", m_sName.c_str()); + sMdn = VALUE_NOT_SUPPORTED; + std::string sCmd("AT+CNUM"); + std::string sResult = sendCommand(sCmd); + size_t end = sResult.find(RSP_OK); + if (end == std::string::npos) { + printWarning("%s| Unable to get MDN from radio using command [%s]", m_sName.c_str(), sCmd.c_str()); + return FAILURE; + } + + size_t start = sResult.find("CNUM:"); + if(start != std::string::npos) { + start += sizeof("CNUM:"); + std::vector<std::string> vParts = MTS::Text::split(sResult.substr(start, end - start), ','); + if(vParts.size() < 3) { + printWarning("%s| Unable to parse MDN from response [%s]", m_sName.c_str(), sResult.c_str()); + return FAILURE; + } + sMdn = MTS::Text::strip(vParts[1], '"'); + if(sMdn.size() == 0) { + printWarning("%s| Unable to get MDN from radio using command [%s]. MDN may not be set.", m_sName.c_str(), sCmd.c_str()); + } + } else { + sMdn = ""; + printWarning("%s| Unable to get MDN from radio using command [%s]. MDN may not be set.", m_sName.c_str(), sCmd.c_str()); + } + + return SUCCESS; +} + +CellularRadio::CODE CellularRadio::getMsid(std::string& sMsid) { + printTrace("%s| Get MSID", m_sName.c_str()); + sMsid = ""; + + std::string sImsi; + if(getImsi(sImsi) == SUCCESS) { + if(sImsi.size() >= 10) { + sMsid = sImsi.substr(sImsi.size() - 10); + printTrace("IMSI: [%s] MEID [%s]", sImsi.c_str(), sMsid.c_str()); + return SUCCESS; + } + } + printWarning("%s| Unable to get MSID from radio", m_sName.c_str()); + return FAILURE; +} + +CellularRadio::CODE CellularRadio::getType(std::string& sType) { + printTrace("%s| Get Type", m_sName.c_str()); + sType = VALUE_NOT_SUPPORTED; + return FAILURE; +} + +CellularRadio::CODE CellularRadio::getCarrier(std::string& sCarrier) { + printTrace("%s| Get Carrier", m_sName.c_str()); + if(m_sCarrier == "") { + Json::Value jData; + if(getNetworkStatus(jData) == SUCCESS) { + if(jData.isMember(KEY_MCC) && jData.isMember(KEY_MNC)) { + std::string sMcc = jData[KEY_MCC].asString(); + std::string sMnc = jData[KEY_MNC].asString(); + Json::Value jLookup = MccMncTable::getInstance()->lookup(sMcc, sMnc); + printTrace("%s| MCC-MNC Lookup: [%s][%s][%s]", m_sName.c_str(), + sMcc.c_str(), sMnc.c_str(), jLookup.toStyledString().c_str()); + if(jLookup.isMember(KEY_CARRIER)) { + m_sCarrier = jLookup[KEY_CARRIER].asString(); + } else { + printWarning("%s| MCC-MNC Lookup did not contain carrier", m_sName.c_str()); + return FAILURE; + } + } else { + printWarning("%s| Network Status did no contain MCC or MNC", m_sName.c_str()); + return FAILURE; + } + } else { + return FAILURE; + |
