diff --git a/internal/xbee/rxframe.go b/internal/xbee/rxframe.go index 5e9b800..2ca81f0 100644 --- a/internal/xbee/rxframe.go +++ b/internal/xbee/rxframe.go @@ -28,7 +28,12 @@ func ParseRxFrame(data []byte) (*RxFrame, error) { // RX options opt := data[11] // todo: use this - fmt.Print(opt) + if (opt & 0x1) == 1 { + rx.ACK = true + } + if (opt & 0x2) == 1 { + rx.BCast = true + } return rx, nil } diff --git a/internal/xbee/rxframe_test.go b/internal/xbee/rxframe_test.go new file mode 100644 index 0000000..39c32d5 --- /dev/null +++ b/internal/xbee/rxframe_test.go @@ -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) + } + }) + } +}