From 8f2306fd1987913250bb31456e43896870517ca9 Mon Sep 17 00:00:00 2001 From: Eugene Shamaev Date: Sat, 6 May 2017 12:12:19 +0300 Subject: [PATCH] AP_HAL: support of several CAN managers (virtual drivers) --- libraries/AP_HAL/CAN.h | 4 ++++ libraries/AP_HAL/HAL.h | 25 +++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/libraries/AP_HAL/CAN.h b/libraries/AP_HAL/CAN.h index 693575f1c1..837a98b09b 100644 --- a/libraries/AP_HAL/CAN.h +++ b/libraries/AP_HAL/CAN.h @@ -29,6 +29,9 @@ #include #include +#define MAX_NUMBER_OF_CAN_INTERFACES 2 +#define MAX_NUMBER_OF_CAN_DRIVERS 2 + class AP_UAVCAN; /** @@ -108,6 +111,7 @@ public: true - CAN manager is initialized */ virtual bool is_initialized() = 0; + virtual void initialized(bool val); virtual AP_UAVCAN *get_UAVCAN(void); virtual void set_UAVCAN(AP_UAVCAN *uavcan); diff --git a/libraries/AP_HAL/HAL.h b/libraries/AP_HAL/HAL.h index 789bd95dba..da8b8f8171 100644 --- a/libraries/AP_HAL/HAL.h +++ b/libraries/AP_HAL/HAL.h @@ -34,7 +34,11 @@ public: AP_HAL::Scheduler* _scheduler, AP_HAL::Util* _util, AP_HAL::OpticalFlow *_opticalflow, - AP_HAL::CANManager* _can_mgr) +#if HAL_WITH_UAVCAN + AP_HAL::CANManager* _can_mgr[MAX_NUMBER_OF_CAN_DRIVERS]) +#else + AP_HAL::CANManager** _can_mgr) +#endif : uartA(_uartA), uartB(_uartB), @@ -52,9 +56,18 @@ public: rcout(_rcout), scheduler(_scheduler), util(_util), - opticalflow(_opticalflow), - can_mgr(_can_mgr) + opticalflow(_opticalflow) { +#if HAL_WITH_UAVCAN + if (_can_mgr == nullptr) { + for (uint8_t i = 0; i < MAX_NUMBER_OF_CAN_DRIVERS; i++) + can_mgr[i] = nullptr; + } else { + for (uint8_t i = 0; i < MAX_NUMBER_OF_CAN_DRIVERS; i++) + can_mgr[i] = _can_mgr[i]; + } +#endif + AP_HAL::init(); } @@ -93,5 +106,9 @@ public: AP_HAL::Scheduler* scheduler; AP_HAL::Util *util; AP_HAL::OpticalFlow *opticalflow; - AP_HAL::CANManager* can_mgr; +#if HAL_WITH_UAVCAN + AP_HAL::CANManager* can_mgr[MAX_NUMBER_OF_CAN_DRIVERS]; +#else + AP_HAL::CANManager** can_mgr; +#endif };