use core::fmt;
use crate::gatt::Characteristic;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ParseError {
Length {
characteristic: Characteristic,
actual: usize,
},
EegFrameType(u8),
EegUnsequenced,
PpgTags {
sample: usize,
},
EmptyResponse,
ResponseLength {
opcode: u8,
actual: usize,
},
UnknownCharacteristic,
}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Length { characteristic, actual } => {
write!(f, "unsupported {characteristic:?} payload length {actual}")
}
Self::EegFrameType(t) => write!(f, "unsupported EEG frame type {t}"),
Self::EegUnsequenced => write!(f, "EEG frame without sequence byte"),
Self::PpgTags { sample } => write!(f, "PPG sample {sample} does not carry tags 1, 2 and 3"),
Self::EmptyResponse => write!(f, "empty command response"),
Self::ResponseLength { opcode, actual } => {
write!(f, "response to 0x{opcode:02x} has unexpected payload length {actual}")
}
Self::UnknownCharacteristic => write!(f, "notification on an unknown characteristic"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for ParseError {}