diff options
author | Jason Reiss <jreiss@multitech.com> | 2015-07-13 12:16:50 -0500 |
---|---|---|
committer | Jason Reiss <jreiss@multitech.com> | 2015-07-13 12:16:50 -0500 |
commit | 84fcf0333a3620c6a70fe0650fda9684e0a1e259 (patch) | |
tree | 99059289c261aa9c2ba731305d224b7fcf7ffe96 | |
parent | 12eb2e9c901e9100e2fb938a64110263c24ea8e8 (diff) | |
download | lora-query-84fcf0333a3620c6a70fe0650fda9684e0a1e259.tar.gz lora-query-84fcf0333a3620c6a70fe0650fda9684e0a1e259.tar.bz2 lora-query-84fcf0333a3620c6a70fe0650fda9684e0a1e259.zip |
feature: add stats reset0.0.2
refactor: cmds and opts
-rw-r--r-- | main.cpp | 52 |
1 files changed, 32 insertions, 20 deletions
@@ -40,12 +40,14 @@ #define MAX_RECEIVED_BYTES 2000 #define TIMEOUT 100 /* By default 100 msec */ -int get_stats = 0; -int get_nodelist = 0; -int get_json = 0; +int opt_get_stats = 0; +int opt_get_nodelist = 0; +int opt_get_json = 0; +int opt_stats_reset = 0; int timeout = TIMEOUT; -const char* stats = "stats"; -const char* nodelist = "node list"; +const char* cmd_stats = "stats"; +const char* cmd_stats_reset = "stats reset"; +const char* cmd_nodelist = "node list"; 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"); @@ -80,13 +82,17 @@ int main(int argc, char**argv) { parseOptions(argc, argv); - if (get_stats) { - getloraData(stats); + if (opt_stats_reset) { + getloraData(cmd_stats_reset); + } + + if (opt_get_stats) { + getloraData(cmd_stats); printStats(); } - if (get_nodelist) { - getloraData(nodelist); - if (get_json) { + if (opt_get_nodelist) { + getloraData(cmd_nodelist); + if (opt_get_json) { printNodeList(); } else { if (receiveStream.str().empty() ) { @@ -237,12 +243,13 @@ void parseOptions(int argc, char** argv) { exit(0); } - const char* short_options = "hvsnjt:"; + const char* short_options = "hvsirnjt:"; const struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'v'}, {"stats", no_argument, 0, 's'}, + {"stats-reset", no_argument, 0, 'r'}, {"node-list", no_argument, 0, 'n'}, {"json", no_argument, 0, 'j'}, {"timeout", required_argument, 0, 't'}, @@ -255,15 +262,19 @@ void parseOptions(int argc, char** argv) { while ((rez=getopt_long(argc, argv, short_options, long_options, &option_index))!=-1) { switch(rez){ case 's': { - ++get_stats; + ++opt_get_stats; break; }; + case 'r': { + ++opt_stats_reset; + break; + }; case 'n': { - ++get_nodelist; + ++opt_get_nodelist; break; }; case 'j': { - ++get_json; + ++opt_get_json; break; }; case 't': { @@ -288,12 +299,13 @@ void parseOptions(int argc, char** argv) { void printHelp(const std::string& sApp) { printf("Usage: %s [-t timeout] [-s] [-n]\n", sApp.c_str()); printf("\tSimple UDP client utility to pull info from LoRa Network server\n"); - printf("\t--timeout (t) : UDP recv timeout, default: 100 (msecs)\n"); - printf("\t--stats (s) : get LoRa Network server statistics\n"); - printf("\t--node-list (n) : get Node List\n"); - printf("\t--json (j) : data in json format\n"); - printf("\t--help (?) : returns this message\n"); - printf("\t--version (v) : print version\n"); + printf("\t--timeout (t) : UDP recv timeout, default: 100 (msecs)\n"); + printf("\t--stats (s) : get LoRa Network server statistics\n"); + printf("\t--stats-reset (r) : reset LoRa Network server statistics\n"); + printf("\t--node-list (n) : get Node List\n"); + printf("\t--json (j) : data in json format\n"); + printf("\t--help (?) : returns this message\n"); + printf("\t--version (v) : print version\n"); } std::string trim(std::string& str) { |