From c7a25433f7cc90b7d302eae1a4e13625be9d7a5a Mon Sep 17 00:00:00 2001 From: Orne Brocaar Date: Mon, 1 Aug 2022 09:28:25 +0100 Subject: [PATCH] Prefer gpstime over rxtime. Remove WORKAROUND_IGNORE_RX_TIME. --- .../basicstation/structs/radio_meta_data.go | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/internal/backend/basicstation/structs/radio_meta_data.go b/internal/backend/basicstation/structs/radio_meta_data.go index a500c0c1..5d9d3d2d 100644 --- a/internal/backend/basicstation/structs/radio_meta_data.go +++ b/internal/backend/basicstation/structs/radio_meta_data.go @@ -3,7 +3,6 @@ package structs import ( "encoding/binary" "math" - "os" "time" "github.com/brocaar/chirpstack-api/go/v3/common" @@ -76,6 +75,17 @@ func SetRadioMetaDataToProto(loraBand band.Band, gatewayID lorawan.EUI64, rmd Ra CrcStatus: gw.CRCStatus_CRC_OK, } + if rxTime := rmd.UpInfo.RxTime; rxTime != 0 { + sec, nsec := math.Modf(rmd.UpInfo.RxTime) + if sec != 0 { + val := time.Unix(int64(sec), int64(nsec)) + pb.RxInfo.Time, err = ptypes.TimestampProto(val) + if err != nil { + return errors.Wrap(err, "rxtime/timestamp proto error") + } + } + } + if gpsTime := rmd.UpInfo.GPSTime; gpsTime != 0 { gpsTimeDur := time.Duration(gpsTime) * time.Microsecond gpsTimeTime := time.Time(gps.NewTimeFromTimeSinceGPSEpoch(gpsTimeDur)) @@ -88,19 +98,6 @@ func SetRadioMetaDataToProto(loraBand band.Band, gatewayID lorawan.EUI64, rmd Ra } - // The WORKAROUND_IGNORE_RX_TIME flag is a workaround in case the reported - // rxtime from the Basics Station must be ignored (e.g. it is not accurate). - if rxTime := rmd.UpInfo.RxTime; rxTime != 0 && os.Getenv("WORKAROUND_IGNORE_RX_TIME") == "" { - sec, nsec := math.Modf(rmd.UpInfo.RxTime) - if sec != 0 { - val := time.Unix(int64(sec), int64(nsec)) - pb.RxInfo.Time, err = ptypes.TimestampProto(val) - if err != nil { - return errors.Wrap(err, "rxtime/timestamp proto error") - } - } - } - // Context pb.RxInfo.Context = make([]byte, 16) binary.BigEndian.PutUint64(pb.RxInfo.Context[0:8], uint64(rmd.UpInfo.RCtx))