22#ifndef LELY_COAPP_NODE_HPP_
23#define LELY_COAPP_NODE_HPP_
75 return static_cast<NmtState>(
static_cast<int>(lhs) &
static_cast<int>(rhs));
80 return static_cast<NmtState>(
static_cast<int>(lhs) |
static_cast<int>(rhs));
85 return static_cast<NmtState>(
static_cast<int>(lhs) ^
static_cast<int>(rhs));
90 return static_cast<NmtState>(~static_cast<int>(lhs));
95 return lhs = lhs & rhs;
100 return lhs = lhs | rhs;
105 return lhs = lhs ^ rhs;
120 using duration = io::TimerBase::duration;
121 using time_point = io::TimerBase::time_point;
144 const ::std::string& dcf_txt, const ::std::string& dcf_bin =
"",
149 const ::std::string& dcf_txt, const ::std::string& dcf_bin =
"",
151 :
Node(nullptr, timer, chan, dcf_txt, dcf_bin,
id) {}
154 Node& operator=(
const Node&) =
delete;
165 io::Clock
GetClock() const noexcept;
191 *io::make_timer_queue_wait_wrapper(exec, ::std::forward<F>(f)));
206 *io::make_timer_queue_wait_wrapper(exec, ::std::forward<F>(f)));
211 typename ::std::enable_if<!::std::is_base_of<
219 typename ::std::enable_if<!::std::is_base_of<
305 ::std::chrono::milliseconds delay);
341 void ConfigHeartbeat(uint8_t
id, const ::std::chrono::milliseconds& ms,
342 ::std::error_code& ec);
354 void ConfigHeartbeat(uint8_t
id, const ::std::chrono::milliseconds& ms);
370 void OnHeartbeat(::std::function<
void(uint8_t,
bool)> on_heartbeat);
389 ::std::function<
void(
int, ::std::error_code,
const void*, ::std::size_t)>
399 void OnRpdoError(::std::function<
void(
int, uint16_t, uint8_t)> on_rpdo_error);
409 ::std::function<
void(
int, ::std::error_code,
const void*, ::std::size_t)>
418 void OnSync(::std::function<
void(uint8_t,
const time_point&)> on_sync);
427 void OnSyncError(::std::function<
void(uint16_t, uint8_t)> on_sync_error);
436 ::std::function<
void(const ::std::chrono::system_clock::time_point&)>
446 ::std::function<
void(uint8_t, uint16_t, uint8_t, uint8_t[5])> on_emcy);
455 void OnSwitchBitrate(::std::function<
void(
int, ::std::chrono::milliseconds)>
467 void lock()
override;
497 virtual
void OnCanState(io::CanState new_state,
498 io::CanState old_state) noexcept;
527 void Error(uint16_t eec, uint8_t er,
528 const uint8_t msef[5] =
nullptr) noexcept;
537 void RpdoRtr(
int num = 0) noexcept;
562 DamMpdoEvent(
int num, uint8_t
id, uint16_t idx, uint8_t subidx, T value);
568 TpdoEventMutex tpdo_event_mutex;
572 io::CanState old_state) noexcept final;
640 OnRpdo(
int num, ::std::error_code ec,
const void* p,
641 ::std::size_t n)
noexcept {
662 OnRpdoError(
int num, uint16_t eec, uint8_t er)
noexcept {
687 OnTpdo(
int num, ::std::error_code ec,
const void* p,
688 ::std::size_t n)
noexcept {
704 OnSync(uint8_t cnt,
const time_point& t)
noexcept {
729 OnTime(const ::std::chrono::system_clock::time_point& abs_time)
noexcept {
742 OnEmcy(uint8_t
id, uint16_t eec, uint8_t er, uint8_t msef[5])
noexcept {
758 OnSwitchBitrate(
int bitrate, ::std::chrono::milliseconds delay)
noexcept {
774 virtual void OnStore(uint8_t
id,
int bitrate);
777 ::std::unique_ptr<Impl_> impl_;
This header file is part of the I/O library; it contains the C++ interface for the timer queue.
The CANopen device description.
uint8_t id() const noexcept
Returns the node-ID.
The base class for CANopen LSS masters.
A recursive mutex-like object that can be used to postpone the transmission of acyclic and event-driv...
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(const time_point &t, io_tqueue_wait **pwait=nullptr)
Equivalent to AsyncWait(nullptr, t, pwait).
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...
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.
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 when an NMT state change or boot-up event is detected for a remo...
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.
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.
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...
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.
__co_nmt * nmt() const noexcept
Returns a pointer to the internal CANopen NMT master/slave service from <lely/co/nmt....
ev::Future< void, ::std::exception_ptr > AsyncWait(const duration &d, io_tqueue_wait **pwait=nullptr)
Equivalent to AsyncWait(nullptr, d, pwait).
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,...
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).
__can_net * net() const noexcept
Returns a pointer to the internal CAN network interface from <lely/can/net.h>.
ev::Executor GetExecutor() const noexcept
Returns the executor used to process I/O and CANopen events.
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.
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.
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).
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.
void RpdoRtr(int num=0) noexcept
Requests the transmission of a PDO by sending a CAN frame with the RTR (Remote Transmission Request) ...
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*.
virtual void on_can_error(CanError error) noexcept
The function invoked when an error is detected on the CAN bus.
virtual void on_can_state(CanState new_state, CanState old_state) noexcept
The function invoked when a CAN bus state change is detected.
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.
NmtCommand
The NMT command specifiers.
@ ENTER_PREOP
Enter pre-operational.
@ RESET_COMM
Reset communication.
A CANopen NMT master/slave service.
A wait operation suitable for use with a timer queue.
If T is one of the CANopen basic types, provides the member constant value equal to true.
This header file is part of the I/O library; it contains the C++ interface for the timer queue.