From 1f74983d618e6a15aa9cdea32962d67306942c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20=C3=96zkan?= Date: Sun, 6 Sep 2026 23:14:16 +0300 Subject: [PATCH] fix(configurator): allow startup without arguments --- Makefile | 2 +- firmware/tools/configurator/Makefile | 4 ++-- firmware/tools/configurator/src/main.rs | 17 ++++++++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index a0f6f54..2679a0d 100644 --- a/Makefile +++ b/Makefile @@ -83,7 +83,7 @@ help: ## Show the command interface (the default) ' make firmware/boards/kakute-f7-mini-v3' \ ' make firmware/boards/kakute-f7-mini-v3 flash' \ ' make docs -- build' \ - ' make firmware/tools/configurator -- --source-system 255 --serial /dev/ttyUSB0 --baud 115200' \ + ' make firmware/tools/configurator' \ ' make firmware/tools/sitl -- move 5 3 1 --wait' nix-shell: ## Enter the reproducible Nix development shell diff --git a/firmware/tools/configurator/Makefile b/firmware/tools/configurator/Makefile index 75a7aa3..e05cc29 100644 --- a/firmware/tools/configurator/Makefile +++ b/firmware/tools/configurator/Makefile @@ -22,8 +22,8 @@ else help: ## Show configurator commands @printf '%s\n' 'Configurator' '' \ - 'The root Makefile passes every argument after -- to the application:' \ - ' make firmware/tools/configurator -- --source-system 255 --serial /dev/ttyUSB0 --baud 115200' + 'Start the local web application, then select the serial device in the browser:' \ + ' make firmware/tools/configurator' endif diff --git a/firmware/tools/configurator/src/main.rs b/firmware/tools/configurator/src/main.rs index ae4dacf..cce8236 100644 --- a/firmware/tools/configurator/src/main.rs +++ b/firmware/tools/configurator/src/main.rs @@ -6,6 +6,7 @@ use kaptan_configurator::{SerialBaud, SerialController, SharedState, serve_conne use kaptan_file_mavlink::Principal; const LISTEN_ADDRESS: &str = "127.0.0.1:4861"; +const DEFAULT_GCS_SYSTEM_ID: u8 = 255; const GCS_COMPONENT_ID: u8 = 190; fn main() -> std::io::Result<()> { @@ -81,11 +82,10 @@ fn arguments_from(mut values: impl Iterator) -> std::io::Result return Err(invalid_arguments(&flag)), } } - let source_system = source_system.ok_or_else(|| invalid_arguments("--source-system"))?; Ok(Arguments { serial_path, baud, - source_system, + source_system: source_system.unwrap_or(DEFAULT_GCS_SYSTEM_ID), }) } @@ -93,7 +93,7 @@ fn invalid_arguments(flag: &str) -> std::io::Error { std::io::Error::new( std::io::ErrorKind::InvalidInput, format!( - "invalid {flag}; usage: kaptan-configurator --source-system ID [--serial PATH] [--baud RATE]" + "invalid {flag}; usage: kaptan-configurator [--source-system ID] [--serial PATH] [--baud RATE]" ), ) } @@ -108,7 +108,15 @@ mod tests { } #[test] - fn command_line_defaults_to_115200_and_requires_an_exact_source_system() { + fn command_line_requires_no_arguments() { + let accepted = arguments_from(core::iter::empty()).unwrap(); + assert_eq!(accepted.serial_path, None); + assert_eq!(accepted.baud, SerialBaud::try_new(115_200).unwrap()); + assert_eq!(accepted.source_system, DEFAULT_GCS_SYSTEM_ID); + } + + #[test] + fn command_line_accepts_serial_and_source_overrides() { let accepted = arguments_from( ["--source-system", "255", "--serial", "/dev/ttyACM0"] .into_iter() @@ -161,7 +169,6 @@ mod tests { vec!["--source-system", "255", "--baud"], vec!["--source-system", "0"], vec!["--source-system", "255", "--source-system", "254"], - vec![], ] { let rejected = arguments_from(values.into_iter().map(String::from)) .expect_err("invalid baud arguments must be rejected");