Skip to content

Commit

Permalink
AP_DroneCAN: DNA_Server: fix handling of empty entry
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tpwrules authored and Pradeep-Carbonix committed Aug 14, 2024
1 parent 869810f commit 536debe
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libraries/AP_DroneCAN/AP_DroneCAN_DNA_Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 536debe

Please sign in to comment.