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