Lely core libraries  2.2.5
lss.hpp
Go to the documentation of this file.
1 
23 #ifndef LELY_CO_LSS_HPP_
24 #define LELY_CO_LSS_HPP_
25 
26 #ifndef __cplusplus
27 #error "include <lely/co/lss.h> for the C interface"
28 #endif
29 
30 #include <lely/can/net.hpp>
31 #include <lely/co/lss.h>
32 
33 namespace lely {
34 
36 template <>
38  typedef __co_lss 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_lss_alloc();
47  }
48 
49  static void
50  free(void* ptr) noexcept {
51  __co_lss_free(ptr);
52  }
53 
54  static pointer
55  init(pointer p, CONMT* nmt) noexcept {
56  return __co_lss_init(p, nmt);
57  }
58 
59  static void
60  fini(pointer p) noexcept {
61  __co_lss_fini(p);
62  }
63 };
64 
66 class COLSS : public incomplete_c_type<__co_lss> {
68 
69  public:
70  explicit COLSS(CONMT* nmt) : c_base(nmt) {}
71 
72  CONMT*
73  getNMT() const noexcept {
74  return co_lss_get_nmt(this);
75  }
76 
77  void
78  getRateInd(co_lss_rate_ind_t** pind, void** pdata) const noexcept {
79  co_lss_get_rate_ind(this, pind, pdata);
80  }
81 
82  void
83  setRateInd(co_lss_rate_ind_t* ind, void* data) noexcept {
84  co_lss_set_rate_ind(this, ind, data);
85  }
86 
87  template <class F>
88  void
89  setRateInd(F* f) noexcept {
91  static_cast<void*>(f));
92  }
93 
94  template <class C, typename c_mem_fn<co_lss_rate_ind_t*, C>::type M>
95  void
96  setRateInd(C* obj) noexcept {
98  static_cast<void*>(obj));
99  }
100 
101  void
102  getStoreInd(co_lss_store_ind_t** pind, void** pdata) const noexcept {
103  co_lss_get_store_ind(this, pind, pdata);
104  }
105 
106  void
107  setStoreInd(co_lss_store_ind_t* ind, void* data) noexcept {
108  co_lss_set_store_ind(this, ind, data);
109  }
110 
111  template <class F>
112  void
113  setStoreInd(F* f) noexcept {
115  static_cast<void*>(f));
116  }
117 
118  template <class C, typename c_mem_fn<co_lss_store_ind_t*, C>::type M>
119  void
120  setStoreInd(C* obj) noexcept {
122  static_cast<void*>(obj));
123  }
124 
125  co_unsigned16_t
126  getInhibit() const noexcept {
127  return co_lss_get_inhibit(this);
128  }
129 
130  void
131  setInhibit(co_unsigned16_t inhibit) noexcept {
132  co_lss_set_inhibit(this, inhibit);
133  }
134 
135  int
136  getTimeout() const noexcept {
137  return co_lss_get_timeout(this);
138  }
139 
140  void
141  setTimeout(int timeout) noexcept {
142  co_lss_set_timeout(this, timeout);
143  }
144 
145  bool
146  isMaster() const noexcept {
147  return !!co_lss_is_master(this);
148  }
149 
150  bool
151  isIdle() const noexcept {
152  return !!co_lss_is_idle(this);
153  }
154 
155  void
156  abortReq() noexcept {
157  co_lss_abort_req(this);
158  }
159 
160  int
161  switchReq(co_unsigned8_t mode) noexcept {
162  return co_lss_switch_req(this, mode);
163  }
164 
165  int
166  switchSelReq(const co_id& id, co_lss_cs_ind_t* ind, void* data) noexcept {
167  return co_lss_switch_sel_req(this, &id, ind, data);
168  }
169 
170  template <class F>
171  int
172  switchSelReq(const co_id& id, F* f) noexcept {
173  return switchSelReq(id, &c_obj_call<co_lss_cs_ind_t*, F>::function,
174  static_cast<void*>(f));
175  }
176 
177  template <class C, typename c_mem_fn<co_lss_cs_ind_t*, C>::type M>
178  int
179  switchSelReq(const co_id& id, C* obj) noexcept {
180  return switchSelReq(id, &c_mem_call<co_lss_cs_ind_t*, C, M>::function,
181  static_cast<void*>(obj));
182  }
183 
184  int
185  setIdReq(co_unsigned8_t id, co_lss_err_ind_t* ind, void* data) noexcept {
186  return co_lss_set_id_req(this, id, ind, data);
187  }
188 
189  template <class F>
190  int
191  setIdReq(co_unsigned8_t id, F* f) noexcept {
192  return setIdReq(id, &c_obj_call<co_lss_err_ind_t*, F>::function,
193  static_cast<void*>(f));
194  }
195 
196  template <class C, typename c_mem_fn<co_lss_err_ind_t*, C>::type M>
197  int
198  setIdReq(co_unsigned8_t id, C* obj) noexcept {
200  static_cast<void*>(obj));
201  }
202 
203  int
204  setRateReq(co_unsigned16_t rate, co_lss_err_ind_t* ind, void* data) noexcept {
205  return co_lss_set_rate_req(this, rate, ind, data);
206  }
207 
208  template <class F>
209  int
210  setRateReq(co_unsigned16_t rate, F* f) noexcept {
211  return setRateReq(rate, &c_obj_call<co_lss_err_ind_t*, F>::function,
212  static_cast<void*>(f));
213  }
214 
215  template <class C, typename c_mem_fn<co_lss_err_ind_t*, C>::type M>
216  int
217  setRateReq(co_unsigned16_t rate, C* obj) noexcept {
218  return setRateReq(rate, &c_mem_call<co_lss_err_ind_t*, C, M>::function,
219  static_cast<void*>(obj));
220  }
221 
222  int
223  switchRateReq(int delay) noexcept {
224  return co_lss_switch_rate_req(this, delay);
225  }
226 
227  int
228  storeReq(co_lss_err_ind_t* ind, void* data) noexcept {
229  return co_lss_store_req(this, ind, data);
230  }
231 
232  template <class F>
233  int
234  storeReq(F* f) noexcept {
236  static_cast<void*>(f));
237  }
238 
239  template <class C, typename c_mem_fn<co_lss_err_ind_t*, C>::type M>
240  int
241  storeReq(C* obj) noexcept {
243  static_cast<void*>(obj));
244  }
245 
246  int
247  getVendorIdReq(co_lss_lssid_ind_t* ind, void* data) noexcept {
248  return co_lss_get_vendor_id_req(this, ind, data);
249  }
250 
251  template <class F>
252  int
253  getVendorIdReq(F* f) noexcept {
254  return getVendorIdReq(&c_obj_call<co_lss_lssid_ind_t*, F>::function,
255  static_cast<void*>(f));
256  }
257 
258  template <class C, typename c_mem_fn<co_lss_lssid_ind_t*, C>::type M>
259  int
260  getVendorIdReq(C* obj) noexcept {
262  static_cast<void*>(obj));
263  }
264 
265  int
266  getProductCodeReq(co_lss_lssid_ind_t* ind, void* data) noexcept {
267  return co_lss_get_product_code_req(this, ind, data);
268  }
269 
270  template <class F>
271  int
272  getProductCodeReq(F* f) noexcept {
273  return getProductCodeReq(&c_obj_call<co_lss_lssid_ind_t*, F>::function,
274  static_cast<void*>(f));
275  }
276 
277  template <class C, typename c_mem_fn<co_lss_lssid_ind_t*, C>::type M>
278  int
279  getProductCodeReq(C* obj) noexcept {
280  return getProductCodeReq(&c_mem_call<co_lss_lssid_ind_t*, C, M>::function,
281  static_cast<void*>(obj));
282  }
283 
284  int
285  getRevisionReq(co_lss_lssid_ind_t* ind, void* data) noexcept {
286  return co_lss_get_revision_req(this, ind, data);
287  }
288 
289  template <class F>
290  int
291  getRevisionReq(F* f) noexcept {
292  return getRevisionReq(&c_obj_call<co_lss_lssid_ind_t*, F>::function,
293  static_cast<void*>(f));
294  }
295 
296  template <class C, typename c_mem_fn<co_lss_lssid_ind_t*, C>::type M>
297  int
298  getRevisionReq(C* obj) noexcept {
300  static_cast<void*>(obj));
301  }
302 
303  int
304  getSerialNrReq(co_lss_lssid_ind_t* ind, void* data) noexcept {
305  return co_lss_get_serial_nr_req(this, ind, data);
306  }
307 
308  template <class F>
309  int
310  getSerialNrReq(F* f) noexcept {
311  return getSerialNrReq(&c_obj_call<co_lss_lssid_ind_t*, F>::function,
312  static_cast<void*>(f));
313  }
314 
315  template <class C, typename c_mem_fn<co_lss_lssid_ind_t*, C>::type M>
316  int
317  getSerialNrReq(C* obj) noexcept {
319  static_cast<void*>(obj));
320  }
321 
322  int
323  getIdReq(co_lss_nid_ind_t* ind, void* data) noexcept {
324  return co_lss_get_id_req(this, ind, data);
325  }
326 
327  template <class F>
328  int
329  getIdReq(F* f) noexcept {
331  static_cast<void*>(f));
332  }
333 
334  template <class C, typename c_mem_fn<co_lss_nid_ind_t*, C>::type M>
335  int
336  getIdReq(C* obj) noexcept {
338  static_cast<void*>(obj));
339  }
340 
341  int
342  idSlaveReq(const co_id& lo, const co_id& hi, co_lss_cs_ind_t* ind,
343  void* data) noexcept {
344  return co_lss_id_slave_req(this, &lo, &hi, ind, data);
345  }
346 
347  template <class F>
348  int
349  idSlaveReq(const co_id& lo, const co_id& hi, F* f) noexcept {
350  return idSlaveReq(lo, hi, &c_obj_call<co_lss_cs_ind_t*, F>::function,
351  static_cast<void*>(f));
352  }
353 
354  template <class C, typename c_mem_fn<co_lss_cs_ind_t*, C>::type M>
355  int
356  idSlaveReq(const co_id& lo, const co_id& hi, C* obj) noexcept {
357  return idSlaveReq(lo, hi, &c_mem_call<co_lss_cs_ind_t*, C, M>::function,
358  static_cast<void*>(obj));
359  }
360 
361  int
362  idNonCfgSlaveReq(co_lss_cs_ind_t* ind, void* data) noexcept {
363  return co_lss_id_non_cfg_slave_req(this, ind, data);
364  }
365 
366  template <class F>
367  int
368  idNonCfgSlaveReq(F* f) noexcept {
369  return idNonCfgSlaveReq(&c_obj_call<co_lss_cs_ind_t*, F>::function,
370  static_cast<void*>(f));
371  }
372 
373  template <class C, typename c_mem_fn<co_lss_cs_ind_t*, C>::type M>
374  int
375  idNonCfgSlaveReq(C* obj) noexcept {
376  return idNonCfgSlaveReq(&c_mem_call<co_lss_cs_ind_t*, C, M>::function,
377  static_cast<void*>(obj));
378  }
379 
380  int
381  slowscanReq(const co_id& lo, const co_id& hi, co_lss_scan_ind_t* ind,
382  void* data) noexcept {
383  return co_lss_slowscan_req(this, &lo, &hi, ind, data);
384  }
385 
386  template <class F>
387  int
388  slowscanReq(const co_id& lo, const co_id& hi, F* f) noexcept {
389  return slowscanReq(lo, hi, &c_obj_call<co_lss_scan_ind_t*, F>::function,
390  static_cast<void*>(f));
391  }
392 
393  template <class C, typename c_mem_fn<co_lss_scan_ind_t*, C>::type M>
394  int
395  slowscanReq(const co_id& lo, const co_id& hi, C* obj) noexcept {
396  return slowscanReq(lo, hi, &c_mem_call<co_lss_scan_ind_t*, C, M>::function,
397  static_cast<void*>(obj));
398  }
399 
400  int
401  fastscanReq(const co_id* id, const co_id* mask, co_lss_scan_ind_t* ind,
402  void* data) noexcept {
403  return co_lss_fastscan_req(this, id, mask, ind, data);
404  }
405 
406  template <class F>
407  int
408  fastscanReq(const co_id* id, const co_id* mask, F* f) noexcept {
409  return fastscanReq(id, mask, &c_obj_call<co_lss_scan_ind_t*, F>::function,
410  static_cast<void*>(f));
411  }
412 
413  template <class C, typename c_mem_fn<co_lss_scan_ind_t*, C>::type M>
414  int
415  fastscanReq(const co_id* id, const co_id* mask, C* obj) noexcept {
416  return fastscanReq(id, mask,
418  static_cast<void*>(obj));
419  }
420 
421  protected:
422  ~COLSS() = default;
423 };
424 
425 } // namespace lely
426 
427 #endif // !LELY_CO_LSS_HPP_
An opaque CANopen LSS master/slave service type.
Definition: lss.hpp:66
An opaque CANopen NMT master/slave service type.
Definition: nmt.hpp:71
The base class for a C++ interface to an incomplete C type.
Definition: c_type.hpp:249
This header file is part of the CANopen library; it contains the Layer Setting Services (LSS) and pro...
void co_lss_lssid_ind_t(co_lss_t *lss, co_unsigned8_t cs, co_unsigned32_t id, void *data)
The type of a CANopen LSS inquire identity indication function, invoked when an 'inquire identity ven...
Definition: lss.h:114
int co_lss_get_vendor_id_req(co_lss_t *lss, co_lss_lssid_ind_t *ind, void *data)
Requests the 'inquire identity vendor-ID' service.
Definition: lss.c:1092
int co_lss_store_ind_t(co_lss_t *lss, co_unsigned8_t id, co_unsigned16_t rate, void *data)
The type of a CANopen LSS 'store configuration' indication function, invoked when the pending node-ID...
Definition: lss.h:72
void co_lss_err_ind_t(co_lss_t *lss, co_unsigned8_t cs, co_unsigned8_t err, co_unsigned8_t spec, void *data)
The type of a CANopen LSS error received indication function, invoked when a 'configure node-ID',...
Definition: lss.h:99
int co_lss_is_master(const co_lss_t *lss)
Returns 1 if the specified CANopen LSS service is a master, and 0 if not.
Definition: lss.c:895
void co_lss_nid_ind_t(co_lss_t *lss, co_unsigned8_t cs, co_unsigned8_t id, void *data)
The type of a CANopen LSS inquire node-ID indication function, invoked when an 'inquire node-ID' requ...
Definition: lss.h:126
int co_lss_set_id_req(co_lss_t *lss, co_unsigned8_t id, co_lss_err_ind_t *ind, void *data)
Requests the 'configure node-ID' service.
Definition: lss.c:971
void co_lss_set_timeout(co_lss_t *lss, int timeout)
Sets the timeout of an LSS master service.
Definition: lss.c:882
co_unsigned16_t co_lss_get_inhibit(const co_lss_t *lss)
Returns the inhibit time (in multiples of 100 microseconds) of an LSS master service.
Definition: lss.c:858
void co_lss_scan_ind_t(co_lss_t *lss, co_unsigned8_t cs, const struct co_id *id, void *data)
The type of a CANopen LSS identify remote slave indication function, invoked when a 'Slowscan' or 'Fa...
Definition: lss.h:140
int co_lss_slowscan_req(co_lss_t *lss, const struct co_id *lo, const struct co_id *hi, co_lss_scan_ind_t *ind, void *data)
Requests the 'LSS Slowscan' service.
Definition: lss.c:1279
int co_lss_switch_rate_req(co_lss_t *lss, int delay)
Requests the 'activate bit timing parameters' service.
Definition: lss.c:1044
int co_lss_get_id_req(co_lss_t *lss, co_lss_nid_ind_t *ind, void *data)
Requests the 'inquire node-ID' service.
Definition: lss.c:1194
int co_lss_get_revision_req(co_lss_t *lss, co_lss_lssid_ind_t *ind, void *data)
Requests the 'inquire identity revision-number' service.
Definition: lss.c:1142
void co_lss_set_store_ind(co_lss_t *lss, co_lss_store_ind_t *ind, void *data)
Sets the indication function invoked when an LSS 'store configuration' request is received.
Definition: lss.c:847
int co_lss_switch_sel_req(co_lss_t *lss, const struct co_id *id, co_lss_cs_ind_t *ind, void *data)
Requests the 'switch state selective' service.
Definition: lss.c:949
void co_lss_get_rate_ind(const co_lss_t *lss, co_lss_rate_ind_t **pind, void **pdata)
Retrieves the indication function invoked when an LSS 'activate bit timing' request is received.
Definition: lss.c:815
int co_lss_switch_req(co_lss_t *lss, co_unsigned8_t mode)
Requests the 'switch state global' service.
Definition: lss.c:927
int co_lss_set_rate_req(co_lss_t *lss, co_unsigned16_t rate, co_lss_err_ind_t *ind, void *data)
Requests the 'configure bit timing parameters' service.
Definition: lss.c:1003
int co_lss_is_idle(const co_lss_t *lss)
Returns 1 if the specified LSS master is idle, and 0 if a request is ongoing.
Definition: lss.c:911
void co_lss_set_rate_ind(co_lss_t *lss, co_lss_rate_ind_t *ind, void *data)
Sets the indication function invoked when an LSS 'activate bit timing' request is received.
Definition: lss.c:826
int co_lss_get_timeout(const co_lss_t *lss)
Returns the timeout (in milliseconds) of an LSS master service.
Definition: lss.c:874
int co_lss_get_product_code_req(co_lss_t *lss, co_lss_lssid_ind_t *ind, void *data)
Requests the 'inquire identity product-code' service.
Definition: lss.c:1117
co_nmt_t * co_lss_get_nmt(const co_lss_t *lss)
Returns a pointer to the NMT service of an LSS master/slave service.
Definition: lss.c:807
int co_lss_id_slave_req(co_lss_t *lss, const struct co_id *lo, const struct co_id *hi, co_lss_cs_ind_t *ind, void *data)
Requests the 'LSS identify remote slave' service.
Definition: lss.c:1219
int co_lss_store_req(co_lss_t *lss, co_lss_err_ind_t *ind, void *data)
Requests the 'store configuration' service.
Definition: lss.c:1067
void co_lss_cs_ind_t(co_lss_t *lss, co_unsigned8_t cs, void *data)
The type of a CANopen LSS command received indication function, invoked when a 'switch state selectiv...
Definition: lss.h:85
void co_lss_rate_ind_t(co_lss_t *lss, co_unsigned16_t rate, int delay, void *data)
The type of a CANopen LSS 'activate bit timing' indication function, invoked when a baudrate switch i...
Definition: lss.h:56
int co_lss_id_non_cfg_slave_req(co_lss_t *lss, co_lss_cs_ind_t *ind, void *data)
Requests the 'LSS identify non-configured remote slave' service.
Definition: lss.c:1253
int co_lss_fastscan_req(co_lss_t *lss, const struct co_id *id, const struct co_id *mask, co_lss_scan_ind_t *ind, void *data)
Requests the 'LSS Fastscan' service.
Definition: lss.c:1315
int co_lss_get_serial_nr_req(co_lss_t *lss, co_lss_lssid_ind_t *ind, void *data)
Requests the 'inquire identity serial-number' service.
Definition: lss.c:1168
void co_lss_abort_req(co_lss_t *lss)
Aborts the current LSS master request.
Definition: lss.c:919
void co_lss_get_store_ind(const co_lss_t *lss, co_lss_store_ind_t **pind, void **pdata)
Retrieves the indication function invoked when an LSS 'store configuration' request is received.
Definition: lss.c:835
void co_lss_set_inhibit(co_lss_t *lss, co_unsigned16_t inhibit)
Sets the inhibit time between successive LSS messages of an LSS master service.
Definition: lss.c:866
This header file is part of the CAN library; it contains the C++ interface of the CAN network interfa...
A CANopen LSS master/slave service.
Definition: lss.c:44
An identity record.
Definition: dev.h:33
A class template supplying a uniform interface to certain attributes of C types.
Definition: c_type.hpp:350