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
51  RAW_IMU_OUTPUT = 11002, ///< @ref RawIMUOutput
53  IMU_INPUT = 11004, ///< @ref IMUInput
54  GNSS_ATTITUDE_OUTPUT = 11005, ///< @ref GNSSAttitudeOutput
55  RAW_GNSS_ATTITUDE_OUTPUT = 11006, ///< @ref RawGNSSAttitudeOutput
56 
57  // Vehicle measurement messages.
59  11101, ///< @ref DeprecatedWheelSpeedMeasurement
61  11102, ///< @ref DeprecatedVehicleSpeedMeasurement
62 
63  WHEEL_TICK_INPUT = 11103, ///< @ref WheelTickInput
64  VEHICLE_TICK_INPUT = 11104, ///< @ref VehicleTickInput
65  WHEEL_SPEED_INPUT = 11105, ///< @ref WheelSpeedInput
66  VEHICLE_SPEED_INPUT = 11106, ///< @ref VehicleSpeedInput
67 
68  RAW_WHEEL_TICK_OUTPUT = 11123, ///< @ref RawWheelTickOutput
69  RAW_VEHICLE_TICK_OUTPUT = 11124, ///< @ref RawVehicleTickOutput
70  RAW_WHEEL_SPEED_OUTPUT = 11125, ///< @ref RawWheelSpeedOutput
71  RAW_VEHICLE_SPEED_OUTPUT = 11126, ///< @ref RawVehicleSpeedOutput
72 
73  WHEEL_SPEED_OUTPUT = 11135, ///< @ref WheelSpeedOutput
74  VEHICLE_SPEED_OUTPUT = 11136, ///< @ref VehicleSpeedOutput
75 
76  // ROS messages.
77  ROS_POSE = 12000, ///< @ref ros::PoseMessage
78  ROS_GPS_FIX = 12010, ///< @ref ros::GPSFixMessage
79  ROS_IMU = 12011, ///< @ref ros::IMUMessage
80 
81  // Command and control messages.
82  COMMAND_RESPONSE = 13000, ///< @ref CommandResponseMessage
83  MESSAGE_REQUEST = 13001, ///< @ref MessageRequest
84  RESET_REQUEST = 13002, ///< @ref ResetRequest
85  VERSION_INFO = 13003, ///< @ref VersionInfoMessage
86  EVENT_NOTIFICATION = 13004, ///< @ref EventNotificationMessage
87  SHUTDOWN_REQUEST = 13005, ///< @ref ShutdownRequest
88  FAULT_CONTROL = 13006, ///< @ref FaultControlMessage
89  DEVICE_ID = 13007, ///< @ref DeviceIDMessage
90  STARTUP_REQUEST = 13008, ///< @ref StartupRequest
91 
92  SET_CONFIG = 13100, ///< @ref SetConfigMessage
93  GET_CONFIG = 13101, ///< @ref GetConfigMessage
94  SAVE_CONFIG = 13102, ///< @ref SaveConfigMessage
95  CONFIG_RESPONSE = 13103, ///< @ref ConfigResponseMessage
96 
97  IMPORT_DATA = 13110, ///< @ref ImportDataMessage
98  EXPORT_DATA = 13111, ///< @ref ExportDataMessage
99  PLATFORM_STORAGE_DATA = 13113, ///< @ref PlatformStorageDataMessage
100  INPUT_DATA_WRAPPER = 13120, ///< @ref InputDataWrapperMessage
101 
102  SET_MESSAGE_RATE = 13220, ///< @ref SetMessageRate
103  GET_MESSAGE_RATE = 13221, ///< @ref GetMessageRate
104  MESSAGE_RATE_RESPONSE = 13222, ///< @ref MessageRateResponse
105  SUPPORTED_IO_INTERFACES = 13223, ///< @ref SupportedIOInterfacesMessage
106 
107  LBAND_FRAME = 14000, ///< @ref LBandFrameMessage
108 
109  STA5635_COMMAND = 14100, ///< @ref STA5635Command
110  STA5635_COMMAND_RESPONSE = 14101, ///< @ref STA5635CommandResponse
111  STA5635_IQ_DATA = 14102, ///< @ref STA5635IQData
112 
113  /// The maximum defined @ref MessageType enum value.
115 };
116 
117 /**
118  * @brief Get a human-friendly string name for the specified @ref MessageType.
119  * @ingroup enum_definitions
120  *
121  * @param type The desired message type.
122  *
123  * @return The corresponding string name.
124  */
126  switch (type) {
128  return "Invalid";
129 
130  // Navigation solution messages.
131  case MessageType::POSE:
132  return "Pose";
133 
135  return "GNSS Info";
136 
138  return "GNSS Satellite";
139 
141  return "Pose Auxiliary";
142 
144  return "Calibration Status";
145 
147  return "Relative ENU Position";
148 
149  // Device status messages.
151  return "System Status";
152 
153  // Sensor measurement messages.
155  return "IMU Output";
156 
158  return "Raw GNSS Heading Output";
159 
161  return "Raw IMU Output";
162 
164  return "GNSS Heading Output";
165 
167  return "IMU Input";
168 
170  return "GNSS Attitude Output";
171 
173  return "Raw GNSS Attitude Output";
174 
176  return "Wheel Speed Measurement";
177 
179  return "Vehicle Speed Measurement";
180 
182  return "Wheel Tick Input";
183 
185  return "Vehicle Tick Input";
186 
188  return "Wheel Speed Input";
189 
191  return "Vehicle Speed Input";
192 
194  return "Raw Wheel Tick Output";
195 
197  return "Raw Vehicle Tick Output";
198 
200  return "Raw Wheel Speed Output";
201 
203  return "Raw Vehicle Speed Output";
204 
206  return "Wheel Speed Output";
207 
209  return "Vehicle Speed Output";
210 
211  // ROS messages.
213  return "ROS Pose";
214 
216  return "ROS GPSFix";
217 
219  return "ROS IMU";
220 
221  // Command and control messages.
223  return "Command Response";
224 
226  return "Message Transmission Request";
227 
229  return "Reset Request";
230 
232  return "Version Information";
233 
235  return "Event Notification";
236 
238  return "Shutdown Request";
239 
241  return "Startup Request";
242 
244  return "Device ID Information";
245 
247  return "Fault Control";
248 
250  return "Set Configuration Parameter";
251 
253  return "Get Configuration Parameter";
254 
256  return "Save Configuration";
257 
259  return "Configuration Parameter Value";
260 
262  return "Set Message Rate";
263 
265  return "Get Message Rate";
266 
268  return "Supported IO Interfaces";
269 
271  return "Message Rate Response";
272 
274  return "Import Data To Device";
275 
277  return "Export Data From Device";
278 
280  return "Platform Data Contents";
281 
283  return "Wrapped Input Data";
284 
286  return "L-band Frame Contents";
287 
289  return "STA5635 Command";
290 
292  return "STA5635 Command Response";
293 
295  return "STA5635 IQ Data";
296  }
297  return "Unrecognized Message";
298 }
299 
300 /**
301  * @brief @ref MessageType stream operator.
302  * @ingroup enum_definitions
303  */
304 inline p1_ostream& operator<<(p1_ostream& stream, MessageType type) {
305  stream << to_string(type) << " (" << (int)type << ")";
306  return stream;
307 }
308 
309 /**
310  * @brief Check if the specified message type is a user command.
311  * @ingroup messages
312  *
313  * See also @ref IsResponse().
314  *
315  * @param message_type The message type in question.
316  *
317  * @return `true` if the message is a FusionEngine command.
318  */
320  switch (message_type) {
334  return true;
335 
337  case MessageType::POSE:
378  return false;
379  }
380  return false;
381 }
382 
383 /**
384  * @brief Check if the specified message type is a response to a user command.
385  * @ingroup messages
386  *
387  * See also @ref IsCommand().
388  *
389  * @param message_type The message type in question.
390  *
391  * @return `true` if the message is a FusionEngine command response.
392  */
394  switch (message_type) {
399  return true;
400  default:
401  return false;
402  }
403 }
404 
405 /** @brief Command response status indicators. */
406 enum class Response : uint8_t {
407  OK = 0,
408  /**
409  * A version specified in the command or subcommand could not be handled.
410  * This could mean that the version was too new, or it was old and there was
411  * not a translation for it.
412  */
414  /**
415  * The command interacts with a feature that is not present on the target
416  * device (e.g., Setting the baud rate on a device without a serial port).
417  */
419  /**
420  * One or more values in the command were not in acceptable ranges (e.g., An
421  * undefined enum value, or an invalid baud rate).
422  */
423  VALUE_ERROR = 3,
424  /**
425  * The command would require adding too many elements to an internal
426  * storage.
427  */
428  INSUFFICIENT_SPACE = 4,
429  /**
430  * There was a runtime failure executing the command.
431  */
432  EXECUTION_FAILURE = 5,
433  /**
434  * The header `payload_size_bytes` is in conflict with the size of the
435  * message based on its type and type specific length fields.
436  */
438  /**
439  * Requested data was corrupted and not available.
440  */
441  DATA_CORRUPTED = 7,
442  /**
443  * The requested data isn't available.
444  */
445  NO_DATA_STORED = 8,
446  /**
447  * The device is in a state where it can't process the command.
448  */
449  UNAVAILABLE = 9,
450  /**
451  * An interface specified in the command is invalid, or unsupported on the
452  * target device.
453  */
455 };
456 
457 /**
458  * @brief Get a human-friendly string name for the specified @ref Response.
459  *
460  * @param val The enum to get the string name for.
461  *
462  * @return The corresponding string name.
463  */
465  switch (val) {
466  case Response::OK:
467  return "Ok";
469  return "Unsupported Command Version";
471  return "Unsupported Feature";
473  return "Value Error";
475  return "Insufficient Space";
477  return "Execution Failure";
479  return "Inconsistent Payload Length";
481  return "Data Corrupted";
483  return "No Data Stored";
485  return "Device Unavailable";
487  return "Unsupported Interface";
488  }
489  return "Unrecognized";
490 }
491 
492 /**
493  * @brief @ref Response stream operator.
494  */
495 inline p1_ostream& operator<<(p1_ostream& stream, Response val) {
496  stream << to_string(val) << " (" << (int)val << ")";
497  return stream;
498 }
499 
500 /**
501  * @brief Navigation solution type definitions.
502  */
503 enum class SolutionType : uint8_t {
504  /** Invalid, no position available. */
505  Invalid = 0,
506  /** Standalone GNSS fix, no GNSS corrections data used. */
507  AutonomousGPS = 1,
508  /**
509  * Differential GNSS pseudorange solution using a local RTK base station or
510  * SSR or SBAS corrections.
511  */
512  DGPS = 2,
513  /**
514  * GNSS RTK solution with fixed integer carrier phase ambiguities (one or more
515  * signals fixed).
516  */
517  RTKFixed = 4,
518  /** GNSS RTK solution with floating point carrier phase ambiguities. */
519  RTKFloat = 5,
520  /** Integrated position using dead reckoning. */
521  Integrate = 6,
522  /** Using vision measurements. */
523  Visual = 9,
524  /**
525  * GNSS precise point positioning (PPP) pseudorange/carrier phase solution.
526  */
527  PPP = 10,
528  MAX_VALUE = PPP,
529 };
530 
531 /**
532  * @brief Get a human-friendly string name for the specified @ref SolutionType.
533  * @ingroup enum_definitions
534  *
535  * @param type The desired message type.
536  *
537  * @return The corresponding string name.
538  */
540  switch (type) {
542  return "Invalid";
543 
545  return "Stand Alone GNSS";
546 
547  case SolutionType::DGPS:
548  return "Differential GNSS";
549 
551  return "Fixed RTK GNSS";
552 
554  return "Real-valued Ambiguity RTK GNSS";
555 
557  return "Dead Reckoning";
558 
560  return "Visual Navigation";
561 
562  case SolutionType::PPP:
563  return "PPP GNSS";
564 
565  default:
566  return "Unrecognized Solution Type";
567  }
568 }
569 
570 /**
571  * @brief @ref SolutionType stream operator.
572  * @ingroup enum_definitions
573  */
575  stream << to_string(type) << " (" << (int)type << ")";
576  return stream;
577 }
578 
579 /** @} */
580 
581 /**
582  * @brief Generic timestamp representation.
583  *
584  * This structure may be used to store Point One system time values (referenced
585  * to the start of the device), UNIX times (referenced to January 1, 1970), or
586  * GPS times (referenced to January 6, 1980).
587  */
589  static constexpr uint32_t INVALID = 0xFFFFFFFF;
590 
591  /**
592  * The number of full seconds since the epoch. Set to @ref INVALID if
593  * the timestamp is invalid or unknown.
594  */
595  uint32_t seconds = INVALID;
596 
597  /** The fractional part of the second, expressed in nanoseconds. */
598  uint32_t fraction_ns = INVALID;
599 };
600 
601 /**
602  * @brief The header present at the beginning of every message.
603  * @ingroup messages
604  *
605  * The header is followed immediately in the binary stream by the message
606  * payload specified by @ref message_type.
607  */
609  static constexpr uint8_t SYNC0 = 0x2E; // '.'
610  static constexpr uint8_t SYNC1 = 0x31; // '1'
611 
612  static constexpr uint32_t INVALID_SOURCE_ID = 0xFFFFFFFF;
613 
614  /**
615  * The maximum expected message size (in bytes), used for sanity checking.
616  */
617  static const size_t MAX_MESSAGE_SIZE_BYTES = (1 << 24);
618 
619  /** Message sync bytes: always set to ASCII `.1` (0x2E, 0x31). */
620  uint8_t sync[2] = {SYNC0, SYNC1};
621 
622  uint8_t reserved[2] = {0};
623 
624  /**
625  * The 32-bit CRC of all bytes from and including the @ref protocol_version
626  * field to the last byte in the message, including the message payload. This
627  * uses the standard CRC-32 generator polynomial in reversed order
628  * (0xEDB88320).
629  *
630  * See also @ref crc_support.
631  */
632  uint32_t crc = 0;
633 
634  /** The version of the P1 binary protocol being used. */
635  uint8_t protocol_version = 2;
636 
637  /**
638  * The version of the message type specified by @ref message_type to follow.
639  */
640  uint8_t message_version = 0;
641 
642  /** Type identifier for the serialized message to follow. */
644 
645  /** The sequence number of this message. */
646  uint32_t sequence_number = 0;
647 
648  /** The size of the serialized message (bytes). */
649  uint32_t payload_size_bytes = 0;
650 
651  /** Identifies the source of the serialized data. */
652  uint32_t source_identifier = INVALID_SOURCE_ID;
653 };
654 
655 /**
656  * @brief Check if the specified message is a user command.
657  * @ingroup messages
658  *
659  * See @ref IsCommand() for details.
660  *
661  * @param header Header of a received FusionEngine message.
662  *
663  * @return `true` if the message is a FusionEngine command.
664  */
666  return IsCommand(header.message_type);
667 }
668 
669 /**
670  * @brief Check if the specified message type is a response to a user command.
671  * @ingroup messages
672  *
673  * See @ref IsResponse() for details.
674  *
675  * @param header Header of a received FusionEngine message.
676  *
677  * @return `true` if the message is a FusionEngine command response.
678  */
680  return IsResponse(header.message_type);
681 }
682 
683 /**
684  * @brief The base class for all message payloads.
685  * @ingroup messages
686  */
688  // Currently empty - used simply to distinguish between payload definitions
689  // and other types.
690 };
691 
692 #pragma pack(pop)
693 
694 /**
695  * @defgroup messages Message Definitions
696  * @brief Type definitions for all defined messages.
697  *
698  * See also @ref MessageType.
699  */
700 
701 } // namespace messages
702 } // namespace fusion_engine
703 } // 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
@ STA5635_COMMAND
STA5635Command
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:503
P1_CONSTEXPR_FUNC const char * to_string(ConfigType type)
Get a human-friendly string name for the specified ConfigType.
MessageType message_type
Type identifier for the serialized message to follow.
Definition: defs.h:643
The header present at the beginning of every message.
Definition: defs.h:608
@ 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
@ INPUT_DATA_WRAPPER
InputDataWrapperMessage
@ INCONSISTENT_PAYLOAD_LENGTH
The header payload_size_bytes is in conflict with the size of the message based on its type and type ...
@ STA5635_IQ_DATA
STA5635IQData
@ 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
@ 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:393
@ LBAND_FRAME
LBandFrameMessage
@ DEPRECATED_VEHICLE_SPEED_MEASUREMENT
DeprecatedVehicleSpeedMeasurement
The base class for all message payloads.
Definition: defs.h:687
@ VALUE_ERROR
One or more values in the command were not in acceptable ranges (e.g., An undefined enum value,...
@ STA5635_COMMAND_RESPONSE
STA5635CommandResponse
P1_CONSTEXPR_FUNC bool IsCommand(MessageType message_type)
Check if the specified message type is a user command.
Definition: defs.h:319
@ 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.
@ GNSS_ATTITUDE_OUTPUT
GNSSAttitudeOutput
@ EXECUTION_FAILURE
There was a runtime failure executing the command.
@ DEPRECATED_RAW_HEADING_OUTPUT
@ RAW_GNSS_ATTITUDE_OUTPUT
RawGNSSAttitudeOutput
@ IMU_OUTPUT
IMUOutput
@ Visual
Using vision measurements.
@ RAW_IMU_OUTPUT
RawIMUOutput
@ DEPRECATED_HEADING_OUTPUT
@ GET_MESSAGE_RATE
GetMessageRate
@ UNSUPPORTED_INTERFACE
An interface specified in the command is invalid, or unsupported on the target device.
std::ostream p1_ostream
Definition: portability.h:75
Response
Command response status indicators.
Definition: defs.h:406
@ NO_DATA_STORED
The requested data isn't available.
@ EXPORT_DATA
ExportDataMessage
@ VEHICLE_SPEED_INPUT
VehicleSpeedInput
p1_ostream & operator<<(p1_ostream &stream, ConfigType type)
ConfigType stream operator.
@ 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
@ INVALID
@ VEHICLE_TICK_INPUT
VehicleTickInput
@ GET_CONFIG
GetConfigMessage
@ RELATIVE_ENU_POSITION
RelativeENUPositionMessage
@ SET_CONFIG
SetConfigMessage
@ EVENT_NOTIFICATION
EventNotificationMessage
Generic timestamp representation.
Definition: defs.h:588
@ 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....
@ FAULT_CONTROL
FaultControlMessage
@ WHEEL_TICK_INPUT
WheelTickInput
@ CONFIG_RESPONSE
ConfigResponseMessage