22 #ifndef LELY_COAPP_DRIVER_HPP_
23 #define LELY_COAPP_DRIVER_HPP_
38 using time_point = BasicMaster::time_point;
54 virtual uint8_t
netid() const noexcept = 0;
57 virtual uint8_t
id() const noexcept = 0;
65 io::CanState old_state) noexcept = 0;
82 virtual
void OnRpdoWrite(uint16_t idx, uint8_t subidx) noexcept = 0;
176 const ::std::
string& what) noexcept = 0;
194 ::std::function<
void(::std::error_code ec)> res) noexcept = 0;
210 ::std::function<
void(::std::error_code ec)> res) noexcept = 0;
222 virtual
void OnSync(uint8_t cnt, const time_point& t) noexcept = 0;
243 const ::std::chrono::system_clock::time_point& abs_time) noexcept = 0;
254 virtual
void OnEmcy(uint16_t eec, uint8_t er, uint8_t msef[5]) noexcept = 0;
283 using DriverBase::time_point;
284 using duration = BasicMaster::duration;
317 return master.
netid();
321 id() const noexcept final {
335 ::std::error_code& ec) {
361 return master.
Boot(
id());
447 template <
class T,
class F>
451 ::std::forward<F>(con));
460 template <
class T,
class F>
462 SubmitRead(uint16_t idx, uint8_t subidx, F&& con, ::std::error_code& ec) {
464 ::std::forward<F>(con), ec);
472 template <
class T,
class F>
475 const ::std::chrono::milliseconds& timeout) {
477 ::std::forward<F>(con), timeout);
495 template <
class T,
class F>
498 const ::std::chrono::milliseconds& timeout,
499 ::std::error_code& ec) {
501 ::std::forward<F>(con), timeout, ec);
510 template <
class T,
class F>
514 ::std::forward<T>(value), ::std::forward<F>(con));
523 template <
class T,
class F>
526 ::std::error_code& ec) {
528 ::std::forward<T>(value), ::std::forward<F>(con), ec);
536 template <
class T,
class F>
539 const ::std::chrono::milliseconds& timeout) {
541 ::std::forward<T>(value), ::std::forward<F>(con),
561 template <
class T,
class F>
564 const ::std::chrono::milliseconds& timeout,
565 ::std::error_code& ec) {
567 ::std::forward<T>(value), ::std::forward<F>(con),
600 const ::std::chrono::milliseconds& timeout) {
614 ::std::forward<T>(value));
634 const ::std::chrono::milliseconds& timeout) {
636 ::std::forward<T>(value), timeout);
664 template <
class F,
class... Args>
667 GetExecutor().
post(::std::forward<F>(f), ::std::forward<Args>(args)...);
693 using MapType = ::std::map<uint8_t, LogicalDriverBase*>;
719 void OnRpdoWrite(uint16_t idx, uint8_t subidx) noexcept
override;
755 const ::std::string& what) noexcept
override;
764 ::std::function<
void(::std::error_code ec)> res) noexcept
override;
773 ::std::function<
void(::std::error_code ec)> res) noexcept
override;
780 void OnSync(uint8_t cnt,
const time_point& t) noexcept
override;
787 void OnSyncError(uint16_t eec, uint8_t er) noexcept
override;
794 void OnTime(const ::std::chrono::system_clock::time_point&
795 abs_time) noexcept
override;
802 void OnEmcy(uint16_t eec, uint8_t er, uint8_t msef[5]) noexcept
override;
822 const uint8_t id_{0xff};
The base class for drivers for remote CANopen nodes.
void SubmitWrite(uint16_t idx, uint8_t subidx, T &&value, F &&con)
Equivalent to SubmitWrite(uint16_t idx, uint8_t subidx, T&& value, F&& con, const ::std::chrono::mill...
SdoFuture< void > AsyncWrite(uint16_t idx, uint8_t subidx, T &&value)
Equivalent to AsyncWrite(uint16_t idx, uint8_t subidx, T&& value, const ::std::chrono::milliseconds& ...
SdoFuture< void > AsyncWait(const duration &d)
Submits an asynchronous wait operation and creates a future which becomes ready once the wait operati...
void SubmitRead(uint16_t idx, uint8_t subidx, F &&con, const ::std::chrono::milliseconds &timeout)
Equivalent to SubmitRead(uint16_t idx, uint8_t subidx, F&& con, const ::std::chrono::milliseconds& ti...
uint8_t netid() const noexcept final
Returns the network-ID.
SdoFuture< void > AsyncWait(const time_point &t)
Submits an asynchronous wait operation and creates a future which becomes ready once the wait operati...
void ConfigHeartbeat(const ::std::chrono::milliseconds &ms)
Configures heartbeat consumption by updating CANopen object 1016 (Consumer heartbeat time).
bool IsReady() const
Returns true if the remote node is ready (i.e., the NMT boot slave process has successfully completed...
void SubmitWrite(uint16_t idx, uint8_t subidx, T &&value, F &&con, const ::std::chrono::milliseconds &timeout)
Equivalent to SubmitWrite(uint16_t idx, uint8_t subidx, T&& value, F&& con, const ::std::chrono::mill...
TpdoEventMutex & tpdo_event_mutex
ev::Executor GetExecutor() const noexcept final
Returns the executor used to execute event handlers for this driver, including SDO confirmation funct...
BasicDriver(BasicMaster &master, uint8_t id)
Creates a new driver for a remote CANopen node and registers it with the master.
void SubmitRead(uint16_t idx, uint8_t subidx, F &&con, const ::std::chrono::milliseconds &timeout, ::std::error_code &ec)
Queues an asynchronous read (SDO upload) operation.
SdoFuture< T > AsyncRead(uint16_t idx, uint8_t subidx, const ::std::chrono::milliseconds &timeout)
Queues an asynchronous read (SDO upload) operation and creates a future which becomes ready once the ...
uint8_t id() const noexcept final
Returns the node-ID.
void SubmitWrite(uint16_t idx, uint8_t subidx, T &&value, F &&con, const ::std::chrono::milliseconds &timeout, ::std::error_code &ec)
Queues an asynchronous write (SDO download) operation.
void ConfigHeartbeat(const ::std::chrono::milliseconds &ms, ::std::error_code &ec)
Configures heartbeat consumption by updating CANopen object 1016 (Consumer heartbeat time).
void SubmitRead(uint16_t idx, uint8_t subidx, F &&con, ::std::error_code &ec)
Equivalent to SubmitRead(uint16_t idx, uint8_t subidx, F&& con, const ::std::chrono::milliseconds& ti...
void SubmitWrite(uint16_t idx, uint8_t subidx, T &&value, F &&con, ::std::error_code &ec)
Equivalent to SubmitWrite(uint16_t idx, uint8_t subidx, T&& value, F&& con, const ::std::chrono::mill...
bool Boot()
Requests the NMT 'boot slave' process for the remote node.
SdoFuture< T > AsyncRead(uint16_t idx, uint8_t subidx)
Equivalent to AsyncRead(uint16_t idx, uint8_t subidx, const ::std::chrono::milliseconds& timeout),...
SdoFuture< void > AsyncWrite(uint16_t idx, uint8_t subidx, T &&value, const ::std::chrono::milliseconds &timeout)
Queues an asynchronous write (SDO download) operation and creates a future which becomes ready once t...
void SubmitWait(const duration &d, F &&f)
Submits a wait operation.
void SubmitRead(uint16_t idx, uint8_t subidx, F &&con)
Equivalent to SubmitRead(uint16_t idx, uint8_t subidx, F&& con, const ::std::chrono::milliseconds& ti...
void Error()
Indicates the occurrence of an error event on the remote node and triggers the error handling process...
void SubmitWait(const time_point &t, F &&f)
Submits a wait operation.
BasicMaster & master
A reference to the master with which this driver is registered.
void Post(F &&f, Args &&... args)
Schedules the specified Callable object for execution by the executor for this driver.
An accessor providing read-only access to TPDO-mapped objects in a remote object dictionary.
A mutator providing read/write access to TPDO-mapped objects in a remote object dictionary.
SdoFuture< void > AsyncWrite(ev_exec_t *exec, uint8_t id, uint16_t idx, uint8_t subidx, T &&value)
Equivalent to AsyncWrite(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx,...
SdoFuture< T > AsyncRead(ev_exec_t *exec, uint8_t id, uint16_t idx, uint8_t subidx)
Equivalent to AsyncRead(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx,...
void Error(uint8_t id)
Indicates the occurrence of an error event on a remote node and triggers the error handling process (...
bool Boot(uint8_t id)
Requests the NMT 'boot slave' process for the specified node.
bool IsReady(uint8_t id) const
Returns true if the remote node is ready (i.e., the NMT 'boot slave' process has successfully complet...
void SubmitRead(uint8_t id, SdoUploadRequest< T > &req)
Equivalent to SubmitRead(uint8_t id, SdoUploadRequest<T>& req, ::std::error_code& ec),...
void SubmitWrite(uint8_t id, SdoDownloadRequest< T > &req)
Equivalent to SubmitWrite(uint8_t id, SdoDownloadRequest<T>& req, ::std::error_code& ec),...
uint8_t netid() const noexcept
Returns the network-ID.
The abstract driver interface for a remote CANopen node.
virtual void OnCommand(NmtCommand cs) noexcept=0
The function invoked when an NMT state change occurs on the master.
virtual void OnSync(uint8_t cnt, const time_point &t) noexcept=0
The function invoked when a SYNC message is sent/received by the master.
virtual uint8_t netid() const noexcept=0
Returns the network-ID.
virtual void OnNodeGuarding(bool occurred) noexcept=0
The function invoked when a node guarding timeout event occurs or is resolved for the remote node.
virtual void OnHeartbeat(bool occurred) noexcept=0
The function invoked when a heartbeat timeout event occurs or is resolved for the remote node.
virtual void OnConfig(::std::function< void(::std::error_code ec)> res) noexcept=0
The function invoked when the 'update configuration' step is reached during the NMT 'boot slave' proc...
virtual void OnCanError(io::CanError error) noexcept=0
The function invoked when an error is detected on the CAN bus.
virtual ev::Executor GetExecutor() const noexcept=0
Returns the executor used to execute event handlers for this driver, including SDO confirmation funct...
virtual void OnTime(const ::std::chrono::system_clock::time_point &abs_time) noexcept=0
The function invoked when a TIME message is received by the master.
virtual void OnDeconfig(::std::function< void(::std::error_code ec)> res) noexcept=0
The function invoked by BasicMaster::AsyncDeconfig() to start the deconfiguration process.
virtual void OnSyncError(uint16_t eec, uint8_t er) noexcept=0
The function invoked when the data length of a received SYNC message does not match.
virtual void OnState(NmtState st) noexcept=0
The function invoked when an NMT state change or boot-up event is detected for the remote node by the...
virtual uint8_t id() const noexcept=0
Returns the node-ID.
virtual void OnCanState(io::CanState new_state, io::CanState old_state) noexcept=0
The function invoked when a CAN bus state change is detected.
virtual void OnEmcy(uint16_t eec, uint8_t er, uint8_t msef[5]) noexcept=0
The function invoked when an EMCY message is received from the remote node.
virtual void OnBoot(NmtState st, char es, const ::std::string &what) noexcept=0
The function invoked when the NMT 'boot slave' process completes for the remote node.
The abstract driver interface for a logical device on a remote CANopen node.
virtual int Number() const noexcept=0
Returns the number of the logical device on the remote node.
A CANopen driver running its own dedicated event loop in a separate thread.
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 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 SubmitWait(const time_point &t, io_tqueue_wait &wait)
Submits a wait operation.
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*.
void post(ev_task &task) noexcept
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.
This header file is part of the C++ CANopen application library; it contains the CANopen master decla...
NmtCommand
The NMT command specifiers.