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