-
-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add LR-FHSS only and LoRa & LR-FHSS ADR algorithms.
- Loading branch information
Showing
18 changed files
with
805 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package adr | ||
|
||
import ( | ||
"github.com/brocaar/chirpstack-network-server/v3/adr" | ||
"github.com/brocaar/chirpstack-network-server/v3/internal/band" | ||
) | ||
|
||
// LoRaLRFHSSHandler implements a LoRa / LR-FHSS ADR handler. | ||
type LoRaLRFHSSHandler struct{} | ||
|
||
// ID returns the ID. | ||
func (h *LoRaLRFHSSHandler) ID() (string, error) { | ||
return "lora_lr_fhss", nil | ||
} | ||
|
||
// Name returns the name. | ||
func (h *LoRaLRFHSSHandler) Name() (string, error) { | ||
return "LoRa & LR-FHSS ADR algorithm", nil | ||
} | ||
|
||
// Handle handles the ADR request. | ||
func (h *LoRaLRFHSSHandler) Handle(req adr.HandleRequest) (adr.HandleResponse, error) { | ||
resp := adr.HandleResponse{ | ||
DR: req.DR, | ||
TxPowerIndex: req.TxPowerIndex, | ||
NbTrans: req.NbTrans, | ||
} | ||
|
||
band := band.Band() | ||
loRaHandler := DefaultHandler{} | ||
lrFHSSHandler := LRFHSSHandler{} | ||
|
||
loRaResp, err := loRaHandler.Handle(req) | ||
if err != nil { | ||
return resp, err | ||
} | ||
|
||
loRaDR, err := band.GetDataRate(loRaResp.DR) | ||
if err != nil { | ||
return resp, err | ||
} | ||
|
||
lrFHSSResp, err := lrFHSSHandler.Handle(req) | ||
if err != nil { | ||
return resp, err | ||
} | ||
|
||
// For SF < 10, LoRa is a better option, for SF >= 10 use LR-FHSS. | ||
if loRaDR.SpreadFactor < 10 { | ||
return loRaResp, nil | ||
} | ||
|
||
return lrFHSSResp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package adr | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/brocaar/chirpstack-network-server/v3/adr" | ||
"github.com/brocaar/chirpstack-network-server/v3/internal/band" | ||
"github.com/brocaar/chirpstack-network-server/v3/internal/test" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestLoRaLRFHSSHandler(t *testing.T) { | ||
h := &LoRaLRFHSSHandler{} | ||
|
||
t.Run("ID", func(t *testing.T) { | ||
assert := require.New(t) | ||
id, err := h.ID() | ||
assert.NoError(err) | ||
assert.Equal("lora_lr_fhss", id) | ||
}) | ||
|
||
t.Run("Handle", func(t *testing.T) { | ||
conf := test.GetConfig() | ||
|
||
// Add channel with LR-FHSS data-rate enabled. | ||
conf.NetworkServer.NetworkSettings.ExtraChannels = append(conf.NetworkServer.NetworkSettings.ExtraChannels, struct { | ||
Frequency uint32 `mapstructure:"frequency"` | ||
MinDR int `mapstructure:"min_dr"` | ||
MaxDR int `mapstructure:"max_dr"` | ||
}{ | ||
Frequency: 867300000, | ||
MinDR: 10, | ||
MaxDR: 11, | ||
}) | ||
band.Setup(conf) | ||
|
||
tests := []struct { | ||
name string | ||
request adr.HandleRequest | ||
response adr.HandleResponse | ||
}{ | ||
{ | ||
name: "switch to DR 3 (LoRa)", | ||
request: adr.HandleRequest{ | ||
ADR: true, | ||
DR: 0, | ||
NbTrans: 1, | ||
MaxDR: 11, | ||
RequiredSNRForDR: -20, | ||
UplinkHistory: []adr.UplinkMetaData{ | ||
{ | ||
MaxSNR: -10, | ||
}, | ||
}, | ||
}, | ||
response: adr.HandleResponse{ | ||
DR: 3, | ||
NbTrans: 1, | ||
}, | ||
}, | ||
{ | ||
name: "switch to DR 3 (LoRa)", | ||
request: adr.HandleRequest{ | ||
ADR: true, | ||
DR: 0, | ||
NbTrans: 3, | ||
MaxDR: 11, | ||
RequiredSNRForDR: -20, | ||
UplinkHistory: []adr.UplinkMetaData{ | ||
{ | ||
MaxSNR: -12, | ||
}, | ||
}, | ||
}, | ||
response: adr.HandleResponse{ | ||
DR: 10, | ||
NbTrans: 1, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tst := range tests { | ||
t.Run(tst.name, func(t *testing.T) { | ||
assert := require.New(t) | ||
|
||
resp, err := h.Handle(tst.request) | ||
assert.NoError(err) | ||
assert.Equal(tst.response, resp) | ||
}) | ||
} | ||
}) | ||
} |
Oops, something went wrong.