rxframe test skeleton and options parsing

This commit is contained in:
saji 2023-05-03 11:29:27 -05:00
parent 59760b79dd
commit 96dd5c541b
2 changed files with 53 additions and 1 deletions

View file

@ -28,7 +28,12 @@ func ParseRxFrame(data []byte) (*RxFrame, error) {
// RX options // RX options
opt := data[11] opt := data[11]
// todo: use this // todo: use this
fmt.Print(opt) if (opt & 0x1) == 1 {
rx.ACK = true
}
if (opt & 0x2) == 1 {
rx.BCast = true
}
return rx, nil return rx, nil
} }

View file

@ -0,0 +1,47 @@
package xbee
import (
"reflect"
"testing"
)
func TestParseRxFrame(t *testing.T) {
type args struct {
data []byte
}
tests := []struct {
name string
args args
want *RxFrame
wantErr bool
}{
// TODO: Add test cases.
{
name: "64-bit unicast",
args: args{
// This was taken from the xbee 900hp data sheet, pg 154.
// the bolded "frame" there has an error and doesn't include the last two bytes.
data: []byte{0x90, 0x00, 0x13, 0xA2, 0x00, 0x41, 0xAE, 0xB5, 0x4E, 0xFF, 0xFE, 0xC1, 0x54, 0x78, 0x44, 0x61, 0x74, 0x61},
},
want: &RxFrame{
Source: 0x0013A20041AEB54E,
ACK: true,
BCast: false,
Payload: []byte{0x54, 0x78, 0x44, 0x61, 0x74, 0x61},
},
// Todo: use XCTU to generate more example packets.
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ParseRxFrame(tt.args.data)
if (err != nil) != tt.wantErr {
t.Errorf("ParseRxFrame() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("ParseRxFrame() = %v, want %v", got, tt.want)
}
})
}
}