1use crate::prelude::*;
5
6#[derive(Debug, Copy, Clone)]
8#[repr(u8)]
9pub enum SerializationError {
10 TailInvalid,
12 HeadInvalid,
13 TrackerDelimiterInvalid,
14 TofDelimiterInvalid,
15 StreamTooShort,
16 StreamTooLong,
17 ValueNotFound,
18 EventFragment,
19 UnknownPayload,
20 IncorrectPacketType,
21 WrongByteSize,
22 JsonDecodingError,
23 TomlDecodingError,
24 Disconnected,
25 ObjectNotFound,
26 UnsupportedVersion,
27 WrongProtocolVersion
28}
29
30impl SerializationError {
31 pub fn as_str(&self) -> &str {
32 match self {
33 SerializationError::TailInvalid => "TailInvalid",
34 SerializationError::HeadInvalid => "HeadInvalid",
35 SerializationError::TrackerDelimiterInvalid => "TrackerDelimiterInvalid",
36 SerializationError::TofDelimiterInvalid => "TofDelimiterInvalid",
37 SerializationError::StreamTooShort => "StreamTooLong",
38 SerializationError::StreamTooLong => "StreamTooLong",
39 SerializationError::ValueNotFound => "ValueNotFound",
40 SerializationError::EventFragment => "EventFragment",
41 SerializationError::UnknownPayload => "UnknownPayload",
42 SerializationError::IncorrectPacketType => "IncorrectPacketType",
43 SerializationError::WrongByteSize => "WrongByteSize",
44 SerializationError::JsonDecodingError => "JsonDecodingError",
45 SerializationError::TomlDecodingError => "TomlDecodingError",
46 SerializationError::Disconnected => "Disconnected",
47 SerializationError::ObjectNotFound => "ObjectNotFound",
48 SerializationError::UnsupportedVersion => "UnsupportedVersion",
49 SerializationError::WrongProtocolVersion => "WrongProtoclVersion",
50 }
51 }
52}
53
54impl fmt::Display for SerializationError {
55 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
56 write!(f, "<SerializationError : {}>", self.as_str())
57 }
58}
59
60impl Error for SerializationError {
61}
62
63#[derive(Debug, Copy, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
70#[repr(u8)]
71pub enum IPBusError {
72 DecodingFailed,
73 InvalidTransactionID,
74 InvalidPacketID,
75 NotAStatusPacket,
76 ConnectionTimeout,
77 UdpSendFailed,
78 UdpReceiveFailed
79}
80
81impl IPBusError {
82 pub fn to_string(&self) -> String {
83 match self {
84 IPBusError::DecodingFailed => String::from("DecodingFailed"),
85 IPBusError::InvalidTransactionID => String::from("InvalidTransactionID"),
86 IPBusError::InvalidPacketID => String::from("InvalidPacketID"),
87 IPBusError::NotAStatusPacket => String::from("NotAStatusPacket"),
88 IPBusError::ConnectionTimeout => String::from("ConnectionTimeout"),
89 IPBusError::UdpSendFailed => String::from("UdpSendFailed"),
90 IPBusError::UdpReceiveFailed => String::from("UdpReceiveFailed"),
91 }
92 }
93}
94
95impl fmt::Display for IPBusError {
96 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
97 write!(f, "<IPBusError: {}>", self.to_string())
98 }
99}
100
101impl Error for IPBusError {
102}
103
104#[derive(Debug, Copy, Clone)]
108#[repr(u8)]
109pub enum WaveformError {
110 TimeIndexOutOfBounds,
111 TimesTooSmall,
112 NegativeLowerBound,
113 OutOfRangeUpperBound,
114 OutOfRangeLowerBound,
115 DidNotCrossThreshold,
116 TooSpiky,
117}
118
119impl fmt::Display for WaveformError {
120 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
121 let disp : &str;
122 match self {
123 Self::TimeIndexOutOfBounds => { disp = "TimeIndexOutOfBounds"}
124 Self::TimesTooSmall => { disp = "TimesTooSmall"}
125 Self::NegativeLowerBound => { disp = "NegativeLowerBound"}
126 Self::OutOfRangeUpperBound => { disp = "OutOfRangeUpperBound"}
127 Self::OutOfRangeLowerBound => { disp = "OutOfRangeLowerBound"} ,
128 Self::DidNotCrossThreshold => { disp = "DidNotCrossThreshold"}
129 Self::TooSpiky => { disp = "TooSpiky"}
130 }
131 write!(f, "<WaveformError: {}>", disp)
132 }
133}
134
135impl Error for WaveformError {
136}
137
138#[derive(Debug, Copy, Clone)]
141#[repr(u8)]
142pub enum CalibrationError {
143 EmptyInputData,
144 CanNotConnectToMyOwnZMQSocket,
145 CalibrationFailed,
146 WrongBoardId,
147 IncompatibleFlightCalibrations,
148}
149
150impl fmt::Display for CalibrationError {
151 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
152 let repr : &str;
153 match self {
154 Self::EmptyInputData => { repr = "EmptyInputData"},
155 Self::CanNotConnectToMyOwnZMQSocket => { repr = "CanNotConnectToMyOwnZMQSocket"},
156 Self::CalibrationFailed => { repr = "CalibrationFailed"},
157 Self::WrongBoardId => { repr = "WrongBoardId"},
158 Self::IncompatibleFlightCalibrations => { repr = "IncompatibleFlightCalibrations"},
159 }
160 write!(f, "<CalibrationError : {}>", repr)
161 }
162}
163
164impl Error for CalibrationError {
165}
166
167#[derive(Debug,Copy,Clone)]
170#[repr(u8)]
171pub enum UserError {
172 IneligibleChannelLabel,
173 NoChannel9Data,
174}
175
176impl fmt::Display for UserError {
177 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
178 let disp : &str;
179 match self {
180 UserError::IneligibleChannelLabel => {
181 disp = "IneligibleChannelLabel";
182 },
183 UserError::NoChannel9Data => {
184 disp = "NoChannel9Data";
185 },
186 }
187 write!(f, "<UserError : {}>", disp)
188 }
189}
190
191impl Error for UserError {
192}
193
194#[derive(Debug,Copy,Clone)]
197#[repr(u8)]
198pub enum AnalysisError {
199 MissingChannel,
200 NoChannel9,
201 InputBroken,
202 DataMangling
203}
204
205impl fmt::Display for AnalysisError {
206 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
207 let disp : &str;
208 match self {
209 AnalysisError::MissingChannel => {disp = "MissingChannel"},
210 AnalysisError::NoChannel9 => {disp = "NoChannel9"},
211 AnalysisError::InputBroken => {disp = "InputBroken"},
212 AnalysisError::DataMangling => {disp = "DataMangling"}
213
214 }
215 write!(f, "<AnalysisError : {}>", disp)
216 }
217}
218
219impl Error for AnalysisError {
220}
221
222#[derive(Debug, Copy, Clone)]
225#[repr(u8)]
226pub enum SensorError {
227 ReadoutError,
228}
229
230impl fmt::Display for SensorError {
231 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
232 let disp : &str;
233 match self {
234 SensorError::ReadoutError => {disp = "ReadoutError"},
235 }
236 write!(f, "<SensorError : {}>", disp)
237 }
238}
239
240impl Error for SensorError {
241}
242
243#[derive(Debug, Copy, Clone, serde::Deserialize, serde::Serialize)]
246#[repr(u8)]
247pub enum StagingError {
248 NoCurrentConfig,
249 QueueEmpty,
250}
251
252impl fmt::Display for StagingError {
253 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
254 let disp : &str;
255 match self {
256 StagingError::NoCurrentConfig => {disp = "NoCurrentConfig"}
257 StagingError::QueueEmpty => {disp = "QueueEmpty"}
258 }
259 write!(f, "<StagingError : {}>", disp)
260 }
261}
262
263impl Error for StagingError {
264}
265
266#[derive(Debug, Copy, Clone, serde::Deserialize, serde::Serialize)]
269#[repr(u8)]
270pub enum TofError {
271 CanNotConnect,
272}
273
274impl fmt::Display for TofError {
275 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
276 let disp : &str;
277 match self {
278 TofError::CanNotConnect => {disp = "CanNotConnect";}
279 }
280 write!(f, "<TofError : {}>", disp)
281 }
282}
283
284impl Error for TofError {
285}
286
287#[derive(Debug, Copy, Clone)]
311#[repr(u8)]
312pub enum RunError {
313 EmptyInputData,
314 CanNotConnectToMyOwnZMQSocket
315}
316
317impl fmt::Display for RunError {
318 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
319 let disp : &str;
320 match self {
321 RunError::EmptyInputData => {disp = "EmptyInputData"},
322 RunError::CanNotConnectToMyOwnZMQSocket => {disp = "CanNotConnectToMyOwnZMQSocket"},
323 }
324 write!(f, "<RunError : {}>", disp)
325 }
326}
327
328
329impl Error for RunError {
330}
331
332#[derive(Debug, Copy, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
335#[repr(u8)]
336pub enum MasterTriggerError {
337 Unknown,
338 EventQueueEmpty,
339 MaskTooLarge,
340 BrokenPackage,
341 DAQNotAvailable,
342 PackageFormatIncorrect,
343 PackageHeaderIncorrect,
344 PackageFooterIncorrect,
345 FailedOperation,
346 UdpTimeOut,
347 DataTooShort
348}
349
350impl fmt::Display for MasterTriggerError {
351 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
352 let disp = serde_json::to_string(self).unwrap_or(
353 String::from("Error: cannot unwrap this MasterTriggerError"));
354 write!(f, "<MasterTriggerError : {}>", disp)
355 }
356}
357
358impl Error for MasterTriggerError {
359}
360
361impl From<Box<dyn std::error::Error>> for MasterTriggerError {
363 fn from(err: Box<dyn std::error::Error>) -> Self {
364 error!("Converting {err} to MasterTriggerError! Exact error type might be incorrect!");
365 MasterTriggerError::FailedOperation
366 }
367}
368
369