Lely core libraries  2.2.5
lely::canopen::FiberDriver Class Reference

A CANopen driver running its tasks and callbacks in fibers. More...

#include <fiber_driver.hpp>

Inheritance diagram for lely::canopen::FiberDriver:
Collaboration diagram for lely::canopen::FiberDriver:

Public Member Functions

 FiberDriver (ev_exec_t *exec, AsyncMaster &master, uint8_t id)
 Creates a new CANopen driver and its associated fiber executor. More...
 
 FiberDriver (AsyncMaster &master, uint8_t id)
 Creates a new CANopen driver and its associated fiber executor.
 
ev::Executor GetStrand () const noexcept
 Returns the strand executor associated with the driver.
 
template<class F , class... Args>
void Defer (F &&f, Args &&... args)
 Schedules the specified Callable object for execution by strand for this driver. More...
 
template<class T >
Wait (SdoFuture< T > f)
 Waits for the specified future to become ready by suspending the calling fiber. More...
 
template<class T >
typename ::std::enable_if<!::std::is_void< T >::value, T >::type Wait (SdoFuture< T > f, ::std::error_code &ec)
 Waits for the specified future to become ready by suspending the calling fiber. More...
 
void Wait (SdoFuture< void > f, ::std::error_code &ec)
 Waits for the specified future to become ready by suspending the calling fiber. More...
 
void USleep (uint_least64_t usec)
 Suspends the calling fiber for usec microseconds. More...
 
void USleep (uint_least64_t usec, ::std::error_code &ec)
 Suspends the calling fiber for usec microseconds. More...
 
- Public Member Functions inherited from lely::canopen::BasicDriver
 BasicDriver (ev_exec_t *exec, BasicMaster &master, uint8_t id)
 Creates a new driver for a remote CANopen node and registers it with the master. More...
 
 BasicDriver (BasicMaster &master, uint8_t id)
 Creates a new driver for a remote CANopen node and registers it with the master.
 
ev::Executor GetExecutor () const noexcept final
 Returns the executor used to execute event handlers for this driver, including SDO confirmation functions.
 
uint8_t netid () const noexcept final
 Returns the network-ID.
 
uint8_t id () const noexcept final
 Returns the node-ID.
 
void ConfigHeartbeat (const ::std::chrono::milliseconds &ms, ::std::error_code &ec)
 Configures heartbeat consumption by updating CANopen object 1016 (Consumer heartbeat time). More...
 
void ConfigHeartbeat (const ::std::chrono::milliseconds &ms)
 Configures heartbeat consumption by updating CANopen object 1016 (Consumer heartbeat time). More...
 
bool Boot ()
 Requests the NMT 'boot slave' process for the remote node. More...
 
bool IsReady () const
 Returns true if the remote node is ready (i.e., the NMT boot slave process has successfully completed and no subsequent boot-up event has been received) and false if not. More...
 
void Error ()
 Indicates the occurrence of an error event on the remote node and triggers the error handling process. More...
 
template<class F >
void SubmitWait (const time_point &t, F &&f)
 Submits a wait operation. More...
 
template<class F >
void SubmitWait (const duration &d, F &&f)
 Submits a wait operation. More...
 
SdoFuture< void > AsyncWait (const time_point &t)
 Submits an asynchronous wait operation and creates a future which becomes ready once the wait operation completes (or is canceled). More...
 
SdoFuture< void > AsyncWait (const duration &d)
 Submits an asynchronous wait operation and creates a future which becomes ready once the wait operation completes (or is canceled). More...
 
template<class T , class F >
void SubmitRead (uint16_t idx, uint8_t subidx, F &&con)
 Equivalent to SubmitRead(uint16_t idx, uint8_t subidx, F&& con, const ::std::chrono::milliseconds& timeout), except that it uses the SDO timeout given by lely::canopen::BasicMaster::GetTimeout().
 
template<class T , class F >
void SubmitRead (uint16_t idx, uint8_t subidx, F &&con, ::std::error_code &ec)
 Equivalent to SubmitRead(uint16_t idx, uint8_t subidx, F&& con, const ::std::chrono::milliseconds& timeout, ::std::error_code& ec), except that it uses the SDO timeout given by lely::canopen::BasicMaster::GetTimeout().
 
template<class T , class F >
void SubmitRead (uint16_t idx, uint8_t subidx, F &&con, const ::std::chrono::milliseconds &timeout)
 Equivalent to SubmitRead(uint16_t idx, uint8_t subidx, F&& con, const ::std::chrono::milliseconds& timeout, ::std::error_code& ec), except that it throws lely::canopen::SdoError on error.
 
template<class T , class F >
void SubmitRead (uint16_t idx, uint8_t subidx, F &&con, const ::std::chrono::milliseconds &timeout, ::std::error_code &ec)
 Queues an asynchronous read (SDO upload) operation. More...
 
template<class T , class F >
void SubmitWrite (uint16_t idx, uint8_t subidx, T &&value, F &&con)
 Equivalent to SubmitWrite(uint16_t idx, uint8_t subidx, T&& value, F&& con, const ::std::chrono::milliseconds& timeout), except that it uses the SDO timeout given by lely::canopen::BasicMaster::GetTimeout().
 
template<class T , class F >
void SubmitWrite (uint16_t idx, uint8_t subidx, T &&value, F &&con, ::std::error_code &ec)
 Equivalent to SubmitWrite(uint16_t idx, uint8_t subidx, T&& value, F&& con, const ::std::chrono::milliseconds& timeout, ::std::error_code& ec), except that it uses the SDO timeout given by lely::canopen::BasicMaster::GetTimeout().
 
template<class T , class F >
void SubmitWrite (uint16_t idx, uint8_t subidx, T &&value, F &&con, const ::std::chrono::milliseconds &timeout)
 Equivalent to SubmitWrite(uint16_t idx, uint8_t subidx, T&& value, F&& con, const ::std::chrono::milliseconds& timeout, ::std::error_code& ec), except that it throws lely::canopen::SdoError on error.
 
template<class T , class F >
void SubmitWrite (uint16_t idx, uint8_t subidx, T &&value, F &&con, const ::std::chrono::milliseconds &timeout, ::std::error_code &ec)
 Queues an asynchronous write (SDO download) operation. More...
 
template<class T >
SdoFuture< T > AsyncRead (uint16_t idx, uint8_t subidx)
 Equivalent to AsyncRead(uint16_t idx, uint8_t subidx, const ::std::chrono::milliseconds& timeout), except that it uses the SDO timeout given by lely::canopen::BasicMaster::GetTimeout().
 
template<class T >
SdoFuture< T > AsyncRead (uint16_t idx, uint8_t subidx, const ::std::chrono::milliseconds &timeout)
 Queues an asynchronous read (SDO upload) operation and creates a future which becomes ready once the request completes (or is canceled). More...
 
template<class T >
SdoFuture< void > AsyncWrite (uint16_t idx, uint8_t subidx, T &&value)
 Equivalent to AsyncWrite(uint16_t idx, uint8_t subidx, T&& value, const ::std::chrono::milliseconds& timeout), except that it uses the SDO timeout given by lely::canopen::BasicMaster::GetTimeout().
 
template<class T >
SdoFuture< void > AsyncWrite (uint16_t idx, uint8_t subidx, T &&value, const ::std::chrono::milliseconds &timeout)
 Queues an asynchronous write (SDO download) operation and creates a future which becomes ready once the request completes (or is canceled). More...
 
void Insert (LogicalDriverBase &driver)
 Registers a logical device driver for the remote node. More...
 
void Erase (LogicalDriverBase &driver)
 Unregisters a logical device driver for the remote node. More...
 
template<class F , class... Args>
void Post (F &&f, Args &&... args)
 Schedules the specified Callable object for execution by the executor for this driver. More...
 

Additional Inherited Members

- Data Fields inherited from lely::canopen::BasicDriver
BasicMastermaster
 A reference to the master with which this driver is registered.
 
class BasicMaster::RpdoMapped rpdo_mapped
 An accessor providing read-only access to RPDO-mapped objects in the remote object dictionary. More...
 
class BasicMaster::TpdoMapped tpdo_mapped
 A mutator providing read/write access to TPDO-mapped objects in the remote object dictionary. More...
 
TpdoEventMutextpdo_event_mutex
 
- Protected Member Functions inherited from lely::canopen::BasicDriver
void OnCanState (io::CanState new_state, io::CanState old_state) noexcept override
 The default implementation notifies all registered logical device drivers. More...
 
void OnCanError (io::CanError error) noexcept override
 The default implementation notifies all registered logical device drivers. More...
 
void OnRpdoWrite (uint16_t idx, uint8_t subidx) noexcept override
 The default implementation notifies all registered logical device drivers, unless the object index is part of the standardized profile area of a logical device (6000..9FFF). More...
 
void OnCommand (NmtCommand cs) noexcept override
 The default implementation notifies all registered logical device drivers. More...
 
void OnNodeGuarding (bool occurred) noexcept override
 The default implementation notifies all registered logical device drivers. More...
 
void OnHeartbeat (bool occurred) noexcept override
 The default implementation notifies all registered logical device drivers. More...
 
void OnState (NmtState st) noexcept override
 The default implementation notifies all registered logical device drivers. More...
 
void OnBoot (NmtState st, char es, const ::std::string &what) noexcept override
 The default implementation notifies all registered logical device drivers. More...
 
void OnConfig (::std::function< void(::std::error_code ec)> res) noexcept override
 The default implementation invokes AsyncConfig() to start the configuration process for all registered logical device drivers. More...
 
void OnDeconfig (::std::function< void(::std::error_code ec)> res) noexcept override
 The default implementation invokes AsyncDeconfig() to start the deconfiguration process for all registered logical device drivers. More...
 
void OnSync (uint8_t cnt, const time_point &t) noexcept override
 The default implementation notifies all registered logical device drivers. More...
 
void OnSyncError (uint16_t eec, uint8_t er) noexcept override
 The default implementation notifies all registered logical device drivers. More...
 
void OnTime (const ::std::chrono::system_clock::time_point &abs_time) noexcept override
 The default implementation notifies all registered logical device drivers. More...
 
void OnEmcy (uint16_t eec, uint8_t er, uint8_t msef[5]) noexcept override
 The default implementation notifies all registered logical device drivers. More...
 
SdoFuture< void > AsyncConfig (int num=0)
 Invokes LogicalDriverBase::AsyncConfig() for the specified logical device driver. More...
 
SdoFuture< void > AsyncDeconfig (int num=0)
 Invokes LogicalDriverBase::AsyncDeconfig() for the specified logical device driver. More...
 

Detailed Description

A CANopen driver running its tasks and callbacks in fibers.

The driver MUST be instantiated on the thread on which its task are run.

Definition at line 54 of file fiber_driver.hpp.

Constructor & Destructor Documentation

◆ FiberDriver()

lely::canopen::FiberDriver::FiberDriver ( ev_exec_t exec,
AsyncMaster master,
uint8_t  id 
)
explicit

Creates a new CANopen driver and its associated fiber executor.

Parameters
execthe inner executor used to create the fiber executor. If exec is a null pointer, the CANopen master executor is used.
mastera reference to a CANopen master.
idthe node-ID of the remote node (in the range [1..127]).
Exceptions
std::out_of_rangeif the node-ID is invalid or already registered.

Definition at line 49 of file fiber_driver.cpp.

Member Function Documentation

◆ Defer()

template<class F , class... Args>
void lely::canopen::FiberDriver::Defer ( F &&  f,
Args &&...  args 
)
inline

Schedules the specified Callable object for execution by strand for this driver.

See also
GetStrand().

Definition at line 87 of file fiber_driver.hpp.

◆ Wait() [1/3]

template<class T >
T lely::canopen::FiberDriver::Wait ( SdoFuture< T >  f)
inline

Waits for the specified future to become ready by suspending the calling fiber.

This function MUST only be called from tasks submitted to the executor associated with this driver.

Returns
the value stored in the future on success.
Exceptions
theexception stored in the future on failure.
See also
DriverBase::GetExecutor()

Definition at line 106 of file fiber_driver.hpp.

◆ Wait() [2/3]

template<class T >
typename ::std::enable_if<!::std::is_void<T>::value, T>::type lely::canopen::FiberDriver::Wait ( SdoFuture< T >  f,
::std::error_code &  ec 
)
inline

Waits for the specified future to become ready by suspending the calling fiber.

The error code (0 on success) is stored in ec.

This function MUST only be called from tasks submitted to the executor associated with this driver.

Returns
the value stored in the future on success, or an empty value on error.
See also
DriverBase::GetExecutor()

Definition at line 125 of file fiber_driver.hpp.

◆ Wait() [3/3]

void lely::canopen::FiberDriver::Wait ( SdoFuture< void >  f,
::std::error_code &  ec 
)

Waits for the specified future to become ready by suspending the calling fiber.

The error code (0 on success) is stored in ec.

This function MUST only be called from tasks submitted to the executor associated with this driver.

See also
DriverBase::GetExecutor()

Definition at line 55 of file fiber_driver.cpp.

◆ USleep() [1/2]

void lely::canopen::FiberDriver::USleep ( uint_least64_t  usec)

Suspends the calling fiber for usec microseconds.

This function is equivalent to Wait(AsyncWait(::std::chrono::microseconds(usec))).

Definition at line 67 of file fiber_driver.cpp.

◆ USleep() [2/2]

void lely::canopen::FiberDriver::USleep ( uint_least64_t  usec,
::std::error_code &  ec 
)

Suspends the calling fiber for usec microseconds.

This function is equivalent to Wait(AsyncWait(::std::chrono::microseconds(usec)), ec).

Definition at line 72 of file fiber_driver.cpp.


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