Skip to content

Class espos_n2k::TwaiReceiver

ClassList > espos_n2k > TwaiReceiver

Reads CAN frames from the TWAI peripheral and emits them as CanMessage values, on the shared node's RX task.

  • #include <espos_n2k/twai_receiver.h>

Public Types

Type Name
typedef std::function< void(const CanMessage &)> FrameFn

Public Functions

Type Name
TwaiReceiver (const TwaiReceiverConfig & config={})
uint32_t bus_off_count () const
Bus-off events counted by the shared node since it came up.
bool bus_running () const
Is the shared TWAI node up? False means the driver never started (bad pins, a failed twai_new_node_onchip) which from a candump socket looks exactly like a bus with nothing on it.
uint32_t error_count () const
Bus errors seen by the controller, and the flags of the most recent one (arb_lost, bit_err, form_err, stuff_err, ack_err IDF's twai_error_flags_t).
bool ever_received () const
True if we have received at least one frame since boot.
uint32_t frames_dropped () const
uint32_t frames_received () const
Frames the ISR accepted, and frames it had to drop because the queue was full.
uint32_t last_error_flags () const
int64_t seconds_since_last_rx () const
Seconds since the last received frame.
void set_on_frame (FrameFn fn)
Called on the receiver task for every frame. Set before start() .
void start ()
void stop ()
~TwaiReceiver ()

Public Types Documentation

typedef FrameFn

using espos_n2k::TwaiReceiver::FrameFn =  std::function<void(const CanMessage&)>;

Public Functions Documentation

function TwaiReceiver

explicit espos_n2k::TwaiReceiver::TwaiReceiver (
    const TwaiReceiverConfig & config={}
) 

function bus_off_count

Bus-off events counted by the shared node since it came up.

uint32_t espos_n2k::TwaiReceiver::bus_off_count () const


function bus_running

Is the shared TWAI node up? False means the driver never started (bad pins, a failed twai_new_node_onchip) which from a candump socket looks exactly like a bus with nothing on it.

bool espos_n2k::TwaiReceiver::bus_running () const


function error_count

Bus errors seen by the controller, and the flags of the most recent one (arb_lost, bit_err, form_err, stuff_err, ack_err IDF's twai_error_flags_t).

uint32_t espos_n2k::TwaiReceiver::error_count () const

Errors rising while frames stay at zero is the signature of a bus that is wired but wrong: an ack error on every transmission means nothing else is listening, and a stuff or form error storm usually means the bitrate does not match.


function ever_received

True if we have received at least one frame since boot.

inline bool espos_n2k::TwaiReceiver::ever_received () const


function frames_dropped

uint32_t espos_n2k::TwaiReceiver::frames_dropped () const

function frames_received

Frames the ISR accepted, and frames it had to drop because the queue was full.

uint32_t espos_n2k::TwaiReceiver::frames_received () const

A rising drop count is a consumer that cannot keep up, not a bus problem.


function last_error_flags

uint32_t espos_n2k::TwaiReceiver::last_error_flags () const

function seconds_since_last_rx

Seconds since the last received frame.

inline int64_t espos_n2k::TwaiReceiver::seconds_since_last_rx () const

Returns INT64_MAX if no frame has ever been received. esp_timer_get_time() returns int64 microseconds since boot — overflows in ~292,000 years, so no rollover concerns. (Was rx_count_ uint32 which overflowed at ~20 days of busy N2K traffic.)


function set_on_frame

Called on the receiver task for every frame. Set before start() .

inline void espos_n2k::TwaiReceiver::set_on_frame (
    FrameFn fn
) 


function start

void espos_n2k::TwaiReceiver::start () 

function stop

void espos_n2k::TwaiReceiver::stop () 

function ~TwaiReceiver

espos_n2k::TwaiReceiver::~TwaiReceiver () 


The documentation for this class was generated from the following file espos_n2k/include/espos_n2k/twai_receiver.h