mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 06:28:27 -04:00
AP_BoardConfig: support KDECAN
Until #9397 is fixed, we need to have separate params for each driver type, but code was left as generic as possible
This commit is contained in:
parent
8850ab73a6
commit
37965b13b6
@ -35,7 +35,10 @@
|
||||
#include <AP_HAL_ChibiOS/CAN.h>
|
||||
#endif
|
||||
|
||||
#include <AP_Vehicle/AP_Vehicle.h>
|
||||
|
||||
#include <AP_UAVCAN/AP_UAVCAN.h>
|
||||
#include <AP_KDECAN/AP_KDECAN.h>
|
||||
|
||||
extern const AP_HAL::HAL& hal;
|
||||
|
||||
@ -137,20 +140,34 @@ 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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AP_BoardConfig_CAN& AP::can() {
|
||||
return *AP_BoardConfig_CAN::get_singleton();
|
||||
|
@ -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];
|
||||
|
@ -17,13 +17,21 @@
|
||||
|
||||
#if HAL_WITH_UAVCAN
|
||||
#include "AP_BoardConfig_CAN.h"
|
||||
#include <AP_Vehicle/AP_Vehicle.h>
|
||||
|
||||
#include <AP_UAVCAN/AP_UAVCAN.h>
|
||||
|
||||
// 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 <AP_KDECAN/AP_KDECAN.h>
|
||||
#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
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user