From ac8d94851bb1a0bb22cd9815a483e8ed2a99e8f5 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Mon, 3 Feb 2020 15:06:52 -0600 Subject: Added spi path option to test_loragw_cal --- libloragw/tst/test_loragw_cal.c | 44 ++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/libloragw/tst/test_loragw_cal.c b/libloragw/tst/test_loragw_cal.c index 533d189..60c5ce7 100644 --- a/libloragw/tst/test_loragw_cal.c +++ b/libloragw/tst/test_loragw_cal.c @@ -31,12 +31,13 @@ Maintainer: Sylvain Miermont #include /* sigaction */ #include /* cos */ #include /* getopt access */ +#include /* getopt_long */ #include "loragw_hal.h" #include "loragw_reg.h" #include "loragw_aux.h" #include "loragw_radio.h" - +#include "loragw_spi.h" /* -------------------------------------------------------------------------- */ /* --- PRIVATE MACROS ------------------------------------------------------- */ @@ -99,13 +100,14 @@ void usage (void); void usage(void) { printf("Library version information: %s\n", lgw_version_info()); printf( "Available options:\n"); - printf( " -h print this help\n"); - printf( " -a Radio A frequency in MHz\n"); - printf( " -b Radio B frequency in MHz\n"); - printf( " -r Radio type (SX1255:1255, SX1257:1257)\n"); - printf( " -n Number of calibration iterations\n"); - printf( " -k Concentrator clock source (0:radio_A, 1:radio_B(default))\n"); - printf( " -t Radio to run TX calibration on (0:None(default), 1:radio_A, 2:radio_B, 3:both)\n"); + printf( " -h print this help\n"); + printf( " -a Radio A frequency in MHz\n"); + printf( " -b Radio B frequency in MHz\n"); + printf( " -r Radio type (SX1255:1255, SX1257:1257)\n"); + printf( " -n Number of calibration iterations\n"); + printf( " -k Concentrator clock source (0:radio_A, 1:radio_B(default))\n"); + printf( " -t Radio to run TX calibration on (0:None(default), 1:radio_A, 2:radio_B, 3:both)\n"); + printf(" --path path of SPIDEV e.g. /dev/spidev0.0\n"); } /* -------------------------------------------------------------------------- */ @@ -142,8 +144,16 @@ int main(int argc, char **argv) uint8_t tx_enable = 0; int nb_cal = 5; + /* 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:r:n:k:t:")) != -1) { + while ((i = getopt_long (argc, argv, "ha:b:r:n:k:t:", long_options, &option_index)) != -1) { switch (i) { case 'h': usage(); @@ -190,6 +200,22 @@ int main(int argc, char **argv) sscanf(optarg, "%i", &xi); tx_enable = (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(); -- cgit v1.2.3