mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-15 04:13:40 +00:00
lora/lorawan: implement minimal Join() function, and supporting functions
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
+16
-1
@@ -3,6 +3,7 @@ package lorawan
|
||||
import (
|
||||
"crypto/aes"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"math"
|
||||
)
|
||||
@@ -19,6 +20,21 @@ type Session struct {
|
||||
DLSettings uint8
|
||||
}
|
||||
|
||||
// SetDevAddr configures the Session DevAddr
|
||||
func (s *Session) SetDevAddr(devAddr []uint8) error {
|
||||
if len(devAddr) != 4 {
|
||||
return errors.New("invalid length")
|
||||
}
|
||||
|
||||
copy(s.DevAddr[:], devAddr)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Session) GetDevAddr() string {
|
||||
return hex.EncodeToString(s.DevAddr[:])
|
||||
}
|
||||
|
||||
// GenMessage Forge an uplink message
|
||||
func (s *Session) GenMessage(dir uint8, payload []uint8) ([]uint8, error) {
|
||||
var buf []uint8
|
||||
@@ -87,4 +103,3 @@ func (s *Session) genFRMPayload(dir uint8, fCnt uint32, payload []byte, isFOpts
|
||||
}
|
||||
return encrypted[:len(payload)], nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user