23 #ifndef LELY_CO_CSDO_HPP_
24 #define LELY_CO_CSDO_HPP_
26 #if !defined(__cplusplus) || LELY_NO_CXX
27 #error "include <lely/co/csdo.h> for the C interface"
43 dnReq(CODev& dev, co_unsigned16_t idx, co_unsigned8_t subidx,
const void* ptr,
50 dnReq(CODev& dev, co_unsigned16_t idx, co_unsigned8_t subidx,
const void* ptr,
51 size_t n, F* f) noexcept {
52 return dnReq(dev, idx, subidx, ptr, n,
53 &c_obj_call<co_csdo_dn_con_t*, F>::function,
54 static_cast<void*
>(f));
57 template <class T, typename c_mem_fn<co_csdo_dn_con_t*, T>::type M>
59 dnReq(CODev& dev, co_unsigned16_t idx, co_unsigned8_t subidx,
const void* ptr,
60 size_t n, T* t) noexcept {
61 return dnReq(dev, idx, subidx, ptr, n,
62 &c_mem_call<co_csdo_dn_con_t*, T, M>::function,
63 static_cast<void*
>(t));
66 template <co_
unsigned16_t N>
68 dnReq(CODev& dev, co_unsigned16_t idx, co_unsigned8_t subidx,
73 template <co_
unsigned16_t N,
class F>
75 dnReq(CODev& dev, co_unsigned16_t idx, co_unsigned8_t subidx,
76 const COVal<N>& val, F* f) noexcept {
77 return dnReq<N>(dev, idx, subidx, val,
78 &c_obj_call<co_csdo_dn_con_t*, F>::function,
79 static_cast<void*
>(f));
82 template <co_unsigned16_t N,
class T,
83 typename c_mem_fn<co_csdo_dn_con_t*, T>::type M>
85 dnReq(CODev& dev, co_unsigned16_t idx, co_unsigned8_t subidx,
86 const COVal<N>& val, T* t) noexcept {
87 return dnReq<N>(dev, idx, subidx, val,
88 &c_mem_call<co_csdo_dn_con_t*, T, M>::function,
89 static_cast<void*
>(t));
93 upReq(
const CODev& dev, co_unsigned16_t idx, co_unsigned8_t subidx,
98 template <class T, typename COCSDOUpCon<T>::type M>
100 upReq(
const CODev& dev, co_unsigned16_t idx, co_unsigned8_t subidx,
101 void* data) noexcept {
102 return upReq(dev, idx, subidx, &COCSDOUpCon<T>::template function<M>, data);
105 template <
class T,
class F>
107 upReq(
const CODev& dev, co_unsigned16_t idx, co_unsigned8_t subidx,
109 return upReq(dev, idx, subidx,
110 &COCSDOUpCon<T>::template
function<
111 &c_obj_call<
typename COCSDOUpCon<T>::type, F>::
function>,
112 static_cast<void*
>(f));
115 template <
class T,
class C,
116 typename c_mem_fn<typename COCSDOUpCon<T>::type, C>::type M>
118 upReq(
const CODev& dev, co_unsigned16_t idx, co_unsigned8_t subidx,
120 return upReq(dev, idx, subidx,
121 &COCSDOUpCon<T>::template
function<
122 &c_mem_call<
typename COCSDOUpCon<T>::type, C, M>::
function>,
123 static_cast<void*
>(obj));
137 return __co_csdo_alloc();
141 free(
void* ptr) noexcept {
147 return __co_csdo_init(p, net, dev, num);
174 getNet()
const noexcept {
179 getDev()
const noexcept {
184 getNum()
const noexcept {
189 getPar()
const noexcept {
194 getTimeout()
const noexcept {
199 setTimeout(
int timeout) noexcept {
204 getDnInd(
co_csdo_ind_t** pind,
void** pdata)
const noexcept {
215 setDnInd(F* f) noexcept {
219 template <class C, typename c_mem_fn<co_csdo_ind_t*, C>::type M>
221 setDnInd(C* obj) noexcept {
223 static_cast<void*
>(obj));
227 getUpInd(
co_csdo_ind_t** pind,
void** pdata)
const noexcept {
238 setUpInd(F* f) noexcept {
242 template <class C, typename c_mem_fn<co_csdo_ind_t*, C>::type M>
244 setUpInd(C* obj) noexcept {
246 static_cast<void*
>(obj));
250 isIdle()
const noexcept {
260 dnReq(co_unsigned16_t idx, co_unsigned8_t subidx,
const void* ptr,
size_t n,
267 dnReq(co_unsigned16_t idx, co_unsigned8_t subidx,
const void* ptr,
size_t n,
269 return dnReq(idx, subidx, ptr, n,
271 static_cast<void*
>(f));
274 template <class T, typename c_mem_fn<co_csdo_dn_con_t*, T>::type M>
276 dnReq(co_unsigned16_t idx, co_unsigned8_t subidx,
const void* ptr,
size_t n,
278 return dnReq(idx, subidx, ptr, n,
280 static_cast<void*
>(t));
283 template <co_
unsigned16_t N>
285 dnReq(co_unsigned16_t idx, co_unsigned8_t subidx,
const COVal<N>& val,
290 template <co_
unsigned16_t N,
class F>
292 dnReq(co_unsigned16_t idx, co_unsigned8_t subidx,
const COVal<N>& val,
294 return dnReq<N>(idx, subidx, val,
296 static_cast<void*
>(f));
299 template <co_unsigned16_t N,
class T,
302 dnReq(co_unsigned16_t idx, co_unsigned8_t subidx,
const COVal<N>& val,
304 return dnReq<N>(idx, subidx, val,
306 static_cast<void*
>(t));
311 void* data) noexcept {
315 template <class T, typename COCSDOUpCon<T>::type M>
317 upReq(co_unsigned16_t idx, co_unsigned8_t subidx,
void* data) noexcept {
321 template <
class T,
class F>
323 upReq(co_unsigned16_t idx, co_unsigned8_t subidx, F* f) noexcept {
324 return upReq(idx, subidx,
327 static_cast<void*
>(f));
330 template <
class T,
class C,
333 upReq(co_unsigned16_t idx, co_unsigned8_t subidx, C* obj) noexcept {
338 static_cast<void*
>(obj));
342 blkDnReq(co_unsigned16_t idx, co_unsigned8_t subidx,
const void* ptr,
349 blkDnReq(co_unsigned16_t idx, co_unsigned8_t subidx,
const void* ptr,
350 size_t n, F* f) noexcept {
351 return blkDnReq(idx, subidx, ptr, n,
353 static_cast<void*
>(f));
356 template <class C, typename c_mem_fn<co_csdo_dn_con_t*, C>::type M>
358 blkDnReq(co_unsigned16_t idx, co_unsigned8_t subidx,
const void* ptr,
359 size_t n, C* obj) noexcept {
360 return blkDnReq(idx, subidx, ptr, n,
362 static_cast<void*
>(obj));
366 blkUpReq(co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned8_t pst,
371 template <class T, typename COCSDOUpCon<T>::type M>
373 blkUpReq(co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned8_t pst,
374 void* data) noexcept {
379 template <
class T,
class F>
381 blkUpReq(co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned8_t pst,
387 static_cast<void*
>(f));
390 template <
class T,
class C,
393 blkUpReq(co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned8_t pst,
399 static_cast<void*
>(obj));
414 typedef void (*type)(
COCSDO* sdo, co_unsigned16_t idx, co_unsigned8_t subidx,
415 co_unsigned32_t ac, T val,
void* data);
419 function(
COCSDO* sdo, co_unsigned16_t idx, co_unsigned8_t subidx,
420 co_unsigned32_t ac,
const void* ptr,
size_t n,
void* data) noexcept {
422 if (!ptr || n <
sizeof(T)) {
424 }
else if (n >
sizeof(T)) {
430 return (*M)(sdo, idx, subidx, ac, val, data);
442 typedef void (*type)(
COCSDO* sdo, co_unsigned16_t idx, co_unsigned8_t subidx,
443 co_unsigned32_t ac,
const char* vs,
void* data);
447 function(
COCSDO* sdo, co_unsigned16_t idx, co_unsigned8_t subidx,
448 co_unsigned32_t ac,
const void* ptr,
size_t n,
void* data) noexcept {
451 return (*M)(sdo, idx, subidx, ac, val, data);
463 typedef void (*type)(
COCSDO* sdo, co_unsigned16_t idx, co_unsigned8_t subidx,
464 co_unsigned32_t ac, ::std::string vs,
void* data);
468 function(
COCSDO* sdo, co_unsigned16_t idx, co_unsigned8_t subidx,
469 co_unsigned32_t ac,
const void* ptr,
size_t n,
void* data) noexcept {
470 const char* vs =
static_cast<const char*
>(ptr);
471 if (!ac && vs && n) {
472 #if !__cpp_exceptions
475 return (*M)(sdo, idx, subidx, ac, ::std::string(vs, vs + n), data);
476 #if !__cpp_exceptions
482 return (*M)(sdo, idx, subidx, ac, ::std::string(), data);
494 typedef void (*type)(
COCSDO* sdo, co_unsigned16_t idx, co_unsigned8_t subidx,
495 co_unsigned32_t ac,
const uint_least8_t* os,
size_t n,
500 function(
COCSDO* sdo, co_unsigned16_t idx, co_unsigned8_t subidx,
501 co_unsigned32_t ac,
const void* ptr,
size_t n,
void* data) noexcept {
502 const uint_least8_t* os =
static_cast<const uint_least8_t*
>(ptr);
503 return (*M)(sdo, idx, subidx, ac, n ? os : 0, n, data);
515 typedef void (*type)(
COCSDO* sdo, co_unsigned16_t idx, co_unsigned8_t subidx,
516 co_unsigned32_t ac, ::std::vector<uint_least8_t> os,
521 function(
COCSDO* sdo, co_unsigned16_t idx, co_unsigned8_t subidx,
522 co_unsigned32_t ac,
const void* ptr,
size_t n,
void* data) noexcept {
523 const uint_least8_t* os =
static_cast<const uint_least8_t*
>(ptr);
524 if (!ac && os && n) {
525 #if !__cpp_exceptions
528 return (*M)(sdo, idx, subidx, ac,
529 ::std::vector<uint_least8_t>(os, os + n), data);
530 #if !__cpp_exceptions
536 return (*M)(sdo, idx, subidx, ac, ::std::vector<uint_least8_t>(), data);
548 typedef void (*type)(
COCSDO* sdo, co_unsigned16_t idx, co_unsigned8_t subidx,
549 co_unsigned32_t ac,
const char16_t* us,
void* data);
553 function(
COCSDO* sdo, co_unsigned16_t idx, co_unsigned8_t subidx,
554 co_unsigned32_t ac,
const void* ptr,
size_t n,
void* data) noexcept {
557 return (*M)(sdo, idx, subidx, ac, val, data);
569 typedef void (*type)(
COCSDO* sdo, co_unsigned16_t idx, co_unsigned8_t subidx,
570 co_unsigned32_t ac, ::std::basic_string<char16_t> us,
575 function(
COCSDO* sdo, co_unsigned16_t idx, co_unsigned8_t subidx,
576 co_unsigned32_t ac,
const void* ptr,
size_t n,
void* data) noexcept {
579 const char16_t* us = val;
580 if (!ac && us && n) {
581 #if !__cpp_exceptions
584 return (*M)(sdo, idx, subidx, ac,
585 ::std::basic_string<char16_t>(us, us + n), data);
586 #if !__cpp_exceptions
592 return (*M)(sdo, idx, subidx, ac, ::std::basic_string<char16_t>(), data);
604 typedef void (*type)(
COCSDO* sdo, co_unsigned16_t idx, co_unsigned8_t subidx,
605 co_unsigned32_t ac,
const void* dom,
size_t n,
610 function(
COCSDO* sdo, co_unsigned16_t idx, co_unsigned8_t subidx,
611 co_unsigned32_t ac,
const void* ptr,
size_t n,
void* data) noexcept {
612 return (*M)(sdo, idx, subidx, ac, n ? ptr : 0, n, data);
An opaque CAN network interface type.
An opaque CANopen Client-SDO service type.
An opaque CANopen device type.
A CANopen value containing an array of (16-bit) Unicode characters.
A CANopen value containing an array of visible characters.
The base class for a C++ interface to an incomplete C type.
This header file is part of the CANopen library; it contains the Client-SDO declarations.
int co_csdo_up_req(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_csdo_up_con_t *con, void *data)
Submits an upload request to a remote Server-SDO.
void co_csdo_up_con_t(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac, const void *ptr, size_t n, void *data)
The type of a CANopen Client-SDO upload confirmation callback function, invoked when an upload reques...
int co_dev_up_req(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx, co_csdo_up_con_t *con, void *data)
Submits an upload request to a local device.
void co_csdo_stop(co_csdo_t *sdo)
Stops a Client-SDO service.
int co_csdo_is_idle(const co_csdo_t *sdo)
Returns 1 if the specified Client-SDO service is idle, and 0 if a transfer is ongoing.
int co_csdo_dn_req(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, const void *ptr, size_t n, co_csdo_dn_con_t *con, void *data)
Submits a download request to a remote Server-SDO.
int co_dev_dn_val_req(co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned16_t type, const void *val, co_csdo_dn_con_t *con, void *data)
Submits a download request to a local device.
void co_csdo_dn_con_t(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac, void *data)
The type of a CANopen Client-SDO download confirmation callback function, invoked when a download req...
int co_dev_dn_req(co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx, const void *ptr, size_t n, co_csdo_dn_con_t *con, void *data)
Submits a download request to a local device.
void co_csdo_set_timeout(co_csdo_t *sdo, int timeout)
Sets the timeout of a Client-SDO.
can_net_t * co_csdo_get_net(const co_csdo_t *sdo)
Returns a pointer to the CAN network of a Client-SDO.
int co_csdo_get_timeout(const co_csdo_t *sdo)
Returns the timeout (in milliseconds) of a Client-SDO.
int co_csdo_start(co_csdo_t *sdo)
Starts a Client-SDO service.
int co_csdo_blk_up_req(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned8_t pst, co_csdo_up_con_t *con, void *data)
Submits a block upload request to a remote Server-SDO.
int co_csdo_blk_dn_req(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, const void *ptr, size_t n, co_csdo_dn_con_t *con, void *data)
Submits a block download request to a remote Server-SDO.
void co_csdo_set_up_ind(co_csdo_t *sdo, co_csdo_ind_t *ind, void *data)
Sets the indication function used to notify the user of the progress of the current SDO upload reques...
void co_csdo_abort_req(co_csdo_t *sdo, co_unsigned32_t ac)
Submits an abort transfer request to a remote Server-SDO.
void co_csdo_ind_t(const co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, size_t size, size_t nbyte, void *data)
The type of a CANopen Client-SDO request progress indication function, used to notify the user of the...
void co_csdo_get_up_ind(const co_csdo_t *sdo, co_csdo_ind_t **pind, void **pdata)
Retrieves the indication function used to notify the user of the progress of the current SDO upload r...
void co_csdo_set_dn_ind(co_csdo_t *sdo, co_csdo_ind_t *ind, void *data)
Sets the indication function used to notify the user of the progress of the current SDO download requ...
const struct co_sdo_par * co_csdo_get_par(const co_csdo_t *sdo)
Returns a pointer to the SDO parameter record of a Client-SDO.
co_unsigned8_t co_csdo_get_num(const co_csdo_t *sdo)
Returns the SDO number of a Client-SDO.
co_dev_t * co_csdo_get_dev(const co_csdo_t *sdo)
Returns a pointer to the CANopen device of a Client-SDO.
void co_csdo_get_dn_ind(const co_csdo_t *sdo, co_csdo_ind_t **pind, void **pdata)
Retrieves the indication function used to notify the user of the progress of the current SDO download...
int co_csdo_dn_val_req(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned16_t type, const void *val, co_csdo_dn_con_t *con, void *data)
Submits a download request to a remote Server-SDO.
#define CO_SDO_AC_TYPE_LEN_LO
SDO abort code: Data type does not match, length of service parameter too low.
#define CO_SDO_AC_TYPE_LEN_HI
SDO abort code: Data type does not match, length of service parameter too high.
#define CO_SDO_AC_ERROR
SDO abort code: General error.
#define CO_SDO_AC_NO_MEM
SDO abort code: Out of memory.
This header file is part of the CAN library; it contains the C++ interface of the CAN network interfa...
A CANopen Client-SDO upload confirmation callback wrapper that deserializes the received value on suc...
A class template supplying a uniform interface to certain attributes of C types.
co_unsigned32_t co_val_read_sdo(co_unsigned16_t type, void *val, const void *ptr, size_t n)
Reads a value of the specified data type from an SDO buffer.
This header file is part of the CANopen library; it contains the C++ interface of the CANopen value d...