summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Reiss <jreiss@multitech.com>2017-05-01 14:43:31 -0500
committerJason Reiss <jreiss@multitech.com>2017-05-01 14:43:31 -0500
commitfec609b89aedcdace9ba5411206936ea7bf64d1a (patch)
tree3506db090eef88fab680de82788cb01db3ca61a7
parent969757837587a34a01dc578707ed10ad2cd4fef1 (diff)
downloadlora-query-fec609b89aedcdace9ba5411206936ea7bf64d1a.tar.gz
lora-query-fec609b89aedcdace9ba5411206936ea7bf64d1a.tar.bz2
lora-query-fec609b89aedcdace9ba5411206936ea7bf64d1a.zip
Add --command (-x) option to pass all parameters to command port interface
-rw-r--r--main.cpp37
1 files changed, 34 insertions, 3 deletions
diff --git a/main.cpp b/main.cpp
index bf6e3e4..9c1241e 100644
--- a/main.cpp
+++ b/main.cpp
@@ -48,7 +48,9 @@ int opt_get_nodeconfig = 0;
int opt_add_node = 0;
int opt_delete_node = 0;
int opt_update_node = 0;
+int opt_command = 0;
+char* command_command;
char* node_get_addr;
char* node_delete_addr;
char* node_config_addr;
@@ -57,6 +59,8 @@ char* node_update_field;
char* node_update_value;
int node_add_count = 0;
char* node_add_args[6];
+int command_count = 0;
+char* command_args[20];
int timeout = TIMEOUT;
@@ -67,6 +71,7 @@ const char* cmd_node_config = "node config";
const char* cmd_node_update = "node update";
const char* cmd_node_delete = "node delete";
const char* cmd_nodeadd = "node add";
+const std::string lora_command_output("/var/tmp/lora_command_output");
const std::string lora_network_stats_json("/var/tmp/lora_network_stats.json");
const std::string lora_network_nodelist("/var/tmp/lora_network_nodelist");
const std::string lora_network_nodelist_json("/var/tmp/lora_network_nodelist.json");
@@ -106,13 +111,27 @@ void parseOptions(int argc, char** argv);
void printHelp(const std::string& sApp);
std::string trim(std::string& str);
-int main(int argc, char**argv)
- {
+int main(int argc, char**argv) {
parseOptions(argc, argv);
if (opt_stats_reset) {
runCmd(cmd_stats_reset);
}
+
+ if (opt_command) {
+ std::stringstream cmd;
+
+ for (int i = 0; i < command_count; i++) {
+ cmd << " " << command_args[i];
+ }
+
+ runCmd(cmd.str().c_str());
+ if (receiveStream.str().empty()) {
+ return 0;
+ }
+ saveToFile(lora_command_output, receiveStream.str());
+ std::cout << receiveStream.str();
+ }
if (opt_get_stats) {
runCmd(cmd_stats);
@@ -367,7 +386,7 @@ void parseOptions(int argc, char** argv) {
exit(0);
}
- const char* short_options = "hvsrnc:a:u:d:jt:";
+ const char* short_options = "hvsrnc:a:u:d:jt:x:";
const struct option long_options[] = {
{ "help", no_argument, 0, 'h' },
@@ -379,6 +398,7 @@ void parseOptions(int argc, char** argv) {
{ "node-add", required_argument, 0, 'a' },
{ "node-update", required_argument, 0, 'u' },
{ "node-delete", required_argument, 0, 'd' },
+ { "command", required_argument, 0, 'x' },
{ "json", no_argument, 0, 'j' },
{ "timeout", required_argument, 0, 't' },
{ 0, 0, 0, 0 }
@@ -389,6 +409,14 @@ void parseOptions(int argc, char** argv) {
while ((rez = getopt_long(argc, argv, short_options, long_options, &option_index)) != -1) {
switch (rez) {
+ case 'x': {
+ ++opt_command;
+ command_args[command_count++] = optarg;
+ for (int i = optind; i < argc; i++) {
+ command_args[command_count++] = argv[i];
+ }
+ break;
+ }
case 's': {
++opt_get_stats;
break;
@@ -467,6 +495,9 @@ void printHelp(const std::string& sApp) {
printf("\t\tex: --node-update 00000001 appkey 4c194e20d396b5f7d3e1551e4cd320de\n");
printf("\t--node-delete (d) : delete a Node\n");
printf("\t\tex: --node-delete <NODE-ADDR>\n");
+ printf("\t--command (x) : send command string to network server\n");
+ printf("\t\tusage: --command <COMMAND-NAME> <COMMAND-OPTIONS> ...\n");
+ printf("\t\tex: --command device list json\n");
printf("\t--json (j) : data in json format\n");
printf("\t--help (?) : returns this message\n");
printf("\t--version (v) : print version\n");