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
123struct co_sdo_req;
124
125#ifdef __cplusplus
126extern "C" {
127#endif
128
142typedef co_unsigned32_t co_sub_dn_ind_t(
143 co_sub_t *sub, struct co_sdo_req *req, void *data);
144
157typedef 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
161void *__co_obj_alloc(void);
162void __co_obj_free(void *ptr);
163#endif
164
165struct __co_obj *__co_obj_init(struct __co_obj *obj, co_unsigned16_t idx,
166 void *val, size_t size);
167void __co_obj_fini(struct __co_obj *obj);
168
169#if !LELY_NO_MALLOC
170
181co_obj_t *co_obj_create(co_unsigned16_t idx);
182
184void co_obj_destroy(co_obj_t *obj);
185
186#endif // !LELY_NO_MALLOC
187
196co_obj_t *co_obj_prev(const co_obj_t *obj);
197
205co_obj_t *co_obj_next(const co_obj_t *obj);
206
208co_dev_t *co_obj_get_dev(const co_obj_t *obj);
209
211co_unsigned16_t co_obj_get_idx(const co_obj_t *obj);
212
224co_unsigned8_t co_obj_get_subidx(const co_obj_t *obj, co_unsigned8_t maxsubidx,
225 co_unsigned8_t *subidx);
226
239int co_obj_insert_sub(co_obj_t *obj, co_sub_t *sub);
240
251int co_obj_remove_sub(co_obj_t *obj, co_sub_t *sub);
252
263co_sub_t *co_obj_find_sub(const co_obj_t *obj, co_unsigned8_t subidx);
264
273
282
284const char *co_obj_get_name(const co_obj_t *obj);
285
294int co_obj_set_name(co_obj_t *obj, const char *name);
295
297co_unsigned8_t co_obj_get_code(const co_obj_t *obj);
298
312int co_obj_set_code(co_obj_t *obj, co_unsigned8_t code);
313
320void *co_obj_addressof_val(const co_obj_t *obj);
321
327size_t co_obj_sizeof_val(const co_obj_t *obj);
328
336const void *co_obj_get_val(const co_obj_t *obj, co_unsigned8_t subidx);
337
353size_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
377void co_obj_set_dn_ind(co_obj_t *obj, co_sub_dn_ind_t *ind, void *data);
378
389void co_obj_set_up_ind(co_obj_t *obj, co_sub_up_ind_t *ind, void *data);
390
391#if !LELY_NO_MALLOC
392void *__co_sub_alloc(void);
393void __co_sub_free(void *ptr);
394#endif
395
396struct __co_sub *__co_sub_init(struct __co_sub *sub, co_unsigned8_t subidx,
397 co_unsigned16_t type, void *val);
398void __co_sub_fini(struct __co_sub *sub);
399
400#if !LELY_NO_MALLOC
401
414co_sub_t *co_sub_create(co_unsigned8_t subidx, co_unsigned16_t type);
415
417void co_sub_destroy(co_sub_t *sub);
418
419#endif // !LELY_NO_MALLOC
420
429co_sub_t *co_sub_prev(const co_sub_t *sub);
430
439co_sub_t *co_sub_next(const co_sub_t *sub);
440
445co_obj_t *co_sub_get_obj(const co_sub_t *sub);
446
448co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub);
449
451const char *co_sub_get_name(const co_sub_t *sub);
452
461int co_sub_set_name(co_sub_t *sub, const char *name);
462
464co_unsigned16_t co_sub_get_type(const co_sub_t *sub);
465
473const void *co_sub_addressof_min(const co_sub_t *sub);
474
482size_t co_sub_sizeof_min(const co_sub_t *sub);
483
491const void *co_sub_get_min(const co_sub_t *sub);
492
507size_t co_sub_set_min(co_sub_t *sub, const void *ptr, size_t n);
508
516const void *co_sub_addressof_max(const co_sub_t *sub);
517
525size_t co_sub_sizeof_max(const co_sub_t *sub);
526
534const void *co_sub_get_max(const co_sub_t *sub);
535
550size_t co_sub_set_max(co_sub_t *sub, const void *ptr, size_t n);
551
558const void *co_sub_addressof_def(const co_sub_t *sub);
559
566size_t co_sub_sizeof_def(const co_sub_t *sub);
567
575const void *co_sub_get_def(const co_sub_t *sub);
576
591size_t co_sub_set_def(co_sub_t *sub, const void *ptr, size_t n);
592
599const void *co_sub_addressof_val(const co_sub_t *sub);
600
607size_t co_sub_sizeof_val(const co_sub_t *sub);
608
616const void *co_sub_get_val(const co_sub_t *sub);
617
632size_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
653co_unsigned32_t co_sub_chk_val(
654 const co_sub_t *sub, co_unsigned16_t type, const void *val);
655
657unsigned int co_sub_get_access(const co_sub_t *sub);
658
671int co_sub_set_access(co_sub_t *sub, unsigned int access);
672
679int co_sub_get_pdo_mapping(const co_sub_t *sub);
680
687
689unsigned int co_sub_get_flags(const co_sub_t *sub);
690
692void co_sub_set_flags(co_sub_t *sub, unsigned int flags);
693
700const char *co_sub_get_upload_file(const co_sub_t *sub);
701
716int co_sub_set_upload_file(co_sub_t *sub, const char *filename);
717
724const char *co_sub_get_download_file(const co_sub_t *sub);
725
740int co_sub_set_download_file(co_sub_t *sub, const char *filename);
741
754 const co_sub_t *sub, co_sub_dn_ind_t **pind, void **pdata);
755
769void co_sub_set_dn_ind(co_sub_t *sub, co_sub_dn_ind_t *ind, void *data);
770
789int co_sub_on_dn(co_sub_t *sub, struct co_sdo_req *req, co_unsigned32_t *pac);
790
808co_unsigned32_t co_sub_dn_ind(co_sub_t *sub, struct co_sdo_req *req);
809
828co_unsigned32_t co_sub_dn_ind_val(
829 co_sub_t *sub, co_unsigned16_t type, const void *val);
830
846int co_sub_dn(co_sub_t *sub, void *val);
847
860 const co_sub_t *sub, co_sub_up_ind_t **pind, void **pdata);
861
875void co_sub_set_up_ind(co_sub_t *sub, co_sub_up_ind_t *ind, void *data);
876
893int co_sub_on_up(const co_sub_t *sub, struct co_sdo_req *req,
894 co_unsigned32_t *pac);
895
908co_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_sub_t * co_sub_prev(const co_sub_t *sub)
Finds the previous sub-object in a CANopen object.
Definition: obj.c:533
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
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
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_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
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
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
void * co_obj_addressof_val(const co_obj_t *obj)
Returns the address of the value of a CANopen object.
Definition: obj.c:328
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
Definition: obj.c:164
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_get_def(const co_sub_t *sub)
Returns a pointer to the default value of a CANopen sub-object.
Definition: obj.c:683
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
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
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
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
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
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
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
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
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
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
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
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
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
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_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
co_unsigned8_t co_obj_get_code(const co_obj_t *obj)
Returns the object code of a CANopen object.
Definition: obj.c:303
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_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
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
int co_obj_set_name(co_obj_t *obj, const char *name)
Sets the name of a CANopen object.
Definition: obj.c:278
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
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
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
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_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
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
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
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
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
co_obj_t * co_obj_create(co_unsigned16_t idx)
Creates a CANopen object.
Definition: obj.c:114
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
co_sub_t * co_sub_next(const co_sub_t *sub)
Finds the next sub-object in a CANopen object.
Definition: obj.c:542
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
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
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
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_sub_t * co_sub_create(co_unsigned8_t subidx, co_unsigned16_t type)
Creates a CANopen sub-object.
Definition: obj.c:497
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
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
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.