From a4ed77c847d27594ba5cb5e9bb381a8a021d8374 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Thu, 9 May 2024 21:21:58 +1000 Subject: [PATCH] use PathBuf directly for file paths on disk --- bestool/src/beslink/message.rs | 6 +++--- bestool/src/cmds/read_image.rs | 5 +++-- bestool/src/cmds/write_image.rs | 6 +++--- bestool/src/cmds/write_image_then_monitor.rs | 7 ++++--- bestool/src/main.rs | 8 +++----- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/bestool/src/beslink/message.rs b/bestool/src/beslink/message.rs index 6ff57b0..d0ea976 100644 --- a/bestool/src/beslink/message.rs +++ b/bestool/src/beslink/message.rs @@ -169,7 +169,7 @@ pub fn read_message(serial_port: &mut Box) -> Result Result<(), BESLinkError> { - let checksum = calculate_message_checksum(&packet[0..packet.len()-1]); + let checksum = calculate_message_checksum(&packet[0..packet.len() - 1]); if checksum == packet[packet.len() - 1] { return Ok(()); } @@ -275,7 +275,7 @@ mod tests { ], ]; for v in test_messages { - assert!(validate_packet_checksum(&v).is_ok()) - } + assert!(validate_packet_checksum(&v).is_ok()) + } } } diff --git a/bestool/src/cmds/read_image.rs b/bestool/src/cmds/read_image.rs index ac1ef11..d2839cd 100644 --- a/bestool/src/cmds/read_image.rs +++ b/bestool/src/cmds/read_image.rs @@ -6,12 +6,13 @@ use crate::serial_port_opener::open_serial_port_with_wait; use serialport::SerialPort; use std::fs::File; use std::io::prelude::*; +use std::path::PathBuf; use std::time::Duration; use tracing::error; use tracing::info; pub fn cmd_read_image( - input_file: &str, + input_file: &PathBuf, port_name: &str, start: usize, length: usize, @@ -33,7 +34,7 @@ pub fn cmd_read_image( } } fn do_read_flash_data( - output_file_path: &str, + output_file_path: &PathBuf, serial_port: &mut Box, start: usize, length: usize, diff --git a/bestool/src/cmds/write_image.rs b/bestool/src/cmds/write_image.rs index 5033d79..3d6f035 100644 --- a/bestool/src/cmds/write_image.rs +++ b/bestool/src/cmds/write_image.rs @@ -5,12 +5,12 @@ use crate::beslink::{ use crate::serial_port_opener::open_serial_port_with_wait; use serialport::{ClearBuffer, SerialPort}; use std::fs; - +use std::path::PathBuf; use std::time::Duration; use tracing::error; use tracing::info; -pub fn cmd_write_image(input_file: &str, port_name: &str, wait_for_port: bool) { +pub fn cmd_write_image(input_file: &PathBuf, port_name: &str, wait_for_port: bool) { //First gain sync to the device println!("Writing binary data to {port_name} @ {BES_PROGRAMMING_BAUDRATE}"); let mut port = open_serial_port_with_wait(port_name, BES_PROGRAMMING_BAUDRATE, wait_for_port); @@ -39,7 +39,7 @@ pub fn cmd_write_image(input_file: &str, port_name: &str, wait_for_port: bool) { } } fn do_burn_image_to_flash( - input_file: &str, + input_file: &PathBuf, serial_port: &mut Box, ) -> Result<(), BESLinkError> { // Open file, read file, call burn_image_to_flash diff --git a/bestool/src/cmds/write_image_then_monitor.rs b/bestool/src/cmds/write_image_then_monitor.rs index ac60a56..0d2b276 100644 --- a/bestool/src/cmds/write_image_then_monitor.rs +++ b/bestool/src/cmds/write_image_then_monitor.rs @@ -8,12 +8,13 @@ use serialport::{ClearBuffer, SerialPort}; use std::fs; +use std::path::PathBuf; use std::time::Duration; use tracing::error; use tracing::info; pub fn cmd_write_image_then_monitor( - input_file: &str, + input_file_path: &PathBuf, serial_port: &str, monitor_baud_rate: u32, wait_for_port: bool, @@ -38,7 +39,7 @@ pub fn cmd_write_image_then_monitor( } } info!("Now doing firmware load"); - match do_burn_image_to_flash(input_file, &mut port) { + match do_burn_image_to_flash(input_file_path, &mut port) { Ok(_) => { info!("Done..."); } @@ -65,7 +66,7 @@ pub fn cmd_write_image_then_monitor( } } fn do_burn_image_to_flash( - input_file: &str, + input_file: &PathBuf, serial_port: &mut Box, ) -> Result<(), BESLinkError> { // Open file, read file, call burn_image_to_flash diff --git a/bestool/src/main.rs b/bestool/src/main.rs index d225699..32c30e3 100644 --- a/bestool/src/main.rs +++ b/bestool/src/main.rs @@ -89,18 +89,16 @@ fn main() { BesTool::SerialMonitor(args) => { cmd_serial_port_monitor(&args.serial_port_path, args.baud_rate, args.wait); } - BesTool::WriteImage(args) => { - cmd_write_image(args.firmware_path.to_str().unwrap(), &args.port, args.wait) - } + BesTool::WriteImage(args) => cmd_write_image(&args.firmware_path, &args.port, args.wait), BesTool::ReadImage(args) => cmd_read_image( - args.firmware_path.to_str().unwrap(), + &args.firmware_path, &args.port, args.offset as usize, args.length as usize, args.wait, ), BesTool::WriteImageThenMonitor(args) => cmd_write_image_then_monitor( - args.firmware_path.to_str().unwrap(), + &args.firmware_path, &args.port, args.monitor_baud_rate, args.wait,