Lely core libraries  1.9.2
lely::canopen::IoContext Class Reference

The I/O context. More...

#include <io_context.hpp>

Inheritance diagram for lely::canopen::IoContext:

Data Structures

struct  Impl_
 The internal implementation of the I/O context. More...
 

Public Member Functions

 IoContext (aio::TimerBase &timer, aio::CanBusBase &bus, BasicLockable *mutex=nullptr)
 Creates a new I/O context. More...
 
aio::ExecutorBase GetExecutor () const noexcept
 Returns the executor used to process I/O events on the CAN bus.
 
template<class F >
void Post (F &&f)
 Schedules the specified Callable object for execution. More...
 

Protected Member Functions

CANNetnet () const noexcept
 Returns a pointer to the internal CAN network interface from <lely/can/net.hpp>.
 
void SetTime ()
 Update the CAN network time. More...
 
virtual void OnCanState (CanState new_state, CanState old_state) noexcept
 The function invoked when a CAN bus state change is detected. More...
 
virtual void OnCanError (CanError error) noexcept
 The function invoked when an error is detected on the CAN bus. More...
 

Detailed Description

The I/O context.

This context manages all timer and I/O events on the CAN bus.

Definition at line 42 of file io_context.hpp.

Constructor & Destructor Documentation

◆ IoContext()

lely::canopen::IoContext::IoContext ( aio::TimerBase &  timer,
aio::CanBusBase &  bus,
BasicLockable mutex = nullptr 
)

Creates a new I/O context.

Parameters
timerthe timer used for CANopen events.
busa handle to the CAN bus.
mutexan (optional) pointer to the mutex to be locked while timer and I/O events are processed. The mutex MUST be unlocked when any public member function is invoked; it will be locked for the duration of any call to a virtual member function (OnCanState() or OnCanError()).

Definition at line 74 of file io_context.cpp.

Member Function Documentation

◆ Post()

template<class F >
void lely::canopen::IoContext::Post ( F &&  f)
inline

Schedules the specified Callable object for execution.

See also
GetExecutor()

Definition at line 70 of file io_context.hpp.

◆ SetTime()

void lely::canopen::IoContext::SetTime ( )
protected

Update the CAN network time.

If a mutex was passed to the constructor, it MUST be locked for the duration of this call.

Definition at line 91 of file io_context.cpp.

◆ OnCanState()

virtual void lely::canopen::IoContext::OnCanState ( CanState  new_state,
CanState  old_state 
)
inlineprotectedvirtualnoexcept

The function invoked when a CAN bus state change is detected.

The state is represented by one the CanState::ACTIVE, CanState::PASSIVE or CanState::BUSOFF values.

Parameters
new_statethe current state of the CAN bus.
old_statethe previous state of the CAN bus.

Reimplemented in lely::canopen::AsyncMaster, lely::canopen::BasicMaster, and lely::canopen::Node.

Definition at line 104 of file io_context.hpp.

◆ OnCanError()

virtual void lely::canopen::IoContext::OnCanError ( CanError  error)
inlineprotectedvirtualnoexcept

The function invoked when an error is detected on the CAN bus.

Parameters
errora bitwise combination of CanError::BIT, CanError::STUFF, CanError::CRC, CanError::FORM, CanError::ACK and CanError::OTHER.

Reimplemented in lely::canopen::AsyncMaster, and lely::canopen::BasicMaster.

Definition at line 117 of file io_context.hpp.


The documentation for this class was generated from the following files: