22 #ifndef LELY_COAPP_LOGICAL_DRIVER_HPP_
23 #define LELY_COAPP_LOGICAL_DRIVER_HPP_
34 template <
class = BasicDriver>
35 class BasicLogicalDriver;
41 using DriverBase::time_point;
42 using duration = BasicMaster::duration;
51 return driver.GetExecutor();
60 id() const noexcept final {
81 return DeviceType() & 0xffff;
117 return driver.SubmitWait(t, ::std::forward<F>(f));
130 return driver.SubmitWait(d, ::std::forward<F>(f));
143 return driver.AsyncWait(t);
156 return driver.AsyncWait(d);
165 template <
class T,
class F>
168 driver.SubmitRead<T>(ObjectIndex(idx), subidx, ::std::forward<F>(con));
177 template <
class T,
class F>
179 SubmitRead(uint16_t idx, uint8_t subidx, F&& con, ::std::error_code& ec) {
180 driver.SubmitRead<T>(ObjectIndex(idx), subidx, ::std::forward<F>(con), ec);
188 template <
class T,
class F>
191 const ::std::chrono::milliseconds& timeout) {
192 driver.SubmitRead<T>(ObjectIndex(idx), subidx, ::std::forward<F>(con),
211 template <
class T,
class F>
214 const ::std::chrono::milliseconds& timeout,
215 ::std::error_code& ec) {
216 driver.SubmitRead<T>(ObjectIndex(idx), subidx, ::std::forward<F>(con),
226 template <
class T,
class F>
229 driver.SubmitWrite(ObjectIndex(idx), subidx, ::std::forward<T>(value),
230 ::std::forward<F>(con));
239 template <
class T,
class F>
242 ::std::error_code& ec) {
243 driver.SubmitWrite(ObjectIndex(idx), subidx, ::std::forward<T>(value),
244 ::std::forward<F>(con), ec);
252 template <
class T,
class F>
255 const ::std::chrono::milliseconds& timeout) {
256 driver.SubmitWrite(ObjectIndex(idx), subidx, ::std::forward<T>(value),
257 ::std::forward<F>(con), timeout);
276 template <
class T,
class F>
279 const ::std::chrono::milliseconds& timeout,
280 ::std::error_code& ec) {
281 driver.SubmitWrite(ObjectIndex(idx), subidx, ::std::forward<T>(value),
282 ::std::forward<F>(con), timeout, ec);
294 return driver.AsyncRead<T>(ObjectIndex(idx), subidx);
314 const ::std::chrono::milliseconds& timeout) {
315 return driver.AsyncRead<T>(ObjectIndex(idx), subidx, timeout);
327 return driver.AsyncWrite(ObjectIndex(idx), subidx,
328 ::std::forward<T>(value));
348 const ::std::chrono::milliseconds& timeout) {
349 return driver.AsyncWrite(ObjectIndex(idx), subidx, ::std::forward<T>(value),
359 template <
class F,
class... Args>
362 GetExecutor().post(::std::forward<F>(f), ::std::forward<Args>(args)...);
379 return self_.driver.rpdo_mapped[self_.ObjectIndex(idx)];
394 return self_.driver.tpdo_mapped[self_.ObjectIndex(idx)];
398 const auto& tpdo_mapped = self_.driver.tpdo_mapped;
399 return tpdo_mapped[self_.ObjectIndex(idx)];
420 OnRpdoWrite(uint16_t , uint8_t ) noexcept
override {}
438 const ::std::string& ) noexcept
override {}
441 OnConfig(::std::function<
void(::std::error_code ec)> res) noexcept
override {
442 res(::std::error_code{});
447 ::std::function<
void(::std::error_code ec)> res) noexcept
override {
448 res(::std::error_code{});
452 OnSync(uint8_t ,
const time_point& ) noexcept
override {}
458 OnTime(const ::std::chrono::system_clock::
459 time_point& ) noexcept
override {}
463 uint8_t [5]) noexcept
override {}
473 return (idx >= 0x6000 && idx <= 0x67ff) ? idx + (num_ - 1) * 0x800 : idx;
485 template <
class Driver>
The base class for drivers for remote CANopen nodes.
The base class for drivers for logical devices on remote CANopen nodes.
void SubmitWait(const duration &d, F &&f)
Submits a wait operation.
uint8_t netid() const noexcept final
Returns the network-ID.
void Error()
Indicates the occurrence of an error event on the remote node and triggers the error handling process...
void OnConfig(::std::function< void(::std::error_code ec)> res) noexcept override
The function invoked when the 'update configuration' step is reached during the NMT 'boot slave' proc...
uint16_t ObjectIndex(uint16_t idx) const noexcept
Converts an object index, if it is part of the standardized profile area, from the first logical devi...
void OnTime(const ::std::chrono::system_clock::time_point &) noexcept override
The function invoked when a TIME message is received by the master.
bool IsReady() const
Returns true if the remote node is ready (i.e., the NMT boot slave process has successfully completed...
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 ...
BasicMaster & master
A reference to the master with which driver is registered.
int Number() const noexcept final
Returns the number of the logical device on the remote node.
uint32_t DeviceType() const noexcept
Returns the device type of the logical device on the remote node.
void OnNodeGuarding(bool) noexcept override
The function invoked when a node guarding timeout event occurs or is resolved 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 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...
void OnSyncError(uint16_t, uint8_t) noexcept override
The function invoked when the data length of a received SYNC message does not match.
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 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 SubmitWait(const time_point &t, F &&f)
Submits a wait operation.
SdoFuture< T > AsyncRead(uint16_t idx, uint8_t subidx)
Equivalent to AsyncRead(uint16_t idx, uint8_t subidx, const ::std::chrono::milliseconds& timeout),...
uint8_t id() const noexcept final
Returns the node-ID.
void OnCanError(io::CanError) noexcept override
The function invoked when an error is detected on the CAN bus.
int Profile() const noexcept
Returns the device profile number of the logical device on the remote node, or 0 if the device does n...
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 OnState(NmtState) noexcept override
The function invoked when an NMT state change or boot-up event is detected for the remote node by the...
void Post(F &&f, Args &&... args)
Schedules the specified Callable object for execution by the executor for this driver.
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 OnBoot(NmtState, char, const ::std::string &) noexcept override
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, ::std::error_code &ec)
Queues an asynchronous write (SDO download) operation.
void OnCanState(io::CanState, io::CanState) noexcept override
The function invoked when a CAN bus state change is detected.
BasicDriver & driver
A reference to the driver with which this logical device driver is registered.
void OnEmcy(uint16_t, uint8_t, uint8_t[5]) noexcept override
The function invoked when an EMCY message is received from the remote node.
void OnCommand(NmtCommand) noexcept override
The function invoked when an NMT state change occurs on the master.
void OnDeconfig(::std::function< void(::std::error_code ec)> res) noexcept override
The function invoked by BasicMaster::AsyncDeconfig() to start the deconfiguration process.
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...
void OnHeartbeat(bool) noexcept override
The function invoked when a heartbeat timeout event occurs or is resolved for the remote node.
SdoFuture< void > AsyncWait(const duration &d)
Submits an asynchronous wait operation and creates a future which becomes ready once the wait operati...
ev::Executor GetExecutor() const noexcept final
Returns the executor used to execute event handlers for this driver, including SDO confirmation funct...
void OnSync(uint8_t, const time_point &) noexcept override
The function invoked when a SYNC message is sent/received by 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.
TpdoEventMutex & tpdo_event_mutex
SdoFuture< void > AsyncWait(const time_point &t)
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)
Equivalent to SubmitRead(uint16_t idx, uint8_t subidx, F&& con, const ::std::chrono::milliseconds& ti...
The base class for drivers for logical devices on remote CANopen nodes.
Driver & driver
A reference to the driver with which this logical device driver is registered.
An accessor providing read-only access to a CANopen object in a local object dictionary.
A mutator providing read/write access to a CANopen object in a local object dictionary.
The abstract driver interface for a logical device on a remote CANopen node.
An abstract task executor. This class is a wrapper around #ev_exec_t*.
This header file is part of the C++ CANopen application library; it contains the remote node driver i...
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.
NmtCommand
The NMT command specifiers.