22#ifndef LELY_CO_OBJ_HPP_
23#define LELY_CO_OBJ_HPP_
25#if !defined(__cplusplus) || LELY_NO_CXX
26#error "include <lely/co/obj.h> for the C interface"
39template <co_
unsigned16_t>
41template <co_
unsigned16_t>
55 return __co_obj_alloc();
59 free(
void* ptr)
noexcept {
64 init(
pointer p, co_unsigned16_t idx)
noexcept {
65 return __co_obj_init(p, idx, 0, 0);
79 explicit COObj(co_unsigned16_t idx) :
c_base(idx) {}
82 getDev()
const noexcept {
87 getIdx()
const noexcept {
92 getSubidx(co_unsigned8_t maxsubidx, co_unsigned8_t* subidx)
const noexcept {
96 ::std::vector<co_unsigned8_t>
98 std::vector<co_unsigned8_t> subidx(getSubidx(0, 0));
99 getSubidx(subidx.size(), subidx.data());
104 insert(
COSub* sub)
noexcept {
108 remove(
COSub* sub)
noexcept {
113 find(co_unsigned8_t subidx)
const noexcept {
118 getName()
const noexcept {
123 setName(
const char* name)
noexcept {
128 getCode()
const noexcept {
133 setCode(co_unsigned8_t code)
noexcept {
137 template <co_
unsigned16_t N>
139 getVal(co_unsigned8_t subidx)
const noexcept {
144 setVal(co_unsigned8_t subidx,
const void* ptr, ::std::size_t n)
noexcept {
148 template <co_
unsigned16_t N>
150 setVal(co_unsigned8_t subidx,
const COVal<N>& val)
noexcept {
151 return setVal(subidx, val.address(), val.size());
156 setVal(co_unsigned8_t subidx,
const T& val)
noexcept {
157 return setVal<co_type_traits_T<T>::index>(subidx, val);
167 setDnInd(F* f)
noexcept {
171 template <class C, typename c_mem_fn<co_sub_dn_ind_t*, C>::type M>
173 setDnInd(C* obj)
noexcept {
175 static_cast<void*
>(obj));
185 setUpInd(F* f)
noexcept {
189 template <class C, typename c_mem_fn<co_sub_up_ind_t*, C>::type M>
191 setUpInd(C* obj)
noexcept {
193 static_cast<void*
>(obj));
211 return __co_sub_alloc();
215 free(
void* ptr)
noexcept {
220 init(
pointer p, co_unsigned8_t subidx, co_unsigned16_t type)
noexcept {
221 return __co_sub_init(p, subidx, type, 0);
235 COSub(co_unsigned8_t subidx, co_unsigned16_t type) :
c_base(subidx, type) {}
238 getObj()
const noexcept {
243 getSubidx()
const noexcept {
248 getName()
const noexcept {
253 setName(
const char* name)
noexcept {
258 getType()
const noexcept {
263 addressofMin()
const noexcept {
268 sizeofMin()
const noexcept {
272 template <co_
unsigned16_t N>
274 getMin()
const noexcept {
279 setMin(
const void* ptr, ::std::size_t n)
noexcept {
283 template <co_
unsigned16_t N>
285 setMin(
const COVal<N>& val)
noexcept {
286 return setMin(val.address(), val.size());
291 setMin(
const T& val)
noexcept {
292 return setMin<co_type_traits_T<T>::index>(val);
296 addressofMax()
const noexcept {
301 sizeofMax()
const noexcept {
305 template <co_
unsigned16_t N>
307 getMax()
const noexcept {
312 setMax(
const void* ptr, ::std::size_t n)
noexcept {
316 template <co_
unsigned16_t N>
318 setMax(
const COVal<N>& val)
noexcept {
319 return setMax(val.address(), val.size());
324 setMax(
const T& val)
noexcept {
325 return setMax<co_type_traits_T<T>::index>(val);
329 addressofDef()
const noexcept {
334 sizeofDef()
const noexcept {
338 template <co_
unsigned16_t N>
340 getDef()
const noexcept {
345 setDef(
const void* ptr, ::std::size_t n)
noexcept {
349 template <co_
unsigned16_t N>
351 setDef(
const COVal<N>& val)
noexcept {
352 return setDef(val.address(), val.size());
357 setDef(
const T& val)
noexcept {
358 return setDef<co_type_traits_T<T>::index>(val);
362 addressofVal()
const noexcept {
367 sizeofVal()
const noexcept {
371 template <co_
unsigned16_t N>
373 getVal()
const noexcept {
378 setVal(
const void* ptr, ::std::size_t n)
noexcept {
382 template <co_
unsigned16_t N>
384 setVal(
const COVal<N>& val)
noexcept {
385 return setVal(val.address(), val.size());
390 setVal(
const T& val)
noexcept {
391 return setVal<co_type_traits_T<T>::index>(val);
394 template <co_
unsigned16_t N>
396 chkVal(
const COVal<N>& val)
const noexcept {
402 chkVal(
const T& val)
const noexcept {
403 return chkVal<co_type_traits_T<T>::index>(val);
407 getAccess()
const noexcept {
412 setAccess(
unsigned int access)
noexcept {
417 getPDOMapping()
const noexcept {
422 setPDOMapping(
unsigned int pdo_mapping)
noexcept {
427 getFlags()
const noexcept {
432 setFlags(
unsigned int flags)
noexcept {
437 getUploadFile()
const noexcept {
442 setUploadFile(
const char* filename)
noexcept {
447 getDownloadFile()
const noexcept {
452 setDownloadFile(
const char* filename)
noexcept {
466 template <co_unsigned16_t N, typename COSubDnInd<N>::type M>
468 setDnInd(
void* data)
noexcept {
472 template <co_
unsigned16_t N,
class F>
474 setDnInd(F* f)
noexcept {
477 static_cast<void*
>(f));
480 template <co_unsigned16_t N,
class C,
483 setDnInd(C* obj)
noexcept {
486 static_cast<void*
>(obj));
490 onDn(
co_sdo_req& req, co_unsigned32_t* pac)
noexcept {
499 template <co_
unsigned16_t N>
501 dnInd(
const COVal<N>& val)
noexcept {
505 template <co_
unsigned16_t N>
521 template <co_unsigned16_t N, typename COSubUpInd<N>::type M>
523 setUpInd(
void* data)
noexcept {
527 template <co_
unsigned16_t N,
class F>
529 setUpInd(F* f)
noexcept {
532 static_cast<void*
>(f));
535 template <co_unsigned16_t N,
class C,
538 setUpInd(C* obj)
noexcept {
541 static_cast<void*
>(obj));
545 onUp(
co_sdo_req& req, co_unsigned32_t* pac)
const noexcept {
563template <co_
unsigned16_t N>
565 typedef co_unsigned32_t (*type)(
COSub* sub,
COVal<N>& val,
void* data);
568 static co_unsigned32_t
570 co_unsigned32_t ac = 0;
575 if ((ac = sub->chkVal(val)))
return ac;
577 if ((ac = (*M)(sub, val, data)))
return ac;
589template <co_
unsigned16_t N>
591 typedef co_unsigned32_t (*type)(
const COSub* sub,
COVal<N>& val,
void* data);
594 static co_unsigned32_t
596 co_unsigned32_t ac = 0;
600 if ((ac = (*M)(sub, val, data)))
return ac;
This header file is part of the utilities library; it contains the C callback wrapper declarations.
This header file is part of the utilities library; it contains the C to C++ interface declarations.
An opaque CANopen device type.
An opaque CANopen object type.
An opaque CANopen sub-object type.
The base class for a C++ interface to an incomplete C type.
This header file is part of the CANopen library; it contains the Service Data Object (SDO) declaratio...
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,...
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.
This header file is part of the CANopen library; it contains the object dictionary declarations.
int co_sub_set_access(co_sub_t *sub, unsigned int access)
Sets the access type 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.
int co_sub_set_name(co_sub_t *sub, const char *name)
Sets the name of a CANopen sub-object.
co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub)
Returns the sub-index of a CANopen sub-object.
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.
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_sub_set_download_file(co_sub_t *sub, const char *filename)
Sets the value of the DownloadFile attribute of a CANopen sub-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()...
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.
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
const char * co_sub_get_name(const co_sub_t *sub)
Returns the name 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.
const void * co_sub_get_val(const co_sub_t *sub)
Returns a pointer to the current value of a CANopen sub-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,...
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.
int co_obj_set_code(co_obj_t *obj, co_unsigned8_t code)
Sets the code (type) of a CANopen object.
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.
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().
void co_sub_set_flags(co_sub_t *sub, unsigned int flags)
Sets the object flags 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()...
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.
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.
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_sub_t * co_obj_find_sub(const co_obj_t *obj, co_unsigned8_t subidx)
Finds a sub-object in a CANopen object.
const void * co_sub_addressof_def(const co_sub_t *sub)
Returns the address of the default value of a CANopen sub-object.
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.
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.
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.
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 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_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...
co_unsigned8_t co_obj_get_code(const co_obj_t *obj)
Returns the object code of a CANopen object.
const void * co_sub_addressof_val(const co_sub_t *sub)
Returns the address of the current value of 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.
unsigned int co_sub_get_flags(const co_sub_t *sub)
Returns the object flags of a CANopen sub-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,...
int co_obj_set_name(co_obj_t *obj, const char *name)
Sets the name of a CANopen object.
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.
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.
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.
const char * co_obj_get_name(const co_obj_t *obj)
Returns the name of a CANopen object.
int co_obj_remove_sub(co_obj_t *obj, co_sub_t *sub)
Removes a sub-object from a CANopen 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.
void co_sub_set_pdo_mapping(co_sub_t *sub, int pdo_mapping)
Enables or disables PDO mapping a CANopen sub-object.
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...
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 ...
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.
co_dev_t * co_obj_get_dev(const co_obj_t *obj)
Returns a pointer to the CANopen device containing the specified object.
int co_obj_insert_sub(co_obj_t *obj, co_sub_t *sub)
Inserts a sub-object into a CANopen object.
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.
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.
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.
unsigned int co_sub_get_access(const co_sub_t *sub)
Returns the access type of a CANopen sub-object.
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.
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.
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.
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.
co_unsigned16_t co_sub_get_type(const co_sub_t *sub)
Returns the data type of a CANopen sub-object.
A CANopen SDO upload/download request.
A CANopen CANopen sub-object download indication callback wrapper.
A CANopen CANopen sub-object upload indication callback wrapper.
A class template supplying a uniform interface to certain attributes of C types.
This header file is part of the CANopen library; it contains the C++ interface of the CANopen value d...