22 #ifndef LELY_COAPP_NODE_HPP_
23 #define LELY_COAPP_NODE_HPP_
74 return static_cast<NmtState>(
static_cast<int>(lhs) &
static_cast<int>(rhs));
79 return static_cast<NmtState>(
static_cast<int>(lhs) |
static_cast<int>(rhs));
84 return static_cast<NmtState>(
static_cast<int>(lhs) ^
static_cast<int>(rhs));
89 return static_cast<NmtState>(~static_cast<int>(lhs));
94 return lhs = lhs & rhs;
99 return lhs = lhs | rhs;
104 return lhs = lhs ^ rhs;
119 using duration = io::TimerBase::duration;
120 using time_point = io::TimerBase::time_point;
143 const ::std::string& dcf_txt, const ::std::string& dcf_bin =
"",
148 const ::std::string& dcf_txt, const ::std::string& dcf_bin =
"",
150 :
Node(nullptr, timer, chan, dcf_txt, dcf_bin,
id) {}
153 Node& operator=(
const Node&) =
delete;
164 io::Clock
GetClock() const noexcept;
190 *io::make_timer_queue_wait_wrapper(exec, ::std::forward<F>(f)));
205 *io::make_timer_queue_wait_wrapper(exec, ::std::forward<F>(f)));
210 typename ::std::enable_if<!::std::is_base_of<
218 typename ::std::enable_if<!::std::is_base_of<
304 ::std::chrono::milliseconds delay);
340 void ConfigHeartbeat(uint8_t
id, const ::std::chrono::milliseconds& ms,
341 ::std::error_code& ec);
353 void ConfigHeartbeat(uint8_t
id, const ::std::chrono::milliseconds& ms);
369 void OnHeartbeat(::std::function<
void(uint8_t,
bool)> on_heartbeat);
388 ::std::function<
void(
int, ::std::error_code,
const void*, ::std::size_t)>
398 void OnRpdoError(::std::function<
void(
int, uint16_t, uint8_t)> on_rpdo_error);
408 ::std::function<
void(
int, ::std::error_code,
const void*, ::std::size_t)>
417 void OnSync(::std::function<
void(uint8_t,
const time_point&)> on_sync);
426 void OnSyncError(::std::function<
void(uint16_t, uint8_t)> on_sync_error);
435 ::std::function<
void(const ::std::chrono::system_clock::time_point&)>
445 ::std::function<
void(uint8_t, uint16_t, uint8_t, uint8_t[5])> on_emcy);
454 void OnSwitchBitrate(::std::function<
void(
int, ::std::chrono::milliseconds)>
466 void lock()
override;
496 virtual
void OnCanState(io::CanState new_state,
497 io::CanState old_state) noexcept;
526 void Error(uint16_t eec, uint8_t er,
527 const uint8_t msef[5] =
nullptr) noexcept;
536 void RpdoRtr(
int num = 0) noexcept;
553 #ifndef DOXYGEN_SHOULD_SKIP_THIS
626 OnRpdo(
int num, ::std::error_code ec,
const void* p,
627 ::std::size_t n) noexcept {
673 OnTpdo(
int num, ::std::error_code ec,
const void* p,
674 ::std::size_t n) noexcept {
690 OnSync(uint8_t cnt,
const time_point& t) noexcept {
715 OnTime(const ::std::chrono::system_clock::time_point& abs_time) noexcept {
728 OnEmcy(uint8_t
id, uint16_t eec, uint8_t er, uint8_t msef[5]) noexcept {
760 virtual void OnStore(uint8_t
id,
int bitrate);
762 #ifdef DOXYGEN_SHOULD_SKIP_THIS
767 ::std::unique_ptr<Impl_> impl_;
This header file is part of the I/O library; it contains the C++ interface for the timer queue.
An opaque CAN network interface type.
An opaque CANopen NMT master/slave service type.
The CANopen device description.
uint8_t id() const noexcept
Returns the node-ID.
The base class for CANopen LSS masters.
A mutex-like object that can be used to postpone the transmission of acyclic and event-driven Transmi...
void lock() override
Blocks until a lock can be obtained for the current execution agent (thread, process,...
void unlock() override
Releases the lock held by the execution agent. Throws no exceptions.
The base class for CANopen nodes.
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 operati...
ev::Future< void, ::std::exception_ptr > AsyncWait(const duration &d, io_tqueue_wait **pwait=nullptr)
Equivalent to AsyncWait(nullptr, d, pwait).
void Reset()
(Re)starts the node.
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.
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).
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 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 remot...
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 hea...
void SetTime()
Updates the CAN network time.
CANNet * net() const noexcept
Returns a pointer to the internal CAN network interface from <lely/can/net.hpp>.
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 OnCommand(::std::function< void(NmtCommand)> on_command)
Registers the function to be invoked when an NMT command is received from the master.
virtual void OnTime(const ::std::chrono::system_clock::time_point &abs_time) noexcept
The function invoked when a TIME 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 device...
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.
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.
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.
virtual void OnCommand(NmtCommand cs) noexcept
The function invoked when an NMT command is received from the master.
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.
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.
CONMT * nmt() const noexcept
Returns a pointer to the internal CANopen NMT master/slave service from <lely/co/nmt....
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...
io::ContextBase GetContext() const noexcept
Returns the underlying I/O context with which this context is registered.
void TpdoEvent(int num=0) noexcept
Triggers the transmission of an acyclic or event-driven PDO.
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.
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,...
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.
virtual void OnSync(uint8_t cnt, const time_point &t) noexcept
The function invoked when a SYNC message is sent/received.
TpdoEventMutex tpdo_event_mutex
The mutex used to postpone the transmission of acyclic and event-driven PDOs.
ev::Executor GetExecutor() const noexcept
Returns the executor used to process I/O and CANopen events.
void on_can_error(io::CanError error) noexcept final
The function invoked when an error is detected on the CAN bus.
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 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 SubmitWait(const duration &d, ev_exec_t *exec, F &&f)
Submits a wait operation.
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.
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.
io::Clock GetClock() const noexcept
Returns the clock used by the timer.
bool AbortWait(io_tqueue_wait &wait) noexcept
Aborts the specified wait operation if it is pending.
virtual void OnHeartbeat(uint8_t id, bool occurred) noexcept
The function invoked when a heartbeat timeout event occurs or is resolved.
ev::Future< void, ::std::exception_ptr > AsyncWait(const time_point &t, io_tqueue_wait **pwait=nullptr)
Equivalent to AsyncWait(nullptr, t, pwait).
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).
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.
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 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 SubmitWait(const time_point &t, io_tqueue_wait &wait)
Submits a wait operation.
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 h...
void RpdoRtr(int num=0) noexcept
Requests the transmission of a PDO by sending a CAN frame with the RTR (Remote Transmission Request) ...
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 ...
bool CancelWait(io_tqueue_wait &wait) noexcept
Cancels the specified wait operation if it is pending.
The type of objects thrown as exceptions to report a system error with an associated error code.
An abstract task executor. This class is a wrapper around #ev_exec_t*.
A reference to an abstract CAN channel.
A reference to an abstract CAN controller.
A CAN network interface. This class is a wrapper around io_can_net_t*.
A reference to an abstract timer.
An abstract interface conforming to the BasicLockable concept.
This header file is part of the C++ CANopen application library; it contains the CANopen device descr...
CanError
The error flags of a CAN bus, which are not mutually exclusive.
CanState
The states of a CAN node, depending on the TX/RX error count.
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
@ TOGGLE
The mask to get/set the toggle bit from an NMT state.
@ RESET_COMM
Reset communication (a local NMT sub-state).
@ RESET_NODE
Reset application (a local NMT sub-state).
NmtCommand
The NMT command specifiers.
@ ENTER_PREOP
Enter pre-operational.
@ RESET_COMM
Reset communication.
A wait operation suitable for use with a timer queue.
This header file is part of the I/O library; it contains the C++ interface for the timer queue.