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