kopia lustrzana https://github.com/cyoung/stratux
Message formatting error causing CRC mismatch in some messages.
rodzic
ca48d84959
commit
89259cdfac
11
gen_gdl90.go
11
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.
|
||||
|
|
Ładowanie…
Reference in New Issue