Lely core libraries  2.2.5
master.hpp
Go to the documentation of this file.
1 
22 #ifndef LELY_COCPP_MASTER_HPP_
23 #define LELY_COCPP_MASTER_HPP_
24 
25 #include <lely/coapp/node.hpp>
26 #include <lely/coapp/sdo.hpp>
27 
28 #include <map>
29 #include <memory>
30 #include <string>
31 #include <utility>
32 
33 #include <cstddef>
34 
35 namespace lely {
36 
37 namespace canopen {
38 
39 class DriverBase;
40 
50 class BasicMaster : public Node, protected ::std::map<uint8_t, DriverBase*> {
51  public:
52  class Object;
53  class ConstObject;
54 
59  class SubObject {
60  friend class Object;
61 
62  public:
63  SubObject(const SubObject&) = default;
64  SubObject(SubObject&&) = default;
65 
66  SubObject& operator=(const SubObject&) = default;
67  SubObject& operator=(SubObject&&) = default;
68 
79  template <class T>
80  SubObject&
81  operator=(T&& value) {
82  Write(::std::forward<T>(value));
83  return *this;
84  }
85 
94  template <class T>
95  operator T() const {
96  return Read<T>();
97  }
98 
110  template <class T>
111  T
112  Read() const {
113  return id_ ? master_->TpdoRead<T>(id_, idx_, subidx_)
114  : master_->Read<T>(idx_, subidx_);
115  }
116 
128  template <class T>
129  T
130  Read(::std::error_code& ec) const {
131  return id_ ? master_->TpdoRead<T>(id_, idx_, subidx_, ec)
132  : master_->Read<T>(idx_, subidx_, ec);
133  }
134 
146  template <class T>
147  void
148  Write(T&& value) {
149  if (id_)
150  master_->TpdoWrite(id_, idx_, subidx_, ::std::forward<T>(value));
151  else
152  master_->Write(idx_, subidx_, ::std::forward<T>(value));
153  }
154 
168  template <class T>
169  void
170  Write(T&& value, ::std::error_code& ec) {
171  if (id_)
172  master_->TpdoWrite(id_, idx_, subidx_, ::std::forward<T>(value), ec);
173  else
174  master_->Write(idx_, subidx_, ::std::forward<T>(value), ec);
175  }
176 
188  void
189  Write(const void* p, ::std::size_t n) {
190  if (!id_) master_->Write(idx_, subidx_, p, n);
191  }
192 
203  void
204  Write(const void* p, ::std::size_t n, ::std::error_code& ec) {
205  if (!id_) master_->Write(idx_, subidx_, p, n, ec);
206  }
207 
218  void
220  if (id_)
221  master_->TpdoWriteEvent(id_, idx_, subidx_);
222  else
223  master_->WriteEvent(idx_, subidx_);
224  }
225 
236  void
237  WriteEvent(::std::error_code& ec) noexcept {
238  if (id_)
239  master_->TpdoWriteEvent(id_, idx_, subidx_, ec);
240  else
241  master_->WriteEvent(idx_, subidx_, ec);
242  }
243 
244  private:
245  SubObject(BasicMaster* master, uint16_t idx, uint8_t subidx) noexcept
246  : SubObject(master, 0, idx, subidx) {}
247 
248  SubObject(BasicMaster* master, uint8_t id, uint16_t idx,
249  uint8_t subidx) noexcept
250  : master_(master), idx_(idx), subidx_(subidx), id_(id) {}
251 
252  BasicMaster* master_;
253  uint16_t idx_;
254  uint8_t subidx_;
255  uint8_t id_;
256  };
257 
263  friend class Object;
264  friend class ConstObject;
265 
266  public:
275  template <class T>
276  operator T() const {
277  return Read<T>();
278  }
279 
292  template <class T>
293  T
294  Read() const {
295  return id_ ? (is_rpdo_ ? master_->RpdoRead<T>(id_, idx_, subidx_)
296  : master_->TpdoRead<T>(id_, idx_, subidx_))
297  : master_->Read<T>(idx_, subidx_);
298  }
299 
312  template <class T>
313  T
314  Read(::std::error_code& ec) const {
315  return id_ ? (is_rpdo_ ? master_->RpdoRead<T>(id_, idx_, subidx_, ec)
316  : master_->TpdoRead<T>(id_, idx_, subidx_, ec))
317  : master_->Read<T>(idx_, subidx_, ec);
318  }
319 
320  private:
321  ConstSubObject(const BasicMaster* master, uint16_t idx,
322  uint8_t subidx) noexcept
323  : ConstSubObject(master, 0, idx, subidx, false) {}
324 
325  ConstSubObject(const BasicMaster* master, uint8_t id, uint16_t idx,
326  uint8_t subidx, bool is_rpdo) noexcept
327  : master_(master),
328  idx_(idx),
329  subidx_(subidx),
330  id_(id),
331  is_rpdo_(is_rpdo) {}
332 
333  const BasicMaster* master_;
334  uint16_t idx_;
335  uint8_t subidx_;
336  uint8_t id_ : 7;
337  uint8_t is_rpdo_ : 1;
338  };
339 
340  class RpdoMapped;
341  class TpdoMapped;
342 
347  class Object {
348  friend class TpdoMapped;
349  friend class BasicMaster;
350 
351  public:
363  SubObject operator[](uint8_t subidx) noexcept {
364  return SubObject(master_, id_, idx_, subidx);
365  }
366 
378  ConstSubObject operator[](uint8_t subidx) const noexcept {
379  return ConstSubObject(master_, id_, idx_, subidx, false);
380  }
381 
382  private:
383  Object(BasicMaster* master, uint16_t idx) noexcept
384  : Object(master, 0, idx) {}
385 
386  Object(BasicMaster* master, uint8_t id, uint16_t idx) noexcept
387  : master_(master), idx_(idx), id_(id) {}
388 
389  BasicMaster* master_;
390  uint16_t idx_;
391  uint8_t id_;
392  };
393 
398  class ConstObject {
399  friend class RpdoMapped;
400  friend class TpdoMapped;
401  friend class BasicMaster;
402 
403  public:
415  ConstSubObject operator[](uint8_t subidx) const noexcept {
416  return ConstSubObject(master_, id_, idx_, subidx, is_rpdo_);
417  }
418 
419  private:
420  ConstObject(const BasicMaster* master, uint16_t idx) noexcept
421  : ConstObject(master, 0, idx, false) {}
422 
423  ConstObject(const BasicMaster* master, uint8_t id, uint16_t idx,
424  bool is_rpdo) noexcept
425  : master_(master), idx_(idx), id_(id), is_rpdo_(is_rpdo) {}
426 
427  const BasicMaster* master_;
428  uint16_t idx_;
429  uint8_t id_ : 7;
430  uint8_t is_rpdo_ : 1;
431  };
432 
437  class RpdoMapped {
438  friend class BasicMaster;
439 
440  public:
451  ConstObject operator[](uint16_t idx) const noexcept {
452  return ConstObject(master_, id_, idx, true);
453  }
454 
455  private:
456  RpdoMapped(const BasicMaster* master, uint8_t id) noexcept
457  : master_(master), id_(id) {}
458 
459  const BasicMaster* master_;
460  uint8_t id_;
461  };
462 
467  class TpdoMapped {
468  friend class BasicMaster;
469 
470  public:
481  Object operator[](uint16_t idx) noexcept {
482  return Object(master_, id_, idx);
483  }
484 
495  ConstObject operator[](uint16_t idx) const noexcept {
496  return ConstObject(master_, id_, idx, false);
497  }
498 
499  private:
500  TpdoMapped(BasicMaster* master, uint8_t id) noexcept
501  : master_(master), id_(id) {}
502 
503  BasicMaster* master_;
504  uint8_t id_;
505  };
506 
509  friend class BasicMaster;
510 
511  public:
512  void lock() override;
513  void unlock() override;
514 
515  protected:
516  using Node::TpdoEventMutex::TpdoEventMutex;
517  };
518 
532  template <class T>
533  using ReadSignature = void(uint8_t id, uint16_t idx, uint8_t subidx,
534  ::std::error_code ec, T value);
535 
548  using WriteSignature = void(uint8_t id, uint16_t idx, uint8_t subidx,
549  ::std::error_code ec);
550 
571  explicit BasicMaster(ev_exec_t* exec, io::TimerBase& timer,
572  io::CanChannelBase& chan, const ::std::string& dcf_txt,
573  const ::std::string& dcf_bin = "", uint8_t id = 0xff);
574 
577  const ::std::string& dcf_txt,
578  const ::std::string& dcf_bin = "", uint8_t id = 0xff)
579  : BasicMaster(nullptr, timer, chan, dcf_txt, dcf_bin, id) {}
580 
581  virtual ~BasicMaster();
582 
593  Object operator[](::std::ptrdiff_t idx) noexcept { return Object(this, idx); }
594 
605  ConstObject operator[](::std::ptrdiff_t idx) const noexcept {
606  return ConstObject(this, idx);
607  }
608 
619  RpdoMapped RpdoMapped(uint8_t id) const noexcept { return {this, id}; }
620 
631  TpdoMapped TpdoMapped(uint8_t id) noexcept { return {this, id}; }
632 
637  bool Boot(uint8_t id);
638 
650  bool IsReady(uint8_t id) const;
651 
661  ev::Future<void> AsyncDeconfig(uint8_t id);
662 
673 
683  void Error(uint8_t id);
684 
685  /*
686  * Generates an EMCY error and triggers the error handling behavior according
687  * to object 1029:01 (Error behavior object) in case of a communication error
688  * (emergency error code 0x81xx).
689  *
690  * @param eec the emergency error code.
691  * @param er the error register.
692  * @param msef the manufacturer-specific error code.
693  */
694  void Error(uint16_t eec, uint8_t er,
695  const uint8_t msef[5] = nullptr) noexcept;
696 
703  void Command(NmtCommand cs, uint8_t id = 0);
704 
706  void RpdoRtr(int num = 0) noexcept;
707 
709  void TpdoEvent(int num = 0) noexcept;
710 
717  ::std::chrono::milliseconds GetTimeout() const;
718 
725  void SetTimeout(const ::std::chrono::milliseconds& timeout);
726 
732  template <class T>
733  void
734  SubmitRead(uint8_t id, SdoUploadRequest<T>& req) {
735  ::std::error_code ec;
736  SubmitRead(id, req, ec);
737  if (ec) throw SdoError(id, req.idx, req.subidx, ec, "SubmitRead");
738  }
739 
748  template <class T>
749  void
750  SubmitRead(uint8_t id, SdoUploadRequest<T>& req, ::std::error_code& ec) {
751  ::std::lock_guard<BasicLockable> lock(*this);
752 
753  ec.clear();
754  auto sdo = GetSdo(id);
755  if (sdo) {
756  SetTime();
757  sdo->SubmitUpload(req);
758  } else {
759  ec = SdoErrc::NO_SDO;
760  }
761  }
762 
768  template <class T, class F>
769  void
770  SubmitRead(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx,
771  F&& con) {
772  SubmitRead<T>(exec, id, idx, subidx, ::std::forward<F>(con), GetTimeout());
773  }
774 
780  template <class T, class F>
781  void
782  SubmitRead(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx, F&& con,
783  ::std::error_code& ec) {
784  SubmitRead<T>(exec, id, idx, subidx, ::std::forward<F>(con), GetTimeout(),
785  ec);
786  }
787 
793  template <class T, class F>
794  void
795  SubmitRead(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx, F&& con,
796  const ::std::chrono::milliseconds& timeout) {
797  ::std::error_code ec;
798  SubmitRead<T>(exec, id, idx, subidx, ::std::forward<F>(con), timeout, ec);
799  if (ec) throw SdoError(id, idx, subidx, ec, "SubmitRead");
800  }
801 
819  template <class T, class F>
820  void
821  SubmitRead(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx, F&& con,
822  const ::std::chrono::milliseconds& timeout,
823  ::std::error_code& ec) {
824  ::std::lock_guard<BasicLockable> lock(*this);
825 
826  ec.clear();
827  auto sdo = GetSdo(id);
828  if (sdo) {
829  SetTime();
830  sdo->SubmitUpload<T>(exec, idx, subidx, ::std::forward<F>(con), timeout);
831  } else {
832  ec = SdoErrc::NO_SDO;
833  }
834  }
835 
841  template <class T>
842  void
843  SubmitWrite(uint8_t id, SdoDownloadRequest<T>& req) {
844  ::std::error_code ec;
845  SubmitWrite(id, req, ec);
846  if (ec) throw SdoError(id, req.idx, req.subidx, ec, "SubmitWrite");
847  }
848 
857  template <class T>
858  void
859  SubmitWrite(uint8_t id, SdoDownloadRequest<T>& req, ::std::error_code& ec) {
860  ::std::lock_guard<BasicLockable> lock(*this);
861 
862  ec.clear();
863  auto sdo = GetSdo(id);
864  if (sdo) {
865  SetTime();
866  sdo->SubmitDownload(req);
867  } else {
868  ec = SdoErrc::NO_SDO;
869  }
870  }
871 
877  template <class T, class F>
878  void
879  SubmitWrite(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx,
880  T&& value, F&& con) {
881  SubmitWrite(exec, id, idx, subidx, ::std::forward<T>(value),
882  ::std::forward<F>(con), GetTimeout());
883  }
884 
890  template <class T, class F>
891  void
892  SubmitWrite(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx,
893  T&& value, F&& con, ::std::error_code& ec) {
894  SubmitWrite(exec, id, idx, subidx, ::std::forward<T>(value),
895  ::std::forward<F>(con), GetTimeout(), ec);
896  }
897 
903  template <class T, class F>
904  void
905  SubmitWrite(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx,
906  T&& value, F&& con, const ::std::chrono::milliseconds& timeout) {
907  ::std::error_code ec;
908  SubmitWrite(exec, id, idx, subidx, ::std::forward<T>(value),
909  ::std::forward<F>(con), timeout, ec);
910  if (ec) throw SdoError(id, idx, subidx, ec, "SubmitWrite");
911  }
912 
931  template <class T, class F>
932  void
933  SubmitWrite(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx,
934  T&& value, F&& con, const ::std::chrono::milliseconds& timeout,
935  ::std::error_code& ec) {
936  ::std::lock_guard<BasicLockable> lock(*this);
937 
938  ec.clear();
939  auto sdo = GetSdo(id);
940  if (sdo) {
941  SetTime();
942  sdo->SubmitDownload(exec, idx, subidx, ::std::forward<T>(value),
943  ::std::forward<F>(con), timeout);
944  } else {
945  ec = SdoErrc::NO_SDO;
946  }
947  }
948 
954  template <class T>
956  AsyncRead(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx) {
957  return AsyncRead<T>(exec, id, idx, subidx, GetTimeout());
958  }
959 
976  template <class T>
978  AsyncRead(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx,
979  const ::std::chrono::milliseconds& timeout) {
980  if (!exec) exec = GetExecutor();
981 
982  ::std::lock_guard<BasicLockable> lock(*this);
983 
984  auto sdo = GetSdo(id);
985  if (sdo) {
986  SetTime();
987  return sdo->AsyncUpload<T>(exec, idx, subidx, timeout);
988  } else {
989  return make_error_sdo_future<T>(id, idx, subidx, SdoErrc::NO_SDO,
990  "AsyncRead");
991  }
992  }
993 
999  template <class T>
1001  AsyncWrite(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx,
1002  T&& value) {
1003  return AsyncWrite(exec, id, idx, subidx, ::std::forward<T>(value),
1004  GetTimeout());
1005  }
1006 
1023  template <class T>
1025  AsyncWrite(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx,
1026  T&& value, const ::std::chrono::milliseconds& timeout) {
1027  if (!exec) exec = GetExecutor();
1028 
1029  ::std::lock_guard<BasicLockable> lock(*this);
1030 
1031  auto sdo = GetSdo(id);
1032  if (sdo) {
1033  SetTime();
1034  return sdo->AsyncDownload<T>(exec, idx, subidx, ::std::forward<T>(value),
1035  timeout);
1036  } else {
1037  return make_error_sdo_future<void>(id, idx, subidx, SdoErrc::NO_SDO,
1038  "AsyncWrite");
1039  }
1040  }
1041 
1051  void Insert(DriverBase& driver);
1052 
1058  void Erase(DriverBase& driver);
1059 
1066  void OnNodeGuarding(::std::function<void(uint8_t, bool)> on_node_guarding);
1067 
1074  void OnBoot(
1075  ::std::function<void(uint8_t, NmtState, char, const ::std::string&)>
1076  on_boot);
1077 
1080 
1081  protected:
1082  using MapType = ::std::map<uint8_t, DriverBase*>;
1083 
1089  void IsReady(uint8_t id, bool ready) noexcept;
1090 
1096  void OnCanError(io::CanError error) noexcept override;
1097 
1104  void OnCanState(io::CanState new_state,
1105  io::CanState old_state) noexcept override;
1106 
1113  void OnRpdoWrite(uint8_t id, uint16_t idx, uint8_t subidx) noexcept override;
1114 
1122  void OnCommand(NmtCommand cs) noexcept override;
1123 
1140  virtual void OnNodeGuarding(uint8_t id, bool occurred) noexcept;
1141 
1148  void OnHeartbeat(uint8_t id, bool occurred) noexcept override;
1149 
1159  void OnState(uint8_t id, NmtState st) noexcept override;
1160 
1204  virtual void OnBoot(uint8_t id, NmtState st, char es,
1205  const ::std::string& what) noexcept;
1206 
1219  virtual void OnConfig(uint8_t id) noexcept;
1220 
1227  void ConfigResult(uint8_t id, ::std::error_code ec) noexcept;
1228 
1234  void OnSync(uint8_t cnt, const time_point& t) noexcept override;
1235 
1241  void OnSyncError(uint16_t eec, uint8_t er) noexcept override;
1242 
1248  void OnTime(const ::std::chrono::system_clock::time_point&
1249  abs_time) noexcept override;
1250 
1257  void OnEmcy(uint8_t id, uint16_t eec, uint8_t er,
1258  uint8_t msef[5]) noexcept override;
1259 
1270  bool IsConfig(uint8_t id) const;
1271 
1277  Sdo* GetSdo(uint8_t id);
1278 
1284  void CancelSdo(uint8_t id = 0);
1285 
1286  private:
1287  struct Impl_;
1288  ::std::unique_ptr<Impl_> impl_;
1289 };
1290 
1296 class AsyncMaster : public BasicMaster {
1297  public:
1299 
1300  protected:
1307  void OnCanError(io::CanError error) noexcept override;
1308 
1315  void OnCanState(io::CanState new_state,
1316  io::CanState old_state) noexcept override;
1317 
1324  void OnRpdoWrite(uint8_t id, uint16_t idx, uint8_t subidx) noexcept override;
1325 
1333  void OnCommand(NmtCommand cs) noexcept override;
1334 
1341  void OnNodeGuarding(uint8_t id, bool occurred) noexcept override;
1342 
1349  void OnHeartbeat(uint8_t id, bool occurred) noexcept override;
1350 
1358  void OnState(uint8_t id, NmtState st) noexcept override;
1359 
1366  void OnBoot(uint8_t id, NmtState st, char es,
1367  const ::std::string& what) noexcept override;
1368 
1375  void OnConfig(uint8_t id) noexcept override;
1376 
1383  void OnSync(uint8_t cnt, const time_point& t) noexcept override;
1384 
1391  void OnSyncError(uint16_t eec, uint8_t er) noexcept override;
1392 
1399  void OnTime(const ::std::chrono::system_clock::time_point&
1400  abs_time) noexcept override;
1401 
1408  void OnEmcy(uint8_t id, uint16_t eec, uint8_t er,
1409  uint8_t msef[5]) noexcept override;
1410 };
1411 
1412 } // namespace canopen
1413 
1414 } // namespace lely
1415 
1416 #endif // LELY_COCPP_MASTER_HPP_
A reference to an abstract timer.
Definition: timer.hpp:130
virtual void OnConfig(uint8_t id) noexcept
The function invoked when the &#39;update configuration&#39; step is reached during the NMT &#39;boot slave&#39; proc...
Definition: master.cpp:318
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
Definition: ev.h:29
ConstObject operator[](::std::ptrdiff_t idx) const noexcept
Returns an accessor object that provides read-only access to the specified CANopen object in the loca...
Definition: master.hpp:605
void TpdoWriteEvent(uint8_t id, uint16_t idx, uint8_t subidx)
Triggers the transmission of every event-driven, asynchronous Transmit-PDO which is mapped into the s...
Definition: device.cpp:695
void lock() final
Blocks until a lock can be obtained for the current execution agent (thread, process, task).
Definition: can_net.hpp:104
void OnSyncError(uint16_t eec, uint8_t er) noexcept override
The default implementation notifies all registered drivers.
Definition: master.cpp:355
The CANopen master.
Definition: master.hpp:50
void SubmitWrite(ev_exec_t *exec, uint8_t id, uint16_t idx, uint8_t subidx, T &&value, F &&con, ::std::error_code &ec)
Equivalent to SubmitWrite(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx, T&& value, F&& con, const ::std::chrono::milliseconds& timeout, ::std::error_code& ec), except that it uses the SDO timeout given by GetTimeout().
Definition: master.hpp:892
SdoFuture< void > AsyncWrite(ev_exec_t *exec, uint8_t id, 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...
Definition: master.hpp:1025
An asynchronous CANopen master.
Definition: master.hpp:1296
void SubmitWrite(uint8_t id, SdoDownloadRequest< T > &req)
Equivalent to SubmitWrite(uint8_t id, SdoDownloadRequest<T>& req, ::std::error_code& ec)...
Definition: master.hpp:843
void SubmitRead(uint8_t id, SdoUploadRequest< T > &req)
Equivalent to SubmitRead(uint8_t id, SdoUploadRequest<T>& req, ::std::error_code& ec)...
Definition: master.hpp:734
void CancelSdo(uint8_t id=0)
Aborts any ongoing or pending SDO requests for the specified slave.
Definition: master.cpp:408
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...
Definition: master.hpp:204
void OnState(uint8_t id, NmtState st) noexcept override
The default implementation notifies the driver registered for node id.
Definition: master.cpp:293
void TpdoEvent(int num=0) noexcept
Definition: master.cpp:168
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...
Definition: master.hpp:189
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) ...
Definition: master.hpp:549
NmtCommand
The NMT command specifiers.
Definition: node.hpp:42
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...
Definition: master.hpp:314
void unlock() final
Releases the lock held by the execution agent. Throws no exceptions.
Definition: can_net.hpp:109
The abstract driver interface for a remote CANopen node.
Definition: driver.hpp:36
An accessor providing read-only access to a CANopen object in a local object dictionary.
Definition: master.hpp:398
void Write(T &&value)
Writes a value to the sub-object by submitting an SDO download request to the local object dictionary...
Definition: master.hpp:148
void SetTimeout(const ::std::chrono::milliseconds &timeout)
Sets the SDO timeout used during the NMT &#39;boot slave&#39; and &#39;check configuration&#39; processes.
Definition: master.cpp:182
ConstSubObject operator[](uint8_t subidx) const noexcept
Returns an accessor object that provides read-only access to the specified CANopen sub-object in the ...
Definition: master.hpp:378
ConstObject operator[](uint16_t idx) const noexcept
Returns an accessor object that provides read-only access to the specified TPDO-mapped object in the ...
Definition: master.hpp:495
void SubmitRead(uint8_t id, SdoUploadRequest< T > &req, ::std::error_code &ec)
Queues an asynchronous read (SDO upload) operation.
Definition: master.hpp:750
CanState
The states of a CAN node, depending on the TX/RX error count.
Definition: err.hpp:33
ev::Executor GetExecutor() const noexcept
Returns the executor used to process I/O and CANopen events.
Definition: node.cpp:106
Object operator[](::std::ptrdiff_t idx) noexcept
Returns a mutator object that provides read/write access to the specified CANopen object in the local...
Definition: master.hpp:593
Resource not available: SDO connection.
void OnSync(uint8_t cnt, const time_point &t) noexcept override
The default implementation notifies all registered drivers.
Definition: master.cpp:347
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...
Definition: master.hpp:534
void Error(uint8_t id)
Indicates the occurrence of an error event on a remote node and triggers the error handling process (...
Definition: master.cpp:139
typename ::std::enable_if< detail::is_canopen_basic< T >::value, T >::type TpdoRead(uint8_t id, uint16_t idx, uint8_t subidx) const
Submits an SDO upload request to a TPDO-mapped sub-object in the local object dictionary, which reads the value that will be written to an RPDO-mapped sub-object in a remote object dictionary by a Transmit-PDO.
void RpdoRtr(int num=0) noexcept
Definition: master.cpp:161
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.
Definition: master.cpp:372
typename ::std::enable_if< detail::is_canopen_basic< T >::value >::type TpdoWrite(uint8_t id, uint16_t idx, uint8_t subidx, T value)
Writes a value to a sub-object in a remote object dictionary by submitting an SDO download request to...
void OnRpdoWrite(uint8_t id, uint16_t idx, uint8_t subidx) noexcept override
The default implementation notifies the driver registered for node id.
Definition: master.cpp:255
uint8_t subidx
The object sub-index.
Definition: sdo.hpp:193
SdoFuture< T > AsyncRead(ev_exec_t *exec, uint8_t id, 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 ...
Definition: master.hpp:978
void WriteEvent()
Checks if the sub-object can be mapped into a PDO and, if so, triggers the transmission of every acyc...
Definition: master.hpp:219
bool IsConfig(uint8_t id) const
Returns true if the remote node is configuring (i.e., the &#39;update configuration&#39; step of the NMT &#39;boo...
Definition: master.cpp:382
void SubmitRead(ev_exec_t *exec, uint8_t id, uint16_t idx, uint8_t subidx, F &&con, ::std::error_code &ec)
Equivalent to SubmitRead(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx, F&& con, const ::std::chrono::milliseconds& timeout, ::std::error_code& ec), except that it uses the SDO timeout given by GetTimeout().
Definition: master.hpp:782
void SubmitWrite(ev_exec_t *exec, uint8_t id, 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.
Definition: master.hpp:933
TpdoMapped TpdoMapped(uint8_t id) noexcept
Returns a mutator object that provides read/write access to TPDO-mapped objects in the remote object ...
Definition: master.hpp:631
An accessor providing read-only access to a CANopen sub-object in a local object dictionary.
Definition: master.hpp:262
uint16_t idx
The object index.
Definition: sdo.hpp:191
CanError
The error flags of a CAN bus, which are not mutually exclusive.
Definition: err.hpp:47
void SetTime()
Updates the CAN network time.
Definition: node.cpp:326
bool Boot(uint8_t id)
Requests the NMT &#39;boot slave&#39; process for the specified node.
Definition: master.cpp:84
RpdoMapped RpdoMapped(uint8_t id) const noexcept
Returns an accessor object that provides read-only access to RPDO-mapped objects in the remote object...
Definition: master.hpp:619
void Command(NmtCommand cs, uint8_t id=0)
Issues an NMT command to a slave.
Definition: master.cpp:153
The internal implementation of the CANopen master.
Definition: master.cpp:45
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, const ::std::chrono::milliseconds& timeout), except that it uses the SDO timeout given by GetTimeout().
Definition: master.hpp:956
A mutator providing read/write access to TPDO-mapped objects in a remote object dictionary.
Definition: master.hpp:467
typename ::std::enable_if< detail::is_canopen_type< T >::value, T >::type Read(uint16_t idx, uint8_t subidx) const
Submits an SDO upload request to the local object dictionary.
void OnCommand(NmtCommand cs) noexcept override
The default implementation notifies all registered drivers.
Definition: master.cpp:264
void WriteEvent(uint16_t idx, uint8_t subidx)
Checks if the specified sub-object in the local object dictionary can be mapped into a PDO and...
Definition: device.cpp:474
The type of objects thrown as exceptions to report a system error with an associated error code...
Definition: exception.hpp:54
An accessor providing read-only access to TPDO-mapped objects in a remote object dictionary.
Definition: master.hpp:437
void SubmitWrite(uint8_t id, SdoDownloadRequest< T > &req, ::std::error_code &ec)
Queues an asynchronous write (SDO download) operation.
Definition: master.hpp:859
T Read() const
Reads the value of the sub-object by submitting an SDO upload request to the local object dictionary...
Definition: master.hpp:112
An SDO download (i.e., write) request.
Definition: sdo.hpp:238
TpdoEventMutex tpdo_event_mutex
Definition: master.hpp:1079
A mutex-like object that can be used to postpone the transmission of acyclic and event-driven Transmi...
Definition: node.hpp:462
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, T&& value, const ::std::chrono::milliseconds& timeout), except that it uses the SDO timeout given by GetTimeout().
Definition: master.hpp:1001
void SubmitWrite(ev_exec_t *exec, uint8_t id, uint16_t idx, uint8_t subidx, T &&value, F &&con, const ::std::chrono::milliseconds &timeout)
Equivalent to SubmitWrite(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx, T&& value, F&& con, const ::std::chrono::milliseconds& timeout, ::std::error_code& ec), except that it throws lely::canopen::SdoError on error.
Definition: master.hpp:905
void Insert(DriverBase &driver)
Registers a driver for a remote CANopen node.
Definition: master.cpp:189
ConstSubObject operator[](uint8_t subidx) const noexcept
Returns an accessor object that provides read-only access to the specified CANopen sub-object in the ...
Definition: master.hpp:415
void OnCanState(io::CanState new_state, io::CanState old_state) noexcept override
The default implementation invokes lely::canopen::Node::OnCanState() and notifies each registered dri...
Definition: master.cpp:246
SubObject operator[](uint8_t subidx) noexcept
Returns a mutator object that provides read/write access to the specified CANopen sub-object in the l...
Definition: master.hpp:363
typename ::std::enable_if< detail::is_canopen_basic< T >::value >::type Write(uint16_t idx, uint8_t subidx, T value)
Submits an SDO download request to the local object dictionary.
BasicMaster(ev_exec_t *exec, io::TimerBase &timer, io::CanChannelBase &chan, const ::std::string &dcf_txt, const ::std::string &dcf_bin="", uint8_t id=0xff)
Creates a new CANopen master.
Definition: master.cpp:74
void SubmitWrite(ev_exec_t *exec, uint8_t id, uint16_t idx, uint8_t subidx, T &&value, F &&con)
Equivalent to SubmitWrite(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx, T&& value, F&& con, ::std::error_code& ec), except that it throws lely::canopen::SdoError on error.
Definition: master.hpp:879
ev::Future<::std::size_t, void > AsyncDeconfig()
Queues the DriverBase::OnDeconfig() method for all registered drivers and creates a future which beco...
Definition: master.cpp:124
This header file is part of the C++ CANopen application library; it contains the CANopen node declara...
void OnHeartbeat(uint8_t id, bool occurred) noexcept override
The default implementation notifies the driver registered for node id.
Definition: master.cpp:284
A mutator providing read/write access to a CANopen object in a local object dictionary.
Definition: master.hpp:347
::std::chrono::milliseconds GetTimeout() const
Returns the SDO timeout used during the NMT &#39;boot slave&#39; and &#39;check configuration&#39; processes...
Definition: master.cpp:175
NmtState
The NMT states.
Definition: node.hpp:56
void WriteEvent(::std::error_code &ec) noexcept
Checks if the sub-object can be mapped into a PDO and, if so, triggers the transmission of every acyc...
Definition: master.hpp:237
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...
Definition: master.hpp:170
void SubmitRead(ev_exec_t *exec, uint8_t id, uint16_t idx, uint8_t subidx, F &&con, const ::std::chrono::milliseconds &timeout, ::std::error_code &ec)
Queues an asynchronous read (SDO upload) operation.
Definition: master.hpp:821
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...
Definition: master.hpp:130
BasicMaster(io::TimerBase &timer, io::CanChannelBase &chan, const ::std::string &dcf_txt, const ::std::string &dcf_bin="", uint8_t id=0xff)
Creates a new CANopen master.
Definition: master.hpp:576
void OnBoot(::std::function< void(uint8_t, NmtState, char, const ::std::string &)> on_boot)
Registers the function invoked when the NMT &#39;boot slave&#39; process completes.
Definition: master.cpp:225
An SDO upload (i.e., read) request.
Definition: sdo.hpp:273
A Client-SDO queue.
Definition: sdo.hpp:407
Definition: buf.hpp:32
SubObject & operator=(T &&value)
Sets the value of the sub-object.
Definition: master.hpp:81
void SubmitRead(ev_exec_t *exec, uint8_t id, uint16_t idx, uint8_t subidx, F &&con, const ::std::chrono::milliseconds &timeout)
Equivalent to SubmitRead(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx, F&& con, const ::std::chrono::milliseconds& timeout, ::std::error_code& ec), except that it throws lely::canopen::SdoError on error.
Definition: master.hpp:795
void OnNodeGuarding(::std::function< void(uint8_t, bool)> on_node_guarding)
Registers the function invoked when a node guarding timeout event occurs or is resolved.
Definition: master.cpp:218
T Read() const
Reads the value of the sub-object by submitting an SDO upload request to the local object dictionary...
Definition: master.hpp:294
uint8_t id() const noexcept
Returns the node-ID.
Definition: device.cpp:161
void OnTime(const ::std::chrono::system_clock::time_point &abs_time) noexcept override
The default implementation notifies all registered drivers.
Definition: master.cpp:363
void ConfigResult(uint8_t id, ::std::error_code ec) noexcept
Reports the result of the &#39;update configuration&#39; step to the NMT service.
Definition: master.cpp:336
Sdo * GetSdo(uint8_t id)
Returns a pointer to the default client-SDO service for the given node.
Definition: master.cpp:389
The base class for CANopen nodes.
Definition: node.hpp:115
This header file is part of the C++ CANopen master library; it contains the Client-SDO queue declarat...
A mutator providing read/write access to a CANopen sub-object in a local object dictionary.
Definition: master.hpp:59
void SubmitRead(ev_exec_t *exec, uint8_t id, uint16_t idx, uint8_t subidx, F &&con)
Equivalent to SubmitRead(ev_exec_t* exec, uint8_t id, uint16_t idx, uint8_t subidx, F&& con, ::std::error_code& ec), except that it throws lely::canopen::SdoError on error.
Definition: master.hpp:770
ConstObject operator[](uint16_t idx) const noexcept
Returns an accessor object that provides read-only access to the specified RPDO-mapped object in the ...
Definition: master.hpp:451
Object operator[](uint16_t idx) noexcept
Returns a mutator object that provides read/write access to the specified PDO-mapped object in the re...
Definition: master.hpp:481
bool IsReady(uint8_t id) const
Returns true if the remote node is ready (i.e., the NMT &#39;boot slave&#39; process has successfully complet...
Definition: master.cpp:106
The type of exception thrown when an SDO abort code is received.
Definition: sdo_error.hpp:121
void OnCanError(io::CanError error) noexcept override
The default implementation notifies all registered drivers.
Definition: master.cpp:238
A reference to an abstract CAN channel.
Definition: can.hpp:429
A future.
Definition: future.hpp:50
void Erase(DriverBase &driver)
Unregisters a driver for a remote CANopen node.
Definition: master.cpp:206