Dynamic Node Allocation
https://dronecan.github.io/Specification/6._Application_level_functions/
The following diagram may aid understanding of the allocatee side of the algorithm:
Handler
static void handle_DNA_Allocation(CanardInstance *ins, CanardRxTransfer *transfer){}
Function header, this is on the allottee side that handles the allocation from the flight controller
if(canardGetLocalNodeID(&canard) != CANARD_BROADCAST_NODE_ID){
// allocated
return;
}
Here the constant CANARD_BROADCAST_NODE_ID
= 0, the function canardGetLocalNodeID gets the node_id of the current canard instance.
In canardInit(), there is a line out_ins->node_id = CANARD_BROADCAST_NODE_ID, where we set the node_id to 0 on startup.
uint8_t canardGetLocalNodeID(const CanardInstance* ins)
{
return ins->node_id;
}
Now allocate a random time interval for the gap between each DNA process to avoid as much collision as possible as all components connected on the CAN will be requesting a node ID on startup.
Here transfer->source_node_id is set to 0 if it is anonymous, indicating a broadcasted from an unallocated node.
Error handling and if the message is in the correct length and contains the correct information. Complete the dynamic node allocation.
Send Request
static void request_DNA()
Function header for the request for dynamic node allocation from the allocatee side.