diff --git a/libraries/AP_BoardConfig/AP_BoardConfig_CAN.cpp b/libraries/AP_BoardConfig/AP_BoardConfig_CAN.cpp index 9483491b34..9c4fbcefbd 100644 --- a/libraries/AP_BoardConfig/AP_BoardConfig_CAN.cpp +++ b/libraries/AP_BoardConfig/AP_BoardConfig_CAN.cpp @@ -35,7 +35,10 @@ #include #endif +#include + #include +#include extern const AP_HAL::HAL& hal; @@ -137,17 +140,31 @@ void AP_BoardConfig_CAN::init() printf("can_mgr %d initialized well\n\r", i + 1); if (prot_type == Protocol_Type_UAVCAN) { - _drivers[i]._driver = new AP_UAVCAN; + _drivers[i]._driver = _drivers[i]._uavcan = new AP_UAVCAN; if (_drivers[i]._driver == nullptr) { AP_HAL::panic("Failed to allocate uavcan %d\n\r", i + 1); continue; } - AP_Param::load_object_from_eeprom(_drivers[i]._driver, AP_UAVCAN::var_info); + AP_Param::load_object_from_eeprom(_drivers[i]._uavcan, AP_UAVCAN::var_info); + } else if (prot_type == Protocol_Type_KDECAN) { +// To be replaced with macro saying if KDECAN library is included +#if APM_BUILD_TYPE(APM_BUILD_ArduCopter) || APM_BUILD_TYPE(APM_BUILD_ArduPlane) || APM_BUILD_TYPE(APM_BUILD_ArduSub) + _drivers[i]._driver = _drivers[i]._kdecan = new AP_KDECAN; - _drivers[i]._driver->init(i); + if (_drivers[i]._driver == nullptr) { + AP_HAL::panic("Failed to allocate KDECAN %d\n\r", i + 1); + continue; + } + + AP_Param::load_object_from_eeprom(_drivers[i]._kdecan, AP_KDECAN::var_info); +#endif + } else { + continue; } + + _drivers[i]._driver->init(i); } } } diff --git a/libraries/AP_BoardConfig/AP_BoardConfig_CAN.h b/libraries/AP_BoardConfig/AP_BoardConfig_CAN.h index 0cd7f9da89..897f3b71d2 100644 --- a/libraries/AP_BoardConfig/AP_BoardConfig_CAN.h +++ b/libraries/AP_BoardConfig/AP_BoardConfig_CAN.h @@ -25,6 +25,7 @@ public: enum Protocol_Type : uint8_t { Protocol_Type_None = 0, Protocol_Type_UAVCAN = 1, + Protocol_Type_KDECAN = 2, }; void init(void); @@ -120,6 +121,8 @@ private: AP_Int8 _protocol_type; Protocol_Type _protocol_type_cache; AP_HAL::CANProtocol* _driver; + AP_HAL::CANProtocol* _uavcan; + AP_HAL::CANProtocol* _kdecan; }; Interface _interfaces[MAX_NUMBER_OF_CAN_INTERFACES]; diff --git a/libraries/AP_BoardConfig/canbus_driver.cpp b/libraries/AP_BoardConfig/canbus_driver.cpp index 49b35a538c..a13c58870f 100644 --- a/libraries/AP_BoardConfig/canbus_driver.cpp +++ b/libraries/AP_BoardConfig/canbus_driver.cpp @@ -16,14 +16,22 @@ #include #if HAL_WITH_UAVCAN -#include "AP_BoardConfig_CAN.h" -#include + #include "AP_BoardConfig_CAN.h" + #include + + #include + + // To be replaced with macro saying if KDECAN library is included + #if APM_BUILD_TYPE(APM_BUILD_ArduCopter) || APM_BUILD_TYPE(APM_BUILD_ArduPlane) || APM_BUILD_TYPE(APM_BUILD_ArduSub) + #include + #endif // table of user settable CAN bus parameters const AP_Param::GroupInfo AP_BoardConfig_CAN::Driver::var_info[] = { // @Param: PROTOCOL // @DisplayName: Enable use of specific protocol over virtual driver // @Description: Enabling this option starts selected protocol that will use this virtual driver + // @Values{Copter,Plane,Sub}: 0:Disabled,1:UAVCAN,2:KDECAN // @Values: 0:Disabled,1:UAVCAN // @User: Advanced // @RebootRequired: True @@ -31,7 +39,14 @@ const AP_Param::GroupInfo AP_BoardConfig_CAN::Driver::var_info[] = { // @Group: UC_ // @Path: ../AP_UAVCAN/AP_UAVCAN.cpp - AP_SUBGROUPPTR(_driver, "UC_", 2, AP_BoardConfig_CAN::Driver, AP_UAVCAN), + AP_SUBGROUPPTR(_uavcan, "UC_", 2, AP_BoardConfig_CAN::Driver, AP_UAVCAN), + +// To be replaced with macro saying if KDECAN library is included +#if APM_BUILD_TYPE(APM_BUILD_ArduCopter) || APM_BUILD_TYPE(APM_BUILD_ArduPlane) || APM_BUILD_TYPE(APM_BUILD_ArduSub) + // @Group: KDE_ + // @Path: ../AP_KDECAN/AP_KDECAN.cpp + AP_SUBGROUPPTR(_kdecan, "KDE_", 3, AP_BoardConfig_CAN::Driver, AP_KDECAN), +#endif AP_GROUPEND };