diff options
Diffstat (limited to 'libloragw/tst')
-rw-r--r-- | libloragw/tst/test_loragw_cal.c | 44 | ||||
-rw-r--r-- | libloragw/tst/test_loragw_gps.c | 4 | ||||
-rw-r--r-- | libloragw/tst/test_loragw_hal.c | 31 | ||||
-rw-r--r-- | libloragw/tst/test_loragw_reg.c | 59 | ||||
-rw-r--r-- | libloragw/tst/test_loragw_spi.c | 119 |
5 files changed, 224 insertions, 33 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 <signal.h> /* sigaction */ #include <math.h> /* cos */ #include <unistd.h> /* getopt access */ +#include <getopt.h> /* 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 <float> Radio A frequency in MHz\n"); - printf( " -b <float> Radio B frequency in MHz\n"); - printf( " -r <int> Radio type (SX1255:1255, SX1257:1257)\n"); - printf( " -n <uint> Number of calibration iterations\n"); - printf( " -k <int> Concentrator clock source (0:radio_A, 1:radio_B(default))\n"); - printf( " -t <int> 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 <float> Radio A frequency in MHz\n"); + printf( " -b <float> Radio B frequency in MHz\n"); + printf( " -r <int> Radio type (SX1255:1255, SX1257:1257)\n"); + printf( " -n <uint> Number of calibration iterations\n"); + printf( " -k <int> Concentrator clock source (0:radio_A, 1:radio_B(default))\n"); + printf( " -t <int> Radio to run TX calibration on (0:None(default), 1:radio_A, 2:radio_B, 3:both)\n"); + printf(" --path <string> 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(); 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 e2fee5e..37e8b42 100644 --- a/libloragw/tst/test_loragw_hal.c +++ b/libloragw/tst/test_loragw_hal.c @@ -30,7 +30,9 @@ Maintainer: Sylvain Miermont #include <string.h> /* memset */ #include <signal.h> /* sigaction */ #include <unistd.h> /* getopt access */ +#include <getopt.h> /* 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 <float> Radio TX frequency in MHz\n"); printf( " -r <int> Radio type (SX1255:1255, SX1257:1257)\n"); printf( " -k <int> Concentrator clock source (0: radio_A, 1: radio_B(default))\n"); + printf(" --path <string> 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; } 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 <stdint.h> #include <stdio.h> +#include <string.h> +#include <getopt.h> /* 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 <string> 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 diff --git a/libloragw/tst/test_loragw_spi.c b/libloragw/tst/test_loragw_spi.c index 872a075..4d06eaa 100644 --- a/libloragw/tst/test_loragw_spi.c +++ b/libloragw/tst/test_loragw_spi.c @@ -19,8 +19,11 @@ Maintainer: Sylvain Miermont /* --- DEPENDANCIES --------------------------------------------------------- */ #include <stdint.h> +#include <string.h> #include <stdio.h> +#include <getopt.h> /* getopt_long */ +#include "loragw_hal.h" #include "loragw_spi.h" /* -------------------------------------------------------------------------- */ @@ -37,7 +40,7 @@ Maintainer: Sylvain Miermont /* -------------------------------------------------------------------------- */ /* --- MAIN FUNCTION -------------------------------------------------------- */ -int main() +int main(int argc, char **argv) { int i; void *spi_target = NULL; @@ -46,37 +49,119 @@ int main() uint8_t datain[BURST_TEST_SIZE]; uint8_t spi_mux_mode = LGW_SPI_MUX_MODE0; + /* Parameter parsing */ + int option_index = 0; + static struct option long_options[] = { + {"path", 1, 0, 0}, + {0, 0, 0, 0} + }; + char arg_s[64]; + + while ((i = getopt_long (argc, argv, "h", long_options, &option_index)) != -1) { + switch (i) { + case 'h': + printf("~~~ Library version string~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); + printf(" %s\n", lgw_version_info()); + printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); + printf(" --path <string> Path of SPIDEV e.g. /dev/spidev0.0\n"); + printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); + return 0; + 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 LGW_SPI_ERROR; + } + else { + lgw_spi_set_path(arg_s); + } + } + else { + printf("ERROR: argument parsing options. Use -h to print help\n"); + return LGW_SPI_ERROR; + } + break; + + default: + printf("ERROR: argument parsing options. Use -h to print help\n"); + return LGW_SPI_ERROR; + } + } + for (i = 0; i < BURST_TEST_SIZE; ++i) { dataout[i] = 0x30 + (i % 10); /* ASCCI code for 0 -> 9 */ datain[i] = 0x23; /* garbage data, to be overwritten by received data */ } printf("Beginning of test for loragw_spi.c\n"); - lgw_spi_open(&spi_target); + + int spi_stat = lgw_spi_open(&spi_target); + + if (spi_stat != LGW_SPI_SUCCESS) { + printf("ERROR: Unable to connect to concentrator\n"); + return LGW_SPI_ERROR; + } /* normal R/W test */ - for (i = 0; i < TIMING_REPEAT; ++i) - lgw_spi_w(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0xAA, 0x96); - for (i = 0; i < TIMING_REPEAT; ++i) - lgw_spi_r(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, &data); + for (i = 0; i < TIMING_REPEAT; ++i) { + spi_stat = lgw_spi_w(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0xAA, 0x96); + if (spi_stat != LGW_SPI_SUCCESS) { + printf("ERROR: Failed write normal R/W test\n"); + return LGW_SPI_ERROR; + } + } + for (i = 0; i < TIMING_REPEAT; ++i) { + spi_stat = lgw_spi_r(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, &data); + if (spi_stat != LGW_SPI_SUCCESS) { + printf("ERROR: Failed read normal R/W test\n"); + return LGW_SPI_ERROR; + } + } /* burst R/W test, small bursts << LGW_BURST_CHUNK */ - for (i = 0; i < TIMING_REPEAT; ++i) - lgw_spi_wb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, dataout, 16); - for (i = 0; i < TIMING_REPEAT; ++i) - lgw_spi_rb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, datain, 16); + for (i = 0; i < TIMING_REPEAT; ++i) { + spi_stat = lgw_spi_wb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, dataout, 16); + if (spi_stat != LGW_SPI_SUCCESS) { + printf("ERROR: Failed write small burst R/W test\n"); + return LGW_SPI_ERROR; + } + } + for (i = 0; i < TIMING_REPEAT; ++i) { + spi_stat = lgw_spi_rb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, datain, 16); + if (spi_stat != LGW_SPI_SUCCESS) { + printf("ERROR: Failed read small burst R/W test\n"); + return LGW_SPI_ERROR; + } + } /* burst R/W test, large bursts >> LGW_BURST_CHUNK */ - for (i = 0; i < TIMING_REPEAT; ++i) - lgw_spi_wb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x5A, dataout, ARRAY_SIZE(dataout)); - for (i = 0; i < TIMING_REPEAT; ++i) - lgw_spi_rb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x5A, datain, ARRAY_SIZE(datain)); + for (i = 0; i < TIMING_REPEAT; ++i) { + spi_stat = lgw_spi_wb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x5A, dataout, ARRAY_SIZE(dataout)); + if (spi_stat != LGW_SPI_SUCCESS) { + printf("ERROR: Failed write large burst R/W test\n"); + return LGW_SPI_ERROR; + } + } + for (i = 0; i < TIMING_REPEAT; ++i) { + spi_stat = lgw_spi_rb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x5A, datain, ARRAY_SIZE(datain)); + if (spi_stat != LGW_SPI_SUCCESS) { + printf("ERROR: Failed read large burst R/W test\n"); + return LGW_SPI_ERROR; + } + } /* last read (blocking), just to be sure no to quit before the FTDI buffer is flushed */ - lgw_spi_r(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, &data); - printf("data received (simple read): %d\n",data); - + spi_stat = lgw_spi_r(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, &data); + if (spi_stat != LGW_SPI_SUCCESS) { + printf("ERROR: Failed to read last block\n"); + return LGW_SPI_ERROR; + } lgw_spi_close(spi_target); + + printf("data received (simple read): %d\n",data); printf("End of test for loragw_spi.c\n"); return 0; |