firewire_fireworks_protocols/
transport.rs1use super::*;
10
11const CATEGORY_TRANSPORT: u32 = 2;
12
13const CMD_SET_TRANSMIT_MODE: u32 = 0;
14
15#[derive(Debug, Copy, Clone, PartialEq, Eq)]
17pub enum TxPacketFormat {
18 Unique,
20 Iec61883,
22}
23
24impl Default for TxPacketFormat {
25 fn default() -> Self {
26 Self::Iec61883
27 }
28}
29
30fn serialize_tx_packet_format(fmt: &TxPacketFormat) -> u32 {
31 match fmt {
32 TxPacketFormat::Unique => 0,
33 TxPacketFormat::Iec61883 => 1,
34 }
35}
36
37#[cfg(test)]
38fn deserialize_tx_packet_format(fmt: &mut TxPacketFormat, val: u32) {
39 *fmt = match val {
40 1 => TxPacketFormat::Iec61883,
41 _ => TxPacketFormat::Unique,
42 };
43}
44
45impl<O, P> EfwWhollyUpdatableParamsOperation<P, TxPacketFormat> for O
46where
47 O: EfwHardwareSpecification,
48 P: EfwProtocolExtManual,
49{
50 fn update_wholly(proto: &mut P, states: &TxPacketFormat, timeout_ms: u32) -> Result<(), Error> {
51 assert!(Self::CAPABILITIES
52 .iter()
53 .find(|cap| HwCap::ChangeableRespAddr.eq(cap))
54 .is_some());
55
56 let args = [serialize_tx_packet_format(states)];
57 let mut params = Vec::new();
58 proto.transaction(
59 CATEGORY_TRANSPORT,
60 CMD_SET_TRANSMIT_MODE,
61 &args,
62 &mut params,
63 timeout_ms,
64 )
65 }
66}
67
68#[cfg(test)]
69mod test {
70 use super::*;
71
72 #[test]
73 fn tx_packet_format_serdes() {
74 [TxPacketFormat::Unique, TxPacketFormat::Iec61883]
75 .iter()
76 .for_each(|fmt| {
77 let val = serialize_tx_packet_format(fmt);
78 let mut f = TxPacketFormat::default();
79 deserialize_tx_packet_format(&mut f, val);
80 assert_eq!(*fmt, f);
81 });
82 }
83}