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;
82 virtual void OnRpdoWrite(uint16_t idx, uint8_t subidx) noexcept = 0;
121 virtual void OnHeartbeat(
bool occurred) 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;
233 virtual void OnSyncError(uint16_t eec, uint8_t er) 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;
261 virtual int Number()
const noexcept = 0;
279 protected ::std::map<uint8_t, LogicalDriverBase*> {
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};
829 #endif // LELY_COAPP_DRIVER_HPP_ 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 OnSync(uint8_t cnt, const time_point &t) noexcept=0
The function invoked when a SYNC message is sent/received by the master.
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
void ConfigHeartbeat(const ::std::chrono::milliseconds &ms)
Configures heartbeat consumption by updating CANopen object 1016 (Consumer heartbeat time)...
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 ...
ev::Executor GetExecutor() const noexcept final
Returns the executor used to execute event handlers for this driver, including SDO confirmation funct...
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.
void SubmitWrite(uint8_t id, SdoDownloadRequest< T > &req)
Equivalent to SubmitWrite(uint8_t id, SdoDownloadRequest<T>& req, ::std::error_code& ec)...
The base class for drivers for remote CANopen nodes.
bool IsReady() const
Returns true if the remote node is ready (i.e., the NMT boot slave process has successfully completed...
void SubmitRead(uint8_t id, SdoUploadRequest< T > &req)
Equivalent to SubmitRead(uint8_t id, SdoUploadRequest<T>& req, ::std::error_code& ec)...
virtual void OnCanState(io::CanState new_state, io::CanState old_state) noexcept=0
The function invoked when a CAN bus state change is detected.
void SubmitWait(const time_point &t, io_tqueue_wait &wait)
Submits a wait operation.
void post(ev_task &task) noexcept
NmtCommand
The NMT command specifiers.
void Post(F &&f, Args &&... args)
Schedules the specified Callable object for execution by the executor for this driver.
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 uint8_t netid() const noexcept=0
Returns the network-ID.
virtual uint8_t id() const noexcept=0
Returns the node-ID.
BasicDriver(BasicMaster &master, uint8_t id)
Creates a new driver for a remote CANopen node and registers it with the master.
The abstract driver interface for a remote CANopen node.
This header file is part of the C++ CANopen application library; it contains the CANopen master decla...
SdoFuture< void > AsyncWait(const time_point &t)
Submits an asynchronous wait operation and creates a future which becomes ready once the wait operati...
CanState
The states of a CAN node, depending on the TX/RX error count.
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...
uint8_t id() const noexcept final
Returns the node-ID.
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.
void Error(uint8_t id)
Indicates the occurrence of an error event on a remote node and triggers the error handling process (...
virtual void OnCommand(NmtCommand cs) noexcept=0
The function invoked when an NMT state change occurs on the master.
SdoFuture< T > AsyncRead(uint16_t idx, uint8_t subidx)
Equivalent to AsyncRead(uint16_t idx, uint8_t subidx, const ::std::chrono::milliseconds& timeout)...
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
Returns the network-ID.
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 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.
CanError
The error flags of a CAN bus, which are not mutually exclusive.
bool Boot(uint8_t id)
Requests the NMT 'boot slave' process for the specified node.
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...
A CANopen driver running its own dedicated event loop in a separate thread.
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, const ::std::chrono::milliseconds& timeout), except that it uses the SDO timeout given by GetTimeout().
A mutator providing read/write access to TPDO-mapped objects in a remote object dictionary.
void SubmitWait(const time_point &t, F &&f)
Submits a wait operation.
void SubmitWait(const duration &d, F &&f)
Submits a wait operation.
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...
The type of objects thrown as exceptions to report a system error with an associated error code...
An accessor providing read-only access to TPDO-mapped objects in a remote object dictionary.
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.
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.
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...
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...
SdoFuture< void > AsyncWait(const duration &d)
Submits an asynchronous wait operation and creates a future which becomes ready once the wait operati...
virtual void OnHeartbeat(bool occurred) noexcept=0
The function invoked when a heartbeat timeout event occurs or is resolved for the remote node...
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, T&& value, const ::std::chrono::milliseconds& timeout), except that it uses the SDO timeout given by GetTimeout().
An abstract task executor. This class is a wrapper around ev_exec_t*.
BasicMaster & master
A reference to the master with which this driver is registered.
bool Boot()
Requests the NMT 'boot slave' process for the remote node.
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& ...
void Error()
Indicates the occurrence of an error event on the remote node and triggers the error handling process...
virtual ev::Executor GetExecutor() const noexcept=0
Returns the executor used to execute event handlers for this driver, including SDO confirmation funct...
uint8_t netid() const noexcept final
Returns the network-ID.
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...
virtual void OnCanError(io::CanError error) noexcept=0
The function invoked when an error is detected on the CAN bus.
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(const ::std::chrono::milliseconds &ms, ::std::error_code &ec)
Configures heartbeat consumption by updating CANopen object 1016 (Consumer heartbeat time)...
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...
virtual void OnDeconfig(::std::function< void(::std::error_code ec)> res) noexcept=0
The function invoked by BasicMaster::AsyncDeconfig() to start the deconfiguration process...
The abstract driver interface for a logical device on a remote CANopen node.
TpdoEventMutex & tpdo_event_mutex
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 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...