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
//! Ember concentrator parameters.
use core::num::TryFromIntError;
use core::time::Duration;
use le_stream::{FromLeStream, ToLeStream};
/// Concentrator parameters.
#[derive(Clone, Debug, Default, Eq, PartialEq, FromLeStream, ToLeStream)]
pub struct Parameters {
concentrator_type: u16,
min_time: u16,
max_time: u16,
route_error_threshold: u8,
delivery_failure_threshold: u8,
max_hops: u8,
}
impl Parameters {
/// Create a new `Parameters` instance.
///
/// # Errors
/// Returns a [`TryFromIntError`] if the `min_time` or `max_time` values are too large to fit.
pub fn new(
concentrator_type: Type,
min_time: Duration,
max_time: Duration,
route_error_threshold: u8,
delivery_failure_threshold: u8,
max_hops: u8,
) -> Result<Self, TryFromIntError> {
Ok(Self {
concentrator_type: concentrator_type as u16,
min_time: min_time.as_secs().try_into()?,
max_time: max_time.as_secs().try_into()?,
route_error_threshold,
delivery_failure_threshold,
max_hops,
})
}
}
/// Ember concentrator type.
#[derive(Clone, Debug, Eq, PartialEq)]
#[repr(u16)]
pub enum Type {
/// A concentrator with insufficient memory to store source routes for the entire network.
///
/// Route records are sent to the concentrator prior to every inbound APS unicast.
LowRam = 0xFFF8,
/// A concentrator with sufficient memory to store source routes for the entire network.
///
/// Remote nodes stop sending route records once the concentrator has successfully received one.
HighRam = 0xFFF9,
}