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
use deku::prelude::*;

use crate::transport;

use super::{Address, AddressType, NlsMethod};

#[derive(DekuRead, DekuWrite, Default, Debug, Clone, PartialEq)]
pub struct Control {
    #[deku(bits = 1)]
    has_no_origin_access_id: bool,
    #[deku(bits = 1)]
    has_hopping: bool,

    origin_address_type: AddressType,

    #[deku(pad_bits_before = "1")]
    nls_method: NlsMethod,
}

#[derive(DekuRead, DekuWrite, Default, Debug, Clone, PartialEq)]
pub struct HoppingControl {
    /// Hopping counter for no-hop and one-hop routing.
    #[deku(bits = 1, pad_bits_before = "1")]
    hop_counter: bool,

    #[deku(pad_bits_after = "4")]
    destination_address_type: AddressType,
}

#[derive(DekuRead, DekuWrite, Default, Debug, Clone, PartialEq)]
#[deku(ctx = "command_length: u32", ctx_default = "u32::MAX")]
pub struct Frame {
    control: Control,

    #[deku(cond = "control.has_hopping")]
    hopping_control: Option<HoppingControl>,

    origin_access_class: u8,

    #[deku(ctx = "control.origin_address_type")]
    origin_access_adress: Address,

    #[deku(ctx = "command_length")]
    frame: transport::Frame,
}