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
@@ -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
|
||||
|
||||
|
||||
@@ -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<Item = String>) -> std::io::Result<A
|
||||
_ => 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");
|
||||
|
||||
Reference in new issue
Block a user