refactor(firmware): simplify configuration and diagnostics

This commit is contained in:
Onur Özkan committed 2026-08-23 00:40:36 +03:00
1 parent ba9c97ed3b
commit fdf82a5114
96 files changed
+1612 -2772

No files matched your search

+13 -26
View File
@@ -33,13 +33,7 @@ where
store: S,
) -> Result<Self, StartupError<S::Error>> {
let configuration = ConfigManager::recover(factory, capabilities, store)?;
let logging = configuration.active().mavlink_logging();
let filter = if logging.enabled() {
kaptan_log::LogFilter::up_to(logging.maximum_severity())
} else {
kaptan_log::LogFilter::disabled()
};
let mavlink_logs = RuntimeMavlinkLogQueue::new(filter);
let mavlink_logs = RuntimeMavlinkLogQueue::new(configuration.active().mavlink_logging());
Ok(Self {
configuration,
mavlink_logs,
@@ -76,7 +70,7 @@ where
}
/// Immutable boot-active MAVLink log policy copied from the validated profile.
pub const fn mavlink_log_filter(&self) -> kaptan_log::LogFilter {
pub const fn mavlink_log_filter(&self) -> kaptan_log::LevelFilter {
self.mavlink_logs.filter()
}
}
@@ -84,7 +78,7 @@ where
#[cfg(test)]
mod tests {
use kaptan_config::{ConfigModel, ConfigStore, ConfigValue};
use kaptan_log::{LogFlags, LogRecord, LogText, Severity};
use kaptan_log::{Level, LevelFilter, LogFlags, LogRecord, LogText};
use super::FlightRuntime;
@@ -113,18 +107,11 @@ mod tests {
)
.expect("factory configuration validates");
assert_eq!(
runtime
.configuration()
.active()
.mavlink_logging()
.maximum_severity(),
runtime
.mavlink_log_filter()
.maximum_severity()
.expect("factory enables MAVLink logs")
runtime.configuration().active().mavlink_logging(),
runtime.mavlink_log_filter()
);
runtime.publish_log_event(LogRecord::new(
Severity::Info,
Level::Info,
LogFlags::NONE,
LogText::from_message("runtime ready"),
));
@@ -132,13 +119,13 @@ mod tests {
}
#[test]
fn disabled_mavlink_sink_filters_every_severity() {
fn disabled_mavlink_sink_filters_every_level() {
let mut factory = kaptan_flight_config::CandidateProfile::factory();
let enabled = kaptan_flight_config::CandidateProfile::descriptors()
.find(|descriptor| descriptor.display_key == "mavlink.logging.enabled")
.expect("MAVLink logging enable descriptor");
let level_filter = kaptan_flight_config::CandidateProfile::descriptors()
.find(|descriptor| descriptor.display_key == "mavlink.logging.level_filter")
.expect("MAVLink log-level descriptor");
factory
.set_field(enabled.id, ConfigValue::Bool(false))
.set_field(level_filter.id, ConfigValue::U32(0))
.unwrap();
let mut runtime = FlightRuntime::recover(
factory,
@@ -147,9 +134,9 @@ mod tests {
)
.expect("disabled MAVLink sink is valid");
assert_eq!(runtime.mavlink_log_filter().maximum_severity(), None);
assert_eq!(runtime.mavlink_log_filter(), LevelFilter::Off);
runtime.publish_log_event(LogRecord::new(
Severity::Error,
Level::Error,
LogFlags::NONE,
LogText::from_message("not routed to MAVLink"),
));