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  HEADING_MEASUREMENT = 11001, ///< @ref HeadingMeasurement
46 
47  // Vehicle measurement messages.
48  WHEEL_SPEED_MEASUREMENT = 11101, ///< @ref WheelSpeedMeasurement
49  VEHICLE_SPEED_MEASUREMENT = 11102, ///< @ref VehicleSpeedMeasurement
50  WHEEL_TICK_MEASUREMENT = 11103, ///< @ref WheelTickMeasurement
51  VEHICLE_TICK_MEASUREMENT = 11104, ///< @ref VehicleTickMeasurement
52 
53  // ROS messages.
54  ROS_POSE = 12000, ///< @ref ros::PoseMessage
55  ROS_GPS_FIX = 12010, ///< @ref ros::GPSFixMessage
56  ROS_IMU = 12011, ///< @ref ros::IMUMessage
57 
58  // Command and control messages.
59  COMMAND_RESPONSE = 13000, ///< @ref CommandResponseMessage
60  MESSAGE_REQUEST = 13001, ///< @ref MessageRequest
61  RESET_REQUEST = 13002, ///< @ref ResetRequest
62  VERSION_INFO = 13003, ///< @ref VersionInfoMessage
63  EVENT_NOTIFICATION = 13004, ///< @ref EventNotificationMessage
64  SHUTDOWN_REQUEST = 13005, ///< @ref ShutdownRequest
65  FAULT_CONTROL = 13006, ///< @ref FaultControlMessage
66 
67  SET_CONFIG = 13100, ///< @ref SetConfigMessage
68  GET_CONFIG = 13101, ///< @ref GetConfigMessage
69  SAVE_CONFIG = 13102, ///< @ref SaveConfigMessage
70  CONFIG_RESPONSE = 13103, ///< @ref ConfigResponseMessage
71 
72  IMPORT_DATA = 13110, ///< @ref ImportDataMessage
73  EXPORT_DATA = 13111, ///< @ref ExportDataMessage
74  PLATFORM_STORAGE_DATA = 13113, ///< @ref PlatformStorageDataMessage
75 
76  SET_MESSAGE_RATE = 13220, ///< @ref SetMessageRate
77  GET_MESSAGE_RATE = 13221, ///< @ref GetMessageRate
78  MESSAGE_RATE_RESPONSE = 13222, ///< @ref MessageRateResponse
79 
80  /// The maximum defined @ref MessageType enum value.
82 };
83 
84 /**
85  * @brief Get a human-friendly string name for the specified @ref MessageType.
86  * @ingroup enum_definitions
87  *
88  * @param type The desired message type.
89  *
90  * @return The corresponding string name.
91  */
92 inline const char* to_string(MessageType type) {
93  switch (type) {
95  return "Invalid";
96 
97  // Navigation solution messages.
98  case MessageType::POSE:
99  return "Pose";
100 
102  return "GNSS Info";
103 
105  return "GNSS Satellite";
106 
108  return "Pose Auxiliary";
109 
111  return "Calibration Status";
112 
114  return "Relative ENU Position";
115 
116  // Sensor measurement messages.
118  return "IMU Measurement";
119 
121  return "Heading Measurement";
122 
124  return "Wheel Speed Measurement";
125 
127  return "Vehicle Speed Measurement";
128 
130  return "Wheel Tick Measurement";
131 
133  return "Vehicle Tick Measurement";
134 
135  // ROS messages.
137  return "ROS Pose";
138 
140  return "ROS GPSFix";
141 
143  return "ROS IMU";
144 
145  // Command and control messages.
147  return "Command Response";
148 
150  return "Message Transmission Request";
151 
153  return "Reset Request";
154 
156  return "Version Information";
157 
159  return "Event Notification";
160 
162  return "Shutdown Request";
163 
165  return "Fault Control";
166 
168  return "Set Configuration Parameter";
169 
171  return "Get Configuration Parameter";
172 
174  return "Save Configuration";
175 
177  return "Configuration Parameter Value";
178 
180  return "Set Message Rate";
181 
183  return "Get Message Rate";
184 
186  return "Message Rate Response";
187 
189  return "Import Data To Device";
190 
192  return "Export Data From Device";
193 
195  return "Platform Data Contents";
196 
197  default:
198  return "Unrecognized Message";
199  }
200 }
201 
202 /**
203  * @brief @ref MessageType stream operator.
204  * @ingroup enum_definitions
205  */
206 inline std::ostream& operator<<(std::ostream& stream, MessageType type) {
207  stream << to_string(type) << " (" << (int)type << ")";
208  return stream;
209 }
210 
211 /**
212  * @brief System/constellation type definitions.
213  */
214 enum class SatelliteType : uint8_t {
215  UNKNOWN = 0,
216  GPS = 1,
217  GLONASS = 2,
218  LEO = 3,
219  GALILEO = 4,
220  BEIDOU = 5,
221  QZSS = 6,
222  MIXED = 7,
223  SBAS = 8,
224  IRNSS = 9,
225  MAX_VALUE = IRNSS,
226 };
227 
228 /**
229  * @brief Get a human-friendly string name for the specified @ref SatelliteType
230  * (GNSS constellation).
231  * @ingroup enum_definitions
232  *
233  * @param type The desired satellite type.
234  *
235  * @return The corresponding string name.
236  */
237 inline const char* to_string(SatelliteType type) {
238  switch (type) {
240  return "Unknown";
241 
242  case SatelliteType::GPS:
243  return "GPS";
244 
246  return "GLONASS";
247 
248  case SatelliteType::LEO:
249  return "LEO";
250 
252  return "Galileo";
253 
255  return "BeiDou";
256 
257  case SatelliteType::QZSS:
258  return "QZSS";
259 
261  return "Mixed";
262 
263  case SatelliteType::SBAS:
264  return "SBAS";
265 
267  return "IRNSS";
268 
269  default:
270  return "Invalid System";
271  }
272 }
273 
274 /**
275  * @brief @ref SatelliteType stream operator.
276  * @ingroup enum_definitions
277  */
278 inline std::ostream& operator<<(std::ostream& stream, SatelliteType type) {
279  stream << to_string(type) << " (" << (int)type << ")";
280  return stream;
281 }
282 
283 /** @brief Command response status indicators. */
284 enum class Response : uint8_t {
285  OK = 0,
286  /**
287  * A version specified in the command or subcommand could not be handled.
288  * This could mean that the version was too new, or it was old and there was
289  * not a translation for it.
290  */
292  /**
293  * The command interacts with a feature that is not present on the target
294  * device (e.g., Setting the baud rate on a device without a serial port).
295  */
297  /**
298  * One or more values in the command were not in acceptable ranges (e.g., An
299  * undefined enum value, or an invalid baud rate).
300  */
301  VALUE_ERROR = 3,
302  /**
303  * The command would require adding too many elements to an internal
304  * storage.
305  */
306  INSUFFICIENT_SPACE = 4,
307  /**
308  * There was a runtime failure executing the command.
309  */
310  EXECUTION_FAILURE = 5,
311  /**
312  * The header `payload_size_bytes` is in conflict with the size of the
313  * message based on its type and type specific length fields.
314  */
316  /**
317  * Requested data was corrupted and not available.
318  */
319  DATA_CORRUPTED = 7,
320  /**
321  * The requested data isn't available.
322  */
323  NO_DATA_STORED = 8,
324  /**
325  * The device is in a state where it can't process the command.
326  */
327  UNAVAILABLE = 9,
328 };
329 
330 /**
331  * @brief Get a human-friendly string name for the specified @ref Response.
332  *
333  * @param val The enum to get the string name for.
334  *
335  * @return The corresponding string name.
336  */
337 inline const char* to_string(Response val) {
338  switch (val) {
339  case Response::OK:
340  return "Ok";
342  return "Unsupported Command Version";
344  return "Unsupported Feature";
346  return "Value Error";
348  return "Insufficient Space";
350  return "Execution Failure";
352  return "Inconsistent Payload Length";
354  return "Data Corrupted";
356  return "No Data Stored";
358  return "Device Unavailable";
359  default:
360  return "Unrecognized";
361  }
362 }
363 
364 /**
365  * @brief @ref Response stream operator.
366  */
367 inline std::ostream& operator<<(std::ostream& stream, Response val) {
368  stream << to_string(val) << " (" << (int)val << ")";
369  return stream;
370 }
371 
372 /**
373  * @brief Navigation solution type definitions.
374  */
375 enum class SolutionType : uint8_t {
376  /** Invalid, no position available. */
377  Invalid = 0,
378  /** Standalone GNSS fix, no GNSS corrections data used. */
379  AutonomousGPS = 1,
380  /**
381  * Differential GNSS pseudorange solution using a local RTK base station or
382  * SSR or SBAS corrections.
383  */
384  DGPS = 2,
385  /**
386  * GNSS RTK solution with fixed integer carrier phase ambiguities (one or more
387  * signals fixed).
388  */
389  RTKFixed = 4,
390  /** GNSS RTK solution with floating point carrier phase ambiguities. */
391  RTKFloat = 5,
392  /** Integrated position using dead reckoning. */
393  Integrate = 6,
394  /** Using vision measurements. */
395  Visual = 9,
396  /**
397  * GNSS precise point positioning (PPP) pseudorange/carrier phase solution.
398  */
399  PPP = 10,
400  MAX_VALUE = PPP,
401 };
402 
403 /**
404  * @brief Get a human-friendly string name for the specified @ref SolutionType.
405  * @ingroup enum_definitions
406  *
407  * @param type The desired message type.
408  *
409  * @return The corresponding string name.
410  */
411 inline const char* to_string(SolutionType type) {
412  switch (type) {
414  return "Invalid";
415 
417  return "Stand Alone GNSS";
418 
419  case SolutionType::DGPS:
420  return "Differential GNSS";
421 
423  return "Fixed RTK GNSS";
424 
426  return "Real-valued Ambiguity RTK GNSS";
427 
429  return "Dead Reckoning";
430 
432  return "Visual Navigation";
433 
434  case SolutionType::PPP:
435  return "PPP GNSS";
436 
437  default:
438  return "Unrecognized Solution Type";
439  }
440 }
441 
442 /**
443  * @brief @ref SolutionType stream operator.
444  * @ingroup enum_definitions
445  */
446 inline std::ostream& operator<<(std::ostream& stream, SolutionType type) {
447  stream << to_string(type) << " (" << (int)type << ")";
448  return stream;
449 }
450 
451 /** @} */
452 
453 /**
454  * @brief Generic timestamp representation.
455  *
456  * This structure may be used to store Point One system time values (referenced
457  * to the start of the device), UNIX times (referenced to January 1, 1970), or
458  * GPS times (referenced to January 6, 1980).
459  */
460 struct alignas(4) Timestamp {
461  static constexpr uint32_t INVALID = 0xFFFFFFFF;
462 
463  /**
464  * The number of full seconds since the epoch. Set to @ref INVALID if
465  * the timestamp is invalid or unknown.
466  */
467  uint32_t seconds = INVALID;
468 
469  /** The fractional part of the second, expressed in nanoseconds. */
470  uint32_t fraction_ns = INVALID;
471 };
472 
473 /**
474  * @brief The header present at the beginning of every message.
475  * @ingroup messages
476  *
477  * The header is followed immediately in the binary stream by the message
478  * payload specified by @ref message_type.
479  */
480 struct alignas(4) MessageHeader {
481  static constexpr uint8_t SYNC0 = 0x2E; // '.'
482  static constexpr uint8_t SYNC1 = 0x31; // '1'
483 
484  static constexpr uint32_t INVALID_SOURCE_ID = 0xFFFFFFFF;
485 
486  /**
487  * The maximum expected message size (in bytes), used for sanity checking.
488  */
489  static const size_t MAX_MESSAGE_SIZE_BYTES = (1 << 24);
490 
491  /** Message sync bytes: always set to ASCII `.1` (0x2E, 0x31). */
492  uint8_t sync[2] = {SYNC0, SYNC1};
493 
494  uint8_t reserved[2] = {0};
495 
496  /**
497  * The 32-bit CRC of all bytes from and including the @ref protocol_version
498  * field to the last byte in the message, including the message payload. This
499  * uses the standard CRC-32 generator polynomial in reversed order
500  * (0xEDB88320).
501  *
502  * See also @ref crc_support.
503  */
504  uint32_t crc = 0;
505 
506  /** The version of the P1 binary protocol being used. */
507  uint8_t protocol_version = 2;
508 
509  /**
510  * The version of the message type specified by @ref message_type to follow.
511  */
512  uint8_t message_version = 0;
513 
514  /** Type identifier for the serialized message to follow. */
516 
517  /** The sequence number of this message. */
518  uint32_t sequence_number = 0;
519 
520  /** The size of the serialized message (bytes). */
521  uint32_t payload_size_bytes = 0;
522 
523  /** Identifies the source of the serialized data. */
525 };
526 
527 /**
528  * @brief The base class for all message payloads.
529  * @ingroup messages
530  */
532  // Currently empty - used simply to distinguish between payload definitions
533  // and other types.
534 };
535 
536 #pragma pack(pop)
537 
538 /**
539  * @defgroup messages Message Definitions
540  * @brief Type definitions for all defined messages.
541  *
542  * See also @ref MessageType.
543  */
544 
545 } // namespace messages
546 } // namespace fusion_engine
547 } // namespace point_one
@ IMPORT_DATA
ImportDataMessage
uint32_t source_identifier
Identifies the source of the serialized data.
Definition: defs.h:524
@ MAX_VALUE
The maximum defined MessageType enum value.
@ POSE_AUX
PoseAuxMessage
static constexpr uint8_t SYNC0
Definition: defs.h:481
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:518
@ RTKFloat
GNSS RTK solution with floating point carrier phase ambiguities.
@ OK
SolutionType
Navigation solution type definitions.
Definition: defs.h:375
MessageType message_type
Type identifier for the serialized message to follow.
Definition: defs.h:515
The header present at the beginning of every message.
Definition: defs.h:480
@ 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:489
@ SHUTDOWN_REQUEST
ShutdownRequest
@ UNAVAILABLE
The device is in a state where it can't process the command.
@ 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:492
@ ROS_GPS_FIX
ros::GPSFixMessage
@ ROS_POSE
ros::PoseMessage
@ 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.
@ MESSAGE_RATE_RESPONSE
MessageRateResponse
@ 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:214
@ MAX_VALUE
The base class for all message payloads.
Definition: defs.h:531
@ 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:484
@ WHEEL_SPEED_MEASUREMENT
WheelSpeedMeasurement
@ VERSION_INFO
VersionInfoMessage
uint8_t protocol_version
The version of the P1 binary protocol being used.
Definition: defs.h:507
@ 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:482
@ Visual
Using vision measurements.
static constexpr uint32_t INVALID
Definition: defs.h:461
@ GET_MESSAGE_RATE
GetMessageRate
@ GPS
Response
Command response status indicators.
Definition: defs.h:284
@ NO_DATA_STORED
The requested data isn't available.
@ EXPORT_DATA
ExportDataMessage
uint32_t payload_size_bytes
The size of the serialized message (bytes).
Definition: defs.h:521
uint32_t seconds
The number of full seconds since the epoch.
Definition: defs.h:467
@ WHEEL_TICK_MEASUREMENT
WheelTickMeasurement
@ SET_MESSAGE_RATE
SetMessageRate
uint32_t fraction_ns
The fractional part of the second, expressed in nanoseconds.
Definition: defs.h:470
@ GET_CONFIG
GetConfigMessage
@ RELATIVE_ENU_POSITION
RelativeENUPositionMessage
@ SET_CONFIG
SetConfigMessage
std::ostream & operator<<(std::ostream &stream, ConfigType type)
ConfigType stream operator.
@ GLONASS
@ HEADING_MEASUREMENT
HeadingMeasurement
@ EVENT_NOTIFICATION
EventNotificationMessage
Generic timestamp representation.
Definition: defs.h:460
@ PLATFORM_STORAGE_DATA
PlatformStorageDataMessage
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:504
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:512
@ UNSUPPORTED_FEATURE
The command interacts with a feature that is not present on the target device (e.g....
@ LEO
@ GALILEO
@ FAULT_CONTROL
FaultControlMessage
@ IRNSS
@ CONFIG_RESPONSE
ConfigResponseMessage