From 2bcae9d7746410063a0e5c5529af472f317106ef Mon Sep 17 00:00:00 2001 From: Josh Pieper Date: Fri, 10 Sep 2021 15:39:04 -0400 Subject: [PATCH] Include a minimal checksum on the CAN message size SPI register --- fw/can_bridge.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fw/can_bridge.h b/fw/can_bridge.h index cdeb8e4..fd74477 100644 --- a/fw/can_bridge.h +++ b/fw/can_bridge.h @@ -357,12 +357,17 @@ class CanBridge { }; } if (address == 2) { + address16_buf_[kBufferItems] = 0; for (size_t i = 0; i < kBufferItems; i++) { const auto item = can_rx_queue_[i]; address16_buf_[i] = (item == nullptr) ? 0 : (item->size + 5); + address16_buf_[kBufferItems] += address16_buf_[i]; } + address16_buf_[kBufferItems] ^= 0xff; + return { - address16_buf_, + std::string_view(reinterpret_cast(&address16_buf_[0]), + sizeof(address16_buf_)), {}, }; } @@ -579,7 +584,7 @@ class CanBridge { uint8_t can1_reset_count_ = 0; uint8_t can2_reset_count_ = 0; - char address16_buf_[kBufferItems] = {}; + uint8_t address16_buf_[kBufferItems + 1] = {}; uint8_t status_buf_[12] = {}; Configuration can_config1_;