Fixposition SDK 0.0.0-heads/main-0-g97f6014
Collection of c++ libraries and apps for use with Fixposition products on Linux
Loading...
Searching...
No Matches
parser_fpb.hpp
Go to the documentation of this file.
1/**
2 * \verbatim
3 * ___ ___
4 * \ \ / /
5 * \ \/ / Copyright (c) Fixposition AG (www.fixposition.com) and contributors
6 * / /\ \ License: see the LICENSE file
7 * /__/ \__\
8 * \endverbatim
9 *
10 * @file
11 * @brief Fixposition SDK: to_json() helpers for some fpsdk::common::parser::fpb messages
12 */
13#ifndef __FPSDK_COMMON_TO_JSON_PARSER_FPB_HPP__
14#define __FPSDK_COMMON_TO_JSON_PARSER_FPB_HPP__
15
16/* LIBC/STL */
17#include <cstring>
18
19/* EXTERNAL */
20#include <nlohmann/json.hpp>
21
22/* PACKAGE */
23#include "../parser/fpb.hpp"
24#include "../string.hpp"
25#include "../types.hpp"
26
27#ifndef _DOXYGEN_ // not documenting these
28/* ****************************************************************************************************************** */
30
31inline void to_json(nlohmann::json& j, const FpbMeasurementsMeasType e)
32{
33 switch (e) { // clang-format off
34 case FpbMeasurementsMeasType::UNSPECIFIED: j = "UNSPECIFIED"; return;
35 case FpbMeasurementsMeasType::VELOCITY: j = "VELOCITY"; return;
36 } // clang-format on
38}
39
40inline void to_json(nlohmann::json& j, const FpbMeasurementsMeasLoc e)
41{
42 switch (e) { // clang-format off
43 case FpbMeasurementsMeasLoc::UNSPECIFIED: j = "UNSPECIFIED"; return;
44 case FpbMeasurementsMeasLoc::RC: j = "RC"; return;
45 case FpbMeasurementsMeasLoc::FR: j = "FR"; return;
46 case FpbMeasurementsMeasLoc::FL: j = "FL"; return;
47 case FpbMeasurementsMeasLoc::RR: j = "RR"; return;
48 case FpbMeasurementsMeasLoc::RL: j = "RL"; return;
49 } // clang-format on
51}
52
53inline void to_json(nlohmann::json& j, const FpbMeasurementsTimestampType e)
54{
55 switch (e) { // clang-format off
56 case FpbMeasurementsTimestampType::UNSPECIFIED: j = "UNSPECIFIED"; return;
57 case FpbMeasurementsTimestampType::TIMEOFARRIVAL: j = "TIMEOFARRIVAL"; return;
58 case FpbMeasurementsTimestampType::MONOTONIC: j = "MONOTONIC"; return;
59 case FpbMeasurementsTimestampType::GPS: j = "GPS"; return;
60 } // clang-format on
62}
63
64// ---------------------------------------------------------------------------------------------------------------------
65
66inline void to_json_FP_B_MEASUREMENTS(nlohmann::json& j, const std::vector<uint8_t>& data)
67{
68 if (data.size() < (FP_B_FRAME_SIZE + FP_B_MEASUREMENTS_HEAD_SIZE)) {
69 return;
70 }
72 std::memcpy(&head, &data[FP_B_HEAD_SIZE], sizeof(head));
73 if (data.size() !=
75 return;
76 }
77 j["num_meas"] = head.num_meas;
78 j["meas"] = nlohmann::json::array();
79 for (std::size_t ix = 0; ix < head.num_meas; ix++) {
82 sizeof(meas));
83 auto m = nlohmann::json::object();
84 auto xyz = nlohmann::json::array({ nullptr, nullptr, nullptr });
85 if (meas.meas_x_valid != 0) {
86 xyz[0] = meas.meas_x;
87 }
88 if (meas.meas_y_valid != 0) {
89 xyz[1] = meas.meas_y;
90 }
91 if (meas.meas_z_valid != 0) {
92 xyz[2] = meas.meas_z;
93 }
94 m["xyz"] = xyz;
95 m["type"] = (FpbMeasurementsMeasType)meas.meas_type;
96 m["loc"] = (FpbMeasurementsMeasLoc)meas.meas_loc;
97 m["timestamp"] = (FpbMeasurementsTimestampType)meas.timestamp_type;
98 m["gps_wno"] = meas.gps_wno;
99 m["gps_tow"] = meas.gps_tow;
100 j["meas"].push_back(m);
101 }
102}
103
104// ---------------------------------------------------------------------------------------------------------------------
105
106inline nlohmann::json to_json_FP_B(const ParserMsg& msg)
107{
108 auto j = nlohmann::json::object();
109 switch (FpbMsgId(msg.Data())) { // clang-format off
110 case FP_B_MEASUREMENTS_MSGID: to_json_FP_B_MEASUREMENTS(j, msg.data_); break;
111 } // clang-format on
112 return j;
113}
114
115} // namespace fpsdk::common::parser::fpb
116/* ****************************************************************************************************************** */
117#endif // !_DOXYGEN_
118#endif // __FPSDK_COMMON_TO_JSON_PARSER_FPB_HPP__
Fixposition SDK: Parser FP_B routines and types.
Parser FP_B routines and types.
Definition fpb.hpp:105
static constexpr std::size_t FP_B_MEASUREMENTS_HEAD_SIZE
FP_B-MEASUREMENTS payload head size.
Definition fpb.hpp:337
static constexpr std::size_t FP_B_FRAME_SIZE
Size (in bytes) of FP_B frame.
Definition fpb.hpp:108
static constexpr std::size_t FP_B_HEAD_SIZE
Size of FP_B frame header.
Definition fpb.hpp:109
FpbMeasurementsTimestampType
FP_B-MEASUREMENTS timestamp type.
Definition fpb.hpp:360
@ MONOTONIC
Use monotonic time [any] (stored in the gps_tow field)
Definition fpb.hpp:363
@ TIMEOFARRIVAL
Use time of arrival of the measurement (ignore gps_wno and gps_tow)
Definition fpb.hpp:362
@ GPS
Use GPS time (stored in gps_wno [-] and gps_tow [ms] fields)
Definition fpb.hpp:364
FpbMeasurementsMeasType
FP_B-MEASUREMENTS measurement type.
Definition fpb.hpp:341
@ VELOCITY
Velocity measuement (wheel speed)
Definition fpb.hpp:343
constexpr uint16_t FpbMsgId(const uint8_t *msg)
Get message ID.
Definition fpb.hpp:122
FpbMeasurementsMeasLoc
FP_B-MEASUREMENTS measurement location.
Definition fpb.hpp:349
@ FR
Measurement of a sensor at the front-right (FR)
Definition fpb.hpp:352
@ RC
Measurement of a sensor at the rear-center (RC)
Definition fpb.hpp:351
@ RL
Measurement of a sensor at the rear-left (RL)
Definition fpb.hpp:355
@ FL
Measurement of a sensor at the front-left (FL)
Definition fpb.hpp:353
@ RR
Measurement of a sensor at the rear-right (RR)
Definition fpb.hpp:354
static constexpr uint16_t FP_B_MEASUREMENTS_MSGID
FP_B-MEASUREMENTS message ID.
Definition fpb.hpp:240
static constexpr std::size_t FP_B_MEASUREMENTS_MEAS_SIZE
Size of FpbMeasurementsMeas.
Definition fpb.hpp:390
std::string Sprintf(const char *const fmt,...) PRINTF_ATTR(1)
Format string.
constexpr std::underlying_type< T >::type EnumToVal(T enum_val)
Convert enum class constant to the underlying integral type value.
Definition types.hpp:47
Fixposition SDK: String utilities.
FP_B-MEASUREMENTS payload: head.
Definition fpb.hpp:328
FP_B-MEASUREMENTS payload: measurement.
Definition fpb.hpp:369
Fixposition SDK: Common types and type helpers.