Lely core libraries  2.3.4
tpdo.hpp
Go to the documentation of this file.
1 
23 #ifndef LELY_CO_TPDO_HPP_
24 #define LELY_CO_TPDO_HPP_
25 
26 #if !defined(__cplusplus) || LELY_NO_CXX
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 
49  static void
50  free(void* ptr) noexcept {
51  __co_tpdo_free(ptr);
52  }
53 
54  static pointer
55  init(pointer p, CANNet* net, CODev* dev, co_unsigned16_t num) noexcept {
56  return __co_tpdo_init(p, net, dev, num);
57  }
58 
59  static void
60  fini(pointer p) noexcept {
61  __co_tpdo_fini(p);
62  }
63 };
64 
66 class COTPDO : public incomplete_c_type<__co_tpdo> {
68 
69  public:
70  COTPDO(CANNet* net, CODev* dev, co_unsigned16_t num)
71  : c_base(net, dev, num) {}
72 
73  int
74  start() noexcept {
75  return co_tpdo_start(this);
76  }
77 
78  void
79  stop() noexcept {
80  co_tpdo_stop(this);
81  }
82 
83  CANNet*
84  getNet() const noexcept {
85  return co_tpdo_get_net(this);
86  }
87 
88  CODev*
89  getDev() const noexcept {
90  return co_tpdo_get_dev(this);
91  }
92 
93  co_unsigned16_t
94  getNum() const noexcept {
95  return co_tpdo_get_num(this);
96  }
97 
98  const co_pdo_comm_par&
99  getCommPar() const noexcept {
100  return *co_tpdo_get_comm_par(this);
101  }
102 
103  const co_pdo_map_par&
104  getMapPar() const noexcept {
105  return *co_tpdo_get_map_par(this);
106  }
107 
108  void
109  getInd(co_tpdo_ind_t** pind, void** pdata) const noexcept {
110  co_tpdo_get_ind(this, pind, pdata);
111  }
112 
113  void
114  setInd(co_tpdo_ind_t* ind, void* data) noexcept {
115  co_tpdo_set_ind(this, ind, data);
116  }
117 
118  template <class F>
119  void
120  setInd(F* f) noexcept {
121  setInd(&c_obj_call<co_tpdo_ind_t*, F>::function, static_cast<void*>(f));
122  }
123 
124  template <class C, typename c_mem_fn<co_tpdo_ind_t*, C>::type M>
125  void
126  setInd(C* obj) noexcept {
128  static_cast<void*>(obj));
129  }
130 
131  int
132  event() noexcept {
133  return co_tpdo_event(this);
134  }
135 
136  int
137  sync(co_unsigned8_t cnt) noexcept {
138  return co_tpdo_sync(this, cnt);
139  }
140 
141  void
142  getNext(timespec& tp) noexcept {
143  co_tpdo_get_next(this, &tp);
144  }
145 
146  protected:
147  ~COTPDO() = default;
148 };
149 
150 } // namespace lely
151 
152 #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:452
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:428
co_pdo_comm_par
A PDO communication parameter record.
Definition: pdo.h:64
co_tpdo_start
int co_tpdo_start(co_tpdo_t *pdo)
Starts a Transmit-PDO service.
Definition: tpdo.c:340
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:444
__co_tpdo
A CANopen Transmit-PDO.
Definition: tpdo.c:53
lely::COTPDO
An opaque CANopen Transmit-PDO service type.
Definition: tpdo.hpp:66
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:655
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:565
co_tpdo_event
int co_tpdo_event(co_tpdo_t *pdo)
Triggers the transmission of an acyclic or event-driven PDO.
Definition: tpdo.c:509
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 is sent or an error occurs.
Definition: tpdo.c:468
co_pdo_map_par
A PDO mapping parameter record.
Definition: pdo.h:90
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:436
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:460
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 is sent or an error occurs.
Definition: tpdo.c:479
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:46
co_tpdo_stop
void co_tpdo_stop(co_tpdo_t *pdo)
Stops a Transmit-PDO service.
Definition: tpdo.c:392
lely::CODev
An opaque CANopen device type.
Definition: dev.hpp:77