
use thiserror::Error;

#[derive(Error, Debug)]
pub enum MailboxError {

    #[error("Mailbox timeout on slave {slave}")]
    Timeout { slave: u16 },

    #[error("Mailbox cancelled")]
    Cancelled,

    #[error("Mailbox protocol error on slave {slave}: code 0x{error_code:X}")]
    Protocol { slave: u16, error_code: u32 },

    #[error("SDO abort on slave {slave}: 0x{abort_code:08X}")]
    CoEAbort { slave: u16, abort_code: u32 },

    #[error("FoE error on slave {slave}: code 0x{error_code:X}")]
    FoEError { slave: u16, error_code: u32 },

    #[error("Invalid argument")]
    InvalidArgument,

    #[error("Unknown error: {0}")]
    Other(String),
}

pub type MailboxResult<T> = Result<T, MailboxError>;
