Lely core libraries 1.9.2
tpdo.hpp
Go to the documentation of this file.
1
23#ifndef LELY_CO_TPDO_HPP_
24#define LELY_CO_TPDO_HPP_
25
26#ifndef __cplusplus
27#error "include <lely/co/tpdo.h> for the C interface"
28#endif
29
30#include <lely/can/net.hpp>
31#include <lely/co/tpdo.h>
32
33namespace lely {
34
36template <>
38 typedef __co_tpdo value_type;
39 typedef value_type& reference;
40 typedef const value_type& const_reference;
41 typedef value_type* pointer;
42 typedef const value_type* const_pointer;
43
44 static void*
45 alloc() noexcept {
46 return __co_tpdo_alloc();
47 }
48 static void
49 free(void* ptr) noexcept {
50 __co_tpdo_free(ptr);
51 }
52
53 static pointer
54 init(pointer p, CANNet* net, CODev* dev, co_unsigned16_t num) noexcept {
55 return __co_tpdo_init(p, net, dev, num);
56 }
57
58 static void
59 fini(pointer p) noexcept {
60 __co_tpdo_fini(p);
61 }
62};
63
65class COTPDO : public incomplete_c_type<__co_tpdo> {
67
68 public:
69 COTPDO(CANNet* net, CODev* dev, co_unsigned16_t num)
70 : c_base(net, dev, num) {}
71
72 CANNet*
73 getNet() const noexcept {
74 return co_tpdo_get_net(this);
75 }
76 CODev*
77 getDev() const noexcept {
78 return co_tpdo_get_dev(this);
79 }
80
81 co_unsigned16_t
82 getNum() const noexcept {
83 return co_tpdo_get_num(this);
84 }
85
86 const co_pdo_comm_par&
87 getCommPar() const noexcept {
88 return *co_tpdo_get_comm_par(this);
89 }
90
91 const co_pdo_map_par&
92 getMapPar() const noexcept {
93 return *co_tpdo_get_map_par(this);
94 }
95
96 void
97 getInd(co_tpdo_ind_t** pind, void** pdata) const noexcept {
98 co_tpdo_get_ind(this, pind, pdata);
99 }
100
101 void
102 setInd(co_tpdo_ind_t* ind, void* data) noexcept {
103 co_tpdo_set_ind(this, ind, data);
104 }
105
106 template <class F>
107 void
108 setInd(F* f) noexcept {
109 setInd(&c_obj_call<co_tpdo_ind_t*, F>::function, static_cast<void*>(f));
110 }
111
112 template <class C, typename c_mem_fn<co_tpdo_ind_t*, C>::type M>
113 void
114 setInd(C* obj) noexcept {
116 static_cast<void*>(obj));
117 }
118
119 int
120 event() noexcept {
121 return co_tpdo_event(this);
122 }
123
124 int
125 sync(co_unsigned8_t cnt) noexcept {
126 return co_tpdo_sync(this, cnt);
127 }
128
129 void
130 getNext(timespec& tp) noexcept {
131 co_tpdo_get_next(this, &tp);
132 }
133
134 protected:
135 ~COTPDO() {}
136};
137
138} // namespace lely
139
140#endif // !LELY_CO_TPDO_HPP_
An opaque CAN network interface type.
Definition: net.hpp:83
An opaque CANopen device type.
Definition: dev.hpp:76
An opaque CANopen Transmit-PDO service type.
Definition: tpdo.hpp:65
The base class for a C++ interface to an incomplete C type.
Definition: c_type.hpp:245
Global namespace for the Lely Industries N.V. libraries.
Definition: buf.hpp:32
This header file is part of the CAN library; it contains the C++ interface of the CAN network interfa...
A CANopen Transmit-PDO.
Definition: tpdo.c:41
A PDO communication parameter record.
Definition: pdo.h:43
A PDO mapping parameter record.
Definition: pdo.h:69
A class template supplying a uniform interface to certain attributes of C types.
Definition: c_type.hpp:344
A time type with nanosecond resolution.
Definition: time.h:83
This header file is part of the CANopen library; it contains the Transmit-PDO declarations.
can_net_t * co_tpdo_get_net(const co_tpdo_t *pdo)
Returns a pointer to the CAN network of a Transmit-PDO.
Definition: tpdo.c:335
int co_tpdo_event(co_tpdo_t *pdo)
Triggers the transmission of an event-driven (asynchronous) PDO.
Definition: tpdo.c:395
const struct co_pdo_map_par * co_tpdo_get_map_par(const co_tpdo_t *pdo)
Returns a pointer to the PDO mapping parameter record of a Transmit-PDO.
Definition: tpdo.c:367
const struct co_pdo_comm_par * co_tpdo_get_comm_par(const co_tpdo_t *pdo)
Returns a pointer to the PDO communication parameter record of a Transmit-PDO.
Definition: tpdo.c:359
void co_tpdo_get_next(const co_tpdo_t *pdo, struct timespec *tp)
Retrieves the time at which the next event-driven TPDO may be sent.
Definition: tpdo.c:504
void co_tpdo_get_ind(const co_tpdo_t *pdo, co_tpdo_ind_t **pind, void **pdata)
Retrieves the indication function invoked when a Transmit-PDO error occurs.
Definition: tpdo.c:375
void co_tpdo_ind_t(co_tpdo_t *pdo, co_unsigned32_t ac, const void *ptr, size_t n, void *data)
The type of a CANopen Transmit-PDO indication function, invoked when a PDO is sent or an error occurs...
Definition: tpdo.h:45
void co_tpdo_set_ind(co_tpdo_t *pdo, co_tpdo_ind_t *ind, void *data)
Sets the indication function invoked when a Transmit-PDO error occurs.
Definition: tpdo.c:386
int co_tpdo_sync(co_tpdo_t *pdo, co_unsigned8_t cnt)
Triggers the transmission of a synchronous PDO.
Definition: tpdo.c:436
co_dev_t * co_tpdo_get_dev(const co_tpdo_t *pdo)
Returns a pointer to the CANopen device of a Transmit-PDO.
Definition: tpdo.c:343
co_unsigned16_t co_tpdo_get_num(const co_tpdo_t *pdo)
Returns the PDO number of a Transmit-PDO.
Definition: tpdo.c:351