summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Sharma <harsh.sharma@multitech.com>2020-02-03 15:49:47 -0600
committerHarsh Sharma <harsh.sharma@multitech.com>2020-02-03 15:49:47 -0600
commit228116b1958515947d208149cccbb8c9a9a6ab83 (patch)
treeb83f74a520486973d9ff6569e53f96bdda3f128e
parentfebb8372c248a11007eee7ea0267178f0dec61ee (diff)
downloadlora_gateway_mtac_full-228116b1958515947d208149cccbb8c9a9a6ab83.tar.gz
lora_gateway_mtac_full-228116b1958515947d208149cccbb8c9a9a6ab83.tar.bz2
lora_gateway_mtac_full-228116b1958515947d208149cccbb8c9a9a6ab83.zip
Changed util spectral scan path parameter to match other utilities
-rw-r--r--util_spectral_scan/src/util_spectral_scan.c46
1 files 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 <unistd.h> /* getopt */
#include <string.h>
#include <signal.h>
+#include <getopt.h> /* 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 <float>:<float>:<float> 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 <uint> Channel bandwidth in KHz [25,50,100,125,200,250,500]\n");
- printf(" -n <uint> Total number of RSSI points [1..65535]\n");
- printf(" -o <int> Offset in dB to be applied to the SX127x RSSI [-128..127]\n");
- printf(" -l <char> Log file name\n");
- printf(" -p <char> path of SPIDEV e.g. /dev/spidev0.0\n");
- printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
+ printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
+ printf(" -f <float>:<float>:<float> 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 <uint> Channel bandwidth in KHz [25,50,100,125,200,250,500]\n");
+ printf(" -n <uint> Total number of RSSI points [1..65535]\n");
+ printf(" -o <int> Offset in dB to be applied to the SX127x RSSI [-128..127]\n");
+ printf(" -l <string> Log file name\n");
+ printf(" --path <string> path of SPIDEV e.g. /dev/spidev0.0\n");
+ printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
return EXIT_SUCCESS;
case 'f': /* -f <float>:<float>:<float> Frequency vector to scan in MHz, start:step:stop */
@@ -208,13 +216,19 @@ int main( int argc, char ** argv )
}
break;
- case 'p': /* -p <char> 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;