AP_Periph: clean up node ID parameter handling

Properly document the range and behavior.

Rename storage variable as it doesn't connect to the DNA preferred ID
feature.
This commit is contained in:
Thomas Watson 2024-09-08 23:36:10 -05:00 committed by Andrew Tridgell
parent aca624486d
commit dcd34dd39e
2 changed files with 8 additions and 11 deletions

View File

@ -86,9 +86,9 @@ const AP_Param::Info AP_Periph_FW::var_info[] = {
GSCALAR(format_version, "FORMAT_VERSION", 0),
// @Param: CAN_NODE
// @DisplayName: UAVCAN node that is used for this network
// @Description: UAVCAN node should be set implicitly or 0 for dynamic node allocation
// @Range: 0 250
// @DisplayName: DroneCAN node ID used by this node on all networks
// @Description: Value of 0 requests any ID from a DNA server, any other value sets that ID ignoring DNA
// @Range: 0 127
// @User: Advanced
// @RebootRequired: True
GSCALAR(can_node, "CAN_NODE", HAL_CAN_DEFAULT_NODE_ID),

View File

@ -125,10 +125,7 @@ HAL_GPIO_PIN_TERMCAN1
};
#endif // CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS && defined(HAL_GPIO_PIN_TERMCAN1)
#ifndef HAL_CAN_DEFAULT_NODE_ID
#define HAL_CAN_DEFAULT_NODE_ID CANARD_BROADCAST_NODE_ID
#endif
uint8_t PreferredNodeID = HAL_CAN_DEFAULT_NODE_ID;
uint8_t user_set_node_id = HAL_CAN_DEFAULT_NODE_ID;
#ifndef AP_PERIPH_PROBE_CONTINUOUS
#define AP_PERIPH_PROBE_CONTINUOUS 0
@ -1550,7 +1547,7 @@ bool AP_Periph_FW::can_do_dna()
// Structure of the request is documented in the DSDL definition
// See http://uavcan.org/Specification/6._Application_level_functions/#dynamic-node-id-allocation
uint8_t allocation_request[CANARD_CAN_FRAME_MAX_DATA_LEN - 1];
allocation_request[0] = (uint8_t)(PreferredNodeID << 1U);
allocation_request[0] = 0; // we are only called if the user has not set an ID, so request any ID
if (dronecan.node_id_allocation_unique_id_offset == 0) {
allocation_request[0] |= 1; // First part of unique ID
@ -1590,7 +1587,7 @@ void AP_Periph_FW::can_start()
node_status.uptime_sec = AP_HAL::millis() / 1000U;
if (g.can_node >= 0 && g.can_node < 128) {
PreferredNodeID = g.can_node;
user_set_node_id = g.can_node;
}
#if !defined(HAL_NO_FLASH_SUPPORT) && !defined(HAL_NO_ROMFS_SUPPORT)
@ -1662,8 +1659,8 @@ void AP_Periph_FW::can_start()
canardInit(&dronecan.canard, (uint8_t *)dronecan.canard_memory_pool, sizeof(dronecan.canard_memory_pool),
onTransferReceived_trampoline, shouldAcceptTransfer_trampoline, this);
if (PreferredNodeID != CANARD_BROADCAST_NODE_ID) {
canardSetLocalNodeID(&dronecan.canard, PreferredNodeID);
if (user_set_node_id != CANARD_BROADCAST_NODE_ID) {
canardSetLocalNodeID(&dronecan.canard, user_set_node_id);
}
}