Skip to content

Commit 8b85209

Browse files
Fix null time when GPS not available in GW (#196)
1 parent 238bf98 commit 8b85209

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

internal/backend/basicstation/structs/radio_meta_data.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package structs
22

33
import (
44
"encoding/binary"
5+
"math"
56
"time"
67

78
"github.com/brocaar/chirpstack-api/go/v3/common"
@@ -22,6 +23,7 @@ type RadioMetaData struct {
2223

2324
// RadioMetaDataUpInfo contains the radio meta-data uplink info.
2425
type RadioMetaDataUpInfo struct {
26+
RxTime float64 `json:"rxtime"`
2527
RCtx uint64 `json:"rctx"`
2628
XTime uint64 `json:"xtime"`
2729
GPSTime int64 `json:"gpstime"`
@@ -80,11 +82,22 @@ func SetRadioMetaDataToProto(loraBand band.Band, gatewayID lorawan.EUI64, rmd Ra
8082
pb.RxInfo.TimeSinceGpsEpoch = ptypes.DurationProto(gpsTimeDur)
8183
pb.RxInfo.Time, err = ptypes.TimestampProto(gpsTimeTime)
8284
if err != nil {
83-
return errors.Wrap(err, "timestamp proto error")
85+
return errors.Wrap(err, "GPSTime/timestamp proto error")
8486
}
8587

8688
}
8789

90+
if rxTime := rmd.UpInfo.RxTime; rxTime != 0 {
91+
sec, nsec := math.Modf(rmd.UpInfo.RxTime)
92+
if sec != 0 {
93+
val := time.Unix(int64(sec), int64(nsec))
94+
pb.RxInfo.Time, err = ptypes.TimestampProto(val)
95+
if err != nil {
96+
return errors.Wrap(err, "rxtime/timestamp proto error")
97+
}
98+
}
99+
}
100+
88101
// Context
89102
pb.RxInfo.Context = make([]byte, 16)
90103
binary.BigEndian.PutUint64(pb.RxInfo.Context[0:8], uint64(rmd.UpInfo.RCtx))

0 commit comments

Comments
 (0)