summaryrefslogtreecommitdiff
path: root/libloragw/tst/test_loragw_reg.c
diff options
context:
space:
mode:
Diffstat (limited to 'libloragw/tst/test_loragw_reg.c')
-rw-r--r--libloragw/tst/test_loragw_reg.c59
1 files changed, 57 insertions, 2 deletions
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