Skip to content

Commit

Permalink
Fix using only a single receive window.
Browse files Browse the repository at this point in the history
Currently only RX1 is being used. Todo is a switch for using RX1 or RX2
(based on duty-cycle management?).
  • Loading branch information
brocaar committed Apr 27, 2016
1 parent 4dfba3c commit 2604fc6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 40 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Untagged

* Publish notification to application on node join
* Handle duplicated downlink payloads (when running multiple LoRa Server instances each receiving the TXPayload from MQTT)
* Fix: use only one receive-window

## 0.5.1

Expand Down
26 changes: 14 additions & 12 deletions internal/loraserver/loraserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,14 @@ func handleDataDownReply(ctx Context, rxPacket models.RXPacket, ns models.NodeSe
return fmt.Errorf("send tx packet (rx window 1) to gateway error: %s", err)
}

// TODO: implement receive window 1 / 2 switch. Based on duty cycle status of gateway?
// window 2
txPacket.TXInfo.Timestamp = rxPacket.RXInfo.Timestamp + uint32(band.ReceiveDelay2/time.Microsecond)
txPacket.TXInfo.Frequency = band.RX2Frequency
txPacket.TXInfo.DataRate = band.DataRateConfiguration[band.RX2DataRate]
if err := ctx.Gateway.Send(txPacket); err != nil {
return fmt.Errorf("send tx packet (rx window 2) to gateway error: %s", err)
}
// txPacket.TXInfo.Timestamp = rxPacket.RXInfo.Timestamp + uint32(band.ReceiveDelay2/time.Microsecond)
// txPacket.TXInfo.Frequency = band.RX2Frequency
// txPacket.TXInfo.DataRate = band.DataRateConfiguration[band.RX2DataRate]
// if err := ctx.Gateway.Send(txPacket); err != nil {
// return fmt.Errorf("send tx packet (rx window 2) to gateway error: %s", err)
// }

// increment the FCntDown when MType != ConfirmedDataDown. In case of
// ConfirmedDataDown we increment on ACK.
Expand Down Expand Up @@ -497,13 +498,14 @@ func handleCollectedJoinRequestPackets(ctx Context, rxPackets RXPackets) error {
return fmt.Errorf("send tx packet (rx window 1) to gateway error: %s", err)
}

// TODO: implement receive window 1 / 2 switch. Based on duty cycle status of gateway?
// window 2
txPacket.TXInfo.Timestamp = rxPacket.RXInfo.Timestamp + uint32(band.JoinAcceptDelay2/time.Microsecond)
txPacket.TXInfo.Frequency = band.RX2Frequency
txPacket.TXInfo.DataRate = band.DataRateConfiguration[band.RX2DataRate]
if err = ctx.Gateway.Send(txPacket); err != nil {
return fmt.Errorf("send tx packet (rx window 2) to gateway error: %s", err)
}
// txPacket.TXInfo.Timestamp = rxPacket.RXInfo.Timestamp + uint32(band.JoinAcceptDelay2/time.Microsecond)
// txPacket.TXInfo.Frequency = band.RX2Frequency
// txPacket.TXInfo.DataRate = band.DataRateConfiguration[band.RX2DataRate]
// if err = ctx.Gateway.Send(txPacket); err != nil {
// return fmt.Errorf("send tx packet (rx window 2) to gateway error: %s", err)
// }

// send a notification to the application that a node joined the network
return ctx.Application.SendNotification(ns.DevEUI, ns.AppEUI, models.JoinNotificationType, models.JoinNotification{
Expand Down
44 changes: 16 additions & 28 deletions internal/loraserver/loraserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,19 @@ func TestHandleDataUpPackets(t *testing.T) {
_ = <-app.rxPayloadChan
})

Convey("Then two identical packets are sent to the gateway (two receive windows)", func() {
txPacket1 := <-gw.txPacketChan
txPacket2 := <-gw.txPacketChan
So(txPacket1.PHYPayload, ShouldResemble, txPacket2.PHYPayload)
Convey("Then a packet is sent to the gateway", func() {
txPacket := <-gw.txPacketChan

macPL, ok := txPacket1.PHYPayload.MACPayload.(*lorawan.MACPayload)
macPL, ok := txPacket.PHYPayload.MACPayload.(*lorawan.MACPayload)
So(ok, ShouldBeTrue)

Convey("Then these packets contain the expected values", func() {
So(txPacket1.PHYPayload.MHDR.MType, ShouldEqual, lorawan.UnconfirmedDataDown)
Convey("Then this packet contains the expected values", func() {
So(txPacket.PHYPayload.MHDR.MType, ShouldEqual, lorawan.UnconfirmedDataDown)
So(macPL.FHDR.FCnt, ShouldEqual, ns.FCntDown)
So(macPL.FHDR.FCtrl.ACK, ShouldBeFalse)
So(*macPL.FPort, ShouldEqual, 5)

So(txPacket1.PHYPayload.DecryptFRMPayload(ns.AppSKey), ShouldBeNil)
So(txPacket.PHYPayload.DecryptFRMPayload(ns.AppSKey), ShouldBeNil)
So(len(macPL.FRMPayload), ShouldEqual, 1)
pl, ok := macPL.FRMPayload[0].(*lorawan.DataPayload)
So(ok, ShouldBeTrue)
Expand Down Expand Up @@ -205,21 +203,19 @@ func TestHandleDataUpPackets(t *testing.T) {
_ = <-app.rxPayloadChan
})

Convey("Then two identical packets are sent to the gateway (two receive windows)", func() {
txPacket1 := <-gw.txPacketChan
txPacket2 := <-gw.txPacketChan
So(txPacket1.PHYPayload, ShouldResemble, txPacket2.PHYPayload)
Convey("Then a packet is sent to the gateway", func() {
txPacket := <-gw.txPacketChan

macPL, ok := txPacket1.PHYPayload.MACPayload.(*lorawan.MACPayload)
macPL, ok := txPacket.PHYPayload.MACPayload.(*lorawan.MACPayload)
So(ok, ShouldBeTrue)

Convey("Then these packets contain the expected values", func() {
So(txPacket1.PHYPayload.MHDR.MType, ShouldEqual, lorawan.ConfirmedDataDown)
Convey("Then this packet contains the expected values", func() {
So(txPacket.PHYPayload.MHDR.MType, ShouldEqual, lorawan.ConfirmedDataDown)
So(macPL.FHDR.FCnt, ShouldEqual, ns.FCntDown)
So(macPL.FHDR.FCtrl.ACK, ShouldBeFalse)
So(*macPL.FPort, ShouldEqual, 5)

So(txPacket1.PHYPayload.DecryptFRMPayload(ns.AppSKey), ShouldBeNil)
So(txPacket.PHYPayload.DecryptFRMPayload(ns.AppSKey), ShouldBeNil)
So(len(macPL.FRMPayload), ShouldEqual, 1)
pl, ok := macPL.FRMPayload[0].(*lorawan.DataPayload)
So(ok, ShouldBeTrue)
Expand Down Expand Up @@ -321,13 +317,10 @@ func TestHandleDataUpPackets(t *testing.T) {
})
})

Convey("Then two ACK packets are sent to the gateway (two receive windows)", func() {
txPacket1 := <-gw.txPacketChan
txPacket2 := <-gw.txPacketChan
Convey("Then a ACK packet is sent to the gateway", func() {
txPacket := <-gw.txPacketChan

So(txPacket1.PHYPayload.MIC, ShouldEqual, txPacket2.PHYPayload.MIC)

macPL, ok := txPacket1.PHYPayload.MACPayload.(*lorawan.MACPayload)
macPL, ok := txPacket.PHYPayload.MACPayload.(*lorawan.MACPayload)
So(ok, ShouldBeTrue)

So(macPL.FHDR.FCtrl.ACK, ShouldBeTrue)
Expand Down Expand Up @@ -416,15 +409,10 @@ func TestHandleJoinRequestPackets(t *testing.T) {
So(phy.DecryptJoinAcceptPayload(node.AppKey), ShouldBeNil)
So(phy.MHDR.MType, ShouldEqual, lorawan.JoinAccept)

Convey("Then the first delay is 5 sec", func() {
Convey("Then the delay is 5 sec", func() {
So(txPacket.TXInfo.Timestamp, ShouldEqual, rxPacket.RXInfo.Timestamp+uint32(5*time.Second/time.Microsecond))
})

Convey("Then the second delay is 6 sec", func() {
txPacket = <-g.txPacketChan
So(txPacket.TXInfo.Timestamp, ShouldEqual, rxPacket.RXInfo.Timestamp+uint32(6*time.Second/time.Microsecond))
})

Convey("Then a node-session was created", func() {
jaPL, ok := phy.MACPayload.(*lorawan.JoinAcceptPayload)
So(ok, ShouldBeTrue)
Expand Down

0 comments on commit 2604fc6

Please sign in to comment.