stdbin_decoder.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "data_models/stdbin.h"
5 #include "memory_block_parser.h"
6 
7 #include <boost/circular_buffer.hpp>
8 #include <boost/noncopyable.hpp>
9 
10 #include <functional>
11 #include <set>
12 
13 namespace ixblue_stdbin_decoder
14 {
15 
33 class StdBinDecoder : private boost::noncopyable
34 {
35  // we sort the parsers list by offsetMask because this is a design constraint. We need
36  // to process parser in the same order than data are filled in memory.
37  typedef std::set<
39  std::function<bool(const MemoryBlockParserPtr&, const MemoryBlockParserPtr&)>>
41 
42  static constexpr size_t HEADER_SIZE_V2 = 21;
43  static constexpr size_t HEADER_SIZE_V3 = 25;
44  static constexpr size_t HEADER_SIZE_V4 = 27;
45  static constexpr size_t HEADER_SIZE_V5 = 27;
46  static constexpr size_t ANSWER_HEADER_SIZE = 5;
47  static constexpr size_t CHECKSUM_SIZE = 4;
48 
49 public:
50  StdBinDecoder();
51 
59  void addNewData(const uint8_t* data, std::size_t length);
60 
76  void addNewData(const std::vector<uint8_t>& data);
77 
87  bool parseNextFrame();
88 
89  Data::BinaryNav getLastNavData(void) const { return lastParsed; }
91  const std::vector<uint8_t>& getLastAnswerData(void) const { return lastAnswer; }
92 
93 protected:
97  Data::NavHeader parseHeader(boost::asio::const_buffer& buffer) const;
98  Data::NavHeader::MessageType getHeaderType(boost::asio::const_buffer& buffer) const;
105  void compareChecksum();
106  // We set the parsers set "constant" to be sure that the content of this set will be
107  // the same during all the lifetime of this object. We can only add memory bloc parser
108  // at construction.
112 
115  std::vector<uint8_t> lastAnswer;
116 
117  // We store in this buffer the current frame's data. This memory chunk is managed by
118  // the parsing state machine. See function \c parse.
119  boost::circular_buffer<uint8_t> internalBuffer;
120 };
121 } // namespace ixblue_stdbin_decoder
ixblue_stdbin_decoder::StdBinDecoder::getLastHeaderData
Data::NavHeader getLastHeaderData(void) const
Definition: stdbin_decoder.h:90
ixblue_stdbin_decoder::StdBinDecoder::CHECKSUM_SIZE
static constexpr size_t CHECKSUM_SIZE
Definition: stdbin_decoder.h:47
ixblue_stdbin_decoder::Data::NavHeader
Definition: nav_header.h:9
ixblue_stdbin_decoder::StdBinDecoder::tParsersSet
std::set< MemoryBlockParserPtr, std::function< bool(const MemoryBlockParserPtr &, const MemoryBlockParserPtr &)> > tParsersSet
Definition: stdbin_decoder.h:40
ixblue_stdbin_decoder::StdBinDecoder::StdBinDecoder
StdBinDecoder()
Definition: stdbin_decoder.cpp:72
ixblue_stdbin_decoder::StdBinDecoder::lastAnswer
std::vector< uint8_t > lastAnswer
Definition: stdbin_decoder.h:115
ixblue_stdbin_decoder::StdBinDecoder::addNewData
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,...
Definition: stdbin_decoder.cpp:158
memory_block_parser.h
ixblue_stdbin_decoder::StdBinDecoder::getHeaderType
Data::NavHeader::MessageType getHeaderType(boost::asio::const_buffer &buffer) const
Definition: stdbin_decoder.cpp:341
ixblue_stdbin_decoder::StdBinDecoder::HEADER_SIZE_V5
static constexpr size_t HEADER_SIZE_V5
Definition: stdbin_decoder.h:45
ixblue_stdbin_decoder::StdBinDecoder::HEADER_SIZE_V4
static constexpr size_t HEADER_SIZE_V4
Definition: stdbin_decoder.h:44
ixblue_stdbin_decoder::StdBinDecoder::getLastNavData
Data::BinaryNav getLastNavData(void) const
Definition: stdbin_decoder.h:89
ixblue_stdbin_decoder::StdBinDecoder::HEADER_SIZE_V2
static constexpr size_t HEADER_SIZE_V2
Definition: stdbin_decoder.h:42
ixblue_stdbin_decoder::StdBinDecoder::extendedNavigationParsers
const tParsersSet extendedNavigationParsers
Definition: stdbin_decoder.h:110
nav_header.h
ixblue_stdbin_decoder::StdBinDecoder::parseHeader
Data::NavHeader parseHeader(boost::asio::const_buffer &buffer) const
Definition: stdbin_decoder.cpp:289
ixblue_stdbin_decoder::MemoryBlockParserPtr
std::shared_ptr< MemoryBlockParser > MemoryBlockParserPtr
Definition: memory_block_parser.h:57
ixblue_stdbin_decoder::StdBinDecoder::compareChecksum
void compareChecksum()
Compute current frame checksum and compare with the frame checksum. If mismatch, throw std::runtime_e...
Definition: stdbin_decoder.cpp:264
ixblue_stdbin_decoder::StdBinDecoder::parseNextFrame
bool parseNextFrame()
Try to parse a frame from the parser internal buffer. Some binary data must have been added with the ...
Definition: stdbin_decoder.cpp:163
ixblue_stdbin_decoder::StdBinDecoder::externalDataParsers
const tParsersSet externalDataParsers
Definition: stdbin_decoder.h:111
ixblue_stdbin_decoder::Data::NavHeader::MessageType
MessageType
Definition: nav_header.h:11
ixblue_stdbin_decoder::Data::BinaryNav
Definition: stdbin.h:67
ixblue_stdbin_decoder::StdBinDecoder::getLastAnswerData
const std::vector< uint8_t > & getLastAnswerData(void) const
Definition: stdbin_decoder.h:91
ixblue_stdbin_decoder::StdBinDecoder::lastHeader
Data::NavHeader lastHeader
Definition: stdbin_decoder.h:114
ixblue_stdbin_decoder::StdBinDecoder
Parser of a STDBIN IXblue message. This is the entry point of the library. Usage of this class is as ...
Definition: stdbin_decoder.h:33
ixblue_stdbin_decoder::StdBinDecoder::HEADER_SIZE_V3
static constexpr size_t HEADER_SIZE_V3
Definition: stdbin_decoder.h:43
ixblue_stdbin_decoder::StdBinDecoder::navigationParsers
const tParsersSet navigationParsers
Definition: stdbin_decoder.h:109
ixblue_stdbin_decoder::StdBinDecoder::ANSWER_HEADER_SIZE
static constexpr size_t ANSWER_HEADER_SIZE
Definition: stdbin_decoder.h:46
ixblue_stdbin_decoder::StdBinDecoder::internalBuffer
boost::circular_buffer< uint8_t > internalBuffer
Definition: stdbin_decoder.h:119
stdbin.h
ixblue_stdbin_decoder::StdBinDecoder::lastParsed
Data::BinaryNav lastParsed
Definition: stdbin_decoder.h:113
ixblue_stdbin_decoder
Definition: data_models/extended_navigation_data/raw_rotation_rate_vessel_frame.h:3
ixblue_stdbin_decoder::StdBinDecoder::haveEnoughBytesToParseHeader
bool haveEnoughBytesToParseHeader()
Definition: stdbin_decoder.cpp:222


ixblue_stdbin_decoder
Author(s): Adrien BARRAL , Laure LEBROTON
autogenerated on Wed Apr 6 2022 02:55:48