refactor(firmware): centralize configuration and diagnostics

This commit is contained in:
Onur Özkan committed 2026-08-22 18:37:18 +03:00
1 parent 7048ed89d0
commit 387fdaad23
140 files changed
+6891 -4541

No files matched your search

+20 -16
View File
@@ -61,7 +61,7 @@ impl LogFlags {
pub const TRACE: Self = Self(1 << 0);
/// Text did not fit the fixed record buffer.
pub const TRUNCATED: Self = Self(1 << 1);
/// Adjacent equivalent records were coalesced.
/// Multiple ISR producer observations were folded into one mailbox event.
pub const COALESCED: Self = Self(1 << 2);
/// Raw MAVLink bitmask.
@@ -69,6 +69,11 @@ impl LogFlags {
self.0
}
/// Bits valid for an ordinary `KAPTAN_LOG` record.
pub const fn log_bits(self) -> u8 {
self.0 & (Self::TRACE.0 | Self::TRUNCATED.0)
}
/// Bits valid for an error-only record. Trace is a property of ordinary
/// `KAPTAN_LOG` diagnostics and is intentionally never emitted on
/// `KAPTAN_ERROR`.
@@ -122,8 +127,6 @@ pub struct LogRecord {
severity: Severity,
flags: LogFlags,
body: RecordBody,
/// Adjacent equivalent diagnostics retained as one record.
pub occurrences: u32,
}
impl LogRecord {
@@ -144,7 +147,6 @@ impl LogRecord {
severity,
flags: with_truncation(flags, message),
body: RecordBody::Log { message },
occurrences: 1,
}
}
@@ -158,6 +160,20 @@ impl LogRecord {
Self::error_with_severity(Severity::Error, flags, path, additional_information)
}
/// Creates one record from a typed derived error without choosing a sink.
pub fn from_error<E: ErrorReport>(flags: LogFlags, error: &E) -> Self {
Self::from_static_error(flags, error.static_error())
}
/// Creates one record from an ISR-safe static error without choosing a sink.
pub fn from_static_error(flags: LogFlags, error: &'static StaticError) -> Self {
Self::error(
flags,
ErrorPath::from_message(error.path()),
ErrorAdditionalInformation::from_message(error.additional_information()),
)
}
fn error_with_severity(
severity: Severity,
flags: LogFlags,
@@ -172,7 +188,6 @@ impl LogRecord {
path,
additional_information,
},
occurrences: 1,
}
}
@@ -228,17 +243,6 @@ impl LogRecord {
RecordBody::Error { .. } => DeliveryClass::Critical,
}
}
/// Tests whether two pending records can coalesce without hiding a new
/// payload, severity, or delivery class.
pub fn is_equivalent_to(&self, other: &Self) -> bool {
self.severity == other.severity && self.flags == other.flags && self.body == other.body
}
pub(crate) fn increment_occurrences(&mut self) {
self.occurrences = self.occurrences.saturating_add(1);
self.flags = self.flags.with(LogFlags::COALESCED);
}
}
fn with_truncation(mut flags: LogFlags, value: LogText) -> LogFlags {