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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
use std::error::Error;
mod config;
mod message;
#[cfg(feature = "async")]
mod async_impl;
#[cfg(feature = "async")]
pub use self::async_impl::{Blynk, Client, Event, Protocol};
#[cfg(not(feature = "async"))]
mod blocking;
#[cfg(not(feature = "async"))]
pub use self::blocking::{Blynk, Client, Event, Protocol};
pub use self::config::Config;
pub enum ConnectionState {
Disconnected,
Connecting,
Authentiacting,
Authenticated,
}
impl Default for ConnectionState {
fn default() -> Self {
ConnectionState::Disconnected
}
}
mod conf {
use std::time::Duration;
pub const SOCK_MAX_TIMEOUT: Duration = Duration::from_secs(5);
pub const SOCK_TIMEOUT: Duration = Duration::from_millis(1000);
pub const RETRIES_TX_DELAY: Duration = Duration::from_millis(2);
pub const RETRIES_TX_MAX_NUM: u8 = 3;
pub const RECONNECT_SLEEP: Duration = Duration::from_secs(1);
pub const HEARTBEAT_PERIOD: Duration = Duration::from_secs(5);
}
pub struct DefaultHandler {}
use std::result;
use std::{fmt, io};
#[derive(Debug)]
pub enum BlynkError {
Io(io::Error),
Dns,
MessageSend,
EmptyBuffer,
Redirection,
HeartbeatSet(message::ProtocolStatus),
InvalidAuthToken,
InvalidMessageId,
InvalidMessageHeader,
InvalidMessageBody,
StreamIsNone,
ReaderNotAvailable,
}
impl fmt::Display for BlynkError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
BlynkError::Io(ref err) => err.fmt(f),
BlynkError::Dns => write!(f, "Problem resolving host"),
BlynkError::MessageSend => write!(f, "Problem sending message"),
BlynkError::EmptyBuffer => write!(f, "No message to process"),
BlynkError::Redirection => write!(f, "Redirection problem"),
BlynkError::HeartbeatSet(ref ps) => write!(f, "Problem setting heartbeat {:?}", ps),
BlynkError::InvalidAuthToken => write!(f, "Invalid auth token"),
BlynkError::InvalidMessageId => write!(f, "Message id is zero"),
BlynkError::InvalidMessageHeader => write!(f, "Problem parsing message header"),
BlynkError::InvalidMessageBody => write!(f, "Malformed message body"),
BlynkError::StreamIsNone => write!(f, "Stream not available"),
BlynkError::ReaderNotAvailable => write!(f, "Unable to access reader"),
}
}
}
impl Error for BlynkError {}
impl From<io::Error> for BlynkError {
fn from(err: io::Error) -> BlynkError {
BlynkError::Io(err)
}
}
type Result<T> = result::Result<T, BlynkError>;