22#ifndef LELY_COAPP_DRIVER_HPP_
23#define LELY_COAPP_DRIVER_HPP_
38 using time_point = BasicMaster::time_point;
40 DriverBase() =
default;
42 DriverBase(
const DriverBase&) =
delete;
43 DriverBase& operator=(
const DriverBase&) =
delete;
45 virtual ~DriverBase() =
default;
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;
130 virtual
void OnSync(uint8_t cnt, const time_point& t) noexcept = 0;
151 const ::
std::chrono::system_clock::time_point& abs_time) noexcept = 0;
162 virtual
void OnEmcy(uint16_t eec, uint8_t er, uint8_t msef[5]) noexcept = 0;
220 const ::
std::
string& what) noexcept = 0;
238 ::
std::function<
void(::
std::error_code ec)> res) noexcept = 0;
254 ::
std::function<
void(::
std::error_code ec)> res) noexcept = 0;
280 friend class LoopDriver;
283 using DriverBase::time_point;
284 using duration = BasicMaster::duration;
321 id() const noexcept final {
335 ::std::error_code& ec) {
336 master.ConfigHeartbeat(
id(), ms, ec);
350 master.ConfigHeartbeat(
id(), ms);
375 return master.IsReady(
id());
403 master.DamMpdoEvent(num,
id(), idx, subidx, value);
464 template <
class T,
class F>
468 ::std::forward<F>(con));
477 template <
class T,
class F>
479 SubmitRead(uint16_t idx, uint8_t subidx, F&& con, ::std::error_code& ec) {
481 ::std::forward<F>(con), ec);
489 template <
class T,
class F>
492 const ::std::chrono::milliseconds& timeout) {
494 ::std::forward<F>(con), timeout);
512 template <
class T,
class F>
515 const ::std::chrono::milliseconds& timeout,
516 ::std::error_code& ec) {
518 ::std::forward<F>(con), timeout, ec);
527 template <
class T,
class F>
531 ::std::forward<F>(con));
540 template <
class T,
class F>
543 ::std::error_code& ec) {
545 ::std::forward<F>(con), ec);
553 template <
class T,
class F>
556 const ::std::chrono::milliseconds& timeout) {
558 ::std::forward<F>(con), timeout);
580 template <
class T,
class F>
583 const ::std::chrono::milliseconds& timeout,
584 ::std::error_code& ec) {
586 ::std::forward<F>(con), timeout, ec);
595 template <
class T,
class F>
599 ::std::forward<T>(value), ::std::forward<F>(con));
608 template <
class T,
class F>
611 ::std::error_code& ec) {
613 ::std::forward<T>(value), ::std::forward<F>(con), ec);
621 template <
class T,
class F>
624 const ::std::chrono::milliseconds& timeout) {
626 ::std::forward<T>(value), ::std::forward<F>(con),
646 template <
class T,
class F>
649 const ::std::chrono::milliseconds& timeout,
650 ::std::error_code& ec) {
652 ::std::forward<T>(value), ::std::forward<F>(con),
662 template <
class T,
class F>
666 ::std::forward<T>(value), ::std::forward<F>(con));
675 template <
class T,
class F>
678 ::std::error_code& ec) {
680 ::std::forward<T>(value), ::std::forward<F>(con),
689 template <
class T,
class F>
692 const ::std::chrono::milliseconds& timeout) {
694 ::std::forward<T>(value), ::std::forward<F>(con),
718 template <
class T,
class F>
721 const ::std::chrono::milliseconds& timeout,
722 ::std::error_code& ec) {
724 ::std::forward<T>(value), ::std::forward<F>(con),
738 ::std::forward<F>(con));
750 ::std::error_code& ec) {
752 ::std::forward<F>(con), ec);
763 const ::std::chrono::milliseconds& timeout) {
765 ::std::forward<F>(con), timeout);
790 const ::std::chrono::milliseconds& timeout,
791 ::std::error_code& ec) {
793 ::std::forward<F>(con), timeout, ec);
829 const ::std::chrono::milliseconds& timeout) {
853 const ::std::chrono::milliseconds& timeout,
854 ::std::error_code& ec) {
888 const ::std::chrono::milliseconds& timeout) {
925 const ::std::chrono::milliseconds& timeout) {
939 ::std::forward<T>(value));
959 const ::std::chrono::milliseconds& timeout) {
961 ::std::forward<T>(value), timeout);
974 ::std::forward<T>(value));
998 const ::std::chrono::milliseconds& timeout) {
1000 ::std::forward<T>(value), timeout);
1032 const ::std::chrono::milliseconds& timeout) {
1090 template <
class F,
class... Args>
1093 GetExecutor().
post(::std::forward<F>(f), ::std::forward<Args>(args)...);
1119 using MapType = ::std::map<uint8_t, LogicalDriverBase*>;
1145 void OnRpdoWrite(uint16_t idx, uint8_t subidx)
noexcept override;
1159 void OnHeartbeat(
bool occurred)
noexcept override;
1173 void OnSync(uint8_t cnt,
const time_point& t)
noexcept override;
1180 void OnSyncError(uint16_t eec, uint8_t er)
noexcept override;
1187 void OnTime(const ::std::chrono::system_clock::time_point& abs_time)
noexcept
1195 void OnEmcy(uint16_t eec, uint8_t er, uint8_t msef[5])
noexcept override;
1210 const ::std::string& what)
noexcept override;
1219 ::std::function<
void(::std::error_code ec)> res)
noexcept override;
1228 ::std::function<
void(::std::error_code ec)> res)
noexcept override;
1248 const uint8_t id_{0xff};
The base class for drivers for remote CANopen nodes.
SdoFuture< void > AsyncWriteDcf(const uint8_t *begin, const uint8_t *end)
Equivalent to AsyncWriteDcf(const uint8_t* begin, const uint8_t* end, const ::std::chrono::millisecon...
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 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...
class BasicMaster::RpdoMapped rpdo_mapped
An accessor providing read-only access to RPDO-mapped objects in the remote object dictionary.
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.
void ConfigHeartbeat(const ::std::chrono::milliseconds &ms)
Configures heartbeat consumption by updating CANopen object 1016 (Consumer heartbeat time).
void SubmitBlockWrite(uint16_t idx, uint8_t subidx, T &&value, F &&con, const ::std::chrono::milliseconds &timeout, ::std::error_code &ec)
Queues an asynchronous write (SDO block download) operation.
SdoFuture< void > AsyncDeconfig(int num=0)
Invokes LogicalDriverBase::AsyncDeconfig() for the specified logical device driver.
SdoFuture< void > AsyncWriteDcf(const char *path)
Equivalent to AsyncWriteDcf(const char* path, const ::std::chrono::milliseconds& timeout),...
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 > AsyncWait(const duration &d)
Submits an asynchronous wait operation and creates a future which becomes ready once the wait operati...
SdoFuture< void > AsyncWait(const time_point &t)
Submits an asynchronous wait operation and creates a future which becomes ready once the wait operati...
void SubmitBlockWrite(uint16_t idx, uint8_t subidx, T &&value, F &&con)
Equivalent to SubmitBlockWrite(uint16_t idx, uint8_t subidx, T&& value, F&& con, const ::std::chrono:...
bool IsReady() const
Returns true if the remote node is ready (i.e., the NMT boot slave process has successfully completed...
void SubmitBlockRead(uint16_t idx, uint8_t subidx, F &&con, const ::std::chrono::milliseconds &timeout)
Equivalent to SubmitBlockRead(uint16_t idx, uint8_t subidx, F&& con, const ::std::chrono::millisecond...
SdoFuture< void > AsyncWriteDcf(const char *path, const ::std::chrono::milliseconds &timeout)
Queues a series of asynchronous write (SDO download) operations, corresponding to the entries in the ...
SdoFuture< void > AsyncConfig(int num=0)
Invokes LogicalDriverBase::AsyncConfig() for the specified logical device driver.
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...
SdoFuture< void > AsyncBlockWrite(uint16_t idx, uint8_t subidx, T &&value)
Equivalent to AsyncBlockWrite(uint16_t idx, uint8_t subidx, T&& value, const ::std::chrono::milliseco...
void SubmitWriteDcf(const uint8_t *begin, const uint8_t *end, F &&con, ::std::error_code &ec)
Equivalent to SubmitWriteDcf(const uint8_t* begin, const uint8_t* end, F&& con, const ::std::chrono::...
void DamMpdoEvent(int num, uint16_t idx, uint8_t subidx, T value)
Triggers the transmission of a destination address mode multiplex PDO (DAM-MPDO).
TpdoEventMutex & tpdo_event_mutex
void SubmitWriteDcf(const char *path, F &&con)
Equivalent to SubmitWriteDcf(const char* path, F&& con, const ::std::chrono::milliseconds& timeout),...
SdoFuture< T > AsyncBlockRead(uint16_t idx, uint8_t subidx)
Equivalent to AsyncBlockRead(uint16_t idx, uint8_t subidx, const ::std::chrono::milliseconds& timeout...
ev::Executor GetExecutor() const noexcept final
Returns the executor used to execute event handlers for this driver, including SDO confirmation funct...
void SubmitWriteDcf(const uint8_t *begin, const uint8_t *end, F &&con)
Equivalent to SubmitWriteDcf(const uint8_t* begin, const uint8_t* end, F&& con, const ::std::chrono::...
BasicDriver(BasicMaster &master, uint8_t id)
Creates a new driver for a remote CANopen node and registers it with the master.
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 ...
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.
uint8_t id() const noexcept final
Returns the node-ID.
void SubmitBlockWrite(uint16_t idx, uint8_t subidx, T &&value, F &&con, const ::std::chrono::milliseconds &timeout)
Equivalent to SubmitBlockWrite(uint16_t idx, uint8_t subidx, T&& value, F&& con, const ::std::chrono:...
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...
SdoFuture< T > AsyncBlockRead(uint16_t idx, uint8_t subidx, const ::std::chrono::milliseconds &timeout)
Queues an asynchronous read (SDO block upload) operation and creates a future which becomes ready onc...
bool Boot()
Requests the NMT 'boot slave' process for the remote 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.
void SubmitBlockRead(uint16_t idx, uint8_t subidx, F &&con, const ::std::chrono::milliseconds &timeout, ::std::error_code &ec)
Queues an asynchronous read (SDO block upload) operation.
void SubmitBlockWrite(uint16_t idx, uint8_t subidx, T &&value, F &&con, ::std::error_code &ec)
Equivalent to SubmitBlockWrite(uint16_t idx, uint8_t subidx, T&& value, F&& con, const ::std::chrono:...
void SubmitWait(const duration &d, F &&f)
Submits a wait operation.
void SubmitWriteDcf(const char *path, F &&con, const ::std::chrono::milliseconds &timeout, ::std::error_code &ec)
Queues a series of asynchronous write (SDO download) operations.
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...
SdoFuture< void > AsyncWriteDcf(const uint8_t *begin, const uint8_t *end, const ::std::chrono::milliseconds &timeout)
Queues a series of asynchronous write (SDO download) operations, corresponding to the entries in the ...
void SubmitWriteDcf(const uint8_t *begin, const uint8_t *end, F &&con, const ::std::chrono::milliseconds &timeout)
Equivalent to SubmitWriteDcf(const uint8_t* begin, const uint8_t* end, F&& con, const ::std::chrono::...
class BasicMaster::TpdoMapped tpdo_mapped
A mutator providing read/write access to TPDO-mapped objects in the remote object dictionary.
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 Error()
Indicates the occurrence of an error event on the remote node and triggers the error handling process...
void SubmitWriteDcf(const uint8_t *begin, const uint8_t *end, F &&con, const ::std::chrono::milliseconds &timeout, ::std::error_code &ec)
Queues a series of asynchronous write (SDO download) operations.
void SubmitWriteDcf(const char *path, F &&con, const ::std::chrono::milliseconds &timeout)
Equivalent to SubmitWriteDcf(const char* path, F&& con, const ::std::chrono::milliseconds& timeout,...
SdoFuture< void > AsyncBlockWrite(uint16_t idx, uint8_t subidx, T &&value, const ::std::chrono::milliseconds &timeout)
Queues an asynchronous write (SDO block download) operation and creates a future which becomes ready ...
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 SubmitWriteDcf(const char *path, F &&con, ::std::error_code &ec)
Equivalent to SubmitWriteDcf(const char* path, F&& con, const ::std::chrono::milliseconds& timeout,...
void SubmitWait(const time_point &t, F &&f)
Submits a wait operation.
void SubmitBlockRead(uint16_t idx, uint8_t subidx, F &&con, ::std::error_code &ec)
Equivalent to SubmitBlockRead(uint16_t idx, uint8_t subidx, F&& con, const ::std::chrono::millisecond...
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.
void SubmitBlockRead(uint16_t idx, uint8_t subidx, F &&con)
Equivalent to SubmitBlockRead(uint16_t idx, uint8_t subidx, F&& con, const ::std::chrono::millisecond...
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.
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 SdoFuture< void > AsyncConfig()=0
Asynchronously updates the logical device type and, on success, queues the DriverBase::OnConfig() met...
virtual int Number() const noexcept=0
Returns the number of the logical device on the remote node.
virtual SdoFuture< void > AsyncDeconfig()=0
Queues the DriverBase::OnDeconfig() method and creates a future which becomes ready once the deconfig...
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...
The namespace for the C++ CANopen application library.
NmtCommand
The NMT command specifiers.
ev::Future< T, ::std::exception_ptr > SdoFuture
A helper alias template for the type of future used to retrieve the result of an asynchronous SDO req...