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