From e4b66900abb578d3e3d7a1c15f0b31d637984f7b Mon Sep 17 00:00:00 2001 From: Jason Reiss Date: Mon, 24 Jan 2022 10:52:07 -0600 Subject: gps update only once per second --- libloragw/src/loragw_gps.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/libloragw/src/loragw_gps.c b/libloragw/src/loragw_gps.c index 3b19909..2698c4b 100644 --- a/libloragw/src/loragw_gps.c +++ b/libloragw/src/loragw_gps.c @@ -637,6 +637,10 @@ int lgw_gps_sync(struct tref *ref, uint32_t count_us, struct timespec gps_time) if (ref->systime != 0) { cnt_diff = (double)(count_us - ref->count_us) / (double)(TS_CPS); /* uncorrected by xtal_err */ utc_diff = (double)((gps_time.tv_sec - timezone) - (ref->utc).tv_sec) + (1E-9 * (double)(gps_time.tv_nsec - (ref->utc).tv_nsec)); + + if (!calibrating && utc_diff < 1.0) + return LGW_GPS_ERROR; + if (cnt_diff != 0 && utc_diff != 0) { // prevent divide by zero slope = cnt_diff/utc_diff; } else { @@ -645,12 +649,7 @@ int lgw_gps_sync(struct tref *ref, uint32_t count_us, struct timespec gps_time) update = (slope >= MINUS_10PPM && slope <= PLUS_10PPM); - if (cnt_diff > 1.5) { - update = true; - slope = 1.0; - } else if (!calibrating && utc_diff < 10.0) { - return LGW_GPS_ERROR; - } else if (calibrating && !update && utc_diff > 1.5) { + if (calibrating && !update && utc_diff > 1.5) { update = true; } else if (update) { calibrating = false; -- cgit v1.2.3