Skip to content

Commit 24f85c6

Browse files
committed
Changes after lorawan vendor update.
1 parent b82c876 commit 24f85c6

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

backend/mqttpubsub/backend_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
"github.com/brocaar/loraserver/models"
9+
"github.com/brocaar/lorawan"
910
"github.com/eclipse/paho.mqtt.golang"
1011
. "github.com/smartystreets/goconvey/convey"
1112
)
@@ -44,6 +45,13 @@ func TestBackend(t *testing.T) {
4445
MAC: [8]byte{1, 2, 3, 4, 5, 6, 7, 8},
4546
Time: time.Now().UTC(),
4647
},
48+
PHYPayload: lorawan.PHYPayload{
49+
MHDR: lorawan.MHDR{
50+
MType: lorawan.UnconfirmedDataUp,
51+
Major: lorawan.LoRaWANR1,
52+
},
53+
MACPayload: &lorawan.MACPayload{},
54+
},
4755
}
4856

4957
err := backend.PublishGatewayRX([8]byte{1, 2, 3, 4, 5, 6, 7, 8}, rxPacket)
@@ -65,6 +73,13 @@ func TestBackend(t *testing.T) {
6573
TXInfo: models.TXInfo{
6674
MAC: [8]byte{1, 2, 3, 4, 5, 6, 7, 8},
6775
},
76+
PHYPayload: lorawan.PHYPayload{
77+
MHDR: lorawan.MHDR{
78+
MType: lorawan.UnconfirmedDataUp,
79+
Major: lorawan.LoRaWANR1,
80+
},
81+
MACPayload: &lorawan.MACPayload{},
82+
},
6883
}
6984
b, err := json.Marshal(txPacket)
7085
So(err, ShouldBeNil)

gateway/backend.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,8 @@ func newGatewayStatsPacket(mac lorawan.EUI64, stat Stat) models.GatewayStatsPack
360360

361361
// newRXPacketFromRXPK transforms a Semtech packet into a models.RXPacket.
362362
func newRXPacketFromRXPK(mac lorawan.EUI64, rxpk RXPK) (models.RXPacket, error) {
363-
phy := lorawan.NewPHYPayload(true) // uplink payload
364-
bytes, err := base64.StdEncoding.DecodeString(rxpk.Data)
365-
if err != nil {
366-
return models.RXPacket{}, fmt.Errorf("could not base64 decode data: %s", err)
367-
}
368-
if err := phy.UnmarshalBinary(bytes); err != nil {
363+
var phy lorawan.PHYPayload
364+
if err := phy.UnmarshalText([]byte(rxpk.Data)); err != nil {
369365
return models.RXPacket{}, fmt.Errorf("could not unmarshal PHYPayload: %s", err)
370366
}
371367

@@ -444,7 +440,7 @@ func newDataRateFromDatR(d DatR) (band.DataRate, error) {
444440

445441
dr.Modulation = band.LoRaModulation
446442
dr.SpreadFactor = sf
447-
dr.Bandwith = bw
443+
dr.Bandwidth = bw
448444
return dr, nil
449445
}
450446

@@ -460,7 +456,7 @@ func newDataRateFromDatR(d DatR) (band.DataRate, error) {
460456
func newDatRfromDataRate(d band.DataRate) DatR {
461457
if d.Modulation == band.LoRaModulation {
462458
return DatR{
463-
LoRa: fmt.Sprintf("SF%dBW%d", d.SpreadFactor, d.Bandwith),
459+
LoRa: fmt.Sprintf("SF%dBW%d", d.SpreadFactor, d.Bandwidth),
464460
}
465461
}
466462

gateway/backend_test.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,13 @@ func TestBackend(t *testing.T) {
135135

136136
Convey("Given a TXPacket", func() {
137137
var nwkSKey lorawan.AES128Key
138-
macPL := lorawan.NewMACPayload(false)
139-
phy := lorawan.NewPHYPayload(false)
140-
phy.MACPayload = macPL
141-
phy.MHDR = lorawan.MHDR{
142-
MType: lorawan.UnconfirmedDataDown,
143-
Major: lorawan.LoRaWANR1,
138+
139+
phy := lorawan.PHYPayload{
140+
MHDR: lorawan.MHDR{
141+
MType: lorawan.UnconfirmedDataDown,
142+
Major: lorawan.LoRaWANR1,
143+
},
144+
MACPayload: &lorawan.MACPayload{},
144145
}
145146
So(phy.SetMIC(nwkSKey), ShouldBeNil)
146147

@@ -154,7 +155,7 @@ func TestBackend(t *testing.T) {
154155
DataRate: band.DataRate{
155156
Modulation: band.LoRaModulation,
156157
SpreadFactor: 12,
157-
Bandwith: 250,
158+
Bandwidth: 250,
158159
},
159160
CodeRate: "4/5",
160161
},
@@ -198,7 +199,7 @@ func TestBackend(t *testing.T) {
198199
var pullResp PullRespPacket
199200
So(pullResp.UnmarshalBinary(buf[:i]), ShouldBeNil)
200201

201-
b, err := phy.MarshalBinary()
202+
str, err := phy.MarshalText()
202203
So(err, ShouldBeNil)
203204

204205
So(pullResp, ShouldResemble, PullRespPacket{
@@ -214,7 +215,7 @@ func TestBackend(t *testing.T) {
214215
},
215216
CodR: "4/5",
216217
Size: uint16(len(b)),
217-
Data: base64.StdEncoding.EncodeToString(b),
218+
Data: string(str),
218219
IPol: true,
219220
},
220221
},
@@ -288,7 +289,7 @@ func TestNewRXPacketFromRXPK(t *testing.T) {
288289
b, err := base64.StdEncoding.DecodeString(rxpk.Data)
289290
So(err, ShouldBeNil)
290291

291-
phy := lorawan.NewPHYPayload(true)
292+
var phy lorawan.PHYPayload
292293
So(phy.UnmarshalBinary(b), ShouldBeNil)
293294

294295
So(rxPacket.PHYPayload, ShouldResemble, phy)
@@ -304,7 +305,7 @@ func TestNewRXPacketFromRXPK(t *testing.T) {
304305
DataRate: band.DataRate{
305306
Modulation: band.LoRaModulation,
306307
SpreadFactor: 7,
307-
Bandwith: 125,
308+
Bandwidth: 125,
308309
},
309310
CodeRate: "4/5",
310311
RSSI: -51,

0 commit comments

Comments
 (0)