defs.h
Go to the documentation of this file.
1 /**************************************************************************/ /**
2  * @brief Point One FusionEngine output message common definitions.
3  * @file
4  ******************************************************************************/
5 
6 #pragma once
7 
8 #include <cmath> // For NAN
9 #include <cstdint>
10 #include <ostream>
11 #include <string>
12 
13 namespace point_one {
14 namespace fusion_engine {
15 namespace messages {
16 
17 // Enforce 4-byte alignment and packing of all data structures and values so
18 // that floating point values are aligned on platforms that require it.
19 #pragma pack(push, 4)
20 
21 /**
22  * @defgroup enum_definitions Common Enumeration Definitions
23  * @{
24  */
25 
26 /**
27  * @brief System/constellation type definitions.
28  */
29 enum class SatelliteType : uint8_t {
30  UNKNOWN = 0,
31  GPS = 1,
32  GLONASS = 2,
33  LEO = 3,
34  GALILEO = 4,
35  BEIDOU = 5,
36  QZSS = 6,
37  MIXED = 7,
38  SBAS = 8,
39  IRNSS = 9,
40  MAX_VALUE = IRNSS,
41 };
42 
43 /**
44  * @brief Navigation solution type definitions.
45  */
46 enum class SolutionType : uint8_t {
47  /** Invalid, no position available. */
48  Invalid = 0,
49  /** Standalone GNSS fix, no correction data used. */
50  AutonomousGPS = 1,
51  /**
52  * Differential GNSS pseudorange solution using a local RTK base station or
53  * SSR or SBAS corrections.
54  */
55  DGPS = 2,
56  /**
57  * GNSS RTK solution with fixed integer carrier phase ambiguities (one or more
58  * signals fixed).
59  */
60  RTKFixed = 4,
61  /** GNSS RTK solution with floating point carrier phase ambiguities. */
62  RTKFloat = 5,
63  /** Integrated position using dead reckoning. */
64  Integrate = 6,
65  /** Using vision measurements. */
66  Visual = 9,
67  /**
68  * GNSS precise point positioning (PPP) pseudorange/carrier phase solution.
69  */
70  PPP = 10,
71  MAX_VALUE = PPP,
72 };
73 
74 /**
75  * @brief Identifiers for the defined output message types.
76  * @ingroup messages
77  */
78 enum class MessageType : uint16_t {
79  INVALID = 0, ///< Invalid message type
80 
81  // INS solution messages.
82  POSE = 10000, ///< @ref PoseMessage
83  GNSS_INFO = 10001, ///< @ref GNSSInfoMessage
84  GNSS_SATELLITE = 10002, ///< @ref GNSSSatelliteMessage
85  POSE_AUX = 10003, ///< @ref PoseAuxMessage
86 
87  // Sensor measurement messages.
88  IMU_MEASUREMENT = 11000, ///< @ref IMUMeasurement
89 
90  // ROS messages.
91  ROS_POSE = 12000, ///< @ref ros::PoseMessage
92  ROS_GPS_FIX = 12010, ///< @ref ros::GPSFixMessage
93  ROS_IMU = 12011, ///< @ref ros::IMUMessage
94 
96 };
97 
98 /** @} */
99 
100 /**
101  * @brief Generic timestamp representation.
102  *
103  * This structure may be used to store Point One system time values (referenced
104  * to the start of the device), UNIX times (referenced to January 1, 1970), or
105  * GPS times (referenced to January 6, 1980).
106  */
107 struct Timestamp {
108  static constexpr uint32_t INVALID = 0xFFFFFFFF;
109 
110  /**
111  * The number of full seconds since the epoch. Set to @ref INVALID if
112  * the timestamp is invalid or unknown.
113  */
114  uint32_t seconds = INVALID;
115 
116  /** The fractional part of the second, expressed in nanoseconds. */
117  uint32_t fraction_ns = INVALID;
118 };
119 
120 /**
121  * @brief The header present at the beginning of every message.
122  *
123  * The header is followed immediately in the binary stream by the message
124  * payload specified by @ref message_type.
125  */
127  static constexpr uint8_t SYNC0 = 0x2E; // '.'
128  static constexpr uint8_t SYNC1 = 0x31; // '1'
129 
130  static constexpr uint32_t INVALID_SOURCE_ID = 0xFFFFFFFF;
131 
132  /**
133  * The maximum expected message size (in bytes), used for sanity checking.
134  */
135  static const size_t MAX_MESSAGE_SIZE_BYTES = (1 << 24);
136 
137  /** Message sync bytes: always set to ASCII `.1` (0x2E, 0x31). */
138  uint8_t sync[2] = {SYNC0, SYNC1};
139 
140  uint8_t reserved[2] = {0};
141 
142  /**
143  * The 32-bit CRC of all bytes from and including the @ref protocol_version
144  * field to the last byte in the message, including the message payload. This
145  * uses the standard CRC-32 generator polynomial in reversed order
146  * (0xEDB88320).
147  *
148  * See also @ref crc_support.
149  */
150  uint32_t crc = 0;
151 
152  /** The version of the P1 binary protocol being used. */
153  uint8_t protocol_version = 2;
154 
155  /**
156  * The version of the message type specified by @ref message_type to follow.
157  */
158  uint8_t message_version = 0;
159 
160  /** Type identifier for the serialized message to follow. */
162 
163  /** The sequence number of this message. */
164  uint32_t sequence_number = 0;
165 
166  /** The size of the serialized message (bytes). */
167  uint32_t payload_size_bytes = 0;
168 
169  /** Identifies the source of the serialized data. */
171 };
172 
173 #pragma pack(pop)
174 
175 /**
176  * @brief Get a human-friendly string name for the specified @ref SatelliteType
177  * (GNSS constellation).
178  * @ingroup enum_definitions
179  *
180  * @param type The desired satellite type.
181  *
182  * @return The corresponding string name.
183  */
184 inline const char* to_string(SatelliteType type) {
185  switch (type) {
187  return "Unknown";
188 
189  case SatelliteType::GPS:
190  return "GPS";
191 
193  return "GLONASS";
194 
195  case SatelliteType::LEO:
196  return "LEO";
197 
199  return "Galileo";
200 
202  return "BeiDou";
203 
204  case SatelliteType::QZSS:
205  return "QZSS";
206 
208  return "Mixed";
209 
210  case SatelliteType::SBAS:
211  return "SBAS";
212 
214  return "IRNSS";
215 
216  default:
217  return "Invalid System";
218  }
219 }
220 
221 /**
222  * @brief @ref SatelliteType stream operator.
223  * @ingroup enum_definitions
224  */
225 inline std::ostream& operator<<(std::ostream& stream, SatelliteType type) {
226  stream << to_string(type);
227  if (type > SatelliteType::MAX_VALUE) {
228  stream << " (" << (int)type << ")";
229  }
230  return stream;
231 }
232 
233 /**
234  * @brief Get a human-friendly string name for the specified @ref MessageType.
235  * @ingroup enum_definitions
236  *
237  * @param type The desired message type.
238  *
239  * @return The corresponding string name.
240  */
241 inline const char* to_string(MessageType type) {
242  switch (type) {
244  return "Invalid";
245 
246  case MessageType::POSE:
247  return "Pose";
248 
250  return "GNSS Info";
251 
253  return "GNSS Satellite";
254 
256  return "Pose Auxiliary";
257 
259  return "IMU Measurement";
260 
262  return "ROS Pose";
263 
265  return "ROS GPSFix";
266 
268  return "ROS IMU";
269 
270  default:
271  return "Unrecognized Message";
272  }
273 }
274 
275 /**
276  * @brief @ref MessageType stream operator.
277  * @ingroup enum_definitions
278  */
279 inline std::ostream& operator<<(std::ostream& stream, MessageType type) {
280  stream << to_string(type);
281  if (type > MessageType::MAX_VALUE) {
282  stream << " (" << (int)type << ")";
283  }
284  return stream;
285 }
286 
287 /**
288  * @brief Get a human-friendly string name for the specified @ref SolutionType.
289  * @ingroup enum_definitions
290  *
291  * @param type The desired message type.
292  *
293  * @return The corresponding string name.
294  */
295 inline const char* to_string(SolutionType type) {
296  switch (type) {
298  return "Invalid";
299 
301  return "Stand Alone GNSS";
302 
303  case SolutionType::DGPS:
304  return "Differential GNSS";
305 
307  return "Fixed RTK GNSS";
308 
310  return "Real-valued Ambiguity RTK GNSS";
311 
313  return "Dead Reckoning";
314 
316  return "Visual Navigation";
317 
318  case SolutionType::PPP:
319  return "PPP GNSS";
320 
321  default:
322  return "Unrecognized Solution Type";
323  }
324 }
325 
326 /**
327  * @brief @ref SolutionType stream operator.
328  * @ingroup enum_definitions
329  */
330 inline std::ostream& operator<<(std::ostream& stream, SolutionType type) {
331  stream << to_string(type);
332  if (type > SolutionType::MAX_VALUE) {
333  stream << " (" << (int)type << ")";
334  }
335  return stream;
336 }
337 
338 /**
339  * @defgroup messages Message Definitions
340  * @brief Type definitions for all defined messages.
341  *
342  * See also @ref MessageType.
343  */
344 
345 } // namespace messages
346 } // namespace fusion_engine
347 } // namespace point_one
uint32_t source_identifier
Identifies the source of the serialized data.
Definition: defs.h:170
@ MAX_VALUE
@ POSE_AUX
PoseAuxMessage
static constexpr uint8_t SYNC0
Definition: defs.h:127
MessageType
Identifiers for the defined output message types.
Definition: defs.h:78
uint32_t sequence_number
The sequence number of this message.
Definition: defs.h:164
@ RTKFloat
GNSS RTK solution with floating point carrier phase ambiguities.
SolutionType
Navigation solution type definitions.
Definition: defs.h:46
MessageType message_type
Type identifier for the serialized message to follow.
Definition: defs.h:161
The header present at the beginning of every message.
Definition: defs.h:126
static const size_t MAX_MESSAGE_SIZE_BYTES
The maximum expected message size (in bytes), used for sanity checking.
Definition: defs.h:135
@ GNSS_INFO
GNSSInfoMessage
@ MIXED
const char * to_string(SatelliteType type)
Get a human-friendly string name for the specified SatelliteType (GNSS constellation).
Definition: defs.h:184
@ BEIDOU
uint8_t sync[2]
Message sync bytes: always set to ASCII .1 (0x2E, 0x31).
Definition: defs.h:138
@ ROS_GPS_FIX
ros::GPSFixMessage
@ ROS_POSE
ros::PoseMessage
@ INVALID
Invalid message type.
@ MAX_VALUE
@ SBAS
@ UNKNOWN
@ DGPS
Differential GNSS pseudorange solution using a local RTK base station or SSR or SBAS corrections.
@ GNSS_SATELLITE
GNSSSatelliteMessage
@ AutonomousGPS
Standalone GNSS fix, no correction data used.
SatelliteType
System/constellation type definitions.
Definition: defs.h:29
@ MAX_VALUE
@ IMU_MEASUREMENT
IMUMeasurement
@ RTKFixed
GNSS RTK solution with fixed integer carrier phase ambiguities (one or more signals fixed).
std::ostream & operator<<(std::ostream &stream, SatelliteType type)
SatelliteType stream operator.
Definition: defs.h:225
static constexpr uint32_t INVALID_SOURCE_ID
Definition: defs.h:130
uint8_t protocol_version
The version of the P1 binary protocol being used.
Definition: defs.h:153
@ ROS_IMU
ros::IMUMessage
@ POSE
PoseMessage
@ Invalid
Invalid, no position available.
Definition: crc.cc:52
@ Integrate
Integrated position using dead reckoning.
static constexpr uint8_t SYNC1
Definition: defs.h:128
@ Visual
Using vision measurements.
static constexpr uint32_t INVALID
Definition: defs.h:108
@ GPS
uint32_t payload_size_bytes
The size of the serialized message (bytes).
Definition: defs.h:167
uint32_t seconds
The number of full seconds since the epoch.
Definition: defs.h:114
uint32_t fraction_ns
The fractional part of the second, expressed in nanoseconds.
Definition: defs.h:117
@ GLONASS
Generic timestamp representation.
Definition: defs.h:107
uint32_t crc
The 32-bit CRC of all bytes from and including the protocol_version field to the last byte in the mes...
Definition: defs.h:150
@ PPP
GNSS precise point positioning (PPP) pseudorange/carrier phase solution.
@ QZSS
uint8_t message_version
The version of the message type specified by message_type to follow.
Definition: defs.h:158
@ LEO
@ GALILEO
@ IRNSS