Skip to content

Commit d411d3b

Browse files
committed
Update chirpstack_api + add CrcStatus field back to UplinkRxInfo.
1 parent ad00a52 commit d411d3b

13 files changed

+47
-14
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.17
44

55
require (
66
github.com/brocaar/lorawan v0.0.0-20220207095711-d675789e16ab
7-
github.com/chirpstack/chirpstack/api/go/v4 v4.1.0
7+
github.com/chirpstack/chirpstack/api/go/v4 v4.2.0
88
github.com/eclipse/paho.mqtt.golang v1.4.1
99
github.com/go-zeromq/zmq4 v0.7.0
1010
github.com/golang-jwt/jwt/v4 v4.4.2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cb
101101
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
102102
github.com/chirpstack/chirpstack/api/go/v4 v4.1.0 h1:D3ViDwYMmB9yE050i8EbqkGkIkPz8w4NwkdbPk1iat8=
103103
github.com/chirpstack/chirpstack/api/go/v4 v4.1.0/go.mod h1:KBW7imf70O9ifrMmoFH8+dn0+MUFS1PdC5shXH7W3dI=
104+
github.com/chirpstack/chirpstack/api/go/v4 v4.2.0 h1:XswPjMY3Pqqo4V8ZgjhL3MfDeIvmAUakZSxefLj+5U0=
105+
github.com/chirpstack/chirpstack/api/go/v4 v4.2.0/go.mod h1:KBW7imf70O9ifrMmoFH8+dn0+MUFS1PdC5shXH7W3dI=
104106
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
105107
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
106108
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=

internal/backend/basicstation/backend_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ func (ts *BackendTestSuite) TestUplinkDataFrame() {
183183
Rssi: 120,
184184
Snr: 5.5,
185185
Context: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
186+
CrcStatus: gw.CRCStatus_CRC_OK,
186187
},
187188
}, uplinkFrame))
188189

@@ -267,6 +268,7 @@ func (ts *BackendTestSuite) TestJoinRequest() {
267268
Rssi: 120,
268269
Snr: 5.5,
269270
Context: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
271+
CrcStatus: gw.CRCStatus_CRC_OK,
270272
},
271273
}, uplinkFrame))
272274

@@ -346,6 +348,7 @@ func (ts *BackendTestSuite) TestProprietaryDataFrame() {
346348
Rssi: 120,
347349
Snr: 5.5,
348350
Context: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
351+
CrcStatus: gw.CRCStatus_CRC_OK,
349352
},
350353
}, uplinkFrame))
351354

internal/backend/basicstation/structs/join_request_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func TestJoinRequestToProto(t *testing.T) {
6666
Rssi: 120,
6767
Snr: 5.5,
6868
Context: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
69+
CrcStatus: gw.CRCStatus_CRC_OK,
6970
},
7071
}, pb)
7172

internal/backend/basicstation/structs/radio_meta_data.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func SetRadioMetaDataToProto(loraBand band.Band, gatewayID lorawan.EUI64, rmd Ra
7474
GatewayId: gatewayID.String(),
7575
Rssi: int32(rmd.UpInfo.RSSI),
7676
Snr: float32(rmd.UpInfo.SNR),
77+
CrcStatus: gw.CRCStatus_CRC_OK,
7778
}
7879

7980
if rxTime := rmd.UpInfo.RxTime; rxTime != 0 {

internal/backend/basicstation/structs/radio_meta_data_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func TestSetRadioMetaDataToProto(t *testing.T) {
5555
Rssi: 120,
5656
Snr: 5.5,
5757
Context: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
58+
CrcStatus: gw.CRCStatus_CRC_OK,
5859
},
5960
},
6061
},
@@ -84,6 +85,7 @@ func TestSetRadioMetaDataToProto(t *testing.T) {
8485
GatewayId: "0102030405060708",
8586
Rssi: 120,
8687
Context: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
88+
CrcStatus: gw.CRCStatus_CRC_OK,
8789
},
8890
},
8991
},
@@ -120,6 +122,7 @@ func TestSetRadioMetaDataToProto(t *testing.T) {
120122
Context: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
121123
TimeSinceGpsEpoch: durationpb.New(5 * time.Second),
122124
Time: timeP,
125+
CrcStatus: gw.CRCStatus_CRC_OK,
123126
},
124127
},
125128
},

internal/backend/basicstation/structs/uplink_data_frame_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func TestUplinkDataFrameToProto(t *testing.T) {
5959
Rssi: 120,
6060
Snr: 5.5,
6161
Context: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
62+
CrcStatus: gw.CRCStatus_CRC_OK,
6263
},
6364
},
6465
},
@@ -103,6 +104,7 @@ func TestUplinkDataFrameToProto(t *testing.T) {
103104
Rssi: 120,
104105
Snr: 5.5,
105106
Context: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
107+
CrcStatus: gw.CRCStatus_CRC_OK,
106108
},
107109
},
108110
},
@@ -148,6 +150,7 @@ func TestUplinkDataFrameToProto(t *testing.T) {
148150
Rssi: 120,
149151
Snr: 5.5,
150152
Context: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
153+
CrcStatus: gw.CRCStatus_CRC_OK,
151154
},
152155
},
153156
},

internal/backend/basicstation/structs/uplink_proprietary_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func TestUplinkProprietaryFrameToProto(t *testing.T) {
5151
Rssi: 120,
5252
Snr: 5.5,
5353
Context: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
54+
CrcStatus: gw.CRCStatus_CRC_OK,
5455
},
5556
},
5657
},

internal/backend/semtechudp/backend.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ type Backend struct {
4242

4343
udpSendChan chan udpPacket
4444

45-
wg sync.WaitGroup
46-
conn *net.UDPConn
47-
closed bool
48-
gateways gateways
49-
fakeRxTime bool
45+
wg sync.WaitGroup
46+
conn *net.UDPConn
47+
closed bool
48+
gateways gateways
49+
fakeRxTime bool
50+
skipCRCCheck bool
5051
}
5152

5253
// NewBackend creates a new backend.
@@ -68,8 +69,9 @@ func NewBackend(conf config.Config) (*Backend, error) {
6869
gateways: gateways{
6970
gateways: make(map[lorawan.EUI64]gateway),
7071
},
71-
fakeRxTime: conf.Backend.SemtechUDP.FakeRxTime,
72-
cache: cache.New(15*time.Second, 15*time.Second),
72+
fakeRxTime: conf.Backend.SemtechUDP.FakeRxTime,
73+
skipCRCCheck: conf.Backend.SemtechUDP.SkipCRCCheck,
74+
cache: cache.New(15*time.Second, 15*time.Second),
7375
}
7476

7577
go func() {
@@ -468,7 +470,7 @@ func (b *Backend) handlePushData(up udpPacket) error {
468470
}
469471

470472
// uplink frames
471-
uplinkFrames, err := p.GetUplinkFrames(b.fakeRxTime)
473+
uplinkFrames, err := p.GetUplinkFrames(b.skipCRCCheck, b.fakeRxTime)
472474
if err != nil {
473475
return errors.Wrap(err, "get uplink frames error")
474476
}

internal/backend/semtechudp/backend_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ func (ts *BackendTestSuite) TestPushData() {
772772
Channel: 2,
773773
RfChain: 1,
774774
Context: []byte{0x2a, 0x33, 0x7a, 0xb3},
775+
CrcStatus: gw.CRCStatus_CRC_OK,
775776
},
776777
},
777778
},

internal/backend/semtechudp/packets/push_data.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ func (p PushDataPacket) GetGatewayStats() (*gw.GatewayStats, error) {
8181
}
8282

8383
// GetUplinkFrames returns a slice of gw.UplinkFrame.
84-
func (p PushDataPacket) GetUplinkFrames(FakeRxInfoTime bool) ([]*gw.UplinkFrame, error) {
84+
func (p PushDataPacket) GetUplinkFrames(skipCRCCheck bool, FakeRxInfoTime bool) ([]*gw.UplinkFrame, error) {
8585
var frames []*gw.UplinkFrame
8686

8787
for i := range p.Payload.RXPK {
8888
// validate CRC
89-
if p.Payload.RXPK[i].Stat != 1 {
89+
if p.Payload.RXPK[i].Stat != 1 && !skipCRCCheck {
9090
continue
9191
}
9292

@@ -145,6 +145,15 @@ func getUplinkFrame(gatewayID lorawan.EUI64, rxpk RXPK, FakeRxInfoTime bool) (*g
145145
},
146146
}
147147

148+
switch rxpk.Stat {
149+
case 1:
150+
frame.RxInfo.CrcStatus = gw.CRCStatus_CRC_OK
151+
case -1:
152+
frame.RxInfo.CrcStatus = gw.CRCStatus_BAD_CRC
153+
default:
154+
frame.RxInfo.CrcStatus = gw.CRCStatus_NO_CRC
155+
}
156+
148157
// Context
149158
binary.BigEndian.PutUint32(frame.RxInfo.Context, rxpk.Tmst)
150159

internal/backend/semtechudp/packets/push_data_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ func TestGetUplinkFrame(t *testing.T) {
271271
Board: 2,
272272
Antenna: 0,
273273
Context: []byte{0x00, 0x0f, 0x42, 0x40},
274+
CrcStatus: gw.CRCStatus_CRC_OK,
274275
},
275276
},
276277
},
@@ -345,6 +346,7 @@ func TestGetUplinkFrame(t *testing.T) {
345346
Board: 2,
346347
Antenna: 8,
347348
Context: []byte{0x00, 0x0f, 0x42, 0x40},
349+
CrcStatus: gw.CRCStatus_CRC_OK,
348350
},
349351
},
350352
{
@@ -373,6 +375,7 @@ func TestGetUplinkFrame(t *testing.T) {
373375
Board: 2,
374376
Antenna: 9,
375377
Context: []byte{0x00, 0x0f, 0x42, 0x40},
378+
CrcStatus: gw.CRCStatus_CRC_OK,
376379
},
377380
},
378381
},
@@ -422,6 +425,7 @@ func TestGetUplinkFrame(t *testing.T) {
422425
GatewayId: "0102030405060708",
423426
Rssi: -74,
424427
Context: []byte{0x00, 0x0f, 0x42, 0x40},
428+
CrcStatus: gw.CRCStatus_CRC_OK,
425429
},
426430
},
427431
},
@@ -482,6 +486,7 @@ func TestGetUplinkFrame(t *testing.T) {
482486
Board: 2,
483487
Antenna: 0,
484488
Context: []byte{0x00, 0x0f, 0x42, 0x40},
489+
CrcStatus: gw.CRCStatus_CRC_OK,
485490
},
486491
},
487492
},
@@ -544,6 +549,7 @@ func TestGetUplinkFrame(t *testing.T) {
544549
Metadata: map[string]string{
545550
"gateway_name": "test-gateway",
546551
},
552+
CrcStatus: gw.CRCStatus_CRC_OK,
547553
},
548554
},
549555
},
@@ -553,7 +559,7 @@ func TestGetUplinkFrame(t *testing.T) {
553559
for _, test := range testTable {
554560
t.Run(test.Name, func(t *testing.T) {
555561
assert := require.New(t)
556-
f, err := test.PushDataPacket.GetUplinkFrames(false)
562+
f, err := test.PushDataPacket.GetUplinkFrames(false, false)
557563
assert.Nil(err)
558564

559565
for _, ff := range f {

internal/config/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ type Config struct {
2020
Type string `mapstructure:"type"`
2121

2222
SemtechUDP struct {
23-
UDPBind string `mapstructure:"udp_bind"`
24-
FakeRxTime bool `mapstructure:"fake_rx_time"`
23+
UDPBind string `mapstructure:"udp_bind"`
24+
SkipCRCCheck bool `mapstructure:"skip_crc_check"`
25+
FakeRxTime bool `mapstructure:"fake_rx_time"`
2526
} `mapstructure:"semtech_udp"`
2627

2728
BasicStation struct {

0 commit comments

Comments
 (0)