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
fpl.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::fpl messages
12 */
13#ifndef __FPSDK_COMMON_TO_JSON_FPL_HPP__
14#define __FPSDK_COMMON_TO_JSON_FPL_HPP__
15
16/* LIBC/STL */
17
18/* EXTERNAL */
19#include <nlohmann/json.hpp>
20
21/* PACKAGE */
22#include "../fpl.hpp"
23#include "../string.hpp"
24#include "time.hpp"
25
26#ifndef _DOXYGEN_ // not documenting these
27/* ****************************************************************************************************************** */
28namespace fpsdk::common::fpl {
29
30inline void to_json(nlohmann::json& j, const LogStatus& s)
31{
32 j = nlohmann::json::object({
33 { "_type", FplTypeStr(FplType::LOGSTATUS) },
34 { "_yaml", s.yaml_ },
35 { "state", s.state_ },
36 { "queue_size_", s.queue_size_ },
37 { "queue_peak", s.queue_peak_ },
38 { "queue_skip", s.queue_skip_ },
39 { "queue_bsize", s.queue_bsize_ },
40 { "queue_bpeak", s.queue_bpeak_ },
41 { "log_count", s.log_count_ },
42 { "log_errors", s.log_errors_ },
43 { "log_size", s.log_size_ },
44 { "log_duration", s.log_duration_ },
45 { "log_time_posix", s.log_time_posix_ },
46 { "log_time_iso", s.log_time_iso_ },
47 { "pos_source", s.pos_source_ },
48 { "pos_fix_type", s.pos_fix_type_ },
49 { "pos_lat", s.pos_lat_ },
50 { "pos_lon", s.pos_lon_ },
51 { "pos_height", s.pos_height_ },
52 });
53}
54
55// ---------------------------------------------------------------------------------------------------------------------
56
57inline void to_json(nlohmann::json& j, const LogMeta& m)
58{
59 j = nlohmann::json::object({
60 { "_type", FplTypeStr(FplType::LOGMETA) },
61 { "_yaml", m.yaml_ },
62 { "hw_uid", m.hw_uid_ },
63 { "product_model", m.product_model_ },
64 { "sw_version", m.sw_version_ },
65 { "log_start_time_posix", m.log_start_time_posix_ },
66 { "log_start_time_iso", m.log_start_time_iso_ },
67 { "log_profile", m.log_profile_ },
68 { "log_target", m.log_target_ },
69 { "log_filename", m.log_filename_ },
70 });
71}
72
73// ---------------------------------------------------------------------------------------------------------------------
74
75inline void to_json(nlohmann::json& j, const StreamMsg& m)
76{
77 j = nlohmann::json::object({
78 { "_type", FplTypeStr(FplType::STREAMMSG) },
79 { "_stamp", m.rec_time_ },
80 { "_stream", m.stream_name_ },
81 });
82
83 if (std::all_of(m.msg_data_.data(), m.msg_data_.data() + m.msg_data_.size(),
84 [](const uint8_t c) { return std::isprint(c) || std::isspace(c); })) {
85 j["_raw"] = string::BufToStr(m.msg_data_);
86 } else {
87 j["_raw_b64"] = string::Base64Enc(m.msg_data_);
88 }
89}
90
91// ---------------------------------------------------------------------------------------------------------------------
92
93inline void to_json(nlohmann::json& j, const FileDump& m)
94{
95 j = nlohmann::json::object({
96 { "_type", FplTypeStr(FplType::FILEDUMP) },
97 { "_mtime", m.mtime_.GetRosTime() },
98 { "_filename", m.filename_ },
99 });
100
101 if (std::all_of(m.data_.data(), m.data_.data() + m.data_.size(),
102 [](const uint8_t c) { return std::isprint(c) || std::isspace(c); })) {
103 j["_data"] = string::BufToStr(m.data_);
104 } else {
105 j["_data_b64"] = string::Base64Enc(m.data_);
106 }
107}
108
109} // namespace fpsdk::common::fpl
110/* ****************************************************************************************************************** */
111#endif // !_DOXYGEN_
112#endif // __FPSDK_COMMON_TO_JSON_FPL_HPP__
Fixposition SDK: .fpl utilities.
.fpl utilities
Definition fpl.hpp:38
@ LOGSTATUS
Logging status.
Definition fpl.hpp:51
@ LOGMETA
Logfile meta data.
Definition fpl.hpp:49
@ FILEDUMP
Dump of an entire (small) file.
Definition fpl.hpp:52
@ STREAMMSG
Stream message raw data with timestamp.
Definition fpl.hpp:50
const char * FplTypeStr(const FplType type)
Stringify type.
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: String utilities.
Helper for extracting data of a stream message (NMEA, RTCM3, etc.)
Definition fpl.hpp:403
Helper for extracting meta data.
Definition fpl.hpp:261
Helper for extracting recording status data.
Definition fpl.hpp:289
Helper for extracting data of a stream message (NMEA, RTCM3, etc.)
Definition fpl.hpp:381
Fixposition SDK: to_json() helpers for some fpsdk::common::time types.