22 #ifndef LELY_CO_OBJ_HPP_ 23 #define LELY_CO_OBJ_HPP_ 26 #error "include <lely/co/obj.h> for the C interface" 39 template <co_
unsigned16_t>
41 template <co_
unsigned16_t>
55 return __co_obj_alloc();
58 free(
void* ptr) noexcept {
63 init(pointer p, co_unsigned16_t idx) noexcept {
64 return __co_obj_init(p, idx);
68 fini(pointer p) noexcept {
78 explicit COObj(co_unsigned16_t idx) : c_base(idx) {}
81 getDev()
const noexcept {
86 getIdx()
const noexcept {
91 getSubidx(co_unsigned8_t maxsubidx, co_unsigned8_t* subidx)
const noexcept {
95 ::std::vector<co_unsigned8_t>
97 std::vector<co_unsigned8_t> subidx(getSubidx(0, 0));
98 getSubidx(subidx.size(), subidx.data());
103 insert(
COSub* sub) noexcept {
107 remove(
COSub* sub) noexcept {
112 find(co_unsigned8_t subidx)
const noexcept {
117 getName()
const noexcept {
122 setName(
const char* name) noexcept {
127 getCode()
const noexcept {
132 setCode(co_unsigned8_t code) noexcept {
136 template <co_
unsigned16_t N>
138 getVal(co_unsigned8_t subidx)
const noexcept {
143 setVal(co_unsigned8_t subidx,
const void* ptr, ::std::size_t n) noexcept {
147 template <co_
unsigned16_t N>
149 setVal(co_unsigned8_t subidx,
const COVal<N>& val) noexcept {
150 return setVal(subidx, val.address(), val.size());
155 setVal(co_unsigned8_t subidx,
const T& val) noexcept {
156 return setVal<co_type_traits_T<T>::index>(subidx, val);
166 setDnInd(F* f) noexcept {
170 template <class C, typename c_mem_fn<co_sub_dn_ind_t*, C>::type M>
172 setDnInd(C* obj) noexcept {
174 static_cast<void*>(obj));
184 setUpInd(F* f) noexcept {
188 template <class C, typename c_mem_fn<co_sub_up_ind_t*, C>::type M>
190 setUpInd(C* obj) noexcept {
192 static_cast<void*>(obj));
210 return __co_sub_alloc();
213 free(
void* ptr) noexcept {
218 init(pointer p, co_unsigned8_t subidx, co_unsigned16_t type) noexcept {
219 return __co_sub_init(p, subidx, type);
223 fini(pointer p) noexcept {
233 COSub(co_unsigned8_t subidx, co_unsigned16_t type) : c_base(subidx, type) {}
236 getObj()
const noexcept {
241 getSubidx()
const noexcept {
246 getName()
const noexcept {
251 setName(
const char* name) noexcept {
256 getType()
const noexcept {
261 addressofMin()
const noexcept {
266 sizeofMin()
const noexcept {
270 template <co_
unsigned16_t N>
272 getMin()
const noexcept {
277 setMin(
const void* ptr, ::std::size_t n) noexcept {
281 template <co_
unsigned16_t N>
283 setMin(
const COVal<N>& val) noexcept {
284 return setMin(val.address(), val.size());
289 setMin(
const T& val) noexcept {
290 return setMin<co_type_traits_T<T>::index>(val);
294 addressofMax()
const noexcept {
299 sizeofMax()
const noexcept {
303 template <co_
unsigned16_t N>
305 getMax()
const noexcept {
310 setMax(
const void* ptr, ::std::size_t n) noexcept {
314 template <co_
unsigned16_t N>
316 setMax(
const COVal<N>& val) noexcept {
317 return setMax(val.address(), val.size());
322 setMax(
const T& val) noexcept {
323 return setMax<co_type_traits_T<T>::index>(val);
327 addressofDef()
const noexcept {
332 sizeofDef()
const noexcept {
336 template <co_
unsigned16_t N>
338 getDef()
const noexcept {
343 setDef(
const void* ptr, ::std::size_t n) noexcept {
347 template <co_
unsigned16_t N>
349 setDef(
const COVal<N>& val) noexcept {
350 return setDef(val.address(), val.size());
355 setDef(
const T& val) noexcept {
356 return setDef<co_type_traits_T<T>::index>(val);
360 addressofVal()
const noexcept {
365 sizeofVal()
const noexcept {
369 template <co_
unsigned16_t N>
371 getVal()
const noexcept {
376 setVal(
const void* ptr, ::std::size_t n) noexcept {
380 template <co_
unsigned16_t N>
382 setVal(
const COVal<N>& val) noexcept {
383 return setVal(val.address(), val.size());
388 setVal(
const T& val) noexcept {
389 return setVal<co_type_traits_T<T>::index>(val);
392 template <co_
unsigned16_t N>
394 chkVal(
const COVal<N>& val)
const noexcept {
400 chkVal(
const T& val)
const noexcept {
401 return chkVal<co_type_traits_T<T>::index>(val);
405 getAccess()
const noexcept {
410 setAccess(
unsigned int access) noexcept {
415 getPDOMapping()
const noexcept {
420 setPDOMapping(
unsigned int pdo_mapping) noexcept {
425 getFlags()
const noexcept {
430 setFlags(
unsigned int flags) noexcept {
435 getUploadFile()
const noexcept {
440 setUploadFile(
const char* filename) noexcept {
445 getDownloadFile()
const noexcept {
450 setDownloadFile(
const char* filename) noexcept {
464 template <co_unsigned16_t N, typename COSubDnInd<N>::type M>
466 setDnInd(
void* data) noexcept {
470 template <co_
unsigned16_t N,
class F>
472 setDnInd(F* f) noexcept {
475 static_cast<void*>(f));
478 template <co_unsigned16_t N,
class C,
481 setDnInd(C* obj) noexcept {
484 static_cast<void*>(obj));
488 onDn(
co_sdo_req& req, co_unsigned32_t* pac) noexcept {
497 template <co_
unsigned16_t N>
499 dnInd(
const COVal<N>& val) noexcept {
503 template <co_
unsigned16_t N>
519 template <co_unsigned16_t N, typename COSubUpInd<N>::type M>
521 setUpInd(
void* data) noexcept {
525 template <co_
unsigned16_t N,
class F>
527 setUpInd(F* f) noexcept {
530 static_cast<void*>(f));
533 template <co_unsigned16_t N,
class C,
536 setUpInd(C* obj) noexcept {
539 static_cast<void*>(obj));
543 onUp(
co_sdo_req& req, co_unsigned32_t* pac)
const noexcept {
561 template <co_
unsigned16_t N>
563 typedef co_unsigned32_t (*type)(
COSub* sub,
COVal<N>& val,
void* data);
566 static co_unsigned32_t
568 co_unsigned32_t ac = 0;
573 if ((ac = sub->chkVal(val)))
return ac;
575 if ((ac = (*M)(sub, val, data)))
return ac;
587 template <co_
unsigned16_t N>
589 typedef co_unsigned32_t (*type)(
const COSub* sub,
COVal<N>& val,
void* data);
592 static co_unsigned32_t
594 co_unsigned32_t ac = 0;
598 if ((ac = (*M)(sub, val, data)))
return ac;
607 #endif // !LELY_CO_OBJ_HPP_ A CANopen CANopen sub-object upload indication callback wrapper.
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.
A CANopen SDO upload/download request.
int co_obj_insert_sub(co_obj_t *obj, co_sub_t *sub)
Inserts a sub-object into a CANopen object.
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, or NULL if the attribute does not exist.
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.
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.
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()...
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...
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.
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.
int co_sub_set_name(co_sub_t *sub, const char *name)
Sets the name of a CANopen sub-object.
size_t co_sub_sizeof_def(const co_sub_t *sub)
Returns size (in bytes) of the default value of a CANopen sub-object.
int co_obj_set_code(co_obj_t *obj, co_unsigned8_t code)
Sets the code (type) of a CANopen object.
void co_sub_set_flags(co_sub_t *sub, unsigned int flags)
Sets the object flags of a CANopen sub-object.
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...
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.
int co_sdo_req_up_val(struct co_sdo_req *req, co_unsigned16_t type, const void *val, co_unsigned32_t *pac)
Writes the specified value to a buffer and constructs a CANopen SDO upload request.
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.
const void * co_sub_get_def(const co_sub_t *sub)
Returns a pointer to the default value of a CANopen sub-object.
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.
The base class for a C++ interface to an incomplete C type.
An opaque CANopen device type.
co_unsigned8_t co_obj_get_code(const co_obj_t *obj)
Returns the object code of a CANopen object.
This header file is part of the CANopen library; it contains the Service Data Object (SDO) declaratio...
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...
This header file is part of the CANopen library; it contains the C++ interface of the CANopen value d...
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.
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.
const void * co_sub_addressof_def(const co_sub_t *sub)
Returns the address of the default value of a CANopen sub-object.
unsigned int co_sub_get_access(const co_sub_t *sub)
Returns the access type of a CANopen sub-object.
int co_obj_remove_sub(co_obj_t *obj, co_sub_t *sub)
Removes a sub-object from a CANopen object.
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.
An opaque CANopen object type.
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.
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.
This header file is part of the utilities library; it contains the C to C++ interface declarations...
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.
const void * co_sub_get_val(const co_sub_t *sub)
Returns a pointer to the current value of a CANopen sub-object.
void co_sub_set_pdo_mapping(co_sub_t *sub, int pdo_mapping)
Enables or disables PDO mapping a CANopen sub-object.
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.
An opaque CANopen sub-object type.
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().
co_dev_t * co_obj_get_dev(const co_obj_t *obj)
Returns a pointer to the CANopen device containing the specified object.
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, or NULL if the attribute does not exist.
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...
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.
unsigned int co_sub_get_flags(const co_sub_t *sub)
Returns the object flags of a CANopen sub-object.
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.
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.
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.
const void * co_sub_addressof_val(const co_sub_t *sub)
Returns the address of the current value of a CANopen sub-object.
int co_sub_set_access(co_sub_t *sub, unsigned int access)
Sets the access type of a CANopen sub-object.
int co_sdo_req_dn_val(struct co_sdo_req *req, co_unsigned16_t type, void *val, co_unsigned32_t *pac)
Copies the next segment of the specified CANopen SDO download request to the internal buffer and...
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.
int co_obj_set_name(co_obj_t *obj, const char *name)
Sets the name of a CANopen object.
A CANopen CANopen sub-object download indication callback wrapper.
co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub)
Returns the sub-index of a CANopen sub-object.
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.
const char * co_obj_get_name(const co_obj_t *obj)
Returns the name of a CANopen object.
size_t co_sub_sizeof_val(const co_sub_t *sub)
Returns size (in bytes) of the current value of a CANopen sub-object.
co_unsigned16_t co_sub_get_type(const co_sub_t *sub)
Returns the data type of a CANopen sub-object.
co_sub_t * co_obj_find_sub(const co_obj_t *obj, co_unsigned8_t subidx)
Finds a sub-object in a CANopen object.
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()...
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
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.
const char * co_sub_get_name(const co_sub_t *sub)
Returns the name of a CANopen sub-object.
This header file is part of the CANopen library; it contains the object dictionary declarations...
This header file is part of the utilities library; it contains the C callback wrapper declarations...
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...
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.
A class template supplying a uniform interface to certain attributes of C types.
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 ...