timex_datalink/protocol_3/
sound_options.rs1use crate::PacketGenerator;
6use crate::helpers::crc_packets_wrapper;
7
8pub struct SoundOptions {
12 pub hourly_chime: bool,
14
15 pub button_beep: bool,
17}
18
19impl PacketGenerator for SoundOptions {
20 fn packets(&self) -> Vec<Vec<u8>> {
21 const CPACKET_BEEPS: u8 = 0x71;
23
24 let mut raw_packet = Vec::with_capacity(3);
26 raw_packet.push(CPACKET_BEEPS);
27 raw_packet.push(if self.hourly_chime { 1 } else { 0 });
28 raw_packet.push(if self.button_beep { 1 } else { 0 });
29
30 crc_packets_wrapper::wrap_packets_with_crc(vec![raw_packet])
32 }
33}
34
35#[cfg(test)]
36mod tests {
37 use super::*;
38
39 #[test]
40 fn test_sound_options() {
41 let sound_options = SoundOptions {
42 hourly_chime: true,
43 button_beep: false,
44 };
45
46 let expected = vec![vec![6, 113, 1, 0, 3, 81]];
48
49 assert_eq!(sound_options.packets(), expected);
50 }
51}