From 5124f5ef9baec5db7d6a30f1e3fd1653cd1667ef Mon Sep 17 00:00:00 2001 From: Cyril Brulebois Date: Fri, 8 Jan 2021 21:48:09 +0100 Subject: [PATCH] Get current UNIX time after getting concentrator's time lgw_get_trigcnt() performs a read from hardware, which can be delayed for whatever reason. Instead of looking at the clock before accessing hardware, do that *after* the concentrator's time has been obtained. This solves a number of intermittent errors of this type: ERROR: Packet REJECTED (jit error=2) --- lora_pkt_fwd/src/timersync.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lora_pkt_fwd/src/timersync.c b/lora_pkt_fwd/src/timersync.c index c0f488c..21102a2 100644 --- a/lora_pkt_fwd/src/timersync.c +++ b/lora_pkt_fwd/src/timersync.c @@ -92,12 +92,12 @@ void thread_timersync(void) { struct timeval offset_drift = {0, 0}; /* delta between current and previous offset */ while (!exit_sig && !quit_sig) { - /* Get current unix time */ - gettimeofday(&unix_timeval, NULL); - /* Get current concentrator counter value (1MHz) */ lgw_get_trigcnt(&sx1301_timecount); + /* Get current unix time */ + gettimeofday(&unix_timeval, NULL); + concentrator_timeval.tv_sec = sx1301_timecount / 1000000UL; concentrator_timeval.tv_usec = sx1301_timecount - (concentrator_timeval.tv_sec * 1000000UL); -- 2.11.0