Lely core libraries  2.3.4
emcy.hpp
Go to the documentation of this file.
1 
23 #ifndef LELY_CO_EMCY_HPP_
24 #define LELY_CO_EMCY_HPP_
25 
26 #if !defined(__cplusplus) || LELY_NO_CXX
27 #error "include <lely/co/emcy.h> for the C interface"
28 #endif
29 
30 #include <lely/can/net.hpp>
31 #include <lely/co/emcy.h>
32 
33 namespace lely {
34 
36 template <>
38  typedef __co_emcy 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_emcy_alloc();
47  }
48 
49  static void
50  free(void* ptr) noexcept {
51  __co_emcy_free(ptr);
52  }
53 
54  static pointer
55  init(pointer p, CANNet* net, CODev* dev) noexcept {
56  return __co_emcy_init(p, net, dev);
57  }
58 
59  static void
60  fini(pointer p) noexcept {
61  __co_emcy_fini(p);
62  }
63 };
64 
66 class COEmcy : public incomplete_c_type<__co_emcy> {
68 
69  public:
70  COEmcy(CANNet* net, CODev* dev) : c_base(net, dev) {}
71 
72  int
73  start() noexcept {
74  return co_emcy_start(this);
75  }
76 
77  void
78  stop() noexcept {
79  co_emcy_stop(this);
80  }
81 
82  CANNet*
83  getNet() const noexcept {
84  return co_emcy_get_net(this);
85  }
86 
87  CODev*
88  getDev() const noexcept {
89  return co_emcy_get_dev(this);
90  }
91 
92  int
93  push(co_unsigned16_t eec, co_unsigned8_t er,
94  const co_unsigned8_t msef[5] = 0) noexcept {
95  return co_emcy_push(this, eec, er, msef);
96  }
97 
98  int
99  pop(co_unsigned16_t* peec = 0, co_unsigned8_t* per = 0) noexcept {
100  return co_emcy_pop(this, peec, per);
101  }
102 
103  void
104  peek(co_unsigned16_t* peec = 0, co_unsigned8_t* per = 0) const noexcept {
105  co_emcy_peek(this, peec, per);
106  }
107 
108  int
109  remove(size_t n) noexcept {
110  return co_emcy_remove(this, n);
111  }
112 
113  ssize_t
114  find(co_unsigned16_t eec) const noexcept {
115  return co_emcy_find(this, eec);
116  }
117 
118  int
119  clear() noexcept {
120  return co_emcy_clear(this);
121  }
122 
123  void
124  getInd(co_emcy_ind_t** pind, void** pdata) const noexcept {
125  co_emcy_get_ind(this, pind, pdata);
126  }
127 
128  void
129  setInd(co_emcy_ind_t* ind, void* data) noexcept {
130  co_emcy_set_ind(this, ind, data);
131  }
132 
133  template <class F>
134  void
135  setInd(F* f) noexcept {
136  setInd(&c_obj_call<co_emcy_ind_t*, F>::function, static_cast<void*>(f));
137  }
138 
139  template <class C, typename c_mem_fn<co_emcy_ind_t*, C>::type M>
140  void
141  setInd(C* obj) noexcept {
143  static_cast<void*>(obj));
144  }
145 
146  protected:
147  ~COEmcy() = default;
148 };
149 
150 } // namespace lely
151 
152 #endif // !LELY_CO_EMCY_HPP_
emcy.h
lely::incomplete_c_type
The base class for a C++ interface to an incomplete C type.
Definition: c_type.hpp:249
co_emcy_find
ssize_t co_emcy_find(const co_emcy_t *emcy, co_unsigned16_t eec)
Finds a CANopen EMCY message in the stack.
Definition: emcy.c:582
co_emcy_stop
void co_emcy_stop(co_emcy_t *emcy)
Stops an EMCY service.
Definition: emcy.c:410
net.hpp
co_emcy_get_ind
void co_emcy_get_ind(const co_emcy_t *emcy, co_emcy_ind_t **pind, void **pdata)
Retrieves the indication function invoked when a CANopen EMCY message is received.
Definition: emcy.c:614
lely::c_obj_call
Definition: c_call.hpp:62
co_emcy_get_dev
co_dev_t * co_emcy_get_dev(const co_emcy_t *emcy)
Returns a pointer to the CANopen device of an EMCY producer/consumer service.
Definition: emcy.c:462
co_emcy_peek
void co_emcy_peek(const co_emcy_t *emcy, co_unsigned16_t *peec, co_unsigned8_t *per)
Retrieves, but does not pop, the most recent CANopen EMCY message from the stack.
Definition: emcy.c:536
co_emcy_start
int co_emcy_start(co_emcy_t *emcy)
Starts an EMCY service.
Definition: emcy.c:370
co_emcy_get_net
can_net_t * co_emcy_get_net(const co_emcy_t *emcy)
Returns a pointer to the CAN network of an EMCY producer/consumer service.
Definition: emcy.c:454
co_emcy_ind_t
void co_emcy_ind_t(co_emcy_t *emcy, co_unsigned8_t id, co_unsigned16_t eec, co_unsigned8_t er, co_unsigned8_t msef[5], void *data)
The type of a CANopen EMCY indication function, invoked when an EMCY message is received.
Definition: emcy.h:52
__co_emcy
A CANopen EMCY producer/consumer service.
Definition: emcy.c:85
lely::CANNet
An opaque CAN network interface type.
Definition: net.hpp:85
lely::c_type_traits
A class template supplying a uniform interface to certain attributes of C types.
Definition: c_type.hpp:120
co_emcy_pop
int co_emcy_pop(co_emcy_t *emcy, co_unsigned16_t *peec, co_unsigned8_t *per)
Pops the most recent CANopen EMCY message from the stack and broadcasts an 'error reset' message if t...
Definition: emcy.c:526
co_emcy_remove
int co_emcy_remove(co_emcy_t *emcy, size_t n)
Pops a CANopen EMCY message from the stack, even if it is not the most recent message,...
Definition: emcy.c:551
lely::c_mem_call
Definition: c_call.hpp:67
co_emcy_push
int co_emcy_push(co_emcy_t *emcy, co_unsigned16_t eec, co_unsigned8_t er, const co_unsigned8_t msef[5])
Pushes a CANopen EMCY message to the stack and broadcasts it if the EMCY producer service is active.
Definition: emcy.c:470
co_emcy_set_ind
void co_emcy_set_ind(co_emcy_t *emcy, co_emcy_ind_t *ind, void *data)
Sets the indication function invoked when a CANopen EMCY message is received.
Definition: emcy.c:625
lely::COEmcy
An opaque CANopen EMCY producer/consumer service type.
Definition: emcy.hpp:66
co_emcy_clear
int co_emcy_clear(co_emcy_t *emcy)
Clears the CANopen EMCY message stack and broadcasts the 'error reset/no error' message if the EMCY p...
Definition: emcy.c:595
lely::CODev
An opaque CANopen device type.
Definition: dev.hpp:77