Too many things for a single commit but in summary:
We got them data bytes computer majigs being transmitted to the display and correctly parsed over there. Also seems to be fast. I won't touch performance issues until I have this working and documented tho.
This commit is contained in:
+44
-1
@@ -55,13 +55,56 @@ func Test_TelemetryField(t *testing.T) {
|
||||
expect: []byte{0x08, 0x0E, 0x61, 0x20, 0x63, 0x6F, 0x6F, 0x6C, 0x20, 0x73,
|
||||
0x74, 0x72, 0x69, 0x6E, 0x67, 0x21},
|
||||
},
|
||||
{
|
||||
name: "test_char",
|
||||
tf: TelemetryField{
|
||||
Type: DataTypeCHAR,
|
||||
Raw: uint64('R'),
|
||||
},
|
||||
expect: []byte{0x09, 0x52},
|
||||
},
|
||||
}
|
||||
|
||||
bufPtr := bufferPool.Get().(*[]byte)
|
||||
buf := (*bufPtr)[:0]
|
||||
|
||||
for _, test := range tests {
|
||||
result := test.tf.Pack()
|
||||
result := test.tf.Pack(buf)
|
||||
|
||||
if !bytes.Equal(result, test.expect) {
|
||||
t.Errorf("\nTest: %s\nExpected: %v\nGot: %v\n", test.name, test.expect, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_TelemetryData(t *testing.T) {
|
||||
data := TelemetryData{
|
||||
ActiveBinds: []BoundField{
|
||||
{
|
||||
Key: "Speed",
|
||||
ID: Speed,
|
||||
},
|
||||
{
|
||||
Key: "Gear",
|
||||
ID: Gear,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
data.Values[Speed] = TelemetryField{
|
||||
Type: DataTypeUINT16,
|
||||
Raw: uint64(254),
|
||||
}
|
||||
|
||||
data.Values[Gear] = TelemetryField{
|
||||
Type: DataTypeCHAR,
|
||||
Raw: uint64('R'),
|
||||
}
|
||||
|
||||
expect := []byte{0x02, 0xFE, 0x00, 0x09, 0x52}
|
||||
|
||||
result := data.Pack()
|
||||
if !bytes.Equal(result, expect) {
|
||||
t.Errorf("\nExpected: %v\nGot: %v\n", expect, result)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user