Lely core libraries  1.9.2
dev.h
Go to the documentation of this file.
1 
22 #ifndef LELY_CO_DEV_H_
23 #define LELY_CO_DEV_H_
24 
25 #include <lely/co/type.h>
26 
27 #include <stddef.h>
28 
30 #define CO_DEFSTRUCT_ID 0x0023
31 
33 struct co_id {
35  co_unsigned8_t n;
37  co_unsigned32_t vendor_id;
39  co_unsigned32_t product_code;
41  co_unsigned32_t revision;
43  co_unsigned32_t serial_nr;
44 };
45 
47 #define CO_ID_INIT \
48  { \
49  4, 0, 0, 0, 0 \
50  }
51 
53 #define CO_NUM_NETWORKS 127
54 
56 #define CO_NUM_NODES 127
57 
59 #define CO_BAUD_1000 0x0001
60 
62 #define CO_BAUD_800 0x0002
63 
65 #define CO_BAUD_500 0x0004
66 
68 #define CO_BAUD_250 0x0008
69 
71 #define CO_BAUD_125 0x0020
72 
74 #define CO_BAUD_50 0x0040
75 
77 #define CO_BAUD_20 0x0080
78 
80 #define CO_BAUD_10 0x0100
81 
83 #define CO_BAUD_AUTO 0x0200
84 
85 #ifdef __cplusplus
86 extern "C" {
87 #endif
88 
89 void *__co_dev_alloc(void);
90 void __co_dev_free(void *ptr);
91 struct __co_dev *__co_dev_init(struct __co_dev *dev, co_unsigned8_t id);
92 void __co_dev_fini(struct __co_dev *dev);
93 
104 co_dev_t *co_dev_create(co_unsigned8_t id);
105 
111 void co_dev_destroy(co_dev_t *dev);
112 
114 co_unsigned8_t co_dev_get_netid(const co_dev_t *dev);
115 
124 int co_dev_set_netid(co_dev_t *dev, co_unsigned8_t id);
125 
127 co_unsigned8_t co_dev_get_id(const co_dev_t *dev);
128 
138 int co_dev_set_id(co_dev_t *dev, co_unsigned8_t id);
139 
152 co_unsigned16_t co_dev_get_idx(const co_dev_t *dev, co_unsigned16_t maxidx,
153  co_unsigned16_t *idx);
154 
167 int co_dev_insert_obj(co_dev_t *dev, co_obj_t *obj);
168 
179 int co_dev_remove_obj(co_dev_t *dev, co_obj_t *obj);
180 
191 co_obj_t *co_dev_find_obj(const co_dev_t *dev, co_unsigned16_t idx);
192 
202 co_sub_t *co_dev_find_sub(const co_dev_t *dev, co_unsigned16_t idx,
203  co_unsigned8_t subidx);
204 
206 const char *co_dev_get_name(const co_dev_t *dev);
207 
216 int co_dev_set_name(co_dev_t *dev, const char *name);
217 
223 const char *co_dev_get_vendor_name(const co_dev_t *dev);
224 
233 int co_dev_set_vendor_name(co_dev_t *dev, const char *vendor_name);
234 
236 co_unsigned32_t co_dev_get_vendor_id(const co_dev_t *dev);
237 
239 void co_dev_set_vendor_id(co_dev_t *dev, co_unsigned32_t vendor_id);
240 
246 const char *co_dev_get_product_name(const co_dev_t *dev);
247 
256 int co_dev_set_product_name(co_dev_t *dev, const char *product_name);
257 
259 co_unsigned32_t co_dev_get_product_code(const co_dev_t *dev);
260 
262 void co_dev_set_product_code(co_dev_t *dev, co_unsigned32_t product_code);
263 
265 co_unsigned32_t co_dev_get_revision(const co_dev_t *dev);
266 
268 void co_dev_set_revision(co_dev_t *dev, co_unsigned32_t revision);
269 
275 const char *co_dev_get_order_code(const co_dev_t *dev);
276 
285 int co_dev_set_order_code(co_dev_t *dev, const char *order_code);
286 
294 unsigned int co_dev_get_baud(const co_dev_t *dev);
295 
306 void co_dev_set_baud(co_dev_t *dev, unsigned int baud);
307 
313 co_unsigned16_t co_dev_get_rate(const co_dev_t *dev);
314 
323 void co_dev_set_rate(co_dev_t *dev, co_unsigned16_t rate);
324 
326 int co_dev_get_lss(const co_dev_t *dev);
327 
329 void co_dev_set_lss(co_dev_t *dev, int lss);
330 
337 co_unsigned32_t co_dev_get_dummy(const co_dev_t *dev);
338 
349 void co_dev_set_dummy(co_dev_t *dev, co_unsigned32_t dummy);
350 
358 const void *co_dev_get_val(const co_dev_t *dev, co_unsigned16_t idx,
359  co_unsigned8_t subidx);
360 
377 size_t co_dev_set_val(co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx,
378  const void *ptr, size_t n);
379 
380 #define LELY_CO_DEFINE_TYPE(a, b, c, d) \
381  co_##b##_t co_dev_get_val_##c(const co_dev_t *dev, \
382  co_unsigned16_t idx, co_unsigned8_t subidx); \
383  size_t co_dev_set_val_##c(co_dev_t *dev, co_unsigned16_t idx, \
384  co_unsigned8_t subidx, co_##b##_t c);
385 #include <lely/co/def/basic.def>
386 #undef LELY_CO_DEFINE_TYPE
387 
404 size_t co_dev_read_sub(co_dev_t *dev, co_unsigned16_t *pidx,
405  co_unsigned8_t *psubidx, const uint8_t *begin,
406  const uint8_t *end);
407 
426 size_t co_dev_write_sub(const co_dev_t *dev, co_unsigned16_t idx,
427  co_unsigned8_t subidx, uint8_t *begin, uint8_t *end);
428 
446 int co_dev_read_dcf(co_dev_t *dev, co_unsigned16_t *pmin, co_unsigned16_t *pmax,
447  void *const *ptr);
448 
466 int co_dev_read_dcf_file(co_dev_t *dev, co_unsigned16_t *pmin,
467  co_unsigned16_t *pmax, const char *filename);
468 
484 int co_dev_write_dcf(const co_dev_t *dev, co_unsigned16_t min,
485  co_unsigned16_t max, void **ptr);
486 
501 int co_dev_write_dcf_file(const co_dev_t *dev, co_unsigned16_t min,
502  co_unsigned16_t max, const char *filename);
503 
504 #ifdef __cplusplus
505 }
506 #endif
507 
508 #endif // !LELY_CO_DEV_H_
int lss
A flag specifying whether LSS is supported (1) or not (0).
Definition: dev.c:64
void co_dev_set_revision(co_dev_t *dev, co_unsigned32_t revision)
Sets the revision number of a CANopen device.
Definition: dev.c:427
void co_dev_set_lss(co_dev_t *dev, int lss)
Sets the LSS support flag.
Definition: dev.c:505
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:521
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, and writes them to a memory buffer, in the concise DCF format.
Definition: dev.c:776
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:513
co_unsigned8_t n
Highest sub-index supported.
Definition: dev.h:35
A CANopen sub-object.
Definition: obj.h:54
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, and stores them in the object dictionary of a CANopen device.
Definition: dev.c:682
char * order_code
A pointer to the order code.
Definition: dev.c:58
co_unsigned32_t revision
The revision number.
Definition: dev.c:56
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:264
const char * co_dev_get_name(const co_dev_t *dev)
Returns the name of a CANopen device.
Definition: dev.c:297
co_unsigned8_t co_dev_get_id(const co_dev_t *dev)
Returns the node-ID of a CANopen device.
Definition: dev.c:198
size_t co_dev_read_sub(co_dev_t *dev, co_unsigned16_t *pidx, co_unsigned8_t *psubidx, const uint8_t *begin, const uint8_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:580
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:411
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:335
unsigned baud
The supported bit rates.
Definition: dev.c:60
co_unsigned32_t co_dev_get_vendor_id(const co_dev_t *dev)
Returns the vendor ID of a CANopen device.
Definition: dev.c:357
char * name
A pointer to the name of the device.
Definition: dev.c:46
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:539
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:529
co_unsigned32_t product_code
Product code.
Definition: dev.h:39
co_unsigned32_t vendor_id
The vendor ID.
Definition: dev.c:50
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:373
int co_dev_set_netid(co_dev_t *dev, co_unsigned8_t id)
Sets the network-ID of a CANopen device.
Definition: dev.c:183
co_unsigned32_t vendor_id
Vendor-ID.
Definition: dev.h:37
char * product_name
A pointer to the product name.
Definition: dev.c:52
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:243
co_unsigned8_t co_dev_get_netid(const co_dev_t *dev)
Returns the network-ID of a CANopen device.
Definition: dev.c:175
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:443
co_unsigned32_t co_dev_get_revision(const co_dev_t *dev)
Returns the revision number of a CANopen device.
Definition: dev.c:419
size_t co_dev_write_sub(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx, uint8_t *begin, uint8_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:638
This header file is part of the C11 and POSIX compatibility library; it includes <stddef.h> and defines any missing functionality.
void co_dev_set_rate(co_dev_t *dev, co_unsigned16_t rate)
Sets the (pending) baudrate of a CANopen device.
Definition: dev.c:489
co_unsigned32_t dummy
The data types supported for mapping dummy entries in PDOs.
Definition: dev.c:66
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, CO_BAUD_800, CO_BAUD_500, CO_BAUD_250, CO_BAUD_125, CO_BAUD_50, CO_BAUD_20, CO_BAUD_10 and CO_BAUD_AUTO).
Definition: dev.c:465
co_unsigned32_t revision
Revision number.
Definition: dev.h:41
A CANopen device.
Definition: dev.c:38
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:224
co_unsigned32_t serial_nr
Serial number.
Definition: dev.h:43
void co_dev_destroy(co_dev_t *dev)
Destroys a CANopen device, including all objects in its object dictionary.
Definition: dev.c:166
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:435
co_unsigned32_t product_code
The product code.
Definition: dev.c:54
char * vendor_name
A pointer to the vendor name.
Definition: dev.c:48
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:327
co_dev_t * co_dev_create(co_unsigned8_t id)
Creates a new CANopen device.
Definition: dev.c:141
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:381
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:481
int co_dev_set_id(co_dev_t *dev, co_unsigned8_t id)
Sets the node-ID of a CANopen device.
Definition: dev.c:206
void co_dev_set_baud(co_dev_t *dev, unsigned int baud)
Sets the supported bit rates of a CANopen device.
Definition: dev.c:473
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
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:725
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, and writes them to a file, in the concise DCF format.
Definition: dev.c:851
int co_dev_set_name(co_dev_t *dev, const char *name)
Sets the name of a CANopen device.
Definition: dev.c:305
A CANopen object.
Definition: obj.h:32
int co_dev_get_lss(const co_dev_t *dev)
Returns 1 if LSS is supported and 0 if not.
Definition: dev.c:497
An identity record.
Definition: dev.h:33
co_unsigned16_t rate
The (pending) baudrate (in kbit/s).
Definition: dev.c:62
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:365
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_unsigned32_t co_dev_get_product_code(const co_dev_t *dev)
Returns the product code of a CANopen device.
Definition: dev.c:403
This header file is part of the CANopen library; it contains the CANopen type definitions.