summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Sharma <harsh.sharma@multitech.com>2020-02-03 14:39:58 -0600
committerHarsh Sharma <harsh.sharma@multitech.com>2020-02-03 14:39:58 -0600
commit9eb0233d94d05b89d8dab1ad192f5010d1282341 (patch)
tree5030fc6ad8743b4d86e1e91b7672d46335542b01
parent24cd1e066310ebabe6968c28d9ee2cd87bd28e26 (diff)
downloadlora_gateway_mtac_full-9eb0233d94d05b89d8dab1ad192f5010d1282341.tar.gz
lora_gateway_mtac_full-9eb0233d94d05b89d8dab1ad192f5010d1282341.tar.bz2
lora_gateway_mtac_full-9eb0233d94d05b89d8dab1ad192f5010d1282341.zip
Changed getopt path option to conform with other utilities
-rw-r--r--util_lbt_test/src/util_lbt_test.c46
-rw-r--r--util_tx_continuous/src/util_tx_continuous.c54
2 files changed, 56 insertions, 44 deletions
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 <unistd.h> /* getopt access */
#include <stdlib.h> /* rand */
#include <string.h> /* strncmp */
+#include <getopt.h> /* 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 <float> frequency in MHz of the first LBT channel\n");
- printf(" -o <int> offset in dB to be applied to the SX127x RSSI [-128..127]\n");
- printf(" -r <int> target RSSI: signal strength target used to detect if the channel is clear or not [-128..0]\n");
- printf(" -s <uint> scan time in µs for all 8 LBT channels [128,5000]\n");
- printf(" -p <string> path of SPIDEV e.g. /dev/spidev0.0\n");
+ printf(" -h print this help\n");
+ printf(" -f <float> frequency in MHz of the first LBT channel\n");
+ printf(" -o <int> offset in dB to be applied to the SX127x RSSI [-128..127]\n");
+ printf(" -r <int> target RSSI: signal strength target used to detect if the channel is clear or not [-128..0]\n");
+ printf(" -s <uint> scan time in µs for all 8 LBT channels [128,5000]\n");
+ printf(" --path <string> 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 <int> 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();
diff --git a/util_tx_continuous/src/util_tx_continuous.c b/util_tx_continuous/src/util_tx_continuous.c
index 6cf2999..aeaae8d 100644
--- a/util_tx_continuous/src/util_tx_continuous.c
+++ b/util_tx_continuous/src/util_tx_continuous.c
@@ -293,35 +293,35 @@ int main(int argc, char **argv)
}
break;
- case 'f':
- i = sscanf(optarg, "%f", &arg_f);
- if ((i != 1) || (arg_f < 1)) {
- printf("ERROR: argument parsing of -f argument. Use -h to print help\n");
- return EXIT_FAILURE;
- }
- else {
- freq_hz = (uint32_t)((arg_f * 1e6) + 0.5);
- }
- break;
-
- case 'r':
- i = sscanf(optarg, "%u", &arg_u);
- switch (arg_u) {
- case 1255:
- radio_type = LGW_RADIO_TYPE_SX1255;
- break;
- case 1257:
- radio_type = LGW_RADIO_TYPE_SX1257;
- break;
- default:
- printf("ERROR: argument parsing of -r argument. Use -h to print help\n");
+ case 'f':
+ i = sscanf(optarg, "%f", &arg_f);
+ if ((i != 1) || (arg_f < 1)) {
+ printf("ERROR: argument parsing of -f argument. Use -h to print help\n");
return EXIT_FAILURE;
- }
- break;
+ }
+ else {
+ freq_hz = (uint32_t)((arg_f * 1e6) + 0.5);
+ }
+ break;
- default:
- printf("ERROR: argument parsing options. Use -h to print help\n");
- return EXIT_FAILURE;
+ case 'r':
+ i = sscanf(optarg, "%u", &arg_u);
+ switch (arg_u) {
+ case 1255:
+ radio_type = LGW_RADIO_TYPE_SX1255;
+ break;
+ case 1257:
+ radio_type = LGW_RADIO_TYPE_SX1257;
+ break;
+ default:
+ printf("ERROR: argument parsing of -r argument. Use -h to print help\n");
+ return EXIT_FAILURE;
+ }
+ break;
+
+ default:
+ printf("ERROR: argument parsing options. Use -h to print help\n");
+ return EXIT_FAILURE;
}
}