Class TwaiInterface

Inheritance Relationships

Base Type

Class Documentation

class TwaiInterface : public hi_can::FilteredCanInterface

Inheritance diagram for hi_can::TwaiInterface:

Collaboration diagram for hi_can::TwaiInterface:

Public Functions

virtual ~TwaiInterface()
TwaiInterface(const TwaiInterface&) = delete
inline TwaiInterface(TwaiInterface &&other) noexcept
TwaiInterface &operator=(const TwaiInterface&) = delete
inline TwaiInterface &operator=(TwaiInterface &&other) noexcept
virtual void transmit(const Packet &packet) override

Transmits a packet on the CAN bus.

Parameters:
const Packet &packet

Packet to transmit

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

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

void handle()

Handle error detection and recovery on the underlying TWAI bus.

This function must be called regularly to ensure that the bus recovers and has errors handled correctly.

virtual TwaiInterface &add_filter(const addressing::filter_t &address) override

Add a filter to the interface.

Returns:

Itself for chaining

virtual TwaiInterface &remove_filter(const addressing::filter_t &address) override

Remove a filter from the interface.

Returns:

Itself for chaining

Public Static Functions

static TwaiInterface &get_instance(bsp::pin_pair_t pins = std::make_pair(bsp::CAN_TX_PIN, bsp::CAN_RX_PIN), uint8_t controller_id = 0, addressing::filter_t filter = {})

Friends

inline friend void swap(TwaiInterface &first, TwaiInterface &second) noexcept