Lely core libraries  2.3.4
lss.hpp
Go to the documentation of this file.
1 
23 #ifndef LELY_CO_LSS_HPP_
24 #define LELY_CO_LSS_HPP_
25 
26 #if !defined(__cplusplus) || LELY_NO_CXX
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  int
73  start() noexcept {
74  return co_lss_start(this);
75  }
76 
77  void
78  stop() noexcept {
79  co_lss_stop(this);
80  }
81 
82  CONMT*
83  getNMT() const noexcept {
84  return co_lss_get_nmt(this);
85  }
86 
87  void
88  getRateInd(co_lss_rate_ind_t** pind, void** pdata) const noexcept {
89  co_lss_get_rate_ind(this, pind, pdata);
90  }
91 
92  void
93  setRateInd(co_lss_rate_ind_t* ind, void* data) noexcept {
94  co_lss_set_rate_ind(this, ind, data);
95  }
96 
97  template <class F>
98  void
99  setRateInd(F* f) noexcept {
101  static_cast<void*>(f));
102  }
103 
104  template <class C, typename c_mem_fn<co_lss_rate_ind_t*, C>::type M>
105  void
106  setRateInd(C* obj) noexcept {
108  static_cast<void*>(obj));
109  }
110 
111  void
112  getStoreInd(co_lss_store_ind_t** pind, void** pdata) const noexcept {
113  co_lss_get_store_ind(this, pind, pdata);
114  }
115 
116  void
117  setStoreInd(co_lss_store_ind_t* ind, void* data) noexcept {
118  co_lss_set_store_ind(this, ind, data);
119  }
120 
121  template <class F>
122  void
123  setStoreInd(F* f) noexcept {
125  static_cast<void*>(f));
126  }
127 
128  template <class C, typename c_mem_fn<co_lss_store_ind_t*, C>::type M>
129  void
130  setStoreInd(C* obj) noexcept {
132  static_cast<void*>(obj));
133  }
134 
135  co_unsigned16_t
136  getInhibit() const noexcept {
137  return co_lss_get_inhibit(this);
138  }
139 
140  void
141  setInhibit(co_unsigned16_t inhibit) noexcept {
142  co_lss_set_inhibit(this, inhibit);
143  }
144 
145  int
146  getTimeout() const noexcept {
147  return co_lss_get_timeout(this);
148  }
149 
150  void
151  setTimeout(int timeout) noexcept {
152  co_lss_set_timeout(this, timeout);
153  }
154 
155  bool
156  isMaster() const noexcept {
157  return !!co_lss_is_master(this);
158  }
159 
160  bool
161  isIdle() const noexcept {
162  return !!co_lss_is_idle(this);
163  }
164 
165  void
166  abortReq() noexcept {
167  co_lss_abort_req(this);
168  }
169 
170  int
171  switchReq(co_unsigned8_t mode) noexcept {
172  return co_lss_switch_req(this, mode);
173  }
174 
175  int
176  switchSelReq(const co_id& id, co_lss_cs_ind_t* ind, void* data) noexcept {
177  return co_lss_switch_sel_req(this, &id, ind, data);
178  }
179 
180  template <class F>
181  int
182  switchSelReq(const co_id& id, F* f) noexcept {
183  return switchSelReq(id, &c_obj_call<co_lss_cs_ind_t*, F>::function,
184  static_cast<void*>(f));
185  }
186 
187  template <class C, typename c_mem_fn<co_lss_cs_ind_t*, C>::type M>
188  int
189  switchSelReq(const co_id& id, C* obj) noexcept {
190  return switchSelReq(id, &c_mem_call<co_lss_cs_ind_t*, C, M>::function,
191  static_cast<void*>(obj));
192  }
193 
194  int
195  setIdReq(co_unsigned8_t id, co_lss_err_ind_t* ind, void* data) noexcept {
196  return co_lss_set_id_req(this, id, ind, data);
197  }
198 
199  template <class F>
200  int
201  setIdReq(co_unsigned8_t id, F* f) noexcept {
202  return setIdReq(id, &c_obj_call<co_lss_err_ind_t*, F>::function,
203  static_cast<void*>(f));
204  }
205 
206  template <class C, typename c_mem_fn<co_lss_err_ind_t*, C>::type M>
207  int
208  setIdReq(co_unsigned8_t id, C* obj) noexcept {
210  static_cast<void*>(obj));
211  }
212 
213  int
214  setRateReq(co_unsigned16_t rate, co_lss_err_ind_t* ind, void* data) noexcept {
215  return co_lss_set_rate_req(this, rate, ind, data);
216  }
217 
218  template <class F>
219  int
220  setRateReq(co_unsigned16_t rate, F* f) noexcept {
221  return setRateReq(rate, &c_obj_call<co_lss_err_ind_t*, F>::function,
222  static_cast<void*>(f));
223  }
224 
225  template <class C, typename c_mem_fn<co_lss_err_ind_t*, C>::type M>
226  int
227  setRateReq(co_unsigned16_t rate, C* obj) noexcept {
228  return setRateReq(rate, &c_mem_call<co_lss_err_ind_t*, C, M>::function,
229  static_cast<void*>(obj));
230  }
231 
232  int
233  switchRateReq(int delay) noexcept {
234  return co_lss_switch_rate_req(this, delay);
235  }
236 
237  int
238  storeReq(co_lss_err_ind_t* ind, void* data) noexcept {
239  return co_lss_store_req(this, ind, data);
240  }
241 
242  template <class F>
243  int
244  storeReq(F* f) noexcept {
246  static_cast<void*>(f));
247  }
248 
249  template <class C, typename c_mem_fn<co_lss_err_ind_t*, C>::type M>
250  int
251  storeReq(C* obj) noexcept {
253  static_cast<void*>(obj));
254  }
255 
256  int
257  getVendorIdReq(co_lss_lssid_ind_t* ind, void* data) noexcept {
258  return co_lss_get_vendor_id_req(this, ind, data);
259  }
260 
261  template <class F>
262  int
263  getVendorIdReq(F* f) noexcept {
264  return getVendorIdReq(&c_obj_call<co_lss_lssid_ind_t*, F>::function,
265  static_cast<void*>(f));
266  }
267 
268  template <class C, typename c_mem_fn<co_lss_lssid_ind_t*, C>::type M>
269  int
270  getVendorIdReq(C* obj) noexcept {
272  static_cast<void*>(obj));
273  }
274 
275  int
276  getProductCodeReq(co_lss_lssid_ind_t* ind, void* data) noexcept {
277  return co_lss_get_product_code_req(this, ind, data);
278  }
279 
280  template <class F>
281  int
282  getProductCodeReq(F* f) noexcept {
283  return getProductCodeReq(&c_obj_call<co_lss_lssid_ind_t*, F>::function,
284  static_cast<void*>(f));
285  }
286 
287  template <class C, typename c_mem_fn<co_lss_lssid_ind_t*, C>::type M>
288  int
289  getProductCodeReq(C* obj) noexcept {
290  return getProductCodeReq(&c_mem_call<co_lss_lssid_ind_t*, C, M>::function,
291  static_cast<void*>(obj));
292  }
293 
294  int
295  getRevisionReq(co_lss_lssid_ind_t* ind, void* data) noexcept {
296  return co_lss_get_revision_req(this, ind, data);
297  }
298 
299  template <class F>
300  int
301  getRevisionReq(F* f) noexcept {
302  return getRevisionReq(&c_obj_call<co_lss_lssid_ind_t*, F>::function,
303  static_cast<void*>(f));
304  }
305 
306  template <class C, typename c_mem_fn<co_lss_lssid_ind_t*, C>::type M>
307  int
308  getRevisionReq(C* obj) noexcept {
310  static_cast<void*>(obj));
311  }
312 
313  int
314  getSerialNrReq(co_lss_lssid_ind_t* ind, void* data) noexcept {
315  return co_lss_get_serial_nr_req(this, ind, data);
316  }
317 
318  template <class F>
319  int
320  getSerialNrReq(F* f) noexcept {
321  return getSerialNrReq(&c_obj_call<co_lss_lssid_ind_t*, F>::function,
322  static_cast<void*>(f));
323  }
324 
325  template <class C, typename c_mem_fn<co_lss_lssid_ind_t*, C>::type M>
326  int
327  getSerialNrReq(C* obj) noexcept {
329  static_cast<void*>(obj));
330  }
331 
332  int
333  getIdReq(co_lss_nid_ind_t* ind, void* data) noexcept {
334  return co_lss_get_id_req(this, ind, data);
335  }
336 
337  template <class F>
338  int
339  getIdReq(F* f) noexcept {
341  static_cast<void*>(f));
342  }
343 
344  template <class C, typename c_mem_fn<co_lss_nid_ind_t*, C>::type M>
345  int
346  getIdReq(C* obj) noexcept {
348  static_cast<void*>(obj));
349  }
350 
351  int
352  idSlaveReq(const co_id& lo, const co_id& hi, co_lss_cs_ind_t* ind,
353  void* data) noexcept {
354  return co_lss_id_slave_req(this, &lo, &hi, ind, data);
355  }
356 
357  template <class F>
358  int
359  idSlaveReq(const co_id& lo, const co_id& hi, F* f) noexcept {
360  return idSlaveReq(lo, hi, &c_obj_call<co_lss_cs_ind_t*, F>::function,
361  static_cast<void*>(f));
362  }
363 
364  template <class C, typename c_mem_fn<co_lss_cs_ind_t*, C>::type M>
365  int
366  idSlaveReq(const co_id& lo, const co_id& hi, C* obj) noexcept {
367  return idSlaveReq(lo, hi, &c_mem_call<co_lss_cs_ind_t*, C, M>::function,
368  static_cast<void*>(obj));
369  }
370 
371  int
372  idNonCfgSlaveReq(co_lss_cs_ind_t* ind, void* data) noexcept {
373  return co_lss_id_non_cfg_slave_req(this, ind, data);
374  }
375 
376  template <class F>
377  int
378  idNonCfgSlaveReq(F* f) noexcept {
379  return idNonCfgSlaveReq(&c_obj_call<co_lss_cs_ind_t*, F>::function,
380  static_cast<void*>(f));
381  }
382 
383  template <class C, typename c_mem_fn<co_lss_cs_ind_t*, C>::type M>
384  int
385  idNonCfgSlaveReq(C* obj) noexcept {
386  return idNonCfgSlaveReq(&c_mem_call<co_lss_cs_ind_t*, C, M>::function,
387  static_cast<void*>(obj));
388  }
389 
390  int
391  slowscanReq(const co_id& lo, const co_id& hi, co_lss_scan_ind_t* ind,
392  void* data) noexcept {
393  return co_lss_slowscan_req(this, &lo, &hi, ind, data);
394  }
395 
396  template <class F>
397  int
398  slowscanReq(const co_id& lo, const co_id& hi, F* f) noexcept {
399  return slowscanReq(lo, hi, &c_obj_call<co_lss_scan_ind_t*, F>::function,
400  static_cast<void*>(f));
401  }
402 
403  template <class C, typename c_mem_fn<co_lss_scan_ind_t*, C>::type M>
404  int
405  slowscanReq(const co_id& lo, const co_id& hi, C* obj) noexcept {
406  return slowscanReq(lo, hi, &c_mem_call<co_lss_scan_ind_t*, C, M>::function,
407  static_cast<void*>(obj));
408  }
409 
410  int
411  fastscanReq(const co_id* id, const co_id* mask, co_lss_scan_ind_t* ind,
412  void* data) noexcept {
413  return co_lss_fastscan_req(this, id, mask, ind, data);
414  }
415 
416  template <class F>
417  int
418  fastscanReq(const co_id* id, const co_id* mask, F* f) noexcept {
419  return fastscanReq(id, mask, &c_obj_call<co_lss_scan_ind_t*, F>::function,
420  static_cast<void*>(f));
421  }
422 
423  template <class C, typename c_mem_fn<co_lss_scan_ind_t*, C>::type M>
424  int
425  fastscanReq(const co_id* id, const co_id* mask, C* obj) noexcept {
426  return fastscanReq(id, mask,
428  static_cast<void*>(obj));
429  }
430 
431  protected:
432  ~COLSS() = default;
433 };
434 
435 } // namespace lely
436 
437 #endif // !LELY_CO_LSS_HPP_
co_lss_set_rate_ind
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:876
co_lss_is_master
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:945
lely::incomplete_c_type
The base class for a C++ interface to an incomplete C type.
Definition: c_type.hpp:249
co_lss_switch_req
int co_lss_switch_req(co_lss_t *lss, co_unsigned8_t mode)
Requests the 'switch state global' service.
Definition: lss.c:977
co_lss_cs_ind_t
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
net.hpp
co_lss_set_rate_req
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:1053
co_lss_store_req
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:1117
co_lss_lssid_ind_t
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
lely::c_obj_call
Definition: c_call.hpp:62
co_lss_scan_ind_t
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
co_lss_get_timeout
int co_lss_get_timeout(const co_lss_t *lss)
Returns the timeout (in milliseconds) of an LSS master service.
Definition: lss.c:924
co_lss_stop
void co_lss_stop(co_lss_t *lss)
Stops an LSS service.
Definition: lss.c:833
lely::CONMT
An opaque CANopen NMT master/slave service type.
Definition: nmt.hpp:71
co_lss_rate_ind_t
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
co_lss_err_ind_t
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
co_lss_id_non_cfg_slave_req
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:1303
co_id
An identity record.
Definition: dev.h:33
co_lss_is_idle
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:961
co_lss_nid_ind_t
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
co_lss_get_serial_nr_req
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:1218
co_lss_slowscan_req
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:1329
co_lss_get_rate_ind
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:865
co_lss_set_store_ind
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:897
lss.h
__co_lss
A CANopen LSS master/slave service.
Definition: lss.c:44
co_lss_get_inhibit
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:908
lely::c_type_traits
A class template supplying a uniform interface to certain attributes of C types.
Definition: c_type.hpp:120
co_lss_set_timeout
void co_lss_set_timeout(co_lss_t *lss, int timeout)
Sets the timeout of an LSS master service.
Definition: lss.c:932
co_lss_abort_req
void co_lss_abort_req(co_lss_t *lss)
Aborts the current LSS master request.
Definition: lss.c:969
co_lss_id_slave_req
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:1269
co_lss_get_nmt
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:857
lely::c_mem_call
Definition: c_call.hpp:67
co_lss_store_ind_t
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
co_lss_set_inhibit
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:916
lely::COLSS
An opaque CANopen LSS master/slave service type.
Definition: lss.hpp:66
co_lss_set_id_req
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:1021
co_lss_switch_sel_req
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:999
co_lss_get_product_code_req
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:1167
co_lss_get_store_ind
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:885
co_lss_start
int co_lss_start(co_lss_t *lss)
Starts an LSS service.
Definition: lss.c:820
co_lss_get_id_req
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:1244
co_lss_fastscan_req
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:1365
co_lss_get_revision_req
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:1192
co_lss_switch_rate_req
int co_lss_switch_rate_req(co_lss_t *lss, int delay)
Requests the 'activate bit timing parameters' service.
Definition: lss.c:1094
co_lss_get_vendor_id_req
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:1142