Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Static Private Attributes | List of all members
ixblue_stdbin_decoder::StdBinDecoder Class Reference

Parser of a STDBIN IXblue message. This is the entry point of the library. Usage of this class is as follow : More...

#include <stdbin_decoder.h>

Inheritance diagram for ixblue_stdbin_decoder::StdBinDecoder:
Inheritance graph
[legend]

Public Member Functions

void addNewData (const uint8_t *data, std::size_t length)
 Add new binary data to the parser internal buffer The new data can only be a part of a frame, the parser will manage to assemble the several parts in order to decode it. More...
 
void addNewData (const std::vector< uint8_t > &data)
 Add new binary data to the parser internal buffer The new data can only be a part of a frame, the parser will manage to assemble the several parts in order to decode it. More...
 
const std::vector< uint8_t > & getLastAnswerData (void) const
 
Data::NavHeader getLastHeaderData (void) const
 
Data::BinaryNav getLastNavData (void) const
 
bool parseNextFrame ()
 Try to parse a frame from the parser internal buffer. Some binary data must have been added with the addNewData() method beforehand. This method is able to handle buffer with header at the middle of the frame as found on connection-less communication like serial port (RS-232). More...
 
 StdBinDecoder ()
 

Protected Member Functions

void compareChecksum ()
 Compute current frame checksum and compare with the frame checksum. If mismatch, throw std::runtime_error exception.

Exceptions
runtime_errorif bad checksum.
More...
 
Data::NavHeader::MessageType getHeaderType (boost::asio::const_buffer &buffer) const
 
bool haveEnoughBytesToParseHeader ()
 
Data::NavHeader parseHeader (boost::asio::const_buffer &buffer) const
 

Protected Attributes

const tParsersSet extendedNavigationParsers
 
const tParsersSet externalDataParsers
 
boost::circular_buffer< uint8_t > internalBuffer
 
std::vector< uint8_t > lastAnswer
 
Data::NavHeader lastHeader
 
Data::BinaryNav lastParsed
 
const tParsersSet navigationParsers
 

Private Types

typedef std::set< MemoryBlockParserPtr, std::function< bool(const MemoryBlockParserPtr &, const MemoryBlockParserPtr &)> > tParsersSet
 

Static Private Attributes

static constexpr size_t ANSWER_HEADER_SIZE = 5
 
static constexpr size_t CHECKSUM_SIZE = 4
 
static constexpr size_t HEADER_SIZE_V2 = 21
 
static constexpr size_t HEADER_SIZE_V3 = 25
 
static constexpr size_t HEADER_SIZE_V4 = 27
 
static constexpr size_t HEADER_SIZE_V5 = 27
 

Detailed Description

Parser of a STDBIN IXblue message. This is the entry point of the library. Usage of this class is as follow :

try{
if(parser.parse(buffer)) {
auto navDatas = parser.getLastMessage();
}
}catch(std::runtime_error& e){
// Parsing error are reported by throwing std::runtime_exception.
}

parse method can be called with a partial buffer. Data will be agglomerated until the full frame have been received.

Definition at line 33 of file stdbin_decoder.h.

Member Typedef Documentation

Definition at line 40 of file stdbin_decoder.h.

Constructor & Destructor Documentation

ixblue_stdbin_decoder::StdBinDecoder::StdBinDecoder ( )

Definition at line 72 of file stdbin_decoder.cpp.

Member Function Documentation

void ixblue_stdbin_decoder::StdBinDecoder::addNewData ( const uint8_t *  data,
std::size_t  length 
)

Add new binary data to the parser internal buffer The new data can only be a part of a frame, the parser will manage to assemble the several parts in order to decode it.

Parameters
dataa pointer to a contiguous memory buffer
lengththe amount of bytes to read from the buffer

Definition at line 158 of file stdbin_decoder.cpp.

void ixblue_stdbin_decoder::StdBinDecoder::addNewData ( const std::vector< uint8_t > &  data)

Add new binary data to the parser internal buffer The new data can only be a part of a frame, the parser will manage to assemble the several parts in order to decode it.

Parameters
dataa std::vector containing data to copy into the internal buffer
Warning
The vector must be full of received bytes because it will be entirely copied to the internal buffer. If the vector is only partially filled, use the other oveload:
std::vector<uint8_t> buf(2000);
std::size_t byteRead = socket.read(buf);
// here, the buf only contains byteRead valid bytes
parser.addNewData(buf.data(), bytesRead);

Definition at line 153 of file stdbin_decoder.cpp.

void ixblue_stdbin_decoder::StdBinDecoder::compareChecksum ( )
protected

Compute current frame checksum and compare with the frame checksum. If mismatch, throw std::runtime_error exception.

Exceptions
runtime_errorif bad checksum.

Definition at line 259 of file stdbin_decoder.cpp.

Data::NavHeader::MessageType ixblue_stdbin_decoder::StdBinDecoder::getHeaderType ( boost::asio::const_buffer &  buffer) const
protected

Definition at line 333 of file stdbin_decoder.cpp.

const std::vector<uint8_t>& ixblue_stdbin_decoder::StdBinDecoder::getLastAnswerData ( void  ) const
inline

Definition at line 91 of file stdbin_decoder.h.

Data::NavHeader ixblue_stdbin_decoder::StdBinDecoder::getLastHeaderData ( void  ) const
inline

Definition at line 90 of file stdbin_decoder.h.

Data::BinaryNav ixblue_stdbin_decoder::StdBinDecoder::getLastNavData ( void  ) const
inline

Definition at line 89 of file stdbin_decoder.h.

bool ixblue_stdbin_decoder::StdBinDecoder::haveEnoughBytesToParseHeader ( )
protected

Definition at line 222 of file stdbin_decoder.cpp.

Data::NavHeader ixblue_stdbin_decoder::StdBinDecoder::parseHeader ( boost::asio::const_buffer &  buffer) const
protected
Exceptions
runtime_errorif a parse error occurs.

Definition at line 281 of file stdbin_decoder.cpp.

bool ixblue_stdbin_decoder::StdBinDecoder::parseNextFrame ( )

Try to parse a frame from the parser internal buffer. Some binary data must have been added with the addNewData() method beforehand. This method is able to handle buffer with header at the middle of the frame as found on connection-less communication like serial port (RS-232).

Returns
true if the frame has been completly parsed, false otherwise. If frame has been parsed, result is accessible via getLastNavData();
Exceptions
runtime_errorif a parse error occurs.

Definition at line 163 of file stdbin_decoder.cpp.

Member Data Documentation

constexpr size_t ixblue_stdbin_decoder::StdBinDecoder::ANSWER_HEADER_SIZE = 5
staticprivate

Definition at line 46 of file stdbin_decoder.h.

constexpr size_t ixblue_stdbin_decoder::StdBinDecoder::CHECKSUM_SIZE = 4
staticprivate

Definition at line 47 of file stdbin_decoder.h.

const tParsersSet ixblue_stdbin_decoder::StdBinDecoder::extendedNavigationParsers
protected

Definition at line 110 of file stdbin_decoder.h.

const tParsersSet ixblue_stdbin_decoder::StdBinDecoder::externalDataParsers
protected

Definition at line 111 of file stdbin_decoder.h.

constexpr size_t ixblue_stdbin_decoder::StdBinDecoder::HEADER_SIZE_V2 = 21
staticprivate

Definition at line 42 of file stdbin_decoder.h.

constexpr size_t ixblue_stdbin_decoder::StdBinDecoder::HEADER_SIZE_V3 = 25
staticprivate

Definition at line 43 of file stdbin_decoder.h.

constexpr size_t ixblue_stdbin_decoder::StdBinDecoder::HEADER_SIZE_V4 = 27
staticprivate

Definition at line 44 of file stdbin_decoder.h.

constexpr size_t ixblue_stdbin_decoder::StdBinDecoder::HEADER_SIZE_V5 = 27
staticprivate

Definition at line 45 of file stdbin_decoder.h.

boost::circular_buffer<uint8_t> ixblue_stdbin_decoder::StdBinDecoder::internalBuffer
protected

Definition at line 119 of file stdbin_decoder.h.

std::vector<uint8_t> ixblue_stdbin_decoder::StdBinDecoder::lastAnswer
protected

Definition at line 115 of file stdbin_decoder.h.

Data::NavHeader ixblue_stdbin_decoder::StdBinDecoder::lastHeader
protected

Definition at line 114 of file stdbin_decoder.h.

Data::BinaryNav ixblue_stdbin_decoder::StdBinDecoder::lastParsed
protected

Definition at line 113 of file stdbin_decoder.h.

const tParsersSet ixblue_stdbin_decoder::StdBinDecoder::navigationParsers
protected

Definition at line 109 of file stdbin_decoder.h.


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


ixblue_stdbin_decoder
Author(s): Adrien BARRAL , Laure LEBROTON
autogenerated on Sat Jan 9 2021 03:13:21