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