summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Sharma <harsh.sharma@multitech.com>2021-12-02 14:40:37 -0600
committerHarsh Sharma <harsh.sharma@multitech.com>2021-12-02 14:40:37 -0600
commit7dfad6c35334110b9b7e26cb434af2dcca95d0aa (patch)
tree80e679d8d19c8f0ea0a79b7a69958126343b797d
parent6178d2a35ff4a788578fef4f5c0e40288eba7857 (diff)
downloadlora_gateway_mtac_full-7dfad6c35334110b9b7e26cb434af2dcca95d0aa.tar.gz
lora_gateway_mtac_full-7dfad6c35334110b9b7e26cb434af2dcca95d0aa.tar.bz2
lora_gateway_mtac_full-7dfad6c35334110b9b7e26cb434af2dcca95d0aa.zip
Fixed cnt diff and xtal err messing up gps sync5.0.10
-rw-r--r--libloragw/src/loragw_gps.c17
1 files 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;
}