Lely core libraries  2.2.5
lely::canopen::BasicLogicalDriver< BasicDriver > Class Reference

The base class for drivers for logical devices on remote CANopen nodes. More...

#include <logical_driver.hpp>

Inheritance diagram for lely::canopen::BasicLogicalDriver< BasicDriver >:
Collaboration diagram for lely::canopen::BasicLogicalDriver< BasicDriver >:

Data Structures

class  RpdoMapped
 
class  TpdoMapped
 

Public Member Functions

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.
 
int Number () const noexcept final
 Returns the number of the logical device on the remote node.
 
uint32_t DeviceType () const noexcept
 Returns the device type of the logical device on the remote node.
 
int Profile () const noexcept
 Returns the device profile number of the logical device on the remote node, or 0 if the device does not follow a standardized profile.
 
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...
 
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 driver is registered.
 
BasicDriverdriver
 A reference to the driver with which this logical device driver is registered.
 
TpdoEventMutextpdo_event_mutex
 

Protected Member Functions

void OnCanState (io::CanState, io::CanState) noexcept override
 The function invoked when a CAN bus state change is detected. More...
 
void OnCanError (io::CanError) noexcept override
 The function invoked when an error is detected on the CAN bus. More...
 
void OnCommand (NmtCommand) noexcept override
 The function invoked when an NMT state change occurs on the master. More...
 
void OnNodeGuarding (bool) noexcept override
 The function invoked when a node guarding timeout event occurs or is resolved for the remote node. More...
 
void OnHeartbeat (bool) noexcept override
 The function invoked when a heartbeat timeout event occurs or is resolved for the remote node. More...
 
void OnState (NmtState) noexcept override
 The function invoked when an NMT state change or boot-up event is detected for the remote node by the heartbeat protocol. More...
 
void OnBoot (NmtState, char, const ::std::string &) noexcept override
 The function invoked when the NMT 'boot slave' process completes for the remote node. More...
 
void OnConfig (::std::function< void(::std::error_code ec)> res) noexcept override
 The function invoked when the 'update configuration' step is reached during the NMT 'boot slave' process of the remote node. More...
 
void OnDeconfig (::std::function< void(::std::error_code ec)> res) noexcept override
 The function invoked by BasicMaster::AsyncDeconfig() to start the deconfiguration process. More...
 
void OnSync (uint8_t, const time_point &) noexcept override
 The function invoked when a SYNC message is sent/received by the master. More...
 
void OnSyncError (uint16_t, uint8_t) noexcept override
 The function invoked when the data length of a received SYNC message does not match. More...
 
void OnTime (const ::std::chrono::system_clock::time_point &) noexcept override
 The function invoked when a TIME message is received by the master. More...
 
void OnEmcy (uint16_t, uint8_t, uint8_t[5]) noexcept override
 The function invoked when an EMCY message is received from the remote node. More...
 
uint16_t ObjectIndex (uint16_t idx) const noexcept
 Converts an object index, if it is part of the standardized profile area, from the first logical device to the actual logical device. More...
 

Detailed Description

The base class for drivers for logical devices on remote CANopen nodes.

Definition at line 39 of file logical_driver.hpp.

Member Function Documentation

◆ IsReady()

bool lely::canopen::BasicLogicalDriver< 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.

See also
BasicDriver::IsReady()

Definition at line 92 of file logical_driver.hpp.

◆ Error()

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

See also
BasicDriver::Error()

Definition at line 103 of file logical_driver.hpp.

◆ SubmitWait() [1/2]

template<class F >
void lely::canopen::BasicLogicalDriver< 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 116 of file logical_driver.hpp.

◆ SubmitWait() [2/2]

template<class F >
void lely::canopen::BasicLogicalDriver< 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 129 of file logical_driver.hpp.

◆ AsyncWait() [1/2]

SdoFuture<void> lely::canopen::BasicLogicalDriver< 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 142 of file logical_driver.hpp.

◆ AsyncWait() [2/2]

SdoFuture<void> lely::canopen::BasicLogicalDriver< 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 155 of file logical_driver.hpp.

◆ SubmitRead()

template<class T , class F >
void lely::canopen::BasicLogicalDriver< 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 213 of file logical_driver.hpp.

◆ SubmitWrite()

template<class T , class F >
void lely::canopen::BasicLogicalDriver< 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 278 of file logical_driver.hpp.

◆ AsyncRead()

template<class T >
SdoFuture<T> lely::canopen::BasicLogicalDriver< 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 313 of file logical_driver.hpp.

◆ AsyncWrite()

template<class T >
SdoFuture<void> lely::canopen::BasicLogicalDriver< 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 347 of file logical_driver.hpp.

◆ Post()

template<class F , class... Args>
void lely::canopen::BasicLogicalDriver< 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 361 of file logical_driver.hpp.

◆ OnCanState()

void lely::canopen::BasicLogicalDriver< BasicDriver >::OnCanState ( io::CanState  new_state,
io::CanState  old_state 
)
inlineoverrideprotectedvirtualnoexcept

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

See also
BasicMaster::OnCanState()

Implements lely::canopen::DriverBase.

Definition at line 413 of file logical_driver.hpp.

◆ OnCanError()

void lely::canopen::BasicLogicalDriver< BasicDriver >::OnCanError ( io::CanError  error)
inlineoverrideprotectedvirtualnoexcept

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

See also
BasicMaster::OnCanError()

Implements lely::canopen::DriverBase.

Definition at line 417 of file logical_driver.hpp.

◆ OnCommand()

void lely::canopen::BasicLogicalDriver< BasicDriver >::OnCommand ( NmtCommand  cs)
inlineoverrideprotectedvirtualnoexcept

The function invoked when an NMT state change occurs on the master.

Parameters
csthe NMT command specifier.
See also
BasicMaster::OnCommand()

Implements lely::canopen::DriverBase.

Definition at line 423 of file logical_driver.hpp.

◆ OnNodeGuarding()

void lely::canopen::BasicLogicalDriver< BasicDriver >::OnNodeGuarding ( bool  occurred)
inlineoverrideprotectedvirtualnoexcept

The function invoked when a node guarding timeout event occurs or is resolved for the remote node.

Note that depending on the value of object 1029:01 (Error behavior object) in the object dictionary of the master, the occurrence of a node guarding event MAY trigger an NMT state transition on the master. If so, this function is called after the state change completes.

Parameters
occurredtrue if the node guarding event occurred, false if it was resolved.
See also
BasicMaster::OnNodeGuarding()

Implements lely::canopen::DriverBase.

Definition at line 427 of file logical_driver.hpp.

◆ OnHeartbeat()

void lely::canopen::BasicLogicalDriver< BasicDriver >::OnHeartbeat ( bool  occurred)
inlineoverrideprotectedvirtualnoexcept

The function invoked when a heartbeat timeout event occurs or is resolved for the remote node.

Note that depending on the value of object 1029:01 (Error behavior object) in the object dictionary of the master, the occurrence of a heartbeat timeout event MAY trigger an NMT state transition on the master. If so, this function is called after the state change completes.

Parameters
occurredtrue if the heartbeat timeout event occurred, false if it was resolved.
See also
BasicMaster::OnHeartbeat()

Implements lely::canopen::DriverBase.

Definition at line 431 of file logical_driver.hpp.

◆ OnState()

void lely::canopen::BasicLogicalDriver< BasicDriver >::OnState ( NmtState  st)
inlineoverrideprotectedvirtualnoexcept

The function invoked when an NMT state change or boot-up event is detected for the remote node by the heartbeat protocol.

Parameters
stthe state of the remote node. Note that the NMT sub-states NmtState::RESET_NODE and NmtState::RESET_COMM are never reported for remote nodes.
See also
BasicMaster::OnState()

Implements lely::canopen::DriverBase.

Definition at line 434 of file logical_driver.hpp.

◆ OnBoot()

void lely::canopen::BasicLogicalDriver< BasicDriver >::OnBoot ( NmtState  st,
char  es,
const ::std::string &  what 
)
inlineoverrideprotectedvirtualnoexcept

The function invoked when the NMT 'boot slave' process completes for the remote node.

Parameters
stthe state of the remote node (including the toggle bit (NmtState::TOGGLE) if node guarding is enabled).
esthe error status (in the range ['A'..'O'], or 0 on success):
  • 'A': The CANopen device is not listed in object 1F81.
  • 'B': No response received for upload request of object 1000.
  • 'C': Value of object 1000 from CANopen device is different to value in object 1F84 (Device type).
  • 'D': Value of object 1018:01 from CANopen device is different to value in object 1F85 (Vendor-ID).
  • 'E': Heartbeat event. No heartbeat message received from CANopen device.
  • 'F': Node guarding event. No confirmation for guarding request received from CANopen device.
  • 'G': Objects for program download are not configured or inconsistent.
  • 'H': Software update is required, but not allowed because of configuration or current status.
  • 'I': Software update is required, but program download failed.
  • 'J': Configuration download failed.
  • 'K': Heartbeat event during start error control service. No heartbeat message received from CANopen device during start error control service.
  • 'L': NMT slave was initially operational. (CANopen manager may resume operation with other CANopen devices)
  • 'M': Value of object 1018:02 from CANopen device is different to value in object 1F86 (Product code).
  • 'N': Value of object 1018:03 from CANopen device is different to value in object 1F87 (Revision number).
  • 'O': Value of object 1018:04 from CANopen device is different to value in object 1F88 (Serial number).
whatif es is non-zero, contains a string explaining the error.
See also
BasicMaster::OnBoot()

Implements lely::canopen::DriverBase.

Definition at line 437 of file logical_driver.hpp.

◆ OnConfig()

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

The function invoked when the 'update configuration' step is reached during the NMT 'boot slave' process of the remote node.

The 'boot slave' process is halted until the result of the 'update configuration' step is communicated to the master.

Note that OnConfig() MUST be a non-blocking function; the configuration update MUST be executed asynchronously or run in a different thread.

Parameters
resthe function to invoke on completion of the 'update configuration' step. The argument to res is the result: 0 on success, or an SDO abort code on error.
See also
BasicMaster::OnConfig()

Implements lely::canopen::DriverBase.

Definition at line 441 of file logical_driver.hpp.

◆ OnDeconfig()

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

The function invoked by BasicMaster::AsyncDeconfig() to start the deconfiguration process.

The process does not complete until the result is communicated to the master.

Note that OnDeconfig() MUST be a non-blocking function; the deconfiguration process MUST be executed asynchronously or run in a different thread.

Parameters
resthe function to invoke when the deconfiguration process completes. The argument to res is the result: 0 on success, or an error code on failure.

Implements lely::canopen::DriverBase.

Definition at line 446 of file logical_driver.hpp.

◆ OnSync()

void lely::canopen::BasicLogicalDriver< BasicDriver >::OnSync ( uint8_t  cnt,
const time_point &  t 
)
inlineoverrideprotectedvirtualnoexcept

The function invoked when a SYNC message is sent/received by the master.

Note that this function is called after all PDOs are processed/sent.

Parameters
cntthe counter (in the range [1..240]), or 0 if the SYNC message is empty.
tthe time at which the SYNC message was sent/received.
See also
BasicMaster::OnSync()

Implements lely::canopen::DriverBase.

Definition at line 452 of file logical_driver.hpp.

◆ OnSyncError()

void lely::canopen::BasicLogicalDriver< BasicDriver >::OnSyncError ( uint16_t  eec,
uint8_t  er 
)
inlineoverrideprotectedvirtualnoexcept

The function invoked when the data length of a received SYNC message does not match.

Parameters
eecthe emergency error code (0x8240).
erthe error register (0x10).
See also
BasicMaster::OnSyncError()

Implements lely::canopen::DriverBase.

Definition at line 455 of file logical_driver.hpp.

◆ OnTime()

void lely::canopen::BasicLogicalDriver< BasicDriver >::OnTime ( const ::std::chrono::system_clock::time_point &  abs_time)
inlineoverrideprotectedvirtualnoexcept

The function invoked when a TIME message is received by the master.

Parameters
abs_timea time point representing the received time stamp.
See also
BasicMaster::OnTime()

Implements lely::canopen::DriverBase.

Definition at line 458 of file logical_driver.hpp.

◆ OnEmcy()

void lely::canopen::BasicLogicalDriver< BasicDriver >::OnEmcy ( uint16_t  eec,
uint8_t  er,
uint8_t  msef[5] 
)
inlineoverrideprotectedvirtualnoexcept

The function invoked when an EMCY message is received from the remote node.

Parameters
eecthe emergency error code.
erthe error register.
msefthe manufacturer-specific error code.
See also
BasicMaster::OnEmcy()

Implements lely::canopen::DriverBase.

Definition at line 462 of file logical_driver.hpp.

◆ ObjectIndex()

uint16_t lely::canopen::BasicLogicalDriver< BasicDriver >::ObjectIndex ( uint16_t  idx) const
inlineprotectednoexcept

Converts an object index, if it is part of the standardized profile area, from the first logical device to the actual logical device.

This allows the driver to treat index 6000..67FF as the profile area, even if Number() != 1.

Definition at line 472 of file logical_driver.hpp.

Field Documentation

◆ tpdo_event_mutex


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