EV3UartProtocolParserSensorSide
EV3UartProtocolParserSensorSide::Parser Class Reference

#include <EV3UartProtocolParserSensorSide.hpp>

Classes

struct  HeaderInformation
 

Public Member Functions

 Parser ()
 
 Parser (const Parser &)=delete
 
ParserReturn update (uint8_t input)
 
uint8_t * data ()
 
const uint8_t * data () const
 
void reset_state ()
 

Private Member Functions

uint8_t payload_length (const uint8_t hdr)
 
HeaderInformation analyze_header (const uint8_t hdr)
 

Private Attributes

uint8_t buffer [BUFFER_LEN]
 
uint8_t message_payload_length = 0
 
uint8_t message_pending_bytes = 0
 
State current_state = State::STATE_START
 

Detailed Description

Parser for parsing EV3 UART sensor protocol messages that come from the EV3

Definition at line 218 of file EV3UartProtocolParserSensorSide.hpp.

Constructor & Destructor Documentation

◆ Parser() [1/2]

EV3UartProtocolParserSensorSide::Parser::Parser ( )

Definition at line 66 of file EV3UartProtocolParserSensorSide.cpp.

◆ Parser() [2/2]

EV3UartProtocolParserSensorSide::Parser::Parser ( const Parser )
delete

Member Function Documentation

◆ analyze_header()

Parser::HeaderInformation EV3UartProtocolParserSensorSide::Parser::analyze_header ( const uint8_t  hdr)
private

Analyze an EV3 message header

Parameters
hdrmessage header byte
Returns
HeaderInformation structure containing information about the header

Definition at line 22 of file EV3UartProtocolParserSensorSide.cpp.

References EV3UartProtocolParserSensorSide::Parser::HeaderInformation::header_valid.

◆ data() [1/2]

uint8_t * EV3UartProtocolParserSensorSide::Parser::data ( )

Obtain a pointer to the data received from the EV3 by the parser.

Memory addresses up to, (but not including) BUFFER_LEN -1 bytes away from this pointer are guaranteed to be accessible.

Precondition
update() returned a ParserReturn structure that has ParserReturn::res set to any value except ParseResult::INSUFFICIENT_DATA. If this precondition is not met, data can still be viewed through this pointer, but the area pointed to by this pointer SHOULD NOT be modified.
Returns
pointer to the data received from the EV3
res Pointer points to
RECEIVED_INVALID_HEADER Meaningless data
RECEIVED_SYS_ACK Meaningless data
RECEIVED_SYS_NACK Meaningless data
RECEIVED_CMD_SELECT SELECT message's payload
RECEIVED_CMD_WRITE WRITE message's payload
RECEIVED_CMD_INVALID_FCS Payload of message with invalid FCS
Warning
The block of memory pointed to by the returned pointer may be modified by update() on the next call to that function. Ownership of this area of memory is NOT TRANSFERRED to the user's application. If the payload needs to be reused after another call to update() , it needs to be copied to another buffer.

Definition at line 134 of file EV3UartProtocolParserSensorSide.cpp.

◆ data() [2/2]

const uint8_t * EV3UartProtocolParserSensorSide::Parser::data ( ) const

Provides the same functionality as the similarly named function, except that it returns a pointer to a memory region that cannot be modified.

See also
update()
Returns
pointer to the data received from the EV3

Definition at line 138 of file EV3UartProtocolParserSensorSide.cpp.

◆ payload_length()

uint8_t EV3UartProtocolParserSensorSide::Parser::payload_length ( const uint8_t  hdr)
private

Obtain the payload length from a valid message header byte

Parameters
hdrmessage header byte
Returns
payload length of a particular message, in bytes.

Definition at line 18 of file EV3UartProtocolParserSensorSide.cpp.

References EV3UartProtocolParserSensorSide::two_pow().

Here is the call graph for this function:

◆ reset_state()

void EV3UartProtocolParserSensorSide::Parser::reset_state ( )

Reset the state of the parser, so that the next byte input into the parser will be treated as a header byte candidate.

Definition at line 142 of file EV3UartProtocolParserSensorSide.cpp.

References EV3UartProtocolParserSensorSide::STATE_START.

◆ update()

Member Data Documentation

◆ buffer

uint8_t EV3UartProtocolParserSensorSide::Parser::buffer[BUFFER_LEN]
private

Internal buffer used to buffer information from the EV3.

buffer[0] stores the header byte received from the EV3 buffer[1] stores the first byte of the payload from the EV3 buffer[payload_length + 1] stores the FCS byte received from the EV3

Definition at line 227 of file EV3UartProtocolParserSensorSide.hpp.

◆ current_state

State EV3UartProtocolParserSensorSide::Parser::current_state = State::STATE_START
private

Definition at line 230 of file EV3UartProtocolParserSensorSide.hpp.

◆ message_payload_length

uint8_t EV3UartProtocolParserSensorSide::Parser::message_payload_length = 0
private

Definition at line 228 of file EV3UartProtocolParserSensorSide.hpp.

◆ message_pending_bytes

uint8_t EV3UartProtocolParserSensorSide::Parser::message_pending_bytes = 0
private

Definition at line 229 of file EV3UartProtocolParserSensorSide.hpp.


The documentation for this class was generated from the following files: