uds_client/uds_client/
pci.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3pub enum PciType {
4 SingleFrame, FirstFrame, ConsecutiveFrame, FlowControl, }
9
10#[derive(Debug, Clone, Copy)]
11pub struct PciByte {
12 pub pci_type: PciType,
13 pub value: u8, }
15
16impl From<PciByte> for u8 {
17 fn from(pci_byte: PciByte) -> Self {
18 match pci_byte.pci_type {
19 PciType::SingleFrame => pci_byte.value & 0x0F,
20 PciType::FirstFrame => 0x10 | (pci_byte.value & 0x0F),
21 PciType::ConsecutiveFrame => 0x20 | (pci_byte.value & 0x0F),
22 PciType::FlowControl => 0x30 | (pci_byte.value & 0x0F),
23 }
24 }
25}
26
27impl PciByte {
29 pub fn new(pci_type: PciType, value: u8) -> Self {
30 Self { pci_type, value }
31 }
32
33 pub fn get_type(&self) -> PciType {
34 self.pci_type
35 }
36
37 pub fn get_value(&self) -> u8 {
38 self.value
39 }
40
41 pub fn as_byte(&self) -> u8 {
42 match self.pci_type {
43 PciType::SingleFrame => self.value & 0x0F,
44 PciType::FirstFrame => 0x10 | (self.value & 0x0F),
45 PciType::ConsecutiveFrame => 0x20 | (self.value & 0x0F),
46 PciType::FlowControl => 0x30 | (self.value & 0x0F),
47 }
48 }
49}