summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Hatch <jhatch@multitech.com>2019-07-29 08:50:07 -0500
committerJeff Hatch <jhatch@multitech.com>2019-07-29 08:50:07 -0500
commitb0d99ce30902aa70969696846107c65310309bc3 (patch)
tree74f9f45d2a90d5b1368be2c768651f15110b4507
parent74fb4bb2d18bb1bd5b3a0ffa933064611a24de0d (diff)
parent9c23881580b3d04755751629e2cb7e36f01c9529 (diff)
downloadradio-cmd-b0d99ce30902aa70969696846107c65310309bc3.tar.gz
radio-cmd-b0d99ce30902aa70969696846107c65310309bc3.tar.bz2
radio-cmd-b0d99ce30902aa70969696846107c65310309bc3.zip
Merge branch 'quectel-radio' into 'master'
mPower Edge Q4: Quectel radio support See merge request !2
-rw-r--r--main.cpp181
1 files changed, 123 insertions, 58 deletions
diff --git a/main.cpp b/main.cpp
index a5eeb97..d72faee 100644
--- a/main.cpp
+++ b/main.cpp
@@ -21,7 +21,7 @@
#include <mts/MTS_Text.h>
#include <mts/MTS_Logger.h>
#include <mts/MTS_AutoPtr.h>
-#include <mts/MTS_IO_CellularRadio.h>
+#include <mts/MTS_IO_ICellularRadio.h>
#include <mts/MTS_IO_CellularRadioFactory.h>
#include <json/json.h>
#include <sstream>
@@ -66,8 +66,10 @@ std::string g_sRxDiversity;
std::string g_sActiveFirmware;
std::string g_sConfigFile;
Json::Value g_jData;
+std::string g_sRadioMode;
+std::string g_sSimPin;
-MTS::AutoPtr<MTS::IO::CellularRadio> g_apRadio;
+MTS::AutoPtr<MTS::IO::ICellularRadio> g_apRadio;
int32_t g_iOptions = 0;
@@ -102,52 +104,63 @@ 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_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);
void initializeCache();
void shutdown();
-const char *code2str(MTS::IO::CellularRadio::CODE code);
+const char *code2str(MTS::IO::ICellularRadio::CODE code);
std::string loadImeiFromDeviceInfo();
-
-
- int iOption = 0;
- static struct option long_options[] =
- { { "help", no_argument, 0, '?' },
- { "version", no_argument, 0, 'v' },
- { "printlvl", required_argument, 0, 'p' },
- { "device", required_argument, 0, 'd' },
- { "config-file", required_argument, 0, 'c' },
- { "set-mdn", required_argument, 0, 'n' },
- { "set-msl", required_argument, 0, 'm' },
- { "set-msid", required_argument, 0, 's' },
- { "msl", required_argument, 0, 'l' },
- { "mdn", required_argument, 0, 'k' },
- { "msid", required_argument, 0, 'j' },
- { "set-active-firmware" , required_argument, 0, 'f' },
- { "set-rx-diversity", required_argument, 0, 'r' },
- { "set-mip-active-profile", required_argument, 0, '0' },
- { "set-mip-nai", required_argument, 0, '1' },
- { "set-mip-home-ip", required_argument, 0, '2' },
- { "set-mip-primary-ha", required_argument, 0, '3' },
- { "set-mip-secondary-ha", required_argument, 0, '4' },
- { "set-mip-mn-aaa-spi", required_argument, 0, '5' },
- { "set-mip-mn-ha-spi", required_argument, 0, '6' },
- { "set-mip-rev-tun", required_argument, 0, '7' },
- { "set-mip-mn-aaa-ss", required_argument, 0, '8' },
- { "set-mip-mn-ha-ss", required_argument, 0, '9' },
- { "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 },
- { 0, 0, 0, 0 } };
+MTS::IO::ICellularRadio::RADIO_NETWORK_MODE radioModeEnum(const std::string &mode);
+const char* radioModeStr(MTS::IO::ICellularRadio::RADIO_NETWORK_MODE mode);
+
+
+static int iOption = 0;
+static struct option long_options[] = {
+ { "help", no_argument, 0, '?' },
+ { "version", no_argument, 0, 'v' },
+ { "printlvl", required_argument, 0, 'p' },
+ { "device", required_argument, 0, 'd' },
+ { "config-file", required_argument, 0, 'c' },
+ { "set-mdn", required_argument, 0, 'n' },
+ { "set-msl", required_argument, 0, 'm' },
+ { "set-msid", required_argument, 0, 's' },
+ { "msl", required_argument, 0, 'l' },
+ { "mdn", required_argument, 0, 'k' },
+ { "msid", required_argument, 0, 'j' },
+ { "set-active-firmware" , required_argument, 0, 'f' },
+ { "set-rx-diversity", required_argument, 0, 'r' },
+ { "set-mip-active-profile", required_argument, 0, '0' },
+ { "set-mip-nai", required_argument, 0, '1' },
+ { "set-mip-home-ip", required_argument, 0, '2' },
+ { "set-mip-primary-ha", required_argument, 0, '3' },
+ { "set-mip-secondary-ha", required_argument, 0, '4' },
+ { "set-mip-mn-aaa-spi", required_argument, 0, '5' },
+ { "set-mip-mn-ha-spi", required_argument, 0, '6' },
+ { "set-mip-rev-tun", required_argument, 0, '7' },
+ { "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 },
+ { 0, 0, 0, 0 }
+};
Json::Value getStaticData();
Json::Value getNetworkData();
-MTS::IO::CellularRadio::UpdateCb cb = [](const Json::Value& s)->void {
+MTS::IO::ICellularRadio::UpdateCb cb = [](const Json::Value& s)->void {
if(s.isString()) {
printf("%s\n", s.asCString());
}
@@ -199,7 +212,7 @@ int main(int argc, char** argv) {
return EXIT_FAILURE;
}
- CellularRadio::CODE result = CellularRadio::CODE::SUCCESS;
+ ICellularRadio::CODE result = ICellularRadio::CODE::SUCCESS;
if(g_iOptions & OPT_COMMAND) {
int32_t timeoutMillis = DEFAULT_TIMEOUT;
@@ -211,7 +224,7 @@ int main(int argc, char** argv) {
}
}
printDebug("AT Command: %s\n", g_sAtCommand.c_str());
- std::string sResult = g_apRadio->sendCommand(g_sAtCommand, MTS::IO::CellularRadio::DEFAULT_BAIL_STRINGS, timeoutMillis);
+ std::string sResult = g_apRadio->sendCommand(g_sAtCommand, MTS::IO::ICellularRadio::DEFAULT_BAIL_STRINGS, timeoutMillis);
printDebug("RESULT: %s\n", sResult.c_str());
// skip first line
std::size_t pos = sResult.find('\n');
@@ -305,7 +318,7 @@ int main(int argc, char** argv) {
Json::Value jArgs(Json::objectValue);
jArgs["msl"] = g_sMSL;
result = g_apRadio->validateMsl(jArgs);
- if(result == MTS::IO::CellularRadio::CODE::SUCCESS) {
+ if(result == MTS::IO::ICellularRadio::CODE::SUCCESS) {
std::ofstream fMSL((g_sCache + "/" + FMSL).c_str(), std::ios_base::trunc | std::ios_base::out);
if(fMSL.is_open()) {
std::string sMSL;
@@ -358,11 +371,27 @@ 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;
+ result = g_apRadio->unlockSimCard(jArgs);
+ printf("%s\n", code2str(result));
+ } else if(g_iOptions & OPT_RESET_RADIO) {
+ bool ret = g_apRadio->resetRadio();
+ result = (ret) ? ICellularRadio::CODE::SUCCESS : ICellularRadio::CODE::FAILURE;
+ printf("%s\n", code2str(result));
}
shutdown();
- return (result == CellularRadio::CODE::SUCCESS) ? 0 : 1;
+ return (result == ICellularRadio::CODE::SUCCESS) ? 0 : 1;
}
void handle_sigterm(int signum) {
@@ -378,21 +407,15 @@ void shutdown() {
}
}
-void parseOptions(int argc, char** argv) {
- int c;
- //int iOption = 0;
-
+void parseOptions(int argc, char** argv)
+{
if(argc == 1) {
printHelp(argv[0]);
exit(0);
}
- while (1) {
-
- /* getopt_long stores the option index here. */
- int option_index = 0;
-
- c = getopt_long(argc, argv, "t:d:p:r:?v", long_options, &option_index);
+ while (true) {
+ int c = getopt_long(argc, argv, "t:d:p:r:?v", long_options, nullptr);
/* Detect the end of the options. */
if(c == -1) {
@@ -571,6 +594,19 @@ 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;
+ }
+ g_iOptions |= OPT_UNLOCK_SIM_CARD;
+ break;
+
default:
printf("OPTION: [%d] ABORTING!!\n", c);
abort();
@@ -615,9 +651,13 @@ 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");
// 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");
+ printf("\t--unlock-sim-card <SIM PIN> : unlock the SIM card using the PIN code provided\n");
+ printf("\t--reset-radio : reset the radio module using AT commands\n");
printf("\n");
printf("\t--printlvl (p) <level> : sets the printlvl [0-100]\n");
printf("\t--version (v) : returns version\n");
@@ -627,20 +667,45 @@ void printHelp(const std::string& sApp) {
printf("\t\tLE910, HE910, GE910, DE910, CE910\n");
}
-const char *code2str(MTS::IO::CellularRadio::CODE code) {
+const char *code2str(MTS::IO::ICellularRadio::CODE code) {
switch (code) {
- case MTS::IO::CellularRadio::CODE::SUCCESS:
+ case MTS::IO::ICellularRadio::CODE::SUCCESS:
return "Success";
- case MTS::IO::CellularRadio::CODE::ERROR:
+ case MTS::IO::ICellularRadio::CODE::ERROR:
return "Error";
- case MTS::IO::CellularRadio::CODE::FAILURE:
+ case MTS::IO::ICellularRadio::CODE::FAILURE:
return "Failure";
- case MTS::IO::CellularRadio::CODE::NO_RESPONSE:
+ case MTS::IO::ICellularRadio::CODE::NO_RESPONSE:
return "No Response";
- case MTS::IO::CellularRadio::CODE::NOT_APPLICABLE:
+ case MTS::IO::ICellularRadio::CODE::NOT_APPLICABLE:
return "Not Applicable";
- case MTS::IO::CellularRadio::CODE::INVALID_ARGS:
+ case MTS::IO::ICellularRadio::CODE::INVALID_ARGS:
return "Invalid Arguments";
}
return "Unknown";
}
+
+MTS::IO::ICellularRadio::RADIO_NETWORK_MODE radioModeEnum(const std::string &mode)
+{
+ 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 "";
+ }
+}