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) {
307  return true;
308  default:
309  return false;
310  }
311 }
312 
313 /**
314  * @brief Check if the specified message type is a response to a user command.
315  * @ingroup messages
316  *
317  * See also @ref IsCommand().
318  *
319  * @param message_type The message type in question.
320  *
321  * @return `true` if the message is a FusionEngine command response.
322  */
324  switch (message_type) {
328  return true;
329  default:
330  return false;
331  }
332 }
333 
334 /** @brief Command response status indicators. */
335 enum class Response : uint8_t {
336  OK = 0,
337  /**
338  * A version specified in the command or subcommand could not be handled.
339  * This could mean that the version was too new, or it was old and there was
340  * not a translation for it.
341  */
343  /**
344  * The command interacts with a feature that is not present on the target
345  * device (e.g., Setting the baud rate on a device without a serial port).
346  */
348  /**
349  * One or more values in the command were not in acceptable ranges (e.g., An
350  * undefined enum value, or an invalid baud rate).
351  */
352  VALUE_ERROR = 3,
353  /**
354  * The command would require adding too many elements to an internal
355  * storage.
356  */
357  INSUFFICIENT_SPACE = 4,
358  /**
359  * There was a runtime failure executing the command.
360  */
361  EXECUTION_FAILURE = 5,
362  /**
363  * The header `payload_size_bytes` is in conflict with the size of the
364  * message based on its type and type specific length fields.
365  */
367  /**
368  * Requested data was corrupted and not available.
369  */
370  DATA_CORRUPTED = 7,
371  /**
372  * The requested data isn't available.
373  */
374  NO_DATA_STORED = 8,
375  /**
376  * The device is in a state where it can't process the command.
377  */
378  UNAVAILABLE = 9,
379 };
380 
381 /**
382  * @brief Get a human-friendly string name for the specified @ref Response.
383  *
384  * @param val The enum to get the string name for.
385  *
386  * @return The corresponding string name.
387  */
389  switch (val) {
390  case Response::OK:
391  return "Ok";
393  return "Unsupported Command Version";
395  return "Unsupported Feature";
397  return "Value Error";
399  return "Insufficient Space";
401  return "Execution Failure";
403  return "Inconsistent Payload Length";
405  return "Data Corrupted";
407  return "No Data Stored";
409  return "Device Unavailable";
410  default:
411  return "Unrecognized";
412  }
413 }
414 
415 /**
416  * @brief @ref Response stream operator.
417  */
418 inline p1_ostream& operator<<(p1_ostream& stream, Response val) {
419  stream << to_string(val) << " (" << (int)val << ")";
420  return stream;
421 }
422 
423 /**
424  * @brief Navigation solution type definitions.
425  */
426 enum class SolutionType : uint8_t {
427  /** Invalid, no position available. */
428  Invalid = 0,
429  /** Standalone GNSS fix, no GNSS corrections data used. */
430  AutonomousGPS = 1,
431  /**
432  * Differential GNSS pseudorange solution using a local RTK base station or
433  * SSR or SBAS corrections.
434  */
435  DGPS = 2,
436  /**
437  * GNSS RTK solution with fixed integer carrier phase ambiguities (one or more
438  * signals fixed).
439  */
440  RTKFixed = 4,
441  /** GNSS RTK solution with floating point carrier phase ambiguities. */
442  RTKFloat = 5,
443  /** Integrated position using dead reckoning. */
444  Integrate = 6,
445  /** Using vision measurements. */
446  Visual = 9,
447  /**
448  * GNSS precise point positioning (PPP) pseudorange/carrier phase solution.
449  */
450  PPP = 10,
451  MAX_VALUE = PPP,
452 };
453 
454 /**
455  * @brief Get a human-friendly string name for the specified @ref SolutionType.
456  * @ingroup enum_definitions
457  *
458  * @param type The desired message type.
459  *
460  * @return The corresponding string name.
461  */
463  switch (type) {
465  return "Invalid";
466 
468  return "Stand Alone GNSS";
469 
470  case SolutionType::DGPS:
471  return "Differential GNSS";
472 
474  return "Fixed RTK GNSS";
475 
477  return "Real-valued Ambiguity RTK GNSS";
478 
480  return "Dead Reckoning";
481 
483  return "Visual Navigation";
484 
485  case SolutionType::PPP:
486  return "PPP GNSS";
487 
488  default:
489  return "Unrecognized Solution Type";
490  }
491 }
492 
493 /**
494  * @brief @ref SolutionType stream operator.
495  * @ingroup enum_definitions
496  */
498  stream << to_string(type) << " (" << (int)type << ")";
499  return stream;
500 }
501 
502 /** @} */
503 
504 /**
505  * @brief Generic timestamp representation.
506  *
507  * This structure may be used to store Point One system time values (referenced
508  * to the start of the device), UNIX times (referenced to January 1, 1970), or
509  * GPS times (referenced to January 6, 1980).
510  */
512  static constexpr uint32_t INVALID = 0xFFFFFFFF;
513 
514  /**
515  * The number of full seconds since the epoch. Set to @ref INVALID if
516  * the timestamp is invalid or unknown.
517  */
518  uint32_t seconds = INVALID;
519 
520  /** The fractional part of the second, expressed in nanoseconds. */
521  uint32_t fraction_ns = INVALID;
522 };
523 
524 /**
525  * @brief The header present at the beginning of every message.
526  * @ingroup messages
527  *
528  * The header is followed immediately in the binary stream by the message
529  * payload specified by @ref message_type.
530  */
532  static constexpr uint8_t SYNC0 = 0x2E; // '.'
533  static constexpr uint8_t SYNC1 = 0x31; // '1'
534 
535  static constexpr uint32_t INVALID_SOURCE_ID = 0xFFFFFFFF;
536 
537  /**
538  * The maximum expected message size (in bytes), used for sanity checking.
539  */
540  static const size_t MAX_MESSAGE_SIZE_BYTES = (1 << 24);
541 
542  /** Message sync bytes: always set to ASCII `.1` (0x2E, 0x31). */
543  uint8_t sync[2] = {SYNC0, SYNC1};
544 
545  uint8_t reserved[2] = {0};
546 
547  /**
548  * The 32-bit CRC of all bytes from and including the @ref protocol_version
549  * field to the last byte in the message, including the message payload. This
550  * uses the standard CRC-32 generator polynomial in reversed order
551  * (0xEDB88320).
552  *
553  * See also @ref crc_support.
554  */
555  uint32_t crc = 0;
556 
557  /** The version of the P1 binary protocol being used. */
558  uint8_t protocol_version = 2;
559 
560  /**
561  * The version of the message type specified by @ref message_type to follow.
562  */
563  uint8_t message_version = 0;
564 
565  /** Type identifier for the serialized message to follow. */
567 
568  /** The sequence number of this message. */
569  uint32_t sequence_number = 0;
570 
571  /** The size of the serialized message (bytes). */
572  uint32_t payload_size_bytes = 0;
573 
574  /** Identifies the source of the serialized data. */
575  uint32_t source_identifier = INVALID_SOURCE_ID;
576 };
577 
578 /**
579  * @brief Check if the specified message is a user command.
580  * @ingroup messages
581  *
582  * See @ref IsCommand() for details.
583  *
584  * @param header Header of a received FusionEngine message.
585  *
586  * @return `true` if the message is a FusionEngine command.
587  */
589  return IsCommand(header.message_type);
590 }
591 
592 /**
593  * @brief Check if the specified message type is a response to a user command.
594  * @ingroup messages
595  *
596  * See @ref IsResponse() for details.
597  *
598  * @param header Header of a received FusionEngine message.
599  *
600  * @return `true` if the message is a FusionEngine command response.
601  */
603  return IsResponse(header.message_type);
604 }
605 
606 /**
607  * @brief The base class for all message payloads.
608  * @ingroup messages
609  */
611  // Currently empty - used simply to distinguish between payload definitions
612  // and other types.
613 };
614 
615 #pragma pack(pop)
616 
617 /**
618  * @defgroup messages Message Definitions
619  * @brief Type definitions for all defined messages.
620  *
621  * See also @ref MessageType.
622  */
623 
624 } // namespace messages
625 } // namespace fusion_engine
626 } // 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:426
MessageType message_type
Type identifier for the serialized message to follow.
Definition: defs.h:566
The header present at the beginning of every message.
Definition: defs.h:531
@ 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:323
@ LBAND_FRAME
LBandFrameMessage
@ DEPRECATED_VEHICLE_SPEED_MEASUREMENT
DeprecatedVehicleSpeedMeasurement
The base class for all message payloads.
Definition: defs.h:610
@ 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:335
@ 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:511
@ 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