Skip to content
Snippets Groups Projects
Commit ffdcc4b2 authored by Sebastien Binet's avatar Sebastien Binet
Browse files

dif: fixup CRC-16 computation

parent cde01346
No related branches found
No related tags found
No related merge requests found
......@@ -103,6 +103,7 @@ loop:
dec.dif, dec.err,
)
}
dec.crcU8(v)
switch v {
default:
......@@ -113,7 +114,6 @@ loop:
return xerrors.Errorf("dif: DIF 0x%x contains an analog frame", dec.dif)
case frHeader:
dec.crcU8(v)
frameLoop:
for {
v := dec.readU8()
......
......@@ -68,8 +68,9 @@ func (enc *Encoder) Encode(dif *DIF) error {
enc.write(frame.Data[:])
}
enc.writeU8(frTrailer)
crc := enc.crc.Sum16() // gb-trailer not part of CRC-16
enc.writeU8(gbTrailer)
crc := enc.crc.Sum16()
enc.writeU16(crc)
return enc.err
......
......@@ -159,7 +159,7 @@ func TestDecoder(t *testing.T) {
frTrailer,
gbTrailer,
0x4c, 0x1a, // CRC-16
0x26, 0xa2, // CRC-16
},
},
{
......@@ -187,7 +187,7 @@ func TestDecoder(t *testing.T) {
frTrailer,
gbTrailer,
0x4c, 0x1a, // CRC-16
0x26, 0xa2, // CRC-16
gbHeader,
difID,
......@@ -210,7 +210,7 @@ func TestDecoder(t *testing.T) {
frTrailer,
gbTrailer,
0xfa, 0x67, // CRC-16
0x9c, 0xbf, // CRC-16
},
},
{
......@@ -239,7 +239,7 @@ func TestDecoder(t *testing.T) {
frTrailer,
gbTrailer,
0x52, 0x3f, // CRC-16
0xf0, 0x5d, // CRC-16
},
},
{
......@@ -510,7 +510,7 @@ func TestDecoder(t *testing.T) {
gbTrailer,
0xb5, 0xff, // CRC-16
},
want: xerrors.Errorf("dif: DIF 0x%x inconsistent CRC: recv=0xb5ff comp=0x4c1a", difID),
want: xerrors.Errorf("dif: DIF 0x%x inconsistent CRC: recv=0xb5ff comp=0x26a2", difID),
},
} {
t.Run(tc.name, func(t *testing.T) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment