Skip to content

Commit

Permalink
Prefer gpstime over rxtime. Remove WORKAROUND_IGNORE_RX_TIME.
Browse files Browse the repository at this point in the history
  • Loading branch information
brocaar committed Aug 1, 2022
1 parent d6b046e commit c7a2543
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions internal/backend/basicstation/structs/radio_meta_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package structs
import (
"encoding/binary"
"math"
"os"
"time"

"github.com/brocaar/chirpstack-api/go/v3/common"
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down

0 comments on commit c7a2543

Please sign in to comment.