From 86219cfd58437f2a6fad35d44e9e22eb0e191b48 Mon Sep 17 00:00:00 2001 From: Adrian Del Grosso <10929341+ad3154@users.noreply.github.com> Date: Thu, 28 Dec 2023 10:55:11 -0700 Subject: [PATCH] [HW]: Add a way to get each channel's assigned frame handler (cherry picked from commit 61482dcb6970ec57b79e929d3abbe2a0dbbb9bad) --- .../hardware_integration/can_hardware_interface.hpp | 5 +++++ hardware_integration/src/can_hardware_interface.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/hardware_integration/include/isobus/hardware_integration/can_hardware_interface.hpp b/hardware_integration/include/isobus/hardware_integration/can_hardware_interface.hpp index b1bf0da6..6102ea66 100644 --- a/hardware_integration/include/isobus/hardware_integration/can_hardware_interface.hpp +++ b/hardware_integration/include/isobus/hardware_integration/can_hardware_interface.hpp @@ -64,6 +64,11 @@ namespace isobus /// @returns `true` if the driver was removed from the channel, otherwise `false` static bool unassign_can_channel_frame_handler(std::uint8_t channelIndex); + /// @brief Gets the CAN driver assigned to a channel + /// @param[in] channelIndex The channel to get the driver from + /// @returns The driver assigned to the channel, or `nullptr` if the channel is not assigned + static std::shared_ptr get_assigned_can_channel_frame_handler(std::uint8_t channelIndex); + /// @brief Starts the threads for managing the CAN stack and CAN drivers /// @returns `true` if the threads were started, otherwise false (perhaps they are already running) static bool start(); diff --git a/hardware_integration/src/can_hardware_interface.cpp b/hardware_integration/src/can_hardware_interface.cpp index af5483ee..9661f783 100644 --- a/hardware_integration/src/can_hardware_interface.cpp +++ b/hardware_integration/src/can_hardware_interface.cpp @@ -126,6 +126,17 @@ namespace isobus return true; } + std::shared_ptr CANHardwareInterface::get_assigned_can_channel_frame_handler(std::uint8_t channelIndex) + { + std::shared_ptr retVal; + + if (channelIndex < hardwareChannels.size()) + { + retVal = hardwareChannels.at(channelIndex)->frameHandler; + } + return retVal; + } + bool CANHardwareInterface::start() { std::lock_guard lock(hardwareChannelsMutex);