EV3UartProtocolParserSensorSide
/home/shenghao/eclipse-workspace/EV3UartProtocolParserSensorSide/EV3UartProtocolParserSensorSide.hpp
Go to the documentation of this file.
1 
86 #ifndef EV3UARTPROTOCOLPARSERSENSORSIDE_HPP_
87 #define EV3UARTPROTOCOLPARSERSENSORSIDE_HPP_
88 
89 #include <magics.hpp>
90 #include <framing.hpp>
91 
93 
98 constexpr uint8_t BUFFER_LEN { EV3UartGenerator::Framing::BUFFER_MIN };
99 
108 constexpr uint8_t two_pow(uint8_t val) {
109  return (0x01 << val);
110 }
111 
115 enum class State : uint8_t {
116  STATE_START = 0,
117  WAIT_HEADER = 0,
118  WAIT_CHECKSUM = 1,
119  STATE_END = 1,
120 };
121 
130 constexpr State next_state(State st) {
131  if ((static_cast<uint8_t>(st))
132  != (static_cast<uint8_t>(State::STATE_END)))
133  return static_cast<State>(static_cast<uint8_t>(st) + 1);
134  else
135  return State::STATE_START;
136 }
137 
142 enum class ParseResult : uint8_t {
181 };
182 
208 struct ParserReturn {
210  uint8_t hdr;
211  uint8_t len;
212 };
213 
218 class Parser {
219 private:
227  uint8_t buffer[BUFFER_LEN];
231 
237  uint8_t payload_length(const uint8_t hdr);
238 
259  uint8_t payload_length;
260  };
268  HeaderInformation analyze_header(const uint8_t hdr);
269 public:
270 
271  // We use the default constructor, because we don't really need to do
272  // anything
273 
274  Parser();
275  Parser(const Parser&) = delete;
276 
283  ParserReturn update(uint8_t input);
284 
315  uint8_t* data();
316 
325  const uint8_t* data() const;
326 
331  void reset_state();
332 };
333 }
334 
335 
336 
337 
338 #endif /* EV3UARTPROTOCOLPARSERSENSORSIDE_HPP_ */
Parser is waiting for the checksum byte.
HeaderInformation analyze_header(const uint8_t hdr)
uint8_t len
Payload length of the parsed message.
Parser is waiting for the header byte.