fix(configurator): allow startup without arguments
This commit is contained in:
1 parent
604a7aba86
commit
1f74983d61
3 files changed
+15
-8
No files matched your search
@@ -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' \
|
||||||
' make firmware/boards/kakute-f7-mini-v3 flash' \
|
' make firmware/boards/kakute-f7-mini-v3 flash' \
|
||||||
' make docs -- build' \
|
' 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'
|
' make firmware/tools/sitl -- move 5 3 1 --wait'
|
||||||
|
|
||||||
nix-shell: ## Enter the reproducible Nix development shell
|
nix-shell: ## Enter the reproducible Nix development shell
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ else
|
|||||||
|
|
||||||
help: ## Show configurator commands
|
help: ## Show configurator commands
|
||||||
@printf '%s\n' 'Configurator' '' \
|
@printf '%s\n' 'Configurator' '' \
|
||||||
'The root Makefile passes every argument after -- to the application:' \
|
'Start the local web application, then select the serial device in the browser:' \
|
||||||
' make firmware/tools/configurator -- --source-system 255 --serial /dev/ttyUSB0 --baud 115200'
|
' make firmware/tools/configurator'
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use kaptan_configurator::{SerialBaud, SerialController, SharedState, serve_conne
|
|||||||
use kaptan_file_mavlink::Principal;
|
use kaptan_file_mavlink::Principal;
|
||||||
|
|
||||||
const LISTEN_ADDRESS: &str = "127.0.0.1:4861";
|
const LISTEN_ADDRESS: &str = "127.0.0.1:4861";
|
||||||
|
const DEFAULT_GCS_SYSTEM_ID: u8 = 255;
|
||||||
const GCS_COMPONENT_ID: u8 = 190;
|
const GCS_COMPONENT_ID: u8 = 190;
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
@@ -81,11 +82,10 @@ fn arguments_from(mut values: impl Iterator<Item = String>) -> std::io::Result<A
|
|||||||
_ => return Err(invalid_arguments(&flag)),
|
_ => return Err(invalid_arguments(&flag)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let source_system = source_system.ok_or_else(|| invalid_arguments("--source-system"))?;
|
|
||||||
Ok(Arguments {
|
Ok(Arguments {
|
||||||
serial_path,
|
serial_path,
|
||||||
baud,
|
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::Error::new(
|
||||||
std::io::ErrorKind::InvalidInput,
|
std::io::ErrorKind::InvalidInput,
|
||||||
format!(
|
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]
|
#[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(
|
let accepted = arguments_from(
|
||||||
["--source-system", "255", "--serial", "/dev/ttyACM0"]
|
["--source-system", "255", "--serial", "/dev/ttyACM0"]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -161,7 +169,6 @@ mod tests {
|
|||||||
vec!["--source-system", "255", "--baud"],
|
vec!["--source-system", "255", "--baud"],
|
||||||
vec!["--source-system", "0"],
|
vec!["--source-system", "0"],
|
||||||
vec!["--source-system", "255", "--source-system", "254"],
|
vec!["--source-system", "255", "--source-system", "254"],
|
||||||
vec![],
|
|
||||||
] {
|
] {
|
||||||
let rejected = arguments_from(values.into_iter().map(String::from))
|
let rejected = arguments_from(values.into_iter().map(String::from))
|
||||||
.expect_err("invalid baud arguments must be rejected");
|
.expect_err("invalid baud arguments must be rejected");
|
||||||
|
|||||||
Reference in new issue
Block a user