Skip to content

Commit

Permalink
use PathBuf directly for file paths on disk
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralim committed May 9, 2024
1 parent 9babaf9 commit a4ed77c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions bestool/src/beslink/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub fn read_message(serial_port: &mut Box<dyn SerialPort>) -> Result<BesMessage,
}
}
pub fn validate_packet_checksum(packet: &[u8]) -> 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(());
}
Expand Down Expand Up @@ -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())
}
}
}
5 changes: 3 additions & 2 deletions bestool/src/cmds/read_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<dyn SerialPort>,
start: usize,
length: usize,
Expand Down
6 changes: 3 additions & 3 deletions bestool/src/cmds/write_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<dyn SerialPort>,
) -> Result<(), BESLinkError> {
// Open file, read file, call burn_image_to_flash
Expand Down
7 changes: 4 additions & 3 deletions bestool/src/cmds/write_image_then_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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...");
}
Expand All @@ -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<dyn SerialPort>,
) -> Result<(), BESLinkError> {
// Open file, read file, call burn_image_to_flash
Expand Down
8 changes: 3 additions & 5 deletions bestool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a4ed77c

Please sign in to comment.