Lely core libraries 1.9.2
obj.h
Go to the documentation of this file.
1
22#ifndef LELY_CO_OBJ_H_
23#define LELY_CO_OBJ_H_
24
25#include <lely/co/type.h>
26
27#include <stddef.h>
28
30#define CO_OBJECT_NULL 0x00
31
33#define CO_OBJECT_DOMAIN 0x02
34
36#define CO_OBJECT_DEFTYPE 0x05
37
39#define CO_OBJECT_DEFSTRUCT 0x06
40
42#define CO_OBJECT_VAR 0x07
43
48#define CO_OBJECT_ARRAY 0x08
49
54#define CO_OBJECT_RECORD 0x09
55
57#define CO_ACCESS_READ 0x01
58
60#define CO_ACCESS_WRITE 0x02
61
63#define CO_ACCESS_TPDO 0x04
64
66#define CO_ACCESS_RPDO 0x08
67
69#define CO_ACCESS_RO (CO_ACCESS_READ | CO_ACCESS_TPDO)
70
72#define CO_ACCESS_WO (CO_ACCESS_WRITE | CO_ACCESS_RPDO)
73
75#define CO_ACCESS_RW (CO_ACCESS_RO | CO_ACCESS_WO)
76
78#define CO_ACCESS_RWR (CO_ACCESS_RO | CO_ACCESS_WRITE)
79
81#define CO_ACCESS_RWW (CO_ACCESS_WO | CO_ACCESS_READ)
82
84#define CO_ACCESS_CONST (CO_ACCESS_RO | 0x10)
85
87#define CO_OBJ_FLAGS_READ 0x01
88
90#define CO_OBJ_FLAGS_WRITE 0x02
91
96#define CO_OBJ_FLAGS_UPLOAD_FILE 0x04
97
102#define CO_OBJ_FLAGS_DOWNLOAD_FILE 0x08
103
105#define CO_OBJ_FLAGS_MIN_NODEID 0x10
106
108#define CO_OBJ_FLAGS_MAX_NODEID 0x20
109
111#define CO_OBJ_FLAGS_DEF_NODEID 0x40
112
114#define CO_OBJ_FLAGS_VAL_NODEID 0x80
115
117struct co_sdo_req;
118
119#ifdef __cplusplus
120extern "C" {
121#endif
122
135typedef co_unsigned32_t co_sub_dn_ind_t(
136 co_sub_t *sub, struct co_sdo_req *req, void *data);
137
150typedef co_unsigned32_t co_sub_up_ind_t(
151 const co_sub_t *sub, struct co_sdo_req *req, void *data);
152
153void *__co_obj_alloc(void);
154void __co_obj_free(void *ptr);
155struct __co_obj *__co_obj_init(struct __co_obj *obj, co_unsigned16_t idx);
156void __co_obj_fini(struct __co_obj *obj);
157
168co_obj_t *co_obj_create(co_unsigned16_t idx);
169
171void co_obj_destroy(co_obj_t *obj);
172
174co_dev_t *co_obj_get_dev(const co_obj_t *obj);
175
177co_unsigned16_t co_obj_get_idx(const co_obj_t *obj);
178
190co_unsigned8_t co_obj_get_subidx(const co_obj_t *obj, co_unsigned8_t maxsubidx,
191 co_unsigned8_t *subidx);
192
205int co_obj_insert_sub(co_obj_t *obj, co_sub_t *sub);
206
217int co_obj_remove_sub(co_obj_t *obj, co_sub_t *sub);
218
229co_sub_t *co_obj_find_sub(const co_obj_t *obj, co_unsigned8_t subidx);
230
232const char *co_obj_get_name(const co_obj_t *obj);
233
242int co_obj_set_name(co_obj_t *obj, const char *name);
243
245co_unsigned8_t co_obj_get_code(const co_obj_t *obj);
246
260int co_obj_set_code(co_obj_t *obj, co_unsigned8_t code);
261
268void *co_obj_addressof_val(const co_obj_t *obj);
269
275size_t co_obj_sizeof_val(const co_obj_t *obj);
276
284const void *co_obj_get_val(const co_obj_t *obj, co_unsigned8_t subidx);
285
301size_t co_obj_set_val(co_obj_t *obj, co_unsigned8_t subidx, const void *ptr,
302 size_t n);
303
304#define LELY_CO_DEFINE_TYPE(a, b, c, d) \
305 co_##b##_t co_obj_get_val_##c( \
306 const co_obj_t *obj, co_unsigned8_t subidx); \
307 size_t co_obj_set_val_##c( \
308 co_obj_t *obj, co_unsigned8_t subidx, co_##b##_t c);
309#include <lely/co/def/basic.def>
310#undef LELY_CO_DEFINE_TYPE
311
325void co_obj_set_dn_ind(co_obj_t *obj, co_sub_dn_ind_t *ind, void *data);
326
337void co_obj_set_up_ind(co_obj_t *obj, co_sub_up_ind_t *ind, void *data);
338
339void *__co_sub_alloc(void);
340void __co_sub_free(void *ptr);
341struct __co_sub *__co_sub_init(struct __co_sub *sub, co_unsigned8_t subidx,
342 co_unsigned16_t type);
343void __co_sub_fini(struct __co_sub *sub);
344
357co_sub_t *co_sub_create(co_unsigned8_t subidx, co_unsigned16_t type);
358
360void co_sub_destroy(co_sub_t *sub);
361
366co_obj_t *co_sub_get_obj(const co_sub_t *sub);
367
369co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub);
370
372const char *co_sub_get_name(const co_sub_t *sub);
373
382int co_sub_set_name(co_sub_t *sub, const char *name);
383
385co_unsigned16_t co_sub_get_type(const co_sub_t *sub);
386
394const void *co_sub_addressof_min(const co_sub_t *sub);
395
403size_t co_sub_sizeof_min(const co_sub_t *sub);
404
412const void *co_sub_get_min(const co_sub_t *sub);
413
428size_t co_sub_set_min(co_sub_t *sub, const void *ptr, size_t n);
429
437const void *co_sub_addressof_max(const co_sub_t *sub);
438
446size_t co_sub_sizeof_max(const co_sub_t *sub);
447
455const void *co_sub_get_max(const co_sub_t *sub);
456
471size_t co_sub_set_max(co_sub_t *sub, const void *ptr, size_t n);
472
479const void *co_sub_addressof_def(const co_sub_t *sub);
480
487size_t co_sub_sizeof_def(const co_sub_t *sub);
488
496const void *co_sub_get_def(const co_sub_t *sub);
497
512size_t co_sub_set_def(co_sub_t *sub, const void *ptr, size_t n);
513
520const void *co_sub_addressof_val(const co_sub_t *sub);
521
528size_t co_sub_sizeof_val(const co_sub_t *sub);
529
537const void *co_sub_get_val(const co_sub_t *sub);
538
553size_t co_sub_set_val(co_sub_t *sub, const void *ptr, size_t n);
554
555#define LELY_CO_DEFINE_TYPE(a, b, c, d) \
556 co_##b##_t co_sub_get_val_##c(const co_sub_t *sub); \
557 size_t co_sub_set_val_##c(co_sub_t *sub, co_##b##_t c);
558#include <lely/co/def/basic.def>
559#undef LELY_CO_DEFINE_TYPE
560
574co_unsigned32_t co_sub_chk_val(
575 const co_sub_t *sub, co_unsigned16_t type, const void *val);
576
578unsigned int co_sub_get_access(const co_sub_t *sub);
579
592int co_sub_set_access(co_sub_t *sub, unsigned int access);
593
600int co_sub_get_pdo_mapping(const co_sub_t *sub);
601
608
610unsigned int co_sub_get_flags(const co_sub_t *sub);
611
613void co_sub_set_flags(co_sub_t *sub, unsigned int flags);
614
627 const co_sub_t *sub, co_sub_dn_ind_t **pind, void **pdata);
628
642void co_sub_set_dn_ind(co_sub_t *sub, co_sub_dn_ind_t *ind, void *data);
643
654co_unsigned32_t co_sub_on_dn(co_sub_t *sub, struct co_sdo_req *req);
655
673co_unsigned32_t co_sub_dn_ind(co_sub_t *sub, struct co_sdo_req *req);
674
693co_unsigned32_t co_sub_dn_ind_val(
694 co_sub_t *sub, co_unsigned16_t type, const void *val);
695
711int co_sub_dn(co_sub_t *sub, void *val);
712
725 const co_sub_t *sub, co_sub_up_ind_t **pind, void **pdata);
726
740void co_sub_set_up_ind(co_sub_t *sub, co_sub_up_ind_t *ind, void *data);
741
752co_unsigned32_t co_sub_on_up(const co_sub_t *sub, struct co_sdo_req *req);
753
766co_unsigned32_t co_sub_up_ind(const co_sub_t *sub, struct co_sdo_req *req);
767
768#ifdef __cplusplus
769}
770#endif
771
772#endif // !LELY_CO_OBJ_H_
int co_sub_set_access(co_sub_t *sub, unsigned int access)
Sets the access type of a CANopen sub-object.
Definition: obj.c:690
co_unsigned8_t co_obj_get_subidx(const co_obj_t *obj, co_unsigned8_t maxsubidx, co_unsigned8_t *subidx)
Retrieves a list of sub-indices in a CANopen object.
Definition: obj.c:144
int co_sub_set_name(co_sub_t *sub, const char *name)
Sets the name of a CANopen sub-object.
Definition: obj.c:484
co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub)
Returns the sub-index of a CANopen sub-object.
Definition: obj.c:466
void co_sub_destroy(co_sub_t *sub)
Destroys a CANopen sub-object.
Definition: obj.c:449
size_t co_sub_set_def(co_sub_t *sub, const void *ptr, size_t n)
Sets the default value of a CANopen sub-object.
Definition: obj.c:592
const void * co_sub_get_min(const co_sub_t *sub)
Returns a pointer to the lower limit of the value of a CANopen sub-object.
Definition: obj.c:530
co_unsigned32_t co_sub_dn_ind(co_sub_t *sub, struct co_sdo_req *req)
Invokes the download indication function of a CANopen sub-object, registered with co_sub_set_dn_ind()...
Definition: obj.c:794
void co_sub_set_up_ind(co_sub_t *sub, co_sub_up_ind_t *ind, void *data)
Sets the upload indication function for a CANopen sub-object.
Definition: obj.c:857
void * co_obj_addressof_val(const co_obj_t *obj)
Returns the address of the value of a CANopen object.
Definition: obj.c:275
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
Definition: obj.c:136
const char * co_sub_get_name(const co_sub_t *sub)
Returns the name of a CANopen sub-object.
Definition: obj.c:476
const void * co_sub_get_def(const co_sub_t *sub)
Returns a pointer to the default value of a CANopen sub-object.
Definition: obj.c:586
const void * co_sub_get_val(const co_sub_t *sub)
Returns a pointer to the current value of a CANopen sub-object.
Definition: obj.c:613
void co_sub_set_dn_ind(co_sub_t *sub, co_sub_dn_ind_t *ind, void *data)
Sets the download indication function for a CANopen sub-object.
Definition: obj.c:749
int co_obj_set_code(co_obj_t *obj, co_unsigned8_t code)
Sets the code (type) of a CANopen object.
Definition: obj.c:258
co_unsigned32_t co_sub_up_ind(const co_sub_t *sub, struct co_sdo_req *req)
Invokes the upload indication function of a CANopen sub-object, registered with co_sub_set_up_ind().
Definition: obj.c:890
void co_sub_set_flags(co_sub_t *sub, unsigned int flags)
Sets the object flags of a CANopen sub-object.
Definition: obj.c:730
co_unsigned32_t co_sub_on_dn(co_sub_t *sub, struct co_sdo_req *req)
Implements the default behavior when a download indication is received by a CANopen sub-object.
Definition: obj.c:758
co_unsigned32_t co_sub_dn_ind_val(co_sub_t *sub, co_unsigned16_t type, const void *val)
Invokes the download indication function of a CANopen sub-object, registered with co_sub_set_dn_ind()...
Definition: obj.c:810
void co_sub_get_dn_ind(const co_sub_t *sub, co_sub_dn_ind_t **pind, void **pdata)
Retrieves the download indication function for a CANopen sub-object.
Definition: obj.c:738
int co_sub_get_pdo_mapping(const co_sub_t *sub)
Returns 1 if it is possible to map the specified CANopen sub-object into a PDO, and 0 if not.
Definition: obj.c:706
size_t co_sub_sizeof_max(const co_sub_t *sub)
Returns size (in bytes) of the upper limit of the value of a CANopen sub-object.
Definition: obj.c:551
co_sub_t * co_obj_find_sub(const co_obj_t *obj, co_unsigned8_t subidx)
Finds a sub-object in a CANopen object.
Definition: obj.c:207
const void * co_sub_addressof_def(const co_sub_t *sub)
Returns the address of the default value of a CANopen sub-object.
Definition: obj.c:574
size_t co_sub_sizeof_def(const co_sub_t *sub)
Returns size (in bytes) of the default value of a CANopen sub-object.
Definition: obj.c:580
void co_sub_get_up_ind(const co_sub_t *sub, co_sub_up_ind_t **pind, void **pdata)
Retrieves the upload indication function for a CANopen sub-object.
Definition: obj.c:846
size_t co_sub_set_val(co_sub_t *sub, const void *ptr, size_t n)
Sets the current value of a CANopen sub-object.
Definition: obj.c:619
const void * co_obj_get_val(const co_obj_t *obj, co_unsigned8_t subidx)
Returns a pointer to the current value of a CANopen sub-object.
Definition: obj.c:287
const void * co_sub_addressof_max(const co_sub_t *sub)
Returns the address of the upper limit of the value of a CANopen sub-object.
Definition: obj.c:545
int co_sub_dn(co_sub_t *sub, void *val)
Downloads (moves) a value into a CANopen sub-object if the refuse-write-on-download flag (CO_OBJ_FLAG...
Definition: obj.c:832
co_unsigned8_t co_obj_get_code(const co_obj_t *obj)
Returns the object code of a CANopen object.
Definition: obj.c:250
const void * co_sub_addressof_val(const co_sub_t *sub)
Returns the address of the current value of a CANopen sub-object.
Definition: obj.c:601
size_t co_sub_set_max(co_sub_t *sub, const void *ptr, size_t n)
Sets the upper limit of a value of a CANopen sub-object.
Definition: obj.c:563
unsigned int co_sub_get_flags(const co_sub_t *sub)
Returns the object flags of a CANopen sub-object.
Definition: obj.c:722
int co_obj_set_name(co_obj_t *obj, const char *name)
Sets the name of a CANopen object.
Definition: obj.c:226
const void * co_sub_get_max(const co_sub_t *sub)
Returns a pointer to the upper limit of the value of a CANopen sub-object.
Definition: obj.c:557
size_t co_sub_set_min(co_sub_t *sub, const void *ptr, size_t n)
Sets the lower limit of a value of a CANopen sub-object.
Definition: obj.c:536
size_t co_sub_sizeof_val(const co_sub_t *sub)
Returns size (in bytes) of the current value of a CANopen sub-object.
Definition: obj.c:607
const char * co_obj_get_name(const co_obj_t *obj)
Returns the name of a CANopen object.
Definition: obj.c:218
int co_obj_remove_sub(co_obj_t *obj, co_sub_t *sub)
Removes a sub-object from a CANopen object.
Definition: obj.c:187
void co_sub_set_pdo_mapping(co_sub_t *sub, int pdo_mapping)
Enables or disables PDO mapping a CANopen sub-object.
Definition: obj.c:714
void co_obj_destroy(co_obj_t *obj)
Destroys a CANopen object, including its sub-objects.
Definition: obj.c:118
co_unsigned32_t co_sub_up_ind_t(const co_sub_t *sub, struct co_sdo_req *req, void *data)
The type of a CANopen sub-object upload indication function, invoked by an SDO upload request.
Definition: obj.h:150
co_unsigned32_t co_sub_dn_ind_t(co_sub_t *sub, struct co_sdo_req *req, void *data)
The type of a CANopen sub-object download indication function, invoked by an SDO download request or ...
Definition: obj.h:135
void co_obj_set_dn_ind(co_obj_t *obj, co_sub_dn_ind_t *ind, void *data)
Sets the download indication function for a CANopen object.
Definition: obj.c:336
co_dev_t * co_obj_get_dev(const co_obj_t *obj)
Returns a pointer to the CANopen device containing the specified object.
Definition: obj.c:128
int co_obj_insert_sub(co_obj_t *obj, co_sub_t *sub)
Inserts a sub-object into a CANopen object.
Definition: obj.c:164
co_obj_t * co_obj_create(co_unsigned16_t idx)
Creates a CANopen object.
Definition: obj.c:106
void co_obj_set_up_ind(co_obj_t *obj, co_sub_up_ind_t *ind, void *data)
Sets the upload indication function for a CANopen object.
Definition: obj.c:345
co_unsigned32_t co_sub_on_up(const co_sub_t *sub, struct co_sdo_req *req)
Implements the default behavior when an upload indication is received by a CANopen sub-object.
Definition: obj.c:866
co_obj_t * co_sub_get_obj(const co_sub_t *sub)
Returns the a pointer to the CANopen object containing the specified sub-object.
Definition: obj.c:458
size_t co_obj_sizeof_val(const co_obj_t *obj)
Returns size (in bytes) of the value of a CANopen object.
Definition: obj.c:281
unsigned int co_sub_get_access(const co_sub_t *sub)
Returns the access type of a CANopen sub-object.
Definition: obj.c:682
const void * co_sub_addressof_min(const co_sub_t *sub)
Returns the address of the lower limit of the value of a CANopen sub-object.
Definition: obj.c:518
size_t co_obj_set_val(co_obj_t *obj, co_unsigned8_t subidx, const void *ptr, size_t n)
Sets the current value of a CANopen sub-object.
Definition: obj.c:294
co_sub_t * co_sub_create(co_unsigned8_t subidx, co_unsigned16_t type)
Creates a CANopen sub-object.
Definition: obj.c:424
co_unsigned32_t co_sub_chk_val(const co_sub_t *sub, co_unsigned16_t type, const void *val)
Checks if the specifed value would be a valid value for a CANopen sub-object.
Definition: obj.c:656
size_t co_sub_sizeof_min(const co_sub_t *sub)
Returns size (in bytes) of the lower limit of the value of a CANopen sub-object.
Definition: obj.c:524
co_unsigned16_t co_sub_get_type(const co_sub_t *sub)
Returns the data type of a CANopen sub-object.
Definition: obj.c:508
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....
A CANopen device.
Definition: dev.c:38
A CANopen object.
Definition: obj.h:32
co_unsigned16_t idx
The object index.
Definition: obj.h:38
co_unsigned8_t code
The object code.
Definition: obj.h:40
char * name
A pointer to the name of the object.
Definition: obj.h:43
A CANopen sub-object.
Definition: obj.h:54
unsigned access
The access type.
Definition: obj.h:78
unsigned flags
The object flags.
Definition: obj.h:82
co_unsigned8_t subidx
The object sub-index.
Definition: obj.h:60
unsigned pdo_mapping
A flag indicating if it is possible to map this object into a PDO.
Definition: obj.h:80
char * name
A pointer to the name of the sub-object.
Definition: obj.h:65
co_unsigned16_t type
The data type.
Definition: obj.h:62
void * val
A pointer to the sub-object value.
Definition: obj.h:76
A CANopen SDO upload/download request.
Definition: sdo.h:178
This header file is part of the CANopen library; it contains the CANopen type definitions.