Lely core libraries 2.3.4
dev.hpp
Go to the documentation of this file.
1
22#ifndef LELY_CO_DEV_HPP_
23#define LELY_CO_DEV_HPP_
24
25#if !defined(__cplusplus) || LELY_NO_CXX
26#error "include <lely/co/dev.h> for the C interface"
27#endif
28
29#include <lely/util/c_call.hpp>
30#include <lely/util/c_type.hpp>
31#include <lely/co/dev.h>
32#include <lely/co/val.hpp>
33
34#include <vector>
35
36struct floc;
37struct co_sdev;
38
39namespace lely {
40
42template <>
44 typedef __co_dev value_type;
45 typedef value_type& reference;
46 typedef const value_type& const_reference;
47 typedef value_type* pointer;
48 typedef const value_type* const_pointer;
49
50 static void*
51 alloc() noexcept {
52 return __co_dev_alloc();
53 }
54
55 static void
56 free(void* ptr) noexcept {
57 __co_dev_free(ptr);
58 }
59
60 static pointer
61 init(pointer p, co_unsigned8_t id) noexcept {
62 return __co_dev_init(p, id);
63 }
64
65 static pointer init(pointer p, const char* filename) noexcept;
66 static pointer init(pointer p, const char* begin, const char* end,
67 floc* at) noexcept;
68 static pointer init(pointer p, const co_sdev* sdev) noexcept;
69
70 static void
71 fini(pointer p) noexcept {
72 __co_dev_fini(p);
73 }
74};
75
77class CODev : public incomplete_c_type<__co_dev> {
79
80 public:
81 explicit CODev(co_unsigned8_t id = 0xff) : c_base(id) {}
82
83 explicit CODev(const char* filename) : c_base(filename) {}
84
85 CODev(const char* begin, const char* end, floc* at = 0)
86 : c_base(begin, end, at) {}
87
88 explicit CODev(const co_sdev* sdev) : c_base(sdev) {}
89
91 getNetid() const noexcept {
92 return co_dev_get_netid(this);
93 }
94
95 int
96 setNetid(co_unsigned8_t id) noexcept {
97 return co_dev_set_netid(this, id);
98 }
99
101 getId() const noexcept {
102 return co_dev_get_id(this);
103 }
104
105 int
106 setId(co_unsigned8_t id) noexcept {
107 return co_dev_set_id(this, id);
108 }
109
111 getIdx(co_unsigned16_t maxidx, co_unsigned16_t* idx) const noexcept {
112 return co_dev_get_idx(this, maxidx, idx);
113 }
114
115 ::std::vector<co_unsigned16_t>
116 getIdx() const {
117 std::vector<co_unsigned16_t> idx(getIdx(0, 0));
118 getIdx(idx.size(), idx.data());
119 return idx;
120 }
121
122 int
123 insert(COObj* obj) noexcept {
124 return co_dev_insert_obj(this, obj);
125 }
126
127 int
128 remove(COObj* obj) noexcept {
129 return co_dev_remove_obj(this, obj);
130 }
131
132 COObj*
133 find(co_unsigned16_t idx) const noexcept {
134 return co_dev_find_obj(this, idx);
135 }
136
137 COSub*
138 find(co_unsigned16_t idx, co_unsigned8_t subidx) const noexcept {
139 return co_dev_find_sub(this, idx, subidx);
140 }
141
142 const char*
143 getName() const noexcept {
144 return co_dev_get_name(this);
145 }
146
147 int
148 setName(const char* name) noexcept {
149 return co_dev_set_name(this, name);
150 }
151
152 const char*
153 getVendorName() const noexcept {
154 return co_dev_get_vendor_name(this);
155 }
156
157 int
158 setVendorName(const char* vendor_name) noexcept {
159 return co_dev_set_vendor_name(this, vendor_name);
160 }
161
163 getVendorId() const noexcept {
164 return co_dev_get_vendor_id(this);
165 }
166
167 void
168 setVendorId(co_unsigned32_t vendor_id) noexcept {
169 co_dev_set_vendor_id(this, vendor_id);
170 }
171
172 const char*
173 getProductName() const noexcept {
174 return co_dev_get_product_name(this);
175 }
176
177 int
178 setProductName(const char* product_name) noexcept {
179 return co_dev_set_product_name(this, product_name);
180 }
181
183 getProductCode() const noexcept {
184 return co_dev_get_product_code(this);
185 }
186
187 void
188 setProductCode(co_unsigned32_t product_code) noexcept {
189 co_dev_set_product_code(this, product_code);
190 }
191
193 getRevision() const noexcept {
194 return co_dev_get_revision(this);
195 }
196
197 void
198 setRevision(co_unsigned32_t revision) noexcept {
199 co_dev_set_revision(this, revision);
200 }
201
202 const char*
203 getOrderCode() const noexcept {
204 return co_dev_get_order_code(this);
205 }
206
207 int
208 setOrderCode(const char* order_code) noexcept {
209 return co_dev_set_order_code(this, order_code);
210 }
211
212 unsigned int
213 getBaud() const noexcept {
214 return co_dev_get_baud(this);
215 }
216
217 void
218 setBaud(unsigned int baud) noexcept {
219 co_dev_set_baud(this, baud);
220 }
221
223 getRate() const noexcept {
224 return co_dev_get_rate(this);
225 }
226
227 void
228 setRate(co_unsigned16_t rate) noexcept {
229 co_dev_set_rate(this, rate);
230 }
231
232 bool
233 getLSS() const noexcept {
234 return !!co_dev_get_lss(this);
235 }
236
237 void
238 setLSS(bool lss) noexcept {
239 co_dev_set_lss(this, lss);
240 }
241
243 getDummy() const noexcept {
244 return co_dev_get_dummy(this);
245 }
246
247 void
248 setDummy(co_unsigned32_t dummy) noexcept {
249 co_dev_set_dummy(this, dummy);
250 }
251
252 template <co_unsigned16_t N>
253 const COVal<N>&
254 getVal(co_unsigned16_t idx, co_unsigned8_t subidx) const noexcept {
255 return *reinterpret_cast<const COVal<N>*>(
256 co_dev_get_val(this, idx, subidx));
257 }
258
259 ::std::size_t
260 setVal(co_unsigned16_t idx, co_unsigned8_t subidx, const void* ptr,
261 ::std::size_t n) noexcept {
262 return co_dev_set_val(this, idx, subidx, ptr, n);
263 }
264
265 template <co_unsigned16_t N>
266 ::std::size_t
267 setVal(co_unsigned16_t idx, co_unsigned8_t subidx,
268 const COVal<N>& val) noexcept {
269 return setVal(idx, subidx, val.address(), val.size());
270 }
271
272 template <class T>
273 ::std::size_t
274 setVal(co_unsigned16_t idx, co_unsigned8_t subidx, const T& val) noexcept {
275 return setVal<co_type_traits_T<T>::index>(idx, subidx, val);
276 }
277
278 ::std::size_t
280 const uint_least8_t* begin, const uint_least8_t* end) noexcept {
281 return co_dev_read_sub(this, pidx, psubidx, begin, end);
282 }
283
284 ::std::size_t
285 writeSub(co_unsigned16_t idx, co_unsigned8_t subidx, uint_least8_t* begin,
286 uint_least8_t* end = 0) const noexcept {
287 return co_dev_write_sub(this, idx, subidx, begin, end);
288 }
289
290 int
292 const COVal<CO_DEFTYPE_DOMAIN>& val) noexcept {
293 return co_dev_read_dcf(this, pmin, pmax,
294 reinterpret_cast<void* const*>(&val));
295 }
296
297 int
299 const char* filename) noexcept {
300 return co_dev_read_dcf_file(this, pmin, pmax, filename);
301 }
302
303 int
304 writeDCF(co_unsigned16_t min, co_unsigned16_t max,
305 COVal<CO_DEFTYPE_DOMAIN>& val) const noexcept {
306 return co_dev_write_dcf(this, min, max, reinterpret_cast<void**>(&val));
307 }
308
309 int
310 writeDCF(co_unsigned16_t min, co_unsigned16_t max,
311 const char* filename) const noexcept {
312 return co_dev_write_dcf_file(this, min, max, filename);
313 }
314
315 void
316 getTPDOEventInd(co_dev_tpdo_event_ind_t** pind, void** pdata) const noexcept {
318 }
319
320 void
321 setTPDOEventInd(co_dev_tpdo_event_ind_t* ind, void* data) noexcept {
322 co_dev_set_tpdo_event_ind(this, ind, data);
323 }
324
325 template <class F>
326 void
327 setTPDOEventInd(F* f) noexcept {
329 static_cast<void*>(f));
330 }
331
333 void
334 setTPDOEventInd(C* obj) noexcept {
336 static_cast<void*>(obj));
337 }
338
339 void
340 TPDOEvent(co_unsigned16_t idx, co_unsigned8_t subidx) noexcept {
341 co_dev_tpdo_event(this, idx, subidx);
342 }
343
344 protected:
345 ~CODev() = default;
346};
347
348} // namespace lely
349
350#endif // !LELY_CO_DEV_HPP_
This header file is part of the utilities library; it contains the C callback wrapper declarations.
This header file is part of the utilities library; it contains the C to C++ interface declarations.
An opaque CANopen device type.
Definition dev.hpp:77
An opaque CANopen object type.
Definition obj.hpp:75
An opaque CANopen sub-object type.
Definition obj.hpp:231
A CANopen value.
Definition val.hpp:42
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 device description declarations.
void co_dev_get_tpdo_event_ind(const co_dev_t *dev, co_dev_tpdo_event_ind_t **pind, void **pdata)
Retrieves the indication function invoked by co_dev_tpdo_event() when an event is indicated for (a su...
Definition dev.c:845
co_obj_t * co_dev_find_obj(const co_dev_t *dev, co_unsigned16_t idx)
Finds an object in the object dictionary of a CANopen device.
Definition dev.c:279
co_unsigned16_t co_dev_get_idx(const co_dev_t *dev, co_unsigned16_t maxidx, co_unsigned16_t *idx)
Retrieves a list of object indices in the object dictionary of a CANopen device.
Definition dev.c:223
int co_dev_read_dcf(co_dev_t *dev, co_unsigned16_t *pmin, co_unsigned16_t *pmax, void *const *ptr)
Reads the values of a range of objects from a memory buffer, in the concise DCF format,...
Definition dev.c:707
size_t co_dev_read_sub(co_dev_t *dev, co_unsigned16_t *pidx, co_unsigned8_t *psubidx, const uint_least8_t *begin, const uint_least8_t *end)
Reads a value from a memory buffer, in the concise DCF format, and stores it in a sub-object in the o...
Definition dev.c:617
co_unsigned8_t co_dev_get_id(const co_dev_t *dev)
Returns the node-ID of a CANopen device.
Definition dev.c:197
int co_dev_set_vendor_name(co_dev_t *dev, const char *vendor_name)
Sets the vendor name of a CANopen device.
Definition dev.c:357
void co_dev_set_product_code(co_dev_t *dev, co_unsigned32_t product_code)
Sets the product code of a CANopen device.
Definition dev.c:443
void co_dev_tpdo_event_ind_t(co_unsigned16_t num, void *data)
The type of a CANopen Transmit-PDO event indication function, invoked by co_dev_tpdo_event() when an ...
Definition dev.h:97
void co_dev_set_dummy(co_dev_t *dev, co_unsigned32_t dummy)
Sets the data types supported by a CANopen device for mapping dummy entries in PDOs.
Definition dev.c:559
int co_dev_insert_obj(co_dev_t *dev, co_obj_t *obj)
Inserts an object into the object dictionary of a CANopen device.
Definition dev.c:242
const char * co_dev_get_product_name(const co_dev_t *dev)
Returns a pointer to the product name of a CANopen device.
Definition dev.c:401
void co_dev_set_vendor_id(co_dev_t *dev, co_unsigned32_t vendor_id)
Sets the vendor ID of a CANopen device.
Definition dev.c:391
int co_dev_set_id(co_dev_t *dev, co_unsigned8_t id)
Sets the node-ID of a CANopen device.
Definition dev.c:205
int co_dev_set_netid(co_dev_t *dev, co_unsigned8_t id)
Sets the network-ID of a CANopen device.
Definition dev.c:182
const char * co_dev_get_vendor_name(const co_dev_t *dev)
Returns a pointer to the vendor name of a CANopen device.
Definition dev.c:349
void co_dev_set_revision(co_dev_t *dev, co_unsigned32_t revision)
Sets the revision number of a CANopen device.
Definition dev.c:459
co_sub_t * co_dev_find_sub(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx)
Finds a sub-object in the object dictionary of a CANopen device.
Definition dev.c:290
co_unsigned16_t co_dev_get_rate(const co_dev_t *dev)
Returns the (pending) baudrate of a CANopen device (in kbit/s).
Definition dev.c:519
int co_dev_write_dcf(const co_dev_t *dev, co_unsigned16_t min, co_unsigned16_t max, void **ptr)
Loads the values of a range of objects in the object dictionary of a CANopen device,...
Definition dev.c:768
int co_dev_remove_obj(co_dev_t *dev, co_obj_t *obj)
Removes an object from the object dictionary a CANopen device.
Definition dev.c:263
int co_dev_get_lss(const co_dev_t *dev)
Returns 1 if LSS is supported and 0 if not.
Definition dev.c:535
co_unsigned8_t co_dev_get_netid(const co_dev_t *dev)
Returns the network-ID of a CANopen device.
Definition dev.c:174
co_unsigned32_t co_dev_get_vendor_id(const co_dev_t *dev)
Returns the vendor ID of a CANopen device.
Definition dev.c:383
void co_dev_set_lss(co_dev_t *dev, int lss)
Sets the LSS support flag.
Definition dev.c:543
int co_dev_set_order_code(co_dev_t *dev, const char *order_code)
Sets the order code of a CANopen device.
Definition dev.c:477
co_unsigned32_t co_dev_get_dummy(const co_dev_t *dev)
Returns the data types supported by a CANopen device for mapping dummy entries in PDOs (one bit for e...
Definition dev.c:551
const char * co_dev_get_name(const co_dev_t *dev)
Returns the name of a CANopen device.
Definition dev.c:317
int co_dev_write_dcf_file(const co_dev_t *dev, co_unsigned16_t min, co_unsigned16_t max, const char *filename)
Loads the values of a range of objects in the object dictionary of a CANopen device,...
Definition dev.c:824
void co_dev_tpdo_event(co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx)
Checks if the specified sub-object in the object dictionary of a CANopen device can be mapped into a ...
Definition dev.c:867
void co_dev_set_rate(co_dev_t *dev, co_unsigned16_t rate)
Sets the (pending) baudrate of a CANopen device.
Definition dev.c:527
size_t co_dev_set_val(co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx, const void *ptr, size_t n)
Sets the current value of a CANopen sub-object.
Definition dev.c:574
unsigned int co_dev_get_baud(const co_dev_t *dev)
Returns the supported bit rates of a CANopen device (any combination of CO_BAUD_1000,...
Definition dev.c:503
co_unsigned32_t co_dev_get_product_code(const co_dev_t *dev)
Returns the product code of a CANopen device.
Definition dev.c:435
const void * co_dev_get_val(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx)
Returns a pointer to the current value of a CANopen sub-object.
Definition dev.c:567
int co_dev_set_product_name(co_dev_t *dev, const char *product_name)
Sets the product name of a CANopen device.
Definition dev.c:409
void co_dev_set_baud(co_dev_t *dev, unsigned int baud)
Sets the supported bit rates of a CANopen device.
Definition dev.c:511
void co_dev_set_tpdo_event_ind(co_dev_t *dev, co_dev_tpdo_event_ind_t *ind, void *data)
Sets the indication function invoked by co_dev_tpdo_event() when an event is indicated for (a sub-obj...
Definition dev.c:857
int co_dev_read_dcf_file(co_dev_t *dev, co_unsigned16_t *pmin, co_unsigned16_t *pmax, const char *filename)
Reads the values of a range of objects from a file, in the concise DCF format, and stores them in the...
Definition dev.c:750
size_t co_dev_write_sub(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx, uint_least8_t *begin, uint_least8_t *end)
Loads the value of a sub-object from the object dictionary of a CANopen device, and writes it to a me...
Definition dev.c:671
const char * co_dev_get_order_code(const co_dev_t *dev)
Returns a pointer to the order code of a CANopen device.
Definition dev.c:469
int co_dev_set_name(co_dev_t *dev, const char *name)
Sets the name of a CANopen device.
Definition dev.c:325
co_unsigned32_t co_dev_get_revision(const co_dev_t *dev)
Returns the revision number of a CANopen device.
Definition dev.c:451
A CANopen device.
Definition dev.h:30
A static CANopen device.
Definition sdev.h:30
A location in a text file.
Definition diag.h:39
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 C++ interface of the CANopen value d...