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
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
89void *__co_dev_alloc(void);
90void __co_dev_free(void *ptr);
91struct __co_dev *__co_dev_init(struct __co_dev *dev, co_unsigned8_t id);
92void __co_dev_fini(struct __co_dev *dev);
93
104co_dev_t *co_dev_create(co_unsigned8_t id);
105
111void co_dev_destroy(co_dev_t *dev);
112
114co_unsigned8_t co_dev_get_netid(const co_dev_t *dev);
115
124int co_dev_set_netid(co_dev_t *dev, co_unsigned8_t id);
125
127co_unsigned8_t co_dev_get_id(const co_dev_t *dev);
128
138int co_dev_set_id(co_dev_t *dev, co_unsigned8_t id);
139
152co_unsigned16_t co_dev_get_idx(const co_dev_t *dev, co_unsigned16_t maxidx,
153 co_unsigned16_t *idx);
154
167int co_dev_insert_obj(co_dev_t *dev, co_obj_t *obj);
168
179int co_dev_remove_obj(co_dev_t *dev, co_obj_t *obj);
180
191co_obj_t *co_dev_find_obj(const co_dev_t *dev, co_unsigned16_t idx);
192
202co_sub_t *co_dev_find_sub(const co_dev_t *dev, co_unsigned16_t idx,
203 co_unsigned8_t subidx);
204
206const char *co_dev_get_name(const co_dev_t *dev);
207
216int co_dev_set_name(co_dev_t *dev, const char *name);
217
223const char *co_dev_get_vendor_name(const co_dev_t *dev);
224
233int co_dev_set_vendor_name(co_dev_t *dev, const char *vendor_name);
234
236co_unsigned32_t co_dev_get_vendor_id(const co_dev_t *dev);
237
239void co_dev_set_vendor_id(co_dev_t *dev, co_unsigned32_t vendor_id);
240
246const char *co_dev_get_product_name(const co_dev_t *dev);
247
256int co_dev_set_product_name(co_dev_t *dev, const char *product_name);
257
259co_unsigned32_t co_dev_get_product_code(const co_dev_t *dev);
260
262void co_dev_set_product_code(co_dev_t *dev, co_unsigned32_t product_code);
263
265co_unsigned32_t co_dev_get_revision(const co_dev_t *dev);
266
268void co_dev_set_revision(co_dev_t *dev, co_unsigned32_t revision);
269
275const char *co_dev_get_order_code(const co_dev_t *dev);
276
285int co_dev_set_order_code(co_dev_t *dev, const char *order_code);
286
294unsigned int co_dev_get_baud(const co_dev_t *dev);
295
306void co_dev_set_baud(co_dev_t *dev, unsigned int baud);
307
313co_unsigned16_t co_dev_get_rate(const co_dev_t *dev);
314
323void co_dev_set_rate(co_dev_t *dev, co_unsigned16_t rate);
324
326int co_dev_get_lss(const co_dev_t *dev);
327
329void co_dev_set_lss(co_dev_t *dev, int lss);
330
337co_unsigned32_t co_dev_get_dummy(const co_dev_t *dev);
338
349void co_dev_set_dummy(co_dev_t *dev, co_unsigned32_t dummy);
350
358const void *co_dev_get_val(const co_dev_t *dev, co_unsigned16_t idx,
359 co_unsigned8_t subidx);
360
377size_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
404size_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
426size_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
446int co_dev_read_dcf(co_dev_t *dev, co_unsigned16_t *pmin, co_unsigned16_t *pmax,
447 void *const *ptr);
448
466int co_dev_read_dcf_file(co_dev_t *dev, co_unsigned16_t *pmin,
467 co_unsigned16_t *pmax, const char *filename);
468
484int co_dev_write_dcf(const co_dev_t *dev, co_unsigned16_t min,
485 co_unsigned16_t max, void **ptr);
486
501int 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_
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:224
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:682
co_unsigned8_t co_dev_get_id(const co_dev_t *dev)
Returns the node-ID of a CANopen device.
Definition: dev.c:198
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
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
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_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
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
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
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
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
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
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
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
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:481
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
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:776
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
int co_dev_get_lss(const co_dev_t *dev)
Returns 1 if LSS is supported and 0 if not.
Definition: dev.c:497
co_unsigned8_t co_dev_get_netid(const co_dev_t *dev)
Returns the network-ID of a CANopen device.
Definition: dev.c:175
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
void co_dev_set_lss(co_dev_t *dev, int lss)
Sets the LSS support flag.
Definition: dev.c:505
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_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
const char * co_dev_get_name(const co_dev_t *dev)
Returns the name of a CANopen device.
Definition: dev.c:297
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:851
void co_dev_destroy(co_dev_t *dev)
Destroys a CANopen device, including all objects in its object dictionary.
Definition: dev.c:166
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
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
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:465
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
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
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
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
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
co_dev_t * co_dev_create(co_unsigned8_t id)
Creates a new CANopen device.
Definition: dev.c:141
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
int co_dev_set_name(co_dev_t *dev, const char *name)
Sets the name of a CANopen device.
Definition: dev.c:305
co_unsigned32_t co_dev_get_revision(const co_dev_t *dev)
Returns the revision number of a CANopen device.
Definition: dev.c:419
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....
A CANopen device.
Definition: dev.c:38
co_unsigned32_t product_code
The product code.
Definition: dev.c:54
char * product_name
A pointer to the product name.
Definition: dev.c:52
co_unsigned16_t rate
The (pending) baudrate (in kbit/s).
Definition: dev.c:62
char * vendor_name
A pointer to the vendor name.
Definition: dev.c:48
char * order_code
A pointer to the order code.
Definition: dev.c:58
unsigned baud
The supported bit rates.
Definition: dev.c:60
int lss
A flag specifying whether LSS is supported (1) or not (0).
Definition: dev.c:64
co_unsigned32_t vendor_id
The vendor ID.
Definition: dev.c:50
co_unsigned32_t revision
The revision number.
Definition: dev.c:56
co_unsigned32_t dummy
The data types supported for mapping dummy entries in PDOs.
Definition: dev.c:66
char * name
A pointer to the name of the device.
Definition: dev.c:46
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.