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
nmea.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::nmea messages
12 */
13#ifndef __FPSDK_COMMON_TO_JSON_NMEA_HPP__
14#define __FPSDK_COMMON_TO_JSON_NMEA_HPP__
15
16/* LIBC/STL */
17
18/* EXTERNAL */
19#include <nlohmann/json.hpp>
20
21/* PACKAGE */
22#include "../parser/nmea.hpp"
23
24#ifndef _DOXYGEN_ // not documenting these
25/* ****************************************************************************************************************** */
27
28inline void to_json(nlohmann::json& j, const NmeaTalkerId e)
29{
30 j = NmeaTalkerIdStr(e);
31}
32
33inline void to_json(nlohmann::json& j, const NmeaFormatter e)
34{
35 j = NmeaFormatterStr(e);
36}
37
38inline void to_json(nlohmann::json& j, const NmeaQualityGga e)
39{
40 j = NmeaQualityGgaStr(e);
41}
42
43inline void to_json(nlohmann::json& j, const NmeaStatusGllRmc e)
44{
46}
47
48inline void to_json(nlohmann::json& j, const NmeaModeGllVtg e)
49{
50 j = NmeaModeGllVtgStr(e);
51}
52
53inline void to_json(nlohmann::json& j, const NmeaModeRmcGns e)
54{
55 j = NmeaModeRmcGnsStr(e);
56}
57
58inline void to_json(nlohmann::json& j, const NmeaNavStatusRmc e)
59{
61}
62
63inline void to_json(nlohmann::json& j, const NmeaOpModeGsa e)
64{
65 j = NmeaOpModeGsaStr(e);
66}
67
68inline void to_json(nlohmann::json& j, const NmeaNavModeGsa e)
69{
70 j = NmeaNavModeGsaStr(e);
71}
72
73inline void to_json(nlohmann::json& j, const NmeaSystemId e)
74{
75 j = NmeaSystemIdStr(e);
76}
77
78inline void to_json(nlohmann::json& j, const NmeaSignalId e)
79{
80 j = NmeaSignalIdStr(e);
81}
82
83// ---------------------------------------------------------------------------------------------------------------------
84
85inline void to_json(nlohmann::json& j, const NmeaTime& m)
86{
87 if (m.valid) {
88 j = nlohmann::json::object({
89 { "hours", m.hours },
90 { "mins", m.mins },
91 { "secs", m.secs },
92 });
93 } else {
94 j = nullptr;
95 }
96}
97
98inline void to_json(nlohmann::json& j, const NmeaDate& m)
99{
100 if (m.valid) {
101 j = nlohmann::json::object({
102 { "years", m.years },
103 { "months", m.months },
104 { "days", m.days },
105 });
106 } else {
107 j = nullptr;
108 }
109}
110
111inline void to_json(nlohmann::json& j, const NmeaLlh& m)
112{
113 if (m.latlon_valid) {
114 j = nlohmann::json::object({
115 { "lat", m.lat },
116 { "lon", m.lon },
117 });
118 if (m.height_valid) {
119 j["height"] = m.height;
120 }
121 } else {
122 j = nullptr;
123 }
124}
125
126inline void to_json(nlohmann::json& j, const NmeaSat& m)
127{
128 if (m.valid) {
129 j = nlohmann::json::object({
130 { "system", m.system },
131 { "svid", m.svid },
132 });
133 } else {
134 j = nullptr;
135 }
136}
137
138inline void to_json(nlohmann::json& j, const NmeaAzEl& m)
139{
140 if (m.valid) {
141 j = nlohmann::json::object({
142 { "system", m.system },
143 { "svid", m.svid },
144 { "el", m.el },
145 { "az", m.az },
146 });
147 } else {
148 j = nullptr;
149 }
150}
151
152inline void to_json(nlohmann::json& j, const NmeaCno& m)
153{
154 if (m.valid) {
155 j = nlohmann::json::object({
156 { "system", m.system },
157 { "svid", m.svid },
158 { "signal", m.signal },
159 { "cno", m.cno },
160 });
161 } else {
162 j = nullptr;
163 }
164}
165
166inline void to_json(nlohmann::json& j, const NmeaInt& m)
167{
168 if (m.valid) {
169 j = m.value;
170 } else {
171 j = nullptr;
172 }
173}
174
175inline void to_json(nlohmann::json& j, const NmeaFloat& m)
176{
177 if (m.valid) {
178 j = m.value;
179 } else {
180 j = nullptr;
181 }
182}
183
184// ---------------------------------------------------------------------------------------------------------------------
185
186inline void to_json(nlohmann::json& j, const NmeaGgaPayload& m)
187{
188 j = nlohmann::json::object({
189 { "time", m.time },
190 { "llh", m.llh },
191 { "height_msl", m.height_msl },
192 { "quality", m.quality },
193 { "num_sv", m.num_sv },
194 { "hdop", m.hdop },
195 { "diff_age", m.diff_age },
196 { "diff_sta", m.diff_sta },
197 });
198}
199
200// ---------------------------------------------------------------------------------------------------------------------
201
202inline void to_json(nlohmann::json& j, const NmeaGllPayload& m)
203{
204 j = nlohmann::json::object({
205 { "ll", m.ll },
206 { "time", m.time },
207 { "status", m.status },
208 { "mode", m.mode },
209 });
210}
211
212// ---------------------------------------------------------------------------------------------------------------------
213
214inline void to_json(nlohmann::json& j, const NmeaRmcPayload& m)
215{
216 j = nlohmann::json::object({
217 { "time", m.time },
218 { "ll", m.ll },
219 { "speed", m.speed },
220 { "course", m.course },
221 { "date", m.date },
222 { "mode", m.mode },
223 { "navstatus", m.navstatus },
224 });
225}
226
227// ---------------------------------------------------------------------------------------------------------------------
228
229inline void to_json(nlohmann::json& j, const NmeaVtgPayload& m)
230{
231 j = nlohmann::json::object({
232 { "cogt", m.cogt },
233 { "cogm", m.cogm },
234 { "sogn", m.sogn },
235 { "sogk", m.sogk },
236 { "mode", m.mode },
237 });
238}
239
240// ---------------------------------------------------------------------------------------------------------------------
241
242inline void to_json(nlohmann::json& j, const NmeaGstPayload& m)
243{
244 j = nlohmann::json::object({
245 { "time", m.time },
246 { "rms_range", m.rms_range },
247 { "std_major", m.std_major },
248 { "std_minor", m.std_minor },
249 { "angle_major", m.angle_major },
250 { "std_lat", m.std_lat },
251 { "std_lon", m.std_lon },
252 { "std_alt", m.std_alt },
253 });
254}
255
256// ---------------------------------------------------------------------------------------------------------------------
257
258inline void to_json(nlohmann::json& j, const NmeaHdtPayload& m)
259{
260 j = nlohmann::json::object({
261 { "heading", m.heading },
262 });
263}
264
265// ---------------------------------------------------------------------------------------------------------------------
266
267inline void to_json(nlohmann::json& j, const NmeaZdaPayload& m)
268{
269 j = nlohmann::json::object({
270 { "time", m.time },
271 { "date", m.date },
272 { "local_hr", m.local_hr },
273 { "local_min", m.local_min },
274 });
275}
276
277// ---------------------------------------------------------------------------------------------------------------------
278
279inline void to_json(nlohmann::json& j, const NmeaGsaPayload& m)
280{
281 j = nlohmann::json::object({
282 { "opmode", m.opmode },
283 { "navmode", m.navmode },
284 { "sats", m.sats },
285 { "num_sats", m.num_sats },
286 { "pdop", m.pdop },
287 { "hdop", m.hdop },
288 { "vdop", m.vdop },
289 { "system", m.system },
290 });
291}
292
293// ---------------------------------------------------------------------------------------------------------------------
294
295inline void to_json(nlohmann::json& j, const NmeaGsvPayload& m)
296{
297 j = nlohmann::json::object({
298 { "num_msgs", m.num_msgs },
299 { "msg_num", m.msg_num },
300 { "tot_num_sat", m.tot_num_sat },
301 { "azels", m.azels },
302 { "num_azels", m.num_azels },
303 { "num_cnos", m.num_cnos },
304 { "system", m.system },
305 { "signal", m.signal },
306 });
307}
308
309// ---------------------------------------------------------------------------------------------------------------------
310
311inline void to_json(nlohmann::json& j, const NmeaPayloadPtr& nmea)
312{
313 j = nlohmann::json::object();
314 if (!nmea) {
315 return;
316 }
317 j["_valid"] = nmea->valid_;
318 j["_talker"] = nmea->talker_;
319 j["_formatter"] = nmea->formatter_;
320 if (nmea) {
321 switch (nmea->formatter_) { // clang-format off
322 case NmeaFormatter::UNSPECIFIED: break;
323 case NmeaFormatter::GGA: j.update(dynamic_cast<const NmeaGgaPayload&>(*nmea)); break;
324 case NmeaFormatter::GLL: j.update(dynamic_cast<const NmeaGllPayload&>(*nmea)); break;
325 case NmeaFormatter::RMC: j.update(dynamic_cast<const NmeaRmcPayload&>(*nmea)); break;
326 case NmeaFormatter::VTG: j.update(dynamic_cast<const NmeaVtgPayload&>(*nmea)); break;
327 case NmeaFormatter::GST: j.update(dynamic_cast<const NmeaGstPayload&>(*nmea)); break;
328 case NmeaFormatter::HDT: j.update(dynamic_cast<const NmeaHdtPayload&>(*nmea)); break;
329 case NmeaFormatter::ZDA: j.update(dynamic_cast<const NmeaZdaPayload&>(*nmea)); break;
330 case NmeaFormatter::GSA: j.update(dynamic_cast<const NmeaGsaPayload&>(*nmea)); break;
331 case NmeaFormatter::GSV: j.update(dynamic_cast<const NmeaGsvPayload&>(*nmea)); break;
332 } // clang-format on
333 }
334}
335
336} // namespace fpsdk::common::parser::nmea
337/* ****************************************************************************************************************** */
338#endif // !_DOXYGEN_
339#endif // __FPSDK_COMMON_TO_JSON_NMEA_HPP__
Parser NMEA routines and types.
Definition nmea.hpp:98
NmeaSystemId
NMEA system IDs.
Definition nmea.hpp:431
NmeaModeRmcGns
NMEA-Gx-RMC and NMEA-Gx-GNS pos mode.
Definition nmea.hpp:339
const char * NmeaNavStatusRmcStr(const NmeaNavStatusRmc navstatus)
Stringify NMEA-Gx-RMC navigational status.
const char * NmeaNavModeGsaStr(const NmeaNavModeGsa navmode)
Stringify NMEA-Gx-GNS nav mode.
NmeaOpModeGsa
NMEA-Gx-GNS operation mode.
Definition nmea.hpp:390
NmeaNavStatusRmc
NMEA-Gx-RMC navigational status.
Definition nmea.hpp:367
const char * NmeaSystemIdStr(const NmeaSystemId system)
Stringify NMEA system ID.
const char * NmeaTalkerIdStr(const NmeaTalkerId talker)
Stringify NMEA talker ID.
const char * NmeaModeRmcGnsStr(const NmeaModeRmcGns mode)
Stringify NMEA-Gx-RMC and NMEA-Gx-GNS pos mode.
const char * NmeaStatusGllRmcStr(const NmeaStatusGllRmc status)
Stringify NMEA-Gx-GLL and NMEA-Gx-RMC status.
NmeaModeGllVtg
NMEA-Gx-GLL and NMEA-Gx-VTG pos mode.
Definition nmea.hpp:314
NmeaFormatter
NMEA formatter.
Definition nmea.hpp:238
@ ZDA
Formatter ZDA (NmeaZdaPayload)
Definition nmea.hpp:246
@ HDT
Formatter HDT (NmeaHdtPayload)
Definition nmea.hpp:245
@ RMC
Formatter RMC (NmeaRmcPayload)
Definition nmea.hpp:242
@ GGA
Formatter GGA (NmeaGgaPayload)
Definition nmea.hpp:240
@ GST
Formatter GST (NmeaGstPayload)
Definition nmea.hpp:244
@ GSV
Formatter GSV (NmeaGsvPayload)
Definition nmea.hpp:248
@ GSA
Formatter GSA (NmeaGsaPayload)
Definition nmea.hpp:247
@ GLL
Formatter GLL (NmeaGllPayload)
Definition nmea.hpp:241
@ VTG
Formatter VTG (NmeaVtgPayload)
Definition nmea.hpp:243
NmeaNavModeGsa
NMEA-Gx-GNS nav mode.
Definition nmea.hpp:409
const char * NmeaModeGllVtgStr(const NmeaModeGllVtg mode)
Stringify NMEA-Gx-GLL and NMEA-Gx-VTG pos mode.
NmeaTalkerId
NMEA talker IDs.
Definition nmea.hpp:213
const char * NmeaQualityGgaStr(const NmeaQualityGga qual)
Stringify NMEA-Gx-GGA quality indicator.
const char * NmeaOpModeGsaStr(const NmeaOpModeGsa opmode)
Stringify NMEA-Gx-GNS operation mode.
const char * NmeaSignalIdStr(const NmeaSignalId signal)
Stringify NMEA signal IDs.
std::unique_ptr< NmeaPayload > NmeaPayloadPtr
Pointer to NMEA payload.
Definition nmea.hpp:808
NmeaStatusGllRmc
NMEA-Gx-GLL and NMEA-Gx-RMC status.
Definition nmea.hpp:292
NmeaSignalId
NMEA signal IDs.
Definition nmea.hpp:456
const char * NmeaFormatterStr(const NmeaFormatter formatter)
Stringify NMEA formatter.
NmeaQualityGga
NMEA-Gx-GGA quality indicator.
Definition nmea.hpp:264
Fixposition SDK: Parser NMEA routines and types.
NMEA date (year, month, day)
Definition nmea.hpp:518
NMEA-Gx-GGA message payload.
Definition nmea.hpp:655
NMEA-Gx-GLL message payload.
Definition nmea.hpp:674
NMEA-Gx-GSA message payload (NMEA 4.11 only!)
Definition nmea.hpp:770
NMEA-Gx-GST message payload.
Definition nmea.hpp:724
NMEA-Gx-GSV message payload (NMEA 4.11 only!)
Definition nmea.hpp:789
NMEA-Gx-HDT message payload.
Definition nmea.hpp:743
NMEA geodetic position.
Definition nmea.hpp:532
NMEA-Gx-RMC message payload.
Definition nmea.hpp:689
NMEA satellite (used, e.g. in GSA)
Definition nmea.hpp:544
NMEA time (hour, minutes, seconds)
Definition nmea.hpp:504
NMEA-Gx-VTG message payload.
Definition nmea.hpp:708
NMEA-Gx-ZDA message payload.
Definition nmea.hpp:755