Fixposition SDK 0.0.0-heads/main-0-g75e6614
Collection of c++ libraries and apps for use with Fixposition products on Linux
Loading...
Searching...
No Matches
parser.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
12 */
13#ifndef __FPSDK_COMMON_TO_JSON_PARSER_HPP__
14#define __FPSDK_COMMON_TO_JSON_PARSER_HPP__
15
16/* LIBC/STL */
17
18/* EXTERNAL */
19#include <nlohmann/json.hpp>
20
21/* PACKAGE */
22#include "../parser/types.hpp"
23#include "../string.hpp"
24#include "parser_fpa.hpp"
25#include "parser_fpb.hpp"
26#include "parser_nmea.hpp"
27#include "parser_ubx.hpp"
28
29#ifndef _DOXYGEN_ // not documenting these
30/* ****************************************************************************************************************** */
31namespace fpsdk::common::parser {
32
33inline void to_json(nlohmann::json& j, const ParserMsg& m)
34{
35 j = nlohmann::json::object({
36 { "_proto", ProtocolStr(m.proto_) },
37 { "_name", m.name_ },
38 { "_seq", m.seq_ },
39 { "_size", m.data_.size() },
40 });
41
42 if (!m.info_.empty()) {
43 j["_info"] = m.info_;
44 } else {
45 j["_info"] = nullptr;
46 }
47
48 if (std::all_of(m.data_.data(), m.data_.data() + m.data_.size(),
49 [](const uint8_t c) { return std::isprint(c) || std::isspace(c); })) {
50 j["_data"] = string::BufToStr(m.data_);
51 } else {
52 j["_data_b64"] = string::Base64Enc(m.data_);
53 }
54}
55
56inline nlohmann::json ParserMsgToJson(const ParserMsg& m)
57{
58 nlohmann::json j = m;
59 switch (m.proto_) { // clang-format off
60 case Protocol::FP_A: j.update(fpa::FpaDecodeMessage(m.data_)); break;
61 case Protocol::FP_B: j.update(fpb::to_json_FP_B(m)); break;
62 case Protocol::NMEA: j.update(nmea::NmeaDecodeMessage(m.data_)); break;
63 case Protocol::UBX: j.update(ubx::to_json_UBX(m)); break;
64 case Protocol::RTCM3:
65 case Protocol::UNI_B:
66 case Protocol::NOV_B:
67 case Protocol::SBF:
68 case Protocol::QGC:
70 case Protocol::OTHER: break;
71 } // clang-format on
72 return j;
73}
74
75// ---------------------------------------------------------------------------------------------------------------------
76
77inline void to_json(nlohmann::json& j, const ParserStats s)
78{
79 j = nlohmann::json::object({
80 { "n_msgs", s.n_msgs_ },
81 { "s_msgs", s.s_msgs_ },
82 { "n_fpa", s.n_fpa_ },
83 { "s_fpa", s.s_fpa_ },
84 { "n_fpb", s.n_fpb_ },
85 { "s_fpb", s.s_fpb_ },
86 { "n_nmea", s.n_nmea_ },
87 { "s_nmea", s.s_nmea_ },
88 { "n_ubx", s.n_ubx_ },
89 { "s_ubx", s.s_ubx_ },
90 { "n_rtcm3", s.n_rtcm3_ },
91 { "s_rtcm3", s.s_rtcm3_ },
92 { "n_unib", s.n_unib_ },
93 { "s_unib", s.s_unib_ },
94 { "n_novb", s.n_novb_ },
95 { "s_novb", s.s_novb_ },
96 { "n_sbf", s.n_sbf_ },
97 { "s_sbf", s.s_sbf_ },
98 { "n_qgc", s.n_qgc_ },
99 { "s_qgc", s.s_qgc_ },
100 { "n_spartn", s.n_spartn_ },
101 { "s_spartn", s.s_spartn_ },
102 { "n_other", s.n_other_ },
103 { "s_other", s.s_other_ },
104 });
105}
106
107} // namespace fpsdk::common::parser
108/* ****************************************************************************************************************** */
109#endif // !_DOXYGEN_
110#endif // __FPSDK_COMMON_TO_JSON_PARSER_HPP__
FpaPayloadPtr FpaDecodeMessage(const uint8_t *msg, const std::size_t msg_size)
Decode FP_A message.
NmeaPayloadPtr NmeaDecodeMessage(const uint8_t *msg, const std::size_t msg_size)
Decode NMEA message.
@ OTHER
Other "message" (unknown or corrupt message, spurious data, line noise, ...) (PROTOCOL_NAME_OTHER).
Definition types.hpp:55
@ SPARTN
SPARTN (PROTOCOL_NAME_SPARTN).
Definition types.hpp:54
@ FP_B
FP_B (Fixposition proprietary binary) (PROTOCOL_NAME_FP_B).
Definition types.hpp:46
@ NMEA
NMEA (PROTOCOL_NAME_NMEA).
Definition types.hpp:47
@ QGC
QGC (Quectel proprietary binary) (PROTOCOL_NAME_QGC).
Definition types.hpp:53
@ SBF
SBF (Septentrio binary format) (PROTOCOL_NAME_SBF).
Definition types.hpp:52
@ UNI_B
UNI_B (Unicore proprietary binary) (PROTOCOL_NAME_UNI_B).
Definition types.hpp:50
@ NOV_B
NOV_B (NovAtel proprietary binary, long or short header) (PROTOCOL_NAME_NOV_B).
Definition types.hpp:51
@ UBX
UBX (u-blox proprietary binary) (PROTOCOL_NAME_UBX).
Definition types.hpp:48
@ FP_A
FP_A (Fixposition proprietary ASCII) (PROTOCOL_NAME_FP_A).
Definition types.hpp:45
@ RTCM3
RTCM3 (PROTOCOL_NAME_RTCM3).
Definition types.hpp:49
const char * ProtocolStr(const Protocol proto)
Stringify Protocol.
std::string BufToStr(const std::vector< uint8_t > &buf)
Convert buffer to string.
std::string Base64Enc(const std::vector< uint8_t > &buf)
Encode to base64.
Fixposition SDK: Parser.
Fixposition SDK: to_json() helpers for some fpsdk::common::parser::fpa messages.
Fixposition SDK: to_json() helpers for some fpsdk::common::parser::fpb messages.
Fixposition SDK: to_json() helpers for some fpsdk::common::parser::nmea messages.
Fixposition SDK: to_json() helpers for some fpsdk::common::parser::ubx messages.
Fixposition SDK: String utilities.
Message frame output by the Parser.
Definition types.hpp:108