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

The base class for drivers for remote CANopen nodes. More...

#include <driver.hpp>

Inheritance diagram for lely::canopen::BasicDriver:
Collaboration diagram for lely::canopen::BasicDriver:

Public Member Functions

 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...
 

Data Fields

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

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

The base class for drivers for remote CANopen nodes.

Definition at line 278 of file driver.hpp.

Constructor & Destructor Documentation

◆ BasicDriver()

lely::canopen::BasicDriver::BasicDriver ( ev_exec_t exec,
BasicMaster master,
uint8_t  id 
)
explicit

Creates a new driver for a remote CANopen node and registers it with the master.

Parameters
execthe executor used to execute event handlers for this driver, including SDO confirmation functions. 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 40 of file driver.cpp.

Member Function Documentation

◆ ConfigHeartbeat() [1/2]

void lely::canopen::BasicDriver::ConfigHeartbeat ( const ::std::chrono::milliseconds &  ms,
::std::error_code &  ec 
)
inline

Configures heartbeat consumption by updating CANopen object 1016 (Consumer heartbeat time).

Parameters
msthe heartbeat timeout (in milliseconds).
ecif heartbeat consumption cannot be configured, the SDO abort code is stored in ec.

Definition at line 334 of file driver.hpp.

◆ ConfigHeartbeat() [2/2]

void lely::canopen::BasicDriver::ConfigHeartbeat ( const ::std::chrono::milliseconds &  ms)
inline

Configures heartbeat consumption by updating CANopen object 1016 (Consumer heartbeat time).

Parameters
msthe heartbeat timeout (in milliseconds).
Exceptions
lely::canopen::SdoErrorif heartbeat consumption cannot be configured.

Definition at line 349 of file driver.hpp.

◆ Boot()

bool lely::canopen::BasicDriver::Boot ( )
inline

Requests the NMT 'boot slave' process for the remote node.

OnBoot() is invoked once the boot-up process completes.

See also
BasicMaster::Boot()

Definition at line 360 of file driver.hpp.

◆ IsReady()

bool lely::canopen::BasicDriver::IsReady ( ) const
inline

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.

If this function returns true, the default client-SDO service is available.

See also
BasicMaster::IsReady()

Definition at line 374 of file driver.hpp.

◆ Error()

void lely::canopen::BasicDriver::Error ( )
inline

Indicates the occurrence of an error event on the remote node and triggers the error handling process.

See also
BasicMaster::Error()

Definition at line 385 of file driver.hpp.

◆ SubmitWait() [1/2]

template<class F >
void lely::canopen::BasicDriver::SubmitWait ( const time_point &  t,
F &&  f 
)
inline

Submits a wait operation.

The completion task is submitted for execution once the specified absolute timeout expires.

Parameters
tthe absolute expiration time of the wait operation.
fthe function to be called on completion of the wait operation.

Definition at line 398 of file driver.hpp.

◆ SubmitWait() [2/2]

template<class F >
void lely::canopen::BasicDriver::SubmitWait ( const duration &  d,
F &&  f 
)
inline

Submits a wait operation.

The completion task is submitted for execution once the specified relative timeout expires.

Parameters
dthe relative expiration time of the wait operation.
fthe function to be called on completion of the wait operation.

Definition at line 411 of file driver.hpp.

◆ AsyncWait() [1/2]

SdoFuture<void> lely::canopen::BasicDriver::AsyncWait ( const time_point &  t)
inline

Submits an asynchronous wait operation and creates a future which becomes ready once the wait operation completes (or is canceled).

Parameters
tthe absolute expiration time of the wait operation.
Returns
a future which holds an exception pointer on error.

Definition at line 424 of file driver.hpp.

◆ AsyncWait() [2/2]

SdoFuture<void> lely::canopen::BasicDriver::AsyncWait ( const duration &  d)
inline

Submits an asynchronous wait operation and creates a future which becomes ready once the wait operation completes (or is canceled).

Parameters
dthe relative expiration time of the wait operation.
Returns
a future which holds an exception pointer on error.

Definition at line 437 of file driver.hpp.

◆ SubmitRead()

template<class T , class F >
void lely::canopen::BasicDriver::SubmitRead ( uint16_t  idx,
uint8_t  subidx,
F &&  con,
const ::std::chrono::milliseconds &  timeout,
::std::error_code &  ec 
)
inline

Queues an asynchronous read (SDO upload) operation.

This function reads the value of a sub-object in a remote object dictionary.

Parameters
idxthe object index.
subidxthe object sub-index.
conthe confirmation function to be called on completion of the SDO request.
timeoutthe SDO timeout. If, after the request is initiated, the timeout expires before receiving a response from the server, the client aborts the transfer with abort code SdoErrc::TIMEOUT.
ecthe error code (0 on success). ec == SdoErrc::NO_SDO if no client-SDO is available.

Definition at line 497 of file driver.hpp.

◆ SubmitWrite()

template<class T , class F >
void lely::canopen::BasicDriver::SubmitWrite ( uint16_t  idx,
uint8_t  subidx,
T &&  value,
F &&  con,
const ::std::chrono::milliseconds &  timeout,
::std::error_code &  ec 
)
inline

Queues an asynchronous write (SDO download) operation.

This function writes a value to a sub-object in a remote object dictionary.

Parameters
idxthe object index.
subidxthe object sub-index.
valuethe value to be written.
conthe confirmation function to be called on completion of the SDO request.
timeoutthe SDO timeout. If, after the request is initiated, the timeout expires before receiving a response from the server, the client aborts the transfer with abort code SdoErrc::TIMEOUT.
ecthe error code (0 on success). ec == SdoErrc::NO_SDO if no client-SDO is available.

Definition at line 563 of file driver.hpp.

◆ AsyncRead()

template<class T >
SdoFuture<T> lely::canopen::BasicDriver::AsyncRead ( uint16_t  idx,
uint8_t  subidx,
const ::std::chrono::milliseconds &  timeout 
)
inline

Queues an asynchronous read (SDO upload) operation and creates a future which becomes ready once the request completes (or is canceled).

Parameters
idxthe object index.
subidxthe object sub-index.
timeoutthe SDO timeout. If, after the request is initiated, the timeout expires before receiving a response from the server, the client aborts the transfer with abort code SdoErrc::TIMEOUT.
Returns
a future which holds the received value on success and the SDO error on failure.

Definition at line 599 of file driver.hpp.

◆ AsyncWrite()

template<class T >
SdoFuture<void> lely::canopen::BasicDriver::AsyncWrite ( uint16_t  idx,
uint8_t  subidx,
T &&  value,
const ::std::chrono::milliseconds &  timeout 
)
inline

Queues an asynchronous write (SDO download) operation and creates a future which becomes ready once the request completes (or is canceled).

Parameters
idxthe object index.
subidxthe object sub-index.
valuethe value to be written.
timeoutthe SDO timeout. If, after the request is initiated, the timeout expires before receiving a response from the server, the client aborts the transfer with abort code SdoErrc::TIMEOUT.
Returns
a future which holds the SDO error on failure.

Definition at line 633 of file driver.hpp.

◆ Insert()

void lely::canopen::BasicDriver::Insert ( LogicalDriverBase driver)

Registers a logical device driver for the remote node.

If an event occurs for the node, or for the entire CANopen network, the corresponding method of the logical driver will be invoked.

Exceptions
std::out_of_rangeif the logical device number is invalid or already registered.
See also
Erase()

Definition at line 53 of file driver.cpp.

◆ Erase()

void lely::canopen::BasicDriver::Erase ( LogicalDriverBase driver)

Unregisters a logical device driver for the remote node.

See also
Insert()

Definition at line 66 of file driver.cpp.

◆ Post()

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

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

See also
GetExecutor()

Definition at line 666 of file driver.hpp.

◆ OnCanState()

void lely::canopen::BasicDriver::OnCanState ( io::CanState  new_state,
io::CanState  old_state 
)
overrideprotectedvirtualnoexcept

The default implementation notifies all registered logical device drivers.

See also
Node::OnCanState(), DriverBase::OnCanState()

Implements lely::canopen::DriverBase.

Definition at line 135 of file driver.cpp.

◆ OnCanError()

void lely::canopen::BasicDriver::OnCanError ( io::CanError  error)
overrideprotectedvirtualnoexcept

The default implementation notifies all registered logical device drivers.

See also
Node::OnCanError(), DriverBase::OnCanError()

Implements lely::canopen::DriverBase.

Definition at line 141 of file driver.cpp.

◆ OnRpdoWrite()

void lely::canopen::BasicDriver::OnRpdoWrite ( uint16_t  idx,
uint8_t  subidx 
)
overrideprotectedvirtualnoexcept

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).

In that case, the driver registered for the corresponding logical device is notified and the object index is adjusted to the standardized profile area of the first logical device (6000..67FF).

See also
DriverBase::OnRpdoWrite()

Implements lely::canopen::DriverBase.

Definition at line 146 of file driver.cpp.

◆ OnCommand()

void lely::canopen::BasicDriver::OnCommand ( NmtCommand  cs)
overrideprotectedvirtualnoexcept

The default implementation notifies all registered logical device drivers.

See also
Node::OnCommand(), DriverBase::OnCommand()

Implements lely::canopen::DriverBase.

Definition at line 157 of file driver.cpp.

◆ OnNodeGuarding()

void lely::canopen::BasicDriver::OnNodeGuarding ( bool  occurred)
overrideprotectedvirtualnoexcept

The default implementation notifies all registered logical device drivers.

See also
DriverBase::OnNodeGuarding()

Implements lely::canopen::DriverBase.

Definition at line 162 of file driver.cpp.

◆ OnHeartbeat()

void lely::canopen::BasicDriver::OnHeartbeat ( bool  occurred)
overrideprotectedvirtualnoexcept

The default implementation notifies all registered logical device drivers.

See also
DriverBase::OnHeartbeat()

Implements lely::canopen::DriverBase.

Definition at line 167 of file driver.cpp.

◆ OnState()

void lely::canopen::BasicDriver::OnState ( NmtState  st)
overrideprotectedvirtualnoexcept

The default implementation notifies all registered logical device drivers.

See also
DriverBase::OnState()

Implements lely::canopen::DriverBase.

Definition at line 172 of file driver.cpp.

◆ OnBoot()

void lely::canopen::BasicDriver::OnBoot ( NmtState  st,
char  es,
const ::std::string &  what 
)
overrideprotectedvirtualnoexcept

The default implementation notifies all registered logical device drivers.

See also
DriverBase::OnBoot()

Implements lely::canopen::DriverBase.

Definition at line 177 of file driver.cpp.

◆ OnConfig()

void lely::canopen::BasicDriver::OnConfig ( ::std::function< void(::std::error_code ec)>  res)
overrideprotectedvirtualnoexcept

The default implementation invokes AsyncConfig() to start the configuration process for all registered logical device drivers.

See also
DriverBase::OnConfig()

Implements lely::canopen::DriverBase.

Definition at line 182 of file driver.cpp.

◆ OnDeconfig()

void lely::canopen::BasicDriver::OnDeconfig ( ::std::function< void(::std::error_code ec)>  res)
overrideprotectedvirtualnoexcept

The default implementation invokes AsyncDeconfig() to start the deconfiguration process for all registered logical device drivers.

See also
DriverBase::OnDeconfig()

Implements lely::canopen::DriverBase.

Definition at line 213 of file driver.cpp.

◆ OnSync()

void lely::canopen::BasicDriver::OnSync ( uint8_t  cnt,
const time_point &  t 
)
overrideprotectedvirtualnoexcept

The default implementation notifies all registered logical device drivers.

See also
Node::OnSync(), DriverBase::OnSync()

Implements lely::canopen::DriverBase.

Definition at line 244 of file driver.cpp.

◆ OnSyncError()

void lely::canopen::BasicDriver::OnSyncError ( uint16_t  eec,
uint8_t  er 
)
overrideprotectedvirtualnoexcept

The default implementation notifies all registered logical device drivers.

See also
Node::OnSyncError(), DriverBase::OnSyncError()

Implements lely::canopen::DriverBase.

Definition at line 249 of file driver.cpp.

◆ OnTime()

void lely::canopen::BasicDriver::OnTime ( const ::std::chrono::system_clock::time_point &  abs_time)
overrideprotectedvirtualnoexcept

The default implementation notifies all registered logical device drivers.

See also
Node::OnTime(), DriverBase::OnTime()

Implements lely::canopen::DriverBase.

Definition at line 254 of file driver.cpp.

◆ OnEmcy()

void lely::canopen::BasicDriver::OnEmcy ( uint16_t  eec,
uint8_t  er,
uint8_t  msef[5] 
)
overrideprotectedvirtualnoexcept

The default implementation notifies all registered logical device drivers.

See also
DriverBase::OnEmcy()

Implements lely::canopen::DriverBase.

Definition at line 260 of file driver.cpp.

◆ AsyncConfig()

SdoFuture< void > lely::canopen::BasicDriver::AsyncConfig ( int  num = 0)
protected

Invokes LogicalDriverBase::AsyncConfig() for the specified logical device driver.

If num is 0, invokes LogicalDriverBase::AsyncConfig() for all registered logical device drivers and returns a future which becomes ready once all configuration processes complete.

Definition at line 72 of file driver.cpp.

◆ AsyncDeconfig()

SdoFuture< void > lely::canopen::BasicDriver::AsyncDeconfig ( int  num = 0)
protected

Invokes LogicalDriverBase::AsyncDeconfig() for the specified logical device driver.

If num is 0, invokes LogicalDriverBase::AsyncDeconfig() for all registered logical device drivers and returns a future which becomes ready once all deconfiguration processes complete.

Definition at line 103 of file driver.cpp.

Field Documentation

◆ rpdo_mapped

class BasicMaster::RpdoMapped lely::canopen::BasicDriver::rpdo_mapped

An accessor providing read-only access to RPDO-mapped objects in the remote object dictionary.

See also
BasicMaster::RpdoMapped()

Definition at line 679 of file driver.hpp.

◆ tpdo_mapped

class BasicMaster::TpdoMapped lely::canopen::BasicDriver::tpdo_mapped

A mutator providing read/write access to TPDO-mapped objects in the remote object dictionary.

See also
BasicMaster::TpdoMapped()

Definition at line 687 of file driver.hpp.

◆ tpdo_event_mutex

TpdoEventMutex& lely::canopen::BasicDriver::tpdo_event_mutex
See also
BasicMaster::tpdo_event_mutex

Definition at line 690 of file driver.hpp.


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