Provides a common queuing and thread layer for running the CAN stack and all CAN drivers.
More...
#include <can_hardware_interface.hpp>
|
static void | update_thread_function () |
| The main thread loop for updating the stack.
|
|
static void | start_threads () |
| Starts all threads related to the hardware interface.
|
|
static void | stop_threads () |
| Stops all threads related to the hardware interface.
|
|
Provides a common queuing and thread layer for running the CAN stack and all CAN drivers.
The CANHardwareInterface
class was created to provide a common queuing and thread layer for running the CAN stack and all CAN drivers to simplify integration and crucially to provide a consistent, safe order of operations for all the function calls needed to properly drive the stack.
Definition at line 36 of file can_hardware_interface.hpp.
◆ ~CANHardwareInterface()
isobus::CANHardwareInterface::~CANHardwareInterface |
( |
| ) |
|
|
privatevirtual |
◆ assign_can_channel_frame_handler()
bool isobus::CANHardwareInterface::assign_can_channel_frame_handler |
( |
std::uint8_t | channelIndex, |
|
|
std::shared_ptr< CANHardwarePlugin > | canDriver ) |
|
static |
Assigns a CAN driver to a channel.
- Parameters
-
[in] | channelIndex | The channel to assign to |
[in] | canDriver | The driver to assign to the channel |
- Note
- The function will fail if the channel is already assigned to a driver or the interface is already started
- Returns
true
if the driver was assigned to the channel, otherwise false
Definition at line 182 of file can_hardware_interface.cpp.
◆ get_assigned_can_channel_frame_handler()
std::shared_ptr< CANHardwarePlugin > isobus::CANHardwareInterface::get_assigned_can_channel_frame_handler |
( |
std::uint8_t | channelIndex | ) |
|
|
static |
Gets the CAN driver assigned to a channel.
- Parameters
-
[in] | channelIndex | The channel to get the driver from |
- Returns
- The driver assigned to the channel, or
nullptr
if the channel is not assigned
Definition at line 242 of file can_hardware_interface.cpp.
◆ get_can_frame_received_event_dispatcher()
EventDispatcher< const CANMessageFrame & > & isobus::CANHardwareInterface::get_can_frame_received_event_dispatcher |
( |
| ) |
|
|
static |
Get the event dispatcher for when a CAN message frame is received from hardware event.
- Returns
- The event dispatcher which can be used to register callbacks/listeners to
Definition at line 328 of file can_hardware_interface.cpp.
◆ get_can_frame_transmitted_event_dispatcher()
EventDispatcher< const CANMessageFrame & > & isobus::CANHardwareInterface::get_can_frame_transmitted_event_dispatcher |
( |
| ) |
|
|
static |
Get the event dispatcher for when a CAN message frame will be send to hardware event.
- Returns
- The event dispatcher which can be used to register callbacks/listeners to
Definition at line 333 of file can_hardware_interface.cpp.
◆ get_number_of_can_channels()
std::uint8_t isobus::CANHardwareInterface::get_number_of_can_channels |
( |
| ) |
|
|
static |
Returns the number of configured CAN channels that the class is managing.
- Returns
- The number of configured CAN channels that the class is managing
Definition at line 210 of file can_hardware_interface.cpp.
◆ get_periodic_update_event_dispatcher()
EventDispatcher & isobus::CANHardwareInterface::get_periodic_update_event_dispatcher |
( |
| ) |
|
|
static |
Get the event dispatcher for when a periodic update is called.
- Returns
- The event dispatcher which can be used to register callbacks/listeners to
Definition at line 338 of file can_hardware_interface.cpp.
◆ get_periodic_update_interval()
std::uint32_t isobus::CANHardwareInterface::get_periodic_update_interval |
( |
| ) |
|
|
static |
Get the interval between periodic updates to the network manager.
- Returns
- The interval between update calls in milliseconds
Definition at line 348 of file can_hardware_interface.cpp.
◆ is_running()
bool isobus::CANHardwareInterface::is_running |
( |
| ) |
|
|
static |
Checks if the CAN stack and CAN drivers are running.
- Returns
true
if the threads are running, otherwise false
Definition at line 290 of file can_hardware_interface.cpp.
◆ set_number_of_can_channels()
bool isobus::CANHardwareInterface::set_number_of_can_channels |
( |
std::uint8_t | value, |
|
|
std::size_t | queueCapacity = 40 ) |
|
static |
Sets the number of CAN channels to manage.
Allocates the proper number of CanHardware
objects to track each CAN channel's Tx and Rx message queues. If you pass in a smaller number than what was already configured, it will delete the unneeded CanHardware
objects.
- Note
- The function will fail if the channel is already assigned to a driver or the interface is already started
- Parameters
-
value | The number of CAN channels to manage |
queueCapacity | The capacity of the transmit and receive queues |
- Returns
true
if the channel count was set, otherwise false
.
Definition at line 161 of file can_hardware_interface.cpp.
◆ set_periodic_update_interval()
void isobus::CANHardwareInterface::set_periodic_update_interval |
( |
std::uint32_t | value | ) |
|
|
static |
Set the interval between periodic updates to the network manager.
- Parameters
-
[in] | value | The interval between update calls in milliseconds |
Definition at line 343 of file can_hardware_interface.cpp.
◆ start()
bool isobus::CANHardwareInterface::start |
( |
| ) |
|
|
static |
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)
Definition at line 253 of file can_hardware_interface.cpp.
◆ start_threads()
void isobus::CANHardwareInterface::start_threads |
( |
| ) |
|
|
staticprivate |
◆ stop()
bool isobus::CANHardwareInterface::stop |
( |
| ) |
|
|
static |
Stops all CAN management threads and discards all remaining messages in the Tx and Rx queues.
- Returns
true
if the threads were stopped, otherwise false
Definition at line 268 of file can_hardware_interface.cpp.
◆ stop_threads()
void isobus::CANHardwareInterface::stop_threads |
( |
| ) |
|
|
staticprivate |
◆ transmit_can_frame()
bool isobus::CANHardwareInterface::transmit_can_frame |
( |
const CANMessageFrame & | frame | ) |
|
|
static |
Called externally, adds a message to a CAN channel's Tx queue.
- Parameters
-
[in] | frame | The frame to add to the Tx queue |
- Returns
true
if the frame was accepted, otherwise false
(maybe wrong channel assigned)
Definition at line 295 of file can_hardware_interface.cpp.
◆ unassign_can_channel_frame_handler()
bool isobus::CANHardwareInterface::unassign_can_channel_frame_handler |
( |
std::uint8_t | channelIndex | ) |
|
|
static |
Removes a CAN driver from a channel.
- Parameters
-
[in] | channelIndex | The channel to remove the driver from |
- Note
- The function will fail if the channel is already assigned to a driver or the interface is already started
- Returns
true
if the driver was removed from the channel, otherwise false
Definition at line 215 of file can_hardware_interface.cpp.
◆ update()
void isobus::CANHardwareInterface::update |
( |
| ) |
|
|
static |
Call this periodically if you have threads disabled.
- Note
- Try to call this very often, say at least every millisecond to ensure CAN messages are retrieved from the hardware
Definition at line 353 of file can_hardware_interface.cpp.
◆ update_thread_function()
void isobus::CANHardwareInterface::update_thread_function |
( |
| ) |
|
|
staticprivate |
◆ frameReceivedEventDispatcher
EventDispatcher< const CANMessageFrame & > isobus::CANHardwareInterface::frameReceivedEventDispatcher |
|
staticprivate |
◆ frameTransmittedEventDispatcher
EventDispatcher< const CANMessageFrame & > isobus::CANHardwareInterface::frameTransmittedEventDispatcher |
|
staticprivate |
◆ hardwareChannels
◆ hardwareChannelsMutex
Mutex isobus::CANHardwareInterface::hardwareChannelsMutex |
|
staticprivate |
◆ lastUpdateTimestamp
std::uint32_t isobus::CANHardwareInterface::lastUpdateTimestamp |
|
staticprivate |
◆ PERIODIC_UPDATE_INTERVAL
constexpr std::uint32_t isobus::CANHardwareInterface::PERIODIC_UPDATE_INTERVAL = 4 |
|
staticconstexprprivate |
◆ periodicUpdateEventDispatcher
EventDispatcher isobus::CANHardwareInterface::periodicUpdateEventDispatcher |
|
staticprivate |
◆ periodicUpdateInterval
◆ SINGLETON
◆ started
bool isobus::CANHardwareInterface::started = false |
|
staticprivate |
◆ updateMutex
Mutex isobus::CANHardwareInterface::updateMutex |
|
staticprivate |
◆ updateThread
std::unique_ptr< std::thread > isobus::CANHardwareInterface::updateThread |
|
staticprivate |
◆ updateThreadWakeupCondition
std::condition_variable isobus::CANHardwareInterface::updateThreadWakeupCondition |
|
staticprivate |
The documentation for this class was generated from the following files: