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