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