Fixposition SDK 0.0.0-heads/main-0-g6a396b9
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 "../cam.hpp"
23#include "../fpl.hpp"
24#include "../string.hpp"
25#include "time.hpp"
26
27#ifndef _DOXYGEN_ // not documenting these
28/* ****************************************************************************************************************** */
29namespace fpsdk::common::fpl {
30
31inline void to_json(nlohmann::json& j, const LogStatus& s)
32{
33 j = nlohmann::json::object({
34 { "_type", FplTypeStr(FplType::LOGSTATUS) },
35 { "_yaml", s.yaml_ },
36 { "state", s.state_ },
37 { "queue_size_", s.queue_size_ },
38 { "queue_peak", s.queue_peak_ },
39 { "queue_skip", s.queue_skip_ },
40 { "queue_bsize", s.queue_bsize_ },
41 { "queue_bpeak", s.queue_bpeak_ },
42 { "log_count", s.log_count_ },
43 { "log_errors", s.log_errors_ },
44 { "log_size", s.log_size_ },
45 { "log_duration", s.log_duration_ },
46 { "log_time_posix", s.log_time_posix_ },
47 { "log_time_iso", s.log_time_iso_ },
48 { "pos_source", s.pos_source_ },
49 { "pos_fix_type", s.pos_fix_type_ },
50 { "pos_lat", s.pos_lat_ },
51 { "pos_lon", s.pos_lon_ },
52 { "pos_height", s.pos_height_ },
53 });
54}
55
56// ---------------------------------------------------------------------------------------------------------------------
57
58inline void to_json(nlohmann::json& j, const LogMeta& m)
59{
60 j = nlohmann::json::object({
61 { "_type", FplTypeStr(FplType::LOGMETA) },
62 { "_yaml", m.yaml_ },
63 { "hw_uid", m.hw_uid_ },
64 { "product_model", m.product_model_ },
65 { "sw_version", m.sw_version_ },
66 { "log_start_time_posix", m.log_start_time_posix_ },
67 { "log_start_time_iso", m.log_start_time_iso_ },
68 { "log_profile", m.log_profile_ },
69 { "log_target", m.log_target_ },
70 { "log_filename", m.log_filename_ },
71 });
72}
73
74// ---------------------------------------------------------------------------------------------------------------------
75
76inline void to_json(nlohmann::json& j, const StreamMsg& m)
77{
78 j = nlohmann::json::object({
79 { "_type", FplTypeStr(FplType::STREAMMSG) },
80 { "_stamp", m.rec_time_ },
81 { "_stream", m.stream_name_ },
82 });
83
84 if (std::all_of(m.msg_data_.data(), m.msg_data_.data() + m.msg_data_.size(),
85 [](const uint8_t c) { return std::isprint(c) || std::isspace(c); })) {
86 j["_data"] = string::BufToStr(m.msg_data_);
87 } else {
88 j["_data_b64"] = string::Base64Enc(m.msg_data_);
89 }
90}
91
92// ---------------------------------------------------------------------------------------------------------------------
93
94inline void to_json(nlohmann::json& j, const FileDump& m)
95{
96 j = nlohmann::json::object({
97 { "_type", FplTypeStr(FplType::FILEDUMP) },
98 { "_mtime", m.mtime_.GetRosTime() },
99 { "_filename", m.filename_ },
100 });
101
102 if (std::all_of(m.data_.data(), m.data_.data() + m.data_.size(),
103 [](const uint8_t c) { return std::isprint(c) || std::isspace(c); })) {
104 j["_data"] = string::BufToStr(m.data_);
105 } else {
106 j["_data_b64"] = string::Base64Enc(m.data_);
107 }
108}
109
110// ---------------------------------------------------------------------------------------------------------------------
111
112inline void to_json(nlohmann::json& j, const CamData& m)
113{
114 j = nlohmann::json::object({
115 { "_type", FplTypeStr(FplType::CAMDATA) },
116 { "cam_id", cam::CamIdToStr(m.cam_id_) },
117 { "type", cam::CamDataTypeToStr(m.type_) },
118 { "fmt", cam::CamDataFmtToStr(m.fmt_) },
119 { "frm", cam::CamDataFrmToStr(m.frm_) },
120 { "seq", m.meta_.seq_ },
121 { "ts", m.meta_.ts_ },
122 { "dt", m.meta_.dt_ },
123 { "width", m.meta_.width_ },
124 { "height", m.meta_.height_ },
125 { "data_b64", string::Base64Enc(m.data_) },
126 });
127}
128
129} // namespace fpsdk::common::fpl
130/* ****************************************************************************************************************** */
131#endif // !_DOXYGEN_
132#endif // __FPSDK_COMMON_TO_JSON_FPL_HPP__
Fixposition SDK: Camera types and utilities.
Fixposition SDK: .fpl utilities.
const char * CamIdToStr(const CamId camid)
Stringify camera ID enum.
const char * CamDataFmtToStr(const CamDataFmt fmt)
Stringify camera data format enum.
const char * CamDataTypeToStr(const CamDataType type)
Stringify camera data type enum.
const char * CamDataFrmToStr(const CamDataFrm frm)
Stringify camera data frame type enum.
.fpl utilities
Definition fpl.hpp:39
@ LOGSTATUS
Logging status.
Definition fpl.hpp:52
@ LOGMETA
Logfile meta data.
Definition fpl.hpp:50
@ FILEDUMP
Dump of an entire (small) file.
Definition fpl.hpp:53
@ STREAMMSG
Stream message raw data with timestamp.
Definition fpl.hpp:51
@ CAMDATA
Camera data (image, video, ...)
Definition fpl.hpp:54
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 camera data (image, video, ...)
Definition fpl.hpp:447
Helper for extracting data of a stream message (NMEA, RTCM3, etc.)
Definition fpl.hpp:405
Helper for extracting meta data.
Definition fpl.hpp:263
Helper for extracting recording status data.
Definition fpl.hpp:291
Helper for extracting data of a stream message (NMEA, RTCM3, etc.)
Definition fpl.hpp:383
Fixposition SDK: to_json() helpers for some fpsdk::common::time types.