Skip to content

Commit 8c118d2

Browse files
committed
Improve scanner
1 parent 9a70eeb commit 8c118d2

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

app_rust/src/windows/diag_scanner.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl DiagScanner {
8383
// Accumulate scan results here
8484
self.can_traffic_id_list.insert(0x07DF, false); // Add OBD-II CAN ID so we don't scan that
8585
self.curr_stage += 1; // We can progress to the next stage!
86-
self.curr_scan_id = 0x07D0; // REMOVE FOR PRODUCTION
86+
self.curr_scan_id = 0x0000; // REMOVE FOR PRODUCTION
8787
self.server.clear_can_rx_buffer();
8888
return Some(DiagScannerMessage::ScanPoll) // Begin the CAN interrogation (Stage 1)
8989
}
@@ -109,10 +109,6 @@ impl DiagScanner {
109109
self.curr_stage += 1;
110110
self.curr_scan_id = 0; // First entry in our array
111111
std::thread::sleep(std::time::Duration::from_millis(100)); // Wait for adapter to rest (For some reason this works)
112-
self.server.clear_can_rx_buffer();
113-
self.server.clear_can_tx_buffer();
114-
self.server.clear_iso15765_rx_buffer();
115-
self.server.clear_iso15765_tx_buffer();
116112
self.clock = Instant::now(); // Reset clock
117113
return Some(DiagScannerMessage::ScanPoll)
118114
},
@@ -251,7 +247,7 @@ impl DiagScanner {
251247
// Interrogate the ECU with extended diagnostic session
252248
match KWP2000ECU::start_diag_session(self.server.clone(), &ecu) {
253249
Ok(mut s) => {
254-
if let Ok(_) = s.run_command(0x1A, &[0x87], 1000) { // Compulsory ECU identification command for KWP2000
250+
if s.run_command(0x1A, &[0x87], 1000).is_ok() { // Compulsory ECU identification command for KWP2000
255251
// TODO maybe replace the ECU name with the Part number?
256252
println!("ECU 0x{:04X} supports KWP2000!", ecu.send_id);
257253
ecu_res.kwp_support = true;
@@ -271,7 +267,7 @@ impl DiagScanner {
271267
if self.curr_scan_id as usize >= self.stage3_results.len() {
272268
return Some(DiagScannerMessage::IncrementStage)
273269
}
274-
let ecu = self.stage3_results[self.curr_scan_id as usize];
270+
let _ecu = self.stage3_results[self.curr_scan_id as usize];
275271
self.curr_scan_id += 1;
276272
Some(DiagScannerMessage::ScanPoll)
277273
}
@@ -356,11 +352,11 @@ impl DiagScanner {
356352

357353
// Setting up the scanner
358354
fn draw_stage_1(&mut self) -> Element<DiagScannerMessage> {
359-
let mut c = Column::new().padding(10).spacing(10).align_items(Align::Center).width(Length::Fill)
355+
Column::new().padding(10).spacing(10).align_items(Align::Center).width(Length::Fill)
360356
.push(title_text("Listening to existing CAN Traffic", crate::themes::TitleSize::P2))
361357
.push(progress_bar(0f32..=10000f32, self.clock.elapsed().as_millis() as f32, ButtonType::Info))
362-
.push(text(format!("Found {} existing can IDs", self.can_traffic_id_list.len()).as_str(), TextType::Normal));
363-
c.into()
358+
.push(text(format!("Found {} existing can IDs", self.can_traffic_id_list.len()).as_str(), TextType::Normal))
359+
.into()
364360
}
365361

366362
fn draw_stage_2(&mut self) -> Element<DiagScannerMessage> {
@@ -400,26 +396,26 @@ impl DiagScanner {
400396
}
401397

402398
fn draw_stage_4(&mut self) -> Element<DiagScannerMessage> {
403-
let mut c = Column::new().padding(10).spacing(10).align_items(Align::Center).width(Length::Fill)
399+
Column::new().padding(10).spacing(10).align_items(Align::Center).width(Length::Fill)
404400
.push(title_text("Network cool down", crate::themes::TitleSize::P2))
405-
.push(progress_bar(0f32..=5000f32, self.clock.elapsed().as_millis() as f32, ButtonType::Info));
406-
c.into()
401+
.push(progress_bar(0f32..=5000f32, self.clock.elapsed().as_millis() as f32, ButtonType::Info))
402+
.into()
407403
}
408404

409405
fn draw_stage_5(&mut self) -> Element<DiagScannerMessage> {
410-
let mut c = Column::new().padding(10).spacing(10).align_items(Align::Center).width(Length::Fill)
406+
Column::new().padding(10).spacing(10).align_items(Align::Center).width(Length::Fill)
411407
.push(title_text("Testing ECUs for KWP2000 Capabilities", crate::themes::TitleSize::P2))
412408
.push(progress_bar(0f32..=self.stage3_results.len() as f32, self.curr_scan_id as f32, ButtonType::Info))
413-
.push(text(format!("Found {} existing can IDs", self.can_traffic_id_list.len()).as_str(), TextType::Normal));
414-
c.into()
409+
.push(text(format!("Found {} existing can IDs", self.can_traffic_id_list.len()).as_str(), TextType::Normal))
410+
.into()
415411
}
416412

417413
fn draw_stage_6(&mut self) -> Element<DiagScannerMessage> {
418-
let mut c = Column::new().padding(10).spacing(10).align_items(Align::Center).width(Length::Fill)
414+
Column::new().padding(10).spacing(10).align_items(Align::Center).width(Length::Fill)
419415
.push(title_text("Testing ECUs for UDS Capability", crate::themes::TitleSize::P2))
420416
.push(progress_bar(0f32..=self.stage3_results.len() as f32, self.curr_scan_id as f32, ButtonType::Info))
421-
.push(text(format!("Found {} existing can IDs", self.can_traffic_id_list.len()).as_str(), TextType::Normal));
422-
c.into()
417+
.push(text(format!("Found {} existing can IDs", self.can_traffic_id_list.len()).as_str(), TextType::Normal))
418+
.into()
423419
}
424420

425421
fn draw_stage_7(&mut self) -> Element<DiagScannerMessage> {

0 commit comments

Comments
 (0)