Lely core libraries 2.3.4
lely::canopen::Node Class Reference

The base class for CANopen nodes. More...

#include <node.hpp>

Inheritance diagram for lely::canopen::Node:
Collaboration diagram for lely::canopen::Node:

Data Structures

struct  Impl_
 The internal implementation of the CANopen node. More...
 
class  TpdoEventMutex
 A recursive mutex-like object that can be used to postpone the transmission of acyclic and event-driven Transmit-PDOs while the lock is held. More...
 

Public Member Functions

 Node (ev_exec_t *exec, io::TimerBase &timer, io::CanChannelBase &chan, const ::std::string &dcf_txt, const ::std::string &dcf_bin="", uint8_t id=0xff)
 Creates a new CANopen node.
 
 Node (io::TimerBase &timer, io::CanChannelBase &chan, const ::std::string &dcf_txt, const ::std::string &dcf_bin="", uint8_t id=0xff)
 Creates a new CANopen node.
 
ev::Executor GetExecutor () const noexcept
 Returns the executor used to process I/O and CANopen events.
 
io::ContextBase GetContext () const noexcept
 Returns the underlying I/O context with which this context is registered.
 
io::Clock GetClock () const noexcept
 Returns the clock used by the timer.
 
void SubmitWait (const time_point &t, io_tqueue_wait &wait)
 Submits a wait operation.
 
void SubmitWait (const duration &d, io_tqueue_wait &wait)
 Submits a wait operation.
 
template<class F >
void SubmitWait (const time_point &t, ev_exec_t *exec, F &&f)
 Submits a wait operation.
 
template<class F >
void SubmitWait (const duration &d, ev_exec_t *exec, F &&f)
 Submits a wait operation.
 
template<class F >
typename::std::enable_if<!::std::is_base_of< io_tqueue_wait, typename::std::decay< F >::type >::value >::type SubmitWait (const time_point &t, F &&f)
 Equivalent to SubmitWait(t, nullptr, f).
 
template<class F >
typename::std::enable_if<!::std::is_base_of< io_tqueue_wait, typename::std::decay< F >::type >::value >::type SubmitWait (const duration &d, F &&f)
 Equivalent to SubmitWait(d, nullptr, f).
 
ev::Future< void, ::std::exception_ptr > AsyncWait (ev_exec_t *exec, const time_point &t, io_tqueue_wait **pwait=nullptr)
 Submits an asynchronous wait operation and creates a future which becomes ready once the wait operation completes (or is canceled).
 
ev::Future< void, ::std::exception_ptr > AsyncWait (ev_exec_t *exec, const duration &d, io_tqueue_wait **pwait=nullptr)
 Submits an asynchronous wait operation and creates a future which becomes ready once the wait operation completes (or is canceled).
 
ev::Future< void, ::std::exception_ptr > AsyncWait (const time_point &t, io_tqueue_wait **pwait=nullptr)
 Equivalent to AsyncWait(nullptr, t, pwait).
 
ev::Future< void, ::std::exception_ptr > AsyncWait (const duration &d, io_tqueue_wait **pwait=nullptr)
 Equivalent to AsyncWait(nullptr, d, pwait).
 
bool CancelWait (io_tqueue_wait &wait) noexcept
 Cancels the specified wait operation if it is pending.
 
bool AbortWait (io_tqueue_wait &wait) noexcept
 Aborts the specified wait operation if it is pending.
 
ev::Future< void, ::std::exception_ptr > AsyncSwitchBitrate (io::CanControllerBase &ctrl, int bitrate, ::std::chrono::milliseconds delay)
 Stops the specified CAN controller and submits asynchronous operations to wait for the delay period, set the new bit rate, wait for the delay period again, and restart the CAN controller.
 
void OnCanState (::std::function< void(io::CanState, io::CanState)> on_can_state)
 Registers the function to be invoked when a CAN bus state change is detected.
 
void OnCanError (::std::function< void(io::CanError)> on_can_error)
 Registers the function to be invoked when an error is detected on the CAN bus.
 
void Reset ()
 (Re)starts the node.
 
void ConfigHeartbeat (uint8_t id, const ::std::chrono::milliseconds &ms, ::std::error_code &ec)
 Configures heartbeat consumption for the specified node by updating CANopen object 1016 (Consumer heartbeat time).
 
void ConfigHeartbeat (uint8_t id, const ::std::chrono::milliseconds &ms)
 Configures heartbeat consumption for the specified node by updating CANopen object 1016 (Consumer heartbeat time).
 
void OnCommand (::std::function< void(NmtCommand)> on_command)
 Registers the function to be invoked when an NMT command is received from the master.
 
void OnHeartbeat (::std::function< void(uint8_t, bool)> on_heartbeat)
 Registers the function to be invoked when a heartbeat timeout event occurs or is resolved.
 
void OnState (::std::function< void(uint8_t, NmtState)> on_state)
 Registers the function to be invoked when an NMT state change or boot-up event is detected for a remote node by the heartbeat protocol.
 
void OnRpdo (::std::function< void(int, ::std::error_code, const void *, ::std::size_t)> on_rpdo)
 Registers the function to be invoked when a Receive-PDO is processed.
 
void OnRpdoError (::std::function< void(int, uint16_t, uint8_t)> on_rpdo_error)
 Registers the function to be invoked when a Receive-PDO length mismatch or timeout error occurs.
 
void OnTpdo (::std::function< void(int, ::std::error_code, const void *, ::std::size_t)> on_tpdo)
 Registers the function to be invoked after a Transmit-PDO is sent or an error occurs.
 
void OnSync (::std::function< void(uint8_t, const time_point &)> on_sync)
 Registers the function to be invoked when a SYNC message is sent/received.
 
void OnSyncError (::std::function< void(uint16_t, uint8_t)> on_sync_error)
 Registers the function to be invoked when the data length of a received SYNC message does not match.
 
void OnTime (::std::function< void(const ::std::chrono::system_clock::time_point &)> on_time)
 Registers the function to be invoked when a TIME message is received.
 
void OnEmcy (::std::function< void(uint8_t, uint16_t, uint8_t, uint8_t[5])> on_emcy)
 Registers the function to be invoked when an EMCY message is received.
 
void OnSwitchBitrate (::std::function< void(int, ::std::chrono::milliseconds)> on_switch_bitrate)
 Registers the function to be invoked when the LSS master activates the bit rate of all CANopen devices in the network.
 
- Public Member Functions inherited from lely::io::CanNet
 CanNet (ev_exec_t *exec, io_timer_t *timer, io_can_chan_t *chan, ::std::size_t txlen=0, int txtimeo=0)
 
 CanNet (io_timer_t *timer, io_can_chan_t *chan, ::std::size_t txlen=0, int txtimeo=0)
 
virtual ~CanNet ()
 
void start () noexcept
 
ContextBase get_ctx () const noexcept
 
ev::Executor get_executor () const noexcept
 
Clock get_clock () const noexcept
 
- Public Member Functions inherited from lely::canopen::Device
 Device (const ::std::string &dcf_txt, const ::std::string &dcf_bin="", uint8_t id=0xff, util::BasicLockable *mutex=nullptr)
 Creates a new CANopen device description.
 
uint8_t netid () const noexcept
 Returns the network-ID.
 
uint8_t id () const noexcept
 Returns the node-ID.
 
template<class T >
typename::std::enable_if< is_canopen< T >::value, T >::type Read (uint16_t idx, uint8_t subidx) const
 Submits an SDO upload request to the local object dictionary.
 
template<class T >
typename::std::enable_if< is_canopen< T >::value, T >::type Read (uint16_t idx, uint8_t subidx, ::std::error_code &ec) const
 Submits an SDO upload request to the local object dictionary.
 
template<class T >
typename::std::enable_if< is_canopen< T >::value >::type Write (uint16_t idx, uint8_t subidx, const T &value)
 Submits an SDO download request to the local object dictionary.
 
template<class T >
typename::std::enable_if< is_canopen< T >::value >::type Write (uint16_t idx, uint8_t subidx, const T &value, ::std::error_code &ec)
 Submits an SDO download request to the local object dictionary.
 
void Write (uint16_t idx, uint8_t subidx, const char *value)
 Submits an SDO download request to the local object dictionary.
 
void Write (uint16_t idx, uint8_t subidx, const char *value, ::std::error_code &ec)
 Submits an SDO download request to the local object dictionary.
 
void Write (uint16_t idx, uint8_t subidx, const char16_t *value)
 Submits an SDO download request to the local object dictionary.
 
void Write (uint16_t idx, uint8_t subidx, const char16_t *value, ::std::error_code &ec)
 Submits an SDO download request to the local object dictionary.
 
void Write (uint16_t idx, uint8_t subidx, const void *p, ::std::size_t n)
 Submits an SDO download request to the local object dictionary.
 
void Write (uint16_t idx, uint8_t subidx, const void *p, ::std::size_t n, ::std::error_code &ec)
 Submits an SDO download request to the local object dictionary.
 
void WriteDcf (const uint8_t *begin, const uint8_t *end)
 Submits a series of SDO download requests to the local object dictionary.
 
void WriteDcf (const uint8_t *begin, const uint8_t *end, ::std::error_code &ec)
 Submits a series of SDO download requests to the local object dictionary.
 
void WriteDcf (const char *path)
 Submits a series of SDO download requests to the local object dictionary.
 
void WriteDcf (const char *path, ::std::error_code &ec)
 Submits a series of SDO download requests to the local object dictionary.
 
void WriteEvent (uint16_t idx, uint8_t subidx)
 Checks if the specified sub-object in the local object dictionary can be mapped into a PDO and, if so, triggers the transmission of every event-driven, asynchronous Transmit-PDO into which the sub-object is mapped.
 
void WriteEvent (uint16_t idx, uint8_t subidx, ::std::error_code &ec) noexcept
 Checks if the specified sub-object in the local object dictionary can be mapped into a PDO and, if so, triggers the transmission of every event-driven, asynchronous Transmit-PDO into which the sub-object is mapped.
 
template<class T >
typename::std::enable_if< is_canopen_basic< T >::value, T >::type RpdoRead (uint8_t id, uint16_t idx, uint8_t subidx) const
 Reads the value of a sub-object in a remote object dictionary by submitting an SDO upload request to the corresponding PDO-mapped sub-object in the local object dictionary.
 
template<class T >
typename::std::enable_if< is_canopen_basic< T >::value, T >::type RpdoRead (uint8_t id, uint16_t idx, uint8_t subidx, ::std::error_code &ec) const
 Reads the value of a sub-object in a remote object dictionary by submitting an SDO upload request to the corresponding PDO-mapped sub-object in the local object dictionary.
 
template<class T >
typename::std::enable_if< is_canopen_basic< T >::value, T >::type TpdoRead (uint8_t id, uint16_t idx, uint8_t subidx) const
 Submits an SDO upload request to a TPDO-mapped sub-object in the local object dictionary, which reads the value that will be written to an RPDO-mapped sub-object in a remote object dictionary by a Transmit-PDO.
 
template<class T >
typename::std::enable_if< is_canopen_basic< T >::value, T >::type TpdoRead (uint8_t id, uint16_t idx, uint8_t subidx, ::std::error_code &ec) const
 Submits an SDO upload request to a TPDO-mapped sub-object in the local object dictionary, which reads the value that will be written to an RPDO-mapped sub-object in a remote object dictionary by a Transmit-PDO.
 
template<class T >
typename::std::enable_if< is_canopen_basic< T >::value >::type TpdoWrite (uint8_t id, uint16_t idx, uint8_t subidx, T value)
 Writes a value to a sub-object in a remote object dictionary by submitting an SDO download request to the corresponding PDO-mapped sub-object in the local object dictionary.
 
template<class T >
typename::std::enable_if< is_canopen_basic< T >::value >::type TpdoWrite (uint8_t id, uint16_t idx, uint8_t subidx, T value, ::std::error_code &ec)
 Writes a value to a sub-object in a remote object dictionary by submitting an SDO download request to the corresponding PDO-mapped sub-object in the local object dictionary.
 
void TpdoWriteEvent (uint8_t id, uint16_t idx, uint8_t subidx)
 Triggers the transmission of every event-driven, asynchronous Transmit-PDO which is mapped into the specified sub-object in a remote object dictionary.
 
void TpdoWriteEvent (uint8_t id, uint16_t idx, uint8_t subidx, ::std::error_code &ec) noexcept
 Triggers the transmission of every event-driven, asynchronous Transmit-PDO which is mapped into the specified sub-object in a remote object dictionary.
 

Protected Member Functions

__can_netnet () const noexcept
 Returns a pointer to the internal CAN network interface from <lely/can/net.h>.
 
void SetTime ()
 Updates the CAN network time.
 
virtual void OnCanState (io::CanState new_state, io::CanState old_state) noexcept
 The function invoked when a CAN bus state change is detected.
 
virtual void OnCanError (io::CanError error) noexcept
 The function invoked when an error is detected on the CAN bus.
 
__co_nmtnmt () const noexcept
 Returns a pointer to the internal CANopen NMT master/slave service from <lely/co/nmt.hpp>.
 
void RpdoRtr (int num=0) noexcept
 Requests the transmission of a PDO by sending a CAN frame with the RTR (Remote Transmission Request) bit set.
 
void TpdoEvent (int num=0) noexcept
 Triggers the transmission of an acyclic or event-driven PDO.
 
- Protected Member Functions inherited from lely::io::CanNet
void lock () final
 Blocks until a lock can be obtained for the current execution agent (thread, process, task).
 
void unlock () final
 Releases the lock held by the execution agent. Throws no exceptions.
 
void set_time ()
 Updates the CAN network time.
 
virtual void on_read_error (::std::error_code ec, ::std::size_t errcnt) noexcept
 The function invoked when a new CAN frame read error occurs, or when a read operation completes successfully after one or more errors.
 
virtual void on_queue_error (::std::error_code ec, ::std::size_t errcnt) noexcept
 The function invoked when a CAN frame is dropped because the transmit queue is full, or when a frame is successfully queued after one or more errors.
 
virtual void on_write_error (::std::error_code ec, ::std::size_t errcnt) noexcept
 The function invoked when a new CAN frame write error occurs, or when a write operation completes successfully after one or more errors.
 
virtual void on_can_state (CanState new_state, CanState old_state) noexcept
 The function invoked when a CAN bus state change is detected.
 
virtual void on_can_error (CanError error) noexcept
 The function invoked when an error is detected on the CAN bus.
 
- Protected Member Functions inherited from lely::canopen::Device
__co_devdev () const noexcept
 Returns a pointer to the internal CANopen device from <lely/co/dev.hpp>.
 
const ::std::type_info & Type (uint16_t idx, uint8_t subidx) const
 Returns the type of a sub-object.
 
const ::std::type_info & Type (uint16_t idx, uint8_t subidx, ::std::error_code &ec) const noexcept
 Returns the type of a sub-object.
 
template<class T >
typename::std::enable_if< is_canopen< T >::value, T >::type Get (uint16_t idx, uint8_t subidx) const
 Reads the value of a sub-object.
 
template<class T >
typename::std::enable_if< is_canopen< T >::value, T >::type Get (uint16_t idx, uint8_t subidx, ::std::error_code &ec) const noexcept
 Reads the value of a sub-object.
 
template<class T >
typename::std::enable_if< is_canopen< T >::value >::type Set (uint16_t idx, uint8_t subidx, const T &value)
 Writes a CANopen value to a sub-object.
 
template<class T >
typename::std::enable_if< is_canopen< T >::value >::type Set (uint16_t idx, uint8_t subidx, const T &value, ::std::error_code &ec) noexcept
 Writes a CANopen value to a sub-object.
 
void Set (uint16_t idx, uint8_t subidx, const char *value)
 Writes a VISIBLE_STRING to a sub-object.
 
void Set (uint16_t idx, uint8_t subidx, const char *value, ::std::error_code &ec) noexcept
 Writes a VISIBLE_STRING to a sub-object.
 
void Set (uint16_t idx, uint8_t subidx, const char16_t *value)
 Writes a UNICODE_STRING to a sub-object.
 
void Set (uint16_t idx, uint8_t subidx, const char16_t *value, ::std::error_code &ec) noexcept
 Writes a UNICODE_STRING to a sub-object.
 
void Set (uint16_t idx, uint8_t subidx, const void *p, ::std::size_t n)
 Writes an OCTET_STRING or DOMAIN value to a sub-object.
 
void Set (uint16_t idx, uint8_t subidx, const void *p, ::std::size_t n, ::std::error_code &ec) noexcept
 Writes an OCTET_STRING or DOMAIN value to a sub-object.
 
const charGetUploadFile (uint16_t idx, uint8_t subidx) const
 Returns the value of the UploadFile attribute of a sub-object, if present.
 
const charGetUploadFile (uint16_t idx, uint8_t subidx, ::std::error_code &ec) const noexcept
 Returns the value of the UploadFile attribute of a sub-object, if present.
 
void SetUploadFile (uint16_t idx, uint8_t subidx, const char *filename)
 Sets the value of the UploadFile attribute of a sub-object, if present.
 
void SetUploadFile (uint16_t idx, uint8_t subidx, const char *filename, ::std::error_code &ec) noexcept
 Sets the value of the UploadFile attribute of a sub-object, if present.
 
const charGetDownloadFile (uint16_t idx, uint8_t subidx) const
 Returns the value of the DownloadFile attribute of a sub-object, if present.
 
const charGetDownloadFile (uint16_t idx, uint8_t subidx, ::std::error_code &ec) const noexcept
 Returns the value of the DownloadFile attribute of a sub-object, if present.
 
void SetDownloadFile (uint16_t idx, uint8_t subidx, const char *filename)
 Sets the value of the DownloadFile attribute of a sub-object, if present.
 
void SetDownloadFile (uint16_t idx, uint8_t subidx, const char *filename, ::std::error_code &ec) noexcept
 Sets the value of the DownloadFile attribute of a sub-object, if present.
 
void SetEvent (uint16_t idx, uint8_t subidx)
 Checks if the specified sub-object in the local object dictionary can be mapped into a PDO and, if so, triggers the transmission of every event-driven, asynchronous Transmit-PDO into which the sub-object is mapped.
 
void SetEvent (uint16_t idx, uint8_t subidx, ::std::error_code &ec) noexcept
 Checks if the specified sub-object in the local object dictionary can be mapped into a PDO and, if so, triggers the transmission of every event-driven, asynchronous Transmit-PDO into which the sub-object is mapped.
 
template<class T >
typename::std::enable_if< is_canopen_basic< T >::value, T >::type RpdoGet (uint8_t id, uint16_t idx, uint8_t subidx) const
 Reads the value of a sub-object in a remote object dictionary by reading the corresponding PDO-mapped sub-object in the local object dictionary.
 
template<class T >
typename::std::enable_if< is_canopen_basic< T >::value, T >::type RpdoGet (uint8_t id, uint16_t idx, uint8_t subidx, ::std::error_code &ec) const noexcept
 Reads the value of a sub-object in a remote object dictionary by reading the corresponding PDO-mapped sub-object in the local object dictionary.
 
template<class T >
typename::std::enable_if< is_canopen_basic< T >::value, T >::type TpdoGet (uint8_t id, uint16_t idx, uint8_t subidx) const
 Reads the value of a TPDO-mapped sub-object in the local object dictionary that will be written to an RPDO-mapped sub-object in a remote object dictionary by a Transmit-PDO.
 
template<class T >
typename::std::enable_if< is_canopen_basic< T >::value, T >::type TpdoGet (uint8_t id, uint16_t idx, uint8_t subidx, ::std::error_code &ec) const noexcept
 Reads the value of a TPDO-mapped sub-object in the local object dictionary that will be written to an RPDO-mapped sub-object in a remote object dictionary by a Transmit-PDO.
 
template<class T >
typename::std::enable_if< is_canopen_basic< T >::value >::type TpdoSet (uint8_t id, uint16_t idx, uint8_t subidx, T value)
 Writes a value to a sub-object in a remote object dictionary by writing to the corresponding PDO-mapped sub-object in the local object dictionary.
 
template<class T >
typename::std::enable_if< is_canopen_basic< T >::value >::type TpdoSet (uint8_t id, uint16_t idx, uint8_t subidx, T value, ::std::error_code &ec) noexcept
 Writes a value to a sub-object in a remote object dictionary by writing to the corresponding PDO-mapped sub-object in the local object dictionary.
 
void TpdoSetEvent (uint8_t id, uint16_t idx, uint8_t subidx)
 Triggers the transmission of every event-driven, asynchronous Transmit-PDO which is mapped into the specified sub-object in a remote object dictionary.
 
void TpdoSetEvent (uint8_t id, uint16_t idx, uint8_t subidx, ::std::error_code &ec) noexcept
 Triggers the transmission of every event-driven, asynchronous Transmit-PDO which is mapped into the specified sub-object in a remote object dictionary.
 
void UpdateRpdoMapping ()
 Updates the mapping from remote TPDO-mapped sub-objects to local RPDO-mapped sub-objects.
 
void UpdateTpdoMapping ()
 Updates the mapping from remote RPDO-mapped sub-objects to local TPDO-mapped sub-objects.
 
void RpdoWrite (uint8_t id, uint16_t idx, uint8_t subidx)
 Invokes OnRpdoWrite() as if a value was written to an RPDO-mapped object in the local object dictionary.
 

Detailed Description

The base class for CANopen nodes.

This class inherits the lely::util::BasicLockable mutex used by lely::canopen::Device. The mutex MUST be unlocked when any public member function is invoked (Reset()); it will be locked for the duration of any call to a virtual member function.

Definition at line 116 of file node.hpp.

Constructor & Destructor Documentation

◆ Node()

lely::canopen::Node::Node ( ev_exec_t exec,
io::TimerBase timer,
io::CanChannelBase chan,
const ::std::string &  dcf_txt,
const ::std::string &  dcf_bin = "",
uint8_t  id = 0xff 
)
explicit

Creates a new CANopen node.

After creation, the node is in the NMT 'Initialisation' state and does not yet create any services or perform any communication. Call Reset() to start the boot-up process.

Parameters
execthe executor used to process I/O and CANopen events. If exec is a null pointer, the CAN channel executor is used.
timerthe timer used for CANopen events. This timer MUST NOT be used for any other purpose.
chana CAN channel. This channel MUST NOT be used for any other purpose.
dcf_txtthe path of the text EDS or DCF containing the device description.
dcf_binthe path of the (binary) concise DCF containing the values of (some of) the objets in the object dictionary. If dcf_bin is empty, no concise DCF is loaded.
idthe node-ID (in the range [1..127, 255]). If id is 255 (unconfigured), the node-ID is obtained from the DCF.

Definition at line 145 of file node.cpp.

Member Function Documentation

◆ SubmitWait() [1/4]

void lely::canopen::Node::SubmitWait ( const time_point &  t,
io_tqueue_wait wait 
)

Submits a wait operation.

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

Definition at line 174 of file node.cpp.

◆ SubmitWait() [2/4]

void lely::canopen::Node::SubmitWait ( const duration &  d,
io_tqueue_wait wait 
)

Submits a wait operation.

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

Definition at line 180 of file node.cpp.

◆ SubmitWait() [3/4]

template<class F >
void lely::canopen::Node::SubmitWait ( const time_point &  t,
ev_exec_t exec,
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.
execthe executor used to execute the completion task.
fthe function to be called on completion of the wait operation.

Definition at line 189 of file node.hpp.

◆ SubmitWait() [4/4]

template<class F >
void lely::canopen::Node::SubmitWait ( const duration &  d,
ev_exec_t exec,
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.
execthe executor used to execute the completion task.
fthe function to be called on completion of the wait operation.

Definition at line 204 of file node.hpp.

◆ AsyncWait() [1/2]

ev::Future< void,::std::exception_ptr > lely::canopen::Node::AsyncWait ( ev_exec_t exec,
const time_point &  t,
io_tqueue_wait **  pwait = nullptr 
)

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

Parameters
execthe executor used to execute the completion task.
tthe absolute expiration time of the wait operation.
pwaitan optional address at which to store a pointer to the wait operation. This can be used to cancel the wait operation with CancelWait().
Returns
a future which holds an exception pointer on error.

Definition at line 185 of file node.cpp.

◆ AsyncWait() [2/2]

ev::Future< void,::std::exception_ptr > lely::canopen::Node::AsyncWait ( ev_exec_t exec,
const duration &  d,
io_tqueue_wait **  pwait = nullptr 
)

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

Parameters
execthe executor used to execute the completion task.
dthe relative expiration time of the wait operation.
pwaitan optional address at which to store a pointer to the wait operation. This can be used to cancel the wait operation with CancelWait().
Returns
a future which holds an exception pointer on error.

Definition at line 198 of file node.cpp.

◆ CancelWait()

bool lely::canopen::Node::CancelWait ( io_tqueue_wait wait)
noexcept

Cancels the specified wait operation if it is pending.

If canceled, the completion task is submitted for exection with ec = ::std::errc::operation_canceled.

Returns
true if the operation was canceled, and false if it was not pending.

Definition at line 203 of file node.cpp.

◆ AbortWait()

bool lely::canopen::Node::AbortWait ( io_tqueue_wait wait)
noexcept

Aborts the specified wait operation if it is pending.

If aborted, the completion task is not submitted for execution.

Returns
true if the operation was aborted, and false if it was not pending.

Definition at line 208 of file node.cpp.

◆ AsyncSwitchBitrate()

ev::Future< void,::std::exception_ptr > lely::canopen::Node::AsyncSwitchBitrate ( io::CanControllerBase ctrl,
int  bitrate,
::std::chrono::milliseconds  delay 
)

Stops the specified CAN controller and submits asynchronous operations to wait for the delay period, set the new bit rate, wait for the delay period again, and restart the CAN controller.

This function can be used to implement the OnSwitchBitrate(int, ::std::chrono::milliseconds) callback in accordance with CiA 305.

Parameters
ctrla CAN controller.
bitratethe new bit rate (in bit/s).
delaythe delay before and after the switch, during which the CAN controller is stopped.
Returns
a future which becomes ready once the CAN controller is restarted or an error occurs.

Definition at line 213 of file node.cpp.

◆ OnCanState() [1/2]

void lely::canopen::Node::OnCanState ( ::std::function< void(io::CanState, io::CanState)>  on_can_state)

Registers the function to be invoked when a CAN bus state change is detected.

Only a single function can be registered at any one time. If on_can_state contains a callable function target, a copy of the target is invoked after OnCanState(io::CanState, io::CanState) completes.

Definition at line 245 of file node.cpp.

◆ OnCanError() [1/2]

void lely::canopen::Node::OnCanError ( ::std::function< void(io::CanError)>  on_can_error)

Registers the function to be invoked when an error is detected on the CAN bus.

Only a single function can be registered at any one time. If on_can_error contains a callable function target, a copy of the target is invoked after OnCanError(io::CanError) completes.

Definition at line 252 of file node.cpp.

◆ Reset()

void lely::canopen::Node::Reset ( )

(Re)starts the node.

This function behaves as if an NMT 'reset node' command has been received. Note that this function will cause the invocation of OnCommand() and therefore MUST NOT be called from that function.

Definition at line 258 of file node.cpp.

◆ ConfigHeartbeat() [1/2]

void lely::canopen::Node::ConfigHeartbeat ( uint8_t  id,
const ::std::chrono::milliseconds &  ms,
::std::error_code &  ec 
)

Configures heartbeat consumption for the specified node by updating CANopen object 1016 (Consumer heartbeat time).

Parameters
idthe node-ID (in the range [1..127]).
msthe heartbeat timeout (in milliseconds).
ecif heartbeat consumption cannot be configured, the SDO abort code is stored in ec.

Definition at line 270 of file node.cpp.

◆ ConfigHeartbeat() [2/2]

void lely::canopen::Node::ConfigHeartbeat ( uint8_t  id,
const ::std::chrono::milliseconds &  ms 
)

Configures heartbeat consumption for the specified node by updating CANopen object 1016 (Consumer heartbeat time).

Parameters
idthe node-ID (in the range [1..127]).
msthe heartbeat timeout (in milliseconds).
Exceptions
lely::canopen::SdoErrorif heartbeat consumption cannot be configured.

Definition at line 283 of file node.cpp.

◆ OnCommand()

void lely::canopen::Node::OnCommand ( ::std::function< void(NmtCommand)>  on_command)

Registers the function to be invoked when an NMT command is received from the master.

Only a single function can be registered at any one time. If on_command contains a callable function target, a copy of the target is invoked after OnCommand(NmtCommand) completes.

Definition at line 290 of file node.cpp.

◆ OnHeartbeat()

void lely::canopen::Node::OnHeartbeat ( ::std::function< void(uint8_t, bool)>  on_heartbeat)

Registers the function to be invoked when a heartbeat timeout event occurs or is resolved.

Only a single function can be registered at any one time. If on_heartbeat contains a callable function target, a copy of the target is invoked after OnHeartbeat(uint8_t, bool) completes.

Definition at line 296 of file node.cpp.

◆ OnState()

void lely::canopen::Node::OnState ( ::std::function< void(uint8_t, NmtState)>  on_state)

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

Only a single function can be registered at any one time. If on_state contains a callable function target, a copy of the target is invoked after OnState(uint8_t, NmtState) completes.

Definition at line 302 of file node.cpp.

◆ OnRpdo()

void lely::canopen::Node::OnRpdo ( ::std::function< void(int, ::std::error_code, const void *, ::std::size_t)>  on_rpdo)

Registers the function to be invoked when a Receive-PDO is processed.

Only a single function can be registered at any one time. If on_rpdo contains a callable function target, a copy of the target is invoked after OnRpdo(int, ::std::error_code, const void*, ::std::size_t) completes.

Definition at line 308 of file node.cpp.

◆ OnRpdoError()

void lely::canopen::Node::OnRpdoError ( ::std::function< void(int, uint16_t, uint8_t)>  on_rpdo_error)

Registers the function to be invoked when a Receive-PDO length mismatch or timeout error occurs.

Only a single function can be registered at any one time. If on_rpdo_error contains a callable function target, a copy of the target is invoked after OnRpdoError(int, uint16_t, uint8_t) completes.

Definition at line 320 of file node.cpp.

◆ OnTpdo()

void lely::canopen::Node::OnTpdo ( ::std::function< void(int, ::std::error_code, const void *, ::std::size_t)>  on_tpdo)

Registers the function to be invoked after a Transmit-PDO is sent or an error occurs.

Only a single function can be registered at any one time. If on_tpdo contains a callable function target, a copy of the target is invoked after OnTpdo(int, ::std::error_code, const void*, ::std::size_t) completes.

Definition at line 330 of file node.cpp.

◆ OnSync()

void lely::canopen::Node::OnSync ( ::std::function< void(uint8_t, const time_point &)>  on_sync)

Registers the function to be invoked when a SYNC message is sent/received.

Only a single function can be registered at any one time. If on_sync contains a callable function target, a copy of the target is invoked after OnSync(uint8_t, const time_point&) completes.

Definition at line 342 of file node.cpp.

◆ OnSyncError()

void lely::canopen::Node::OnSyncError ( ::std::function< void(uint16_t, uint8_t)>  on_sync_error)

Registers the function to be invoked when the data length of a received SYNC message does not match.

Only a single function can be registered at any one time. If on_sync_error contains a callable function target, a copy of the target is invoked after OnSyncError(uint16_t, uint8_t) completes.

Definition at line 352 of file node.cpp.

◆ OnTime()

void lely::canopen::Node::OnTime ( ::std::function< void(const ::std::chrono::system_clock::time_point &)>  on_time)

Registers the function to be invoked when a TIME message is received.

Only a single function can be registered at any one time. If on_time contains a callable function target, a copy of the target is invoked after OnTime(const ::std::chrono::system_clock::time_point&) completes.

Definition at line 362 of file node.cpp.

◆ OnEmcy()

void lely::canopen::Node::OnEmcy ( ::std::function< void(uint8_t, uint16_t, uint8_t, uint8_t[5])>  on_emcy)

Registers the function to be invoked when an EMCY message is received.

Only a single function can be registered at any one time. If on_emcy contains a callable function target, a copy of the target is invoked after OnEmcy(uint8_t, uint16_t, uint8_t, uint8_t[5]) completes.

Definition at line 374 of file node.cpp.

◆ OnSwitchBitrate()

void lely::canopen::Node::OnSwitchBitrate ( ::std::function< void(int, ::std::chrono::milliseconds)>  on_switch_bitrate)

Registers the function to be invoked when the LSS master activates the bit rate of all CANopen devices in the network.

Only a single function can be registered at any one time. If on_switch_bitrate contains a callable function target, a copy of the target is invoked after OnSwitchBitrate(int, ::std::chrono::milliseconds) completes.

Definition at line 385 of file node.cpp.

◆ OnCanState() [2/2]

void lely::canopen::Node::OnCanState ( io::CanState  new_state,
io::CanState  old_state 
)
protectedvirtualnoexcept

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

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

The default implementation sends an EMCY message if the CAN bus is in error passive mode or has recovered from bus off (see Table 26 in CiA 301 v4.2.0).

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

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

Definition at line 420 of file node.cpp.

◆ OnCanError() [2/2]

virtual void lely::canopen::Node::OnCanError ( io::CanError  error)
inlineprotectedvirtualnoexcept

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

Parameters
errorthe detected errors (any combination of CanError::BIT, CanError::STUFF, CanError::CRC, CanError::FORM, CanError::ACK and CanError::OTHER).

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

Definition at line 508 of file node.hpp.

◆ RpdoRtr()

void lely::canopen::Node::RpdoRtr ( int  num = 0)
protectednoexcept

Requests the transmission of a PDO by sending a CAN frame with the RTR (Remote Transmission Request) bit set.

Parameters
numthe PDO number (in the range [1..512]). If num is 0, the transmission of all PDOs is requested.

Definition at line 444 of file node.cpp.

◆ TpdoEvent()

void lely::canopen::Node::TpdoEvent ( int  num = 0)
protectednoexcept

Triggers the transmission of an acyclic or event-driven PDO.

The transmission of PDOs can be postponed by locking #tpdo_event_mutex.

Parameters
numthe PDO number (in the range [1..512]). If num is 0, the transmission of all PDOs is triggered.

Definition at line 457 of file node.cpp.


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