From 536debe50cd78c2b842fcab4169984f99f4aa5d0 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Sat, 13 Jul 2024 15:53:11 -0500 Subject: [PATCH] AP_DroneCAN: DNA_Server: fix handling of empty entry Replaces the check for a CRC of 0 with a check that the hwid is 0. Substantially reduces 1/256 chance that a particular node ID couldn't be stored. --- libraries/AP_DroneCAN/AP_DroneCAN_DNA_Server.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/AP_DroneCAN/AP_DroneCAN_DNA_Server.cpp b/libraries/AP_DroneCAN/AP_DroneCAN_DNA_Server.cpp index 1164d4f734..3e9c414278 100644 --- a/libraries/AP_DroneCAN/AP_DroneCAN_DNA_Server.cpp +++ b/libraries/AP_DroneCAN/AP_DroneCAN_DNA_Server.cpp @@ -202,8 +202,10 @@ bool AP_DroneCAN_DNA_Server::isValidNodeDataAvailable(uint8_t node_id) { NodeData node_data; readNodeData(node_data, node_id); + + uint8_t empty_hwid[sizeof(NodeData::hwid_hash)] {}; uint8_t crc = crc_crc8(node_data.hwid_hash, sizeof(node_data.hwid_hash)); - if (crc == node_data.crc && node_data.crc != 0) { + if (crc == node_data.crc && memcmp(&node_data.hwid_hash[0], &empty_hwid[0], sizeof(empty_hwid)) != 0) { return true; } return false;