From 3b7195f39bb90e269e008adf2736441943ee7f63 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Thu, 5 May 2022 17:07:33 -0500 Subject: Updated gps handlers to use gpsd stream --- libloragw/src/loragw_gps.c | 78 ++++++++++++---------------------------------- 1 file changed, 20 insertions(+), 58 deletions(-) (limited to 'libloragw/src') diff --git a/libloragw/src/loragw_gps.c b/libloragw/src/loragw_gps.c index 43ec0bc..e13b85b 100644 --- a/libloragw/src/loragw_gps.c +++ b/libloragw/src/loragw_gps.c @@ -19,7 +19,6 @@ Maintainer: Michael Coracin /* -------------------------------------------------------------------------- */ /* --- DEPENDANCIES --------------------------------------------------------- */ -#define _GNU_SOURCE /* needed for qsort_r to be defined */ #include /* C99 types */ #include /* bool type */ #include /* printf fprintf */ @@ -59,19 +58,7 @@ Maintainer: Michael Coracin #define UBX_MSG_NAVTIMEGPS_LEN 16 -char* fifo_name; -FILE* pipe_fd; - -#define FIFO_1_NAME "/dev/gps1.fifo" -#define FIFO_2_NAME "/dev/gps2.fifo" - -char fifo_1_make[] = "mkfifo " FIFO_1_NAME; -char fifo_1_pipe[] = "gpspipe -R -r -o " FIFO_1_NAME; -char fifo_1_kill[] = "pkill -f \"gpspipe.*" FIFO_1_NAME "\""; - -char fifo_2_make[] = "mkfifo " FIFO_2_NAME; -char fifo_2_pipe[] = "gpspipe -R -r -o " FIFO_2_NAME; -char fifo_2_kill[] = "pkill -f \"gpspipe.*" FIFO_2_NAME "\""; +static struct gps_data_t gpsdata; /* -------------------------------------------------------------------------- */ /* --- PRIVATE VARIABLES ---------------------------------------------------- */ @@ -267,40 +254,18 @@ int str_chop(char *s, int buff_size, char separator, int *idx_ary, int max_idx) /* -------------------------------------------------------------------------- */ /* --- PUBLIC FUNCTIONS DEFINITION ------------------------------------------ */ -int lgw_gps_enable(char *tty_path, char *gps_family, speed_t target_brate, int *fd_ptr, int slot) { - int i; - int gps_tty_dev; /* file descriptor to the serial port of the GNSS module */ - - /* check input parameters */ - CHECK_NULL(tty_path); - CHECK_NULL(fd_ptr); - - struct stat buf; - - if (slot == 1) { - if (stat(FIFO_1_NAME, &buf) != 0) { - system(fifo_1_make); - } - system(fifo_1_kill); - pipe_fd = popen(fifo_1_pipe, "r"); - fifo_name = FIFO_1_NAME; - } else { - if (stat(FIFO_2_NAME, &buf) != 0) { - system(fifo_2_make); - } - system(fifo_2_kill); - pipe_fd = popen(fifo_2_pipe, "r"); - fifo_name = FIFO_2_NAME; - } - - /* open gps fifo */ - gps_tty_dev = open(fifo_name, O_RDONLY ); +int lgw_gps_enable() { + unsigned int flags; + struct fixsource_t source; + flags |= WATCH_RAW; /* super-raw data (gps binary) */ + flags |= WATCH_NMEA; /* raw NMEA */ + gpsd_source_spec(NULL, &source); - if (gps_tty_dev <= 0) { - printf("ERROR: TTY PORT FAIL TO OPEN, CHECK PATH AND ACCESS RIGHTS\n"); + if (gps_open(source.server, source.port, &gpsdata) != 0) { return LGW_GPS_ERROR; } - *fd_ptr = gps_tty_dev; + + (void)gps_stream(&gpsdata, flags, source.device); /* get timezone info */ tzset(); @@ -315,23 +280,20 @@ int lgw_gps_enable(char *tty_path, char *gps_family, speed_t target_brate, int * /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -int lgw_gps_disable(int fd) { - int i; +int lgw_gps_disable() { + (void)gps_close(&gpsdata); +} - i = close(fd); - i = pclose(pipe_fd); +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ - if (memcmp(fifo_name, FIFO_1_NAME, 14) == 0) - system("rm /dev/gps1.fifo"); - else - system("rm /dev/gps2.fifo"); +int lgw_gps_data_ready() { + return nanowait(gpsdata.gps_fd, NS_IN_SEC); +} - if (i != 0) { - DEBUG_MSG("ERROR: TTY PORT FAIL TO CLOSE - %s\n", strerror(errno)); - return LGW_GPS_ERROR; - } +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ - return LGW_GPS_SUCCESS; +int lgw_gps_stream(char *message, size_t len) { + return recv(gpsdata.gps_fd, message, len, 0); } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -- cgit v1.2.3