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.
18 // Floating point values are aligned on platforms that require it. This is done
19 // with a combination of setting struct attributes, and manual alignment
20 // within the definitions. See the "Message Packing" section of the README.
21 #pragma pack(push, 1)
22 
23 /**
24  * @defgroup enum_definitions Common Enumeration Definitions
25  * @{
26  */
27 
28 /**
29  * @brief Identifiers for the defined output message types.
30  * @ingroup messages
31  */
32 enum class MessageType : uint16_t {
33  INVALID = 0, ///< Invalid message type
34 
35  // Navigation solution messages.
36  POSE = 10000, ///< @ref PoseMessage
37  GNSS_INFO = 10001, ///< @ref GNSSInfoMessage
38  GNSS_SATELLITE = 10002, ///< @ref GNSSSatelliteMessage
39  POSE_AUX = 10003, ///< @ref PoseAuxMessage
40  CALIBRATION_STATUS = 10004, ///< @ref CalibrationStatusMessage
41  RELATIVE_ENU_POSITION = 10005, ///< @ref RelativeENUPositionMessage
42 
43  // Sensor measurement messages.
44  IMU_MEASUREMENT = 11000, ///< @ref IMUMeasurement
45 
46  // Vehicle measurement messages.
47  WHEEL_SPEED_MEASUREMENT = 11101, ///< @ref WheelSpeedMeasurement
48  VEHICLE_SPEED_MEASUREMENT = 11102, ///< @ref VehicleSpeedMeasurement
49  WHEEL_TICK_MEASUREMENT = 11103, ///< @ref WheelTickMeasurement
50  VEHICLE_TICK_MEASUREMENT = 11104, ///< @ref VehicleTickMeasurement
51 
52  // ROS messages.
53  ROS_POSE = 12000, ///< @ref ros::PoseMessage
54  ROS_GPS_FIX = 12010, ///< @ref ros::GPSFixMessage
55  ROS_IMU = 12011, ///< @ref ros::IMUMessage
56 
57  // Command and control messages.
58  COMMAND_RESPONSE = 13000, ///< @ref CommandResponseMessage
59  MESSAGE_REQUEST = 13001, ///< @ref MessageRequest
60  RESET_REQUEST = 13002, ///< @ref ResetRequest
61  VERSION_INFO = 13003, ///< @ref VersionInfoMessage
62  EVENT_NOTIFICATION = 13004, ///< @ref EventNotificationMessage
63  SHUTDOWN_REQUEST = 13005, ///< @ref ShutdownRequest
64 
65  SET_CONFIG = 13100, ///< @ref SetConfigMessage
66  GET_CONFIG = 13101, ///< @ref GetConfigMessage
67  SAVE_CONFIG = 13102, ///< @ref SaveConfigMessage
68  CONFIG_RESPONSE = 13103, ///< @ref ConfigResponseMessage
69 
70  SET_OUTPUT_INTERFACE_CONFIG = 13200, ///< @ref SetOutputInterfaceConfigMessage
71  GET_OUTPUT_INTERFACE_CONFIG = 13201, ///< @ref GetOutputInterfaceConfigMessage
73  13202, ///< @ref OutputInterfaceConfigResponseMessage
74 
75  SET_OUTPUT_MESSAGE_RATE = 13220, ///< @ref SetMessageOutputRate
76  GET_OUTPUT_MESSAGE_RATE = 13221, ///< @ref GetMessageOutputRate
77  OUTPUT_MESSAGE_RATE_RESPONSE = 13222, ///< @ref MessageOutputRateResponse
78 
79  /// The maximum defined @ref MessageType enum value.
81 };
82 
83 /**
84  * @brief Get a human-friendly string name for the specified @ref MessageType.
85  * @ingroup enum_definitions
86  *
87  * @param type The desired message type.
88  *
89  * @return The corresponding string name.
90  */
91 inline const char* to_string(MessageType type) {
92  switch (type) {
94  return "Invalid";
95 
96  // Navigation solution messages.
97  case MessageType::POSE:
98  return "Pose";
99 
101  return "GNSS Info";
102 
104  return "GNSS Satellite";
105 
107  return "Pose Auxiliary";
108 
110  return "Calibration Status";
111 
112  // Sensor measurement messages.
114  return "IMU Measurement";
115 
117  return "Wheel Speed Measurement";
118 
120  return "Vehicle Speed Measurement";
121 
123  return "Wheel Tick Measurement";
124 
125  // ROS messages.
127  return "ROS Pose";
128 
130  return "ROS GPSFix";
131 
133  return "ROS IMU";
134 
135  // Command and control messages.
137  return "Command Response";
138 
140  return "Message Transmission Request";
141 
143  return "Reset Request";
144 
146  return "Version Information";
147 
149  return "Event Notification";
150 
152  return "Shutdown Request";
153 
155  return "Set Configuration Parameter";
156 
158  return "Get Configuration Parameter";
159 
161  return "Save Configuration";
162 
164  return "Configuration Parameter Value";
165 
167  return "Set Output Interface Config";
168 
170  return "Get Output Interface Config";
171 
173  return "Output Interface Config Response";
174 
175  default:
176  return "Unrecognized Message";
177  }
178 }
179 
180 /**
181  * @brief @ref MessageType stream operator.
182  * @ingroup enum_definitions
183  */
184 inline std::ostream& operator<<(std::ostream& stream, MessageType type) {
185  stream << to_string(type) << " (" << (int)type << ")";
186  return stream;
187 }
188 
189 /**
190  * @brief System/constellation type definitions.
191  */
192 enum class SatelliteType : uint8_t {
193  UNKNOWN = 0,
194  GPS = 1,
195  GLONASS = 2,
196  LEO = 3,
197  GALILEO = 4,
198  BEIDOU = 5,
199  QZSS = 6,
200  MIXED = 7,
201  SBAS = 8,
202  IRNSS = 9,
203  MAX_VALUE = IRNSS,
204 };
205 
206 /**
207  * @brief Get a human-friendly string name for the specified @ref SatelliteType
208  * (GNSS constellation).
209  * @ingroup enum_definitions
210  *
211  * @param type The desired satellite type.
212  *
213  * @return The corresponding string name.
214  */
215 inline const char* to_string(SatelliteType type) {
216  switch (type) {
218  return "Unknown";
219 
220  case SatelliteType::GPS:
221  return "GPS";
222 
224  return "GLONASS";
225 
226  case SatelliteType::LEO:
227  return "LEO";
228 
230  return "Galileo";
231 
233  return "BeiDou";
234 
235  case SatelliteType::QZSS:
236  return "QZSS";
237 
239  return "Mixed";
240 
241  case SatelliteType::SBAS:
242  return "SBAS";
243 
245  return "IRNSS";
246 
247  default:
248  return "Invalid System";
249  }
250 }
251 
252 /**
253  * @brief @ref SatelliteType stream operator.
254  * @ingroup enum_definitions
255  */
256 inline std::ostream& operator<<(std::ostream& stream, SatelliteType type) {
257  stream << to_string(type) << " (" << (int)type << ")";
258  return stream;
259 }
260 
261 /** @brief Command response status indicators. */
262 enum class Response : uint8_t {
263  OK = 0,
264  /**
265  * A version specified in the command or subcommand could not be handled.
266  * This could mean that the version was too new, or it was old and there was
267  * not a translation for it.
268  */
270  /**
271  * The command interacts with a feature that is not present on the target
272  * device (e.g., Setting the baud rate on a device without a serial port).
273  */
275  /**
276  * One or more values in the command were not in acceptable ranges (e.g., An
277  * undefined enum value, or an invalid baud rate).
278  */
279  VALUE_ERROR = 3,
280  /**
281  * The command would require adding too many elements to an internal
282  * storage.
283  */
284  INSUFFICIENT_SPACE = 4,
285  /**
286  * There was a runtime failure executing the command.
287  */
288  EXECUTION_FAILURE = 5,
289  /**
290  * The header `payload_size_bytes` is in conflict with the size of the
291  * message based on its type and type specific length fields.
292  */
294  /**
295  * Requested data was corrupted and not available.
296  */
297  DATA_CORRUPTED = 7,
298 };
299 
300 /**
301  * @brief Get a human-friendly string name for the specified @ref Response.
302  *
303  * @param val The enum to get the string name for.
304  *
305  * @return The corresponding string name.
306  */
307 inline const char* to_string(Response val) {
308  switch (val) {
309  case Response::OK:
310  return "Ok";
312  return "Unsupported Command Version";
314  return "Unsupported Feature";
316  return "Value Error";
318  return "Insufficient Space";
320  return "Execution Failure";
322  return "Inconsistent Payload Length";
324  return "Data Corrupted";
325  default:
326  return "Unrecognized";
327  }
328 }
329 
330 /**
331  * @brief @ref Response stream operator.
332  */
333 inline std::ostream& operator<<(std::ostream& stream, Response val) {
334  stream << to_string(val) << " (" << (int)val << ")";
335  return stream;
336 }
337 
338 /**
339  * @brief Navigation solution type definitions.
340  */
341 enum class SolutionType : uint8_t {
342  /** Invalid, no position available. */
343  Invalid = 0,
344  /** Standalone GNSS fix, no GNSS corrections data used. */
345  AutonomousGPS = 1,
346  /**
347  * Differential GNSS pseudorange solution using a local RTK base station or
348  * SSR or SBAS corrections.
349  */
350  DGPS = 2,
351  /**
352  * GNSS RTK solution with fixed integer carrier phase ambiguities (one or more
353  * signals fixed).
354  */
355  RTKFixed = 4,
356  /** GNSS RTK solution with floating point carrier phase ambiguities. */
357  RTKFloat = 5,
358  /** Integrated position using dead reckoning. */
359  Integrate = 6,
360  /** Using vision measurements. */
361  Visual = 9,
362  /**
363  * GNSS precise point positioning (PPP) pseudorange/carrier phase solution.
364  */
365  PPP = 10,
366  MAX_VALUE = PPP,
367 };
368 
369 /**
370  * @brief Get a human-friendly string name for the specified @ref SolutionType.
371  * @ingroup enum_definitions
372  *
373  * @param type The desired message type.
374  *
375  * @return The corresponding string name.
376  */
377 inline const char* to_string(SolutionType type) {
378  switch (type) {
380  return "Invalid";
381 
383  return "Stand Alone GNSS";
384 
385  case SolutionType::DGPS:
386  return "Differential GNSS";
387 
389  return "Fixed RTK GNSS";
390 
392  return "Real-valued Ambiguity RTK GNSS";
393 
395  return "Dead Reckoning";
396 
398  return "Visual Navigation";
399 
400  case SolutionType::PPP:
401  return "PPP GNSS";
402 
403  default:
404  return "Unrecognized Solution Type";
405  }
406 }
407 
408 /**
409  * @brief @ref SolutionType stream operator.
410  * @ingroup enum_definitions
411  */
412 inline std::ostream& operator<<(std::ostream& stream, SolutionType type) {
413  stream << to_string(type) << " (" << (int)type << ")";
414  return stream;
415 }
416 
417 /** @} */
418 
419 /**
420  * @brief Generic timestamp representation.
421  *
422  * This structure may be used to store Point One system time values (referenced
423  * to the start of the device), UNIX times (referenced to January 1, 1970), or
424  * GPS times (referenced to January 6, 1980).
425  */
426 struct alignas(4) Timestamp {
427  static constexpr uint32_t INVALID = 0xFFFFFFFF;
428 
429  /**
430  * The number of full seconds since the epoch. Set to @ref INVALID if
431  * the timestamp is invalid or unknown.
432  */
433  uint32_t seconds = INVALID;
434 
435  /** The fractional part of the second, expressed in nanoseconds. */
436  uint32_t fraction_ns = INVALID;
437 };
438 
439 /**
440  * @brief The header present at the beginning of every message.
441  * @ingroup messages
442  *
443  * The header is followed immediately in the binary stream by the message
444  * payload specified by @ref message_type.
445  */
446 struct alignas(4) MessageHeader {
447  static constexpr uint8_t SYNC0 = 0x2E; // '.'
448  static constexpr uint8_t SYNC1 = 0x31; // '1'
449 
450  static constexpr uint32_t INVALID_SOURCE_ID = 0xFFFFFFFF;
451 
452  /**
453  * The maximum expected message size (in bytes), used for sanity checking.
454  */
455  static const size_t MAX_MESSAGE_SIZE_BYTES = (1 << 24);
456 
457  /** Message sync bytes: always set to ASCII `.1` (0x2E, 0x31). */
458  uint8_t sync[2] = {SYNC0, SYNC1};
459 
460  uint8_t reserved[2] = {0};
461 
462  /**
463  * The 32-bit CRC of all bytes from and including the @ref protocol_version
464  * field to the last byte in the message, including the message payload. This
465  * uses the standard CRC-32 generator polynomial in reversed order
466  * (0xEDB88320).
467  *
468  * See also @ref crc_support.
469  */
470  uint32_t crc = 0;
471 
472  /** The version of the P1 binary protocol being used. */
473  uint8_t protocol_version = 2;
474 
475  /**
476  * The version of the message type specified by @ref message_type to follow.
477  */
478  uint8_t message_version = 0;
479 
480  /** Type identifier for the serialized message to follow. */
482 
483  /** The sequence number of this message. */
484  uint32_t sequence_number = 0;
485 
486  /** The size of the serialized message (bytes). */
487  uint32_t payload_size_bytes = 0;
488 
489  /** Identifies the source of the serialized data. */
491 };
492 
493 /**
494  * @brief The base class for all message payloads.
495  * @ingroup messages
496  */
498  // Currently empty - used simply to distinguish between payload definitions
499  // and other types.
500 };
501 
502 #pragma pack(pop)
503 
504 /**
505  * @defgroup messages Message Definitions
506  * @brief Type definitions for all defined messages.
507  *
508  * See also @ref MessageType.
509  */
510 
511 } // namespace messages
512 } // namespace fusion_engine
513 } // namespace point_one
uint32_t source_identifier
Identifies the source of the serialized data.
Definition: defs.h:490
@ MAX_VALUE
The maximum defined MessageType enum value.
@ POSE_AUX
PoseAuxMessage
static constexpr uint8_t SYNC0
Definition: defs.h:447
MessageType
Identifiers for the defined output message types.
Definition: defs.h:32
uint32_t sequence_number
The sequence number of this message.
Definition: defs.h:484
@ RTKFloat
GNSS RTK solution with floating point carrier phase ambiguities.
@ OK
SolutionType
Navigation solution type definitions.
Definition: defs.h:341
MessageType message_type
Type identifier for the serialized message to follow.
Definition: defs.h:481
The header present at the beginning of every message.
Definition: defs.h:446
@ COMMAND_RESPONSE
CommandResponseMessage
static const size_t MAX_MESSAGE_SIZE_BYTES
The maximum expected message size (in bytes), used for sanity checking.
Definition: defs.h:455
@ SHUTDOWN_REQUEST
ShutdownRequest
@ GET_OUTPUT_INTERFACE_CONFIG
GetOutputInterfaceConfigMessage
@ GNSS_INFO
GNSSInfoMessage
@ MIXED
@ INCONSISTENT_PAYLOAD_LENGTH
The header payload_size_bytes is in conflict with the size of the message based on its type and type ...
@ BEIDOU
uint8_t sync[2]
Message sync bytes: always set to ASCII .1 (0x2E, 0x31).
Definition: defs.h:458
@ ROS_GPS_FIX
ros::GPSFixMessage
@ ROS_POSE
ros::PoseMessage
@ SET_OUTPUT_MESSAGE_RATE
SetMessageOutputRate
@ INVALID
Invalid message type.
@ MAX_VALUE
@ VEHICLE_TICK_MEASUREMENT
VehicleTickMeasurement
@ VEHICLE_SPEED_MEASUREMENT
VehicleSpeedMeasurement
@ SBAS
@ UNKNOWN
@ DGPS
Differential GNSS pseudorange solution using a local RTK base station or SSR or SBAS corrections.
@ SAVE_CONFIG
SaveConfigMessage
@ CALIBRATION_STATUS
CalibrationStatusMessage
@ GNSS_SATELLITE
GNSSSatelliteMessage
@ AutonomousGPS
Standalone GNSS fix, no GNSS corrections data used.
SatelliteType
System/constellation type definitions.
Definition: defs.h:192
@ MAX_VALUE
The base class for all message payloads.
Definition: defs.h:497
@ VALUE_ERROR
One or more values in the command were not in acceptable ranges (e.g., An undefined enum value,...
@ IMU_MEASUREMENT
IMUMeasurement
@ RESET_REQUEST
ResetRequest
@ RTKFixed
GNSS RTK solution with fixed integer carrier phase ambiguities (one or more signals fixed).
static constexpr uint32_t INVALID_SOURCE_ID
Definition: defs.h:450
@ WHEEL_SPEED_MEASUREMENT
WheelSpeedMeasurement
@ VERSION_INFO
VersionInfoMessage
uint8_t protocol_version
The version of the P1 binary protocol being used.
Definition: defs.h:473
@ ROS_IMU
ros::IMUMessage
@ POSE
PoseMessage
@ Invalid
Invalid, no position available.
Definition: logging.h:36
@ Integrate
Integrated position using dead reckoning.
@ UNSUPPORTED_CMD_VERSION
A version specified in the command or subcommand could not be handled.
@ EXECUTION_FAILURE
There was a runtime failure executing the command.
static constexpr uint8_t SYNC1
Definition: defs.h:448
@ Visual
Using vision measurements.
static constexpr uint32_t INVALID
Definition: defs.h:427
@ OUTPUT_INTERFACE_CONFIG_RESPONSE
OutputInterfaceConfigResponseMessage
@ GPS
Response
Command response status indicators.
Definition: defs.h:262
uint32_t payload_size_bytes
The size of the serialized message (bytes).
Definition: defs.h:487
uint32_t seconds
The number of full seconds since the epoch.
Definition: defs.h:433
@ GET_OUTPUT_MESSAGE_RATE
GetMessageOutputRate
@ WHEEL_TICK_MEASUREMENT
WheelTickMeasurement
uint32_t fraction_ns
The fractional part of the second, expressed in nanoseconds.
Definition: defs.h:436
@ OUTPUT_MESSAGE_RATE_RESPONSE
MessageOutputRateResponse
@ GET_CONFIG
GetConfigMessage
@ RELATIVE_ENU_POSITION
RelativeENUPositionMessage
@ SET_CONFIG
SetConfigMessage
std::ostream & operator<<(std::ostream &stream, ConfigType type)
ConfigType stream operator.
@ GLONASS
@ EVENT_NOTIFICATION
EventNotificationMessage
Generic timestamp representation.
Definition: defs.h:426
@ SET_OUTPUT_INTERFACE_CONFIG
SetOutputInterfaceConfigMessage
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:470
const char * to_string(ConfigType type)
Get a human-friendly string name for the specified ConfigType.
@ INSUFFICIENT_SPACE
The command would require adding too many elements to an internal storage.
@ PPP
GNSS precise point positioning (PPP) pseudorange/carrier phase solution.
@ QZSS
@ DATA_CORRUPTED
Requested data was corrupted and not available.
@ MESSAGE_REQUEST
MessageRequest
uint8_t message_version
The version of the message type specified by message_type to follow.
Definition: defs.h:478
@ UNSUPPORTED_FEATURE
The command interacts with a feature that is not present on the target device (e.g....
@ LEO
@ GALILEO
@ IRNSS
@ CONFIG_RESPONSE
ConfigResponseMessage