From 857e83833cadd1365e4a4f284200cdb900bd8eed Mon Sep 17 00:00:00 2001 From: Jason Reiss Date: Mon, 24 Jan 2022 10:54:22 -0600 Subject: wait 32s before scheduling beacons --- lora_pkt_fwd/src/lora_pkt_fwd.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lora_pkt_fwd/src/lora_pkt_fwd.c b/lora_pkt_fwd/src/lora_pkt_fwd.c index 6d87f91..193ef57 100644 --- a/lora_pkt_fwd/src/lora_pkt_fwd.c +++ b/lora_pkt_fwd/src/lora_pkt_fwd.c @@ -334,6 +334,11 @@ void thread_jit(void); void thread_timersync(void); void thread_spectralscan(void); + +struct timespec start_time; +struct timespec check_time; + + /* -------------------------------------------------------------------------- */ /* --- PRIVATE FUNCTIONS DEFINITION ----------------------------------------- */ @@ -1886,9 +1891,6 @@ int main(int argc, char** argv) sigaction(SIGHUP, &sighupact, NULL); /* rotate logfile on HUP */ signal(SIGPIPE, SIG_IGN); /* ignore writes after closing socket */ - struct timespec start_time; - struct timespec check_time; - clock_gettime(CLOCK_MONOTONIC, &start_time); /* main loop task : statistics collection */ @@ -2851,7 +2853,7 @@ void thread_down(void) { while (beacon_loop && (beacon_period != 0)) { pthread_mutex_lock(&mx_timeref); /* Wait for GPS to be ready before inserting beacons in JiT queue */ - if ((gps_ref_valid == true)) { + if ((gps_ref_valid == true) && (int)difftimespec(recv_time, start_time) > 32)) { if (time_reference_gps.gps.tv_sec < last_beacon_gps_time.tv_sec + 128 || (time_reference_gps.gps.tv_sec - last_beacon_gps_time.tv_sec) > (time_t)(beacon_period * (JIT_NUM_BEACON_IN_QUEUE+1))) { @@ -3555,8 +3557,12 @@ void thread_gps(void) { /* try to update time reference with the new GPS time & timestamp */ pthread_mutex_lock(&mx_timeref); - lgw_gps_sync(&time_reference_gps, trig_tstamp, gpsdata.fix.time); + i = lgw_gps_sync(&time_reference_gps, trig_tstamp, gpsdata.fix.time); pthread_mutex_unlock(&mx_timeref); + + if (i != LGW_GPS_SUCCESS) { + MSG("WARNING: [gps] GPS out of sync, keeping previous time reference\n"); + } } else { gps_coord_valid = false; } -- cgit v1.2.3