use core::fmt;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum MavlinkError {
FrameTooShort,
BadMagic(u8),
Truncated,
CrcMismatch {
expected: u16,
found: u16,
},
UnknownMessage(u32),
PayloadTooLong,
Unsigned,
BadSignature,
ReplayedTimestamp,
BadPayload,
UnknownField,
UnknownFieldType,
DuplicateField,
FieldTypeMismatch,
FieldIndexOutOfRange,
ValueOutOfRange,
Closed,
}
impl fmt::Display for MavlinkError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::FrameTooShort => f.write_str("frame is shorter than a valid frame"),
Self::BadMagic(byte) => write!(f, "unrecognized start marker: {byte:#04x}"),
Self::Truncated => f.write_str("frame is shorter than its length field promises"),
Self::CrcMismatch { expected, found } => {
write!(
f,
"checksum mismatch: expected {expected:#06x}, found {found:#06x}"
)
}
Self::UnknownMessage(id) => write!(f, "no CRC_EXTRA known for message id {id}"),
Self::PayloadTooLong => f.write_str("payload exceeds the maximum frame size"),
Self::Unsigned => f.write_str("frame is not signed"),
Self::BadSignature => f.write_str("signature does not verify"),
Self::ReplayedTimestamp => f.write_str("signing timestamp is too old"),
Self::BadPayload => f.write_str("payload does not match the message layout"),
Self::UnknownField => f.write_str("message has no field of that name"),
Self::UnknownFieldType => f.write_str("unrecognized MAVLink field type"),
Self::DuplicateField => f.write_str("message names the same field twice"),
Self::FieldTypeMismatch => f.write_str("field is not of the requested kind"),
Self::FieldIndexOutOfRange => f.write_str("array index is past the end of the field"),
Self::ValueOutOfRange => f.write_str("value does not fit the field type"),
Self::Closed => f.write_str("link reached end of input"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for MavlinkError {}
pub type Result<T> = core::result::Result<T, MavlinkError>;