Lely core libraries 1.9.2
sync.hpp
Go to the documentation of this file.
1
23#ifndef LELY_CO_SYNC_HPP_
24#define LELY_CO_SYNC_HPP_
25
26#ifndef __cplusplus
27#error "include <lely/co/sync.h> for the C interface"
28#endif
29
30#include <lely/can/net.hpp>
31#include <lely/co/sync.h>
32
33namespace lely {
34
36template <>
38 typedef __co_sync 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_sync_alloc();
47 }
48 static void
49 free(void* ptr) noexcept {
50 __co_sync_free(ptr);
51 }
52
53 static pointer
54 init(pointer p, CANNet* net, CODev* dev) noexcept {
55 return __co_sync_init(p, net, dev);
56 }
57
58 static void
59 fini(pointer p) noexcept {
60 __co_sync_fini(p);
61 }
62};
63
65class COSync : public incomplete_c_type<__co_sync> {
67
68 public:
69 COSync(CANNet* net, CODev* dev) : c_base(net, dev) {}
70
71 CANNet*
72 getNet() const noexcept {
73 return co_sync_get_net(this);
74 }
75 CODev*
76 getDev() const noexcept {
77 return co_sync_get_dev(this);
78 }
79
80 void
81 getInd(co_sync_ind_t** pind, void** pdata) const noexcept {
82 co_sync_get_ind(this, pind, pdata);
83 }
84
85 void
86 setInd(co_sync_ind_t* ind, void* data) noexcept {
87 co_sync_set_ind(this, ind, data);
88 }
89
90 template <class F>
91 void
92 setInd(F* f) noexcept {
93 setInd(&c_obj_call<co_sync_ind_t*, F>::function, static_cast<void*>(f));
94 }
95
96 template <class C, typename c_mem_fn<co_sync_ind_t*, C>::type M>
97 void
98 setInd(C* obj) noexcept {
100 static_cast<void*>(obj));
101 }
102
103 void
104 getErr(co_sync_err_t** perr, void** pdata) const noexcept {
105 co_sync_get_err(this, perr, pdata);
106 }
107
108 void
109 setErr(co_sync_err_t* err, void* data) noexcept {
110 co_sync_set_err(this, err, data);
111 }
112
113 template <class F>
114 void
115 setErr(F* f) noexcept {
116 setErr(&c_obj_call<co_sync_err_t*, F>::function, static_cast<void*>(f));
117 }
118
119 template <class C, typename c_mem_fn<co_sync_err_t*, C>::type M>
120 void
121 setErr(C* obj) noexcept {
123 static_cast<void*>(obj));
124 }
125
126 protected:
127 ~COSync() {}
128};
129
130} // namespace lely
131
132#endif // !LELY_CO_SYNC_HPP_
An opaque CAN network interface type.
Definition: net.hpp:83
An opaque CANopen device type.
Definition: dev.hpp:76
An opaque CANopen SYNC producer/consumer service type.
Definition: sync.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 SYNC producer/consumer service.
Definition: sync.c:39
A class template supplying a uniform interface to certain attributes of C types.
Definition: c_type.hpp:344
This header file is part of the CANopen library; it contains the synchronization (SYNC) object declar...
void co_sync_get_err(const co_sync_t *sync, co_sync_err_t **perr, void **pdata)
Retrieves the error handling function of a SYNC consumer service.
Definition: sync.c:302
void co_sync_err_t(co_sync_t *sync, co_unsigned16_t eec, co_unsigned8_t er, void *data)
The type of a CANopen SYNC error handling function, invoked when the SYNC data length does not match.
Definition: sync.h:60
co_dev_t * co_sync_get_dev(const co_sync_t *sync)
Returns a pointer to the CANopen device of a SYNC producer/consumer service.
Definition: sync.c:274
void co_sync_set_err(co_sync_t *sync, co_sync_err_t *err, void *data)
Sets the error handling function of a SYNC consumer service.
Definition: sync.c:313
void co_sync_set_ind(co_sync_t *sync, co_sync_ind_t *ind, void *data)
Sets the indication function invoked after a CANopen SYNC message is received or transmitted.
Definition: sync.c:293
void co_sync_ind_t(co_sync_t *sync, co_unsigned8_t cnt, void *data)
The type of a CANopen SYNC indication function, invoked after a SYNC message is received or transmitt...
Definition: sync.h:49
void co_sync_get_ind(const co_sync_t *sync, co_sync_ind_t **pind, void **pdata)
Retrieves the indication function invoked after a CANopen SYNC message is received or transmitted.
Definition: sync.c:282
can_net_t * co_sync_get_net(const co_sync_t *sync)
Returns a pointer to the CAN network of a SYNC producer/consumer service.
Definition: sync.c:266