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 
117 struct co_sdo_req;
118 
119 #ifdef __cplusplus
120 extern "C" {
121 #endif
122 
135 typedef co_unsigned32_t co_sub_dn_ind_t(
136  co_sub_t *sub, struct co_sdo_req *req, void *data);
137 
150 typedef co_unsigned32_t co_sub_up_ind_t(
151  const co_sub_t *sub, struct co_sdo_req *req, void *data);
152 
153 void *__co_obj_alloc(void);
154 void __co_obj_free(void *ptr);
155 struct __co_obj *__co_obj_init(struct __co_obj *obj, co_unsigned16_t idx);
156 void __co_obj_fini(struct __co_obj *obj);
157 
168 co_obj_t *co_obj_create(co_unsigned16_t idx);
169 
171 void co_obj_destroy(co_obj_t *obj);
172 
174 co_dev_t *co_obj_get_dev(const co_obj_t *obj);
175 
177 co_unsigned16_t co_obj_get_idx(const co_obj_t *obj);
178 
190 co_unsigned8_t co_obj_get_subidx(const co_obj_t *obj, co_unsigned8_t maxsubidx,
191  co_unsigned8_t *subidx);
192 
205 int co_obj_insert_sub(co_obj_t *obj, co_sub_t *sub);
206 
217 int co_obj_remove_sub(co_obj_t *obj, co_sub_t *sub);
218 
229 co_sub_t *co_obj_find_sub(const co_obj_t *obj, co_unsigned8_t subidx);
230 
232 const char *co_obj_get_name(const co_obj_t *obj);
233 
242 int co_obj_set_name(co_obj_t *obj, const char *name);
243 
245 co_unsigned8_t co_obj_get_code(const co_obj_t *obj);
246 
260 int co_obj_set_code(co_obj_t *obj, co_unsigned8_t code);
261 
268 void *co_obj_addressof_val(const co_obj_t *obj);
269 
275 size_t co_obj_sizeof_val(const co_obj_t *obj);
276 
284 const void *co_obj_get_val(const co_obj_t *obj, co_unsigned8_t subidx);
285 
301 size_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 
325 void co_obj_set_dn_ind(co_obj_t *obj, co_sub_dn_ind_t *ind, void *data);
326 
337 void co_obj_set_up_ind(co_obj_t *obj, co_sub_up_ind_t *ind, void *data);
338 
339 void *__co_sub_alloc(void);
340 void __co_sub_free(void *ptr);
341 struct __co_sub *__co_sub_init(struct __co_sub *sub, co_unsigned8_t subidx,
342  co_unsigned16_t type);
343 void __co_sub_fini(struct __co_sub *sub);
344 
357 co_sub_t *co_sub_create(co_unsigned8_t subidx, co_unsigned16_t type);
358 
360 void co_sub_destroy(co_sub_t *sub);
361 
366 co_obj_t *co_sub_get_obj(const co_sub_t *sub);
367 
369 co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub);
370 
372 const char *co_sub_get_name(const co_sub_t *sub);
373 
382 int co_sub_set_name(co_sub_t *sub, const char *name);
383 
385 co_unsigned16_t co_sub_get_type(const co_sub_t *sub);
386 
394 const void *co_sub_addressof_min(const co_sub_t *sub);
395 
403 size_t co_sub_sizeof_min(const co_sub_t *sub);
404 
412 const void *co_sub_get_min(const co_sub_t *sub);
413 
428 size_t co_sub_set_min(co_sub_t *sub, const void *ptr, size_t n);
429 
437 const void *co_sub_addressof_max(const co_sub_t *sub);
438 
446 size_t co_sub_sizeof_max(const co_sub_t *sub);
447 
455 const void *co_sub_get_max(const co_sub_t *sub);
456 
471 size_t co_sub_set_max(co_sub_t *sub, const void *ptr, size_t n);
472 
479 const void *co_sub_addressof_def(const co_sub_t *sub);
480 
487 size_t co_sub_sizeof_def(const co_sub_t *sub);
488 
496 const void *co_sub_get_def(const co_sub_t *sub);
497 
512 size_t co_sub_set_def(co_sub_t *sub, const void *ptr, size_t n);
513 
520 const void *co_sub_addressof_val(const co_sub_t *sub);
521 
528 size_t co_sub_sizeof_val(const co_sub_t *sub);
529 
537 const void *co_sub_get_val(const co_sub_t *sub);
538 
553 size_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 
574 co_unsigned32_t co_sub_chk_val(
575  const co_sub_t *sub, co_unsigned16_t type, const void *val);
576 
578 unsigned int co_sub_get_access(const co_sub_t *sub);
579 
592 int co_sub_set_access(co_sub_t *sub, unsigned int access);
593 
600 int co_sub_get_pdo_mapping(const co_sub_t *sub);
601 
608 
610 unsigned int co_sub_get_flags(const co_sub_t *sub);
611 
613 void co_sub_set_flags(co_sub_t *sub, unsigned int flags);
614 
626 void co_sub_get_dn_ind(
627  const co_sub_t *sub, co_sub_dn_ind_t **pind, void **pdata);
628 
642 void co_sub_set_dn_ind(co_sub_t *sub, co_sub_dn_ind_t *ind, void *data);
643 
654 co_unsigned32_t co_sub_on_dn(co_sub_t *sub, struct co_sdo_req *req);
655 
673 co_unsigned32_t co_sub_dn_ind(co_sub_t *sub, struct co_sdo_req *req);
674 
693 co_unsigned32_t co_sub_dn_ind_val(
694  co_sub_t *sub, co_unsigned16_t type, const void *val);
695 
711 int co_sub_dn(co_sub_t *sub, void *val);
712 
724 void co_sub_get_up_ind(
725  const co_sub_t *sub, co_sub_up_ind_t **pind, void **pdata);
726 
740 void co_sub_set_up_ind(co_sub_t *sub, co_sub_up_ind_t *ind, void *data);
741 
752 co_unsigned32_t co_sub_on_up(const co_sub_t *sub, struct co_sdo_req *req);
753 
766 co_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_
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
A CANopen SDO upload/download request.
Definition: sdo.h:178
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
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
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_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
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 access
The access type.
Definition: obj.h:78
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
A CANopen sub-object.
Definition: obj.h:54
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
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
co_unsigned16_t type
The data type.
Definition: obj.h:62
int co_sub_set_name(co_sub_t *sub, const char *name)
Sets the name of a CANopen sub-object.
Definition: obj.c:484
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
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
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
unsigned flags
The object flags.
Definition: obj.h:82
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_obj_t * co_obj_create(co_unsigned16_t idx)
Creates a CANopen object.
Definition: obj.c:106
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
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
char * name
A pointer to the name of the sub-object.
Definition: obj.h:65
co_unsigned8_t code
The object code.
Definition: obj.h:40
co_unsigned8_t co_obj_get_code(const co_obj_t *obj)
Returns the object code of a CANopen object.
Definition: obj.c:250
void co_sub_destroy(co_sub_t *sub)
Destroys a CANopen sub-object.
Definition: obj.c:449
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
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
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
unsigned int co_sub_get_access(const co_sub_t *sub)
Returns the access type of a CANopen sub-object.
Definition: obj.c:682
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_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
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
void * val
A pointer to the sub-object value.
Definition: obj.h:76
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
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_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
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_pdo_mapping(co_sub_t *sub, int pdo_mapping)
Enables or disables PDO mapping a CANopen sub-object.
Definition: obj.c:714
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_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
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_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
This header file is part of the C11 and POSIX compatibility library; it includes <stddef.h> and defines any missing functionality.
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
co_unsigned16_t idx
The object index.
Definition: obj.h:38
unsigned int co_sub_get_flags(const co_sub_t *sub)
Returns the object flags of a CANopen sub-object.
Definition: obj.c:722
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
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
A CANopen device.
Definition: dev.c:38
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
co_unsigned8_t subidx
The object sub-index.
Definition: obj.h:60
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
void co_obj_destroy(co_obj_t *obj)
Destroys a CANopen object, including its sub-objects.
Definition: obj.c:118
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_sub_t * co_sub_create(co_unsigned8_t subidx, co_unsigned16_t type)
Creates a CANopen sub-object.
Definition: obj.c:424
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
int co_obj_set_name(co_obj_t *obj, const char *name)
Sets the name of a CANopen object.
Definition: obj.c:226
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 object.
Definition: obj.h:43
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
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 char * co_obj_get_name(const co_obj_t *obj)
Returns the name of a CANopen object.
Definition: obj.c:218
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
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
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
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
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
Definition: obj.c:136
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
const char * co_sub_get_name(const co_sub_t *sub)
Returns the name of a CANopen sub-object.
Definition: obj.c:476
A CANopen object.
Definition: obj.h:32
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
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
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_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
This header file is part of the CANopen library; it contains the CANopen type definitions.