diff options
author | Jeff Hatch <jhatch@multitech.com> | 2019-08-13 08:02:45 -0500 |
---|---|---|
committer | Jeff Hatch <jhatch@multitech.com> | 2019-08-13 08:02:45 -0500 |
commit | c01246193e111a6be14449278281ab58865a7123 (patch) | |
tree | d959b371bc508ab4743761d6126c5142ee420767 | |
parent | b0d99ce30902aa70969696846107c65310309bc3 (diff) | |
parent | f7ed3b6a0c21a9345a2d1707c77be4212b03c385 (diff) | |
download | radio-cmd-c01246193e111a6be14449278281ab58865a7123.tar.gz radio-cmd-c01246193e111a6be14449278281ab58865a7123.tar.bz2 radio-cmd-c01246193e111a6be14449278281ab58865a7123.zip |
Merge branch 'MTX-2891-mpower-2g-3g-4g' into 'master'
0.6
Mtx 2891 mpower 2g 3g 4g
See merge request !3
-rw-r--r-- | main.cpp | 81 |
1 files changed, 38 insertions, 43 deletions
@@ -66,8 +66,8 @@ std::string g_sRxDiversity; std::string g_sActiveFirmware; std::string g_sConfigFile; Json::Value g_jData; -std::string g_sRadioMode; std::string g_sSimPin; +std::string g_sCellularMode; MTS::AutoPtr<MTS::IO::ICellularRadio> g_apRadio; @@ -75,7 +75,7 @@ int32_t g_iOptions = 0; const uint32_t OPT_INDIVIDUAL = 0x01FFFFFF; const uint32_t OPT_SUMMARY = 0x7E000000; -const uint32_t OPT_INITIALIZE = 0x10000000; +const uint32_t OPT_INITIALIZE = 0x80000000; const uint32_t OPT_TIMEOUT = 0x00000001; const uint32_t OPT_DEVICE = 0x00000002; @@ -104,11 +104,11 @@ const uint32_t OPT_MSID = 0x00800000; const uint32_t OPT_SETRXDIVERSITY = 0x01000000; const uint32_t OPT_SETACTIVEFIRMWARE = 0x02000000; const uint32_t OPT_CONFIG_FILE = 0x04000000; -const uint32_t OPT_GET_RADIOMODE = 0x08000000; -const uint32_t OPT_SET_RADIOMODE = 0x10000000; +const uint32_t OPT_SET_CELLULAR_MODE = 0x08000000; const uint32_t OPT_UNLOCK_SIM_CARD = 0x20000000; const uint32_t OPT_RESET_RADIO = 0x40000000; + void handle_sigterm(int signum); void printHelp(const std::string& sApp); void parseOptions(int argc, char** argv); @@ -116,8 +116,7 @@ void initializeCache(); void shutdown(); const char *code2str(MTS::IO::ICellularRadio::CODE code); std::string loadImeiFromDeviceInfo(); -MTS::IO::ICellularRadio::RADIO_NETWORK_MODE radioModeEnum(const std::string &mode); -const char* radioModeStr(MTS::IO::ICellularRadio::RADIO_NETWORK_MODE mode); +MTS::IO::ICellularRadio::CELLULAR_MODES cellularModeFlags(const std::string networks); static int iOption = 0; @@ -146,14 +145,13 @@ static struct option long_options[] = { { "set-mip-mn-aaa-ss", required_argument, 0, '8' }, { "set-mip-mn-ha-ss", required_argument, 0, '9' }, { "unlock-sim-card", required_argument, 0, OPT_UNLOCK_SIM_CARD }, - { "get-radio-network-mode", no_argument, &iOption, OPT_GET_RADIOMODE }, - { "set-radio-network-mode", required_argument, 0, OPT_SET_RADIOMODE }, { "reset-radio", no_argument, &iOption, OPT_RESET_RADIO }, { "init-dc", no_argument, &iOption, OPT_INIT_DC }, { "init-fumo", no_argument, &iOption, OPT_INIT_FUMO }, { "init-prl", no_argument, &iOption, OPT_INIT_PRL }, { "init-activation", no_argument, &iOption, OPT_INIT_ACTIVATION }, { "factory-default", no_argument, &iOption, OPT_INIT_RTN }, + { "set-cellular-mode", required_argument, 0, 'w' }, { 0, 0, 0, 0 } }; @@ -371,13 +369,6 @@ int main(int argc, char** argv) { jArgs["fwid"] = g_sActiveFirmware; result = g_apRadio->setActiveFirmware(jArgs); printf("%s\n", code2str(result)); - } else if(g_iOptions & OPT_GET_RADIOMODE) { - ICellularRadio::RADIO_NETWORK_MODE mode; - g_apRadio->getRadioNetworkMode(mode); - printf("%s\n", radioModeStr(mode)); - } else if(g_iOptions & OPT_SET_RADIOMODE) { - ICellularRadio::CODE res = g_apRadio->setRadioNetworkMode(radioModeEnum(g_sRadioMode)); - printf("%s\n", code2str(res)); } else if(g_iOptions & OPT_UNLOCK_SIM_CARD) { Json::Value jArgs(Json::objectValue); jArgs["pin"] = g_sSimPin; @@ -387,6 +378,14 @@ int main(int argc, char** argv) { bool ret = g_apRadio->resetRadio(); result = (ret) ? ICellularRadio::CODE::SUCCESS : ICellularRadio::CODE::FAILURE; printf("%s\n", code2str(result)); + } else if(g_iOptions & OPT_SET_CELLULAR_MODE) { + ICellularRadio::CELLULAR_MODES networks = cellularModeFlags(g_sCellularMode); + if (networks != ICellularRadio::CELLULAR_MODE_NA) { + result = g_apRadio->setCellularMode(networks); + printf("%s\n", code2str(result)); + } else { + printf("Invalid argument: %s\n", g_sCellularMode.c_str()); + } } shutdown(); @@ -594,12 +593,6 @@ void parseOptions(int argc, char** argv) g_iOptions |= OPT_SETMIPMNHASS; break; - case OPT_SET_RADIOMODE: - if (optarg) - g_sRadioMode = optarg; - g_iOptions |= OPT_SET_RADIOMODE; - break; - case OPT_UNLOCK_SIM_CARD: if(optarg != 0) { g_sSimPin = optarg; @@ -607,6 +600,12 @@ void parseOptions(int argc, char** argv) g_iOptions |= OPT_UNLOCK_SIM_CARD; break; + case 'w': + if (optarg) + g_sCellularMode = optarg; + g_iOptions |= OPT_SET_CELLULAR_MODE; + break; + default: printf("OPTION: [%d] ABORTING!!\n", c); abort(); @@ -651,8 +650,7 @@ void printHelp(const std::string& sApp) { printf("\t--set-mip-mn-aaa-ss <VAL> : set MIP MN AAA SS\n"); printf("\t--set-mip-mn-ha-ss <VAL> : set MIP MN HA SS\n"); printf("\t--set-rx-diversity <VAL> : set RX Diversity\n"); - printf("\t--get-radio-network-mode : get selected cellular network\n"); - printf("\t--set-radio-network-mode {auto|gsm|umts} : set cellular network\n"); + printf("\t--set-cellular-mode : set preferred networks eg. 2g,3g,4g\n"); // Applicable for LTE910-NA1 dual FW images only // printf("\t--set-active-firmware <VAL> : switch to a specific firmware image\n"); printf("\t--factory-default [ --msl <MSL> ] : reset to factory defaults\n"); @@ -685,27 +683,24 @@ const char *code2str(MTS::IO::ICellularRadio::CODE code) { return "Unknown"; } -MTS::IO::ICellularRadio::RADIO_NETWORK_MODE radioModeEnum(const std::string &mode) +MTS::IO::ICellularRadio::CELLULAR_MODES cellularModeFlags(const std::string networks) { using namespace MTS::IO; - if (mode == "auto") - return ICellularRadio::RADIO_NETWORK_MODE_AUTO; - else if (mode == "gsm") - return ICellularRadio::RADIO_NETWORK_MODE_GSM_ONLY; - else if (mode == "umts") - return ICellularRadio::RADIO_NETWORK_MODE_UMTS_ONLY; - else - return ICellularRadio::RADIO_NETWORK_MODE_UNKNOWN; - -} - -const char* radioModeStr(MTS::IO::ICellularRadio::RADIO_NETWORK_MODE mode) -{ - using namespace MTS::IO; - switch (mode) { - case ICellularRadio::RADIO_NETWORK_MODE_GSM_ONLY : return "gsm"; - case ICellularRadio::RADIO_NETWORK_MODE_UMTS_ONLY: return "umts"; - case ICellularRadio::RADIO_NETWORK_MODE_AUTO : return "auto"; - default : return ""; + int result = ICellularRadio::CELLULAR_MODE_NA; + const std::vector<std::string> &items = MTS::Text::split(networks, ","); + for (const auto &it: items) { + if (it == "2g") { + result |= ICellularRadio::CELLULAR_MODE_2G; + } else if (it == "3g") { + result |= ICellularRadio::CELLULAR_MODE_3G; + } else if (it == "4g") { + result |= ICellularRadio::CELLULAR_MODE_4G; + } else if (it == "5g") { + result |= ICellularRadio::CELLULAR_MODE_5G; + } else { + result = ICellularRadio::CELLULAR_MODE_NA; + break; + } } + return static_cast<ICellularRadio::CELLULAR_MODES>(result); } |