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) }