1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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>;