diff --git a/on-host/src/main.rs b/on-host/src/main.rs index 53332cf75c2b08c5d62b0676cd8a248f9db5c8b4..3fb373656cb948db401c5a5bc8a097467db325e9 100644 --- a/on-host/src/main.rs +++ b/on-host/src/main.rs @@ -58,21 +58,21 @@ fn main() -> Result<()> { let mut packets = PacketSequence::from(packets); // Open the first serialport available. - // let port_name = if let Some(name) = args.port { - // name - // } else if let Some(name) = get_first_stm32_serial_port()? { - // debug!("found STM32 device on {}", name); - // name - // } else { - // error!("FATAL: no STM32 serial port found, your device may not be connected properly"); - // std::process::exit(1); - // }; - // debug!("connecting to serial port {}...", port_name); - // let mut port = serialport::new(port_name, args.baud_rate) - // .open() - // .into_diagnostic() - // .wrap_err("Failed to open serial port")?; - // let mut write_port = port.try_clone().into_diagnostic()?; + let port_name = if let Some(name) = args.port { + name + } else if let Some(name) = get_first_stm32_serial_port()? { + debug!("found STM32 device on {}", name); + name + } else { + error!("FATAL: no STM32 serial port found, your device may not be connected properly"); + std::process::exit(1); + }; + debug!("connecting to serial port {}...", port_name); + let mut port = serialport::new(port_name, args.baud_rate) + .open() + .into_diagnostic() + .wrap_err("Failed to open serial port")?; + let mut write_port = port.try_clone().into_diagnostic()?; // read from buffer and print to stdout let mut buffer = [0u8; 1000]; @@ -85,7 +85,7 @@ fn main() -> Result<()> { times.push(t.elapsed().as_millis()); } start = Some(Instant::now()); - // write_port.write_packet(packet.to_owned())?; + write_port.write_packet(packet.to_owned())?; debug!( "sent packet ({}/{})", packets.sent_packets(), @@ -93,9 +93,9 @@ fn main() -> Result<()> { ); // if sync mode is enabled then wait for ACK - // if !args.no_sync { - // wait_for_ack(&mut port, &mut buffer); - // } + if !args.no_sync { + wait_for_ack(&mut port, &mut buffer); + } } info!("sent {} packets", packets.sent_packets());