diff options
author | xengineering <me@xengineering.eu> | 2024-05-30 20:00:44 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-05-30 20:06:23 +0200 |
commit | 922d2a0cbd1406c0b437c0a062a8c04129d7dda4 (patch) | |
tree | 933e13ed1bfa7d1c01e9e600db226f1da0c524e4 /software/communication/data_link_test.go | |
parent | 85dc84ab0e8f5bf2fc02ad8881c7a7247bdb492b (diff) | |
download | iot-core-922d2a0cbd1406c0b437c0a062a8c04129d7dda4.tar iot-core-922d2a0cbd1406c0b437c0a062a8c04129d7dda4.tar.zst iot-core-922d2a0cbd1406c0b437c0a062a8c04129d7dda4.zip |
software: communication: Implement unslip()
This implements to decode the Serial Line Internet Protocol (SLIP). It
splits the continuous byte stream into frames. Based on these frames the
rest of the data link layer and upper layers can be implemented.
Diffstat (limited to 'software/communication/data_link_test.go')
-rw-r--r-- | software/communication/data_link_test.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/software/communication/data_link_test.go b/software/communication/data_link_test.go new file mode 100644 index 0000000..91b941d --- /dev/null +++ b/software/communication/data_link_test.go @@ -0,0 +1,33 @@ +package communication + +import ( + "reflect" + "testing" +) + +func TestUnslip(t *testing.T) { + input := []byte{ + 0xFF, 0x12, SLIP_END, + } + + bytes := make(chan byte) + frames := make(chan []byte) + + go func() { + for _, v := range input { + bytes <- v + } + }() + + go func() { + for { + frames <- unslip(bytes) + } + }() + + frame := <-frames + expected := []byte{0xFF, 0x12} + if !reflect.DeepEqual(frame, expected) { + t.Fatalf("Frame '%v' does not match expected '%v'\n", frame, expected) + } +} |