From febb8372c248a11007eee7ea0267178f0dec61ee Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Mon, 3 Feb 2020 15:14:42 -0600 Subject: Added spi path option to test loragw hal --- libloragw/tst/test_loragw_hal.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/libloragw/tst/test_loragw_hal.c b/libloragw/tst/test_loragw_hal.c index e2fee5e..3bdd7b2 100644 --- a/libloragw/tst/test_loragw_hal.c +++ b/libloragw/tst/test_loragw_hal.c @@ -30,7 +30,9 @@ Maintainer: Sylvain Miermont #include /* memset */ #include /* sigaction */ #include /* getopt access */ +#include /* getopt_long */ +#include "loragw_spi.h" #include "loragw_hal.h" #include "loragw_reg.h" #include "loragw_aux.h" @@ -78,6 +80,7 @@ void usage(void) { printf( " -t Radio TX frequency in MHz\n"); printf( " -r Radio type (SX1255:1255, SX1257:1257)\n"); printf( " -k Concentrator clock source (0: radio_A, 1: radio_B(default))\n"); + printf(" --path path of SPIDEV e.g. /dev/spidev0.0\n"); } /* -------------------------------------------------------------------------- */ @@ -107,8 +110,16 @@ int main(int argc, char **argv) double xd = 0.0; int xi = 0; + /* Parameter parsing */ + int option_index = 0; + static struct option long_options[] = { + {"path", 1, 0, 0}, + {0, 0, 0, 0} + }; + char arg_s[64]; + /* parse command line options */ - while ((i = getopt (argc, argv, "ha:b:t:r:k:")) != -1) { + while ((i = getopt_long (argc, argv, "ha:b:r:n:k:t:", long_options, &option_index)) != -1) { switch (i) { case 'h': usage(); @@ -145,6 +156,22 @@ int main(int argc, char **argv) sscanf(optarg, "%i", &xi); clocksource = (uint8_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 -1; + } + else { + lgw_spi_set_path(arg_s); + } + } + else { + printf("ERROR: argument parsing options. Use -h to print help\n"); + return -1; + } + break; default: printf("ERROR: argument parsing\n"); usage(); @@ -307,7 +334,7 @@ int main(int argc, char **argv) if (i == LGW_HAL_SUCCESS) { printf("*** Concentrator started ***\n"); } else { - printf("*** Impossible to start concentrator ***\n"); + printf("*** Unable to start concentrator ***\n"); return -1; } -- cgit v1.2.3