Fix serialization of Confirmed DataBlock

The serialized form should be 10 octets of user-data plus the two octets
for serial/crc.

Previous implementation forgot to account for the two extra octets when
allocating the final data slice.
pull/3/head
Martin Hebnes Pedersen 6 years ago
parent 68378f8fb4
commit 2851102398

@ -81,6 +81,9 @@ func (db *DataBlock) Bytes(dataType uint8, confirmed bool) []byte {
// Applying CRC mask, see DMR AI spec. page 143 // Applying CRC mask, see DMR AI spec. page 143
db.CRC ^= 0x01ff db.CRC ^= 0x01ff
// Grow data slice to support the two byte prefix
data = append(data, make([]byte, 2)...)
data[0] = (db.Serial << 1) | (uint8(db.CRC>>8) & 0x01) data[0] = (db.Serial << 1) | (uint8(db.CRC>>8) & 0x01)
data[1] = uint8(db.CRC) data[1] = uint8(db.CRC)
copy(data[2:], db.Data) copy(data[2:], db.Data)

@ -19,7 +19,8 @@ func TestDataBlock(t *testing.T) {
if data == nil { if data == nil {
t.Fatal("encode failed") t.Fatal("encode failed")
} }
size := int(dataBlockLength(Rate34Data, true)) // Size is the user-data + two octets of serial/crc
size := int(dataBlockLength(Rate34Data, true)) + 2
if len(data) != size { if len(data) != size {
t.Fatalf("encode failed: expected %d bytes, got %d", size, len(data)) t.Fatalf("encode failed: expected %d bytes, got %d", size, len(data))
} }

Loading…
Cancel
Save