From 228116b1958515947d208149cccbb8c9a9a6ab83 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Mon, 3 Feb 2020 15:49:47 -0600 Subject: Changed util spectral scan path parameter to match other utilities --- util_spectral_scan/src/util_spectral_scan.c | 46 +++++++++++++++++++---------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/util_spectral_scan/src/util_spectral_scan.c b/util_spectral_scan/src/util_spectral_scan.c index 91a358f..090dc22 100644 --- a/util_spectral_scan/src/util_spectral_scan.c +++ b/util_spectral_scan/src/util_spectral_scan.c @@ -31,6 +31,7 @@ Maintainer: Michael Coracin #include /* getopt */ #include #include +#include /* getopt_long */ #include "loragw_aux.h" #include "loragw_reg.h" @@ -116,19 +117,26 @@ int main( int argc, char ** argv ) uint16_t rssi_cumu; float rssi_thresh[] = {0.1,0.3,0.5,0.8,1}; + /* Parameter parsing */ + int option_index = 0; + static struct option long_options[] = { + {"path", 1, 0, 0}, + {0, 0, 0, 0} + }; + /* Parse command line options */ - while((i = getopt(argc, argv, "hf:n:b:l:o:p:")) != -1) { + while ((i = getopt_long (argc, argv, "hf:n:b:l:o:p:", long_options, &option_index)) != -1) { switch (i) { case 'h': - printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); - printf(" -f :: Frequency vector to scan in MHz (start:step:stop)\n"); - printf(" start>%3.3f step>%1.3f stop<%3.3f\n", MIN_FREQ/1e6, MIN_STEP_FREQ/1e6, MAX_FREQ/1e6); - printf(" -b Channel bandwidth in KHz [25,50,100,125,200,250,500]\n"); - printf(" -n Total number of RSSI points [1..65535]\n"); - printf(" -o Offset in dB to be applied to the SX127x RSSI [-128..127]\n"); - printf(" -l Log file name\n"); - printf(" -p path of SPIDEV e.g. /dev/spidev0.0\n"); - printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); + printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); + printf(" -f :: Frequency vector to scan in MHz (start:step:stop)\n"); + printf(" start>%3.3f step>%1.3f stop<%3.3f\n", MIN_FREQ/1e6, MIN_STEP_FREQ/1e6, MAX_FREQ/1e6); + printf(" -b Channel bandwidth in KHz [25,50,100,125,200,250,500]\n"); + printf(" -n Total number of RSSI points [1..65535]\n"); + printf(" -o Offset in dB to be applied to the SX127x RSSI [-128..127]\n"); + printf(" -l Log file name\n"); + printf(" --path path of SPIDEV e.g. /dev/spidev0.0\n"); + printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); return EXIT_SUCCESS; case 'f': /* -f :: Frequency vector to scan in MHz, start:step:stop */ @@ -208,13 +216,19 @@ int main( int argc, char ** argv ) } break; - case 'p': /* -p Path for spi device */ - j = sscanf(optarg, "%s", arg_s); - if (j != 1) { - printf("ERROR: argument parsing of -p argument. -h for help.\n"); - return EXIT_FAILURE; + 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 { - lgw_spi_set_path(arg_s); + printf("ERROR: argument parsing options. Use -h to print help\n"); + return EXIT_FAILURE; } break; -- cgit v1.2.3