modality_trace_recorder_plugin/streaming/
command.rs1use derive_more::Display;
2
3#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Display)]
5pub enum Command {
6 #[display(fmt = "Start")]
8 Start,
9 #[display(fmt = "Stop")]
11 Stop,
12}
13
14impl Command {
15 pub const WIRE_SIZE: usize = 8;
17
18 const CMD_SET_ACTIVE: u8 = 1;
20
21 fn param1(&self) -> u8 {
22 match self {
23 Command::Start => 1,
24 Command::Stop => 0,
25 }
26 }
27
28 fn checksum(&self) -> u16 {
29 let sum: u16 = u16::from(Self::CMD_SET_ACTIVE)
30 + u16::from(self.param1());
32 0xFFFF_u16.wrapping_sub(sum)
33 }
34
35 pub fn to_le_bytes(&self) -> [u8; Self::WIRE_SIZE] {
37 let checksum_bytes = self.checksum().to_le_bytes();
38 [
39 Self::CMD_SET_ACTIVE,
40 self.param1(),
41 0,
42 0,
43 0,
44 0,
45 checksum_bytes[0],
46 checksum_bytes[1],
47 ]
48 }
49}