67 using namespace boost::asio;
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();
108 extendedNavigationParsers(
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();
149 internalBuffer{128000}
210 const size_t answerSize =
213 buffer_copy(boost::asio::buffer(
lastAnswer), buffer, answerSize);
214 buffer = buffer + answerSize;
229 switch(protocol_version)
238 throw std::runtime_error(
"Unhandled protocol version");
243 if(protocol_version >= 3 && protocol_version <= 5)
251 throw std::runtime_error(
"Unhandled protocol version for an answer");
270 buffer = buffer + checksumPositionInFrame;
271 uint32_t receivedChecksum = 0;
272 buffer >> receivedChecksum;
274 const uint32_t computedChecksum = std::accumulate(
277 if(receivedChecksum != computedChecksum)
282 std::ostringstream ss;
283 ss <<
"Bad checksum. Received: 0x" << std::hex << receivedChecksum
284 <<
", computed: 0x" << computedChecksum;
285 throw std::runtime_error(ss.str());
293 static constexpr
size_t HEADER_MINIMAL_SIZE = 3;
296 if(buffer_size(buffer) < HEADER_MINIMAL_SIZE)
298 throw std::runtime_error(
"Not enough bytes in buffer to parse header");
304 throw std::runtime_error(
"Incorrect frame header, expected 'I', 'X' or 'A', 'N'");
310 throw std::runtime_error(
311 "Unknown protocol version. Supported protocol are version 2->5");
319 uint32_t extendedNavigationMask;
320 buffer >> extendedNavigationMask;
324 uint16_t navigationSize = 0;
327 buffer >> navigationSize;
348 if(h1 ==
'I' && h2 ==
'X')
353 if(h1 ==
'A' && h2 ==
'N')