Lely core libraries 2.3.4
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
33struct 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
86extern "C" {
87#endif
88
97typedef void co_dev_tpdo_event_ind_t(co_unsigned16_t num, void *data);
98
109typedef void co_dev_sam_mpdo_event_ind_t(co_unsigned16_t num,
110 co_unsigned16_t idx, co_unsigned8_t subidx, void *data);
111
112#if !LELY_NO_MALLOC
113void *__co_dev_alloc(void);
114void __co_dev_free(void *ptr);
115#endif
116
117struct __co_dev *__co_dev_init(struct __co_dev *dev, co_unsigned8_t id);
118void __co_dev_fini(struct __co_dev *dev);
119
120#if !LELY_NO_MALLOC
121
133co_dev_t *co_dev_create(co_unsigned8_t id);
134
140void co_dev_destroy(co_dev_t *dev);
141
142#endif // !LELY_NO_MALLOC
143
145co_unsigned8_t co_dev_get_netid(const co_dev_t *dev);
146
155int co_dev_set_netid(co_dev_t *dev, co_unsigned8_t id);
156
158co_unsigned8_t co_dev_get_id(const co_dev_t *dev);
159
169int co_dev_set_id(co_dev_t *dev, co_unsigned8_t id);
170
183co_unsigned16_t co_dev_get_idx(const co_dev_t *dev, co_unsigned16_t maxidx,
184 co_unsigned16_t *idx);
185
198int co_dev_insert_obj(co_dev_t *dev, co_obj_t *obj);
199
210int co_dev_remove_obj(co_dev_t *dev, co_obj_t *obj);
211
222co_obj_t *co_dev_find_obj(const co_dev_t *dev, co_unsigned16_t idx);
223
233co_sub_t *co_dev_find_sub(const co_dev_t *dev, co_unsigned16_t idx,
234 co_unsigned8_t subidx);
235
246
257
258#if !LELY_NO_CO_OBJ_NAME
259
261const char *co_dev_get_name(const co_dev_t *dev);
262
271int co_dev_set_name(co_dev_t *dev, const char *name);
272
278const char *co_dev_get_vendor_name(const co_dev_t *dev);
279
288int co_dev_set_vendor_name(co_dev_t *dev, const char *vendor_name);
289
290#endif // !LELY_NO_CO_OBJ_NAME
291
293co_unsigned32_t co_dev_get_vendor_id(const co_dev_t *dev);
294
296void co_dev_set_vendor_id(co_dev_t *dev, co_unsigned32_t vendor_id);
297
298#if !LELY_NO_CO_OBJ_NAME
299
305const char *co_dev_get_product_name(const co_dev_t *dev);
306
315int co_dev_set_product_name(co_dev_t *dev, const char *product_name);
316
317#endif // !LELY_NO_CO_OBJ_NAME
318
320co_unsigned32_t co_dev_get_product_code(const co_dev_t *dev);
321
323void co_dev_set_product_code(co_dev_t *dev, co_unsigned32_t product_code);
324
326co_unsigned32_t co_dev_get_revision(const co_dev_t *dev);
327
329void co_dev_set_revision(co_dev_t *dev, co_unsigned32_t revision);
330
331#if !LELY_NO_CO_OBJ_NAME
332
338const char *co_dev_get_order_code(const co_dev_t *dev);
339
348int co_dev_set_order_code(co_dev_t *dev, const char *order_code);
349
350#endif // !LELY_NO_CO_OBJ_NAME
351
359unsigned int co_dev_get_baud(const co_dev_t *dev);
360
371void co_dev_set_baud(co_dev_t *dev, unsigned int baud);
372
378co_unsigned16_t co_dev_get_rate(const co_dev_t *dev);
379
388void co_dev_set_rate(co_dev_t *dev, co_unsigned16_t rate);
389
391int co_dev_get_lss(const co_dev_t *dev);
392
394void co_dev_set_lss(co_dev_t *dev, int lss);
395
402co_unsigned32_t co_dev_get_dummy(const co_dev_t *dev);
403
414void co_dev_set_dummy(co_dev_t *dev, co_unsigned32_t dummy);
415
423const void *co_dev_get_val(const co_dev_t *dev, co_unsigned16_t idx,
424 co_unsigned8_t subidx);
425
442size_t co_dev_set_val(co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx,
443 const void *ptr, size_t n);
444
445#define LELY_CO_DEFINE_TYPE(a, b, c, d) \
446 co_##b##_t co_dev_get_val_##c(const co_dev_t *dev, \
447 co_unsigned16_t idx, co_unsigned8_t subidx); \
448 size_t co_dev_set_val_##c(co_dev_t *dev, co_unsigned16_t idx, \
449 co_unsigned8_t subidx, co_##b##_t c);
450#include <lely/co/def/basic.def>
451#undef LELY_CO_DEFINE_TYPE
452
469size_t co_dev_read_sub(co_dev_t *dev, co_unsigned16_t *pidx,
470 co_unsigned8_t *psubidx, const uint_least8_t *begin,
471 const uint_least8_t *end);
472
492size_t co_dev_write_sub(const co_dev_t *dev, co_unsigned16_t idx,
493 co_unsigned8_t subidx, uint_least8_t *begin,
494 uint_least8_t *end);
495
513int co_dev_read_dcf(co_dev_t *dev, co_unsigned16_t *pmin, co_unsigned16_t *pmax,
514 void *const *ptr);
515
533int co_dev_read_dcf_file(co_dev_t *dev, co_unsigned16_t *pmin,
534 co_unsigned16_t *pmax, const char *filename);
535
551int co_dev_write_dcf(const co_dev_t *dev, co_unsigned16_t min,
552 co_unsigned16_t max, void **ptr);
553
568int co_dev_write_dcf_file(const co_dev_t *dev, co_unsigned16_t min,
569 co_unsigned16_t max, const char *filename);
570
584void co_dev_get_tpdo_event_ind(const co_dev_t *dev,
585 co_dev_tpdo_event_ind_t **pind, void **pdata);
586
600 co_dev_t *dev, co_dev_tpdo_event_ind_t *ind, void *data);
601
617 co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx);
618
632 co_dev_sam_mpdo_event_ind_t **pind, void **pdata);
633
646 co_dev_t *dev, co_dev_sam_mpdo_event_ind_t *ind, void *data);
647
662 co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx);
663
664#ifdef __cplusplus
665}
666#endif
667
668#endif // !LELY_CO_DEV_H_
void co_dev_sam_mpdo_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:939
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_get_sam_mpdo_event_ind(const co_dev_t *dev, co_dev_sam_mpdo_event_ind_t **pind, void **pdata)
Retrieves the indication function invoked by co_dev_sam_mpdo_event() when an event is indicated for (...
Definition: dev.c:917
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
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:306
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
void co_dev_set_sam_mpdo_event_ind(co_dev_t *dev, co_dev_sam_mpdo_event_ind_t *ind, void *data)
Sets the indication function invoked by co_dev_sam_mpdo_event() when an event is indicated for (a sub...
Definition: dev.c:929
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_destroy(co_dev_t *dev)
Destroys a CANopen device, including all objects in its object dictionary.
Definition: dev.c:163
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
void co_dev_sam_mpdo_event_ind_t(co_unsigned16_t num, co_unsigned16_t idx, co_unsigned8_t subidx, void *data)
The type of a CANopen source address mode multiplex PDO event indication function,...
Definition: dev.h:109
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
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:297
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
co_dev_t * co_dev_create(co_unsigned8_t id)
Creates a new CANopen device.
Definition: dev.c:138
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
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....
A CANopen device.
Definition: dev.h:30
co_unsigned32_t product_code
The product code.
Definition: dev.h:50
char * product_name
A pointer to the product name.
Definition: dev.h:47
co_unsigned16_t rate
The (pending) baudrate (in kbit/s).
Definition: dev.h:60
char * vendor_name
A pointer to the vendor name.
Definition: dev.h:41
char * order_code
A pointer to the order code.
Definition: dev.h:55
unsigned baud
The supported bit rates.
Definition: dev.h:58
int lss
A flag specifying whether LSS is supported (1) or not (0).
Definition: dev.h:62
co_unsigned32_t vendor_id
The vendor ID.
Definition: dev.h:44
co_unsigned32_t revision
The revision number.
Definition: dev.h:52
co_unsigned32_t dummy
The data types supported for mapping dummy entries in PDOs.
Definition: dev.h:64
char * name
A pointer to the name of the device.
Definition: dev.h:39
A CANopen object.
Definition: obj.h:31
A CANopen sub-object.
Definition: obj.h:53
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.