pub struct NotebookAdapter {
pub serial_device: String,
pub byte_sleep: f32,
pub packet_sleep: f32,
pub verbose: bool,
}Expand description
Notebook adapter for sending data to Timex watches
This handles the serial communication with the watch, including timing constraints between bytes and packets.
Fields§
§serial_device: StringPath to the serial device
byte_sleep: f32Time to sleep after sending each byte (in seconds)
packet_sleep: f32Time to sleep after sending a packet (in seconds)
verbose: boolEnable verbose output
Implementations§
Source§impl NotebookAdapter
impl NotebookAdapter
Sourcepub const BYTE_SLEEP_DEFAULT: f32 = 0.0250000004f32
pub const BYTE_SLEEP_DEFAULT: f32 = 0.0250000004f32
Default time to sleep after sending a byte (in seconds)
Sourcepub const PACKET_SLEEP_DEFAULT: f32 = 0.25f32
pub const PACKET_SLEEP_DEFAULT: f32 = 0.25f32
Default time to sleep after sending a packet (in seconds)
Sourcepub fn new(
serial_device: String,
byte_sleep: Option<f32>,
packet_sleep: Option<f32>,
verbose: bool,
) -> Self
pub fn new( serial_device: String, byte_sleep: Option<f32>, packet_sleep: Option<f32>, verbose: bool, ) -> Self
Create a new NotebookAdapter with the given parameters
§Arguments
serial_device- Path to the serial devicebyte_sleep- Optional time to sleep after sending each byte (in seconds)packet_sleep- Optional time to sleep after sending a packet (in seconds)verbose- Whether to enable verbose output
Examples found in repository?
examples/protocol4_example.rs (lines 204-209)
30fn main() {
31 // Get the serial port from command line arguments
32 let args: Vec<String> = env::args().collect();
33 let serial_port = match args.len() {
34 1 => {
35 println!("Usage: {} <serial_port_path>", args[0]);
36 println!(" Example: {} /dev/ttyUSB0", args[0]);
37 process::exit(1);
38 },
39 _ => args[1].clone(),
40 };
41 // Create appointments
42 let appointments = vec![
43 Appointment {
44 time: system_time_from_date(2022, 10, 31, 19, 0, 0),
45 message: EepromString::new("Scare the neighbors"),
46 },
47 Appointment {
48 time: system_time_from_date(2022, 11, 24, 17, 0, 0),
49 message: EepromString::new("Feed the neighbors"),
50 },
51 Appointment {
52 time: system_time_from_date(2022, 12, 25, 14, 0, 0),
53 message: EepromString::new("Spoil the neighbors"),
54 },
55 ];
56
57 // Create anniversaries
58 let anniversaries = vec![
59 Anniversary {
60 time: system_time_from_date(1985, 7, 3, 0, 0, 0),
61 anniversary: EepromString::new("Release of Back to the Future"),
62 },
63 Anniversary {
64 time: system_time_from_date(1968, 4, 6, 0, 0, 0),
65 anniversary: EepromString::new("Release of 2001"),
66 },
67 ];
68
69 // Create phone numbers
70 let phone_numbers = vec![
71 PhoneNumber {
72 name: EepromString::new("Marty McFly"),
73 number: PhoneString::new("1112223333"),
74 phone_type: PhoneType::Home,
75 },
76 PhoneNumber {
77 name: EepromString::new("Doc Brown"),
78 number: PhoneString::new("4445556666"),
79 phone_type: PhoneType::Cell,
80 },
81 ];
82
83 // Create lists
84 let lists = vec![
85 List {
86 list_entry: EepromString::new("Muffler bearings"),
87 priority: Some(Priority::Two),
88 },
89 List {
90 list_entry: EepromString::new("Headlight fluid"),
91 priority: Some(Priority::Four),
92 },
93 ];
94
95 // Current time
96 let time1 = SystemTime::now();
97
98 // Create the Protocol4 structure with all components
99 let mut protocol = Protocol4::new();
100
101 // Add mandatory components
102 protocol.add(Sync { length: 100 });
103 protocol.add(Start {});
104
105 // Add multiple time zones
106 protocol.add(Time {
107 zone: 1,
108 is_24h: false,
109 date_format: DateFormat::MonthDashDayDashYear,
110 time: time1,
111 name: CharString::new("PDT", true),
112 });
113
114 protocol.add(Time {
115 zone: 2,
116 is_24h: true,
117 date_format: DateFormat::MonthDashDayDashYear,
118 time: time1,
119 name: CharString::new("GMT", true),
120 });
121
122 // Add multiple alarms
123 protocol.add(Alarm {
124 number: 1,
125 audible: true,
126 time: system_time_from_time(9, 0),
127 message: CharString::new("Wake up", false),
128 });
129
130 protocol.add(Alarm {
131 number: 2,
132 audible: true,
133 time: system_time_from_time(9, 5),
134 message: CharString::new("For real", false),
135 });
136
137 protocol.add(Alarm {
138 number: 3,
139 audible: false,
140 time: system_time_from_time(9, 10),
141 message: CharString::new("Get up", false),
142 });
143
144 protocol.add(Alarm {
145 number: 4,
146 audible: true,
147 time: system_time_from_time(18, 0), // 6 PM
148 message: CharString::new("Or not", false),
149 });
150
151 protocol.add(Alarm {
152 number: 5,
153 audible: false,
154 time: system_time_from_time(14, 0), // 2 PM
155 message: CharString::new("Told you", false),
156 });
157
158 // Add optional components
159 protocol.add(SoundOptions {
160 hourly_chime: true,
161 button_beep: true,
162 });
163
164 protocol.add(SoundTheme {
165 // Data from DEFHIGH.SPC
166 sound_theme_data: vec![0x00, 0x01, 0x02, 0x03],
167 });
168
169 // Create and add EEPROM
170 let eeprom = Eeprom {
171 appointments,
172 anniversaries,
173 lists,
174 phone_numbers,
175 appointment_notification_minutes: Some(NotificationMinutes::FifteenMinutes),
176 };
177 protocol.add(eeprom);
178
179 protocol.add(WristApp {
180 // Data from TIMER13.ZAP
181 wrist_app_data: vec![0x00, 0x01, 0x02, 0x03],
182 });
183
184 // Add End component (mandatory)
185 protocol.add(End {});
186
187 // Generate all packets
188 let all_packets = protocol.packets();
189
190 // Display results
191 println!("Created Protocol4 structure with all components");
192 println!("- Generated {} packet groups", all_packets.len());
193
194 // Print packet summary
195 for (i, packet) in all_packets.iter().enumerate() {
196 // Only print the first few bytes of each packet to avoid overwhelming output
197 let preview: Vec<u8> = packet.iter().take(6).cloned().collect();
198 println!("Packet group {}: {} bytes, starts with {:02X?}...", i, packet.len(), preview);
199 }
200
201 println!("\nTransmitting data to the watch on port: {}", serial_port);
202
203 // Create the notebook adapter and send the packets
204 let adapter = NotebookAdapter::new(
205 serial_port,
206 None, // Use default byte sleep time
207 None, // Use default packet sleep time
208 true, // Enable verbose output
209 );
210
211 match adapter.write(&all_packets) {
212 Ok(_) => println!("\nSuccessfully transmitted data to the watch!"),
213 Err(e) => {
214 eprintln!("\nError transmitting data: {}", e);
215 process::exit(1);
216 }
217 }
218}More examples
examples/protocol3_example.rs (lines 260-265)
35fn main() {
36 // Get the serial port from command line arguments
37 let args: Vec<String> = env::args().collect();
38 let serial_port = match args.len() {
39 1 => {
40 println!("Serial port not specified. Running in preview mode only.");
41 println!("Usage: {} <serial_port_path>", args[0]);
42 println!(" Example: {} /dev/ttyUSB0", args[0]);
43 String::new() // Empty string for preview mode
44 },
45 _ => args[1].clone(),
46 };
47
48 // Create a new Protocol 3 instance
49 let mut protocol = Protocol3::new();
50
51 // Define the appointments
52 let appointments = vec![
53 Appointment::new(
54 system_time_from_date(2022, 10, 31, 19, 0),
55 "Scare the neighbors".to_string()
56 ),
57 Appointment::new(
58 system_time_from_date(2022, 11, 24, 17, 0),
59 "Feed the neighbors".to_string()
60 ),
61 Appointment::new(
62 system_time_from_date(2022, 12, 25, 14, 0),
63 "Spoil the neighbors".to_string()
64 ),
65 ];
66
67 // Define the anniversaries
68 let anniversaries = vec![
69 Anniversary::new(
70 system_time_from_date(1985, 7, 3, 0, 0),
71 "Release of Back to the Future".to_string()
72 ),
73 Anniversary::new(
74 system_time_from_date(1968, 4, 6, 0, 0),
75 "Release of 2001".to_string()
76 ),
77 ];
78
79 // Define the phone numbers
80 let phone_numbers = vec![
81 PhoneNumber::new(
82 "Marty McFly".to_string(),
83 "1112223333".to_string(),
84 Some("H".to_string())
85 ),
86 PhoneNumber::new(
87 "Doc Brown".to_string(),
88 "4445556666".to_string(),
89 Some("C".to_string())
90 ),
91 ];
92
93 // Define the lists
94 let lists = vec![
95 List::new(
96 "Muffler bearings".to_string(),
97 Some(2)
98 ),
99 List::new(
100 "Headlight fluid".to_string(),
101 Some(4)
102 ),
103 ];
104
105 // Add each component to the protocol
106 protocol.add(Sync::default());
107 protocol.add(Start);
108
109 // Add time settings - local time in zone 1
110 let time1 = SystemTime::now();
111 // Convert to DateTime for display
112 let duration = time1.duration_since(SystemTime::UNIX_EPOCH).unwrap();
113 let dt1 = DateTime::<Utc>::from_timestamp(duration.as_secs() as i64, 0).unwrap();
114 println!("Setting local time to: {}", dt1.format("%Y-%m-%d %H:%M:%S"));
115
116 protocol.add(Time {
117 zone: 1,
118 is_24h: false,
119 date_format: DateFormat::MonthDashDayDashYear,
120 time: time1,
121 name: CharString::new("HOME", true),
122 });
123
124 // Add time settings - UTC time in zone 2
125 let time2 = SystemTime::now();
126 protocol.add(Time {
127 zone: 2,
128 is_24h: true,
129 date_format: DateFormat::MonthDashDayDashYear,
130 time: time2,
131 name: CharString::new("UTC", true),
132 });
133
134 // Add alarms
135 protocol.add(Alarm {
136 number: 1,
137 audible: true,
138 hour: 9,
139 minute: 0,
140 message: CharString::new("Wake up", true),
141 });
142
143 protocol.add(Alarm {
144 number: 2,
145 audible: true,
146 hour: 9,
147 minute: 5,
148 message: CharString::new("For real", true),
149 });
150
151 protocol.add(Alarm {
152 number: 3,
153 audible: false,
154 hour: 9,
155 minute: 10,
156 message: CharString::new("Get up", true),
157 });
158
159 protocol.add(Alarm {
160 number: 4,
161 audible: true,
162 hour: 9,
163 minute: 15,
164 message: CharString::new("Or not", true),
165 });
166
167 protocol.add(Alarm {
168 number: 5,
169 audible: false,
170 hour: 11,
171 minute: 30,
172 message: CharString::new("Told you", true),
173 });
174
175 // Create a new EEPROM instance with all data
176 let mut eeprom = Eeprom::new();
177 eeprom.appointments = appointments;
178 eeprom.anniversaries = anniversaries;
179 eeprom.phone_numbers = phone_numbers;
180 eeprom.lists = lists;
181 eeprom.appointment_notification_minutes = Some(15);
182
183 // Add the EEPROM to the protocol
184 protocol.add(eeprom);
185
186 // Use absolute paths for the fixture files (commented out since not used)
187 // let base_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
188
189 // // Load a sound theme from the example SPC file
190 // println!("Loading sound theme from EXAMPLE.SPC...");
191 // let spc_path = base_path.join("fixtures").join("EXAMPLE.SPC");
192 // let sound_theme = match SoundTheme::from_spc_file(&spc_path) {
193 // Ok(theme) => theme,
194 // Err(e) => {
195 // println!("Warning: Could not load SPC file: {}. Using simulated data.", e);
196 // // Create a placeholder with minimal data for the example
197 // SoundTheme::new(vec![0; 32])
198 // }
199 // };
200 // protocol.add(sound_theme);
201
202 // Add sound options
203 protocol.add(SoundOptions {
204 hourly_chime: true,
205 button_beep: true,
206 });
207
208 // // Load a wrist app from the example ZAP file
209 // println!("Loading wrist app from EXAMPLE.ZAP...");
210 // let zap_path = base_path.join("fixtures").join("EXAMPLE.ZAP");
211 // let wrist_app = match WristApp::from_zap_file(&zap_path) {
212 // Ok(app) => app,
213 // Err(e) => {
214 // println!("Warning: Could not load ZAP file: {}. Using simulated data.", e);
215 // // Create a simulated wrist app with demo data
216 // let demo_data = vec![
217 // 49, 53, 48, 32, 100, 97, 116, 97, 58, 32, 76, 111, 114, 101, 109, 32,
218 // 105, 112, 115, 117, 109, 32, 100, 111, 108, 111, 114, 32, 115, 105, 116, 32,
219 // 97, 109, 101, 116, 44, 32, 99, 111, 110, 115, 101, 99, 116, 101, 116, 117,
220 // 114, 32, 97, 100, 105, 112, 105, 115, 99, 105, 110, 103, 32, 101, 108, 105,
221 // 116, 44, 32, 115, 101, 100, 32, 100, 111, 32, 101, 105, 117, 115, 109, 111,
222 // 100, 32, 116, 101, 109, 112, 111, 114, 32, 105, 110, 99, 105, 100, 105, 100,
223 // 117, 110, 116, 32, 117, 116, 32, 108, 97, 98, 111, 114, 101, 32, 101, 116,
224 // 32, 100, 111, 108, 111, 114, 101, 32, 109, 97, 103, 110, 97, 32, 97, 108,
225 // 105, 113, 117, 97, 46
226 // ];
227 // WristApp::new(demo_data)
228 // }
229 // };
230 // protocol.add(wrist_app);
231
232 // Add end command
233 protocol.add(End);
234
235 // Generate all packets
236 let packets = protocol.packets();
237
238 // Print number of packets
239 println!("Generated {} packets for Protocol 3", packets.len());
240
241 // Print packet summary
242 println!("\nPacket summary:");
243 for (i, packet) in packets.iter().enumerate().take(5) {
244 // Only print first few bytes to avoid overwhelming output
245 let preview_len = std::cmp::min(packet.len(), 16);
246 let preview: Vec<u8> = packet.iter().take(preview_len).cloned().collect();
247 println!("Packet {}: {} bytes, starts with {:02X?}{}",
248 i + 1, packet.len(), preview,
249 if packet.len() > preview_len { "..." } else { "" });
250 }
251 if packets.len() > 5 {
252 println!("... and {} more packets", packets.len() - 5);
253 }
254
255 // If a serial port was provided, transmit the data
256 if !serial_port.is_empty() {
257 println!("\nTransmitting data to the watch on port: {}", serial_port);
258
259 // Create the notebook adapter and send the packets
260 let adapter = NotebookAdapter::new(
261 serial_port,
262 Some(0.014), // Use faster sleep times for the example
263 Some(0.08), // Use faster sleep times for the example
264 true, // Enable verbose output
265 );
266
267 match adapter.write(&packets) {
268 Ok(_) => println!("\nSuccessfully transmitted data to the watch!"),
269 Err(e) => {
270 eprintln!("\nError transmitting data: {}", e);
271 process::exit(1);
272 }
273 }
274 } else {
275 println!("\nNo serial port specified. Run with a serial port to transmit data to the watch:");
276 println!("Example: cargo run --example protocol3_example /dev/ttyUSB0");
277 }
278}Sourcepub fn write(&self, packets: &[Vec<u8>]) -> Result<()>
pub fn write(&self, packets: &[Vec<u8>]) -> Result<()>
Write packets to the serial device
§Arguments
packets- A vector of packet byte vectors to send
§Errors
Returns an error if the serial device cannot be opened or if writing fails
Examples found in repository?
examples/protocol4_example.rs (line 211)
30fn main() {
31 // Get the serial port from command line arguments
32 let args: Vec<String> = env::args().collect();
33 let serial_port = match args.len() {
34 1 => {
35 println!("Usage: {} <serial_port_path>", args[0]);
36 println!(" Example: {} /dev/ttyUSB0", args[0]);
37 process::exit(1);
38 },
39 _ => args[1].clone(),
40 };
41 // Create appointments
42 let appointments = vec![
43 Appointment {
44 time: system_time_from_date(2022, 10, 31, 19, 0, 0),
45 message: EepromString::new("Scare the neighbors"),
46 },
47 Appointment {
48 time: system_time_from_date(2022, 11, 24, 17, 0, 0),
49 message: EepromString::new("Feed the neighbors"),
50 },
51 Appointment {
52 time: system_time_from_date(2022, 12, 25, 14, 0, 0),
53 message: EepromString::new("Spoil the neighbors"),
54 },
55 ];
56
57 // Create anniversaries
58 let anniversaries = vec![
59 Anniversary {
60 time: system_time_from_date(1985, 7, 3, 0, 0, 0),
61 anniversary: EepromString::new("Release of Back to the Future"),
62 },
63 Anniversary {
64 time: system_time_from_date(1968, 4, 6, 0, 0, 0),
65 anniversary: EepromString::new("Release of 2001"),
66 },
67 ];
68
69 // Create phone numbers
70 let phone_numbers = vec![
71 PhoneNumber {
72 name: EepromString::new("Marty McFly"),
73 number: PhoneString::new("1112223333"),
74 phone_type: PhoneType::Home,
75 },
76 PhoneNumber {
77 name: EepromString::new("Doc Brown"),
78 number: PhoneString::new("4445556666"),
79 phone_type: PhoneType::Cell,
80 },
81 ];
82
83 // Create lists
84 let lists = vec![
85 List {
86 list_entry: EepromString::new("Muffler bearings"),
87 priority: Some(Priority::Two),
88 },
89 List {
90 list_entry: EepromString::new("Headlight fluid"),
91 priority: Some(Priority::Four),
92 },
93 ];
94
95 // Current time
96 let time1 = SystemTime::now();
97
98 // Create the Protocol4 structure with all components
99 let mut protocol = Protocol4::new();
100
101 // Add mandatory components
102 protocol.add(Sync { length: 100 });
103 protocol.add(Start {});
104
105 // Add multiple time zones
106 protocol.add(Time {
107 zone: 1,
108 is_24h: false,
109 date_format: DateFormat::MonthDashDayDashYear,
110 time: time1,
111 name: CharString::new("PDT", true),
112 });
113
114 protocol.add(Time {
115 zone: 2,
116 is_24h: true,
117 date_format: DateFormat::MonthDashDayDashYear,
118 time: time1,
119 name: CharString::new("GMT", true),
120 });
121
122 // Add multiple alarms
123 protocol.add(Alarm {
124 number: 1,
125 audible: true,
126 time: system_time_from_time(9, 0),
127 message: CharString::new("Wake up", false),
128 });
129
130 protocol.add(Alarm {
131 number: 2,
132 audible: true,
133 time: system_time_from_time(9, 5),
134 message: CharString::new("For real", false),
135 });
136
137 protocol.add(Alarm {
138 number: 3,
139 audible: false,
140 time: system_time_from_time(9, 10),
141 message: CharString::new("Get up", false),
142 });
143
144 protocol.add(Alarm {
145 number: 4,
146 audible: true,
147 time: system_time_from_time(18, 0), // 6 PM
148 message: CharString::new("Or not", false),
149 });
150
151 protocol.add(Alarm {
152 number: 5,
153 audible: false,
154 time: system_time_from_time(14, 0), // 2 PM
155 message: CharString::new("Told you", false),
156 });
157
158 // Add optional components
159 protocol.add(SoundOptions {
160 hourly_chime: true,
161 button_beep: true,
162 });
163
164 protocol.add(SoundTheme {
165 // Data from DEFHIGH.SPC
166 sound_theme_data: vec![0x00, 0x01, 0x02, 0x03],
167 });
168
169 // Create and add EEPROM
170 let eeprom = Eeprom {
171 appointments,
172 anniversaries,
173 lists,
174 phone_numbers,
175 appointment_notification_minutes: Some(NotificationMinutes::FifteenMinutes),
176 };
177 protocol.add(eeprom);
178
179 protocol.add(WristApp {
180 // Data from TIMER13.ZAP
181 wrist_app_data: vec![0x00, 0x01, 0x02, 0x03],
182 });
183
184 // Add End component (mandatory)
185 protocol.add(End {});
186
187 // Generate all packets
188 let all_packets = protocol.packets();
189
190 // Display results
191 println!("Created Protocol4 structure with all components");
192 println!("- Generated {} packet groups", all_packets.len());
193
194 // Print packet summary
195 for (i, packet) in all_packets.iter().enumerate() {
196 // Only print the first few bytes of each packet to avoid overwhelming output
197 let preview: Vec<u8> = packet.iter().take(6).cloned().collect();
198 println!("Packet group {}: {} bytes, starts with {:02X?}...", i, packet.len(), preview);
199 }
200
201 println!("\nTransmitting data to the watch on port: {}", serial_port);
202
203 // Create the notebook adapter and send the packets
204 let adapter = NotebookAdapter::new(
205 serial_port,
206 None, // Use default byte sleep time
207 None, // Use default packet sleep time
208 true, // Enable verbose output
209 );
210
211 match adapter.write(&all_packets) {
212 Ok(_) => println!("\nSuccessfully transmitted data to the watch!"),
213 Err(e) => {
214 eprintln!("\nError transmitting data: {}", e);
215 process::exit(1);
216 }
217 }
218}More examples
examples/protocol3_example.rs (line 267)
35fn main() {
36 // Get the serial port from command line arguments
37 let args: Vec<String> = env::args().collect();
38 let serial_port = match args.len() {
39 1 => {
40 println!("Serial port not specified. Running in preview mode only.");
41 println!("Usage: {} <serial_port_path>", args[0]);
42 println!(" Example: {} /dev/ttyUSB0", args[0]);
43 String::new() // Empty string for preview mode
44 },
45 _ => args[1].clone(),
46 };
47
48 // Create a new Protocol 3 instance
49 let mut protocol = Protocol3::new();
50
51 // Define the appointments
52 let appointments = vec![
53 Appointment::new(
54 system_time_from_date(2022, 10, 31, 19, 0),
55 "Scare the neighbors".to_string()
56 ),
57 Appointment::new(
58 system_time_from_date(2022, 11, 24, 17, 0),
59 "Feed the neighbors".to_string()
60 ),
61 Appointment::new(
62 system_time_from_date(2022, 12, 25, 14, 0),
63 "Spoil the neighbors".to_string()
64 ),
65 ];
66
67 // Define the anniversaries
68 let anniversaries = vec![
69 Anniversary::new(
70 system_time_from_date(1985, 7, 3, 0, 0),
71 "Release of Back to the Future".to_string()
72 ),
73 Anniversary::new(
74 system_time_from_date(1968, 4, 6, 0, 0),
75 "Release of 2001".to_string()
76 ),
77 ];
78
79 // Define the phone numbers
80 let phone_numbers = vec![
81 PhoneNumber::new(
82 "Marty McFly".to_string(),
83 "1112223333".to_string(),
84 Some("H".to_string())
85 ),
86 PhoneNumber::new(
87 "Doc Brown".to_string(),
88 "4445556666".to_string(),
89 Some("C".to_string())
90 ),
91 ];
92
93 // Define the lists
94 let lists = vec![
95 List::new(
96 "Muffler bearings".to_string(),
97 Some(2)
98 ),
99 List::new(
100 "Headlight fluid".to_string(),
101 Some(4)
102 ),
103 ];
104
105 // Add each component to the protocol
106 protocol.add(Sync::default());
107 protocol.add(Start);
108
109 // Add time settings - local time in zone 1
110 let time1 = SystemTime::now();
111 // Convert to DateTime for display
112 let duration = time1.duration_since(SystemTime::UNIX_EPOCH).unwrap();
113 let dt1 = DateTime::<Utc>::from_timestamp(duration.as_secs() as i64, 0).unwrap();
114 println!("Setting local time to: {}", dt1.format("%Y-%m-%d %H:%M:%S"));
115
116 protocol.add(Time {
117 zone: 1,
118 is_24h: false,
119 date_format: DateFormat::MonthDashDayDashYear,
120 time: time1,
121 name: CharString::new("HOME", true),
122 });
123
124 // Add time settings - UTC time in zone 2
125 let time2 = SystemTime::now();
126 protocol.add(Time {
127 zone: 2,
128 is_24h: true,
129 date_format: DateFormat::MonthDashDayDashYear,
130 time: time2,
131 name: CharString::new("UTC", true),
132 });
133
134 // Add alarms
135 protocol.add(Alarm {
136 number: 1,
137 audible: true,
138 hour: 9,
139 minute: 0,
140 message: CharString::new("Wake up", true),
141 });
142
143 protocol.add(Alarm {
144 number: 2,
145 audible: true,
146 hour: 9,
147 minute: 5,
148 message: CharString::new("For real", true),
149 });
150
151 protocol.add(Alarm {
152 number: 3,
153 audible: false,
154 hour: 9,
155 minute: 10,
156 message: CharString::new("Get up", true),
157 });
158
159 protocol.add(Alarm {
160 number: 4,
161 audible: true,
162 hour: 9,
163 minute: 15,
164 message: CharString::new("Or not", true),
165 });
166
167 protocol.add(Alarm {
168 number: 5,
169 audible: false,
170 hour: 11,
171 minute: 30,
172 message: CharString::new("Told you", true),
173 });
174
175 // Create a new EEPROM instance with all data
176 let mut eeprom = Eeprom::new();
177 eeprom.appointments = appointments;
178 eeprom.anniversaries = anniversaries;
179 eeprom.phone_numbers = phone_numbers;
180 eeprom.lists = lists;
181 eeprom.appointment_notification_minutes = Some(15);
182
183 // Add the EEPROM to the protocol
184 protocol.add(eeprom);
185
186 // Use absolute paths for the fixture files (commented out since not used)
187 // let base_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
188
189 // // Load a sound theme from the example SPC file
190 // println!("Loading sound theme from EXAMPLE.SPC...");
191 // let spc_path = base_path.join("fixtures").join("EXAMPLE.SPC");
192 // let sound_theme = match SoundTheme::from_spc_file(&spc_path) {
193 // Ok(theme) => theme,
194 // Err(e) => {
195 // println!("Warning: Could not load SPC file: {}. Using simulated data.", e);
196 // // Create a placeholder with minimal data for the example
197 // SoundTheme::new(vec![0; 32])
198 // }
199 // };
200 // protocol.add(sound_theme);
201
202 // Add sound options
203 protocol.add(SoundOptions {
204 hourly_chime: true,
205 button_beep: true,
206 });
207
208 // // Load a wrist app from the example ZAP file
209 // println!("Loading wrist app from EXAMPLE.ZAP...");
210 // let zap_path = base_path.join("fixtures").join("EXAMPLE.ZAP");
211 // let wrist_app = match WristApp::from_zap_file(&zap_path) {
212 // Ok(app) => app,
213 // Err(e) => {
214 // println!("Warning: Could not load ZAP file: {}. Using simulated data.", e);
215 // // Create a simulated wrist app with demo data
216 // let demo_data = vec![
217 // 49, 53, 48, 32, 100, 97, 116, 97, 58, 32, 76, 111, 114, 101, 109, 32,
218 // 105, 112, 115, 117, 109, 32, 100, 111, 108, 111, 114, 32, 115, 105, 116, 32,
219 // 97, 109, 101, 116, 44, 32, 99, 111, 110, 115, 101, 99, 116, 101, 116, 117,
220 // 114, 32, 97, 100, 105, 112, 105, 115, 99, 105, 110, 103, 32, 101, 108, 105,
221 // 116, 44, 32, 115, 101, 100, 32, 100, 111, 32, 101, 105, 117, 115, 109, 111,
222 // 100, 32, 116, 101, 109, 112, 111, 114, 32, 105, 110, 99, 105, 100, 105, 100,
223 // 117, 110, 116, 32, 117, 116, 32, 108, 97, 98, 111, 114, 101, 32, 101, 116,
224 // 32, 100, 111, 108, 111, 114, 101, 32, 109, 97, 103, 110, 97, 32, 97, 108,
225 // 105, 113, 117, 97, 46
226 // ];
227 // WristApp::new(demo_data)
228 // }
229 // };
230 // protocol.add(wrist_app);
231
232 // Add end command
233 protocol.add(End);
234
235 // Generate all packets
236 let packets = protocol.packets();
237
238 // Print number of packets
239 println!("Generated {} packets for Protocol 3", packets.len());
240
241 // Print packet summary
242 println!("\nPacket summary:");
243 for (i, packet) in packets.iter().enumerate().take(5) {
244 // Only print first few bytes to avoid overwhelming output
245 let preview_len = std::cmp::min(packet.len(), 16);
246 let preview: Vec<u8> = packet.iter().take(preview_len).cloned().collect();
247 println!("Packet {}: {} bytes, starts with {:02X?}{}",
248 i + 1, packet.len(), preview,
249 if packet.len() > preview_len { "..." } else { "" });
250 }
251 if packets.len() > 5 {
252 println!("... and {} more packets", packets.len() - 5);
253 }
254
255 // If a serial port was provided, transmit the data
256 if !serial_port.is_empty() {
257 println!("\nTransmitting data to the watch on port: {}", serial_port);
258
259 // Create the notebook adapter and send the packets
260 let adapter = NotebookAdapter::new(
261 serial_port,
262 Some(0.014), // Use faster sleep times for the example
263 Some(0.08), // Use faster sleep times for the example
264 true, // Enable verbose output
265 );
266
267 match adapter.write(&packets) {
268 Ok(_) => println!("\nSuccessfully transmitted data to the watch!"),
269 Err(e) => {
270 eprintln!("\nError transmitting data: {}", e);
271 process::exit(1);
272 }
273 }
274 } else {
275 println!("\nNo serial port specified. Run with a serial port to transmit data to the watch:");
276 println!("Example: cargo run --example protocol3_example /dev/ttyUSB0");
277 }
278}Auto Trait Implementations§
impl Freeze for NotebookAdapter
impl RefUnwindSafe for NotebookAdapter
impl Send for NotebookAdapter
impl Sync for NotebookAdapter
impl Unpin for NotebookAdapter
impl UnwindSafe for NotebookAdapter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more