summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libloragw/src/loragw_gps.c11
1 files 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;