summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Sharma <harsh.sharma@multitech.com>2020-02-03 16:17:19 -0600
committerHarsh Sharma <harsh.sharma@multitech.com>2020-02-03 16:17:19 -0600
commitdea57d6f29246434173c33c56850708c51fc5b23 (patch)
tree9934346f5279640039a45d3fca37f54f4b3ece04
parent228116b1958515947d208149cccbb8c9a9a6ab83 (diff)
downloadlora_gateway_mtac_full-dea57d6f29246434173c33c56850708c51fc5b23.tar.gz
lora_gateway_mtac_full-dea57d6f29246434173c33c56850708c51fc5b23.tar.bz2
lora_gateway_mtac_full-dea57d6f29246434173c33c56850708c51fc5b23.zip
Added spi dev option to reg utility and added error checking for lgw_connect, cleaned up unused variables in src_loragw_gps.c
-rw-r--r--libloragw/src/loragw_gps.c2
-rw-r--r--libloragw/tst/test_loragw_gps.c4
-rw-r--r--libloragw/tst/test_loragw_hal.c2
-rw-r--r--libloragw/tst/test_loragw_reg.c59
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 <string.h> /* memset */
#include <signal.h> /* sigaction */
#include <unistd.h> /* getopt access */
-#include <getopt.h> /* getopt_long */
+#include <getopt.h> /* 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 <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