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

The base class for CANopen slaves. More...

#include <slave.hpp>

Inheritance diagram for lely::canopen::BasicSlave:
Collaboration diagram for lely::canopen::BasicSlave:

Data Structures

class  ConstObject
 An accessor providing read-only access to a CANopen object in a local object dictionary. More...
 
class  ConstSubObject
 An accessor providing read-only access to a CANopen sub-object in a local object dictionary. More...
 
struct  Impl_
 The internal implementation of the CANopen slave. More...
 
class  Object
 A mutator providing read/write access to a CANopen object in a local object dictionary. More...
 
class  RpdoMapped
 An accessor providing read-only access to RPDO-mapped objects in a remote object dictionary. More...
 
class  SubObject
 A mutator providing read/write access to a CANopen sub-object in a local object dictionary. More...
 
class  TpdoMapped
 A mutator providing read/write access to TPDO-mapped objects in a remote object dictionary. More...
 

Public Member Functions

 BasicSlave (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 slave. More...
 
 BasicSlave (io::TimerBase &timer, io::CanChannelBase &chan, const ::std::string &dcf_txt, const ::std::string &dcf_bin="", uint8_t id=0xff)
 Creates a new CANopen slave.
 
void OnLifeGuarding (::std::function< void(bool)> on_life_guarding)
 Registers the function to be invoked when a life guarding event occurs or is resolved. More...
 
- Public Member Functions inherited from 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)
 Creates a new CANopen node. More...
 
 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. More...
 
void SubmitWait (const duration &d, io_tqueue_wait &wait)
 Submits a wait operation. More...
 
template<class F >
void SubmitWait (const time_point &t, ev_exec_t *exec, F &&f)
 Submits a wait operation. More...
 
template<class F >
void SubmitWait (const duration &d, ev_exec_t *exec, F &&f)
 Submits a wait operation. More...
 
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). More...
 
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). More...
 
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. More...
 
bool AbortWait (io_tqueue_wait &wait) noexcept
 Aborts the specified wait operation if it is pending. More...
 
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. More...
 
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. More...
 
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. More...
 
void Reset ()
 (Re)starts the node. More...
 
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). More...
 
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). More...
 
void OnCommand (::std::function< void(NmtCommand)> on_command)
 Registers the function to be invoked when an NMT command is received from the master. More...
 
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. More...
 
void OnState (::std::function< void(uint8_t, NmtState)> on_state)
 Registers the function to be invoked whenan NMT state change or boot-up event is detected for a remote node by the heartbeat protocol. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
- 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. More...
 
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< detail::is_canopen_type< T >::value, T >::type Read (uint16_t idx, uint8_t subidx) const
 Submits an SDO upload request to the local object dictionary. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_type< 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. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_basic< T >::value >::type Write (uint16_t idx, uint8_t subidx, T value)
 Submits an SDO download request to the local object dictionary. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_basic< T >::value >::type Write (uint16_t idx, uint8_t subidx, T value, ::std::error_code &ec)
 Submits an SDO download request to the local object dictionary. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_array< T >::value >::type Write (uint16_t idx, uint8_t subidx, const T &value)
 Submits an SDO download request to the local object dictionary. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_array< 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. More...
 
void Write (uint16_t idx, uint8_t subidx, const char *value)
 Submits an SDO download request to the local object dictionary. More...
 
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. More...
 
void Write (uint16_t idx, uint8_t subidx, const char16_t *value)
 Submits an SDO download request to the local object dictionary. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
template<class T >
typename ::std::enable_if< detail::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. More...
 
template<class T >
typename ::std::enable_if< detail::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. More...
 
template<class T >
typename ::std::enable_if< detail::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. More...
 
template<class T >
typename ::std::enable_if< detail::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. More...
 
template<class T >
typename ::std::enable_if< detail::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. More...
 
template<class T >
typename ::std::enable_if< detail::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. More...
 
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. More...
 
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. More...
 

Protected Types

template<class T >
using OnReadSignature = ::std::error_code(uint16_t idx, uint8_t subdx, T &value)
 The signature of the callback function invoked on read (SDO upload) access to the local object dictionary. More...
 
template<class T >
using OnWriteSignature = typename ::std::conditional< detail::is_canopen_basic< T >::value, ::std::error_code(uint16_t idx, uint8_t subidx, T &new_val, T old_val), ::std::error_code(uint16_t idx, uint8_t subidx, T &new_val)>::type
 The signature of the callback function invoked on write (SDO download) access to the local object dictionary. More...
 

Protected Member Functions

Object operator[] (::std::ptrdiff_t idx) noexcept
 Returns a mutator object that provides read/write access to the specified CANopen object in the local object dictionary. More...
 
ConstObject operator[] (::std::ptrdiff_t idx) const noexcept
 Returns an accessor object that provides read-only access to the specified CANopen object in the local object dictionary. More...
 
RpdoMapped RpdoMapped (uint8_t id) const noexcept
 Returns an accessor object that provides read-only access to RPDO-mapped objects in the remote object dictionary of the specified node. More...
 
TpdoMapped TpdoMapped (uint8_t id) noexcept
 Returns a mutator object that provides read/write access to TPDO-mapped objects in the remote object dictionary of the specified node. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_type< T >::value >::type OnRead (uint16_t idx, uint8_t subidx, ::std::function< OnReadSignature< T >> ind)
 Registers a callback function to be invoked on read (SDO upload) access to the specified CANopen sub-object in the local object dictionary. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_type< T >::value >::type OnRead (uint16_t idx, uint8_t subidx, ::std::function< OnReadSignature< T >> ind, ::std::error_code &ec)
 Registers a callback function to be invoked on read (SDO upload) access to the specified CANopen sub-object in the local object dictionary. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_type< T >::value >::type OnRead (uint16_t idx, ::std::function< OnReadSignature< T >> ind)
 Registers a callback function to be invoked on read (SDO upload) access to each member of the specified CANopen record or array object in the local object dictionary. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_type< T >::value >::type OnRead (uint16_t idx, ::std::function< OnReadSignature< T >> ind, ::std::error_code &ec)
 Registers a callback function to be invoked on read (SDO upload) access to each member of the specified CANopen record or array object in the local object dictionary. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_type< T >::value >::type OnWrite (uint16_t idx, uint8_t subidx, ::std::function< OnWriteSignature< T >> ind)
 Registers a callback function to be invoked on write (SDO download) access to the specified CANopen sub-object in the local object dictionary. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_type< T >::value >::type OnWrite (uint16_t idx, uint8_t subidx, ::std::function< OnWriteSignature< T >> ind, ::std::error_code &ec)
 Registers a callback function to be invoked on write (SDO download) access to the specified CANopen sub-object in the local object dictionary. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_type< T >::value >::type OnWrite (uint16_t idx, ::std::function< OnWriteSignature< T >> ind)
 Registers a callback function to be invoked on write (SDO download) access to each member of the specified CANopen record or array object in the local object dictionary. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_type< T >::value >::type OnWrite (uint16_t idx, ::std::function< OnWriteSignature< T >> ind, ::std::error_code &ec)
 Registers a callback function to be invoked on write (SDO download) access to each member of the specified CANopen record or array object in the local object dictionary. More...
 
virtual void OnLifeGuarding (bool occurred) noexcept
 The function invoked when a life guarding event occurs or is resolved. More...
 
- Protected Member Functions inherited from lely::canopen::Node
CANNetnet () const noexcept
 Returns a pointer to the internal CAN network interface from <lely/can/net.hpp>.
 
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. More...
 
virtual void OnCanError (io::CanError error) noexcept
 The function invoked when an error is detected on the CAN bus. More...
 
CONMTnmt () 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. More...
 
void TpdoEvent (int num=0) noexcept
 Triggers the transmission of an acyclic or event-driven PDO. More...
 
void on_can_state (io::CanState new_state, io::CanState old_state) noexcept final
 The function invoked when a CAN bus state change is detected. More...
 
void on_can_error (io::CanError error) noexcept final
 The function invoked when an error is detected on the CAN bus. More...
 
virtual void OnCommand (NmtCommand cs) noexcept
 The function invoked when an NMT command is received from the master. More...
 
virtual void OnHeartbeat (uint8_t id, bool occurred) noexcept
 The function invoked when a heartbeat timeout event occurs or is resolved. More...
 
virtual void OnState (uint8_t id, NmtState st) noexcept
 The function invoked when an NMT state change or boot-up event is detected for a remote node by the heartbeat protocol. More...
 
virtual void OnRpdo (int num, ::std::error_code ec, const void *p, ::std::size_t n) noexcept
 The function invoked when a Receive-PDO is processed. More...
 
virtual void OnRpdoError (int num, uint16_t eec, uint8_t er) noexcept
 The function invoked when a Receive-PDO length mismatch or timeout error occurs. More...
 
virtual void OnTpdo (int num, ::std::error_code ec, const void *p, ::std::size_t n) noexcept
 The function invoked after a Transmit-PDO is sent or an error occurs. More...
 
virtual void OnSync (uint8_t cnt, const time_point &t) noexcept
 The function invoked when a SYNC message is sent/received. More...
 
virtual void OnSyncError (uint16_t eec, uint8_t er) noexcept
 The function invoked when the data length of a received SYNC message does not match. More...
 
virtual void OnTime (const ::std::chrono::system_clock::time_point &abs_time) noexcept
 The function invoked when a TIME message is received. More...
 
virtual void OnEmcy (uint8_t id, uint16_t eec, uint8_t er, uint8_t msef[5]) noexcept
 The function invoked when an EMCY message is received. More...
 
virtual void OnSwitchBitrate (int bitrate, ::std::chrono::milliseconds delay) noexcept
 The function invoked when the LSS master activates the bit rate of all CANopen devices in the network. More...
 
virtual void OnStore (uint8_t id, int bitrate)
 The function invoked then a request is received from the LSS master to store the pending node-ID and bit rate to non-volatile memory. More...
 
- 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). More...
 
void unlock () final
 Releases the lock held by the execution agent. Throws no exceptions.
 
void set_time ()
 Updates the CAN network time. More...
 
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. More...
 
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. More...
 
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. More...
 
- Protected Member Functions inherited from lely::canopen::Device
CODevdev () 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. More...
 
const ::std::type_info & Type (uint16_t idx, uint8_t subidx, ::std::error_code &ec) const noexcept
 Returns the type of a sub-object. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_type< T >::value, T >::type Get (uint16_t idx, uint8_t subidx) const
 Reads the value of a sub-object. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_type< T >::value, T >::type Get (uint16_t idx, uint8_t subidx, ::std::error_code &ec) const noexcept
 Reads the value of a sub-object. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_basic< T >::value >::type Set (uint16_t idx, uint8_t subidx, T value)
 Writes a CANopen basic value to a sub-object. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_basic< T >::value >::type Set (uint16_t idx, uint8_t subidx, T value, ::std::error_code &ec) noexcept
 Writes a CANopen basic value to a sub-object. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_array< T >::value >::type Set (uint16_t idx, uint8_t subidx, const T &value)
 Writes a CANopen array value to a sub-object. More...
 
template<class T >
typename ::std::enable_if< detail::is_canopen_array< T >::value >::type Set (uint16_t idx, uint8_t subidx, const T &value, ::std::error_code &ec) noexcept
 Writes a CANopen array value to a sub-object. More...
 
void Set (uint16_t idx, uint8_t subidx, const char *value)
 Writes a VISIBLE_STRING to a sub-object. More...
 
void Set (uint16_t idx, uint8_t subidx, const char *value, ::std::error_code &ec) noexcept
 Writes a VISIBLE_STRING to a sub-object. More...
 
void Set (uint16_t idx, uint8_t subidx, const char16_t *value)
 Writes a UNICODE_STRING to a sub-object. More...
 
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. More...
 
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. More...
 
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. More...
 
const char * GetUploadFile (uint16_t idx, uint8_t subidx) const
 Returns the value of the UploadFile attribute of a sub-object, if present. More...
 
const char * GetUploadFile (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. More...
 
void SetUploadFile (uint16_t idx, uint8_t subidx, const char *filename)
 Sets the value of the UploadFile attribute of a sub-object, if present. More...
 
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. More...
 
const char * GetDownloadFile (uint16_t idx, uint8_t subidx) const
 Returns the value of the DownloadFile attribute of a sub-object, if present. More...
 
const char * GetDownloadFile (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. More...
 
void SetDownloadFile (uint16_t idx, uint8_t subidx, const char *filename)
 Sets the value of the DownloadFile attribute of a sub-object, if present. More...
 
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. More...
 
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. More...
 
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. More...
 
template<class T >
typename ::std::enable_if< detail::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. More...
 
template<class T >
typename ::std::enable_if< detail::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. More...
 
template<class T >
typename ::std::enable_if< detail::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. More...
 
template<class T >
typename ::std::enable_if< detail::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. More...
 
template<class T >
typename ::std::enable_if< detail::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. More...
 
template<class T >
typename ::std::enable_if< detail::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. More...
 
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. More...
 
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. More...
 
void UpdateRpdoMapping ()
 Updates the mapping from remote TPDO-mapped sub-objects to local RPDO-mapped sub-objects. More...
 
void UpdateTpdoMapping ()
 Updates the mapping from remote RPDO-mapped sub-objects to local TPDO-mapped sub-objects. More...
 

Additional Inherited Members

- Protected Attributes inherited from lely::canopen::Node
TpdoEventMutex tpdo_event_mutex
 The mutex used to postpone the transmission of acyclic and event-driven PDOs.
 

Detailed Description

The base class for CANopen slaves.

Definition at line 38 of file slave.hpp.

Member Typedef Documentation

◆ OnReadSignature

template<class T >
using lely::canopen::BasicSlave::OnReadSignature = ::std::error_code(uint16_t idx, uint8_t subdx, T& value)
protected

The signature of the callback function invoked on read (SDO upload) access to the local object dictionary.

Note that the callback function SHOULD NOT throw exceptions. Since it is invoked from C, any exception that is thrown cannot be caught and will result in a call to std::terminate(). The lely::util::BasicLockable mutex implemented by this class is held for the duration of the call.

Parameters
idxthe object index.
subidxthe object sub-index.
valuethe current value in the object dictionary. This value can be modified before it is returned to the client.
Returns
0 on success, or an SDO abort code on error.

Definition at line 610 of file slave.hpp.

◆ OnWriteSignature

template<class T >
using lely::canopen::BasicSlave::OnWriteSignature = typename ::std::conditional< detail::is_canopen_basic<T>::value, ::std::error_code(uint16_t idx, uint8_t subidx, T& new_val, T old_val), ::std::error_code(uint16_t idx, uint8_t subidx, T& new_val)>::type
protected

The signature of the callback function invoked on write (SDO download) access to the local object dictionary.

Note that the callback function SHOULD NOT throw exceptions. Since it is invoked from C, any exception that is thrown cannot be caught and will result in a call to std::terminate(). The lely::util::BasicLockable mutex implemented by this class is held for the duration of the call.

Parameters
idxthe object index.
subidxthe object sub-index.
new_valthe value to be written to the object dictionary. This value can be modified before it is committed.
old_valthe current value in the object dictionary (only for CANopen basic data types).
Returns
0 on success, or an SDO abort code on error.

Definition at line 633 of file slave.hpp.

Constructor & Destructor Documentation

◆ BasicSlave()

lely::canopen::BasicSlave::BasicSlave ( 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 slave.

After creation, the slave 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 78 of file slave.cpp.

Member Function Documentation

◆ OnLifeGuarding() [1/2]

void lely::canopen::BasicSlave::OnLifeGuarding ( ::std::function< void(bool)>  on_life_guarding)

Registers the function to be invoked when a life guarding event occurs or is resolved.

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

Definition at line 87 of file slave.cpp.

◆ operator[]() [1/2]

Object lely::canopen::BasicSlave::operator[] ( ::std::ptrdiff_t  idx)
inlineprotectednoexcept

Returns a mutator object that provides read/write access to the specified CANopen object in the local object dictionary.

Note that this function succeeds even if the object does not exist.

Parameters
idxthe object index.
Returns
a mutator object for a CANopen object in the local object dictionary.

Definition at line 645 of file slave.hpp.

◆ operator[]() [2/2]

ConstObject lely::canopen::BasicSlave::operator[] ( ::std::ptrdiff_t  idx) const
inlineprotectednoexcept

Returns an accessor object that provides read-only access to the specified CANopen object in the local object dictionary.

Note that this function succeeds even if the object does not exist.

Parameters
idxthe object index.
Returns
an accessor object for a CANopen object in the local object dictionary.

Definition at line 657 of file slave.hpp.

◆ RpdoMapped()

RpdoMapped lely::canopen::BasicSlave::RpdoMapped ( uint8_t  id) const
inlineprotectednoexcept

Returns an accessor object that provides read-only access to RPDO-mapped objects in the remote object dictionary of the specified node.

Note that this function succeeds even if no RPDO-mapped objects exist.

Parameters
idthe node-ID.
Returns
an accessor object for RPDO-mapped objects in a remote object dictionary.

Definition at line 672 of file slave.hpp.

◆ TpdoMapped()

TpdoMapped lely::canopen::BasicSlave::TpdoMapped ( uint8_t  id)
inlineprotectednoexcept

Returns a mutator object that provides read/write access to TPDO-mapped objects in the remote object dictionary of the specified node.

Note that this function succeeds even if no TPDO-mapped objects exist.

Parameters
idthe node-ID.
Returns
a mutator object for TPDO-mapped objects in a remote object dictionary.

Definition at line 687 of file slave.hpp.

◆ OnRead() [1/4]

template<class T >
typename ::std::enable_if<detail::is_canopen_type<T>::value>::type lely::canopen::BasicSlave::OnRead ( uint16_t  idx,
uint8_t  subidx,
::std::function< OnReadSignature< T >>  ind 
)
protected

Registers a callback function to be invoked on read (SDO upload) access to the specified CANopen sub-object in the local object dictionary.

Note that the callback function is not invoked if the access checks fail.

Parameters
idxthe object index.
subidxthe object sub-index.
indthe indication function to be called on write access to the specified sub-object.
Exceptions
lely::canopen::SdoErroron error.

◆ OnRead() [2/4]

template<class T >
typename ::std::enable_if<detail::is_canopen_type<T>::value>::type lely::canopen::BasicSlave::OnRead ( uint16_t  idx,
uint8_t  subidx,
::std::function< OnReadSignature< T >>  ind,
::std::error_code &  ec 
)
protected

Registers a callback function to be invoked on read (SDO upload) access to the specified CANopen sub-object in the local object dictionary.

Note that the callback function is not invoked if the access checks fail.

Parameters
idxthe object index.
subidxthe object sub-index.
indthe indication function to be called on write access to the specified sub-object.
econ error, the SDO abort code is stored in ec.

◆ OnRead() [3/4]

template<class T >
typename ::std::enable_if<detail::is_canopen_type<T>::value>::type lely::canopen::BasicSlave::OnRead ( uint16_t  idx,
::std::function< OnReadSignature< T >>  ind 
)
protected

Registers a callback function to be invoked on read (SDO upload) access to each member of the specified CANopen record or array object in the local object dictionary.

Note that the callback function is not invoked if the access checks fail.

Parameters
idxthe object index.
indthe indication function to be called on read access to each member of the specified object.
Exceptions
lely::canopen::SdoErroron error.

◆ OnRead() [4/4]

template<class T >
typename ::std::enable_if<detail::is_canopen_type<T>::value>::type lely::canopen::BasicSlave::OnRead ( uint16_t  idx,
::std::function< OnReadSignature< T >>  ind,
::std::error_code &  ec 
)
protected

Registers a callback function to be invoked on read (SDO upload) access to each member of the specified CANopen record or array object in the local object dictionary.

Note that the callback function is not invoked if the access checks fail.

Parameters
idxthe object index.
indthe indication function to be called on read access to each member of the specified object.
econ error, the SDO abort code is stored in ec.

◆ OnWrite() [1/4]

template<class T >
typename ::std::enable_if<detail::is_canopen_type<T>::value>::type lely::canopen::BasicSlave::OnWrite ( uint16_t  idx,
uint8_t  subidx,
::std::function< OnWriteSignature< T >>  ind 
)
protected

Registers a callback function to be invoked on write (SDO download) access to the specified CANopen sub-object in the local object dictionary.

Note that the callback function is not invoked if the access or range checks fail.

Parameters
idxthe object index.
subidxthe object sub-index.
indthe indication function to be called on read access to the specified sub-object.
Exceptions
lely::canopen::SdoErroron error.

◆ OnWrite() [2/4]

template<class T >
typename ::std::enable_if<detail::is_canopen_type<T>::value>::type lely::canopen::BasicSlave::OnWrite ( uint16_t  idx,
uint8_t  subidx,
::std::function< OnWriteSignature< T >>  ind,
::std::error_code &  ec 
)
protected

Registers a callback function to be invoked on write (SDO download) access to the specified CANopen sub-object in the local object dictionary.

Note that the callback function is not invoked if the access or range checks fail.

Parameters
idxthe object index.
subidxthe object sub-index.
indthe indication function to be called on read access to the specified sub-object.
econ error, the SDO abort code is stored in ec.

◆ OnWrite() [3/4]

template<class T >
typename ::std::enable_if<detail::is_canopen_type<T>::value>::type lely::canopen::BasicSlave::OnWrite ( uint16_t  idx,
::std::function< OnWriteSignature< T >>  ind 
)
protected

Registers a callback function to be invoked on write (SDO download) access to each member of the specified CANopen record or array object in the local object dictionary.

Note that the callback function is not invoked if the access or range checks fail.

Parameters
idxthe object index.
indthe indication function to be called on write access to each member of the specified object.
Exceptions
lely::canopen::SdoErroron error.

◆ OnWrite() [4/4]

template<class T >
typename ::std::enable_if<detail::is_canopen_type<T>::value>::type lely::canopen::BasicSlave::OnWrite ( uint16_t  idx,
::std::function< OnWriteSignature< T >>  ind,
::std::error_code &  ec 
)
protected

Registers a callback function to be invoked on write (SDO download) access to each member of the specified CANopen record or array object in the local object dictionary.

Note that the callback function is not invoked if the access or range checks fail.

Parameters
idxthe object index.
indthe indication function to be called on write access to each member of the specified object.
econ error, the SDO abort code is stored in ec.

◆ OnLifeGuarding() [2/2]

virtual void lely::canopen::BasicSlave::OnLifeGuarding ( bool  occurred)
inlineprotectedvirtualnoexcept

The function invoked when a life guarding event occurs or is resolved.

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

Parameters
occurredtrue if the life guarding event occurred, false if it was resolved.

Definition at line 834 of file slave.hpp.


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