Lely core libraries  2.2.5
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 
136 typedef co_unsigned32_t co_sub_dn_ind_t(
137  co_sub_t *sub, struct co_sdo_req *req, void *data);
138 
151 typedef co_unsigned32_t co_sub_up_ind_t(
152  const co_sub_t *sub, struct co_sdo_req *req, void *data);
153 
154 void *__co_obj_alloc(void);
155 void __co_obj_free(void *ptr);
156 struct __co_obj *__co_obj_init(struct __co_obj *obj, co_unsigned16_t idx);
157 void __co_obj_fini(struct __co_obj *obj);
158 
169 co_obj_t *co_obj_create(co_unsigned16_t idx);
170 
172 void co_obj_destroy(co_obj_t *obj);
173 
182 co_obj_t *co_obj_prev(const co_obj_t *obj);
183 
191 co_obj_t *co_obj_next(const co_obj_t *obj);
192 
194 co_dev_t *co_obj_get_dev(const co_obj_t *obj);
195 
197 co_unsigned16_t co_obj_get_idx(const co_obj_t *obj);
198 
210 co_unsigned8_t co_obj_get_subidx(const co_obj_t *obj, co_unsigned8_t maxsubidx,
211  co_unsigned8_t *subidx);
212 
225 int co_obj_insert_sub(co_obj_t *obj, co_sub_t *sub);
226 
237 int co_obj_remove_sub(co_obj_t *obj, co_sub_t *sub);
238 
249 co_sub_t *co_obj_find_sub(const co_obj_t *obj, co_unsigned8_t subidx);
250 
258 co_sub_t *co_obj_first_sub(const co_obj_t *obj);
259 
267 co_sub_t *co_obj_last_sub(const co_obj_t *obj);
268 
270 const char *co_obj_get_name(const co_obj_t *obj);
271 
280 int co_obj_set_name(co_obj_t *obj, const char *name);
281 
283 co_unsigned8_t co_obj_get_code(const co_obj_t *obj);
284 
298 int co_obj_set_code(co_obj_t *obj, co_unsigned8_t code);
299 
306 void *co_obj_addressof_val(const co_obj_t *obj);
307 
313 size_t co_obj_sizeof_val(const co_obj_t *obj);
314 
322 const void *co_obj_get_val(const co_obj_t *obj, co_unsigned8_t subidx);
323 
339 size_t co_obj_set_val(co_obj_t *obj, co_unsigned8_t subidx, const void *ptr,
340  size_t n);
341 
342 #define LELY_CO_DEFINE_TYPE(a, b, c, d) \
343  co_##b##_t co_obj_get_val_##c( \
344  const co_obj_t *obj, co_unsigned8_t subidx); \
345  size_t co_obj_set_val_##c( \
346  co_obj_t *obj, co_unsigned8_t subidx, co_##b##_t c);
347 #include <lely/co/def/basic.def>
348 #undef LELY_CO_DEFINE_TYPE
349 
363 void co_obj_set_dn_ind(co_obj_t *obj, co_sub_dn_ind_t *ind, void *data);
364 
375 void co_obj_set_up_ind(co_obj_t *obj, co_sub_up_ind_t *ind, void *data);
376 
377 void *__co_sub_alloc(void);
378 void __co_sub_free(void *ptr);
379 struct __co_sub *__co_sub_init(struct __co_sub *sub, co_unsigned8_t subidx,
380  co_unsigned16_t type);
381 void __co_sub_fini(struct __co_sub *sub);
382 
395 co_sub_t *co_sub_create(co_unsigned8_t subidx, co_unsigned16_t type);
396 
398 void co_sub_destroy(co_sub_t *sub);
399 
408 co_sub_t *co_sub_prev(const co_sub_t *sub);
409 
418 co_sub_t *co_sub_next(const co_sub_t *sub);
419 
424 co_obj_t *co_sub_get_obj(const co_sub_t *sub);
425 
427 co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub);
428 
430 const char *co_sub_get_name(const co_sub_t *sub);
431 
440 int co_sub_set_name(co_sub_t *sub, const char *name);
441 
443 co_unsigned16_t co_sub_get_type(const co_sub_t *sub);
444 
452 const void *co_sub_addressof_min(const co_sub_t *sub);
453 
461 size_t co_sub_sizeof_min(const co_sub_t *sub);
462 
470 const void *co_sub_get_min(const co_sub_t *sub);
471 
486 size_t co_sub_set_min(co_sub_t *sub, const void *ptr, size_t n);
487 
495 const void *co_sub_addressof_max(const co_sub_t *sub);
496 
504 size_t co_sub_sizeof_max(const co_sub_t *sub);
505 
513 const void *co_sub_get_max(const co_sub_t *sub);
514 
529 size_t co_sub_set_max(co_sub_t *sub, const void *ptr, size_t n);
530 
537 const void *co_sub_addressof_def(const co_sub_t *sub);
538 
545 size_t co_sub_sizeof_def(const co_sub_t *sub);
546 
554 const void *co_sub_get_def(const co_sub_t *sub);
555 
570 size_t co_sub_set_def(co_sub_t *sub, const void *ptr, size_t n);
571 
578 const void *co_sub_addressof_val(const co_sub_t *sub);
579 
586 size_t co_sub_sizeof_val(const co_sub_t *sub);
587 
595 const void *co_sub_get_val(const co_sub_t *sub);
596 
611 size_t co_sub_set_val(co_sub_t *sub, const void *ptr, size_t n);
612 
613 #define LELY_CO_DEFINE_TYPE(a, b, c, d) \
614  co_##b##_t co_sub_get_val_##c(const co_sub_t *sub); \
615  size_t co_sub_set_val_##c(co_sub_t *sub, co_##b##_t c);
616 #include <lely/co/def/basic.def>
617 #undef LELY_CO_DEFINE_TYPE
618 
632 co_unsigned32_t co_sub_chk_val(
633  const co_sub_t *sub, co_unsigned16_t type, const void *val);
634 
636 unsigned int co_sub_get_access(const co_sub_t *sub);
637 
650 int co_sub_set_access(co_sub_t *sub, unsigned int access);
651 
658 int co_sub_get_pdo_mapping(const co_sub_t *sub);
659 
666 
668 unsigned int co_sub_get_flags(const co_sub_t *sub);
669 
671 void co_sub_set_flags(co_sub_t *sub, unsigned int flags);
672 
679 const char *co_sub_get_upload_file(const co_sub_t *sub);
680 
695 int co_sub_set_upload_file(co_sub_t *sub, const char *filename);
696 
703 const char *co_sub_get_download_file(const co_sub_t *sub);
704 
719 int co_sub_set_download_file(co_sub_t *sub, const char *filename);
720 
732 void co_sub_get_dn_ind(
733  const co_sub_t *sub, co_sub_dn_ind_t **pind, void **pdata);
734 
748 void co_sub_set_dn_ind(co_sub_t *sub, co_sub_dn_ind_t *ind, void *data);
749 
768 int co_sub_on_dn(co_sub_t *sub, struct co_sdo_req *req, co_unsigned32_t *pac);
769 
787 co_unsigned32_t co_sub_dn_ind(co_sub_t *sub, struct co_sdo_req *req);
788 
807 co_unsigned32_t co_sub_dn_ind_val(
808  co_sub_t *sub, co_unsigned16_t type, const void *val);
809 
825 int co_sub_dn(co_sub_t *sub, void *val);
826 
838 void co_sub_get_up_ind(
839  const co_sub_t *sub, co_sub_up_ind_t **pind, void **pdata);
840 
854 void co_sub_set_up_ind(co_sub_t *sub, co_sub_up_ind_t *ind, void *data);
855 
872 int co_sub_on_up(const co_sub_t *sub, struct co_sdo_req *req,
873  co_unsigned32_t *pac);
874 
887 co_unsigned32_t co_sub_up_ind(const co_sub_t *sub, struct co_sdo_req *req);
888 
889 #ifdef __cplusplus
890 }
891 #endif
892 
893 #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:753
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:162
int co_sub_set_name(co_sub_t *sub, const char *name)
Sets the name of a CANopen sub-object.
Definition: obj.c:546
co_obj_t * co_obj_prev(const co_obj_t *obj)
Finds the previous object in the object dictionary of a CANopen device.
Definition: obj.c:128
co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub)
Returns the sub-index of a CANopen sub-object.
Definition: obj.c:528
void co_sub_destroy(co_sub_t *sub)
Destroys a CANopen sub-object.
Definition: obj.c:493
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:146
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:656
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:679
int co_sub_set_download_file(co_sub_t *sub, const char *filename)
Sets the value of the DownloadFile attribute of a CANopen sub-object.
Definition: obj.c:842
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:916
co_sub_t * co_sub_next(const co_sub_t *sub)
Finds the next sub-object in a CANopen object.
Definition: obj.c:511
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:981
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:607
co_sub_t * co_sub_create(co_unsigned8_t subidx, co_unsigned16_t type)
Creates a CANopen sub-object.
Definition: obj.c:468
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
Definition: obj.c:154
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:619
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:638
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:870
const char * co_sub_get_name(const co_sub_t *sub)
Returns the name of a CANopen sub-object.
Definition: obj.c:538
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:580
const char * co_obj_get_name(const co_obj_t *obj)
Returns the name of a CANopen object.
Definition: obj.c:254
int co_obj_set_code(co_obj_t *obj, co_unsigned8_t code)
Sets the code (type) of a CANopen object.
Definition: obj.c:294
int co_sub_set_upload_file(co_sub_t *sub, const char *filename)
Sets the value of the UploadFile attribute of a CANopen sub-object.
Definition: obj.c:815
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:1019
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:650
void co_sub_set_flags(co_sub_t *sub, unsigned int flags)
Sets the object flags of a CANopen sub-object.
Definition: obj.c:793
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:932
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:859
co_sub_t * co_obj_last_sub(const co_obj_t *obj)
Finds the last sub-object (with the highest sub-index) in a CANopen object.
Definition: obj.c:243
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:769
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:667
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:613
void * co_obj_addressof_val(const co_obj_t *obj)
Returns the address of the value of a CANopen object.
Definition: obj.c:311
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:644
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:970
co_sub_t * co_sub_prev(const co_sub_t *sub)
Finds the previous sub-object in a CANopen object.
Definition: obj.c:502
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:685
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:954
co_unsigned8_t co_obj_get_code(const co_obj_t *obj)
Returns the object code of a CANopen object.
Definition: obj.c:286
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:625
unsigned int co_sub_get_flags(const co_sub_t *sub)
Returns the object flags of a CANopen sub-object.
Definition: obj.c:785
co_obj_t * co_obj_next(const co_obj_t *obj)
Finds the next object in the object dictionary of a CANopen device.
Definition: obj.c:137
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:225
int co_obj_set_name(co_obj_t *obj, const char *name)
Sets the name of a CANopen object.
Definition: obj.c:262
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:598
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:673
int co_obj_remove_sub(co_obj_t *obj, co_sub_t *sub)
Removes a sub-object from a CANopen object.
Definition: obj.c:205
int co_sub_on_dn(co_sub_t *sub, struct co_sdo_req *req, co_unsigned32_t *pac)
Implements the default behavior when a download indication is received by a CANopen sub-object.
Definition: obj.c:879
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:323
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:777
co_sub_t * co_obj_first_sub(const co_obj_t *obj)
Finds the first sub-object (with the lowest sub-index) in a CANopen object.
Definition: obj.c:234
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 or Tran...
Definition: obj.h:151
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:136
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:372
int co_obj_insert_sub(co_obj_t *obj, co_sub_t *sub)
Inserts a sub-object into a CANopen object.
Definition: obj.c:182
const char * co_sub_get_download_file(const co_sub_t *sub)
Returns a pointer to the value of the DownloadFile attribute of a CANopen sub-object,...
Definition: obj.c:830
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:520
co_obj_t * co_obj_create(co_unsigned16_t idx)
Creates a CANopen object.
Definition: obj.c:106
const char * co_sub_get_upload_file(const co_sub_t *sub)
Returns a pointer to the value of the UploadFile attribute of a CANopen sub-object,...
Definition: obj.c:803
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:382
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:592
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:317
int co_sub_on_up(const co_sub_t *sub, struct co_sdo_req *req, co_unsigned32_t *pac)
Implements the default behavior when an upload indication is received by a CANopen sub-object.
Definition: obj.c:992
unsigned int co_sub_get_access(const co_sub_t *sub)
Returns the access type of a CANopen sub-object.
Definition: obj.c:745
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:330
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:719
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:586
co_unsigned16_t co_sub_get_type(const co_sub_t *sub)
Returns the data type of a CANopen sub-object.
Definition: obj.c:570
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....
A CANopen device.
Definition: dev.c:41
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 long flags
The object flags.
Definition: obj.h:84
co_unsigned8_t subidx
The object sub-index.
Definition: obj.h:60
unsigned long access
The access type.
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:78
unsigned long pdo_mapping
A flag indicating if it is possible to map this object into a PDO.
Definition: obj.h:82
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.