From 9eb0233d94d05b89d8dab1ad192f5010d1282341 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Mon, 3 Feb 2020 14:39:58 -0600 Subject: Changed getopt path option to conform with other utilities --- util_lbt_test/src/util_lbt_test.c | 46 ++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 17 deletions(-) (limited to 'util_lbt_test/src') diff --git a/util_lbt_test/src/util_lbt_test.c b/util_lbt_test/src/util_lbt_test.c index 16af7ac..f143a92 100644 --- a/util_lbt_test/src/util_lbt_test.c +++ b/util_lbt_test/src/util_lbt_test.c @@ -32,6 +32,7 @@ Maintainer: Michael Coracin #include /* getopt access */ #include /* rand */ #include /* strncmp */ +#include /* getopt_long */ #include "loragw_aux.h" #include "loragw_reg.h" @@ -77,12 +78,12 @@ static void sig_handler(int sigio) { /* describe command line options */ void usage(void) { printf("Available options:\n"); - printf(" -h print this help\n"); - printf(" -f frequency in MHz of the first LBT channel\n"); - printf(" -o offset in dB to be applied to the SX127x RSSI [-128..127]\n"); - printf(" -r target RSSI: signal strength target used to detect if the channel is clear or not [-128..0]\n"); - printf(" -s scan time in µs for all 8 LBT channels [128,5000]\n"); - printf(" -p path of SPIDEV e.g. /dev/spidev0.0\n"); + printf(" -h print this help\n"); + printf(" -f frequency in MHz of the first LBT channel\n"); + printf(" -o offset in dB to be applied to the SX127x RSSI [-128..127]\n"); + printf(" -r target RSSI: signal strength target used to detect if the channel is clear or not [-128..0]\n"); + printf(" -s scan time in µs for all 8 LBT channels [128,5000]\n"); + printf(" --path path of SPIDEV e.g. /dev/spidev0.0\n"); } /* -------------------------------------------------------------------------- */ @@ -92,6 +93,11 @@ int main(int argc, char **argv) { int i; int xi = 0; + int option_index = 0; + static struct option long_options[] = { + {"path", 1, 0, 0}, + {0, 0, 0, 0} + }; char arg_s[64]; /* in/out variables */ double f1 = 0.0; @@ -108,7 +114,7 @@ int main(int argc, char **argv) uint32_t freq_offset; /* parse command line options */ - while ((i = getopt (argc, argv, "h:f:s:r:o:p:")) != -1) { + while ((i = getopt_long (argc, argv, "h:f:s:r:o:", long_options, &option_index)) != -1) { switch (i) { case 'h': usage(); @@ -145,16 +151,6 @@ int main(int argc, char **argv) rssi_target_dBm = xi; } break; - case 'p': - i = sscanf(optarg, "%s", arg_s); - if ((i != 1) || (strncmp(arg_s, "/dev/", 5 ) != 0)) { - printf("ERROR: argument parsing of --path argument. Use -h to print help\n"); - return EXIT_FAILURE; - } - else { - lgw_spi_set_path(arg_s); - } - break; case 'o': /* -o SX127x RSSI offset [-128..127] */ i = sscanf(optarg, "%i", &xi); if((i != 1) || (xi < -128) || (xi > 127)) { @@ -165,6 +161,22 @@ int main(int argc, char **argv) rssi_offset = (int8_t)xi; } break; + + case 0: + if (strcmp(long_options[option_index].name,"path") == 0) { + i = sscanf(optarg, "%s", arg_s); + if ((i != 1) || (strncmp(arg_s, "/dev/", 5 ) != 0)) { + printf("ERROR: argument parsing of --path argument. Use -h to print help\n"); + return EXIT_FAILURE; + } + else { + lgw_spi_set_path(arg_s); + } + } else { + printf("ERROR: argument parsing options. Use -h to print help\n"); + return EXIT_FAILURE; + } + break; default: MSG("ERROR: argument parsing use -h option for help\n"); usage(); -- cgit v1.2.3