1
1
package adr
2
2
3
- import "github.com/brocaar/chirpstack-network-server/v3/adr"
3
+ import (
4
+ "github.com/brocaar/chirpstack-network-server/v3/adr"
5
+ "github.com/brocaar/chirpstack-network-server/v3/internal/band"
6
+ loraband "github.com/brocaar/lorawan/band"
7
+ )
4
8
5
9
// DefaultHandler implements the default ADR handler.
6
10
type DefaultHandler struct {}
@@ -12,7 +16,7 @@ func (h *DefaultHandler) ID() (string, error) {
12
16
13
17
// Name returns the default name.
14
18
func (h * DefaultHandler ) Name () (string , error ) {
15
- return "Default ADR algorithm" , nil
19
+ return "Default ADR algorithm (LoRa only) " , nil
16
20
}
17
21
18
22
// Handle handles the ADR request.
@@ -30,9 +34,31 @@ func (h *DefaultHandler) Handle(req adr.HandleRequest) (adr.HandleResponse, erro
30
34
return resp , nil
31
35
}
32
36
37
+ // The max DR might be configured to a non LoRa (125kHz) data-rate.
38
+ // As this algorithm works on LoRa (125kHz) data-rates only, we need to
39
+ // find the max LoRa (125 kHz) data-rate.
40
+ maxDR := req .MaxDR
41
+ maxLoRaDR := 0
42
+ enabledDRs := band .Band ().GetEnabledUplinkDataRates ()
43
+ for _ , i := range enabledDRs {
44
+ dr , err := band .Band ().GetDataRate (i )
45
+ if err != nil {
46
+ return resp , err
47
+ }
48
+
49
+ if dr .Modulation == loraband .LoRaModulation && dr .Bandwidth == 125 {
50
+ maxLoRaDR = i
51
+ }
52
+ }
53
+
54
+ // Reduce to max LoRa DR.
55
+ if maxDR > maxLoRaDR {
56
+ maxDR = maxLoRaDR
57
+ }
58
+
33
59
// Lower the DR only if it exceeds the max. allowed DR.
34
- if req .DR > req . MaxDR {
35
- resp .DR = req . MaxDR
60
+ if req .DR > maxDR {
61
+ resp .DR = maxDR
36
62
}
37
63
38
64
// Set the new NbTrans.
@@ -50,7 +76,7 @@ func (h *DefaultHandler) Handle(req adr.HandleRequest) (adr.HandleResponse, erro
50
76
return resp , nil
51
77
}
52
78
53
- resp .TxPowerIndex , resp .DR = h .getIdealTxPowerIndexAndDR (nStep , resp .TxPowerIndex , resp .DR , req .MaxTxPowerIndex , req . MaxDR )
79
+ resp .TxPowerIndex , resp .DR = h .getIdealTxPowerIndexAndDR (nStep , resp .TxPowerIndex , resp .DR , req .MaxTxPowerIndex , maxDR )
54
80
55
81
return resp , nil
56
82
}
0 commit comments