Lely core libraries 1.9.2
emcy.hpp
Go to the documentation of this file.
1
23#ifndef LELY_CO_EMCY_HPP_
24#define LELY_CO_EMCY_HPP_
25
26#ifndef __cplusplus
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
33namespace lely {
34
36template <>
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 static void
49 free(void* ptr) noexcept {
50 __co_emcy_free(ptr);
51 }
52
53 static pointer
54 init(pointer p, CANNet* net, CODev* dev) noexcept {
55 return __co_emcy_init(p, net, dev);
56 }
57
58 static void
59 fini(pointer p) noexcept {
60 __co_emcy_fini(p);
61 }
62};
63
65class COEmcy : public incomplete_c_type<__co_emcy> {
67
68 public:
69 COEmcy(CANNet* net, CODev* dev) : c_base(net, dev) {}
70
71 CANNet*
72 getNet() const noexcept {
73 return co_emcy_get_net(this);
74 }
75 CODev*
76 getDev() const noexcept {
77 return co_emcy_get_dev(this);
78 }
79
80 int
81 push(co_unsigned16_t eec, co_unsigned8_t er,
82 const uint8_t msef[5] = 0) noexcept {
83 return co_emcy_push(this, eec, er, msef);
84 }
85
86 int
87 pop(co_unsigned16_t* peec = 0, co_unsigned8_t* per = 0) noexcept {
88 return co_emcy_pop(this, peec, per);
89 }
90
91 void
92 peek(co_unsigned16_t* peec = 0, co_unsigned8_t* per = 0) const noexcept {
93 co_emcy_peek(this, peec, per);
94 }
95
96 int
97 clear() noexcept {
98 return co_emcy_clear(this);
99 }
100
101 void
102 getInd(co_emcy_ind_t** pind, void** pdata) const noexcept {
103 co_emcy_get_ind(this, pind, pdata);
104 }
105
106 void
107 setInd(co_emcy_ind_t* ind, void* data) noexcept {
108 co_emcy_set_ind(this, ind, data);
109 }
110
111 template <class F>
112 void
113 setInd(F* f) noexcept {
114 setInd(&c_obj_call<co_emcy_ind_t*, F>::function, static_cast<void*>(f));
115 }
116
117 template <class C, typename c_mem_fn<co_emcy_ind_t*, C>::type M>
118 void
119 setInd(C* obj) noexcept {
121 static_cast<void*>(obj));
122 }
123
124 protected:
125 ~COEmcy() {}
126};
127
128} // namespace lely
129
130#endif // !LELY_CO_EMCY_HPP_
An opaque CAN network interface type.
Definition: net.hpp:83
An opaque CANopen device type.
Definition: dev.hpp:76
An opaque CANopen EMCY producer/consumer service type.
Definition: emcy.hpp:65
The base class for a C++ interface to an incomplete C type.
Definition: c_type.hpp:245
This header file is part of the CANopen library; it contains the emergency (EMCY) object declarations...
void co_emcy_ind_t(co_emcy_t *emcy, co_unsigned8_t id, co_unsigned16_t eec, co_unsigned8_t er, uint8_t msef[5], void *data)
The type of a CANopen EMCY indication function, invoked when an EMCY message is received.
Definition: emcy.h:52
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:486
int co_emcy_push(co_emcy_t *emcy, co_unsigned16_t eec, co_unsigned8_t er, const uint8_t msef[5])
Pushes a CANopen EMCY message to the stack and broadcasts it if the EMCY producer service is active.
Definition: emcy.c:380
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:467
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:364
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:426
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:456
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:372
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:497
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 EMCY producer/consumer service.
Definition: emcy.c:83
A class template supplying a uniform interface to certain attributes of C types.
Definition: c_type.hpp:344