Lely core libraries  2.3.4
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 
120 #define CO_OBJ_FLAGS_PARAMETER_VALUE 0x100
121 
123 struct co_sdo_req;
124 
125 #ifdef __cplusplus
126 extern "C" {
127 #endif
128 
142 typedef co_unsigned32_t co_sub_dn_ind_t(
143  co_sub_t *sub, struct co_sdo_req *req, void *data);
144 
157 typedef co_unsigned32_t co_sub_up_ind_t(
158  const co_sub_t *sub, struct co_sdo_req *req, void *data);
159 
160 #if !LELY_NO_MALLOC
161 void *__co_obj_alloc(void);
162 void __co_obj_free(void *ptr);
163 #endif
164 
165 struct __co_obj *__co_obj_init(struct __co_obj *obj, co_unsigned16_t idx,
166  void *val, size_t size);
167 void __co_obj_fini(struct __co_obj *obj);
168 
169 #if !LELY_NO_MALLOC
170 
181 co_obj_t *co_obj_create(co_unsigned16_t idx);
182 
184 void co_obj_destroy(co_obj_t *obj);
185 
186 #endif // !LELY_NO_MALLOC
187 
196 co_obj_t *co_obj_prev(const co_obj_t *obj);
197 
205 co_obj_t *co_obj_next(const co_obj_t *obj);
206 
208 co_dev_t *co_obj_get_dev(const co_obj_t *obj);
209 
211 co_unsigned16_t co_obj_get_idx(const co_obj_t *obj);
212 
224 co_unsigned8_t co_obj_get_subidx(const co_obj_t *obj, co_unsigned8_t maxsubidx,
225  co_unsigned8_t *subidx);
226 
239 int co_obj_insert_sub(co_obj_t *obj, co_sub_t *sub);
240 
251 int co_obj_remove_sub(co_obj_t *obj, co_sub_t *sub);
252 
263 co_sub_t *co_obj_find_sub(const co_obj_t *obj, co_unsigned8_t subidx);
264 
272 co_sub_t *co_obj_first_sub(const co_obj_t *obj);
273 
281 co_sub_t *co_obj_last_sub(const co_obj_t *obj);
282 
284 const char *co_obj_get_name(const co_obj_t *obj);
285 
294 int co_obj_set_name(co_obj_t *obj, const char *name);
295 
297 co_unsigned8_t co_obj_get_code(const co_obj_t *obj);
298 
312 int co_obj_set_code(co_obj_t *obj, co_unsigned8_t code);
313 
320 void *co_obj_addressof_val(const co_obj_t *obj);
321 
327 size_t co_obj_sizeof_val(const co_obj_t *obj);
328 
336 const void *co_obj_get_val(const co_obj_t *obj, co_unsigned8_t subidx);
337 
353 size_t co_obj_set_val(co_obj_t *obj, co_unsigned8_t subidx, const void *ptr,
354  size_t n);
355 
356 #define LELY_CO_DEFINE_TYPE(a, b, c, d) \
357  co_##b##_t co_obj_get_val_##c( \
358  const co_obj_t *obj, co_unsigned8_t subidx); \
359  size_t co_obj_set_val_##c( \
360  co_obj_t *obj, co_unsigned8_t subidx, co_##b##_t c);
361 #include <lely/co/def/basic.def>
362 #undef LELY_CO_DEFINE_TYPE
363 
377 void co_obj_set_dn_ind(co_obj_t *obj, co_sub_dn_ind_t *ind, void *data);
378 
389 void co_obj_set_up_ind(co_obj_t *obj, co_sub_up_ind_t *ind, void *data);
390 
391 #if !LELY_NO_MALLOC
392 void *__co_sub_alloc(void);
393 void __co_sub_free(void *ptr);
394 #endif
395 
396 struct __co_sub *__co_sub_init(struct __co_sub *sub, co_unsigned8_t subidx,
397  co_unsigned16_t type, void *val);
398 void __co_sub_fini(struct __co_sub *sub);
399 
400 #if !LELY_NO_MALLOC
401 
414 co_sub_t *co_sub_create(co_unsigned8_t subidx, co_unsigned16_t type);
415 
417 void co_sub_destroy(co_sub_t *sub);
418 
419 #endif // !LELY_NO_MALLOC
420 
429 co_sub_t *co_sub_prev(const co_sub_t *sub);
430 
439 co_sub_t *co_sub_next(const co_sub_t *sub);
440 
445 co_obj_t *co_sub_get_obj(const co_sub_t *sub);
446 
448 co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub);
449 
451 const char *co_sub_get_name(const co_sub_t *sub);
452 
461 int co_sub_set_name(co_sub_t *sub, const char *name);
462 
464 co_unsigned16_t co_sub_get_type(const co_sub_t *sub);
465 
473 const void *co_sub_addressof_min(const co_sub_t *sub);
474 
482 size_t co_sub_sizeof_min(const co_sub_t *sub);
483 
491 const void *co_sub_get_min(const co_sub_t *sub);
492 
507 size_t co_sub_set_min(co_sub_t *sub, const void *ptr, size_t n);
508 
516 const void *co_sub_addressof_max(const co_sub_t *sub);
517 
525 size_t co_sub_sizeof_max(const co_sub_t *sub);
526 
534 const void *co_sub_get_max(const co_sub_t *sub);
535 
550 size_t co_sub_set_max(co_sub_t *sub, const void *ptr, size_t n);
551 
558 const void *co_sub_addressof_def(const co_sub_t *sub);
559 
566 size_t co_sub_sizeof_def(const co_sub_t *sub);
567 
575 const void *co_sub_get_def(const co_sub_t *sub);
576 
591 size_t co_sub_set_def(co_sub_t *sub, const void *ptr, size_t n);
592 
599 const void *co_sub_addressof_val(const co_sub_t *sub);
600 
607 size_t co_sub_sizeof_val(const co_sub_t *sub);
608 
616 const void *co_sub_get_val(const co_sub_t *sub);
617 
632 size_t co_sub_set_val(co_sub_t *sub, const void *ptr, size_t n);
633 
634 #define LELY_CO_DEFINE_TYPE(a, b, c, d) \
635  co_##b##_t co_sub_get_val_##c(const co_sub_t *sub); \
636  size_t co_sub_set_val_##c(co_sub_t *sub, co_##b##_t c);
637 #include <lely/co/def/basic.def>
638 #undef LELY_CO_DEFINE_TYPE
639 
653 co_unsigned32_t co_sub_chk_val(
654  const co_sub_t *sub, co_unsigned16_t type, const void *val);
655 
657 unsigned int co_sub_get_access(const co_sub_t *sub);
658 
671 int co_sub_set_access(co_sub_t *sub, unsigned int access);
672 
679 int co_sub_get_pdo_mapping(const co_sub_t *sub);
680 
687 
689 unsigned int co_sub_get_flags(const co_sub_t *sub);
690 
692 void co_sub_set_flags(co_sub_t *sub, unsigned int flags);
693 
700 const char *co_sub_get_upload_file(const co_sub_t *sub);
701 
716 int co_sub_set_upload_file(co_sub_t *sub, const char *filename);
717 
724 const char *co_sub_get_download_file(const co_sub_t *sub);
725 
740 int co_sub_set_download_file(co_sub_t *sub, const char *filename);
741 
753 void co_sub_get_dn_ind(
754  const co_sub_t *sub, co_sub_dn_ind_t **pind, void **pdata);
755 
769 void co_sub_set_dn_ind(co_sub_t *sub, co_sub_dn_ind_t *ind, void *data);
770 
789 int co_sub_on_dn(co_sub_t *sub, struct co_sdo_req *req, co_unsigned32_t *pac);
790 
808 co_unsigned32_t co_sub_dn_ind(co_sub_t *sub, struct co_sdo_req *req);
809 
828 co_unsigned32_t co_sub_dn_ind_val(
829  co_sub_t *sub, co_unsigned16_t type, const void *val);
830 
846 int co_sub_dn(co_sub_t *sub, void *val);
847 
859 void co_sub_get_up_ind(
860  const co_sub_t *sub, co_sub_up_ind_t **pind, void **pdata);
861 
875 void co_sub_set_up_ind(co_sub_t *sub, co_sub_up_ind_t *ind, void *data);
876 
893 int co_sub_on_up(const co_sub_t *sub, struct co_sdo_req *req,
894  co_unsigned32_t *pac);
895 
908 co_unsigned32_t co_sub_up_ind(const co_sub_t *sub, struct co_sdo_req *req);
909 
910 #ifdef __cplusplus
911 }
912 #endif
913 
914 #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:786
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:172
int co_sub_set_name(co_sub_t *sub, const char *name)
Sets the name of a CANopen sub-object.
Definition: obj.c:578
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:138
co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub)
Returns the sub-index of a CANopen sub-object.
Definition: obj.c:559
void co_sub_destroy(co_sub_t *sub)
Destroys a CANopen sub-object.
Definition: obj.c:522
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:156
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:689
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:712
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:875
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:958
co_sub_t * co_sub_next(const co_sub_t *sub)
Finds the next sub-object in a CANopen object.
Definition: obj.c:542
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:1028
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:640
co_sub_t * co_sub_create(co_unsigned8_t subidx, co_unsigned16_t type)
Creates a CANopen sub-object.
Definition: obj.c:497
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
Definition: obj.c:164
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:652
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:671
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:903
const char * co_sub_get_name(const co_sub_t *sub)
Returns the name of a CANopen sub-object.
Definition: obj.c:568
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:613
const char * co_obj_get_name(const co_obj_t *obj)
Returns the name of a CANopen object.
Definition: obj.c:268
int co_obj_set_code(co_obj_t *obj, co_unsigned8_t code)
Sets the code (type) of a CANopen object.
Definition: obj.c:311
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:848
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:1066
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:683
void co_sub_set_flags(co_sub_t *sub, unsigned int flags)
Sets the object flags of a CANopen sub-object.
Definition: obj.c:826
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:974
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:892
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:258
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:802
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:700
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:646
void * co_obj_addressof_val(const co_obj_t *obj)
Returns the address of the value of a CANopen object.
Definition: obj.c:328
size_t co_sub_sizeof_def(const co_sub_t *sub)
Returns the size (in bytes) of the default value of a CANopen sub-object.
Definition: obj.c:677
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:1017
co_sub_t * co_sub_prev(const co_sub_t *sub)
Finds the previous sub-object in a CANopen object.
Definition: obj.c:533
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:718
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:996
co_unsigned8_t co_obj_get_code(const co_obj_t *obj)
Returns the object code of a CANopen object.
Definition: obj.c:303
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:658
unsigned int co_sub_get_flags(const co_sub_t *sub)
Returns the object flags of a CANopen sub-object.
Definition: obj.c:818
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:147
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:240
int co_obj_set_name(co_obj_t *obj, const char *name)
Sets the name of a CANopen object.
Definition: obj.c:278
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:631
size_t co_sub_sizeof_val(const co_sub_t *sub)
Returns the size (in bytes) of the current value of a CANopen sub-object.
Definition: obj.c:706
int co_obj_remove_sub(co_obj_t *obj, co_sub_t *sub)
Removes a sub-object from a CANopen object.
Definition: obj.c:217
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:912
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:340
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:810
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:249
void co_obj_destroy(co_obj_t *obj)
Destroys a CANopen object, including its sub-objects.
Definition: obj.c:126
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:157
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:142
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:389
int co_obj_insert_sub(co_obj_t *obj, co_sub_t *sub)
Inserts a sub-object into a CANopen object.
Definition: obj.c:192
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:863
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:551
co_obj_t * co_obj_create(co_unsigned16_t idx)
Creates a CANopen object.
Definition: obj.c:114
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:836
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:399
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:625
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:334
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:1039
unsigned int co_sub_get_access(const co_sub_t *sub)
Returns the access type of a CANopen sub-object.
Definition: obj.c:778
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:347
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:752
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:619
co_unsigned16_t co_sub_get_type(const co_sub_t *sub)
Returns the data type of a CANopen sub-object.
Definition: obj.c:603
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....
A CANopen device.
Definition: dev.h:30
A CANopen object.
Definition: obj.h:31
co_unsigned16_t idx
The object index.
Definition: obj.h:37
co_unsigned8_t code
The object code.
Definition: obj.h:39
size_t size
The size (in bytes) of the value at val.
Definition: obj.h:49
char * name
A pointer to the name of the object.
Definition: obj.h:42
void * val
A pointer to the object value.
Definition: obj.h:47
A CANopen sub-object.
Definition: obj.h:53
uint_least32_t pdo_mapping
A flag indicating if it is possible to map this object into a PDO.
Definition: obj.h:81
co_unsigned8_t subidx
The object sub-index.
Definition: obj.h:59
uint_least32_t access
The access type.
Definition: obj.h:79
char * name
A pointer to the name of the sub-object.
Definition: obj.h:64
co_unsigned16_t type
The data type.
Definition: obj.h:61
void * val
A pointer to the sub-object value.
Definition: obj.h:77
uint_least32_t flags
The object flags.
Definition: obj.h:83
A CANopen SDO upload/download request.
Definition: sdo.h:181
This header file is part of the CANopen library; it contains the CANopen type definitions.