Lely core libraries
2.2.5
|
Go to the documentation of this file.
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;
321 id() const noexcept final {
335 ::std::error_code& ec) {
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_
void OnCommand(NmtCommand cs) noexcept override
The default implementation notifies all registered logical device drivers.
void post(ev_task &task) noexcept
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 OnSyncError(uint16_t eec, uint8_t er) noexcept override
The default implementation notifies all registered logical device drivers.
The abstract driver interface for a remote CANopen node.
SdoFuture< T > AsyncRead(uint16_t idx, uint8_t subidx)
Equivalent to AsyncRead(uint16_t idx, uint8_t subidx, const ::std::chrono::milliseconds& timeout),...
NmtCommand
The NMT command specifiers.
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
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...
BasicMaster & master
A reference to the master with which this driver is registered.
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 OnSyncError(uint16_t eec, uint8_t er) noexcept=0
The function invoked when the data length of a received SYNC message does not match.
The base class for drivers for remote CANopen nodes.
virtual void OnNodeGuarding(bool occurred) noexcept=0
The function invoked when a node guarding timeout event occurs or is resolved for the remote node.
BasicDriver(BasicMaster &master, uint8_t id)
Creates a new driver for a remote CANopen node and registers it with the master.
void OnSync(uint8_t cnt, const time_point &t) noexcept override
The default implementation notifies all registered logical device drivers.
virtual SdoFuture< void > AsyncConfig()=0
Asynchronously updates the logical device type and, on success, queues the DriverBase::OnConfig() met...
void OnEmcy(uint16_t eec, uint8_t er, uint8_t msef[5]) noexcept override
The default implementation notifies all registered logical device drivers.
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...
void OnTime(const ::std::chrono::system_clock::time_point &abs_time) noexcept override
The default implementation notifies all registered logical device drivers.
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& ...
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.
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...
A CANopen driver running its own dedicated event loop in a separate thread.
void OnHeartbeat(bool occurred) noexcept override
The default implementation notifies all registered logical device drivers.
void OnCanError(io::CanError error) noexcept override
The default implementation notifies all registered logical device drivers.
uint8_t netid() const noexcept final
Returns the network-ID.
bool Boot(uint8_t id)
Requests the NMT 'boot slave' process for the specified node.
The type of objects thrown as exceptions to report a system error with an associated error code.
void Error(uint8_t id)
Indicates the occurrence of an error event on a remote node and triggers the error handling process (...
virtual void OnCanState(io::CanState new_state, io::CanState old_state) noexcept=0
The function invoked when a CAN bus state change is detected.
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).
void OnRpdoWrite(uint16_t idx, uint8_t subidx) noexcept override
The default implementation notifies all registered logical device drivers, unless the object index is...
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...
uint8_t netid() const noexcept
Returns the network-ID.
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 uint8_t id() const noexcept=0
Returns the node-ID.
CanError
The error flags of a CAN bus, which are not mutually exclusive.
virtual uint8_t netid() const noexcept=0
Returns the network-ID.
CanState
The states of a CAN node, depending on the TX/RX error count.
A mutator providing read/write access to TPDO-mapped objects in a remote object dictionary.
TpdoEventMutex & tpdo_event_mutex
An accessor providing read-only 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,...
void OnState(NmtState st) noexcept override
The default implementation notifies all registered logical device drivers.
An abstract task executor. This class is a wrapper around #ev_exec_t*.
ev::Executor GetExecutor() const noexcept final
Returns the executor used to execute event handlers for this driver, including SDO confirmation funct...
class BasicMaster::TpdoMapped tpdo_mapped
A mutator providing read/write access to TPDO-mapped objects in the remote object dictionary.
SdoFuture< void > AsyncWait(const duration &d)
Submits an asynchronous wait operation and creates a future which becomes ready once the wait operati...
void OnCanState(io::CanState new_state, io::CanState old_state) noexcept override
The default implementation notifies all registered logical device drivers.
SdoFuture< void > AsyncDeconfig(int num=0)
Invokes LogicalDriverBase::AsyncDeconfig() for the specified logical device driver.
void OnNodeGuarding(bool occurred) noexcept override
The default implementation notifies all registered logical device drivers.
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 ...
virtual ev::Executor GetExecutor() const noexcept=0
Returns the executor used to execute event handlers for this driver, including SDO confirmation funct...
void SubmitWrite(uint8_t id, SdoDownloadRequest< T > &req)
Equivalent to SubmitWrite(uint8_t id, SdoDownloadRequest<T>& req, ::std::error_code& ec),...
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 OnConfig(::std::function< void(::std::error_code ec)> res) noexcept override
The default implementation invokes AsyncConfig() to start the configuration process for all registere...
void Erase(LogicalDriverBase &driver)
Unregisters a logical device driver for the remote node.
class BasicMaster::RpdoMapped rpdo_mapped
An accessor providing read-only access to RPDO-mapped objects in the remote object dictionary.
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 SubmitRead(uint8_t id, SdoUploadRequest< T > &req)
Equivalent to SubmitRead(uint8_t id, SdoUploadRequest<T>& req, ::std::error_code& ec),...
SdoFuture< void > AsyncConfig(int num=0)
Invokes LogicalDriverBase::AsyncConfig() for the specified logical device driver.
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...
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...
void Error()
Indicates the occurrence of an error event on the remote node and triggers the error handling process...
void ConfigHeartbeat(const ::std::chrono::milliseconds &ms, ::std::error_code &ec)
Configures heartbeat consumption by updating CANopen object 1016 (Consumer heartbeat time).
void OnBoot(NmtState st, char es, const ::std::string &what) noexcept override
The default implementation notifies all registered logical device drivers.
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, const ::std::chrono::milliseconds &timeout)
Equivalent to SubmitWrite(uint16_t idx, uint8_t subidx, T&& value, F&& con, const ::std::chrono::mill...
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.
void SubmitWait(const duration &d, F &&f)
Submits a wait operation.
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 OnSync(uint8_t cnt, const time_point &t) noexcept=0
The function invoked when a SYNC message is sent/received by the master.
void SubmitWait(const time_point &t, F &&f)
Submits a wait operation.
uint8_t id() const noexcept final
Returns the node-ID.
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...
virtual SdoFuture< void > AsyncDeconfig()=0
Queues the DriverBase::OnDeconfig() method and creates a future which becomes ready once the deconfig...
void SubmitWait(const time_point &t, io_tqueue_wait &wait)
Submits a wait operation.
void Insert(LogicalDriverBase &driver)
Registers a logical device driver for the remote node.
The abstract driver interface for a logical device on a remote CANopen node.
BasicDriver(ev_exec_t *exec, BasicMaster &master, uint8_t id)
Creates a new driver for a remote CANopen node and registers it with the master.
virtual void OnCanError(io::CanError error) noexcept=0
The function invoked when an error is detected on the CAN bus.
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 OnCommand(NmtCommand cs) noexcept=0
The function invoked when an NMT state change occurs on the master.
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 OnDeconfig(::std::function< void(::std::error_code ec)> res) noexcept override
The default implementation invokes AsyncDeconfig() to start the deconfiguration process for all regis...
void Post(F &&f, Args &&... args)
Schedules the specified Callable object for execution by the executor for this driver.
bool IsReady() const
Returns true if the remote node is ready (i.e., the NMT boot slave process has successfully completed...
virtual void OnHeartbeat(bool occurred) noexcept=0
The function invoked when a heartbeat timeout event occurs or is resolved for the remote node.
virtual int Number() const noexcept=0
Returns the number of the logical device on the remote node.