gotelem/xbee/rxframe.go

40 lines
681 B
Go
Raw Normal View History

2023-04-26 22:24:11 +00:00
package xbee
import (
"encoding/binary"
"fmt"
)
type RxFrame struct {
Source uint64
ACK bool
BCast bool
Payload []byte
}
func ParseRxFrame(data []byte) (*RxFrame, error) {
// data is the binary that *isn't* part of the frame
// i.e it excludes start delimiter, length, and checksum.
// check the frame type (data[0])
2023-04-29 15:58:56 +00:00
if data[0] != byte(RxPktType) {
2023-04-26 22:24:11 +00:00
return nil, fmt.Errorf("incorrect frame type 0x%x", data[0])
}
rx := &RxFrame{
Source: binary.BigEndian.Uint64(data[1:]),
Payload: data[12:],
}
// RX options
opt := data[11]
// todo: use this
if (opt & 0x1) == 1 {
rx.ACK = true
}
if (opt & 0x2) == 1 {
rx.BCast = true
}
2023-04-26 22:24:11 +00:00
return rx, nil
}