1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use clyde_3g_eps_api::{ErrorCode, LastError};
#[derive(Clone, Debug, GraphQLEnum)]
pub enum Error {
None,
BadCRC,
UnknownCommand,
CommandDataIncorrect,
ChannelDoesNotExist,
ChannelInactive,
ResetOccurred,
BadADCAcquisition,
FailReadingEEPROM,
InternalSPIError,
CommandError,
UnknownError,
}
#[derive(Clone, Debug, GraphQLObject)]
pub struct ErrorData {
pub motherboard: Error,
pub daughterboard: Option<Error>,
}
fn to_error(error_code: ErrorCode) -> Error {
match error_code {
ErrorCode::None => Error::None,
ErrorCode::UnknownCommand => Error::UnknownCommand,
ErrorCode::CommandDataIncorrect => Error::CommandDataIncorrect,
ErrorCode::ChannelDoesNotExist => Error::ChannelDoesNotExist,
ErrorCode::ChannelInactive => Error::ChannelInactive,
ErrorCode::BadCRC => Error::BadCRC,
ErrorCode::ResetOccurred => Error::ResetOccurred,
ErrorCode::BadADCAcquisition => Error::BadADCAcquisition,
ErrorCode::FailReadingEEPROM => Error::FailReadingEEPROM,
ErrorCode::InternalSPIError => Error::InternalSPIError,
ErrorCode::CommandError => Error::CommandError,
ErrorCode::UnknownError => Error::UnknownError,
}
}
impl Into<ErrorData> for LastError {
fn into(self) -> ErrorData {
ErrorData {
motherboard: to_error(self.motherboard),
daughterboard: self.daughterboard.map(to_error),
}
}
}