summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Sharma <harsh.sharma@multitech.com>2022-05-06 13:46:01 -0500
committerHarsh Sharma <harsh.sharma@multitech.com>2022-05-06 13:46:01 -0500
commit79a392cb7d31c6b08f70511cc3921d30bbb7bec2 (patch)
tree99c07a044d95b6c528650bc6edf9d6ee6f77a7c0
parent14d273376d108fe6a20c8ff27ad0fa82e6ed6731 (diff)
downloadpacket_forwarder_mtac_full-79a392cb7d31c6b08f70511cc3921d30bbb7bec2.tar.gz
packet_forwarder_mtac_full-79a392cb7d31c6b08f70511cc3921d30bbb7bec2.tar.bz2
packet_forwarder_mtac_full-79a392cb7d31c6b08f70511cc3921d30bbb7bec2.zip
Updated gps thread to use gpsd stream4.0.22
-rw-r--r--lora_pkt_fwd/src/lora_pkt_fwd.c66
1 files changed, 29 insertions, 37 deletions
diff --git a/lora_pkt_fwd/src/lora_pkt_fwd.c b/lora_pkt_fwd/src/lora_pkt_fwd.c
index eba3c48..47662e6 100644
--- a/lora_pkt_fwd/src/lora_pkt_fwd.c
+++ b/lora_pkt_fwd/src/lora_pkt_fwd.c
@@ -206,8 +206,7 @@ static double xtal_correct = 1.0;
/* GPS configuration and synchronization */
static bool use_gps = false; /* Use the GPSD stream */
static bool gps_enabled = false; /* is GPS enabled on that gateway ? */
-static char gps_tty_path[64] = "\0"; /* path of the TTY port GPS is connected on */
-static int gps_tty_fd = -1; /* file descriptor of the GPS TTY port */
+
/* GPS time reference */
static pthread_mutex_t mx_timeref = PTHREAD_MUTEX_INITIALIZER; /* control access to GPS time reference */
static bool gps_ref_valid; /* is GPS reference acceptable (ie. not too old) */
@@ -1718,7 +1717,7 @@ int main(int argc, char** argv)
/* Start GPS a.s.a.p., to allow it to lock */
if (use_gps == true) {
- int i = lgw_gps_enable(gps_tty_path, "ubx7", 0, &gps_tty_fd, ((strcmp(lora_port, "ap2") == 0) ? 2 : 1));
+ int i = lgw_gps_enable();
if (i != LGW_GPS_SUCCESS) {
printf("WARNING: [main] impossible to open for GPS sync (Check GPSD)\n");
gps_enabled = false;
@@ -2094,13 +2093,7 @@ int main(int argc, char** argv)
if (gps_enabled == true) {
pthread_cancel(thrid_gps); /* don't wait for GPS thread */
-
- i = lgw_gps_disable(gps_tty_fd);
- if (i == LGW_HAL_SUCCESS) {
- MSG("INFO: GPS closed successfully\n");
- } else {
- MSG("WARNING: failed to close GPS successfully\n");
- }
+ lgw_gps_disable();
}
pthread_join(thrid_spectralscan, NULL); /* wait for spec scan thread */
@@ -3583,18 +3576,16 @@ static void gps_process_coords(void) {
void thread_gps(void) {
/* serial variables */
- char serial_buff[128]; /* buffer to receive GPS data */
+ char serial_buff[4096]; /* buffer to receive GPS data */
size_t wr_idx = 0; /* pointer to end of chars in buffer */
-
/* variables for PPM pulse GPS synchronization */
enum gps_msg latest_msg; /* keep track of latest NMEA message parsed */
- /* initialize some variables before loop */
- memset(serial_buff, 0, sizeof serial_buff);
-
uint8_t read_fail_count = 0;
+ uint8_t empty_packet_count = 0;
enum gps_state state = GPS_RUNNING;
int i;
+ memset(serial_buff, 0, sizeof serial_buff);
while (!exit_sig && !quit_sig) {
size_t rd_idx = 0;
@@ -3603,48 +3594,51 @@ void thread_gps(void) {
switch (state) {
case GPS_LOST: {
- i = lgw_gps_disable(gps_tty_fd);
- if (i == LGW_HAL_SUCCESS) {
- MSG("INFO: GPS closed successfully\n");
- } else {
- MSG("WARNING: failed to close GPS successfully\n");
- }
+ lgw_gps_disable();
+ MSG("INFO: GPS closed\n");
+ empty_packet_count = 0;
read_fail_count = 0;
- state = GPS_RETRYING;
+ state = GPS_RECONNECTING;
wait_ms(5000);
continue;
}
- case GPS_RETRYING: {
- i = lgw_gps_enable(gps_tty_path, "ubx7", 0, &gps_tty_fd, ((strcmp(lora_port, "ap2") == 0) ? 2 : 1));
+ case GPS_RECONNECTING: {
+ /* try and reestablish connection */
+ i = lgw_gps_enable();
if (i != LGW_GPS_SUCCESS) {
printf("WARNING: [main] impossible to open for GPS sync (Check GPSD)\n");
gps_enabled = false;
gps_ref_valid = false;
+ wait_ms(2000);
+ continue;
} else {
printf("INFO: [main] GPSD polling open for GPS synchronization\n");
gps_enabled = true;
gps_ref_valid = false;
- }
- nb_char = read(gps_tty_fd, serial_buff + wr_idx, LGW_GPS_MIN_MSG_SIZE);
- if (nb_char <= 0) {
- printf("WARNING: [gps] reconnect failed\n");
- wait_ms(2000);
- continue;
- } else {
- printf("INFO: [gps] reconnected\n");
state = GPS_RUNNING;
- break;
+ wait_ms(1000);
+ continue;
}
}
case GPS_RUNNING: {
- nb_char = read(gps_tty_fd, serial_buff + wr_idx, LGW_GPS_MIN_MSG_SIZE);
+ int result = lgw_gps_data_ready();
+
+ if (result != 1) {
+ empty_packet_count++;
+ if (empty_packet_count > 9) {
+ state = GPS_LOST;
+ }
+ continue;
+ }
+ /* reading directly from the socket avoids decode overhead */
+ nb_char = lgw_gps_stream(serial_buff + wr_idx, sizeof(serial_buff) - wr_idx);
if (nb_char <= 0) {
printf("WARNING: [gps] read() returned value %zd\n", nb_char);
read_fail_count++;
if (read_fail_count > 9) {
state = GPS_LOST;
- continue;
}
+ continue;
}
break;
}
@@ -3886,8 +3880,6 @@ void thread_spectralscan(void) {
while (!exit_sig && !quit_sig) {
wait_ms(1000);
gettimeofday(&tv, NULL);
- long hms = tv.tv_sec % 86400;
- int min = (hms % 3600) / 60;
pthread_mutex_lock(&mx_scan_config);
if (scan_config_new.read == false) {
scan_config = scan_config_new;