Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_DroneCAN: DNA Server: log duplicate nodes in CAND #26224

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions libraries/AP_DroneCAN/AP_DroneCAN_DNA_Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ void AP_DroneCAN_DNA_Server::verify_nodes()
if (log_count != last_logging_count) {
last_logging_count = log_count;
logged.clearall();
logged_duplicate.clearall();
}
#endif

Expand Down Expand Up @@ -437,12 +438,27 @@ void AP_DroneCAN_DNA_Server::handleNodeInfo(const CanardRxTransfer& transfer, co
if (transfer.source_node_id > MAX_NODE_ID) {
return;
}

// Check if we have seen this node ID before
const bool seen_node_id = isNodeIDOccupied(transfer.source_node_id);

// Get node ID for this unique ID if it has been seen before
const uint8_t prev_node_id = getNodeIDForUniqueID(rsp.hardware_version.unique_id, 16);

// Unique ID for this node is the same as the one registered
const bool unique_id_match = transfer.source_node_id == prev_node_id;

/*
if we haven't logged this node then log it now
*/
#if HAL_LOGGING_ENABLED
if (!logged.get(transfer.source_node_id) && AP::logger().logging_started()) {
const bool duplicate_node = seen_node_id && !unique_id_match;
const bool log_duplicate = duplicate_node && !logged_duplicate.get(transfer.source_node_id);
if (AP::logger().logging_started() && (!logged.get(transfer.source_node_id) || log_duplicate)) {
logged.set(transfer.source_node_id);
if (duplicate_node) {
logged_duplicate.set(transfer.source_node_id);
}
uint64_t uid[2];
memcpy(uid, rsp.hardware_version.unique_id, sizeof(rsp.hardware_version.unique_id));
// @LoggerMessage: CAND
Expand All @@ -467,9 +483,9 @@ void AP_DroneCAN_DNA_Server::handleNodeInfo(const CanardRxTransfer& transfer, co
}
#endif

if (isNodeIDOccupied(transfer.source_node_id)) {
if (seen_node_id) {
//if node_id already registered, just verify if Unique ID matches as well
if (transfer.source_node_id == getNodeIDForUniqueID(rsp.hardware_version.unique_id, 16)) {
if (unique_id_match) {
if (transfer.source_node_id == curr_verifying_node) {
nodeInfo_resp_rcvd = true;
}
Expand All @@ -484,7 +500,6 @@ void AP_DroneCAN_DNA_Server::handleNodeInfo(const CanardRxTransfer& transfer, co
} else {
/* Node Id was not allocated by us, or during this boot, let's register this in our records
Check if we allocated this Node before */
uint8_t prev_node_id = getNodeIDForUniqueID(rsp.hardware_version.unique_id, 16);
if (prev_node_id != 255) {
//yes we did, remove this registration
freeNodeID(prev_node_id);
Expand Down
1 change: 1 addition & 0 deletions libraries/AP_DroneCAN/AP_DroneCAN_DNA_Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class AP_DroneCAN_DNA_Server
Bitmask<128> verified_mask;
Bitmask<128> node_seen_mask;
Bitmask<128> logged;
Bitmask<128> logged_duplicate;
Bitmask<128> node_healthy_mask;

uint8_t last_logging_count;
Expand Down
Loading