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  * Simulate a specified integrity status failure (intended for factory test
107  * purposes only).
108  *
109  * Payload format: `uint8_t`
110  */
111  INTEGRITY_STATUS = 7,
112 };
113 
114 /**
115  * @brief Get a human-friendly string name for the specified @ref FaultType.
116  * @ingroup fault_control_messages
117  *
118  * @param type The desired fault type.
119  *
120  * @return The corresponding string name.
121  */
123  switch (type) {
125  return "Clear Faults";
126 
127  case FaultType::CRASH:
128  return "Crash";
129 
131  return "Fatal Error";
132 
133  case FaultType::COCOM:
134  return "COCOM";
135 
137  return "Enable GNSS";
138 
140  return "Region Blackout";
141 
143  return "Quectel Test";
144 
146  return "Integrity Status";
147 
148  default:
149  return "Unrecognized";
150  }
151 }
152 
153 /**
154  * @brief @ref ConfigurationSource stream operator.
155  * @ingroup fault_control_messages
156  */
157 inline p1_ostream& operator<<(p1_ostream& stream, FaultType type) {
158  stream << to_string(type) << " (" << (int)type << ")";
159  return stream;
160 }
161 
162 /**
163  * @brief The type of COCOM limit to be applied.
164  * @ingroup fault_control_messages
165  */
166 enum class CoComType : uint8_t {
167  /** Clear the current COCOM limit. */
168  NONE = 0,
169  /** Simulate a maximum acceleration limit. */
170  ACCELERATION = 1,
171  /** Simulate a maximum speed limit. */
172  SPEED = 2,
173  /** Simulate a maximum altitude limit. */
174  ALTITUDE = 3,
175 };
176 
177 /**
178  * @brief Get a human-friendly string name for the specified @ref CoComType.
179  * @ingroup fault_control_messages
180  *
181  * @param type The desired type.
182  *
183  * @return The corresponding string name.
184  */
186  switch (type) {
187  case CoComType::NONE:
188  return "No Limit";
190  return "Acceleration";
191  case CoComType::SPEED:
192  return "Speed";
193  case CoComType::ALTITUDE:
194  return "Altitude";
195  default:
196  return "Unrecognized";
197  }
198 }
199 
200 /**
201  * @brief @ref CoComType stream operator.
202  * @ingroup fault_control_messages
203  */
204 inline p1_ostream& operator<<(p1_ostream& stream, CoComType type) {
205  stream << to_string(type) << " (" << (int)type << ")";
206  return stream;
207 }
208 
209 /**
210  * @brief Enable/disable a specified system fault (@ref
211  * MessageType::FAULT_CONTROL, version 1.0).
212  * @ingroup fault_control_messages
213  *
214  * This message is followed by an `N`-byte payload. The size and format of the
215  * payload are specified by the @ref fault_type. See @ref FaultType for details.
216  * For example, a message with a `uint8_t` payload will be serialized as
217  * follows:
218  *
219  * ```
220  * {MessageHeader, FaultControlMessage, uint8_t}
221  * ```
222  *
223  * # Expected Response
224  * The device will respond with a @ref CommandResponseMessage indicating whether
225  * or not the request succeeded.
226  */
228  static constexpr MessageType MESSAGE_TYPE = MessageType::FAULT_CONTROL;
229  static constexpr uint8_t MESSAGE_VERSION = 0;
230 
231  /** The type of fault/control to be performed. */
233 
234  uint8_t reserved[15] = {0};
235 
236  /** The size of the payload (in bytes). */
237  uint32_t payload_length_bytes = 0;
238 
239  // uint8_t payload[N];
240 };
241 
242 #pragma pack(pop)
243 
244 } // namespace messages
245 } // namespace fusion_engine
246 } // 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:648
@ INTEGRITY_STATUS
Simulate a specified integrity status failure (intended for factory test purposes only).
@ 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