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 <string>
11 
14 
15 namespace point_one {
16 namespace fusion_engine {
17 namespace messages {
18 
19 // Enforce 4-byte alignment and packing of all data structures and values.
20 // Floating point values are aligned on platforms that require it. This is done
21 // with a combination of setting struct attributes, and manual alignment
22 // within the definitions. See the "Message Packing" section of the README.
23 #pragma pack(push, 1)
24 
25 /**
26  * @defgroup enum_definitions Common Enumeration Definitions
27  * @{
28  */
29 
30 /**
31  * @brief Identifiers for the defined output message types.
32  * @ingroup messages
33  */
34 enum class MessageType : uint16_t {
35  INVALID = 0, ///< Invalid message type
36 
37  // Navigation solution messages.
38  POSE = 10000, ///< @ref PoseMessage
39  GNSS_INFO = 10001, ///< @ref GNSSInfoMessage
40  GNSS_SATELLITE = 10002, ///< @ref GNSSSatelliteMessage
41  POSE_AUX = 10003, ///< @ref PoseAuxMessage
42  CALIBRATION_STATUS = 10004, ///< @ref CalibrationStatusMessage
43  RELATIVE_ENU_POSITION = 10005, ///< @ref RelativeENUPositionMessage
44 
45  // Device status messages.
46  SYSTEM_STATUS = 10500, ///< @ref SystemStatusMessage
47 
48  // Sensor measurement messages.
49  IMU_OUTPUT = 11000, ///< @ref IMUOutput
50  RAW_HEADING_OUTPUT = 11001, ///< @ref RawHeadingOutput
51  RAW_IMU_OUTPUT = 11002, ///< @ref RawIMUOutput
52  HEADING_OUTPUT = 11003, ///< @ref HeadingOutput
53  IMU_INPUT = 11004, ///< @ref IMUInput
54 
55  // Vehicle measurement messages.
57  11101, ///< @ref DeprecatedWheelSpeedMeasurement
59  11102, ///< @ref DeprecatedVehicleSpeedMeasurement
60 
61  WHEEL_TICK_INPUT = 11103, ///< @ref WheelTickInput
62  VEHICLE_TICK_INPUT = 11104, ///< @ref VehicleTickInput
63  WHEEL_SPEED_INPUT = 11105, ///< @ref WheelSpeedInput
64  VEHICLE_SPEED_INPUT = 11106, ///< @ref VehicleSpeedInput
65 
66  RAW_WHEEL_TICK_OUTPUT = 11123, ///< @ref RawWheelTickOutput
67  RAW_VEHICLE_TICK_OUTPUT = 11124, ///< @ref RawVehicleTickOutput
68  RAW_WHEEL_SPEED_OUTPUT = 11125, ///< @ref RawWheelSpeedOutput
69  RAW_VEHICLE_SPEED_OUTPUT = 11126, ///< @ref RawVehicleSpeedOutput
70 
71  WHEEL_SPEED_OUTPUT = 11135, ///< @ref WheelSpeedOutput
72  VEHICLE_SPEED_OUTPUT = 11136, ///< @ref VehicleSpeedOutput
73 
74  // ROS messages.
75  ROS_POSE = 12000, ///< @ref ros::PoseMessage
76  ROS_GPS_FIX = 12010, ///< @ref ros::GPSFixMessage
77  ROS_IMU = 12011, ///< @ref ros::IMUMessage
78 
79  // Command and control messages.
80  COMMAND_RESPONSE = 13000, ///< @ref CommandResponseMessage
81  MESSAGE_REQUEST = 13001, ///< @ref MessageRequest
82  RESET_REQUEST = 13002, ///< @ref ResetRequest
83  VERSION_INFO = 13003, ///< @ref VersionInfoMessage
84  EVENT_NOTIFICATION = 13004, ///< @ref EventNotificationMessage
85  SHUTDOWN_REQUEST = 13005, ///< @ref ShutdownRequest
86  FAULT_CONTROL = 13006, ///< @ref FaultControlMessage
87  DEVICE_ID = 13007, ///< @ref DeviceIDMessage
88  STARTUP_REQUEST = 13008, ///< @ref StartupRequest
89 
90  SET_CONFIG = 13100, ///< @ref SetConfigMessage
91  GET_CONFIG = 13101, ///< @ref GetConfigMessage
92  SAVE_CONFIG = 13102, ///< @ref SaveConfigMessage
93  CONFIG_RESPONSE = 13103, ///< @ref ConfigResponseMessage
94 
95  IMPORT_DATA = 13110, ///< @ref ImportDataMessage
96  EXPORT_DATA = 13111, ///< @ref ExportDataMessage
97  PLATFORM_STORAGE_DATA = 13113, ///< @ref PlatformStorageDataMessage
98 
99  SET_MESSAGE_RATE = 13220, ///< @ref SetMessageRate
100  GET_MESSAGE_RATE = 13221, ///< @ref GetMessageRate
101  MESSAGE_RATE_RESPONSE = 13222, ///< @ref MessageRateResponse
102  SUPPORTED_IO_INTERFACES = 13223, ///< @ref SupportedIOInterfacesMessage
103 
104  LBAND_FRAME = 14000, ///< @ref LBandFrameMessage
105 
106  /// The maximum defined @ref MessageType enum value.
108 };
109 
110 /**
111  * @brief Get a human-friendly string name for the specified @ref MessageType.
112  * @ingroup enum_definitions
113  *
114  * @param type The desired message type.
115  *
116  * @return The corresponding string name.
117  */
119  switch (type) {
121  return "Invalid";
122 
123  // Navigation solution messages.
124  case MessageType::POSE:
125  return "Pose";
126 
128  return "GNSS Info";
129 
131  return "GNSS Satellite";
132 
134  return "Pose Auxiliary";
135 
137  return "Calibration Status";
138 
140  return "Relative ENU Position";
141 
142  // Device status messages.
144  return "System Status";
145 
146  // Sensor measurement messages.
148  return "IMU Output";
149 
151  return "Raw heading output";
152 
154  return "Raw IMU Output";
155 
157  return "Heading Output";
158 
160  return "IMU Input";
161 
163  return "Wheel Speed Measurement";
164 
166  return "Vehicle Speed Measurement";
167 
169  return "Wheel Tick Input";
170 
172  return "Vehicle Tick Input";
173 
175  return "Wheel Speed Input";
176 
178  return "Vehicle Speed Input";
179 
181  return "Raw Wheel Tick Output";
182 
184  return "Raw Vehicle Tick Output";
185 
187  return "Raw Wheel Speed Output";
188 
190  return "Raw Vehicle Speed Output";
191 
193  return "Wheel Speed Output";
194 
196  return "Vehicle Speed Output";
197 
198  // ROS messages.
200  return "ROS Pose";
201 
203  return "ROS GPSFix";
204 
206  return "ROS IMU";
207 
208  // Command and control messages.
210  return "Command Response";
211 
213  return "Message Transmission Request";
214 
216  return "Reset Request";
217 
219  return "Version Information";
220 
222  return "Event Notification";
223 
225  return "Shutdown Request";
226 
228  return "Startup Request";
229 
231  return "Device ID Information";
232 
234  return "Fault Control";
235 
237  return "Set Configuration Parameter";
238 
240  return "Get Configuration Parameter";
241 
243  return "Save Configuration";
244 
246  return "Configuration Parameter Value";
247 
249  return "Set Message Rate";
250 
252  return "Get Message Rate";
253 
255  return "Supported IO Interfaces";
256 
258  return "Message Rate Response";
259 
261  return "Import Data To Device";
262 
264  return "Export Data From Device";
265 
267  return "Platform Data Contents";
268 
270  return "L-band Frame Contents";
271  }
272  return "Unrecognized Message";
273 }
274 
275 /**
276  * @brief @ref MessageType stream operator.
277  * @ingroup enum_definitions
278  */
279 inline p1_ostream& operator<<(p1_ostream& stream, MessageType type) {
280  stream << to_string(type) << " (" << (int)type << ")";
281  return stream;
282 }
283 
284 /**
285  * @brief Check if the specified message type is a user command.
286  * @ingroup messages
287  *
288  * See also @ref IsResponse().
289  *
290  * @param message_type The message type in question.
291  *
292  * @return `true` if the message is a FusionEngine command.
293  */
295  switch (message_type) {
308  return true;
310  case MessageType::POSE:
346  return false;
347  }
348  return false;
349 }
350 
351 /**
352  * @brief Check if the specified message type is a response to a user command.
353  * @ingroup messages
354  *
355  * See also @ref IsCommand().
356  *
357  * @param message_type The message type in question.
358  *
359  * @return `true` if the message is a FusionEngine command response.
360  */
362  switch (message_type) {
366  return true;
367  default:
368  return false;
369  }
370 }
371 
372 /** @brief Command response status indicators. */
373 enum class Response : uint8_t {
374  OK = 0,
375  /**
376  * A version specified in the command or subcommand could not be handled.
377  * This could mean that the version was too new, or it was old and there was
378  * not a translation for it.
379  */
381  /**
382  * The command interacts with a feature that is not present on the target
383  * device (e.g., Setting the baud rate on a device without a serial port).
384  */
386  /**
387  * One or more values in the command were not in acceptable ranges (e.g., An
388  * undefined enum value, or an invalid baud rate).
389  */
390  VALUE_ERROR = 3,
391  /**
392  * The command would require adding too many elements to an internal
393  * storage.
394  */
395  INSUFFICIENT_SPACE = 4,
396  /**
397  * There was a runtime failure executing the command.
398  */
399  EXECUTION_FAILURE = 5,
400  /**
401  * The header `payload_size_bytes` is in conflict with the size of the
402  * message based on its type and type specific length fields.
403  */
405  /**
406  * Requested data was corrupted and not available.
407  */
408  DATA_CORRUPTED = 7,
409  /**
410  * The requested data isn't available.
411  */
412  NO_DATA_STORED = 8,
413  /**
414  * The device is in a state where it can't process the command.
415  */
416  UNAVAILABLE = 9,
417 };
418 
419 /**
420  * @brief Get a human-friendly string name for the specified @ref Response.
421  *
422  * @param val The enum to get the string name for.
423  *
424  * @return The corresponding string name.
425  */
427  switch (val) {
428  case Response::OK:
429  return "Ok";
431  return "Unsupported Command Version";
433  return "Unsupported Feature";
435  return "Value Error";
437  return "Insufficient Space";
439  return "Execution Failure";
441  return "Inconsistent Payload Length";
443  return "Data Corrupted";
445  return "No Data Stored";
447  return "Device Unavailable";
448  default:
449  return "Unrecognized";
450  }
451 }
452 
453 /**
454  * @brief @ref Response stream operator.
455  */
456 inline p1_ostream& operator<<(p1_ostream& stream, Response val) {
457  stream << to_string(val) << " (" << (int)val << ")";
458  return stream;
459 }
460 
461 /**
462  * @brief Navigation solution type definitions.
463  */
464 enum class SolutionType : uint8_t {
465  /** Invalid, no position available. */
466  Invalid = 0,
467  /** Standalone GNSS fix, no GNSS corrections data used. */
468  AutonomousGPS = 1,
469  /**
470  * Differential GNSS pseudorange solution using a local RTK base station or
471  * SSR or SBAS corrections.
472  */
473  DGPS = 2,
474  /**
475  * GNSS RTK solution with fixed integer carrier phase ambiguities (one or more
476  * signals fixed).
477  */
478  RTKFixed = 4,
479  /** GNSS RTK solution with floating point carrier phase ambiguities. */
480  RTKFloat = 5,
481  /** Integrated position using dead reckoning. */
482  Integrate = 6,
483  /** Using vision measurements. */
484  Visual = 9,
485  /**
486  * GNSS precise point positioning (PPP) pseudorange/carrier phase solution.
487  */
488  PPP = 10,
489  MAX_VALUE = PPP,
490 };
491 
492 /**
493  * @brief Get a human-friendly string name for the specified @ref SolutionType.
494  * @ingroup enum_definitions
495  *
496  * @param type The desired message type.
497  *
498  * @return The corresponding string name.
499  */
501  switch (type) {
503  return "Invalid";
504 
506  return "Stand Alone GNSS";
507 
508  case SolutionType::DGPS:
509  return "Differential GNSS";
510 
512  return "Fixed RTK GNSS";
513 
515  return "Real-valued Ambiguity RTK GNSS";
516 
518  return "Dead Reckoning";
519 
521  return "Visual Navigation";
522 
523  case SolutionType::PPP:
524  return "PPP GNSS";
525 
526  default:
527  return "Unrecognized Solution Type";
528  }
529 }
530 
531 /**
532  * @brief @ref SolutionType stream operator.
533  * @ingroup enum_definitions
534  */
536  stream << to_string(type) << " (" << (int)type << ")";
537  return stream;
538 }
539 
540 /** @} */
541 
542 /**
543  * @brief Generic timestamp representation.
544  *
545  * This structure may be used to store Point One system time values (referenced
546  * to the start of the device), UNIX times (referenced to January 1, 1970), or
547  * GPS times (referenced to January 6, 1980).
548  */
550  static constexpr uint32_t INVALID = 0xFFFFFFFF;
551 
552  /**
553  * The number of full seconds since the epoch. Set to @ref INVALID if
554  * the timestamp is invalid or unknown.
555  */
556  uint32_t seconds = INVALID;
557 
558  /** The fractional part of the second, expressed in nanoseconds. */
559  uint32_t fraction_ns = INVALID;
560 };
561 
562 /**
563  * @brief The header present at the beginning of every message.
564  * @ingroup messages
565  *
566  * The header is followed immediately in the binary stream by the message
567  * payload specified by @ref message_type.
568  */
570  static constexpr uint8_t SYNC0 = 0x2E; // '.'
571  static constexpr uint8_t SYNC1 = 0x31; // '1'
572 
573  static constexpr uint32_t INVALID_SOURCE_ID = 0xFFFFFFFF;
574 
575  /**
576  * The maximum expected message size (in bytes), used for sanity checking.
577  */
578  static const size_t MAX_MESSAGE_SIZE_BYTES = (1 << 24);
579 
580  /** Message sync bytes: always set to ASCII `.1` (0x2E, 0x31). */
581  uint8_t sync[2] = {SYNC0, SYNC1};
582 
583  uint8_t reserved[2] = {0};
584 
585  /**
586  * The 32-bit CRC of all bytes from and including the @ref protocol_version
587  * field to the last byte in the message, including the message payload. This
588  * uses the standard CRC-32 generator polynomial in reversed order
589  * (0xEDB88320).
590  *
591  * See also @ref crc_support.
592  */
593  uint32_t crc = 0;
594 
595  /** The version of the P1 binary protocol being used. */
596  uint8_t protocol_version = 2;
597 
598  /**
599  * The version of the message type specified by @ref message_type to follow.
600  */
601  uint8_t message_version = 0;
602 
603  /** Type identifier for the serialized message to follow. */
605 
606  /** The sequence number of this message. */
607  uint32_t sequence_number = 0;
608 
609  /** The size of the serialized message (bytes). */
610  uint32_t payload_size_bytes = 0;
611 
612  /** Identifies the source of the serialized data. */
613  uint32_t source_identifier = INVALID_SOURCE_ID;
614 };
615 
616 /**
617  * @brief Check if the specified message is a user command.
618  * @ingroup messages
619  *
620  * See @ref IsCommand() for details.
621  *
622  * @param header Header of a received FusionEngine message.
623  *
624  * @return `true` if the message is a FusionEngine command.
625  */
627  return IsCommand(header.message_type);
628 }
629 
630 /**
631  * @brief Check if the specified message type is a response to a user command.
632  * @ingroup messages
633  *
634  * See @ref IsResponse() for details.
635  *
636  * @param header Header of a received FusionEngine message.
637  *
638  * @return `true` if the message is a FusionEngine command response.
639  */
641  return IsResponse(header.message_type);
642 }
643 
644 /**
645  * @brief The base class for all message payloads.
646  * @ingroup messages
647  */
649  // Currently empty - used simply to distinguish between payload definitions
650  // and other types.
651 };
652 
653 #pragma pack(pop)
654 
655 /**
656  * @defgroup messages Message Definitions
657  * @brief Type definitions for all defined messages.
658  *
659  * See also @ref MessageType.
660  */
661 
662 } // namespace messages
663 } // namespace fusion_engine
664 } // namespace point_one
@ RAW_VEHICLE_SPEED_OUTPUT
RawVehicleSpeedOutput
@ IMPORT_DATA
ImportDataMessage
@ IMU_INPUT
IMUInput
@ MAX_VALUE
The maximum defined MessageType enum value.
@ POSE_AUX
PoseAuxMessage
MessageType
Identifiers for the defined output message types.
Definition: defs.h:34
Library portability helper definitions.
@ RTKFloat
GNSS RTK solution with floating point carrier phase ambiguities.
@ OK
SolutionType
Navigation solution type definitions.
Definition: defs.h:464
MessageType message_type
Type identifier for the serialized message to follow.
Definition: defs.h:604
The header present at the beginning of every message.
Definition: defs.h:569
@ COMMAND_RESPONSE
CommandResponseMessage
#define P1_ALIGNAS(N)
Definition: portability.h:57
@ DEVICE_ID
DeviceIDMessage
@ SHUTDOWN_REQUEST
ShutdownRequest
@ UNAVAILABLE
The device is in a state where it can't process the command.
@ RAW_VEHICLE_TICK_OUTPUT
RawVehicleTickOutput
@ DEPRECATED_WHEEL_SPEED_MEASUREMENT
DeprecatedWheelSpeedMeasurement
@ GNSS_INFO
GNSSInfoMessage
@ SUPPORTED_IO_INTERFACES
SupportedIOInterfacesMessage
@ INCONSISTENT_PAYLOAD_LENGTH
The header payload_size_bytes is in conflict with the size of the message based on its type and type ...
@ ROS_GPS_FIX
ros::GPSFixMessage
@ ROS_POSE
ros::PoseMessage
@ RAW_WHEEL_SPEED_OUTPUT
RawWheelSpeedOutput
@ SYSTEM_STATUS
SystemStatusMessage
@ INVALID
Invalid message type.
@ MAX_VALUE
@ DGPS
Differential GNSS pseudorange solution using a local RTK base station or SSR or SBAS corrections.
@ MESSAGE_RATE_RESPONSE
MessageRateResponse
@ SAVE_CONFIG
SaveConfigMessage
@ HEADING_OUTPUT
HeadingOutput
@ CALIBRATION_STATUS
CalibrationStatusMessage
@ GNSS_SATELLITE
GNSSSatelliteMessage
@ AutonomousGPS
Standalone GNSS fix, no GNSS corrections data used.
P1_CONSTEXPR_FUNC bool IsResponse(MessageType message_type)
Check if the specified message type is a response to a user command.
Definition: defs.h:361
@ LBAND_FRAME
LBandFrameMessage
@ DEPRECATED_VEHICLE_SPEED_MEASUREMENT
DeprecatedVehicleSpeedMeasurement
The base class for all message payloads.
Definition: defs.h:648
@ VALUE_ERROR
One or more values in the command were not in acceptable ranges (e.g., An undefined enum value,...
P1_CONSTEXPR_FUNC bool IsCommand(MessageType message_type)
Check if the specified message type is a user command.
Definition: defs.h:294
@ RESET_REQUEST
ResetRequest
@ RTKFixed
GNSS RTK solution with fixed integer carrier phase ambiguities (one or more signals fixed).
@ VERSION_INFO
VersionInfoMessage
@ ROS_IMU
ros::IMUMessage
@ POSE
PoseMessage
@ Invalid
Invalid, no position available.
GNSS signal and frequency type definitions.
Definition: logging.h:38
@ 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.
@ IMU_OUTPUT
IMUOutput
@ Visual
Using vision measurements.
@ RAW_IMU_OUTPUT
RawIMUOutput
P1_CONSTEXPR_FUNC const char * to_string(ConfigType type)
Get a human-friendly string name for the specified ConfigType.
@ GET_MESSAGE_RATE
GetMessageRate
std::ostream p1_ostream
Definition: portability.h:75
Response
Command response status indicators.
Definition: defs.h:373
@ NO_DATA_STORED
The requested data isn't available.
p1_ostream & operator<<(p1_ostream &stream, ConfigType type)
ConfigType stream operator.
@ EXPORT_DATA
ExportDataMessage
@ VEHICLE_SPEED_INPUT
VehicleSpeedInput
@ WHEEL_SPEED_INPUT
WheelSpeedInput
@ SET_MESSAGE_RATE
SetMessageRate
@ WHEEL_SPEED_OUTPUT
WheelSpeedOutput
@ RAW_WHEEL_TICK_OUTPUT
RawWheelTickOutput
#define P1_CONSTEXPR_FUNC
Definition: portability.h:105
@ VEHICLE_SPEED_OUTPUT
VehicleSpeedOutput
@ VEHICLE_TICK_INPUT
VehicleTickInput
@ GET_CONFIG
GetConfigMessage
@ RELATIVE_ENU_POSITION
RelativeENUPositionMessage
@ SET_CONFIG
SetConfigMessage
@ EVENT_NOTIFICATION
EventNotificationMessage
Generic timestamp representation.
Definition: defs.h:549
@ PLATFORM_STORAGE_DATA
PlatformStorageDataMessage
@ STARTUP_REQUEST
StartupRequest
@ INSUFFICIENT_SPACE
The command would require adding too many elements to an internal storage.
@ PPP
GNSS precise point positioning (PPP) pseudorange/carrier phase solution.
@ DATA_CORRUPTED
Requested data was corrupted and not available.
@ MESSAGE_REQUEST
MessageRequest
@ UNSUPPORTED_FEATURE
The command interacts with a feature that is not present on the target device (e.g....
@ RAW_HEADING_OUTPUT
RawHeadingOutput
@ FAULT_CONTROL
FaultControlMessage
@ INVALID
@ WHEEL_TICK_INPUT
WheelTickInput
@ CONFIG_RESPONSE
ConfigResponseMessage