emlabcpp
modern opinionated embedded C++ library
protocol.h
Go to the documentation of this file.
1 
24 #pragma once
25 
26 #include "../../algorithm.h"
27 #include "../../protocol/base.h"
28 #include "../../protocol/endpoint.h"
29 #include "../../protocol/error.h"
30 #include "../../protocol/handler.h"
31 #include "../../protocol/message.h"
32 #include "../../protocol/packet.h"
33 #include "../../protocol/traits.h"
34 #include "../../static_function.h"
35 #include "../../view.h"
36 #include "../contiguous_tree/base.h"
37 #include "../multiplexer.h"
38 #include "../testing/base.h"
39 
40 #include <array>
41 #include <bit>
42 #include <variant>
43 
44 namespace emlabcpp::testing
45 {
46 
47 enum class msgid : uint8_t
48 {
49  EXEC = 0x1,
50  COUNT = 0x2,
51  NAME = 0x3,
52  SUITE_NAME = 0x6,
53  SUITE_DATE = 0x7,
54  FINISHED = 0x9,
55  ERROR = 0xa,
56  FAILURE = 0xb,
57  BOOT = 0xc,
58  INTERNAL_ERROR = 0xf0,
59  PROTOCOL_ERROR = 0xf1,
60  TREE_ERROR = 0xf2,
61 };
62 
63 template < msgid ID >
65 {
66  static constexpr auto id = ID;
67 };
68 
70 {
71  static constexpr auto id = msgid::COUNT;
73 };
74 
76 {
77  static constexpr auto id = msgid::SUITE_NAME;
79 };
80 
82 {
83  static constexpr auto id = msgid::SUITE_DATE;
85 };
86 
88 {
89  static constexpr auto id = msgid::NAME;
91 };
92 
94 {
95  static constexpr auto id = msgid::NAME;
97 };
98 
100 {
101  static constexpr auto id = msgid::TREE_ERROR;
104 };
105 
107 {
108  static constexpr auto id = msgid::FINISHED;
111 };
112 
113 struct boot
114 {
115  static constexpr auto id = msgid::BOOT;
116 };
117 
119 {
120  static constexpr auto id = msgid::EXEC;
123 };
124 
130  exec_request >;
131 
136 
137 enum error_enum : uint8_t
138 {
144  TREE_E = 0x8,
148 };
149 
150 template < error_enum Err >
151 struct error
152 {
153  static constexpr auto id = Err;
154 };
155 
157 {
158  static constexpr auto id = NO_RESPONSE_E;
160 };
161 
163 {
164  static constexpr auto id = WRONG_TYPE_E;
166 };
167 
169 {
170  static constexpr auto id = INPUT_MESSAGE_PROTOCOL_ERROR;
172 };
173 
174 // TODO: this is not good, we want group here
175 using reactor_error_variant = std::variant<
185 
187 {
188  static constexpr auto id = msgid::INTERNAL_ERROR;
190 };
191 
193  boot,
200 
205 
210 
212 // TODO: this needs rethinking /o\ entire multiplexer needs redesign?
213 
214 // TODO: this needs more constructive approach... why is it here?
216 
218 {
219  static constexpr std::endian endianess = std::endian::big;
220  static constexpr std::array< std::byte, 4 > prefix = bytes( 0x42, 0x42, 0x42, 0x42 );
221  using size_type = uint16_t;
223 
225  {
226  std::byte const init{ 0x0 };
227  return accumulate(
228  msg, init, []( std::byte const accum, std::byte const val ) -> std::byte {
229  return accum ^ val;
230  } );
231  }
232 };
233 
236 using message = typename packet::message_type;
237 
238 } // namespace emlabcpp::testing
239 
240 namespace emlabcpp::protocol
241 {
242 
243 extern template class endpoint< testing::packet, testing::packet >;
244 
245 } // namespace emlabcpp::protocol
Protocol library has custom type that represents message, however this is just simple overaly over st...
Definition: message.h:40
Definition: multiplexer.h:121
Generic class to represent view of some container.
Definition: view.h:41
MIT License.
Definition: multiplexer.h:33
uint16_t channel_type
Definition: multiplexer.h:35
decltype(traits_for_impl< D >()) traits_for
Definition: traits.h:59
Definition: error.h:39
Definition: base.h:95
MIT License.
Definition: base.h:37
uint16_t test_id
Definition: base.h:54
std::variant< error< TEST_IS_RUNING_E >, error< TEST_NOT_FOUND_E >, error< BAD_TEST_ID_E >, error< UNDESIRED_MSG_E >, no_response_error, wrong_type_error, tree_error_reply, error< WRONG_MESSAGE_E >, input_message_protocol_error > reactor_error_variant
Definition: protocol.h:184
test_status
Definition: base.h:62
uint32_t node_id
Definition: base.h:42
uint32_t run_id
Definition: base.h:53
typename protocol::handler< controller_reactor_group >::message_type controller_reactor_message
Definition: protocol.h:135
typename protocol::traits_for< controller_reactor_group >::value_type controller_reactor_variant
Definition: protocol.h:133
msgid
Definition: protocol.h:48
typename protocol::traits_for< reactor_controller_group >::value_type reactor_controller_variant
Definition: protocol.h:202
typename packet::message_type message
Definition: protocol.h:236
static constexpr protocol::channel_type core_channel
Definition: protocol.h:215
error_enum
Definition: protocol.h:138
@ NO_RESPONSE_E
Definition: protocol.h:143
@ TEST_IS_RUNING_E
Definition: protocol.h:139
@ TEST_NOT_FOUND_E
Definition: protocol.h:140
@ TREE_E
Definition: protocol.h:144
@ INPUT_MESSAGE_PROTOCOL_ERROR
Definition: protocol.h:147
@ WRONG_MESSAGE_E
Definition: protocol.h:146
@ UNDESIRED_MSG_E
Definition: protocol.h:142
@ BAD_TEST_ID_E
Definition: protocol.h:141
@ WRONG_TYPE_E
Definition: protocol.h:145
typename protocol::handler< reactor_controller_group >::message_type reactor_controller_message
Definition: protocol.h:204
constexpr T accumulate(Container &&cont, T init, BinaryCallable &&f)
Applies callable 'f(init,x)' to each element of container 'x' and actual value of 'init' in iteration...
Definition: algorithm.h:261
contiguous_request_adapter_errors
Definition: base.h:46
constexpr std::array< std::byte, N > bytes(Args const &... args)
Conveft the provided arguments into array of std::byte.
Definition: algorithm.h:524
constexpr view< Iterator > init(Container &&cont, int const step=1)
Returns range over Container, which skips last item of container.
Definition: algorithm.h:101
physical_quantity< 0, 0, 0, 0, 0, 0, 0, 0, 1 > byte
Definition: physical_quantity.h:118
Definition: static_function.h:109
Definition: packet.h:50
tuple is high levle alternative to use just 'std::tuple' that is more friendly for standalone protoco...
Definition: tuple.h:43
message< max_size > message_type
Definition: tuple.h:58
result represents an result of some operation, as an alternative to returning just bool with true/fal...
Definition: result.h:42
Definition: protocol.h:114
Definition: protocol.h:152
Definition: protocol.h:119
run_id rid
Definition: protocol.h:121
test_id tid
Definition: protocol.h:122
Definition: protocol.h:70
test_id count
Definition: protocol.h:72
Definition: protocol.h:65
name_buffer date
Definition: protocol.h:84
name_buffer name
Definition: protocol.h:78
name_buffer name
Definition: protocol.h:96
test_id tid
Definition: protocol.h:90
protocol::error_record rec
Definition: protocol.h:171
Definition: protocol.h:157
msgid msg
Definition: protocol.h:159
Definition: protocol.h:218
static constexpr std::array< std::byte, 4 > prefix
Definition: protocol.h:220
static constexpr std::endian endianess
Definition: protocol.h:219
uint16_t size_type
Definition: protocol.h:221
static constexpr checksum_type get_checksum(view< std::byte const * > const msg)
Definition: protocol.h:224
std::byte checksum_type
Definition: protocol.h:222
reactor_error_variant var
Definition: protocol.h:189
Definition: protocol.h:107
run_id rid
Definition: protocol.h:109
test_status status
Definition: protocol.h:110
Definition: protocol.h:100
node_id nid
Definition: protocol.h:103
contiguous_request_adapter_errors err
Definition: protocol.h:102
Definition: protocol.h:163
node_id nid
Definition: protocol.h:165