From 52d734d95fbe95b040e50481a4d52f28771f6bd6 Mon Sep 17 00:00:00 2001 From: Henner Zeller Date: Sun, 22 Feb 2026 13:28:39 +0100 Subject: [PATCH] Provide some debug output. --- hostcontrol/Cargo.lock | 5 +++-- hostcontrol/Cargo.toml | 1 + hostcontrol/src/stage.rs | 11 ++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/hostcontrol/Cargo.lock b/hostcontrol/Cargo.lock index dc422b4..54a9403 100644 --- a/hostcontrol/Cargo.lock +++ b/hostcontrol/Cargo.lock @@ -1446,6 +1446,7 @@ dependencies = [ "eframe", "egui", "env_logger", + "log", "nalgebra", "nalgebra-macros", "serialport", @@ -1759,9 +1760,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.27" +version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" [[package]] name = "mach2" diff --git a/hostcontrol/Cargo.toml b/hostcontrol/Cargo.toml index f83ff16..16fa0d7 100644 --- a/hostcontrol/Cargo.toml +++ b/hostcontrol/Cargo.toml @@ -11,3 +11,4 @@ nalgebra-macros = "^0.2.2" env_logger = "0.11.8" egui = "0.31.1" eframe = "0.31.1" +log = "0.4.29" diff --git a/hostcontrol/src/stage.rs b/hostcontrol/src/stage.rs index 2f510b5..3d9fefb 100644 --- a/hostcontrol/src/stage.rs +++ b/hostcontrol/src/stage.rs @@ -2,6 +2,7 @@ use std::time::Duration; use thiserror::Error; +use log::debug; fn new_camera_rotation(theta: f64) -> nalgebra::Matrix3 { nalgebra::matrix![ @@ -55,6 +56,8 @@ pub type StageIOResult = std::result::Result; impl StageIO { pub fn new(port: &str, speed: u32) -> StageIOResult { let serial = serialport::new(port, speed).timeout(Duration::from_secs(60)).open()?; + // TODO: read and discard initial characters; some devices like to be + // chatty on start-up. Ok(Self { serial }) } @@ -71,10 +74,12 @@ impl StageIO { } // Send request and wait for response deliminated with a newline - fn send_request>(&mut self, command: S) -> StageIOResult { + pub fn send_request>(&mut self, command: S) -> StageIOResult { + debug!("->: {:?}", command.as_ref()); self.serial.write_all(command.as_ref().as_bytes()).map_err(|e| StageIOError::Write(e))?; - let res = self.receive_until("\n")?; - Ok(res.trim().to_string()) + let response = self.receive_until("\n")?; + debug!("<-: {:?}", response); + Ok(response.trim().to_string()) } }