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
static constexpr size_t HEADER_SIZE_V2
boost::circular_buffer< uint8_t > internalBuffer
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...
static constexpr size_t HEADER_SIZE_V5
Data::BinaryNav getLastNavData(void) const
std::shared_ptr< MemoryBlockParser > MemoryBlockParserPtr
void compareChecksum()
Compute current frame checksum and compare with the frame checksum. If mismatch, throw std::runtime_e...
bool parseNextFrame()
Try to parse a frame from the parser internal buffer. Some binary data must have been added with the ...
const std::vector< uint8_t > & getLastAnswerData(void) const
Data::NavHeader getLastHeaderData(void) const
static constexpr size_t ANSWER_HEADER_SIZE
static constexpr size_t HEADER_SIZE_V3
std::set< MemoryBlockParserPtr, std::function< bool(const MemoryBlockParserPtr &, const MemoryBlockParserPtr &)> > tParsersSet
static constexpr size_t CHECKSUM_SIZE
Data::NavHeader::MessageType getHeaderType(boost::asio::const_buffer &buffer) const
static constexpr size_t HEADER_SIZE_V4
Data::NavHeader parseHeader(boost::asio::const_buffer &buffer) const
Parser of a STDBIN IXblue message. This is the entry point of the library. Usage of this class is as ...


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