Lely core libraries
2.3.4
|
Go to the documentation of this file.
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_;
784 #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.
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...
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...
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.
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 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.
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.
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 unlock() override
Releases the lock held by the execution agent. Throws no exceptions.
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).
If T is one of the CANopen basic types, provides the member constant value equal to true.
An abstract task executor. This class is a wrapper around #ev_exec_t*.
__can_net * net() const noexcept
Returns a pointer to the internal CAN network interface from <lely/can/net.h>.
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 on_can_error(CanError error) noexcept
The function invoked when an error is detected on the CAN bus.
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.
A CANopen NMT master/slave service.
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...
@ 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.
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.
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.
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).
@ 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.
__co_nmt * nmt() const noexcept
Returns a pointer to the internal CANopen NMT master/slave service from <lely/co/nmt....
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.
A CAN network interface. This class is a wrapper around io_can_net_t*.
A recursive mutex-like object that can be used to postpone the transmission of acyclic and event-driv...
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,...