37 #include <boost/spirit/include/qi_binary.hpp>
47 const double pihalf = boost::math::constants::pi<double>() / 2.0;
49 namespace qi = boost::spirit::qi;
53 return std::remainder(
angle, 360.0);
59 qi::parse(buffer, buffer + 8, qi::little_bin_double, val);
68 [[nodiscard]]
bool parseDouble(
const std::string&
string,
double& value)
76 qi::parse(buffer, buffer + 4, qi::little_bin_float, val);
85 [[nodiscard]]
bool parseFloat(
const std::string&
string,
float& value)
100 qi::parse(buffer, buffer + 2, qi::little_word, val);
109 [[nodiscard]]
bool parseInt16(
const std::string&
string, int16_t& value,
120 intermd <= std::numeric_limits<int16_t>::max() &&
121 intermd >= std::numeric_limits<int16_t>::min())
123 value =
static_cast<int16_t
>(intermd);
133 qi::parse(buffer, buffer + 4, qi::little_dword, val);
142 [[nodiscard]]
bool parseInt32(
const std::string&
string, int32_t& value,
153 [[nodiscard]]
bool parseUInt8(
const std::string&
string, uint8_t& value,
164 intermd <= std::numeric_limits<uint8_t>::max())
166 value =
static_cast<uint8_t
>(intermd);
176 qi::parse(buffer, buffer + 2, qi::little_word, val);
185 [[nodiscard]]
bool parseUInt16(
const std::string&
string, uint16_t& value,
196 intermd <= std::numeric_limits<uint16_t>::max())
198 value =
static_cast<uint16_t
>(intermd);
208 qi::parse(buffer, buffer + 4, qi::little_dword, val);
217 [[nodiscard]]
bool parseUInt32(
const std::string&
string, uint32_t& value,
230 uint32_t hours =
static_cast<uint32_t
>(utc_double) / 10000;
231 uint32_t minutes = (
static_cast<uint32_t
>(utc_double) - hours * 10000) / 100;
233 return utc_double -
static_cast<double>(hours * 10000 + minutes * 100) +
234 static_cast<double>(hours * 3600 + minutes * 60);
244 uint32_t whole_degrees =
static_cast<uint32_t
>(dms) / 100;
245 double minutes = dms -
static_cast<double>(whole_degrees * 100);
246 return static_cast<double>(whole_degrees) + minutes / 60.0;
267 time_t time_now = time(0);
273 timeinfo = gmtime(&time_now);
275 uint32_t hours =
static_cast<uint32_t
>(utc_double) / 10000;
276 uint32_t minutes = (
static_cast<uint32_t
>(utc_double) - hours * 10000) / 100;
278 (
static_cast<uint32_t
>(utc_double) - hours * 10000 - minutes * 100);
281 timeinfo->tm_hour = hours;
282 timeinfo->tm_min = minutes;
283 timeinfo->tm_sec = seconds;
295 return timegm(timeinfo);
302 [[nodiscard]] Eigen::Quaterniond
305 double cy = std::cos(yaw * 0.5);
306 double sy = std::sin(yaw * 0.5);
307 double cp = std::cos(pitch * 0.5);
308 double sp = std::sin(pitch * 0.5);
309 double cr = std::cos(roll * 0.5);
310 double sr = std::sin(roll * 0.5);
312 return Eigen::Quaterniond(
313 cr * cp * cy + sr * sp * sy, sr * cp * cy - cr * sp * sy,
314 cr * sp * cy + sr * cp * sy, cr * cp * sy - sr * sp * cy);
331 double pitch,
double yaw)
336 [[nodiscard]] Eigen::Quaterniond
q_enu_ecef(
double lat,
double lon)
338 double sr = sin((
pihalf - lat) / 2.0);
339 double cr = cos((
pihalf - lat) / 2.0);
340 double sy = sin((lon +
pihalf) / 2.0);
341 double cy = cos((lon +
pihalf) / 2.0);
343 return Eigen::Quaterniond(cr * cy, sr * cy, sr * sy, cr * sy);
346 [[nodiscard]] Eigen::Quaterniond
q_ned_ecef(
double lat,
double lon)
348 double sp = sin((-lat -
pihalf) / 2.0);
349 double cp = cos((-lat -
pihalf) / 2.0);
350 double sy = sin(lon / 2.0);
351 double cy = cos(lon / 2.0);
353 return Eigen::Quaterniond(cp * cy, -sp * sy, sp * cy, cp * sy);
356 [[nodiscard]] Eigen::Matrix3d
R_enu_ecef(
double lat,
double lon)
360 double sin_lat = sin(lat);
361 double cos_lat = cos(lat);
362 double sin_lon = sin(lon);
363 double cos_lon = cos(lon);
366 R(0, 1) = -cos_lon * sin_lat;
367 R(0, 2) = cos_lon * cos_lat;
369 R(1, 1) = -sin_lon * sin_lat;
370 R(1, 2) = sin_lon * cos_lat;
378 [[nodiscard]] Eigen::Matrix3d
R_ned_ecef(
double lat,
double lon)
382 double sin_lat = sin(lat);
383 double cos_lat = cos(lat);
384 double sin_lon = sin(lon);
385 double cos_lon = cos(lon);
387 R(0, 0) = -cos_lon * sin_lat;
389 R(0, 2) = -cos_lon * cos_lat;
390 R(1, 0) = -sin_lon * sin_lat;
392 R(1, 2) = -sin_lon * cos_lat;
404 if (period_user == 0)
406 else if (period_user < 1000)
407 return "msec" + std::to_string(period_user);
408 else if (period_user <= 60000)
409 return "sec" + std::to_string(period_user / 1000);
411 return "min" + std::to_string(period_user / 60000);
414 [[nodiscard]] uint16_t
getCrc(
const std::vector<uint8_t>& message)
419 [[nodiscard]] uint16_t
getId(
const std::vector<uint8_t>& message)
423 static uint16_t mask = 8191;
429 [[nodiscard]] uint16_t
getLength(
const std::vector<uint8_t>& message)
434 [[nodiscard]] uint32_t
getTow(
const std::vector<uint8_t>& message)
439 [[nodiscard]] uint16_t
getWnc(
const std::vector<uint8_t>& message)