From 7dfad6c35334110b9b7e26cb434af2dcca95d0aa Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Thu, 2 Dec 2021 14:40:37 -0600 Subject: Fixed cnt diff and xtal err messing up gps sync --- libloragw/src/loragw_gps.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/libloragw/src/loragw_gps.c b/libloragw/src/loragw_gps.c index 7eece2c..3b19909 100644 --- a/libloragw/src/loragw_gps.c +++ b/libloragw/src/loragw_gps.c @@ -637,20 +637,20 @@ 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 (cnt_diff != 0 && utc_diff != 0) { // prevent divide by zero slope = cnt_diff/utc_diff; } else { - slope = 0.0; + slope = 0.0; } update = (slope >= MINUS_10PPM && slope <= PLUS_10PPM); - if (!calibrating && utc_diff < 10.0) { + if (cnt_diff > 1.5) { + update = true; + slope = 1.0; + } else if (!calibrating && utc_diff < 10.0) { return LGW_GPS_ERROR; - } - - if (calibrating && !update && utc_diff > 1.5) { + } else if (calibrating && !update && utc_diff > 1.5) { update = true; } else if (update) { calibrating = false; @@ -658,7 +658,7 @@ int lgw_gps_sync(struct tref *ref, uint32_t count_us, struct timespec gps_time) } else { update = true; - slope = 0.0; + slope = 1.0; } if (update || calibrating) { @@ -666,10 +666,9 @@ int lgw_gps_sync(struct tref *ref, uint32_t count_us, struct timespec gps_time) ref->count_us = count_us; ref->utc.tv_sec = gps_time.tv_sec - timezone; ref->utc.tv_nsec = gps_time.tv_nsec; - // ref->gps.tv_sec = gps_time.tv_sec; ref->gps.tv_sec = gps_time.tv_sec + leap_seconds - 315964800; ref->gps.tv_nsec = gps_time.tv_nsec; - ref->xtal_err = slope; + ref->xtal_err = (slope >= MINUS_10PPM && slope <= PLUS_10PPM) ? slope : 1.0; return LGW_GPS_SUCCESS; } -- cgit v1.2.3