zigbee_core/nwk/frame/command/
link_status.rs1use zigbee_macros::impl_byte;
2use zigbee_types::ShortAddress;
3use zigbee_types::TypeArrayCtx;
4use zigbee_types::TypeArrayRef;
5
6impl_byte! {
7 #[derive(Debug, Clone)]
9 pub struct LinkStatus<'a> {
10 pub command_options: CommandOptions,
11 #[ctx = TypeArrayCtx::Len(usize::from(command_options.entry_count()))]
12 #[ctx_write = ()]
13 pub entries: TypeArrayRef<'a, LinkStatusEntry>,
14 }
15}
16
17impl_byte! {
18 #[derive(Debug, Clone, Copy, Eq, PartialEq)]
20 pub struct CommandOptions(pub u8);
21}
22
23impl CommandOptions {
24 pub fn entry_count(&self) -> u8 {
26 (self.0 & mask::ENTRY_COUNT) >> offset::ENTRY_COUNT
27 }
28
29 #[must_use]
31 pub fn set_entry_count(mut self, value: u8) -> Self {
32 self.0 = (self.0 & !mask::ENTRY_COUNT) | (value << offset::ENTRY_COUNT);
33 self
34 }
35
36 pub fn first_frame(&self) -> bool {
38 (self.0 & mask::FIRST_FRAME) != 0
39 }
40
41 #[must_use]
43 pub fn set_first_frame(mut self, value: bool) -> Self {
44 self.0 = (self.0 & !mask::FIRST_FRAME) | (u8::from(value) << offset::FIRST_FRAME);
45 self
46 }
47
48 pub fn last_frame(&self) -> bool {
50 (self.0 & mask::LAST_FRAME) != 0
51 }
52
53 #[must_use]
55 pub fn set_last_frame(mut self, value: bool) -> Self {
56 self.0 = (self.0 & !mask::LAST_FRAME) | (u8::from(value) << offset::LAST_FRAME);
57 self
58 }
59}
60
61mod offset {
62 pub const ENTRY_COUNT: u8 = 0;
63 pub const FIRST_FRAME: u8 = 4;
64 pub const LAST_FRAME: u8 = 5;
65}
66
67mod mask {
68 pub const ENTRY_COUNT: u8 = 0b0000_1111;
69 pub const FIRST_FRAME: u8 = 0b0001_0000;
70 pub const LAST_FRAME: u8 = 0b0010_0000;
71}
72
73impl_byte! {
74 #[derive(Debug, Clone)]
76 #[repr(packed, Rust)]
77 pub struct LinkStatusEntry {
78 pub neighbor_address: ShortAddress,
79 pub link_status: u8,
80 }
81}