EV3UartProtocolParserSensorSide
EV3UartProtocolParserSensorSide Documentation

This is a C++ parser library for the EV3 UART protocol, meant to decode messages that may arrive at the sensor side of the connection.

Usage

  • Add the following folders to your include paths:
    • EV3UartGenerator/
    • / (root folder of this library)
  • Add the source files in the following folders to the list of built files:
    • EV3UartGenerator/
    • / (root folder of this library)
  • All operations must be done non-recursively

The EV3UartProtocolParserSensorSide::Parser accepts data, byte-by-byte from any UART backend that supplies data that is sent from the EV3 to the sensor.

uint8_t data = uart_get_byte();
Parser p { };
p.update(data);

The parse result is available from the EV3UartProtocolParserSensorSide::Parser::update() function as a ParserReturn structure:

uint8_t data = uart_get_byte();
Parser p { };
ParserReturn r = p.update(data);

The various fields in the EV3UartProtocolParserSensorSide::ParserReturn structure offers more information on what was parsed. EV3UartProtocolParserSensorSide::Parser::data() obtains the payload of the message sent from the EV3, if the header byte from the EV3 does not represent the entirety of the message (i.e. CMD_WRITE and CMD_SELECT messages)

Parser p { };
uint8_t* data = p.data();

If there is a need to reset the state of the parser, i.e. the connection between the EV3 and the sensor has been reset, the function EV3UartProtocolParserSensorSide::Parser::reset_state() can be called. The next byte parsed will be treated as a header byte.

Parser p { };
p.reset_state();

For more information, see EV3UartProtocolParserSensorSide

Tests

This library uses the Catch2 testing framework: https://github.com/catchorg/Catch2

Tests are located under the test/ subfolder.

To build and run the tests,

  • Add the test/ folder recursively to your build path
  • Run the compiled executable.

Licensed under the MIT license.

See LICENSE for more details.