diff options
author | Jason Reiss <jreiss@multitech.com> | 2022-12-21 09:52:50 -0600 |
---|---|---|
committer | Jason Reiss <jreiss@multitech.com> | 2022-12-21 09:52:50 -0600 |
commit | 70a1a032ec437864c806ee76719bbc24ebdc8300 (patch) | |
tree | c8d1139ef85f36f0b664356ce3b5267763651203 /libloragw | |
parent | 928c234b0ebec37f302d5c1e4b0c0f03b6e58d2d (diff) | |
download | lora_gateway_mtac_full-70a1a032ec437864c806ee76719bbc24ebdc8300.tar.gz lora_gateway_mtac_full-70a1a032ec437864c806ee76719bbc24ebdc8300.tar.bz2 lora_gateway_mtac_full-70a1a032ec437864c806ee76719bbc24ebdc8300.zip |
Bugfix: Calculate tmst diff over rollover correctly for cnt2utc and cnt2gps
Diffstat (limited to 'libloragw')
-rw-r--r-- | libloragw/src/loragw_gps.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/libloragw/src/loragw_gps.c b/libloragw/src/loragw_gps.c index b461439..bb37e1b 100644 --- a/libloragw/src/loragw_gps.c +++ b/libloragw/src/loragw_gps.c @@ -719,8 +719,9 @@ int lgw_cnt2utc(struct tref ref, uint32_t count_us, struct timespec *utc) { return LGW_GPS_ERROR; } - /* calculate delta in seconds between reference count_us and target count_us */ - if (count_us > ref.count_us) { + /* calculate delta in seconds between reference count_us and target count_us + calculate rollover diff, uint32 difference is OK */ + if (count_us > ref.count_us || ((ref.count_us & 0xFF000000) == 0xFF000000) && ((count_us & 0xFF000000) == 0)) delta_sec = (double)(count_us - ref.count_us) / (TS_CPS * ref.xtal_err); } else { delta_sec = -(double)(ref.count_us - count_us) / (TS_CPS * ref.xtal_err); @@ -782,8 +783,9 @@ int lgw_cnt2gps(struct tref ref, uint32_t count_us, struct timespec *gps_time) { return LGW_GPS_ERROR; } - /* calculate delta in seconds between reference count_us and target count_us */ - if (count_us > ref.count_us) { + /* calculate delta in seconds between reference count_us and target count_us + calculate rollover diff, uint32 difference is OK */ + if (count_us > ref.count_us || ((ref.count_us & 0xFF000000) == 0xFF000000) && ((count_us & 0xFF000000) == 0)) { delta_sec = (double)(count_us - ref.count_us) / (TS_CPS * ref.xtal_err); } else { delta_sec = -(double)(ref.count_us - count_us) / (TS_CPS * ref.xtal_err); |