From 4d124a9a373c3b9a057519ee167e73423764468d Mon Sep 17 00:00:00 2001 From: Jamie Wark Date: Tue, 21 May 2024 13:35:04 +1200 Subject: [PATCH] gs: drop tmms if invalid --- pkg/ttnpb/udp/translation.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg/ttnpb/udp/translation.go b/pkg/ttnpb/udp/translation.go index d2eb31120bb..2eae5470ca4 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,14 @@ 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) + + if time.Now().Add(gpsTimeDelta).After(ggt) && ggt.Add(gpsTimeDelta).Before(time.Now()) { + goGpsTime = ggt + goTime = goGpsTime + } + case rx.Time != nil: goTime = time.Time(*rx.Time) }