72 StdBinDecoder::StdBinDecoder()
74 {std::make_shared<Parser::AttitudeHeading>(),
75 std::make_shared<Parser::AttitudeHeadingDeviation>(),
76 std::make_shared<Parser::RealTimeHeaveSurgeSway>(),
77 std::make_shared<Parser::SmartHeave>(),
78 std::make_shared<Parser::HeadingRollPitchRate>(),
79 std::make_shared<Parser::RotationRateVesselFrame>(),
80 std::make_shared<Parser::AccelerationVesselFrame>(),
81 std::make_shared<Parser::Position>(),
82 std::make_shared<Parser::PositionDeviation>(),
83 std::make_shared<Parser::SpeedGeographicFrame>(),
84 std::make_shared<Parser::SpeedGeographicFrameDeviation>(),
85 std::make_shared<Parser::CurrentGeographicFrame>(),
86 std::make_shared<Parser::CurrentGeographicFrameDeviation>(),
87 std::make_shared<Parser::SystemDate>(),
88 std::make_shared<Parser::SensorStatus>(),
89 std::make_shared<Parser::INSAlgorithmStatus>(),
90 std::make_shared<Parser::INSSystemStatus>(),
91 std::make_shared<Parser::INSUserStatus>(),
92 std::make_shared<Parser::AHRSAlgorithmStatus>(),
93 std::make_shared<Parser::AHRSSystemStatus>(),
94 std::make_shared<Parser::AHRSUserStatus>(),
95 std::make_shared<Parser::HeaveSurgeSwaySpeed>(),
96 std::make_shared<Parser::SpeedVesselFrame>(),
97 std::make_shared<Parser::AccelerationGeographicFrame>(),
98 std::make_shared<Parser::CourseSpeedoverGround>(),
99 std::make_shared<Parser::Temperatures>(),
100 std::make_shared<Parser::AttitudeQuaternion>(),
101 std::make_shared<Parser::AttitudeQuaternionDeviation>(),
102 std::make_shared<Parser::RawAccelerationVesselFrame>(),
103 std::make_shared<Parser::AccelerationVesselFrameDeviation>(),
104 std::make_shared<Parser::RotationRateVesselFrameDeviation>()},
106 return lhs->getOffsetInMask() < rhs->getOffsetInMask();
109 {std::make_shared<Parser::RotationAccelerationVesselFrame>(),
110 std::make_shared<Parser::RotationAccelerationVesselFrameDeviation>(),
111 std::make_shared<Parser::RawRotationRateVesselFrame>(),
112 std::make_shared<Parser::VehicleAttitudeHeading>(),
113 std::make_shared<Parser::VehiclePosition>(),
114 std::make_shared<Parser::VehiclePositionDeviation>()},
116 return lhs->getOffsetInMask() < rhs->getOffsetInMask();
119 {std::make_shared<Parser::Utc>(),
120 std::make_shared<Parser::Gnss1>(),
121 std::make_shared<Parser::Gnss2>(),
122 std::make_shared<Parser::GnssManual>(),
123 std::make_shared<Parser::Emlog1>(),
124 std::make_shared<Parser::Emlog2>(),
125 std::make_shared<Parser::Depth>(),
126 std::make_shared<Parser::Usbl1>(),
127 std::make_shared<Parser::Usbl2>(),
128 std::make_shared<Parser::Usbl3>(),
129 std::make_shared<Parser::DvlGroundSpeed1>(),
130 std::make_shared<Parser::DvlWaterSpeed1>(),
131 std::make_shared<Parser::SoundVelocity>(),
132 std::make_shared<Parser::Dmi>(),
133 std::make_shared<Parser::Lbl1>(),
134 std::make_shared<Parser::Lbl2>(),
135 std::make_shared<Parser::Lbl3>(),
136 std::make_shared<Parser::Lbl4>(),
137 std::make_shared<Parser::EventMarkerA>(),
138 std::make_shared<Parser::EventMarkerB>(),
139 std::make_shared<Parser::EventMarkerC>(),
140 std::make_shared<Parser::DvlGroundSpeed2>(),
141 std::make_shared<Parser::DvlWaterSpeed2>(),
142 std::make_shared<Parser::TurretAngles>(),
143 std::make_shared<Parser::Vtg1>(),
144 std::make_shared<Parser::Vtg2>(),
145 std::make_shared<Parser::LogBook>()},
147 return lhs->getOffsetInMask() < rhs->getOffsetInMask();
190 parser->parse(buffer, lastHeader.navigationBitMask,
lastParsed);
193 if(lastHeader.extendedNavigationBitMask.is_initialized())
197 parser->parse(buffer, lastHeader.extendedNavigationBitMask.get(),
204 parser->parse(buffer, lastHeader.externalSensorBitMask,
lastParsed);
210 const size_t answerSize =
213 buffer_copy(boost::asio::buffer(
lastAnswer), buffer, answerSize);
214 buffer = buffer + answerSize;
229 switch(protocol_version)
235 default:
throw std::runtime_error(
"Unhandled protocol version");
240 if(protocol_version >= 3 && protocol_version <= 5)
246 throw std::runtime_error(
"Unhandled protocol version for an answer");
265 buffer = buffer + checksumPositionInFrame;
266 uint32_t receivedChecksum = 0;
267 buffer >> receivedChecksum;
269 const uint32_t computedChecksum = std::accumulate(
272 if(receivedChecksum != computedChecksum)
274 std::ostringstream ss;
275 ss <<
"Bad checksum. Received: 0x" << std::hex << receivedChecksum
276 <<
", computed: 0x" << computedChecksum;
277 throw std::runtime_error(ss.str());
285 static constexpr
size_t HEADER_MINIMAL_SIZE = 3;
288 if(buffer_size(buffer) < HEADER_MINIMAL_SIZE)
290 throw std::runtime_error(
"Not enough bytes in buffer to parse header");
296 throw std::runtime_error(
"Incorrect frame header, expected 'I', 'X' or 'A', 'N'");
302 throw std::runtime_error(
303 "Unknown protocol version. Supported protocol are version 2->5");
311 uint32_t extendedNavigationMask;
312 buffer >> extendedNavigationMask;
316 uint16_t navigationSize = 0;
319 buffer >> navigationSize;
340 if(h1 ==
'I' && h2 ==
'X')
345 if(h1 ==
'A' && h2 ==
'N')
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
bool haveEnoughBytesToParseHeader()
const tParsersSet extendedNavigationParsers
std::shared_ptr< MemoryBlockParser > MemoryBlockParserPtr
const tParsersSet externalDataParsers
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 tParsersSet navigationParsers
std::vector< uint8_t > lastAnswer
Data::BinaryNav lastParsed
static constexpr size_t ANSWER_HEADER_SIZE
static constexpr size_t HEADER_SIZE_V3
Data::NavHeader lastHeader
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