diff --git a/libraries/AP_BoardConfig/AP_BoardConfig.cpp b/libraries/AP_BoardConfig/AP_BoardConfig.cpp index e7443a7706..c55dd7737e 100644 --- a/libraries/AP_BoardConfig/AP_BoardConfig.cpp +++ b/libraries/AP_BoardConfig/AP_BoardConfig.cpp @@ -99,6 +99,12 @@ const AP_Param::GroupInfo AP_BoardConfig::var_info[] = { #if CONFIG_HAL_BOARD == HAL_BOARD_PX4 && !defined(CONFIG_ARCH_BOARD_PX4FMU_V1) extern "C" int uavcan_main(int argc, const char *argv[]); + +#define _UAVCAN_IOCBASE (0x4000) // IOCTL base for module UAVCAN +#define _UAVCAN_IOC(_n) (_IOC(_UAVCAN_IOCBASE, _n)) + +#define UAVCAN_IOCG_NODEID_INPROGRESS _UAVCAN_IOC(1) // query if node identification is in progress + #endif void AP_BoardConfig::init() @@ -159,9 +165,17 @@ void AP_BoardConfig::init() if (ret != 0) { hal.console->printf("UAVCAN: failed to start servers\n"); } else { - hal.console->printf("UAVCAN: servers started\n"); - // give some time for CAN bus initialisation - hal.scheduler->delay(500); + fd = open("/dev/uavcan/esc", 0); // design flaw of uavcan driver, this should be /dev/uavcan/node one day + if (fd == -1) { + AP_HAL::panic("Configuration invalid - unable to open /dev/uavcan/esc"); + } + + // delay startup, UAVCAN still discovering nodes + while (ioctl(fd, UAVCAN_IOCG_NODEID_INPROGRESS,0) == OK) { + hal.scheduler->delay(500); + } + hal.console->printf("UAVCAN: node discovery complete\n"); + close(fd); } } #endif