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);