From a0a94c3336574482d16fa910e94d7f07bba60123 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Thu, 2 Jan 2020 13:57:50 -0600 Subject: Added spidev to the commandline options for the util_spi_stress --- util_spi_stress/src/util_spi_stress.c | 37 ++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/util_spi_stress/src/util_spi_stress.c b/util_spi_stress/src/util_spi_stress.c index 6cc5f04..c33f18f 100644 --- a/util_spi_stress/src/util_spi_stress.c +++ b/util_spi_stress/src/util_spi_stress.c @@ -31,6 +31,7 @@ Maintainer: Sylvain Miermont #include /* sigaction */ #include /* getopt access */ #include /* rand */ +#include /* getopt_long */ #include "loragw_reg.h" @@ -77,8 +78,9 @@ static void sig_handler(int sigio) { /* describe command line options */ void usage(void) { MSG( "Available options:\n"); - MSG( " -h print this help\n"); - MSG( " -t specify which test you want to run (1-4)\n"); + MSG( " -h Print this help\n"); + MSG( " -t Specify which test you want to run (1-4)\n"); + MSG( " --path Path of SPIDEV e.g. /dev/spidev0.0\n"); } /* -------------------------------------------------------------------------- */ @@ -105,8 +107,15 @@ int main(int argc, char **argv) uint8_t test_buff[BUFF_SIZE]; uint8_t read_buff[BUFF_SIZE]; + 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, "ht:")) != -1) { + while ((i = getopt_long (argc, argv, "ht:", long_options, &option_index)) != -1) { switch (i) { case 'h': usage(); @@ -123,6 +132,24 @@ int main(int argc, char **argv) } 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 { + MSG("ERROR: argument parsing use -h option for help\n"); + usage(); + return EXIT_FAILURE; + } + break; + default: MSG("ERROR: argument parsing use -h option for help\n"); usage(); @@ -142,7 +169,7 @@ int main(int argc, char **argv) /* start SPI link */ i = lgw_connect(false, DEFAULT_TX_NOTCH_FREQ); if (i != LGW_REG_SUCCESS) { - MSG("ERROR: lgw_connect() did not return SUCCESS"); + MSG("ERROR: Unable to connect to the concentrator\n"); return EXIT_FAILURE; } @@ -160,7 +187,7 @@ int main(int argc, char **argv) } } if (error) { - printf("error during the %ith iteration: write 0x%02X, read 0x%02X\n", i+1, test_value, read_value); + printf("Error during the %ith iteration: write 0x%02X, read 0x%02X\n", i+1, test_value, read_value); printf("Repeat read of target register:"); for (i=0; i