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  * Enable/disable Quectel test features (intended for factory test purposes
100  * only).
101  *
102  * Payload format: `uint8_t` (0=disable, 1=enable)
103  */
104  QUECTEL_TEST = 6,
105 };
106 
107 /**
108  * @brief Get a human-friendly string name for the specified @ref FaultType.
109  * @ingroup fault_control_messages
110  *
111  * @param type The desired fault type.
112  *
113  * @return The corresponding string name.
114  */
116  switch (type) {
118  return "Clear Faults";
119 
120  case FaultType::CRASH:
121  return "Crash";
122 
124  return "Fatal Error";
125 
126  case FaultType::COCOM:
127  return "COCOM";
128 
130  return "Enable GNSS";
131 
133  return "Region Blackout";
134 
136  return "Quectel Test";
137 
138  default:
139  return "Unrecognized";
140  }
141 }
142 
143 /**
144  * @brief @ref ConfigurationSource stream operator.
145  * @ingroup fault_control_messages
146  */
147 inline p1_ostream& operator<<(p1_ostream& stream, FaultType type) {
148  stream << to_string(type) << " (" << (int)type << ")";
149  return stream;
150 }
151 
152 /**
153  * @brief The type of COCOM limit to be applied.
154  * @ingroup fault_control_messages
155  */
156 enum class CoComType : uint8_t {
157  /** Clear the current COCOM limit. */
158  NONE = 0,
159  /** Simulate a maximum acceleration limit. */
160  ACCELERATION = 1,
161  /** Simulate a maximum speed limit. */
162  SPEED = 2,
163  /** Simulate a maximum altitude limit. */
164  ALTITUDE = 3,
165 };
166 
167 /**
168  * @brief Get a human-friendly string name for the specified @ref CoComType.
169  * @ingroup fault_control_messages
170  *
171  * @param type The desired type.
172  *
173  * @return The corresponding string name.
174  */
176  switch (type) {
177  case CoComType::NONE:
178  return "No Limit";
180  return "Acceleration";
181  case CoComType::SPEED:
182  return "Speed";
183  case CoComType::ALTITUDE:
184  return "Altitude";
185  default:
186  return "Unrecognized";
187  }
188 }
189 
190 /**
191  * @brief @ref CoComType stream operator.
192  * @ingroup fault_control_messages
193  */
194 inline p1_ostream& operator<<(p1_ostream& stream, CoComType type) {
195  stream << to_string(type) << " (" << (int)type << ")";
196  return stream;
197 }
198 
199 /**
200  * @brief Enable/disable a specified system fault (@ref
201  * MessageType::FAULT_CONTROL, version 1.0).
202  * @ingroup fault_control_messages
203  *
204  * This message is followed by an `N`-byte payload. The size and format of the
205  * payload are specified by the @ref fault_type. See @ref FaultType for details.
206  * For example, a message with a `uint8_t` payload will be serialized as
207  * follows:
208  *
209  * ```
210  * {MessageHeader, FaultControlMessage, uint8_t}
211  * ```
212  *
213  * # Expected Response
214  * The device will respond with a @ref CommandResponseMessage indicating whether
215  * or not the request succeeded.
216  */
218  static constexpr MessageType MESSAGE_TYPE = MessageType::FAULT_CONTROL;
219  static constexpr uint8_t MESSAGE_VERSION = 0;
220 
221  /** The type of fault/control to be performed. */
223 
224  uint8_t reserved[15] = {0};
225 
226  /** The size of the payload (in bytes). */
227  uint32_t payload_length_bytes = 0;
228 
229  // uint8_t payload[N];
230 };
231 
232 #pragma pack(pop)
233 
234 } // namespace messages
235 } // namespace fusion_engine
236 } // namespace point_one
MessageType
Identifiers for the defined output message types.
Definition: defs.h:34
Library portability helper definitions.
@ CRASH
Force the device to crash (intended for factory test purposes only).
@ ALTITUDE
Simulate a maximum altitude limit.
#define P1_ALIGNAS(N)
Definition: portability.h:57
@ FATAL_ERROR
Force the device to exhibit a fatal error (intended for factory test purposes only).
@ 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:610
@ REGION_BLACKOUT
Simulate a region blackout (intended for factory test purposes only).
GNSS signal and frequency type definitions.
Definition: logging.h:38
P1_CONSTEXPR_FUNC const char * to_string(ConfigType type)
Get a human-friendly string name for the specified ConfigType.
@ QUECTEL_TEST
Enable/disable Quectel test features (intended for factory test purposes only).
std::ostream p1_ostream
Definition: portability.h:75
p1_ostream & operator<<(p1_ostream &stream, ConfigType type)
ConfigType stream operator.
@ ACCELERATION
Simulate a maximum acceleration limit.
#define P1_CONSTEXPR_FUNC
Definition: portability.h:105
@ CLEAR_ALL
Clear existing faults.
@ COCOM
Simulate a COCOM limit (intended for factory test purposes only).
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