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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//! Beacon data structures.
use le_stream::{FromLeStream, ToLeStream};
use macaddr::MacAddr8;
use crate::ember::types::PanId;
/// Beacon data structure.
#[derive(Clone, Debug, Eq, PartialEq, FromLeStream, ToLeStream)]
pub struct Data {
channel: u8,
lqi: u8,
rssi: i8,
depth: u8,
nwk_update_id: u8,
power: i8,
parent_priority: i8,
pan_id: PanId,
extended_pan_id: MacAddr8,
sender: u16,
enhanced: bool,
permit_join: bool,
has_capacity: bool,
}
impl Data {
/// Create a new beacon data structure.
#[expect(clippy::too_many_arguments)]
#[must_use]
pub const fn new(
channel: u8,
lqi: u8,
rssi: i8,
depth: u8,
nwk_update_id: u8,
power: i8,
parent_priority: i8,
pan_id: PanId,
extended_pan_id: MacAddr8,
sender: u16,
enhanced: bool,
permit_join: bool,
has_capacity: bool,
) -> Self {
Self {
channel,
lqi,
rssi,
depth,
nwk_update_id,
power,
parent_priority,
pan_id,
extended_pan_id,
sender,
enhanced,
permit_join,
has_capacity,
}
}
/// Return the channel of the received beacon.
#[must_use]
pub const fn channel(&self) -> u8 {
self.channel
}
/// Return the LQI of the received beacon.
#[must_use]
pub const fn lqi(&self) -> u8 {
self.lqi
}
/// Return the RSSI of the received beacon.
#[must_use]
pub const fn rssi(&self) -> i8 {
self.rssi
}
/// Return the depth of the received beacon.
#[must_use]
pub const fn depth(&self) -> u8 {
self.depth
}
/// Return the network update ID of the received beacon.
#[must_use]
pub const fn nwk_update_id(&self) -> u8 {
self.nwk_update_id
}
/// Return the power level of the received beacon.
///
/// This field is valid only if the beacon is an enhanced beacon.
#[must_use]
pub const fn power(&self) -> Option<i8> {
if self.enhanced {
Some(self.power)
} else {
None
}
}
/// Return the TC connectivity and long uptime from capacity field.
#[must_use]
pub const fn parent_priority(&self) -> i8 {
self.parent_priority
}
/// Return the PAN ID of the received beacon.
#[must_use]
pub const fn pan_id(&self) -> PanId {
self.pan_id
}
/// Return the extended PAN ID of the received beacon.
#[must_use]
pub const fn extended_pan_id(&self) -> MacAddr8 {
self.extended_pan_id
}
/// Return the sender of the received beacon.
#[must_use]
pub const fn sender(&self) -> u16 {
self.sender
}
/// Return whether the beacon is enhanced.
#[must_use]
pub const fn enhanced(&self) -> bool {
self.enhanced
}
/// Return whether the beacon is advertising permit join.
#[must_use]
pub const fn permit_join(&self) -> bool {
self.permit_join
}
/// Return whether the beacon is advertising capacity.
#[must_use]
pub const fn has_capacity(&self) -> bool {
self.has_capacity
}
}
/// The parameters related to beacon prioritization.
#[derive(Clone, Debug, Eq, PartialEq, FromLeStream, ToLeStream)]
pub struct ClassificationParams {
min_rssi_for_receiving_pkts: i8,
beacon_classification_mask: u16,
}
impl ClassificationParams {
/// Create new classification parameters.
#[must_use]
pub const fn new(min_rssi_for_receiving_pkts: i8, beacon_classification_mask: u16) -> Self {
Self {
min_rssi_for_receiving_pkts,
beacon_classification_mask,
}
}
/// Return the minimum RSSI value for receiving packets that is used in some beacon
/// prioritization algorithms.
#[must_use]
pub const fn min_rssi_for_receiving_pkts(&self) -> i8 {
self.min_rssi_for_receiving_pkts
}
/// Return the beacon classification mask that identifies which beacon prioritization algorithm
/// to pick and defines the relevant parameters.
#[must_use]
pub const fn beacon_classification_mask(&self) -> u16 {
self.beacon_classification_mask
}
}
/// Defines an iterator that is used to loop over cached beacons.
#[derive(Clone, Debug, Eq, PartialEq, FromLeStream, ToLeStream)]
pub struct Iterator {
beacon: Data,
index: u8,
}
impl Iterator {
/// Create a new beacon iterator.
#[must_use]
pub const fn new(beacon: Data, index: u8) -> Self {
Self { beacon, index }
}
/// Return the retrieved beacon.
#[must_use]
pub const fn beacon(&self) -> &Data {
&self.beacon
}
/// Return the index of the retrieved beacon.
#[must_use]
pub const fn index(&self) -> u8 {
self.index
}
}