configuration.h
Go to the documentation of this file.
1 /**************************************************************************/ /**
2  * @brief Device configuration settings control messages.
3  * @file
4  ******************************************************************************/
5 
6 #pragma once
7 
8 // If we are compiling under MSVC, disable warning C4200:
9 // nonstandard extension used: zero-sized array in struct/union
10 // Zero-sized arrays are supported by MSVC, GCC, and Clang, and we use them as
11 // convenience placeholders for variable sized message payloads.
12 #ifdef _MSC_VER
13 #pragma warning(push)
14 #pragma warning(disable: 4200)
15 #endif
16 
17 #include <ostream>
18 
20 
21 namespace point_one {
22 namespace fusion_engine {
23 namespace messages {
24 
25 // Enforce 4-byte alignment and packing of all data structures and values.
26 // Floating point values are aligned on platforms that require it. This is done
27 // with a combination of setting struct attributes, and manual alignment
28 // within the definitions. See the "Message Packing" section of the README.
29 #pragma pack(push, 1)
30 
31 /**
32  * @brief An identifier for the contents of a parameter configuration message.
33  * @ingroup config_and_ctrl_messages
34  *
35  * See also @ref SetConfigMessage.
36  */
37 enum class ConfigType : uint16_t {
38  INVALID = 0,
39 
40  /**
41  * The location of the device IMU with respect to the vehicle body frame (in
42  * meters).
43  *
44  * Payload format: @ref Point3f
45  */
46  DEVICE_LEVER_ARM = 16,
47 
48  /**
49  * The orientation of the device IMU with respect to the vehicle body axes.
50  *
51  * Payload format: @ref CoarseOrientation
52  */
54 
55  /**
56  * The location of the GNSS antenna with respect to the vehicle body frame (in
57  * meters).
58  *
59  * Payload format: @ref Point3f
60  */
61  GNSS_LEVER_ARM = 18,
62 
63  /**
64  * The location of the desired output location with respect to the vehicle
65  * body frame (in meters).
66  *
67  * Payload format: @ref Point3f
68  */
69  OUTPUT_LEVER_ARM = 19,
70 
71  /**
72  * Configure the UART0 serial baud rate (in bits/second).
73  *
74  * Payload format: `uint32_t`
75  */
76  UART0_BAUD = 256,
77 
78  /**
79  * Configure the UART1 serial baud rate (in bits/second).
80  *
81  * Payload format: `uint32_t`
82  */
83  UART1_BAUD = 257,
84 };
85 
86 /**
87  * @brief Get a human-friendly string name for the specified @ref ConfigType.
88  * @ingroup config_and_ctrl_messages
89  *
90  * @param type The desired configuration parameter type.
91  *
92  * @return The corresponding string name.
93  */
94 inline const char* to_string(ConfigType type) {
95  switch (type) {
97  return "Invalid";
98 
100  return "Device Lever Arm";
101 
103  return "Device Coarse Orientation";
104 
106  return "GNSS Lever Arm";
107 
109  return "Output Lever Arm";
110 
112  return "UART0 Baud Rate";
113 
115  return "UART1 Baud Rate";
116 
117  default:
118  return "Unrecognized Configuration";
119  }
120 }
121 
122 /**
123  * @brief @ref ConfigType stream operator.
124  * @ingroup config_and_ctrl_messages
125  */
126 inline std::ostream& operator<<(std::ostream& stream, ConfigType type) {
127  stream << to_string(type) << " (" << (int)type << ")";
128  return stream;
129 }
130 
131 /**
132  * @brief The type of a device's configuration settings.
133  * @ingroup config_and_ctrl_messages
134  */
135 enum class ConfigurationSource : uint8_t {
136  ACTIVE = 0, ///< Active configuration currently in use by the device.
137  SAVED = 1, ///< Settings currently saved to persistent storage.
138 };
139 
140 /**
141  * @brief Get a human-friendly string name for the specified @ref
142  * ConfigurationSource.
143  * @ingroup config_and_ctrl_messages
144  *
145  * @param source The desired configuration source.
146  *
147  * @return The corresponding string name.
148  */
149 inline const char* to_string(ConfigurationSource source) {
150  switch (source) {
152  return "Active";
153 
155  return "Saved";
156 
157  default:
158  return "Unrecognized Source";
159  }
160 }
161 
162 /**
163  * @brief @ref ConfigurationSource stream operator.
164  * @ingroup config_and_ctrl_messages
165  */
166 inline std::ostream& operator<<(std::ostream& stream,
167  ConfigurationSource source) {
168  stream << to_string(source) << " (" << (int)source << ")";
169  return stream;
170 }
171 
172 /**
173  * @brief The type configuration save operation to be performed.
174  * @ingroup config_and_ctrl_messages
175  */
176 enum class SaveAction : uint8_t {
177  /** Save all active parameters to persistent storage. */
178  SAVE = 0,
179  /** Revert the active configuration to previously saved values. */
180  REVERT_TO_SAVED = 1,
181  /** Reset the active _and_ saved configuration to default values. */
182  REVERT_TO_DEFAULT = 2,
183 };
184 
185 /**
186  * @brief Get a human-friendly string name for the specified @ref SaveAction.
187  * @ingroup config_and_ctrl_messages
188  *
189  * @param action The desired save operation.
190  *
191  * @return The corresponding string name.
192  */
193 inline const char* to_string(SaveAction action) {
194  switch (action) {
195  case SaveAction::SAVE:
196  return "Save";
197 
199  return "Revert To Saved";
200 
202  return "Revert To Default";
203 
204  default:
205  return "Unknown";
206  }
207 }
208 
209 /**
210  * @brief @ref SaveAction stream operator.
211  * @ingroup config_and_ctrl_messages
212  */
213 inline std::ostream& operator<<(std::ostream& stream, SaveAction action) {
214  stream << to_string(action) << " (" << (int)action << ")";
215  return stream;
216 }
217 
218 /**
219  * @brief Set a user configuration parameter (@ref MessageType::SET_CONFIG,
220  * version 1.0).
221  * @ingroup config_and_ctrl_messages
222  *
223  * The format of the parameter value, @ref config_change_data, is defined by the
224  * the specified @ref config_type (@ref ConfigType). For example, an antenna
225  * lever arm definition may require three 32-bit `float` values, one for each
226  * axis, while a serial port baud rate may be specified as single 32-bit
227  * unsigned integer (`uint32_t`).
228  *
229  * The device will respond with a @ref CommandResponseMessage indicating whether
230  * or not the request was accepted. Not all parameters defined in @ref
231  * ConfigType are supported on all devices.
232  *
233  * Parameter changes are applied to the device's active configuration
234  * immediately, but are not saved to persistent storage and will be restored to
235  * their previous values on reset. To save configuration settings to persistent
236  * storage, see @ref SaveConfigMessage.
237  */
238 struct alignas(4) SetConfigMessage : public MessagePayload {
240  static constexpr uint8_t MESSAGE_VERSION = 0;
241 
242  /** The type of parameter to be configured. */
244 
245  uint8_t reserved[2] = {0};
246 
247  /** The size of the parameter value, @ref config_change_data (in bytes). */
248  uint32_t config_length_bytes = 0;
249 
250  /**
251  * A pointer to the beginning of the configuration parameter value.
252  *
253  * The size and format of the contents is specified by the @ref config_type.
254  * See @ref ConfigType.
255  */
256  uint8_t config_change_data[0];
257 };
258 
259 /**
260  * @brief Query the value of a user configuration parameter (@ref
261  * MessageType::GET_CONFIG, version 1.0).
262  * @ingroup config_and_ctrl_messages
263  *
264  * The device will respond with a @ref ConfigDataMessage containing the
265  * requested parameter value, or a @ref CommandResponseMessage on failure.
266  */
267 struct alignas(4) GetConfigMessage : public MessagePayload {
269  static constexpr uint8_t MESSAGE_VERSION = 0;
270 
271  /** The desired parameter. */
273 
274  /** The config source to request data from (active, saved, etc.). */
276 
277  uint8_t reserved[1] = {0};
278 };
279 
280 /**
281  * @brief Save or reload configuration settings (@ref MessageType::SAVE_CONFIG,
282  * version 1.0).
283  * @ingroup config_and_ctrl_messages
284  *
285  * The device will respond with a @ref CommandResponseMessage indicating whether
286  * or not the request was accepted.
287  */
288 struct alignas(4) SaveConfigMessage : public MessagePayload {
290  static constexpr uint8_t MESSAGE_VERSION = 0;
291 
292  /** The action to performed. */
294 
295  uint8_t reserved[3] = {0};
296 };
297 
298 /**
299  * @brief Response to a @ref GetConfigMessage request (@ref
300  * MessageType::CONFIG_DATA, version 1.0).
301  * @ingroup config_and_ctrl_messages
302  *
303  * This message is followed by `N` bytes, where `N` is equal to @ref
304  * config_length_bytes that make up the data associated with @ref config_type.
305  * For example if the @ref config_type is @ref ConfigType::UART0_BAUD, the
306  * payload will include a single 32-bit unsigned integer:
307  *
308  * ```
309  * {MessageHeader, ConfigDataMessage, uint32_t}
310  * ```
311  *
312  * In response to a @ref GetConfigMessage with an invalid or unsupported @ref
313  * ConfigType, @ref config_type in the resulting @ref ConfigDataMessage will be
314  * set to @ref ConfigType::INVALID. Note that invalid and rejected requests will
315  * receive a @ref ConfigDataMessage, not a @ref CommandResponseMessage.
316  */
317 struct alignas(4) ConfigDataMessage : public MessagePayload {
319  static constexpr uint8_t MESSAGE_VERSION = 0;
320 
321  /** The source of the parameter value (active, saved, etc.). */
323 
324  /**
325  * Set to `true` if the active configuration differs from the saved
326  * configuration for this parameter.
327  */
329 
330  /** The type of configuration parameter contained in this message. */
332 
333  uint8_t reserved[4] = {0};
334 
335  /** The size of the parameter value, @ref config_change_data (in bytes). */
336  uint32_t config_length_bytes = 0;
337 
338  /**
339  * A pointer to the beginning of the configuration parameter value.
340  *
341  * The size and format of the contents is specified by the @ref config_type.
342  * See @ref ConfigType.
343  */
344  uint8_t config_change_data[0];
345 };
346 
347 /**************************************************************************/ /**
348  * @name Configuration Settings Type Definitions
349  * @{
350  ******************************************************************************/
351 
352 /**
353  * @brief A 3-dimensional vector (used for lever arms, etc.).
354  */
355 struct alignas(4) Point3f {
356  float x = NAN;
357  float y = NAN;
358  float z = NAN;
359 };
360 
361 /**
362  * @brief The orientation of a device with respect to the vehicle body axes.
363  *
364  * A device's orientation is defined by specifying how the +x and +z axes of its
365  * IMU are aligned with the vehicle body axes. For example, in a car:
366  * - `forward,up`: device +x = vehicle +x, device +z = vehicle +z (i.e.,
367  * IMU pointed towards the front of the vehicle).
368  * - `left,up`: device +x = vehicle +y, device +z = vehicle +z (i.e., IMU
369  * pointed towards the left side of the vehicle)
370  * - `up,backward`: device +x = vehicle +z, device +z = vehicle -x (i.e.,
371  * IMU pointed vertically upward, with the top of the IMU pointed towards the
372  * trunk)
373  */
374 struct alignas(4) CoarseOrientation {
375  enum class Direction : uint8_t {
376  FORWARD = 0, ///< Aligned with vehicle +x axis.
377  BACKWARD = 1, ///< Aligned with vehicle -x axis.
378  LEFT = 2, ///< Aligned with vehicle +y axis.
379  RIGHT = 3, ///< Aligned with vehicle -y axis.
380  UP = 4, ///< Aligned with vehicle +z axis.
381  DOWN = 5, ///< Aligned with vehicle -z axis.
382  INVALID = 255
383  };
384 
385  /** The direction of the device +x axis relative to the vehicle body axes. */
387 
388  /** The direction of the device +z axis relative to the vehicle body axes. */
390 
391  uint8_t reserved[2] = {0};
392 };
393 
394 #pragma pack(pop)
395 
396 } // namespace messages
397 } // namespace fusion_engine
398 } // namespace point_one
399 
400 #ifdef _MSC_VER
401 #pragma warning(pop)
402 #endif
ConfigType
An identifier for the contents of a parameter configuration message.
Definition: configuration.h:37
@ BACKWARD
Aligned with vehicle -x axis.
static constexpr MessageType MESSAGE_TYPE
A 3-dimensional vector (used for lever arms, etc.).
MessageType
Identifiers for the defined output message types.
Definition: defs.h:80
@ SAVE
Save all active parameters to persistent storage.
The orientation of a device with respect to the vehicle body axes.
@ DEVICE_LEVER_ARM
The location of the device IMU with respect to the vehicle body frame (in meters).
@ REVERT_TO_SAVED
Revert the active configuration to previously saved values.
@ DOWN
Aligned with vehicle -z axis.
static constexpr MessageType MESSAGE_TYPE
@ UART1_BAUD
Configure the UART1 serial baud rate (in bits/second).
@ CONFIG_DATA
ConfigDataMessage
uint8_t config_change_data[0]
A pointer to the beginning of the configuration parameter value.
SaveAction
The type configuration save operation to be performed.
uint8_t config_change_data[0]
A pointer to the beginning of the configuration parameter value.
@ REVERT_TO_DEFAULT
Reset the active and saved configuration to default values.
@ SAVE_CONFIG
SaveConfigMessage
static constexpr MessageType MESSAGE_TYPE
float z
bool active_differs_from_saved
Set to true if the active configuration differs from the saved configuration for this parameter.
@ ACTIVE
Active configuration currently in use by the device.
uint32_t config_length_bytes
The size of the parameter value, config_change_data (in bytes).
ConfigurationSource config_source
The source of the parameter value (active, saved, etc.).
SaveAction action
The action to performed.
The base class for all message payloads.
Definition: defs.h:192
static constexpr MessageType MESSAGE_TYPE
Query the value of a user configuration parameter (MessageType::GET_CONFIG, version 1....
float y
@ INVALID
ConfigType config_type
The desired parameter.
Definition: configuration.h:21
@ UP
Aligned with vehicle +z axis.
Response to a GetConfigMessage request (MessageType::CONFIG_DATA, version 1.0).
Direction
@ DEVICE_COARSE_ORIENTATION
The orientation of the device IMU with respect to the vehicle body axes.
uint32_t config_length_bytes
The size of the parameter value, config_change_data (in bytes).
@ LEFT
Aligned with vehicle +y axis.
ConfigType config_type
The type of parameter to be configured.
@ UART0_BAUD
Configure the UART0 serial baud rate (in bits/second).
Direction z_direction
The direction of the device +z axis relative to the vehicle body axes.
ConfigurationSource request_source
The config source to request data from (active, saved, etc.).
Save or reload configuration settings (MessageType::SAVE_CONFIG, version 1.0).
Set a user configuration parameter (MessageType::SET_CONFIG, version 1.0).
static constexpr uint8_t MESSAGE_VERSION
ConfigType config_type
The type of configuration parameter contained in this message.
@ GET_CONFIG
GetConfigMessage
@ OUTPUT_LEVER_ARM
The location of the desired output location with respect to the vehicle body frame (in meters).
static constexpr uint8_t MESSAGE_VERSION
static constexpr uint8_t MESSAGE_VERSION
@ SAVED
Settings currently saved to persistent storage.
@ SET_CONFIG
SetConfigMessage
std::ostream & operator<<(std::ostream &stream, ConfigType type)
ConfigType stream operator.
Point One FusionEngine output message common definitions.
ConfigurationSource
The type of a device's configuration settings.
float x
const char * to_string(ConfigType type)
Get a human-friendly string name for the specified ConfigType.
Definition: configuration.h:94
@ GNSS_LEVER_ARM
The location of the GNSS antenna with respect to the vehicle body frame (in meters).
@ RIGHT
Aligned with vehicle -y axis.
static constexpr uint8_t MESSAGE_VERSION
Direction x_direction
The direction of the device +x axis relative to the vehicle body axes.
@ INVALID
@ FORWARD
Aligned with vehicle +x axis.