From 6667f456636ff66e0ebe3b0f6e1c0b8cb97af6c0 Mon Sep 17 00:00:00 2001 From: Colin Ru <103983752+HalterCru@users.noreply.github.com> Date: Tue, 28 May 2024 15:31:12 +1200 Subject: [PATCH] Revert "Revert "gs: Ignore stale tmms (#208)" (#209)" This reverts commit 81a629034296b2f00202d018e8086dae6f837f1b. --- pkg/ttnpb/udp/translation.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pkg/ttnpb/udp/translation.go b/pkg/ttnpb/udp/translation.go index d2eb31120b..638c9dfe91 100644 --- a/pkg/ttnpb/udp/translation.go +++ b/pkg/ttnpb/udp/translation.go @@ -29,10 +29,11 @@ import ( ) const ( - delta = 0.001 // For GPS comparisons - lora = "LORA" - fsk = "FSK" - lrfhss = "LR-FHSS" + gpsTimeDelta = 5 * time.Second // for validating tmms/GPS time + delta = 0.001 // For GPS comparisons + lora = "LORA" + fsk = "FSK" + lrfhss = "LR-FHSS" // eirpDelta is the delta between EIRP and ERP. eirpDelta = 2.15 @@ -201,8 +202,15 @@ func convertUplink(rx RxPacket, md UpstreamMetadata) (*ttnpb.UplinkMessage, erro var goTime, goGpsTime time.Time switch { case rx.Tmms != nil: - goGpsTime = gpstime.Parse(time.Duration(*rx.Tmms) * time.Millisecond) - goTime = goGpsTime + + ggt := gpstime.Parse(time.Duration(*rx.Tmms) * time.Millisecond) + currentUTC := time.Now().UTC() + diff := ggt.Sub(currentUTC).Abs().Seconds() + if diff < gpsTimeDelta.Seconds() { + goGpsTime = ggt + goTime = goGpsTime + } + case rx.Time != nil: goTime = time.Time(*rx.Time) }