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
//
// Copyright (C) 2019 Kubos Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//! Data returned by `lastEpsError` query
use clyde_3g_eps_api::{ErrorCode, LastError};
/// Error variants which can be returned by the EPS
#[derive(Clone, Debug, GraphQLEnum)]
pub enum Error {
/// No errors were encountered
None,
/// CRC does not match data
BadCRC,
/// Unknown command received
UnknownCommand,
/// Supplied data incorrect when processing command
CommandDataIncorrect,
/// Selected channel does not exist
ChannelDoesNotExist,
/// Selected channel is currently inactive
ChannelInactive,
/// A reset had to occur
ResetOccurred,
/// There was an error with teh ADC acquisition
BadADCAcquisition,
/// Reading from EEPROM generated an error
FailReadingEEPROM,
/// Generic warning about an error on the internal SPI bus
InternalSPIError,
/// The command to fetch the last error failed
CommandError,
/// Catch all for future error values
UnknownError,
}
/// Last command status for the EPS
#[derive(Clone, Debug, GraphQLObject)]
pub struct ErrorData {
/// Last command status for the motherboard
pub motherboard: Error,
/// Last command status for the daughterboard
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 From<LastError> for ErrorData {
fn from(val: LastError) -> Self {
ErrorData {
motherboard: to_error(val.motherboard),
daughterboard: val.daughterboard.map(to_error),
}
}
}