22#ifndef LELY_COCPP_MASTER_HPP_
23#define LELY_COCPP_MASTER_HPP_
78 Write(::std::forward<T>(value));
108 return master_->
Read<T>(idx_, subidx_);
124 Read(::std::error_code& ec)
const {
125 return master_->
Read<T>(idx_, subidx_, ec);
141 master_->
Write(idx_, subidx_, ::std::forward<T>(value));
159 Write(T&& value, ::std::error_code& ec) {
160 master_->
Write(idx_, subidx_, ::std::forward<T>(value), ec);
176 Write(
const void* p, ::std::size_t n) {
177 master_->
Write(idx_, subidx_, p, n);
192 Write(
const void* p, ::std::size_t n, ::std::error_code& ec) {
193 master_->
Write(idx_, subidx_, p, n, ec);
198 : master_(master), idx_(idx), subidx_(subidx) {}
240 return master_->
Read<T>(idx_, subidx_);
256 Read(::std::error_code& ec)
const {
257 return master_->
Read<T>(idx_, subidx_, ec);
262 : master_(master), idx_(idx), subidx_(subidx) {}
336 : master_(master), idx_(idx) {}
357 ::std::error_code ec, T value);
372 ::std::error_code ec);
389 BasicMaster(aio::TimerBase& timer, aio::CanBusBase& bus,
390 const ::std::string& dcf_txt, const ::std::string& dcf_bin =
"",
428 void Error(uint8_t
id);
439 void Error(uint16_t eec, uint8_t er,
const uint8_t msef[5] =
nullptr);
464 ::std::chrono::milliseconds
GetTimeout()
const;
472 void SetTimeout(const ::std::chrono::milliseconds& timeout);
482 ::std::error_code ec;
483 SubmitRead<T>(
id, req, ec);
484 if (ec)
throw SdoError(
netid(),
id, req.idx, req.subidx, ec,
"SubmitRead");
498 ::std::lock_guard<BasicLockable>
lock(*
this);
504 sdo->SubmitUpload<T>(req);
516 template <
class T,
class F>
518 SubmitRead(uint8_t
id, uint16_t idx, uint8_t subidx, aio::ExecutorBase& exec,
520 SubmitRead<T>(
id, idx, subidx, exec, ::std::forward<F>(con),
GetTimeout());
529 template <
class T,
class F>
531 SubmitRead(uint8_t
id, uint16_t idx, uint8_t subidx, aio::ExecutorBase& exec,
532 F&& con, ::std::error_code& ec) {
533 SubmitRead<T>(
id, idx, subidx, exec, ::std::forward<F>(con),
GetTimeout(),
543 template <
class T,
class F>
545 SubmitRead(uint8_t
id, uint16_t idx, uint8_t subidx, aio::ExecutorBase& exec,
547 ::std::error_code ec;
548 SubmitRead<T>(
id, idx, subidx, exec, ::std::forward<F>(con), timeout, ec);
549 if (ec)
throw SdoError(
netid(),
id, idx, subidx, ec,
"SubmitRead");
569 template <
class T,
class F>
571 SubmitRead(uint8_t
id, uint16_t idx, uint8_t subidx, aio::ExecutorBase& exec,
572 F&& con,
const Sdo::duration& timeout, ::std::error_code& ec) {
573 ::std::lock_guard<BasicLockable>
lock(*
this);
580 sdo->SubmitUpload<T>(
582 [=](uint16_t idx, uint8_t subidx, ::std::error_code ec, T value) {
583 con(
id, idx, subidx, ec, ::std::move(value));
587 sdo->SubmitUpload<T>(idx, subidx, exec,
nullptr, timeout);
602 ::std::error_code ec;
603 SubmitWrite<T>(
id, req, ec);
604 if (ec)
throw SdoError(
netid(),
id, req.idx, req.subidx, ec,
"SubmitWrite");
618 ::std::lock_guard<BasicLockable>
lock(*
this);
624 sdo->SubmitDownload<T>(req);
636 template <
class T,
class F>
639 aio::ExecutorBase& exec, F&& con) {
640 SubmitWrite(
id, idx, subidx, ::std::forward<T>(value), exec,
651 template <
class T,
class F>
654 aio::ExecutorBase& exec, F&& con, ::std::error_code& ec) {
655 SubmitWrite(
id, idx, subidx, ::std::forward<T>(value), exec,
666 template <
class T,
class F>
669 aio::ExecutorBase& exec, F&& con,
const Sdo::duration& timeout) {
670 ::std::error_code ec;
671 SubmitWrite(
id, idx, subidx, ::std::forward<T>(value), exec,
672 ::std::forward<F>(con), timeout, ec);
673 if (ec)
throw SdoError(
netid(),
id, idx, subidx, ec,
"SubmitWrite");
694 template <
class T,
class F>
697 aio::ExecutorBase& exec, F&& con,
const Sdo::duration& timeout,
698 ::std::error_code& ec) {
699 ::std::lock_guard<BasicLockable>
lock(*
this);
707 idx, subidx, ::std::forward<T>(value), exec,
708 [=](uint16_t idx, uint8_t subidx, ::std::error_code ec) {
709 con(
id, idx, subidx, ec);
713 sdo->SubmitDownload(idx, subidx, ::std::forward<T>(value), exec,
728 aio::Future<::std::tuple<::std::error_code, T>>
729 AsyncRead(aio::LoopBase& loop, aio::ExecutorBase& exec, uint8_t
id,
730 uint16_t idx, uint8_t subidx) {
731 return AsyncRead<T>(loop, exec,
id, idx, subidx,
GetTimeout());
753 aio::Future<::std::tuple<::std::error_code, T>>
754 AsyncRead(aio::LoopBase& loop, aio::ExecutorBase& exec, uint8_t
id,
755 uint16_t idx, uint8_t subidx,
const Sdo::duration& timeout) {
756 ::std::lock_guard<BasicLockable>
lock(*
this);
758 aio::Future<::std::tuple<::std::error_code, T>> future(
nullptr);
762 future = sdo->AsyncUpload<T>(loop, exec, idx, subidx, timeout);
774 aio::Future<::std::error_code>
775 AsyncWrite(aio::LoopBase& loop, aio::ExecutorBase& exec, uint8_t
id,
776 uint16_t idx, uint8_t subidx, T&& value) {
777 return AsyncWrite(loop, exec,
id, idx, subidx, ::std::forward<T>(value),
800 aio::Future<::std::error_code>
801 AsyncWrite(aio::LoopBase& loop, aio::ExecutorBase& exec, uint8_t
id,
802 uint16_t idx, uint8_t subidx, T&& value,
804 ::std::lock_guard<BasicLockable>
lock(*
this);
806 aio::Future<::std::error_code> future(
nullptr);
810 future = sdo->AsyncDownload(loop, exec, idx, subidx,
811 ::std::forward<T>(value), timeout);
835 using MapType = ::std::map<uint8_t, DriverBase*>;
850 void OnCanState(CanState new_state, CanState old_state)
noexcept override;
885 void OnHeartbeat(uint8_t
id,
bool occurred)
noexcept override;
942 const ::std::string& what)
noexcept;
956 virtual void OnConfig(uint8_t
id)
noexcept;
964 void ConfigResult(uint8_t
id, ::std::error_code ec)
noexcept;
971 void OnRpdo(
int num, ::std::error_code ec,
const void* p,
972 ::std::size_t n)
noexcept override;
979 void OnRpdoError(
int num, uint16_t eec, uint8_t er)
noexcept override;
986 void OnTpdo(
int num, ::std::error_code ec,
const void* p,
987 ::std::size_t n)
noexcept override;
994 void OnSync(uint8_t cnt,
const time_point& t)
noexcept override;
1001 void OnSyncError(uint16_t eec, uint8_t er)
noexcept override;
1008 void OnTime(const ::std::chrono::system_clock::time_point&
1009 abs_time)
noexcept override;
1017 void OnEmcy(uint8_t
id, uint16_t eec, uint8_t er,
1018 uint8_t msef[5])
noexcept override;
1036 ::std::unique_ptr<Impl_> impl_;
1063 void OnCanState(CanState new_state, CanState old_state)
noexcept override;
1080 void OnNodeGuarding(uint8_t
id,
bool occurred)
noexcept override;
1088 void OnHeartbeat(uint8_t
id,
bool occurred)
noexcept override;
1106 const ::std::string& what)
noexcept override;
1114 void OnConfig(uint8_t
id)
noexcept override;
1122 void OnRpdo(
int num, ::std::error_code ec,
const void* p,
1123 ::std::size_t n)
noexcept override;
1131 void OnRpdoError(
int num, uint16_t eec, uint8_t er)
noexcept override;
1139 void OnTpdo(
int num, ::std::error_code ec,
const void* p,
1140 ::std::size_t n)
noexcept override;
1148 void OnSync(uint8_t cnt,
const time_point& t)
noexcept override;
1156 void OnSyncError(uint16_t eec, uint8_t er)
noexcept override;
1164 void OnTime(const ::std::chrono::system_clock::time_point&
1165 abs_time)
noexcept override;
1173 void OnEmcy(uint8_t
id, uint16_t eec, uint8_t er,
1174 uint8_t msef[5])
noexcept override;
An asynchronous CANopen master.
void OnRpdo(int num, ::std::error_code ec, const void *p, ::std::size_t n) noexcept override
The default implementation queues a notification for all registered drivers.
void OnEmcy(uint8_t id, uint16_t eec, uint8_t er, uint8_t msef[5]) noexcept override
The default implementation queues a notification for the driver registered for node id.
void OnConfig(uint8_t id) noexcept override
The default implementation queues a notification for the driver registered for node id.
void OnBoot(uint8_t id, NmtState st, char es, const ::std::string &what) noexcept override
The default implementation queues a notification for the driver registered for node id.
void OnTpdo(int num, ::std::error_code ec, const void *p, ::std::size_t n) noexcept override
The default implementation queues a notification for all registered drivers.
void OnNodeGuarding(uint8_t id, bool occurred) noexcept override
The default implementation queues a notification for all registered drivers.
void OnSync(uint8_t cnt, const time_point &t) noexcept override
The default implementation queues a notification for all registered drivers.
void OnRpdoError(int num, uint16_t eec, uint8_t er) noexcept override
The default implementation queues a notification for all registered drivers.
void OnHeartbeat(uint8_t id, bool occurred) noexcept override
The default implementation queues a notification for the driver registered for node id.
void OnSyncError(uint16_t eec, uint8_t er) noexcept override
The default implementation queues a notification for all registered drivers.
void OnCanState(CanState new_state, CanState old_state) noexcept override
The default implementation invokes lely::canopen::Node::OnCanState() and queues a notification for ea...
void OnCommand(NmtCommand cs) noexcept override
The default implementation queues a notification for all registered drivers.
void OnState(uint8_t id, NmtState st) noexcept override
The default implementation queues a notification for the driver registered for node id.
void OnCanError(CanError error) noexcept override
The default implementation queues a notification for all registered drivers.
void OnTime(const ::std::chrono::system_clock::time_point &abs_time) noexcept override
The default implementation queues a notification for all registered drivers.
An accessor providing read-only access to a CANopen object in a local object dictionary.
ConstSubObject operator[](uint8_t subidx) const
Returns an accessor object that provides read-only access to the specified CANopen sub-object in the ...
An accessor providing read-only access to a CANopen sub-object in a local object dictionary.
T Read(::std::error_code &ec) const
Reads the value of the sub-object by submitting an SDO upload request to the local object dictionary.
T Read() const
Reads the value of the sub-object by submitting an SDO upload request to the local object dictionary.
A mutator providing read/write access to a CANopen object in a local object dictionary.
SubObject operator[](uint8_t subidx)
Returns a mutator object that provides read/write access to the specified CANopen sub-object in the l...
ConstSubObject operator[](uint8_t subidx) const
Returns an accessor object that provides read-only access to the specified CANopen sub-object in the ...
A mutator providing read/write access to a CANopen sub-object in a local object dictionary.
SubObject & operator=(T &&value)
Sets the value of the sub-object.
void Write(const void *p, ::std::size_t n, ::std::error_code &ec)
Writes an OCTET_STRING or DOMAIN value to the sub-object by submitting an SDO download request to the...
void Write(T &&value, ::std::error_code &ec)
Writes a value to the sub-object by submitting an SDO download request to the local object dictionary...
void Write(const void *p, ::std::size_t n)
Writes an OCTET_STRING or DOMAIN value to the sub-object by submitting an SDO download request to the...
T Read() const
Reads the value of the sub-object by submitting an SDO upload request to the local object dictionary.
void Write(T &&value)
Writes a value to the sub-object by submitting an SDO download request to the local object dictionary...
T Read(::std::error_code &ec) const
Reads the value of the sub-object by submitting an SDO upload request to the local object dictionary.
void OnSyncError(uint16_t eec, uint8_t er) noexcept override
The default implementation notifies all registered drivers.
void SubmitRead(uint8_t id, uint16_t idx, uint8_t subidx, aio::ExecutorBase &exec, F &&con, const Sdo::duration &timeout)
Equivalent to SubmitRead(uint8_t id, uint16_t idx, uint8_t subidx, aio::ExecutorBase& exec,...
ConstObject operator[](uint16_t idx) const
Returns an accessor object that provides read-only access to the specified CANopen object in the loca...
void(uint8_t id, uint16_t idx, uint8_t subidx, ::std::error_code ec) WriteSignature
The signature of the callback function invoked on completion of an asynchronous write (SDO download) ...
void RpdoRtr(int num=0)
Requests the transmission of a PDO.
void SubmitRead(uint8_t id, Sdo::UploadRequest< T > &req)
Equivalent to SubmitRead(uint8_t id, Sdo::UploadRequest<T>& req, ::std::error_code& ec),...
virtual void OnConfig(uint8_t id) noexcept
The function invoked when the 'update configuration' step is reached during the NMT 'boot slave' proc...
void(uint8_t id, uint16_t idx, uint8_t subidx, ::std::error_code ec, T value) ReadSignature
The signature of the callback function invoked on completion of an asynchronous read (SDO upload) ope...
aio::Future<::std::error_code > AsyncWrite(aio::LoopBase &loop, aio::ExecutorBase &exec, uint8_t id, uint16_t idx, uint8_t subidx, T &&value)
Equivalent to AsyncWrite(aio::LoopBase& loop, aio::ExecutorBase& exec, uint8_t id,...
void OnTime(const ::std::chrono::system_clock::time_point &abs_time) noexcept override
The default implementation notifies all registered drivers.
void OnRpdo(int num, ::std::error_code ec, const void *p, ::std::size_t n) noexcept override
The default implementation notifies all registered drivers.
Object operator[](uint16_t idx)
Returns a mutator object that provides read/write access to the specified CANopen object in the local...
void SubmitRead(uint8_t id, uint16_t idx, uint8_t subidx, aio::ExecutorBase &exec, F &&con, const Sdo::duration &timeout, ::std::error_code &ec)
Queues an asynchronous read (SDO upload) operation.
void SubmitRead(uint8_t id, uint16_t idx, uint8_t subidx, aio::ExecutorBase &exec, F &&con)
Equivalent to SubmitRead(uint8_t id, uint16_t idx, uint8_t subidx, aio::ExecutorBase& exec,...
void SubmitWrite(uint8_t id, Sdo::DownloadRequest< T > &req, ::std::error_code &ec)
Queues an asynchronous write (SDO download) operation.
void OnEmcy(uint8_t id, uint16_t eec, uint8_t er, uint8_t msef[5]) noexcept override
The default implementation notifies the driver registered for node id.
void OnHeartbeat(uint8_t id, bool occurred) noexcept override
The default implementation notifies the driver registered for node id.
void Erase(DriverBase &driver)
Unregisters a driver for a remote CANopen node.
void SubmitRead(uint8_t id, Sdo::UploadRequest< T > &req, ::std::error_code &ec)
Queues an asynchronous read (SDO upload) operation.
void OnSync(uint8_t cnt, const time_point &t) noexcept override
The default implementation notifies all registered drivers.
BasicMaster(aio::TimerBase &timer, aio::CanBusBase &bus, const ::std::string &dcf_txt, const ::std::string &dcf_bin="", uint8_t id=0xff)
Creates a new CANopen master.
void TpdoEvent(int num=0)
Triggers the transmission of an event-driven (asynchronous) PDO.
void Insert(DriverBase &driver)
Registers a driver for a remote CANopen node.
void OnRpdoError(int num, uint16_t eec, uint8_t er) noexcept override
The default implementation notifies all registered drivers.
void Error(uint8_t id)
Indicates the occurrence of an error event on a remote node and triggers the error handling process (...
aio::Future<::std::tuple<::std::error_code, T > > AsyncRead(aio::LoopBase &loop, aio::ExecutorBase &exec, uint8_t id, uint16_t idx, uint8_t subidx, const Sdo::duration &timeout)
Queues an asynchronous read (SDO upload) operation and returns a future.
void OnCanError(CanError error) noexcept override
The default implementation notifies all registered drivers.
void SubmitRead(uint8_t id, uint16_t idx, uint8_t subidx, aio::ExecutorBase &exec, F &&con, ::std::error_code &ec)
Equivalent to SubmitRead(uint8_t id, uint16_t idx, uint8_t subidx, aio::ExecutorBase& exec,...
aio::Future<::std::error_code > AsyncWrite(aio::LoopBase &loop, aio::ExecutorBase &exec, uint8_t id, uint16_t idx, uint8_t subidx, T &&value, const Sdo::duration &timeout)
Queues an asynchronous write (SDO download) operation and returns a future.
::std::chrono::milliseconds GetTimeout() const
Returns the SDO timeout used during the NMT 'boot slave' and 'check configuration' processes.
void OnState(uint8_t id, NmtState st) noexcept override
The default implementation notifies the driver registered for node id.
void OnCommand(NmtCommand cs) noexcept override
The default implementation notifies all registered drivers.
virtual void OnBoot(uint8_t id, NmtState st, char es, const ::std::string &what) noexcept
The function invoked when the NMT 'boot slave' process completes.
void OnTpdo(int num, ::std::error_code ec, const void *p, ::std::size_t n) noexcept override
The default implementation notifies all registered drivers.
void SubmitWrite(uint8_t id, uint16_t idx, uint8_t subidx, T &&value, aio::ExecutorBase &exec, F &&con, const Sdo::duration &timeout, ::std::error_code &ec)
Queues an asynchronous write (SDO download) operation.
void SetTimeout(const ::std::chrono::milliseconds &timeout)
Sets the SDO timeout used during the NMT 'boot slave' and 'check configuration' processes.
void ConfigResult(uint8_t id, ::std::error_code ec) noexcept
Reports the result of the 'update configuration' step to the NMT service.
void CancelSdo(uint8_t id=0)
Aborts any ongoing or pending SDO requests for the specified slave.
void OnCanState(CanState new_state, CanState old_state) noexcept override
The default implementation invokes lely::canopen::Node::OnCanState() and notifies each registered dri...
void SubmitWrite(uint8_t id, uint16_t idx, uint8_t subidx, T &&value, aio::ExecutorBase &exec, F &&con)
Equivalent to SubmitWrite(uint8_t id, uint16_t idx, uint8_t subidx, T&& value, aio::ExecutorBase& exe...
void SubmitWrite(uint8_t id, uint16_t idx, uint8_t subidx, T &&value, aio::ExecutorBase &exec, F &&con, ::std::error_code &ec)
Equivalent to SubmitWrite(uint8_t id, uint16_t idx, uint8_t subidx, T&& value, aio::ExecutorBase& exe...
virtual void OnNodeGuarding(uint8_t id, bool occurred) noexcept
The function invoked when a node guarding timeout event occurs or is resolved.
aio::Future<::std::tuple<::std::error_code, T > > AsyncRead(aio::LoopBase &loop, aio::ExecutorBase &exec, uint8_t id, uint16_t idx, uint8_t subidx)
Equivalent to AsyncRead(aio::LoopBase& loop, aio::ExecutorBase& exec, uint8_t id, uint16_t idx,...
void SubmitWrite(uint8_t id, Sdo::DownloadRequest< T > &req)
Equivalent to SubmitWrite(uint8_t id, Sdo::DownloadRequest<T>& req, ::std::error_code& ec),...
void SubmitWrite(uint8_t id, uint16_t idx, uint8_t subidx, T &&value, aio::ExecutorBase &exec, F &&con, const Sdo::duration &timeout)
Equivalent to SubmitWrite(uint8_t id, uint16_t idx, uint8_t subidx, T&& value, aio::ExecutorBase& exe...
Sdo * GetSdo(uint8_t id)
Returns a pointer to the default client-SDO service for the given node.
uint8_t netid() const noexcept
Returns the network-ID.
typename::std::enable_if< detail::IsCanopenType< T >::value, T >::type Read(uint16_t idx, uint8_t subidx) const
Submits an SDO upload request to the local object dictionary.
typename::std::enable_if< detail::IsCanopenBasic< T >::value >::type Write(uint16_t idx, uint8_t subidx, T value)
Submits an SDO download request to the local object dictionary.
The abstract driver interface for a remote CANopen node.
void SetTime()
Update the CAN network time.
The base class for CANopen nodes.
virtual void lock() final override
Blocks until a lock can be obtained for the current execution agent (thread, process,...
The type of exception thrown when an SDO abort code is received.
::std::chrono::milliseconds duration
The type used to represent an SDO timeout duration.
The type of objects thrown as exceptions to report a system error with an associated error code.
This header file is part of the C++ CANopen application library; it contains the mutual exclusion fac...
@ NO_SDO
Resource not available: SDO connection.
NmtCommand
The NMT command specifiers.
Global namespace for the Lely Industries N.V. libraries.
This header file is part of the C++ CANopen application library; it contains the CANopen node declara...
This header file is part of the C++ CANopen master library; it contains the Client-SDO queue declarat...