From 574530978c57b43519dd9f25de33352651af88ad Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Tue, 16 Nov 2021 19:35:20 -0500 Subject: [PATCH] Encoder: Add 1 to host-to-device long format packets Vehicle Spy 3 does this, it's a long-standing firmware idiosyncrasy. Due to the way the device handles packets, this didn't cause a loss of communication, only a "host to device byte" app error under certain circumstances. --- communication/encoder.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/communication/encoder.cpp b/communication/encoder.cpp index 7f44ec4..1a623b0 100644 --- a/communication/encoder.cpp +++ b/communication/encoder.cpp @@ -134,9 +134,10 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector& result, if(shortFormat) { buffer->insert(buffer->begin(), (uint8_t(buffer->size()) << 4) | uint8_t(netid)); } else { - // Size in long format is the size of the entire packet + // Size for the host-to-device long format is the size of the entire packet + 1 // So +1 for AA header, +1 for short format header, +2 for long format size, and +2 for long format NetID - uint16_t size = uint16_t(buffer->size()) + 1 + 1 + 2 + 2; + // Then an extra +1, due to a firmware idiosyncrasy + uint16_t size = uint16_t(buffer->size()) + 1 + 1 + 2 + 2 + 1; buffer->insert(buffer->begin(), { (uint8_t)Network::NetID::RED, // 0x0C for long message (uint8_t)size, // Size, little endian 16-bit