use std::{fmt, path::PathBuf};
use failure::Fail;
use crate::STATE_FILE;
#[derive(Debug, Clone, Copy, Fail)]
pub enum Logic {
#[fail(display = "there was an error during the initialization")]
Init,
}
#[cfg(feature = "gps")]
#[derive(Debug, Clone, Fail)]
pub enum Gps {
#[fail(display = "an error occurred trying to initialize the GPS module")]
Init,
#[fail(display = "the GPS was already initialized when OpenStratos tried to initialize it")]
AlreadyInitialized,
#[fail(display = "invalid GPS status: '{}'", status)]
InvalidStatus {
status: String,
},
}
#[derive(Debug, Fail)]
pub enum Config {
Open {
path: PathBuf,
},
Read {
path: PathBuf,
},
InvalidToml {
path: PathBuf,
},
Invalid {
errors: String,
},
}
impl fmt::Display for Config {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Config::Open { path } => write!(
f,
"error opening the configuration file at '{}'",
path.display()
),
Config::Read { path } => write!(
f,
"error reading the configuration file at '{}'",
path.display()
),
Config::InvalidToml { path } => write!(
f,
"invalid TOML found in the configuration file at '{}'",
path.display()
),
Config::Invalid { errors } => write!(f, "the configuration is invalid:\n{}", errors),
}
}
}
#[derive(Debug, Fail)]
pub enum Fs {
DataInit,
DirectoryCreation {
path: PathBuf,
},
}
impl fmt::Display for Fs {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Fs::DataInit => write!(f, "error initializing the 'data' directory"),
Fs::DirectoryCreation { path } => {
write!(f, "could not create directory '{}'", path.display())
}
}
}
}
#[derive(Debug, Clone, Copy, Fail)]
pub enum Log {
#[fail(display = "error creating the `{}` appender", name)]
Appender {
name: &'static str,
},
#[fail(display = "error building the logger")]
Build,
}
#[derive(Debug, Clone, Fail)]
pub enum LastState {
FileOpen,
FileRead,
FileWrite,
Read,
Invalid {
state: String,
},
}
impl fmt::Display for LastState {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
LastState::FileOpen => {
write!(f, "error opening the last state file at '{}'", STATE_FILE)
}
LastState::FileRead => {
write!(f, "error reading the last state file at '{}'", STATE_FILE)
}
LastState::FileWrite => {
write!(f, "error writing the last state file at '{}'", STATE_FILE)
}
LastState::Read => write!(f, "error reading the last state from '{}'", STATE_FILE),
LastState::Invalid { state } => write!(f, "the last state '{}' is invalid", state),
}
}
}
#[cfg(feature = "fona")]
#[derive(Debug, Fail)]
pub enum Fona {
#[fail(display = "there was an error during the initialization of the FONA module")]
Init,
#[fail(display = "the FONA module did not turn on")]
PowerOn,
#[fail(display = "there was an error turning the FONA 'echo' off")]
EchoOff,
#[fail(
display = "there was no open serial connection when trying to send a command to the \
FONA module"
)]
NoSerial,
#[fail(display = "EOF was found when reading the FONA serial")]
SerialEnd,
#[fail(display = "SMS was longer than the 160 character limit")]
LongSms,
#[fail(display = "error sending SMS on `AT+CMGF=1` response")]
SmsAtCmgf,
#[fail(display = "error sending AT+CMGS message sending SMS")]
SmsAtCmgs,
#[fail(display = "error reading +CMGS response sending SMS")]
SmsCmgs,
#[fail(display = "no OK received after sending SMS")]
SmsOk,
#[fail(display = "error getting location on `AT+CMGF=1` response")]
LocAtCmgf,
#[fail(display = "error getting location on `AT+CGATT=1` response")]
LocAtCgatt,
#[fail(display = "Error getting location on `AT+SAPBR=1,1` response.")]
LocAtSapbr,
#[fail(display = "Error getting location on `AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"` response.")]
LocAtSapbrContype,
#[fail(
display = "Error getting location on `AT+SAPBR=3,1,\"APN\",\"{{fona.location_service}}\"` response."
)]
LocAtSapbrApn,
#[fail(display = "Error getting location on `AT+CIPGSMLOC=1,1` response.")]
LocAtCipgsmloc,
#[fail(display = "error turning GPRS down")]
LocAtGprsDown,
#[fail(display = "error getting longitude via GPRS")]
LocLon,
#[fail(display = "error getting latitude via GPRS")]
LocLat,
#[fail(
display = "an error occurred when trying to read CRLF (\\r\\n) after sending command to \
FONA"
)]
SendCommandCrlf,
#[fail(display = "FONA returned a partial response: `{}`", response)]
PartialResponse {
response: String,
},
#[fail(display = "there was a I/O error when trying to send a command to the FONA module")]
Command,
#[fail(display = "FONA returned an invalid response to AT+CBC")]
CBCInvalidResponse,
#[fail(display = "FONA returned an invalid response to AT+CADC?")]
CADCInvalidResponse,
}
#[cfg(feature = "raspicam")]
#[derive(Debug, Fail)]
pub enum Raspicam {
AlreadyRecording,
FileExists {
file: PathBuf,
},
Test,
TestRemove {
test_file: PathBuf,
},
}
#[cfg(feature = "raspicam")]
impl fmt::Display for Raspicam {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Raspicam::AlreadyRecording => write!(f, "the camera was already recording"),
Raspicam::FileExists { file } => write!(
f,
"the output file {} for the camera already exists",
file.display()
),
Raspicam::Test => write!(f, "an error occurred when trying to test the camera"),
Raspicam::TestRemove { test_file } => write!(
f,
"there was an error trying to remove the camera test file {}",
test_file.display()
),
}
}
}
#[cfg(any(feature = "fona", feature = "gps"))]
#[derive(Debug, Clone, Copy, Fail)]
pub enum Init {
#[cfg(feature = "gps")]
#[fail(display = "error initializing GPS module")]
Gps,
#[cfg(feature = "fona")]
#[fail(display = "error initializing FONA module")]
Fona,
#[cfg(feature = "fona")]
#[fail(display = "error checking GSM connectivity")]
CheckGsmConnectivity,
#[cfg(feature = "fona")]
#[fail(display = "error checking battery status")]
CheckBatteries,
#[cfg(feature = "fona")]
#[fail(display = "not enough battery for the flight")]
NotEnoughBattery,
}