Fixposition SDK 0.0.0-heads/main-0-g6666cac
Collection of c++ libraries and apps for use with Fixposition products on Linux
Loading...
Searching...
No Matches
types.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 *
9 * Based on work by flipflip (https://github.com/phkehl)
10 * \endverbatim
11 *
12 * @file
13 * @brief Fixposition SDK: Parser
14 *
15 * @page FPSDK_COMMON_PARSER_TYPES Parser common types
16 *
17 * **API**: fpsdk_common/parser/types.hpp and fpsdk::common::parser
18 *
19 */
20#ifndef __FPSDK_COMMON_PARSER_TYPES_HPP__
21#define __FPSDK_COMMON_PARSER_TYPES_HPP__
22
23/* LIBC/STL */
24#include <algorithm>
25#include <cstdint>
26#include <string>
27#include <vector>
28
29/* EXTERNAL */
30
31/* PACKAGE */
32
33namespace fpsdk {
34namespace common {
35namespace parser {
36/* ****************************************************************************************************************** */
37
38/**
39 * @brief Protocols (message types), see also @ref FPSDK_COMMON_PARSER_NAMING
40 */
41enum class Protocol : int
42{
43 // See FP_PARSER_NAMEING for naming constraints!
44 FP_A = 1, //!< FP_A (Fixposition proprietary ASCII) (#PROTOCOL_NAME_FP_A)
45 FP_B, //!< FP_B (Fixposition proprietary binary) (#PROTOCOL_NAME_FP_B)
46 NMEA, //!< NMEA (#PROTOCOL_NAME_NMEA)
47 UBX, //!< UBX (u-blox proprietary binary) (#PROTOCOL_NAME_UBX)
48 RTCM3, //!< RTCM3 (#PROTOCOL_NAME_RTCM3)
49 UNI_B, //!< UNI_B (Unicore proprietary binary) (#PROTOCOL_NAME_UNI_B)
50 NOV_B, //!< NOV_B (NovAtel proprietary binary, long or short header) (#PROTOCOL_NAME_NOV_B)
51 SBF, //!< SBF (Septentrio binary format) (#PROTOCOL_NAME_SBF)
52 QGC, //!< QGC (Quectel proprietary binary) (#PROTOCOL_NAME_QGC)
53 SPARTN, //!< SPARTN (#PROTOCOL_NAME_SPARTN)
54 OTHER, //!< Other "message" (unknown or corrupt message, spurious data, line noise, ...) (#PROTOCOL_NAME_OTHER)
55};
56
57/**
58 * @name Protocol names
59 * @{
60 */
61// clang-format off
62 // See FP_PARSER_NAMEING for naming constraints!
63static constexpr const char* PROTOCOL_NAME_FP_A = "FP_A"; //!< Name (label) for Protocol::FP_A
64static constexpr const char* PROTOCOL_NAME_FP_B = "FP_B"; //!< Name (label) for Protocol::FP_B
65static constexpr const char* PROTOCOL_NAME_NMEA = "NMEA"; //!< Name (label) for Protocol::NMEA
66static constexpr const char* PROTOCOL_NAME_UBX = "UBX"; //!< Name (label) for Protocol::UBX
67static constexpr const char* PROTOCOL_NAME_RTCM3 = "RTCM3"; //!< Name (label) for Protocol::RTCM3
68static constexpr const char* PROTOCOL_NAME_UNI_B = "UNI_B"; //!< Name (label) for Protocol::UNI_B
69static constexpr const char* PROTOCOL_NAME_NOV_B = "NOV_B"; //!< Name (label) for Protocol::NOV_B
70static constexpr const char* PROTOCOL_NAME_SBF = "SBF"; //!< Name (label) for Protocol::SBF
71static constexpr const char* PROTOCOL_NAME_QGC = "QGC"; //!< Name (label) for Protocol::QGC
72static constexpr const char* PROTOCOL_NAME_SPARTN = "SPARTN"; //!< Name (label) for Protocol::SPARTN
73static constexpr const char* PROTOCOL_NAME_OTHER = "OTHER"; //!< Name (label) for Protocol::OTHER
74// clang-format on
75///@}
76
77/**
78 * @brief Stringify Protocol
79 *
80 * @param[in] proto The protocol
81 *
82 * @returns a unique string for the type, for example "UBX" (PROTOCOL_NAME_UBX) for Protocol::UBX
83 */
84const char* ProtocolStr(const Protocol proto);
85
86/**
87 * @brief Get Protocol from name
88 *
89 * @param[in] name The protocol name
90 *
91 * @returns the Protocol enum, for example Protocol::UBX for "UBX" (PROTOCOL_NAME_UBX), and for any unknown string
92 * Protocol::OTHER
93 */
94Protocol StrProtocol(const char* name);
95
96/**
97 * @brief Message frame output by the Parser
98 */
100{
101 // clang-format off
102 Protocol proto_ = Protocol::OTHER; //!< Protocol (message type)
103 std::vector<uint8_t> data_; //!< Message data
104 std::string name_; //!< Name of the message
105 mutable std::string info_; //!< Message (debug) info, default empty, call MakeInfo() to fill
106 uint64_t seq_ = 0; //!< Message counter (starting at 1)
107 // clang-format on
108
109 /**
110 * @brief Make info_ field
111 *
112 * Fills the info field, unless it's not empty. Depending on the message, this may or may not put something
113 * useful into the info_ field.
114 */
115 void MakeInfo() const;
116
117 /**
118 * @brief Get message raw data
119 *
120 * @returns a pointer to the message raw data
121 */ // clang-format off
122 inline const uint8_t* Data() const { return data_.data(); } // clang-format on
123
124 /**
125 * @brief Get message raw size
126 *
127 * @returns the message raw size
128 */ // clang-format off
129 inline std::size_t Size() const { return data_.size(); } // clang-format on
130};
131
132/**
133 * @brief Parser statistics
134 */
136{
137 uint64_t n_msgs_ = 0; //!< Number of messages parsed
138 uint64_t s_msgs_ = 0; //!< Total size of messages parsed
139 uint64_t n_fpa_ = 0; //!< Number of Protocol::FP_A messages
140 uint64_t s_fpa_ = 0; //!< Total size of Protocol::FP_A messages
141 uint64_t n_fpb_ = 0; //!< Number of Protocol::FP_B messages
142 uint64_t s_fpb_ = 0; //!< Total size of Protocol::FP_B messages
143 uint64_t n_nmea_ = 0; //!< Number of Protocol::NMEA messages
144 uint64_t s_nmea_ = 0; //!< Total size of Protocol::NMEA messages
145 uint64_t n_ubx_ = 0; //!< Number of Protocol::UBX messages
146 uint64_t s_ubx_ = 0; //!< Total size of Protocol::UBX messages
147 uint64_t n_rtcm3_ = 0; //!< Number of Protocol::RTCM3 messages
148 uint64_t s_rtcm3_ = 0; //!< Total size of Protocol::RTCM3 messages
149 uint64_t n_unib_ = 0; //!< Number of Protocol::UNI_B messages
150 uint64_t s_unib_ = 0; //!< Total size of Protocol::UNI_B messages
151 uint64_t n_novb_ = 0; //!< Number of Protocol::NOV_B messages
152 uint64_t s_novb_ = 0; //!< Total size of Protocol::NOV_B messages
153 uint64_t n_sbf_ = 0; //!< Number of Protocol::SBF messages
154 uint64_t s_sbf_ = 0; //!< Total size of Protocol::SBF messages
155 uint64_t n_qgc_ = 0; //!< Number of Protocol::QGC messages
156 uint64_t s_qgc_ = 0; //!< Total size of Protocol::QGC messages
157 uint64_t n_spartn_ = 0; //!< Number of Protocol::SPARTN messages
158 uint64_t s_spartn_ = 0; //!< Total size of Protocol::SPARTN messages
159 uint64_t n_other_ = 0; //!< Number of Protocol::OTHER messages
160 uint64_t s_other_ = 0; //!< Total size of Protocol::OTHER messages
161
162 /**
163 * @brief Update stats
164 *
165 * @param[in] msg Message to account for
166 */
167 void Update(const ParserMsg& msg);
168};
169
170/**
171 * @name Parser constraints
172 * @{
173 */
174// clang-format off
175static constexpr std::size_t MAX_ADD_SIZE = 32 * 1024; //!< Max size for Parser::Add() that is guaranteed to work
176static constexpr std::size_t MAX_NAME_SIZE = 100; //!< Maximum size of message name string (incl. nul termination)
177static constexpr std::size_t MAX_INFO_SIZE = 400; //!< Maximum size of message info string (incl. nul termination)
178static constexpr std::size_t MAX_FP_A_SIZE = 400; //!< Maximum FP_A message size (must be the same as MAX_NMEA_SIZE)
179static constexpr std::size_t MAX_FP_B_SIZE = 4096; //!< Maximum FP_B message size
180static constexpr std::size_t MAX_NMEA_SIZE = 400; //!< Maximum NMEA message size (standard NMEA would be 82!)
181static constexpr std::size_t MAX_UBX_SIZE = 4096; //!< Maximum UBX message size
182static constexpr std::size_t MAX_RTCM3_SIZE = 1028; //!< Maximum RTCM3 message size
183static constexpr std::size_t MAX_SPARTN_SIZE = 1110; //!< Maximum SPARTN message size
184static constexpr std::size_t MAX_NOV_B_SIZE = 4096; //!< Maximum NOV_B message size
185static constexpr std::size_t MAX_UNI_B_SIZE = 4096; //!< Maximum UNI_B message size
186static constexpr std::size_t MAX_SBF_SIZE = 4608; //!< Maximum SBF message size
187static constexpr std::size_t MAX_QGC_SIZE = 4608; //!< Maximum QGC message size
188static constexpr std::size_t MAX_OTHER_SIZE = 256; //!< Maximum OTHER message size
189static constexpr std::size_t MAX_ANY_SIZE = std::max({ MAX_NMEA_SIZE, MAX_FP_A_SIZE, MAX_FP_B_SIZE, MAX_UBX_SIZE,
191static constexpr std::size_t MIN_ANY_SIZE = std::min({ MAX_NMEA_SIZE, MAX_FP_A_SIZE, MAX_FP_B_SIZE, MAX_UBX_SIZE,
193// clang-format on
194///@}
195
196// Assertions on some constraints we rely on
197static_assert(MAX_ADD_SIZE > (4 * MAX_ANY_SIZE), ""); // Should be fairly large...
198static_assert(MAX_NMEA_SIZE == MAX_FP_A_SIZE, ""); // As documented above
199static_assert(MIN_ANY_SIZE >= 256, ""); // Something reasonable...
200static_assert(MIN_ANY_SIZE < 1024, ""); // Something reasonable...
201static_assert(MAX_ANY_SIZE >= 2048, ""); // Something reasonable...
202static_assert(MAX_ANY_SIZE <= 10240, ""); // Something reasonable...
203static_assert(MAX_RTCM3_SIZE < (0x3ff + 6), ""); // 10-bits payload size + frame size
204static_assert(MAX_SPARTN_SIZE < (0x3ff + 88), ""); // 10-bits payload size + max. frame size
205
206/* ****************************************************************************************************************** */
207} // namespace parser
208} // namespace common
209} // namespace fpsdk
210#endif // __FPSDK_COMMON_PARSER_TYPES_HPP__
static constexpr std::size_t MIN_ANY_SIZE
The smallest of the above.
Definition types.hpp:191
static constexpr std::size_t MAX_NMEA_SIZE
Maximum NMEA message size (standard NMEA would be 82!)
Definition types.hpp:180
Protocol StrProtocol(const char *name)
Get Protocol from name.
static constexpr std::size_t MAX_NAME_SIZE
Maximum size of message name string (incl. nul termination)
Definition types.hpp:176
static constexpr const char * PROTOCOL_NAME_UBX
Name (label) for Protocol::UBX.
Definition types.hpp:66
static constexpr const char * PROTOCOL_NAME_FP_A
Name (label) for Protocol::FP_A.
Definition types.hpp:63
static constexpr std::size_t MAX_SPARTN_SIZE
Maximum SPARTN message size.
Definition types.hpp:183
static constexpr const char * PROTOCOL_NAME_FP_B
Name (label) for Protocol::FP_B.
Definition types.hpp:64
static constexpr std::size_t MAX_FP_A_SIZE
Maximum FP_A message size (must be the same as MAX_NMEA_SIZE)
Definition types.hpp:178
static constexpr const char * PROTOCOL_NAME_UNI_B
Name (label) for Protocol::UNI_B.
Definition types.hpp:68
static constexpr std::size_t MAX_RTCM3_SIZE
Maximum RTCM3 message size.
Definition types.hpp:182
static constexpr const char * PROTOCOL_NAME_SBF
Name (label) for Protocol::SBF.
Definition types.hpp:70
static constexpr const char * PROTOCOL_NAME_QGC
Name (label) for Protocol::QGC.
Definition types.hpp:71
static constexpr const char * PROTOCOL_NAME_RTCM3
Name (label) for Protocol::RTCM3.
Definition types.hpp:67
static constexpr std::size_t MAX_INFO_SIZE
Maximum size of message info string (incl. nul termination)
Definition types.hpp:177
static constexpr const char * PROTOCOL_NAME_NOV_B
Name (label) for Protocol::NOV_B.
Definition types.hpp:69
static constexpr std::size_t MAX_UNI_B_SIZE
Maximum UNI_B message size.
Definition types.hpp:185
static constexpr std::size_t MAX_FP_B_SIZE
Maximum FP_B message size.
Definition types.hpp:179
static constexpr std::size_t MAX_NOV_B_SIZE
Maximum NOV_B message size.
Definition types.hpp:184
Protocol
Protocols (message types), see also Protocol and message naming.
Definition types.hpp:42
@ OTHER
Other "message" (unknown or corrupt message, spurious data, line noise, ...) (PROTOCOL_NAME_OTHER)
Definition types.hpp:54
@ SPARTN
SPARTN (PROTOCOL_NAME_SPARTN)
Definition types.hpp:53
@ FP_B
FP_B (Fixposition proprietary binary) (PROTOCOL_NAME_FP_B)
Definition types.hpp:45
@ NMEA
NMEA (PROTOCOL_NAME_NMEA)
Definition types.hpp:46
@ QGC
QGC (Quectel proprietary binary) (PROTOCOL_NAME_QGC)
Definition types.hpp:52
@ SBF
SBF (Septentrio binary format) (PROTOCOL_NAME_SBF)
Definition types.hpp:51
@ UNI_B
UNI_B (Unicore proprietary binary) (PROTOCOL_NAME_UNI_B)
Definition types.hpp:49
@ NOV_B
NOV_B (NovAtel proprietary binary, long or short header) (PROTOCOL_NAME_NOV_B)
Definition types.hpp:50
@ UBX
UBX (u-blox proprietary binary) (PROTOCOL_NAME_UBX)
Definition types.hpp:47
@ FP_A
FP_A (Fixposition proprietary ASCII) (PROTOCOL_NAME_FP_A)
Definition types.hpp:44
@ RTCM3
RTCM3 (PROTOCOL_NAME_RTCM3)
Definition types.hpp:48
const char * ProtocolStr(const Protocol proto)
Stringify Protocol.
static constexpr const char * PROTOCOL_NAME_NMEA
Name (label) for Protocol::NMEA.
Definition types.hpp:65
static constexpr std::size_t MAX_ADD_SIZE
Max size for Parser::Add() that is guaranteed to work.
Definition types.hpp:175
static constexpr const char * PROTOCOL_NAME_SPARTN
Name (label) for Protocol::SPARTN.
Definition types.hpp:72
static constexpr std::size_t MAX_ANY_SIZE
The largest of the above.
Definition types.hpp:189
static constexpr std::size_t MAX_SBF_SIZE
Maximum SBF message size.
Definition types.hpp:186
static constexpr std::size_t MAX_UBX_SIZE
Maximum UBX message size.
Definition types.hpp:181
static constexpr std::size_t MAX_OTHER_SIZE
Maximum OTHER message size.
Definition types.hpp:188
static constexpr std::size_t MAX_QGC_SIZE
Maximum QGC message size.
Definition types.hpp:187
static constexpr const char * PROTOCOL_NAME_OTHER
Name (label) for Protocol::OTHER.
Definition types.hpp:73
Fixposition SDK: Common library.
Definition doc.hpp:21
Fixposition SDK.
Message frame output by the Parser.
Definition types.hpp:100
std::string info_
Message (debug) info, default empty, call MakeInfo() to fill.
Definition types.hpp:105
Protocol proto_
Protocol (message type)
Definition types.hpp:102
std::string name_
Name of the message.
Definition types.hpp:104
void MakeInfo() const
Make info_ field.
uint64_t seq_
Message counter (starting at 1)
Definition types.hpp:106
const uint8_t * Data() const
Get message raw data.
Definition types.hpp:122
std::vector< uint8_t > data_
Message data.
Definition types.hpp:103
std::size_t Size() const
Get message raw size.
Definition types.hpp:129
uint64_t s_other_
Total size of Protocol::OTHER messages.
Definition types.hpp:160
uint64_t s_nmea_
Total size of Protocol::NMEA messages.
Definition types.hpp:144
uint64_t n_other_
Number of Protocol::OTHER messages.
Definition types.hpp:159
uint64_t n_spartn_
Number of Protocol::SPARTN messages.
Definition types.hpp:157
uint64_t n_qgc_
Number of Protocol::QGC messages.
Definition types.hpp:155
uint64_t s_sbf_
Total size of Protocol::SBF messages.
Definition types.hpp:154
uint64_t s_fpa_
Total size of Protocol::FP_A messages.
Definition types.hpp:140
uint64_t s_spartn_
Total size of Protocol::SPARTN messages.
Definition types.hpp:158
void Update(const ParserMsg &msg)
Update stats.
uint64_t s_qgc_
Total size of Protocol::QGC messages.
Definition types.hpp:156
uint64_t n_fpb_
Number of Protocol::FP_B messages.
Definition types.hpp:141
uint64_t n_unib_
Number of Protocol::UNI_B messages.
Definition types.hpp:149
uint64_t n_fpa_
Number of Protocol::FP_A messages.
Definition types.hpp:139
uint64_t s_fpb_
Total size of Protocol::FP_B messages.
Definition types.hpp:142
uint64_t s_rtcm3_
Total size of Protocol::RTCM3 messages.
Definition types.hpp:148
uint64_t n_rtcm3_
Number of Protocol::RTCM3 messages.
Definition types.hpp:147
uint64_t s_msgs_
Total size of messages parsed.
Definition types.hpp:138
uint64_t n_ubx_
Number of Protocol::UBX messages.
Definition types.hpp:145
uint64_t n_msgs_
Number of messages parsed.
Definition types.hpp:137
uint64_t n_novb_
Number of Protocol::NOV_B messages.
Definition types.hpp:151
uint64_t n_sbf_
Number of Protocol::SBF messages.
Definition types.hpp:153
uint64_t n_nmea_
Number of Protocol::NMEA messages.
Definition types.hpp:143
uint64_t s_unib_
Total size of Protocol::UNI_B messages.
Definition types.hpp:150
uint64_t s_ubx_
Total size of Protocol::UBX messages.
Definition types.hpp:146
uint64_t s_novb_
Total size of Protocol::NOV_B messages.
Definition types.hpp:152