diff options
-rw-r--r-- | main.cpp | 88 |
1 files changed, 20 insertions, 68 deletions
@@ -34,7 +34,6 @@ #include <iostream> #include <fstream> #include <signal.h> -#include <climits> #include "Version.h" const std::string DEFAULT_PORT("/dev/modem_at1"); @@ -69,7 +68,7 @@ std::string g_sConfigFile; Json::Value g_jData; std::string g_sRadioMode; std::string g_sSimPin; -std::string g_sPreferredNetworks; +std::string g_sCellularMode; MTS::AutoPtr<MTS::IO::ICellularRadio> g_apRadio; @@ -112,9 +111,7 @@ const uint32_t OPT_UNLOCK_SIM_CARD = 0x20000000; const uint32_t OPT_RESET_RADIO = 0x40000000; int32_t g_iAuxOptions = 0; -const uint32_t AOPT_GET_AVAIL_PREF_NET = 0x00000001; -const uint32_t AOPT_GET_PREFERRED_NET = 0x00000002; -const uint32_t AOPT_SET_PREFERRED_NET = 0x00000004; +const uint32_t AOPT_SET_CELLULAR_MODE = 0x00000001; void handle_sigterm(int signum); void printHelp(const std::string& sApp); @@ -125,8 +122,7 @@ 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); -std::string preferredNetworksStr(MTS::IO::ICellularRadio::PREFERRED_NETWORKS networks); -MTS::IO::ICellularRadio::PREFERRED_NETWORKS preferredNetworksFlags(const std::string networks); +MTS::IO::ICellularRadio::CELLULAR_MODES cellularModeFlags(const std::string networks); static int iOption = 0; @@ -163,9 +159,7 @@ static struct option long_options[] = { { "init-prl", no_argument, &iOption, OPT_INIT_PRL }, { "init-activation", no_argument, &iOption, OPT_INIT_ACTIVATION }, { "factory-default", no_argument, &iOption, OPT_INIT_RTN }, - { "get-preferred-networks", no_argument, 0, 'a' }, - { "get-available-preferred-networks", no_argument, 0, 'e' }, - { "set-preferred-networks", required_argument, 0, 'w' }, + { "set-cellular-mode", required_argument, 0, 'w' }, { 0, 0, 0, 0 } }; @@ -399,29 +393,13 @@ 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_iAuxOptions & AOPT_GET_AVAIL_PREF_NET) { - ICellularRadio::PREFERRED_NETWORKS networks; - result = g_apRadio->getAvailablePreferredNetworks(networks); - if (result == ICellularRadio::SUCCESS) { - printf("%s\n", preferredNetworksStr(networks).c_str()); - } else { - printf("%s\n", code2str(result)); - } - } else if(g_iAuxOptions & AOPT_GET_PREFERRED_NET) { - ICellularRadio::PREFERRED_NETWORKS networks; - result = g_apRadio->getPreferredNetworks(networks); - if (result == ICellularRadio::SUCCESS) { - printf("%s\n", preferredNetworksStr(networks).c_str()); - } else { - printf("%s\n", code2str(result)); - } - } else if(g_iAuxOptions & AOPT_SET_PREFERRED_NET) { - ICellularRadio::PREFERRED_NETWORKS networks = preferredNetworksFlags(g_sPreferredNetworks); - if (networks != ICellularRadio::PREFERRED_NETWORK_NA) { - result = g_apRadio->setPreferredNetworks(networks); + } else if(g_iAuxOptions & AOPT_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_sPreferredNetworks.c_str()); + printf("Invalid argument: %s\n", g_sCellularMode.c_str()); } } @@ -643,18 +621,10 @@ void parseOptions(int argc, char** argv) g_iOptions |= OPT_UNLOCK_SIM_CARD; break; - case 'a': - g_iAuxOptions |= AOPT_GET_PREFERRED_NET; - break; - - case 'e': - g_iAuxOptions |= AOPT_GET_AVAIL_PREF_NET; - break; - case 'w': if (optarg) - g_sPreferredNetworks = optarg; - g_iAuxOptions |= AOPT_SET_PREFERRED_NET; + g_sCellularMode = optarg; + g_iAuxOptions |= AOPT_SET_CELLULAR_MODE; break; default: @@ -703,9 +673,7 @@ void printHelp(const std::string& sApp) { 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--get-preferred-networks : get currently preferred network\n"); - printf("\t--get-available-preferred-networks : get supported networks to switch\n"); - printf("\t--set-preferred-networks : set preferred networks\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"); @@ -763,40 +731,24 @@ const char* radioModeStr(MTS::IO::ICellularRadio::RADIO_NETWORK_MODE mode) } } -std::string preferredNetworksStr(MTS::IO::ICellularRadio::PREFERRED_NETWORKS networks) -{ - using namespace MTS::IO; - std::string result; - for (size_t i = 0; i<sizeof(networks)*CHAR_BIT; ++i){ - switch (1<<i & networks) { - case ICellularRadio::PREFERRED_NETWORK_2G: result += "2g,"; break; - case ICellularRadio::PREFERRED_NETWORK_3G: result += "3g,"; break; - case ICellularRadio::PREFERRED_NETWORK_4G: result += "4g,"; break; - case ICellularRadio::PREFERRED_NETWORK_5G: result += "5g,"; break; - } - } - result.pop_back(); - return result; -} - -MTS::IO::ICellularRadio::PREFERRED_NETWORKS preferredNetworksFlags(const std::string networks) +MTS::IO::ICellularRadio::CELLULAR_MODES cellularModeFlags(const std::string networks) { using namespace MTS::IO; - int result = ICellularRadio::PREFERRED_NETWORK_NA; + 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::PREFERRED_NETWORK_2G; + result |= ICellularRadio::CELLULAR_MODE_2G; } else if (it == "3g") { - result |= ICellularRadio::PREFERRED_NETWORK_3G; + result |= ICellularRadio::CELLULAR_MODE_3G; } else if (it == "4g") { - result |= ICellularRadio::PREFERRED_NETWORK_4G; + result |= ICellularRadio::CELLULAR_MODE_4G; } else if (it == "5g") { - result |= ICellularRadio::PREFERRED_NETWORK_5G; + result |= ICellularRadio::CELLULAR_MODE_5G; } else { - result = ICellularRadio::PREFERRED_NETWORK_NA; + result = ICellularRadio::CELLULAR_MODE_NA; break; } } - return static_cast<ICellularRadio::PREFERRED_NETWORKS>(result); + return static_cast<ICellularRadio::CELLULAR_MODES>(result); } |