summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksym Telychko <maksym.telychko@globallogic.com>2019-07-25 18:09:24 +0300
committerMaksym Telychko <maksym.telychko@globallogic.com>2019-07-25 18:10:45 +0300
commit4210d68ee7f11599e5d414193390b7ae65f0cfb4 (patch)
treedd33cd6df43c3e29d7aff20748d2941873530e83
parent9c23881580b3d04755751629e2cb7e36f01c9529 (diff)
downloadradio-cmd-4210d68ee7f11599e5d414193390b7ae65f0cfb4.tar.gz
radio-cmd-4210d68ee7f11599e5d414193390b7ae65f0cfb4.tar.bz2
radio-cmd-4210d68ee7f11599e5d414193390b7ae65f0cfb4.zip
MTX-2891 mpower: 2-3-4g switch implementation
-rw-r--r--main.cpp93
1 files changed, 92 insertions, 1 deletions
diff --git a/main.cpp b/main.cpp
index d72faee..85c7563 100644
--- a/main.cpp
+++ b/main.cpp
@@ -34,6 +34,7 @@
#include <iostream>
#include <fstream>
#include <signal.h>
+#include <climits>
#include "Version.h"
const std::string DEFAULT_PORT("/dev/modem_at1");
@@ -68,6 +69,7 @@ std::string g_sConfigFile;
Json::Value g_jData;
std::string g_sRadioMode;
std::string g_sSimPin;
+std::string g_sPreferredNetworks;
MTS::AutoPtr<MTS::IO::ICellularRadio> g_apRadio;
@@ -75,7 +77,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;
@@ -109,6 +111,11 @@ const uint32_t OPT_SET_RADIOMODE = 0x10000000;
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;
+
void handle_sigterm(int signum);
void printHelp(const std::string& sApp);
void parseOptions(int argc, char** argv);
@@ -118,6 +125,8 @@ 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);
static int iOption = 0;
@@ -154,6 +163,9 @@ 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' },
{ 0, 0, 0, 0 }
};
@@ -387,6 +399,30 @@ 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);
+ printf("%s\n", code2str(result));
+ } else {
+ printf("Invalid argument: %s\n", g_sPreferredNetworks.c_str());
+ }
}
shutdown();
@@ -607,6 +643,20 @@ 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;
+ break;
+
default:
printf("OPTION: [%d] ABORTING!!\n", c);
abort();
@@ -653,6 +703,9 @@ 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");
// 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");
@@ -709,3 +762,41 @@ const char* radioModeStr(MTS::IO::ICellularRadio::RADIO_NETWORK_MODE mode)
default : return "";
}
}
+
+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)
+{
+ using namespace MTS::IO;
+ int result = ICellularRadio::PREFERRED_NETWORK_NA;
+ const std::vector<std::string> &items = MTS::Text::split(networks, ",");
+ for (const auto &it: items) {
+ if (it == "2g") {
+ result |= ICellularRadio::PREFERRED_NETWORK_2G;
+ } else if (it == "3g") {
+ result |= ICellularRadio::PREFERRED_NETWORK_3G;
+ } else if (it == "4g") {
+ result |= ICellularRadio::PREFERRED_NETWORK_4G;
+ } else if (it == "5g") {
+ result |= ICellularRadio::PREFERRED_NETWORK_5G;
+ } else {
+ result = ICellularRadio::PREFERRED_NETWORK_NA;
+ break;
+ }
+ }
+ return static_cast<ICellularRadio::PREFERRED_NETWORKS>(result);
+}