Fixposition SDK 0.0.0-heads/main-0-gf826859
Collection of c++ libraries and apps for use with Fixposition products on Linux
Loading...
Searching...
No Matches
parser_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 NmeaModeGll e)
49{
50 j = NmeaModeGllStr(e);
51}
52
53inline void to_json(nlohmann::json& j, const NmeaModeVtg e)
54{
55 j = NmeaModeVtgStr(e);
56}
57
58inline void to_json(nlohmann::json& j, const NmeaModeRmcGns e)
59{
60 j = NmeaModeRmcGnsStr(e);
61}
62
63inline void to_json(nlohmann::json& j, const NmeaNavStatusRmc e)
64{
66}
67
68inline void to_json(nlohmann::json& j, const NmeaOpModeGsa e)
69{
70 j = NmeaOpModeGsaStr(e);
71}
72
73inline void to_json(nlohmann::json& j, const NmeaNavModeGsa e)
74{
75 j = NmeaNavModeGsaStr(e);
76}
77
78inline void to_json(nlohmann::json& j, const NmeaSystemId e)
79{
80 j = NmeaSystemIdStr(e);
81}
82
83inline void to_json(nlohmann::json& j, const NmeaSignalId e)
84{
85 j = NmeaSignalIdStr(e);
86}
87
88// ---------------------------------------------------------------------------------------------------------------------
89
90inline void to_json(nlohmann::json& j, const NmeaTime& m)
91{
92 if (m.valid) {
93 j = nlohmann::json::object({
94 { "hours", m.hours },
95 { "mins", m.mins },
96 { "secs", m.secs },
97 });
98 } else {
99 j = nullptr;
100 }
101}
102
103inline void to_json(nlohmann::json& j, const NmeaDate& m)
104{
105 if (m.valid) {
106 j = nlohmann::json::object({
107 { "years", m.years },
108 { "months", m.months },
109 { "days", m.days },
110 });
111 } else {
112 j = nullptr;
113 }
114}
115
116inline void to_json(nlohmann::json& j, const NmeaLlh& m)
117{
118 if (m.latlon_valid) {
119 j = nlohmann::json::object({
120 { "lat", m.lat },
121 { "lon", m.lon },
122 });
123 if (m.height_valid) {
124 j["height"] = m.height;
125 }
126 } else {
127 j = nullptr;
128 }
129}
130
131inline void to_json(nlohmann::json& j, const NmeaSat& m)
132{
133 if (m.valid) {
134 j = nlohmann::json::object({
135 { "system", m.system },
136 { "svid", m.svid },
137 });
138 } else {
139 j = nullptr;
140 }
141}
142
143inline void to_json(nlohmann::json& j, const NmeaAzEl& m)
144{
145 if (m.valid) {
146 j = nlohmann::json::object({
147 { "system", m.system },
148 { "svid", m.svid },
149 { "el", m.el },
150 { "az", m.az },
151 });
152 } else {
153 j = nullptr;
154 }
155}
156
157inline void to_json(nlohmann::json& j, const NmeaCno& m)
158{
159 if (m.valid) {
160 j = nlohmann::json::object({
161 { "system", m.system },
162 { "svid", m.svid },
163 { "signal", m.signal },
164 { "cno", m.cno },
165 });
166 } else {
167 j = nullptr;
168 }
169}
170
171inline void to_json(nlohmann::json& j, const NmeaInt& m)
172{
173 if (m.valid) {
174 j = m.value;
175 } else {
176 j = nullptr;
177 }
178}
179
180inline void to_json(nlohmann::json& j, const NmeaFloat& m)
181{
182 if (m.valid) {
183 j = m.value;
184 } else {
185 j = nullptr;
186 }
187}
188
189// ---------------------------------------------------------------------------------------------------------------------
190
191inline void to_json(nlohmann::json& j, const NmeaGgaPayload& m)
192{
193 j = nlohmann::json::object({
194 { "time", m.time },
195 { "llh", m.llh },
196 { "height_msl", m.height_msl },
197 { "quality", m.quality },
198 { "num_sv", m.num_sv },
199 { "hdop", m.hdop },
200 { "diff_age", m.diff_age },
201 { "diff_sta", m.diff_sta },
202 });
203}
204
205// ---------------------------------------------------------------------------------------------------------------------
206
207inline void to_json(nlohmann::json& j, const NmeaGllPayload& m)
208{
209 j = nlohmann::json::object({
210 { "ll", m.ll },
211 { "time", m.time },
212 { "status", m.status },
213 { "mode", m.mode },
214 });
215}
216
217// ---------------------------------------------------------------------------------------------------------------------
218
219inline void to_json(nlohmann::json& j, const NmeaRmcPayload& m)
220{
221 j = nlohmann::json::object({
222 { "time", m.time },
223 { "ll", m.ll },
224 { "speed", m.speed },
225 { "course", m.course },
226 { "date", m.date },
227 { "mode", m.mode },
228 { "navstatus", m.navstatus },
229 });
230}
231
232// ---------------------------------------------------------------------------------------------------------------------
233
234inline void to_json(nlohmann::json& j, const NmeaVtgPayload& m)
235{
236 j = nlohmann::json::object({
237 { "cogt", m.cogt },
238 { "cogm", m.cogm },
239 { "sogn", m.sogn },
240 { "sogk", m.sogk },
241 { "mode", m.mode },
242 });
243}
244
245// ---------------------------------------------------------------------------------------------------------------------
246
247inline void to_json(nlohmann::json& j, const NmeaGstPayload& m)
248{
249 j = nlohmann::json::object({
250 { "time", m.time },
251 { "rms_range", m.rms_range },
252 { "std_major", m.std_major },
253 { "std_minor", m.std_minor },
254 { "angle_major", m.angle_major },
255 { "std_lat", m.std_lat },
256 { "std_lon", m.std_lon },
257 { "std_alt", m.std_alt },
258 });
259}
260
261// ---------------------------------------------------------------------------------------------------------------------
262
263inline void to_json(nlohmann::json& j, const NmeaHdtPayload& m)
264{
265 j = nlohmann::json::object({
266 { "heading", m.heading },
267 });
268}
269
270// ---------------------------------------------------------------------------------------------------------------------
271
272inline void to_json(nlohmann::json& j, const NmeaZdaPayload& m)
273{
274 j = nlohmann::json::object({
275 { "time", m.time },
276 { "date", m.date },
277 { "local_hr", m.local_hr },
278 { "local_min", m.local_min },
279 });
280}
281
282// ---------------------------------------------------------------------------------------------------------------------
283
284inline void to_json(nlohmann::json& j, const NmeaGsaPayload& m)
285{
286 j = nlohmann::json::object({
287 { "opmode", m.opmode },
288 { "navmode", m.navmode },
289 { "sats", m.sats },
290 { "num_sats", m.num_sats },
291 { "pdop", m.pdop },
292 { "hdop", m.hdop },
293 { "vdop", m.vdop },
294 { "system", m.system },
295 });
296}
297
298// ---------------------------------------------------------------------------------------------------------------------
299
300inline void to_json(nlohmann::json& j, const NmeaGsvPayload& m)
301{
302 j = nlohmann::json::object({
303 { "num_msgs", m.num_msgs },
304 { "msg_num", m.msg_num },
305 { "tot_num_sat", m.tot_num_sat },
306 { "azels", m.azels },
307 { "num_azels", m.num_azels },
308 { "num_cnos", m.num_cnos },
309 { "system", m.system },
310 { "signal", m.signal },
311 });
312}
313
314// ---------------------------------------------------------------------------------------------------------------------
315
316inline void to_json(nlohmann::json& j, const NmeaPayloadPtr& nmea)
317{
318 j = nlohmann::json::object();
319 if (!nmea) {
320 return;
321 }
322 j["_valid"] = nmea->valid_;
323 j["_talker"] = nmea->talker_;
324 j["_formatter"] = nmea->formatter_;
325 if (nmea) {
326 switch (nmea->formatter_) { // clang-format off
327 case NmeaFormatter::UNSPECIFIED: break;
328 case NmeaFormatter::GGA: j.update(dynamic_cast<const NmeaGgaPayload&>(*nmea)); break;
329 case NmeaFormatter::GLL: j.update(dynamic_cast<const NmeaGllPayload&>(*nmea)); break;
330 case NmeaFormatter::RMC: j.update(dynamic_cast<const NmeaRmcPayload&>(*nmea)); break;
331 case NmeaFormatter::VTG: j.update(dynamic_cast<const NmeaVtgPayload&>(*nmea)); break;
332 case NmeaFormatter::GST: j.update(dynamic_cast<const NmeaGstPayload&>(*nmea)); break;
333 case NmeaFormatter::HDT: j.update(dynamic_cast<const NmeaHdtPayload&>(*nmea)); break;
334 case NmeaFormatter::ZDA: j.update(dynamic_cast<const NmeaZdaPayload&>(*nmea)); break;
335 case NmeaFormatter::GSA: j.update(dynamic_cast<const NmeaGsaPayload&>(*nmea)); break;
336 case NmeaFormatter::GSV: j.update(dynamic_cast<const NmeaGsvPayload&>(*nmea)); break;
337 } // clang-format on
338 }
339}
340
341} // namespace fpsdk::common::parser::nmea
342/* ****************************************************************************************************************** */
343#endif // !_DOXYGEN_
344#endif // __FPSDK_COMMON_TO_JSON_NMEA_HPP__
Parser NMEA routines and types.
Definition nmea.hpp:98
NmeaSystemId
NMEA system IDs.
Definition nmea.hpp:457
NmeaModeRmcGns
NMEA-Gx-RMC and NMEA-Gx-GNS pos mode.
Definition nmea.hpp:365
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:416
NmeaNavStatusRmc
NMEA-Gx-RMC navigational status.
Definition nmea.hpp:393
const char * NmeaSystemIdStr(const NmeaSystemId system)
Stringify NMEA system ID.
const char * NmeaTalkerIdStr(const NmeaTalkerId talker)
Stringify NMEA talker ID.
NmeaModeGll
NMEA-Gx-GLL pos mode.
Definition nmea.hpp:314
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.
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:435
const char * NmeaModeVtgStr(const NmeaModeVtg mode)
Stringify 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 * NmeaModeGllStr(const NmeaModeGll mode)
Stringify NMEA-Gx-GLL pos mode.
const char * NmeaSignalIdStr(const NmeaSignalId signal)
Stringify NMEA signal IDs.
std::unique_ptr< NmeaPayload > NmeaPayloadPtr
Pointer to NMEA payload.
Definition nmea.hpp:834
NmeaStatusGllRmc
NMEA-Gx-GLL and NMEA-Gx-RMC status.
Definition nmea.hpp:292
NmeaModeVtg
NMEA-Gx-VTG pos mode.
Definition nmea.hpp:339
NmeaSignalId
NMEA signal IDs.
Definition nmea.hpp:482
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:544
NMEA-Gx-GGA message payload.
Definition nmea.hpp:681
NMEA-Gx-GLL message payload.
Definition nmea.hpp:700
NMEA-Gx-GSA message payload (NMEA 4.11 only!).
Definition nmea.hpp:796
NMEA-Gx-GST message payload.
Definition nmea.hpp:750
NMEA-Gx-GSV message payload (NMEA 4.11 only!).
Definition nmea.hpp:815
NMEA-Gx-HDT message payload.
Definition nmea.hpp:769
NMEA geodetic position.
Definition nmea.hpp:558
NMEA-Gx-RMC message payload.
Definition nmea.hpp:715
NMEA satellite (used, e.g. in GSA).
Definition nmea.hpp:570
NMEA time (hour, minutes, seconds).
Definition nmea.hpp:530
NMEA-Gx-VTG message payload.
Definition nmea.hpp:734
NMEA-Gx-ZDA message payload.
Definition nmea.hpp:781