From dea57d6f29246434173c33c56850708c51fc5b23 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Mon, 3 Feb 2020 16:17:19 -0600 Subject: Added spi dev option to reg utility and added error checking for lgw_connect, cleaned up unused variables in src_loragw_gps.c --- libloragw/src/loragw_gps.c | 2 -- libloragw/tst/test_loragw_gps.c | 4 +-- libloragw/tst/test_loragw_hal.c | 2 +- libloragw/tst/test_loragw_reg.c | 59 +++++++++++++++++++++++++++++++++++++++-- 4 files changed, 59 insertions(+), 8 deletions(-) diff --git a/libloragw/src/loragw_gps.c b/libloragw/src/loragw_gps.c index bd728b6..19c2f83 100644 --- a/libloragw/src/loragw_gps.c +++ b/libloragw/src/loragw_gps.c @@ -89,8 +89,6 @@ static bool gps_lock_ok = false; static char gps_mod = 'N'; /* GPS mode (N no fix, A autonomous, D differential) */ static short gps_sat = 0; /* number of satellites used for fix */ -static struct termios ttyopt_restore; - /* -------------------------------------------------------------------------- */ /* --- PRIVATE FUNCTIONS DECLARATION ---------------------------------------- */ diff --git a/libloragw/tst/test_loragw_gps.c b/libloragw/tst/test_loragw_gps.c index 6e644f8..fd8c61b 100644 --- a/libloragw/tst/test_loragw_gps.c +++ b/libloragw/tst/test_loragw_gps.c @@ -146,11 +146,9 @@ int main() /* serial variables */ char serial_buff[128]; /* buffer to receive GPS data */ - size_t wr_idx = 0; /* pointer to end of chars in buffer */ - int gps_tty_dev; /* file descriptor to the serial port of the GNSS module */ /* NMEA/UBX variables */ - enum gps_msg latest_msg; /* keep track of latest NMEA/UBX message parsed */ + enum gps_msg latest_msg = UNKNOWN; /* keep track of latest NMEA/UBX message parsed */ fd_set fds; char delim[4] = "$"; diff --git a/libloragw/tst/test_loragw_hal.c b/libloragw/tst/test_loragw_hal.c index 3bdd7b2..37e8b42 100644 --- a/libloragw/tst/test_loragw_hal.c +++ b/libloragw/tst/test_loragw_hal.c @@ -30,7 +30,7 @@ Maintainer: Sylvain Miermont #include /* memset */ #include /* sigaction */ #include /* getopt access */ -#include /* getopt_long */ +#include /* getopt_long */ #include "loragw_spi.h" #include "loragw_hal.h" diff --git a/libloragw/tst/test_loragw_reg.c b/libloragw/tst/test_loragw_reg.c index 37a6f5a..6248a1b 100644 --- a/libloragw/tst/test_loragw_reg.c +++ b/libloragw/tst/test_loragw_reg.c @@ -19,15 +19,27 @@ Maintainer: Sylvain Miermont #include #include +#include +#include /* getopt_long */ +#include "loragw_hal.h" #include "loragw_reg.h" +#include "loragw_spi.h" /* -------------------------------------------------------------------------- */ /* --- MAIN FUNCTION -------------------------------------------------------- */ #define BURST_TEST_LENGTH 8192 -int main() +/* describe command line options */ +void usage(void) { + printf("Library version information: %s\n", lgw_version_info()); + printf( "Available options:\n"); + printf( " -h print this help\n"); + printf(" --path path of SPIDEV e.g. /dev/spidev0.0\n"); +} + +int main(int argc, char **argv) { int32_t read_value, test_value; uint16_t lfsr; @@ -35,9 +47,52 @@ int main() uint8_t burst_buffin[BURST_TEST_LENGTH]; int i; + /* 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_long (argc, argv, "h", long_options, &option_index)) != -1) { + switch (i) { + case 'h': + usage(); + return -1; + 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(); + return -1; + } + } + + printf("Beginning of test for loragw_reg.c\n"); - lgw_connect(false, 129E3); + int result = lgw_connect(false, 129E3); + if (result == -1) { + printf("ERROR: Failed to connect to the board\n"); + return -1; + } /* 2 SPI transactions: -> 0x80 0x00 <- 0x00 0x00 forcing page 0 -> 0x01 0x00 <- 0x00 0x64 checking version -- cgit v1.2.3