Skip to content

Commit

Permalink
AP_DroneCAN: DNAServer: don't "allocate" broadcast ID
Browse files Browse the repository at this point in the history
While technically legal, it's unlikely to have been tested and an
allocatee might do silly things. Also makes the logic a bit more clear
and improves the failure message.
  • Loading branch information
tpwrules committed Sep 9, 2024
1 parent cae102b commit b9d68aa
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions libraries/AP_DroneCAN/AP_DroneCAN_DNA_Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ uint8_t AP_DroneCAN_DNA_Server::Database::handle_allocation(uint8_t node_id, con
resp_node_id = find_free_node_id(node_id > MAX_NODE_ID ? 0 : node_id);
if (resp_node_id != 0) {
create_registration(resp_node_id, unique_id, 16);
} else {
GCS_SEND_TEXT(MAV_SEVERITY_ERROR, "UC Node Alloc Failed!");
}
}
return resp_node_id; // will be 0 if not found and not created
Expand Down Expand Up @@ -465,11 +463,11 @@ void AP_DroneCAN_DNA_Server::handle_allocation(const CanardRxTransfer& transfer,

if (rcvd_unique_id_offset) {
debug_dronecan(AP_CANManager::LOG_DEBUG, "TIME: %lu -- Accepting Followup part! %u\n",
now,
(unsigned long)now,
unsigned((now - last_alloc_msg_ms)));
} else {
debug_dronecan(AP_CANManager::LOG_DEBUG, "TIME: %lu -- Accepting First part! %u\n",
now,
(unsigned long)now,
unsigned((now - last_alloc_msg_ms)));
}

Expand All @@ -492,6 +490,13 @@ void AP_DroneCAN_DNA_Server::handle_allocation(const CanardRxTransfer& transfer,
if (rcvd_unique_id_offset == sizeof(rcvd_unique_id)) { // full unique ID received, allocate it!
rsp.node_id = db.handle_allocation(msg.node_id, rcvd_unique_id);
rcvd_unique_id_offset = 0; // reset state for next allocation
if (rsp.node_id == 0) { // allocation failed
GCS_SEND_TEXT(MAV_SEVERITY_ERROR, "DroneCAN DNA allocation failed; database full");
// don't send reply with a failed ID in case the allocatee does
// silly things, though it is technically legal. the allocatee will
// then time out and try again (though we still won't have an ID!)
return;
}
}

allocation_pub.broadcast(rsp, false); // never publish allocation message with CAN FD
Expand Down

0 comments on commit b9d68aa

Please sign in to comment.