1use crate::prelude::*;
5
6#[derive(Debug, Copy, Clone)]
8#[repr(u8)]
9pub enum SerializationError {
10 Unknown,
12 TailInvalid,
13 HeadInvalid,
14 TrackerDelimiterInvalid,
15 TofDelimiterInvalid,
16 StreamTooShort,
17 StreamTooLong,
18 ValueNotFound,
19 EventFragment,
20 UnknownPayload,
21 IncorrectPacketType,
22 WrongByteSize,
23 InvalidByte,
24 JsonDecodingError,
25 TomlDecodingError,
26 Disconnected,
27 ObjectNotFound,
28 UnsupportedVersion,
29 WrongProtocolVersion,
30 TooManyTrackerEvents,
31 TooManyTrackerHits,
32 DoesNotExist
33}
34
35impl SerializationError {
36 pub fn as_str(&self) -> &str {
37 match self {
38 SerializationError::Unknown => "Unknown",
39 SerializationError::TailInvalid => "TailInvalid",
40 SerializationError::HeadInvalid => "HeadInvalid",
41 SerializationError::TrackerDelimiterInvalid => "TrackerDelimiterInvalid",
42 SerializationError::TofDelimiterInvalid => "TofDelimiterInvalid",
43 SerializationError::StreamTooShort => "StreamTooShort",
44 SerializationError::StreamTooLong => "StreamTooLong",
45 SerializationError::ValueNotFound => "ValueNotFound",
46 SerializationError::EventFragment => "EventFragment",
47 SerializationError::UnknownPayload => "UnknownPayload",
48 SerializationError::IncorrectPacketType => "IncorrectPacketType",
49 SerializationError::WrongByteSize => "WrongByteSize",
50 SerializationError::InvalidByte => "InvalidByte",
51 SerializationError::JsonDecodingError => "JsonDecodingError",
52 SerializationError::TomlDecodingError => "TomlDecodingError",
53 SerializationError::Disconnected => "Disconnected",
54 SerializationError::ObjectNotFound => "ObjectNotFound",
55 SerializationError::UnsupportedVersion => "UnsupportedVersion",
56 SerializationError::WrongProtocolVersion => "WrongProtoclVersion",
57 SerializationError::TooManyTrackerEvents => "TooManyTrackerEvents",
58 SerializationError::TooManyTrackerHits => "TooManyTrackerHits",
59 SerializationError::DoesNotExist => "DoesNotExist"
60 }
61 }
62}
63
64impl fmt::Display for SerializationError {
65 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
66 write!(f, "<SerializationError : {}>", self.as_str())
67 }
68}
69
70impl Error for SerializationError {
71}
72
73#[derive(Debug, Copy, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
80#[repr(u8)]
81pub enum IPBusError {
82 DecodingFailed,
83 InvalidTransactionID,
84 InvalidPacketID,
85 NotAStatusPacket,
86 ConnectionTimeout,
87 UdpSendFailed,
88 UdpReceiveFailed
89}
90
91impl IPBusError {
92 pub fn to_string(&self) -> String {
93 match self {
94 IPBusError::DecodingFailed => String::from("DecodingFailed"),
95 IPBusError::InvalidTransactionID => String::from("InvalidTransactionID"),
96 IPBusError::InvalidPacketID => String::from("InvalidPacketID"),
97 IPBusError::NotAStatusPacket => String::from("NotAStatusPacket"),
98 IPBusError::ConnectionTimeout => String::from("ConnectionTimeout"),
99 IPBusError::UdpSendFailed => String::from("UdpSendFailed"),
100 IPBusError::UdpReceiveFailed => String::from("UdpReceiveFailed"),
101 }
102 }
103}
104
105impl fmt::Display for IPBusError {
106 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
107 write!(f, "<IPBusError: {}>", self.to_string())
108 }
109}
110
111impl Error for IPBusError {
112}
113
114#[derive(Debug, Copy, Clone)]
118#[repr(u8)]
119pub enum WaveformError {
120 TimeIndexOutOfBounds,
121 TimesTooSmall,
122 NegativeLowerBound,
123 OutOfRangeUpperBound,
124 OutOfRangeLowerBound,
125 DidNotCrossThreshold,
126 TooSpiky,
127}
128
129impl fmt::Display for WaveformError {
130 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
131 let disp : &str;
132 match self {
133 Self::TimeIndexOutOfBounds => { disp = "TimeIndexOutOfBounds"}
134 Self::TimesTooSmall => { disp = "TimesTooSmall"}
135 Self::NegativeLowerBound => { disp = "NegativeLowerBound"}
136 Self::OutOfRangeUpperBound => { disp = "OutOfRangeUpperBound"}
137 Self::OutOfRangeLowerBound => { disp = "OutOfRangeLowerBound"} ,
138 Self::DidNotCrossThreshold => { disp = "DidNotCrossThreshold"}
139 Self::TooSpiky => { disp = "TooSpiky"}
140 }
141 write!(f, "<WaveformError: {}>", disp)
142 }
143}
144
145impl Error for WaveformError {
146}
147
148#[derive(Debug, Copy, Clone)]
151#[repr(u8)]
152pub enum CalibrationError {
153 EmptyInputData,
154 CanNotConnectToMyOwnZMQSocket,
155 CalibrationFailed,
156 WrongBoardId,
157 IncompatibleFlightCalibrations,
158 StripIdInvalid,
159 NoStripMaskAvailable,
160 NoPedestalAvailable,
161 NoTransferFnAvailable,
162}
163
164impl fmt::Display for CalibrationError {
165 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
166 let repr : &str;
167 match self {
168 Self::EmptyInputData => { repr = "EmptyInputData"},
169 Self::CanNotConnectToMyOwnZMQSocket => { repr = "CanNotConnectToMyOwnZMQSocket"},
170 Self::CalibrationFailed => { repr = "CalibrationFailed"},
171 Self::WrongBoardId => { repr = "WrongBoardId"},
172 Self::IncompatibleFlightCalibrations => { repr = "IncompatibleFlightCalibrations"},
173 Self::StripIdInvalid => { repr = "StripIdInvalid"},
174 Self::NoTransferFnAvailable => { repr = "NoTransferFnAvailable"},
175 Self::NoStripMaskAvailable => { repr = "NoStripMaskAvailable"},
176 Self::NoPedestalAvailable => { repr = "NoPedestalAvailable"},
177 }
178 write!(f, "<CalibrationError : {}>", repr)
179 }
180}
181
182impl Error for CalibrationError {
183}
184
185#[derive(Debug,Copy,Clone)]
188#[repr(u8)]
189pub enum UserError {
190 IneligibleChannelLabel,
191 NoChannel9Data,
192 WrongPaddleId
193}
194
195impl fmt::Display for UserError {
196 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
197 let disp : &str;
198 match self {
199 UserError::IneligibleChannelLabel => {
200 disp = "IneligibleChannelLabel";
201 }
202 UserError::NoChannel9Data => {
203 disp = "NoChannel9Data";
204 }
205 UserError::WrongPaddleId => {
206 disp = "WrongPaddleId";
207 }
208 }
209 write!(f, "<UserError : {}>", disp)
210 }
211}
212
213impl Error for UserError {
214}
215
216#[derive(Debug,Copy,Clone)]
219#[repr(u8)]
220pub enum AnalysisError {
221 MissingChannel,
222 NoChannel9,
223 InputBroken,
224 DataMangling,
225 OutOfBounds,
226 DidNotConverge
227}
228
229impl fmt::Display for AnalysisError {
230 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
231 let disp : &str;
232 match self {
233 Self::MissingChannel => {disp = "MissingChannel"},
234 Self::NoChannel9 => {disp = "NoChannel9"},
235 Self::InputBroken => {disp = "InputBroken"},
236 Self::DataMangling => {disp = "DataMangling"},
237 Self::DidNotConverge => {disp = "DidNotConverge"},
238 Self::OutOfBounds => {disp = "OutOfBounds"}
239 }
240 write!(f, "<AnalysisError : {}>", disp)
241 }
242}
243
244impl Error for AnalysisError {
245}
246
247#[derive(Debug, Copy, Clone)]
250#[repr(u8)]
251pub enum SensorError {
252 ReadoutError,
253}
254
255impl fmt::Display for SensorError {
256 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
257 let disp : &str;
258 match self {
259 SensorError::ReadoutError => {disp = "ReadoutError"},
260 }
261 write!(f, "<SensorError : {}>", disp)
262 }
263}
264
265impl Error for SensorError {
266}
267
268#[derive(Debug, Copy, Clone, serde::Deserialize, serde::Serialize)]
271#[repr(u8)]
272pub enum StagingError {
273 NoCurrentConfig,
274 QueueEmpty,
275}
276
277impl fmt::Display for StagingError {
278 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
279 let disp : &str;
280 match self {
281 StagingError::NoCurrentConfig => {disp = "NoCurrentConfig"}
282 StagingError::QueueEmpty => {disp = "QueueEmpty"}
283 }
284 write!(f, "<StagingError : {}>", disp)
285 }
286}
287
288impl Error for StagingError {
289}
290
291#[derive(Debug, Copy, Clone, serde::Deserialize, serde::Serialize)]
294#[repr(u8)]
295pub enum TofError {
296 CanNotConnect,
297}
298
299impl fmt::Display for TofError {
300 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
301 let disp : &str;
302 match self {
303 TofError::CanNotConnect => {disp = "CanNotConnect";}
304 }
305 write!(f, "<TofError : {}>", disp)
306 }
307}
308
309impl Error for TofError {
310}
311
312#[derive(Debug, Copy, Clone)]
336#[repr(u8)]
337pub enum RunError {
338 EmptyInputData,
339 CanNotConnectToMyOwnZMQSocket
340}
341
342impl fmt::Display for RunError {
343 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
344 let disp : &str;
345 match self {
346 RunError::EmptyInputData => {disp = "EmptyInputData"},
347 RunError::CanNotConnectToMyOwnZMQSocket => {disp = "CanNotConnectToMyOwnZMQSocket"},
348 }
349 write!(f, "<RunError : {}>", disp)
350 }
351}
352
353
354impl Error for RunError {
355}
356
357#[derive(Debug, Copy, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
360#[repr(u8)]
361pub enum MasterTriggerError {
362 Unknown,
363 EventQueueEmpty,
364 MaskTooLarge,
365 BrokenPackage,
366 DAQNotAvailable,
367 PackageFormatIncorrect,
368 PackageHeaderIncorrect,
369 PackageFooterIncorrect,
370 FailedOperation,
371 UdpTimeOut,
372 DataTooShort
373}
374
375impl fmt::Display for MasterTriggerError {
376 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
377 let disp = serde_json::to_string(self).unwrap_or(
378 String::from("Error: cannot unwrap this MasterTriggerError"));
379 write!(f, "<MasterTriggerError : {}>", disp)
380 }
381}
382
383impl Error for MasterTriggerError {
384}
385
386impl From<Box<dyn std::error::Error>> for MasterTriggerError {
388 fn from(err: Box<dyn std::error::Error>) -> Self {
389 error!("Converting {err} to MasterTriggerError! Exact error type might be incorrect!");
390 MasterTriggerError::FailedOperation
391 }
392}
393
394