Lely core libraries  2.2.5
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 
33 namespace lely {
34 
36 template <>
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 
65 class 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() = default;
136 };
137 
138 } // namespace lely
139 
140 #endif // !LELY_CO_TPDO_HPP_
lely::incomplete_c_type
The base class for a C++ interface to an incomplete C type.
Definition: c_type.hpp:249
net.hpp
lely::c_obj_call
Definition: c_call.hpp:62
co_tpdo_get_comm_par
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:330
co_tpdo_get_net
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:306
co_pdo_comm_par
A PDO communication parameter record.
Definition: pdo.h:43
co_tpdo_get_num
co_unsigned16_t co_tpdo_get_num(const co_tpdo_t *pdo)
Returns the PDO number of a Transmit-PDO.
Definition: tpdo.c:322
__co_tpdo
A CANopen Transmit-PDO.
Definition: tpdo.c:40
lely::COTPDO
An opaque CANopen Transmit-PDO service type.
Definition: tpdo.hpp:65
tpdo.h
lely::CANNet
An opaque CAN network interface type.
Definition: net.hpp:85
co_tpdo_get_next
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:462
lely::c_type_traits
A class template supplying a uniform interface to certain attributes of C types.
Definition: c_type.hpp:120
co_tpdo_sync
int co_tpdo_sync(co_tpdo_t *pdo, co_unsigned8_t cnt)
Triggers the transmission of a synchronous PDO.
Definition: tpdo.c:412
co_tpdo_event
int co_tpdo_event(co_tpdo_t *pdo)
Triggers the transmission of an acyclic or event-driven PDO.
Definition: tpdo.c:366
lely::c_mem_call
Definition: c_call.hpp:67
co_tpdo_get_ind
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:346
co_pdo_map_par
A PDO mapping parameter record.
Definition: pdo.h:69
co_tpdo_get_dev
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:314
co_tpdo_get_map_par
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:338
co_tpdo_set_ind
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:357
co_tpdo_ind_t
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
lely::CODev
An opaque CANopen device type.
Definition: dev.hpp:77