Lely core libraries  2.2.5
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 
97 typedef void co_dev_tpdo_event_ind_t(co_unsigned16_t num, void *data);
98 
99 void *__co_dev_alloc(void);
100 void __co_dev_free(void *ptr);
101 struct __co_dev *__co_dev_init(struct __co_dev *dev, co_unsigned8_t id);
102 void __co_dev_fini(struct __co_dev *dev);
103 
114 co_dev_t *co_dev_create(co_unsigned8_t id);
115 
121 void co_dev_destroy(co_dev_t *dev);
122 
124 co_unsigned8_t co_dev_get_netid(const co_dev_t *dev);
125 
134 int co_dev_set_netid(co_dev_t *dev, co_unsigned8_t id);
135 
137 co_unsigned8_t co_dev_get_id(const co_dev_t *dev);
138 
148 int co_dev_set_id(co_dev_t *dev, co_unsigned8_t id);
149 
162 co_unsigned16_t co_dev_get_idx(const co_dev_t *dev, co_unsigned16_t maxidx,
163  co_unsigned16_t *idx);
164 
177 int co_dev_insert_obj(co_dev_t *dev, co_obj_t *obj);
178 
189 int co_dev_remove_obj(co_dev_t *dev, co_obj_t *obj);
190 
201 co_obj_t *co_dev_find_obj(const co_dev_t *dev, co_unsigned16_t idx);
202 
212 co_sub_t *co_dev_find_sub(const co_dev_t *dev, co_unsigned16_t idx,
213  co_unsigned8_t subidx);
214 
224 co_obj_t *co_dev_first_obj(const co_dev_t *dev);
225 
235 co_obj_t *co_dev_last_obj(const co_dev_t *dev);
236 
238 const char *co_dev_get_name(const co_dev_t *dev);
239 
248 int co_dev_set_name(co_dev_t *dev, const char *name);
249 
255 const char *co_dev_get_vendor_name(const co_dev_t *dev);
256 
265 int co_dev_set_vendor_name(co_dev_t *dev, const char *vendor_name);
266 
268 co_unsigned32_t co_dev_get_vendor_id(const co_dev_t *dev);
269 
271 void co_dev_set_vendor_id(co_dev_t *dev, co_unsigned32_t vendor_id);
272 
278 const char *co_dev_get_product_name(const co_dev_t *dev);
279 
288 int co_dev_set_product_name(co_dev_t *dev, const char *product_name);
289 
291 co_unsigned32_t co_dev_get_product_code(const co_dev_t *dev);
292 
294 void co_dev_set_product_code(co_dev_t *dev, co_unsigned32_t product_code);
295 
297 co_unsigned32_t co_dev_get_revision(const co_dev_t *dev);
298 
300 void co_dev_set_revision(co_dev_t *dev, co_unsigned32_t revision);
301 
307 const char *co_dev_get_order_code(const co_dev_t *dev);
308 
317 int co_dev_set_order_code(co_dev_t *dev, const char *order_code);
318 
326 unsigned int co_dev_get_baud(const co_dev_t *dev);
327 
338 void co_dev_set_baud(co_dev_t *dev, unsigned int baud);
339 
345 co_unsigned16_t co_dev_get_rate(const co_dev_t *dev);
346 
355 void co_dev_set_rate(co_dev_t *dev, co_unsigned16_t rate);
356 
358 int co_dev_get_lss(const co_dev_t *dev);
359 
361 void co_dev_set_lss(co_dev_t *dev, int lss);
362 
369 co_unsigned32_t co_dev_get_dummy(const co_dev_t *dev);
370 
381 void co_dev_set_dummy(co_dev_t *dev, co_unsigned32_t dummy);
382 
390 const void *co_dev_get_val(const co_dev_t *dev, co_unsigned16_t idx,
391  co_unsigned8_t subidx);
392 
409 size_t co_dev_set_val(co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx,
410  const void *ptr, size_t n);
411 
412 #define LELY_CO_DEFINE_TYPE(a, b, c, d) \
413  co_##b##_t co_dev_get_val_##c(const co_dev_t *dev, \
414  co_unsigned16_t idx, co_unsigned8_t subidx); \
415  size_t co_dev_set_val_##c(co_dev_t *dev, co_unsigned16_t idx, \
416  co_unsigned8_t subidx, co_##b##_t c);
417 #include <lely/co/def/basic.def>
418 #undef LELY_CO_DEFINE_TYPE
419 
436 size_t co_dev_read_sub(co_dev_t *dev, co_unsigned16_t *pidx,
437  co_unsigned8_t *psubidx, const uint_least8_t *begin,
438  const uint_least8_t *end);
439 
458 size_t co_dev_write_sub(const co_dev_t *dev, co_unsigned16_t idx,
459  co_unsigned8_t subidx, uint_least8_t *begin,
460  uint_least8_t *end);
461 
479 int co_dev_read_dcf(co_dev_t *dev, co_unsigned16_t *pmin, co_unsigned16_t *pmax,
480  void *const *ptr);
481 
499 int co_dev_read_dcf_file(co_dev_t *dev, co_unsigned16_t *pmin,
500  co_unsigned16_t *pmax, const char *filename);
501 
517 int co_dev_write_dcf(const co_dev_t *dev, co_unsigned16_t min,
518  co_unsigned16_t max, void **ptr);
519 
534 int co_dev_write_dcf_file(const co_dev_t *dev, co_unsigned16_t min,
535  co_unsigned16_t max, const char *filename);
536 
550 void co_dev_get_tpdo_event_ind(const co_dev_t *dev,
551  co_dev_tpdo_event_ind_t **pind, void **pdata);
552 
566  co_dev_t *dev, co_dev_tpdo_event_ind_t *ind, void *data);
567 
582 void co_dev_tpdo_event(
583  co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx);
584 
585 #ifdef __cplusplus
586 }
587 #endif
588 
589 #endif // !LELY_CO_DEV_H_
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:887
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:299
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:233
co_dev_t * co_dev_create(co_unsigned8_t id)
Creates a new CANopen device.
Definition: dev.c:150
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:688
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:606
co_unsigned8_t co_dev_get_id(const co_dev_t *dev)
Returns the node-ID of a CANopen device.
Definition: dev.c:207
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:362
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:556
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:438
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:548
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:252
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:392
const char * co_dev_get_name(const co_dev_t *dev)
Returns the name of a CANopen device.
Definition: dev.c:324
int co_dev_set_id(co_dev_t *dev, co_unsigned8_t id)
Sets the node-ID of a CANopen device.
Definition: dev.c:215
int co_dev_set_netid(co_dev_t *dev, co_unsigned8_t id)
Sets the network-ID of a CANopen device.
Definition: dev.c:192
void co_dev_set_revision(co_dev_t *dev, co_unsigned32_t revision)
Sets the revision number of a CANopen device.
Definition: dev.c:454
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:508
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:783
co_obj_t * co_dev_first_obj(const co_dev_t *dev)
Finds the first object (with the lowest index) in the object dictionary of a CANopen device.
Definition: dev.c:306
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:273
int co_dev_get_lss(const co_dev_t *dev)
Returns 1 if LSS is supported and 0 if not.
Definition: dev.c:524
co_obj_t * co_dev_last_obj(const co_dev_t *dev)
Finds the last object (with the highest index) in the object dictionary of a CANopen device.
Definition: dev.c:315
co_unsigned8_t co_dev_get_netid(const co_dev_t *dev)
Returns the network-ID of a CANopen device.
Definition: dev.c:184
co_unsigned32_t co_dev_get_vendor_id(const co_dev_t *dev)
Returns the vendor ID of a CANopen device.
Definition: dev.c:384
void co_dev_set_lss(co_dev_t *dev, int lss)
Sets the LSS support flag.
Definition: dev.c:532
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:470
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:540
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:400
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:839
void co_dev_destroy(co_dev_t *dev)
Destroys a CANopen device, including all objects in its object dictionary.
Definition: dev.c:175
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:288
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:909
void co_dev_set_rate(co_dev_t *dev, co_unsigned16_t rate)
Sets the (pending) baudrate of a CANopen device.
Definition: dev.c:516
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:563
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:492
co_unsigned32_t co_dev_get_product_code(const co_dev_t *dev)
Returns the product code of a CANopen device.
Definition: dev.c:430
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:408
void co_dev_set_baud(co_dev_t *dev, unsigned int baud)
Sets the supported bit rates of a CANopen device.
Definition: dev.c:500
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:899
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:731
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:354
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:652
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:462
int co_dev_set_name(co_dev_t *dev, const char *name)
Sets the name of a CANopen device.
Definition: dev.c:332
co_unsigned32_t co_dev_get_revision(const co_dev_t *dev)
Returns the revision number of a CANopen device.
Definition: dev.c:446
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....
A CANopen device.
Definition: dev.c:41
co_unsigned32_t product_code
The product code.
Definition: dev.c:57
char * product_name
A pointer to the product name.
Definition: dev.c:55
co_unsigned16_t rate
The (pending) baudrate (in kbit/s).
Definition: dev.c:65
char * vendor_name
A pointer to the vendor name.
Definition: dev.c:51
char * order_code
A pointer to the order code.
Definition: dev.c:61
unsigned baud
The supported bit rates.
Definition: dev.c:63
int lss
A flag specifying whether LSS is supported (1) or not (0).
Definition: dev.c:67
co_unsigned32_t vendor_id
The vendor ID.
Definition: dev.c:53
co_unsigned32_t revision
The revision number.
Definition: dev.c:59
co_unsigned32_t dummy
The data types supported for mapping dummy entries in PDOs.
Definition: dev.c:69
char * name
A pointer to the name of the device.
Definition: dev.c:49
A CANopen object.
Definition: obj.h:32
A CANopen sub-object.
Definition: obj.h:54
An identity record.
Definition: dev.h:33
co_unsigned32_t product_code
Product code.
Definition: dev.h:39
co_unsigned32_t revision
Revision number.
Definition: dev.h:41
co_unsigned8_t n
Highest sub-index supported.
Definition: dev.h:35
co_unsigned32_t vendor_id
Vendor-ID.
Definition: dev.h:37
co_unsigned32_t serial_nr
Serial number.
Definition: dev.h:43
This header file is part of the CANopen library; it contains the CANopen type definitions.