From c1c8158687b7cba57cbc7e80623fe7b8cc8be517 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Sat, 11 Mar 2023 11:46:34 +1100 Subject: [PATCH] AP_CANManager: add and use option to compile SLCAN support out of code --- libraries/AP_CANManager/AP_CANManager.cpp | 8 ++++++++ libraries/AP_CANManager/AP_CANManager.h | 5 +++++ libraries/AP_CANManager/AP_CANManager_config.h | 7 +++++++ libraries/AP_CANManager/AP_SLCANIface.cpp | 4 ++-- libraries/AP_CANManager/AP_SLCANIface.h | 8 +++++--- 5 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 libraries/AP_CANManager/AP_CANManager_config.h diff --git a/libraries/AP_CANManager/AP_CANManager.cpp b/libraries/AP_CANManager/AP_CANManager.cpp index 2c00572326..b84a749c05 100644 --- a/libraries/AP_CANManager/AP_CANManager.cpp +++ b/libraries/AP_CANManager/AP_CANManager.cpp @@ -87,9 +87,11 @@ const AP_Param::GroupInfo AP_CANManager::var_info[] = { AP_SUBGROUPINFO(_drv_param[2], "D3_", 6, AP_CANManager, AP_CANManager::CANDriver_Params), #endif +#if AP_CAN_SLCAN_ENABLED // @Group: SLCAN_ // @Path: ../AP_CANManager/AP_SLCANIface.cpp AP_SUBGROUPINFO(_slcan_interface, "SLCAN_", 7, AP_CANManager, SLCAN::CANIface), +#endif // @Param: LOGLEVEL // @DisplayName: Loglevel @@ -134,8 +136,10 @@ void AP_CANManager::init() _log_pos = 0; } +#if AP_CAN_SLCAN_ENABLED //Reset all SLCAN related params that needs resetting at boot _slcan_interface.reset_params(); +#endif Driver_Type drv_type[HAL_MAX_CAN_PROTOCOL_DRIVERS] = {}; // loop through interfaces and allocate and initialise Iface, @@ -165,11 +169,15 @@ void AP_CANManager::init() bool can_initialised = false; // Check if this interface need hooking up to slcan passthrough // instead of a driver +#if AP_CAN_SLCAN_ENABLED if (_slcan_interface.init_passthrough(i)) { // we have slcan bridge setup pass that on as can iface can_initialised = hal.can[i]->init(_interfaces[i]._bitrate, _interfaces[i]._fdbitrate*1000000, AP_HAL::CANIface::NormalMode); iface = &_slcan_interface; } else { +#else + if (true) { +#endif can_initialised = hal.can[i]->init(_interfaces[i]._bitrate, _interfaces[i]._fdbitrate*1000000, AP_HAL::CANIface::NormalMode); } diff --git a/libraries/AP_CANManager/AP_CANManager.h b/libraries/AP_CANManager/AP_CANManager.h index f5c6a99131..5b04384a8a 100644 --- a/libraries/AP_CANManager/AP_CANManager.h +++ b/libraries/AP_CANManager/AP_CANManager.h @@ -17,6 +17,8 @@ #pragma once +#include "AP_CANManager_config.h" + #include #if HAL_MAX_CAN_PROTOCOL_DRIVERS @@ -166,7 +168,10 @@ private: AP_Int8 _loglevel; uint8_t _num_drivers; +#if AP_CAN_SLCAN_ENABLED SLCAN::CANIface _slcan_interface; +#endif + static AP_CANManager *_singleton; char* _log_buf; diff --git a/libraries/AP_CANManager/AP_CANManager_config.h b/libraries/AP_CANManager/AP_CANManager_config.h new file mode 100644 index 0000000000..c8b9f8af91 --- /dev/null +++ b/libraries/AP_CANManager/AP_CANManager_config.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +#ifndef AP_CAN_SLCAN_ENABLED +#define AP_CAN_SLCAN_ENABLED HAL_MAX_CAN_PROTOCOL_DRIVERS +#endif diff --git a/libraries/AP_CANManager/AP_SLCANIface.cpp b/libraries/AP_CANManager/AP_SLCANIface.cpp index 8c11ffdccc..62ccd0e44e 100644 --- a/libraries/AP_CANManager/AP_SLCANIface.cpp +++ b/libraries/AP_CANManager/AP_SLCANIface.cpp @@ -19,7 +19,7 @@ #include "AP_SLCANIface.h" -#if HAL_MAX_CAN_PROTOCOL_DRIVERS +#if AP_CAN_SLCAN_ENABLED #include #include @@ -770,4 +770,4 @@ void SLCAN::CANIface::reset_params() { _slcan_ser_port.set_and_save(-1); } -#endif +#endif // AP_CAN_SLCAN_ENABLED diff --git a/libraries/AP_CANManager/AP_SLCANIface.h b/libraries/AP_CANManager/AP_SLCANIface.h index 9a67bcdd1d..2f3f35382c 100644 --- a/libraries/AP_CANManager/AP_SLCANIface.h +++ b/libraries/AP_CANManager/AP_SLCANIface.h @@ -17,9 +17,11 @@ #pragma once -#include +#include "AP_CANManager_config.h" -#if HAL_MAX_CAN_PROTOCOL_DRIVERS +#if AP_CAN_SLCAN_ENABLED + +#include #include "AP_HAL/utility/RingBuffer.h" #include @@ -139,4 +141,4 @@ protected: } -#endif +#endif // AP_CAN_SLCAN_ENABLED