Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #755 from TheThingsNetwork/feature/adr
Browse files Browse the repository at this point in the history
Improve ADR for Asian regions
  • Loading branch information
htdvisser authored Feb 18, 2019
2 parents 7d9ce89 + 843ed14 commit fd911b0
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 5 deletions.
1 change: 1 addition & 0 deletions core/band/band.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func Get(region string) (frequencyPlan FrequencyPlan, err error) {
}
frequencyPlan.DownlinkChannels = frequencyPlan.UplinkChannels
frequencyPlan.CFList = &lorawan.CFList{922700000, 922900000, 923100000, 923300000, 0}
frequencyPlan.ADR = &ADRConfig{MinDataRate: 0, MaxDataRate: 5, MinTXPower: 2, MaxTXPower: 14, StepTXPower: 2}
case pb_lorawan.FrequencyPlan_IN_865_867.String():
frequencyPlan.Band, err = lora.GetConfig(lora.IN_865_867, false, lorawan.DwellTimeNoLimit)
case pb_lorawan.FrequencyPlan_RU_864_870.String():
Expand Down
2 changes: 1 addition & 1 deletion core/band/band_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestGet(t *testing.T) {
fp, err := Get("KR_920_923")
a.So(err, ShouldBeNil)
a.So(fp.CFList, ShouldNotBeNil)
a.So(fp.ADR, ShouldBeNil)
a.So(fp.ADR, ShouldNotBeNil)
}

{
Expand Down
22 changes: 18 additions & 4 deletions core/networkserver/adr.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,18 @@ func (n *networkServer) handleDownlinkADR(message *pb_broker.DownlinkMessage, de
func getAdrReqPayloads(dev *device.Device, frequencyPlan *band.FrequencyPlan, drIdx int, powerIdx int) []lorawan.LinkADRReqPayload {
payloads := []lorawan.LinkADRReqPayload{}
switch dev.ADR.Band {
case pb_lorawan.FrequencyPlan_EU_863_870.String():
if dev.ADR.Failed > 0 && powerIdx > 5 {

// Frequency plans with three mandatory channels:
case pb_lorawan.FrequencyPlan_EU_863_870.String(),
pb_lorawan.FrequencyPlan_EU_433.String(),
pb_lorawan.FrequencyPlan_KR_920_923.String(),
pb_lorawan.FrequencyPlan_IN_865_867.String():

if dev.ADR.Band == pb_lorawan.FrequencyPlan_EU_863_870.String() && dev.ADR.Failed > 0 && powerIdx > 5 {
// fall back to txPower 5 for LoRaWAN 1.0
powerIdx = 5
}

payloads = []lorawan.LinkADRReqPayload{
{
DataRate: uint8(drIdx),
Expand All @@ -332,7 +339,12 @@ func getAdrReqPayloads(dev *device.Device, frequencyPlan *band.FrequencyPlan, dr
}
}
}
case pb_lorawan.FrequencyPlan_RU_864_870.String():

// Frequency plans with two default channels:
case pb_lorawan.FrequencyPlan_AS_923.String(),
pb_lorawan.FrequencyPlan_AS_920_923.String(),
pb_lorawan.FrequencyPlan_AS_923_925.String(),
pb_lorawan.FrequencyPlan_RU_864_870.String():
payloads = []lorawan.LinkADRReqPayload{
{
DataRate: uint8(drIdx),
Expand All @@ -344,7 +356,7 @@ func getAdrReqPayloads(dev *device.Device, frequencyPlan *band.FrequencyPlan, dr
},
}
if dev.ADR.Failed > 0 {
// Fall back to the mandatory RU_864_870 LoRaWAN channels
// Fall back to the mandatory LoRaWAN channels
payloads[0].ChMask[0] = true
payloads[0].ChMask[1] = true
} else {
Expand All @@ -356,6 +368,8 @@ func getAdrReqPayloads(dev *device.Device, frequencyPlan *band.FrequencyPlan, dr
}
}
}

// Frequency plans with 8 FSBs:
case pb_lorawan.FrequencyPlan_US_902_928.String(), pb_lorawan.FrequencyPlan_AU_915_928.String():
var dr500 uint8
switch dev.ADR.Band {
Expand Down
86 changes: 86 additions & 0 deletions core/networkserver/adr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,92 @@ func TestHandleDownlinkADR(t *testing.T) {
a.So(payload.ChMask[8], ShouldBeFalse) // 9th channel (FSK) disabled
}

ns.Component.Ctx.Info("Start AS ADR Test")

dev.ADR.DataRate = "SF10BW125"
dev.ADR.TxPower = 10

{
dev.ADR.Band = "AS_923"
message := adrInitDownlinkMessage()
err := ns.handleDownlinkADR(message, dev)
a.So(err, ShouldBeNil)
fOpts := message.Message.GetLoRaWAN().GetMACPayload().FOpts
a.So(fOpts, ShouldHaveLength, 2)
a.So(fOpts[1].CID, ShouldEqual, lorawan.LinkADRReq)
payload := new(lorawan.LinkADRReqPayload)
payload.UnmarshalBinary(fOpts[1].Payload)
a.So(payload.DataRate, ShouldEqual, 5) // SF7BW125
a.So(payload.TXPower, ShouldEqual, 2) // 10
for i := 0; i < 1; i++ { // First 2 channels enabled
a.So(payload.ChMask[i], ShouldBeTrue)
}
for i := 2; i < 8; i++ { // Next 6 channels disabled
a.So(payload.ChMask[i], ShouldBeFalse)
}
}

dev.ADR.DataRate = "SF10BW125"
dev.ADR.TxPower = 10

{
dev.ADR.Band = "AS_920_923"
message := adrInitDownlinkMessage()
err := ns.handleDownlinkADR(message, dev)
a.So(err, ShouldBeNil)
fOpts := message.Message.GetLoRaWAN().GetMACPayload().FOpts
a.So(fOpts, ShouldHaveLength, 2)
a.So(fOpts[1].CID, ShouldEqual, lorawan.LinkADRReq)
payload := new(lorawan.LinkADRReqPayload)
payload.UnmarshalBinary(fOpts[1].Payload)
a.So(payload.DataRate, ShouldEqual, 5) // SF7BW125
a.So(payload.TXPower, ShouldEqual, 2) // 10
for i := 0; i < 8; i++ { // First 8 channels enabled
a.So(payload.ChMask[i], ShouldBeTrue)
}
}

dev.ADR.DataRate = "SF10BW125"
dev.ADR.TxPower = 10

{
dev.ADR.Band = "AS_923_925"
message := adrInitDownlinkMessage()
err := ns.handleDownlinkADR(message, dev)
a.So(err, ShouldBeNil)
fOpts := message.Message.GetLoRaWAN().GetMACPayload().FOpts
a.So(fOpts, ShouldHaveLength, 2)
a.So(fOpts[1].CID, ShouldEqual, lorawan.LinkADRReq)
payload := new(lorawan.LinkADRReqPayload)
payload.UnmarshalBinary(fOpts[1].Payload)
a.So(payload.DataRate, ShouldEqual, 5) // SF7BW125
a.So(payload.TXPower, ShouldEqual, 2) // 10
for i := 0; i < 8; i++ { // First 8 channels enabled
a.So(payload.ChMask[i], ShouldBeTrue)
}
}

dev.ADR.DataRate = "SF10BW125"
dev.ADR.TxPower = 10

{
dev.ADR.Band = "KR_920_923"
message := adrInitDownlinkMessage()
err := ns.handleDownlinkADR(message, dev)
a.So(err, ShouldBeNil)
fOpts := message.Message.GetLoRaWAN().GetMACPayload().FOpts
a.So(fOpts, ShouldHaveLength, 2)
a.So(fOpts[1].CID, ShouldEqual, lorawan.LinkADRReq)
payload := new(lorawan.LinkADRReqPayload)
payload.UnmarshalBinary(fOpts[1].Payload)
a.So(payload.DataRate, ShouldEqual, 5) // SF7BW125
a.So(payload.TXPower, ShouldEqual, 2) // 10
for i := 0; i < 7; i++ { // First 7 channels enabled
a.So(payload.ChMask[i], ShouldBeTrue)
}
a.So(payload.ChMask[7], ShouldBeFalse) // 8th channel disabled
}

dev.ADR.DataRate = "SF10BW125"
dev.ADR.TxPower = 20

Expand Down

0 comments on commit fd911b0

Please sign in to comment.