mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
uavcannode: add CANNODE_NODE_ID to allow setting static node ID
This commit is contained in:
parent
6e8f61c551
commit
0b63b8317a
@ -824,6 +824,27 @@ extern "C" int uavcannode_start(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
// Read the static node ID parameter and use it if no valid node_id from shared memory
|
||||
int32_t cannode_node_id = 0;
|
||||
param_get(param_find("CANNODE_NODE_ID"), &cannode_node_id);
|
||||
|
||||
// Check if the static node ID is in range
|
||||
if (cannode_node_id < 0 || cannode_node_id > 127) {
|
||||
PX4_ERR("Invalid static node ID %ld, using dynamic allocation", cannode_node_id);
|
||||
cannode_node_id = 0;
|
||||
}
|
||||
|
||||
// Assign the static node ID if no dynamic allocation is used. Do wen't override a valid node ID from the bootloader?
|
||||
if (node_id == 0 && cannode_node_id > 0 && cannode_node_id <= 127) {
|
||||
node_id = cannode_node_id;
|
||||
}
|
||||
|
||||
// Persist the node ID for the bootloader
|
||||
bootloader_app_shared_t shared_write = {};
|
||||
shared_write.node_id = node_id;
|
||||
shared_write.bus_speed = bitrate;
|
||||
bootloader_app_shared_write(&shared_write, BootLoader);
|
||||
|
||||
if (
|
||||
#if defined(SUPPORT_ALT_CAN_BOOTLOADER)
|
||||
board_booted_by_px4() &&
|
||||
|
||||
@ -31,6 +31,15 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* UAVCAN CAN node ID (0 for dynamic allocation).
|
||||
*
|
||||
* @min 0
|
||||
* @max 127
|
||||
* @group UAVCAN
|
||||
*/
|
||||
PARAM_DEFINE_INT32(CANNODE_NODE_ID, 0);
|
||||
|
||||
/**
|
||||
* UAVCAN CAN bus bitrate.
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user