fault_control.h
Go to the documentation of this file.
1 /**************************************************************************/ /**
2  * @brief System fault control messages.
3  * @file
4  ******************************************************************************/
5 
6 #pragma once
7 
10 
11 namespace point_one {
12 namespace fusion_engine {
13 namespace messages {
14 
15 // Enforce 4-byte alignment and packing of all data structures and values.
16 // Floating point values are aligned on platforms that require it. This is done
17 // with a combination of setting struct attributes, and manual alignment
18 // within the definitions.
19 #pragma pack(push, 1)
20 
21 /**
22  * @defgroup fault_control_messages System Fault Control
23  * @brief Messages/types for controlling or simulating system faults.
24  * @ingroup config_and_ctrl_messages
25  */
26 
27 /**
28  * @brief Available fault types/control inputs.
29  * @ingroup fault_control_messages
30  *
31  * See @ref FaultControlMessage.
32  */
33 enum class FaultType : uint8_t {
34  /**
35  * Clear existing faults.
36  *
37  * @note
38  * This cannot be used to clear a @ref FaultType::CRASH or @ref
39  * FaultType::FATAL_ERROR.
40  *
41  * Payload format: none
42  */
43  CLEAR_ALL = 0,
44  /**
45  * Force the device to crash (intended for factory test purposes only).
46  *
47  * On crash, the device no longer produce any output on any interfaces, and
48  * will stop responding to commands. If the watchdog is enabled, the device
49  * will restart automatically after the watchdog timer elapses.
50  *
51  * @warning
52  * The device will crash immediately after receiving this request. It will not
53  * send a @ref CommandResponseMessage back to the user.
54  *
55  * Payload format: none
56  */
57  CRASH = 1,
58  /**
59  * Force the device to exhibit a fatal error (intended for factory test
60  * purposes only).
61  *
62  * After a fatal error, the device will stop navigating and will no longer
63  * produce solution messages on any interfaces. Instead, it will output an
64  * @ref EventNotificationMessage indicating the fault status. If the watchdog
65  * is enabled, the device will restart automatically after the watchdog timer
66  * elapses.
67  *
68  * Unlike @ref FaultType::CRASH, a fatal error will send an error notification
69  * to the user, but will still not send a @ref CommandResponseMessage.
70  *
71  * Payload format: none
72  */
73  FATAL_ERROR = 2,
74  /**
75  * Simulate a COCOM limit (intended for factory test purposes only).
76  *
77  * When a COCOM limit is exceeded, the device will stop navigating and will
78  * produce @ref SolutionType::Invalid solution messages. COCOM limits may be
79  * cleared via @ref ResetRequest, or by sending a @ref CoComType::NONE fault
80  * control.
81  *
82  * Payload format: @ref CoComType
83  */
84  COCOM = 3,
85  /**
86  * Enable/disable use of GNSS measurements (intended for dead reckoning
87  * performance testing).
88  *
89  * Payload format: `uint8_t` (0=disable, 1=enable)
90  */
91  ENABLE_GNSS = 4,
92  /**
93  * Simulate a region blackout (intended for factory test purposes only).
94  *
95  * Payload format: `uint8_t` (0=disable, 1=enable)
96  */
97  REGION_BLACKOUT = 5,
98 };
99 
100 /**
101  * @brief Get a human-friendly string name for the specified @ref FaultType.
102  * @ingroup fault_control_messages
103  *
104  * @param type The desired fault type.
105  *
106  * @return The corresponding string name.
107  */
109  switch (type) {
111  return "Clear Faults";
112 
113  case FaultType::CRASH:
114  return "Crash";
115 
117  return "Fatal Error";
118 
119  case FaultType::COCOM:
120  return "COCOM";
121 
123  return "Enable GNSS";
124 
126  return "Region Blackout";
127 
128  default:
129  return "Unrecognized";
130  }
131 }
132 
133 /**
134  * @brief @ref ConfigurationSource stream operator.
135  * @ingroup fault_control_messages
136  */
137 inline std::ostream& operator<<(std::ostream& stream, FaultType type) {
138  stream << to_string(type) << " (" << (int)type << ")";
139  return stream;
140 }
141 
142 /**
143  * @brief The type of COCOM limit to be applied.
144  * @ingroup fault_control_messages
145  */
146 enum class CoComType : uint8_t {
147  /** Clear the current COCOM limit. */
148  NONE = 0,
149  /** Simulate a maximum acceleration limit. */
150  ACCELERATION = 1,
151  /** Simulate a maximum speed limit. */
152  SPEED = 2,
153  /** Simulate a maximum altitude limit. */
154  ALTITUDE = 3,
155 };
156 
157 /**
158  * @brief Get a human-friendly string name for the specified @ref CoComType.
159  * @ingroup fault_control_messages
160  *
161  * @param type The desired type.
162  *
163  * @return The corresponding string name.
164  */
166  switch (type) {
167  case CoComType::NONE:
168  return "No Limit";
170  return "Acceleration";
171  case CoComType::SPEED:
172  return "Speed";
173  case CoComType::ALTITUDE:
174  return "Altitude";
175  default:
176  return "Unrecognized";
177  }
178 }
179 
180 /**
181  * @brief @ref CoComType stream operator.
182  * @ingroup fault_control_messages
183  */
184 inline std::ostream& operator<<(std::ostream& stream, CoComType type) {
185  stream << to_string(type) << " (" << (int)type << ")";
186  return stream;
187 }
188 
189 /**
190  * @brief Enable/disable a specified system fault (@ref
191  * MessageType::FAULT_CONTROL, version 1.0).
192  * @ingroup fault_control_messages
193  *
194  * This message is followed by an `N`-byte payload. The size and format of the
195  * payload are specified by the @ref fault_type. See @ref FaultType for details.
196  * For example, a message with a `uint8_t` payload will be serialized as
197  * follows:
198  *
199  * ```
200  * {MessageHeader, FaultControlMessage, uint8_t}
201  * ```
202  *
203  * # Expected Response
204  * The device will respond with a @ref CommandResponseMessage indicating whether
205  * or not the request succeeded.
206  */
207 struct alignas(4) FaultControlMessage : public MessagePayload {
209  static constexpr uint8_t MESSAGE_VERSION = 0;
210 
211  /** The type of fault/control to be performed. */
213 
214  uint8_t reserved[15] = {0};
215 
216  /** The size of the payload (in bytes). */
217  uint32_t payload_length_bytes = 0;
218 
219  // uint8_t payload[N];
220 };
221 
222 #pragma pack(pop)
223 
224 } // namespace messages
225 } // namespace fusion_engine
226 } // namespace point_one
MessageType
Identifiers for the defined output message types.
Definition: defs.h:35
Library portability helper definitions.
@ CRASH
Force the device to crash (intended for factory test purposes only).
uint32_t payload_length_bytes
The size of the payload (in bytes).
@ ALTITUDE
Simulate a maximum altitude limit.
@ FATAL_ERROR
Force the device to exhibit a fatal error (intended for factory test purposes only).
static constexpr MessageType MESSAGE_TYPE
@ SPEED
Simulate a maximum speed limit.
@ NONE
Clear the current COCOM limit.
@ ENABLE_GNSS
Enable/disable use of GNSS measurements (intended for dead reckoning performance testing).
Enable/disable a specified system fault (MessageType::FAULT_CONTROL, version 1.0).
The base class for all message payloads.
Definition: defs.h:540
@ REGION_BLACKOUT
Simulate a region blackout (intended for factory test purposes only).
GNSS signal and frequency type definitions.
Definition: logging.h:36
FaultType fault_type
The type of fault/control to be performed.
P1_CONSTEXPR_FUNC const char * to_string(ConfigType type)
Get a human-friendly string name for the specified ConfigType.
@ ACCELERATION
Simulate a maximum acceleration limit.
#define P1_CONSTEXPR_FUNC
Definition: portability.h:58
@ CLEAR_ALL
Clear existing faults.
@ COCOM
Simulate a COCOM limit (intended for factory test purposes only).
static constexpr uint8_t MESSAGE_VERSION
std::ostream & operator<<(std::ostream &stream, ConfigType type)
ConfigType stream operator.
Point One FusionEngine output message common definitions.
FaultType
Available fault types/control inputs.
Definition: fault_control.h:33
CoComType
The type of COCOM limit to be applied.
@ FAULT_CONTROL
FaultControlMessage