forked from brocaar/chirpstack-network-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rx_timing_setup.go
41 lines (34 loc) · 1.1 KB
/
rx_timing_setup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package maccommand
import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/brocaar/loraserver/internal/storage"
"github.com/brocaar/lorawan"
)
// RequestRXTimingSetup modifies the RX delay between the end of the TX
// and the opening of the first reception slot.
func RequestRXTimingSetup(del int) storage.MACCommandBlock {
return storage.MACCommandBlock{
CID: lorawan.RXTimingSetupReq,
MACCommands: []lorawan.MACCommand{
{
CID: lorawan.RXTimingSetupReq,
Payload: &lorawan.RXTimingSetupReqPayload{
Delay: uint8(del),
},
},
},
}
}
func handleRXTimingSetupAns(ds *storage.DeviceSession, block storage.MACCommandBlock, pendingBlock *storage.MACCommandBlock) ([]storage.MACCommandBlock, error) {
if pendingBlock == nil || len(pendingBlock.MACCommands) == 0 {
return nil, errors.New("expected pending mac-command")
}
req := pendingBlock.MACCommands[0].Payload.(*lorawan.RXTimingSetupReqPayload)
ds.RXDelay = req.Delay
log.WithFields(log.Fields{
"dev_eui": ds.DevEUI,
"rx_delay": ds.RXDelay,
}).Info("rx_timing_setup request acknowledged")
return nil, nil
}