Fixposition SDK 0.0.0-heads/main-0-g155c724
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
24#ifndef _DOXYGEN_ // not documenting these
25/* ****************************************************************************************************************** */
26namespace fpsdk::common::parser {
27
28inline void to_json(nlohmann::json& j, const ParserMsg& m)
29{
30 j = nlohmann::json::object({
31 { "_proto", ProtocolStr(m.proto_) },
32 { "_name", m.name_ },
33 { "_seq", m.seq_ },
34 });
35
36 if (!m.info_.empty()) {
37 j["_info"] = m.info_;
38 } else {
39 j["_info"] = nullptr;
40 }
41
42 if (std::all_of(m.data_.data(), m.data_.data() + m.data_.size(),
43 [](const uint8_t c) { return std::isprint(c) || std::isspace(c); })) {
44 j["_data"] = string::BufToStr(m.data_);
45 } else {
46 j["_data_b64"] = string::Base64Enc(m.data_);
47 }
48}
49
50// ---------------------------------------------------------------------------------------------------------------------
51
52inline void to_json(nlohmann::json& j, const ParserStats s)
53{
54 j = nlohmann::json::object({
55 { "n_msgs", s.n_msgs_ },
56 { "s_msgs", s.s_msgs_ },
57 { "n_fpa", s.n_fpa_ },
58 { "s_fpa", s.s_fpa_ },
59 { "n_fpb", s.n_fpb_ },
60 { "s_fpb", s.s_fpb_ },
61 { "n_nmea", s.n_nmea_ },
62 { "s_nmea", s.s_nmea_ },
63 { "n_ubx", s.n_ubx_ },
64 { "s_ubx", s.s_ubx_ },
65 { "n_rtcm3", s.n_rtcm3_ },
66 { "s_rtcm3", s.s_rtcm3_ },
67 { "n_unib", s.n_unib_ },
68 { "s_unib", s.s_unib_ },
69 { "n_novb", s.n_novb_ },
70 { "s_novb", s.s_novb_ },
71 { "n_sbf", s.n_sbf_ },
72 { "s_sbf", s.s_sbf_ },
73 { "n_qgc", s.n_qgc_ },
74 { "s_qgc", s.s_qgc_ },
75 { "n_spartn", s.n_spartn_ },
76 { "s_spartn", s.s_spartn_ },
77 { "n_other", s.n_other_ },
78 { "s_other", s.s_other_ },
79 });
80}
81
82} // namespace fpsdk::common::parser
83/* ****************************************************************************************************************** */
84#endif // !_DOXYGEN_
85#endif // __FPSDK_COMMON_TO_JSON_PARSER_HPP__
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.
Message frame output by the Parser.
Definition types.hpp:108