EV3UartGenerator
/home/shenghao/eclipse-workspace/EV3UartGenerator/framing.hpp
Go to the documentation of this file.
1 
31 #ifndef FRAMING_HPP_
32 #define FRAMING_HPP_
33 
34 #include <magics.hpp>
35 
36 namespace EV3UartGenerator {
37 namespace Framing {
38  constexpr uint8_t BUFFER_MIN { 0x23 };
39  constexpr uint8_t PAYLOAD_SENSOR_TO_EV3_MAX { 0x20 };
40  constexpr uint8_t PAYLOAD_EV3_TO_SENSOR_MAX { 0x20 };
41  constexpr uint8_t PAYLOAD_MIN { 0x01 };
42  constexpr uint8_t SYMBOL_MAX { 0x08 };
43 
51  int8_t frame_sys_message(uint8_t* dest, Magics::SYS sys_type);
52 
61  int8_t frame_cmd_type_message(uint8_t* dest, const uint8_t type);
62 
80  int8_t frame_cmd_modes_message(uint8_t* dest, const uint8_t modes,
81  const uint8_t modes_visible);
82 
92  int8_t frame_cmd_speed_message(uint8_t* dest, const uint32_t speed);
93 
102  int8_t frame_cmd_select_message(uint8_t* dest, const uint8_t mode);
103 
114  int8_t frame_cmd_write_message(uint8_t* dest, const uint8_t* data,
115  const uint8_t len);
116 
133  int8_t frame_info_message_name(uint8_t* dest, const uint8_t mode,
134  const char* name);
135 
158  int8_t frame_info_message_span(uint8_t* dest, const uint8_t mode,
159  Magics::INFO_SPAN span_type,
160  const float lower, const float upper);
161 
180  int8_t frame_info_message_symbol(uint8_t* dest, const uint8_t mode,
181  const char* symbol);
182 
212  int8_t frame_info_message_format(uint8_t* dest, const uint8_t mode,
213  const uint8_t elems,
214  Magics::INFO_DTYPE data_type, const uint8_t width,
215  const uint8_t decimals);
216 
232  int8_t frame_data_message(uint8_t* dest, const uint8_t mode,
233  const uint8_t* data,
234  const uint8_t len);
235 
244  uint8_t checksum(const uint8_t* buf, const uint8_t len);
245 
256  constexpr uint8_t log2(uint8_t val) {
257  return (0x1f - __builtin_clz(val)) +
258  (val - (0x01 << (0x1f -__builtin_clz(val))) != 0 ? 1 : 0);
259  }
260 
270  constexpr uint8_t length_code(uint8_t len) {
271  return log2(len) << 0x03;
272  }
273 
284  uint8_t insert_padding(uint8_t* dest, uint8_t len);
285 }
286 }
287 
288 #endif /* FRAMING_HPP_ */
constexpr uint8_t log2(uint8_t val)
Definition: framing.hpp:256
constexpr uint8_t PAYLOAD_EV3_TO_SENSOR_MAX
Maximum size of any payload sent in the EV3 UART sensor protocol, in bytes, from the EV3 to the senso...
Definition: framing.hpp:40
constexpr uint8_t PAYLOAD_SENSOR_TO_EV3_MAX
Maximum size of any payload sent in the EV3 UART sensor protocol, in bytes, to the EV3...
Definition: framing.hpp:39
constexpr uint8_t BUFFER_MIN
Minimum size of the buffer (in bytes) that the user has to provide to each of the framing functions...
Definition: framing.hpp:38
constexpr uint8_t PAYLOAD_MIN
Minimum size of any payload sent in the EV3 UART sensor protocol, regardless of direction, in bytes.
Definition: framing.hpp:41
constexpr uint8_t length_code(uint8_t len)
Definition: framing.hpp:270
constexpr uint8_t SYMBOL_MAX
Maximum length of the string representation (ASCII) of any symbol referencing a the SI unit used to r...
Definition: framing.hpp:42