Skip to main content

zigbee_core/nwk/frame/command/
link_status.rs

1use zigbee_macros::impl_byte;
2use zigbee_types::ShortAddress;
3use zigbee_types::TypeArrayCtx;
4use zigbee_types::TypeArrayRef;
5
6impl_byte! {
7    /// Link Status Command Frame
8    #[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    /// Link Status Command Options
19    #[derive(Debug, Clone, Copy, Eq, PartialEq)]
20    pub struct CommandOptions(pub u8);
21}
22
23impl CommandOptions {
24    /// Entry count
25    pub fn entry_count(&self) -> u8 {
26        (self.0 & mask::ENTRY_COUNT) >> offset::ENTRY_COUNT
27    }
28
29    /// Sets the Entry count
30    #[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    /// First frame
37    pub fn first_frame(&self) -> bool {
38        (self.0 & mask::FIRST_FRAME) != 0
39    }
40
41    /// Sets the First frame
42    #[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    /// Last frame
49    pub fn last_frame(&self) -> bool {
50        (self.0 & mask::LAST_FRAME) != 0
51    }
52
53    /// Sets the Last frame
54    #[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    /// Neighbor Table Entry
75    #[derive(Debug, Clone)]
76    #[repr(packed, Rust)]
77    pub struct LinkStatusEntry {
78        pub neighbor_address: ShortAddress,
79        pub link_status: u8,
80    }
81}