From 25065e728b18fe174dd5f06396276f22ddb04ee2 Mon Sep 17 00:00:00 2001 From: Jason Reiss Date: Wed, 26 Oct 2022 12:13:59 -0500 Subject: gps: move cnt_diff check after calculation --- libloragw/src/loragw_gps.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libloragw/src/loragw_gps.c b/libloragw/src/loragw_gps.c index de0d495..d02e23a 100644 --- a/libloragw/src/loragw_gps.c +++ b/libloragw/src/loragw_gps.c @@ -640,6 +640,11 @@ int lgw_gps_sync(struct tref *ref, uint32_t count_us, struct timespec utc, struc CHECK_NULL(ref); + /* calculate the slope */ + + cnt_diff = (double)(count_us - ref->count_us) / (double)(TS_CPS); /* uncorrected by xtal_err */ + utc_diff = (double)(utc.tv_sec - (ref->utc).tv_sec) + (1E-9 * (double)(utc.tv_nsec - (ref->utc).tv_nsec)); + if (cnt_diff == 0.0 || last_count_us == count_us) { // no pps change from SX1301, invalidate system reference time ref->systime = 0; @@ -649,11 +654,6 @@ int lgw_gps_sync(struct tref *ref, uint32_t count_us, struct timespec utc, struc last_count_us = count_us; - /* calculate the slope */ - - cnt_diff = (double)(count_us - ref->count_us) / (double)(TS_CPS); /* uncorrected by xtal_err */ - utc_diff = (double)(utc.tv_sec - (ref->utc).tv_sec) + (1E-9 * (double)(utc.tv_nsec - (ref->utc).tv_nsec)); - /* detect aberrant points by measuring if slope limits are exceeded */ if (utc_diff != 0) { // prevent divide by zero slope = cnt_diff/utc_diff; -- cgit v1.2.3