Class CanInterface

Inheritance Relationships

Derived Type

Class Documentation

class CanInterface

Inheritance diagram for hi_can::CanInterface:

Interface for sending and receiving packets on the CAN bus.

Subclassed by hi_can::FilteredCanInterface

Public Functions

virtual void transmit(const Packet &packet) = 0

Transmits a packet on the CAN bus.

Parameters:
const Packet &packet

Packet to transmit

virtual std::optional<Packet> receive(bool blocking = false) = 0

Pulls the next packet from the CAN bus buffer.

Parameters:
bool blocking = false

Whether to block until a packet is received

Returns:

The next packet in the buffer, or std::nullopt if the buffer is empty

virtual void receive_all(bool block = true)

Receives all packets from the CAN bus buffer.

Parameters:
bool block = true

Whether to block until at least one packet is received

inline virtual void set_receive_callback(const packet_callback_t &callback)

Sets a callback to be called when a packet is received.

Parameters:
const packet_callback_t &callback

Callback to use

inline void clear_receive_callback()

Clears the receive callback.

Protected Attributes

packet_callback_t _receive_callback = nullptr

The callback to call when a packet is received.