Lely core libraries  2.3.4
sync.hpp
Go to the documentation of this file.
1 
23 #ifndef LELY_CO_SYNC_HPP_
24 #define LELY_CO_SYNC_HPP_
25 
26 #if !defined(__cplusplus) || LELY_NO_CXX
27 #error "include <lely/co/sync.h> for the C interface"
28 #endif
29 
30 #include <lely/can/net.hpp>
31 #include <lely/co/sync.h>
32 
33 namespace lely {
34 
36 template <>
38  typedef __co_sync value_type;
39  typedef value_type& reference;
40  typedef const value_type& const_reference;
41  typedef value_type* pointer;
42  typedef const value_type* const_pointer;
43 
44  static void*
45  alloc() noexcept {
46  return __co_sync_alloc();
47  }
48 
49  static void
50  free(void* ptr) noexcept {
51  __co_sync_free(ptr);
52  }
53 
54  static pointer
55  init(pointer p, CANNet* net, CODev* dev) noexcept {
56  return __co_sync_init(p, net, dev);
57  }
58 
59  static void
60  fini(pointer p) noexcept {
61  __co_sync_fini(p);
62  }
63 };
64 
66 class COSync : public incomplete_c_type<__co_sync> {
68 
69  public:
70  COSync(CANNet* net, CODev* dev) : c_base(net, dev) {}
71 
72  int
73  start() noexcept {
74  return co_sync_start(this);
75  }
76 
77  void
78  stop() noexcept {
79  co_sync_stop(this);
80  }
81 
82  CANNet*
83  getNet() const noexcept {
84  return co_sync_get_net(this);
85  }
86 
87  CODev*
88  getDev() const noexcept {
89  return co_sync_get_dev(this);
90  }
91 
92  void
93  getInd(co_sync_ind_t** pind, void** pdata) const noexcept {
94  co_sync_get_ind(this, pind, pdata);
95  }
96 
97  void
98  setInd(co_sync_ind_t* ind, void* data) noexcept {
99  co_sync_set_ind(this, ind, data);
100  }
101 
102  template <class F>
103  void
104  setInd(F* f) noexcept {
105  setInd(&c_obj_call<co_sync_ind_t*, F>::function, static_cast<void*>(f));
106  }
107 
108  template <class C, typename c_mem_fn<co_sync_ind_t*, C>::type M>
109  void
110  setInd(C* obj) noexcept {
112  static_cast<void*>(obj));
113  }
114 
115  void
116  getErr(co_sync_err_t** perr, void** pdata) const noexcept {
117  co_sync_get_err(this, perr, pdata);
118  }
119 
120  void
121  setErr(co_sync_err_t* err, void* data) noexcept {
122  co_sync_set_err(this, err, data);
123  }
124 
125  template <class F>
126  void
127  setErr(F* f) noexcept {
128  setErr(&c_obj_call<co_sync_err_t*, F>::function, static_cast<void*>(f));
129  }
130 
131  template <class C, typename c_mem_fn<co_sync_err_t*, C>::type M>
132  void
133  setErr(C* obj) noexcept {
135  static_cast<void*>(obj));
136  }
137 
138  protected:
139  ~COSync() = default;
140 };
141 
142 } // namespace lely
143 
144 #endif // !LELY_CO_SYNC_HPP_
An opaque CAN network interface type.
Definition: net.hpp:85
An opaque CANopen device type.
Definition: dev.hpp:77
An opaque CANopen SYNC producer/consumer service type.
Definition: sync.hpp:66
The base class for a C++ interface to an incomplete C type.
Definition: c_type.hpp:249
This header file is part of the CAN library; it contains the C++ interface of the CAN network interfa...
A CANopen SYNC producer/consumer service.
Definition: sync.c:40
A class template supplying a uniform interface to certain attributes of C types.
Definition: c_type.hpp:350
This header file is part of the CANopen library; it contains the synchronization (SYNC) object declar...
void co_sync_get_err(const co_sync_t *sync, co_sync_err_t **perr, void **pdata)
Retrieves the error handling function of a SYNC consumer service.
Definition: sync.c:360
void co_sync_err_t(co_sync_t *sync, co_unsigned16_t eec, co_unsigned8_t er, void *data)
The type of a CANopen SYNC error handling function, invoked when the SYNC data length does not match.
Definition: sync.h:60
void co_sync_set_err(co_sync_t *sync, co_sync_err_t *err, void *data)
Sets the error handling function of a SYNC consumer service.
Definition: sync.c:371
void co_sync_set_ind(co_sync_t *sync, co_sync_ind_t *ind, void *data)
Sets the indication function invoked after a CANopen SYNC message is received or transmitted.
Definition: sync.c:351
co_dev_t * co_sync_get_dev(const co_sync_t *sync)
Returns a pointer to the CANopen device of a SYNC producer/consumer service.
Definition: sync.c:332
void co_sync_ind_t(co_sync_t *sync, co_unsigned8_t cnt, void *data)
The type of a CANopen SYNC indication function, invoked after a SYNC message is received or transmitt...
Definition: sync.h:49
can_net_t * co_sync_get_net(const co_sync_t *sync)
Returns a pointer to the CAN network of a SYNC producer/consumer service.
Definition: sync.c:324
int co_sync_start(co_sync_t *sync)
Starts a SYNC service.
Definition: sync.c:248
void co_sync_stop(co_sync_t *sync)
Stops a SYNC service.
Definition: sync.c:285
void co_sync_get_ind(const co_sync_t *sync, co_sync_ind_t **pind, void **pdata)
Retrieves the indication function invoked after a CANopen SYNC message is received or transmitted.
Definition: sync.c:340