Lely core libraries
2.2.5
|
Go to the documentation of this file.
22 #ifndef LELY_COAPP_LOGICAL_DRIVER_HPP_
23 #define LELY_COAPP_LOGICAL_DRIVER_HPP_
34 template <
class = BasicDriver>
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>
486 class BasicLogicalDriver :
public BasicLogicalDriver<BasicDriver> {
488 BasicLogicalDriver(Driver& driver_,
int num = 1, uint32_t dev = 0)
489 : BasicLogicalDriver<BasicDriver>(driver_, num, dev),
driver(driver_) {}
502 #endif // LELY_COAPP_LOGICAL_DRIVER_HPP_
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 OnSyncError(uint16_t, uint8_t) noexcept override
The function invoked when the data length of a received SYNC message does not match.
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...
NmtCommand
The NMT command specifiers.
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...
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...
The base class for drivers for remote CANopen nodes.
TpdoEventMutex & tpdo_event_mutex
void OnNodeGuarding(bool) noexcept override
The function invoked when a node guarding timeout event occurs or is resolved for the remote node.
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 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 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.
void OnDeconfig(::std::function< void(::std::error_code ec)> res) noexcept override
The function invoked by BasicMaster::AsyncDeconfig() to start the deconfiguration process.
The base class for drivers for logical devices on remote CANopen nodes.
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 SubmitWait(const time_point &t, F &&f)
Submits a wait operation.
CanError
The error flags of a CAN bus, which are not mutually exclusive.
BasicDriver & driver
A reference to the driver with which this logical device driver is registered.
CanState
The states of a CAN node, depending on the TX/RX error count.
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 OnSync(uint8_t, const time_point &) noexcept override
The function invoked when a SYNC message is sent/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...
void OnTime(const ::std::chrono::system_clock::time_point &) noexcept override
The function invoked when a TIME message is received by the master.
void Error()
Indicates the occurrence of an error event on the remote node and triggers the error handling process...
void SubmitWait(const duration &d, F &&f)
Submits a wait operation.
uint32_t DeviceType() const noexcept
Returns the device type of the logical device on the remote node.
An abstract task executor. This class is a wrapper around #ev_exec_t*.
void OnCanState(io::CanState, io::CanState) noexcept override
The function invoked when a CAN bus state change is detected.
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 OnCommand(NmtCommand) noexcept override
The function invoked when an NMT state change occurs on the master.
ev::Executor GetExecutor() const noexcept final
Returns the executor used to execute event handlers for this driver, including SDO confirmation funct...
void OnCanError(io::CanError) noexcept override
The function invoked when an error is detected on the CAN bus.
BasicMaster & master
A reference to the master with which driver is registered.
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 ...
An accessor providing read-only access to a CANopen object in a local object dictionary.
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...
Driver & driver
A reference to the driver with which this logical device driver is registered.
SdoFuture< T > AsyncRead(uint16_t idx, uint8_t subidx)
Equivalent to AsyncRead(uint16_t idx, uint8_t subidx, const ::std::chrono::milliseconds& timeout),...
void OnBoot(NmtState, char, const ::std::string &) noexcept override
The function invoked when the NMT 'boot slave' process completes for the remote node.
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...
The abstract driver interface for a logical device on a remote CANopen node.
void OnHeartbeat(bool) noexcept override
The function invoked when a heartbeat timeout event occurs or is resolved 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& ...
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...
uint8_t id() const noexcept final
Returns the node-ID.
SdoFuture< void > AsyncWait(const duration &d)
Submits an asynchronous wait operation and creates a future which becomes ready once the wait operati...
A mutator providing read/write access to a CANopen object in a local object dictionary.
void Post(F &&f, Args &&... args)
Schedules the specified Callable object for execution by the executor for this driver.
int Number() const noexcept final
Returns the number of the logical device on the remote node.
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...