From 89259cdfac2c2f4b22b81dfe0847d4afb575bad5 Mon Sep 17 00:00:00 2001 From: Christopher Young Date: Wed, 12 Aug 2015 00:00:50 -0400 Subject: [PATCH] Message formatting error causing CRC mismatch in some messages. --- gen_gdl90.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gen_gdl90.go b/gen_gdl90.go index f6a5d061..be07373d 100644 --- a/gen_gdl90.go +++ b/gen_gdl90.go @@ -80,9 +80,13 @@ func crcCompute(data []byte) uint16 { } func prepareMessage(data []byte) []byte { - tmp := []byte{0x7E} // Flag start. // Compute CRC before modifying the message. crc := crcCompute(data) + // Add the two CRC16 bytes before replacing control characters. + data = append(data, byte(crc&0xFF)) + data = append(data, byte(crc>>8)) + + tmp := []byte{0x7E} // Flag start. // Copy the message over, escaping 0x7E (Flag Byte) and 0x7D (Control-Escape). for i := 0; i < len(data); i++ { @@ -94,15 +98,12 @@ func prepareMessage(data []byte) []byte { tmp = append(tmp, mv) } - // Add the two CRC16 bytes. - tmp = append(tmp, byte(crc&0xFF)) - tmp = append(tmp, byte(crc>>8)) - tmp = append(tmp, 0x7E) // Flag end. return tmp } + func makeHeartbeat() []byte { msg := make([]byte, 7) // See p.10.