timex_datalink/protocol_3/
mod.rs

1//! Protocol 3 implementation for Timex Datalink watches.
2
3pub mod sync;
4pub mod start;
5pub mod time;
6pub mod alarm;
7pub mod end;
8pub mod sound_options;
9pub mod sound_theme;
10pub mod eeprom;
11pub mod wrist_app;
12
13pub use sync::Sync;
14pub use start::Start;
15pub use time::Time;
16pub use alarm::Alarm;
17pub use end::End;
18pub use sound_options::SoundOptions;
19pub use sound_theme::SoundTheme;
20pub use eeprom::Eeprom;
21pub use wrist_app::WristApp;
22
23use crate::PacketGenerator;
24
25/// Main Protocol 3 structure
26///
27/// This struct acts as a container for all Protocol 3 models that implement
28/// the PacketGenerator trait. It collects and orders packets from all models
29/// for transmission to the Timex Datalink watch.
30pub struct Protocol3 {
31    /// Collection of models that implement PacketGenerator
32    models: Vec<Box<dyn PacketGenerator>>,
33}
34
35impl Protocol3 {
36    /// Create a new empty Protocol3 instance
37    pub fn new() -> Self {
38        Protocol3 {
39            models: Vec::new()
40        }
41    }
42    
43    /// Add a model to the protocol
44    pub fn add<T: PacketGenerator + 'static>(&mut self, model: T) {
45        self.models.push(Box::new(model));
46    }
47}
48
49impl PacketGenerator for Protocol3 {
50    fn packets(&self) -> Vec<Vec<u8>> {
51        self.models.iter()
52            .flat_map(|model| model.packets())
53            .collect()
54    }
55}