summaryrefslogtreecommitdiff
path: root/util_spi_stress
diff options
context:
space:
mode:
Diffstat (limited to 'util_spi_stress')
-rw-r--r--util_spi_stress/src/util_spi_stress.c37
1 files 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 <signal.h> /* sigaction */
#include <unistd.h> /* getopt access */
#include <stdlib.h> /* rand */
+#include <getopt.h> /* 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 <int> specify which test you want to run (1-4)\n");
+ MSG( " -h Print this help\n");
+ MSG( " -t <uint> Specify which test you want to run (1-4)\n");
+ MSG( " --path <string> 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<READS_WHEN_ERROR; ++i) {
lgw_reg_r(LGW_IMPLICIT_PAYLOAD_LENGHT, &read_value);