Lely core libraries
2.2.5
|
Go to the documentation of this file.
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_;
774 #endif // LELY_COAPP_NODE_HPP_
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.
An abstract interface conforming to the BasicLockable concept.
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.
NmtCommand
The NMT command specifiers.
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
bool AbortWait(io_tqueue_wait &wait) noexcept
Aborts the specified wait operation if it is pending.
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.
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...
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...
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.
A reference to an abstract timer.
void RpdoRtr(int num=0) noexcept
Requests the transmission of a PDO by sending a CAN frame with the RTR (Remote Transmission Request) ...
void Reset()
(Re)starts the node.
The type of objects thrown as exceptions to report a system error with an associated error code.
A reference to an abstract CAN channel.
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.
An opaque CANopen NMT master/slave service type.
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 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 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.
virtual void OnTime(const ::std::chrono::system_clock::time_point &abs_time) noexcept
The function invoked when a TIME message is received.
CanError
The error flags of a CAN bus, which are not mutually exclusive.
ev::Future< void, ::std::exception_ptr > AsyncWait(const duration &d, io_tqueue_wait **pwait=nullptr)
Equivalent to AsyncWait(nullptr, d, pwait).
CanState
The states of a CAN node, depending on the TX/RX error count.
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.
void unlock() override
Releases the lock held by the execution agent. Throws no exceptions.
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...
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 ...
virtual void OnHeartbeat(uint8_t id, bool occurred) noexcept
The function invoked when a heartbeat timeout event occurs or is resolved.
void TpdoEvent(int num=0) noexcept
Triggers the transmission of an acyclic or event-driven PDO.
A wait operation suitable for use with a timer queue.
uint8_t id() const noexcept
Returns the node-ID.
ev::Future< void, ::std::exception_ptr > AsyncWait(const time_point &t, io_tqueue_wait **pwait=nullptr)
Equivalent to AsyncWait(nullptr, t, pwait).
An abstract task executor. This class is a wrapper around #ev_exec_t*.
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 OnCommand(::std::function< void(NmtCommand)> on_command)
Registers the function to be invoked when an NMT command is received from the master.
An opaque CAN network interface type.
void SubmitWait(const duration &d, ev_exec_t *exec, F &&f)
Submits a wait operation.
bool CancelWait(io_tqueue_wait &wait) noexcept
Cancels the specified wait operation if it is pending.
The CANopen device description.
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 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 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.
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 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...
CANNet * net() const noexcept
Returns a pointer to the internal CAN network interface from <lely/can/net.hpp>.
@ RESET_COMM
Reset communication.
The base class for CANopen nodes.
ev::Executor GetExecutor() const noexcept
Returns the executor used to process I/O and CANopen events.
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.
virtual void OnCommand(NmtCommand cs) noexcept
The function invoked when an NMT command is received from the master.
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 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...
void on_can_error(io::CanError error) noexcept final
The function invoked when an error is detected on the CAN bus.
A reference to an abstract CAN controller.
@ RESET_NODE
Reset application (a local NMT sub-state).
void SubmitWait(const time_point &t, io_tqueue_wait &wait)
Submits a wait operation.
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.
void SetTime()
Updates the CAN network time.
void lock() override
Blocks until a lock can be obtained for the current execution agent (thread, process,...
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.
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).
virtual void OnSync(uint8_t cnt, const time_point &t) noexcept
The function invoked when a SYNC message is sent/received.
@ RESET_COMM
Reset communication (a local NMT sub-state).
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).
The base class for CANopen LSS masters.
@ TOGGLE
The mask to get/set the toggle bit from an NMT state.
TpdoEventMutex tpdo_event_mutex
The mutex used to postpone the transmission of acyclic and event-driven PDOs.
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 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...
@ ENTER_PREOP
Enter pre-operational.
CONMT * nmt() const noexcept
Returns a pointer to the internal CANopen NMT master/slave service from <lely/co/nmt....
A CAN network interface. This class is a wrapper around io_can_net_t*.
A mutex-like object that can be used to postpone the transmission of acyclic and event-driven Transmi...
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,...