extern crate serialport;
use std::error::Error as StdError;
use std::fmt;
pub mod communicator;
pub mod eep;
pub mod enocean;
type ParseEspResult<T> = std::result::Result<T, ParseEspError>;
#[derive(Debug, Clone)]
pub struct ParseEspError {
pub kind: ParseEspErrorKind,
pub message: String,
pub byte_index: Option<i16>,
pub packet: Vec<u8>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ParseEspErrorKind {
NoSyncByte,
CrcMismatch,
IncompleteMessage,
Unimplemented,
}
impl fmt::Display for ParseEspError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.byte_index {
Some(bi) => write!(
f,
"{:?} error :{} in {:x?} at index {}",
self.kind, self.message, self.packet, bi
),
_ => write!(
f,
"{:?} error :{} in packet {:x?}",
self.kind, self.message, self.packet
),
}
}
}
impl StdError for ParseEspError {
fn description(&self) -> &str {
&self.message
}
}
type EnoceanMessage = Vec<u8>;