feat(mavlink): adopt the kaptan-native dialect
This commit is contained in:
1 parent
1c90870634
commit
5f91465e66
87 files changed
+7733
-6850
No files matched your search
@@ -32,11 +32,11 @@ struct MavlinkConfig {
|
||||
struct TelemetryConfig {
|
||||
#[config(
|
||||
id = 103,
|
||||
key = "telemetry.raw_imu_hz",
|
||||
key = "telemetry.imu_hz",
|
||||
unit = "Hz",
|
||||
range(min = 1, max = 100)
|
||||
)]
|
||||
raw_imu_hz: u8,
|
||||
imu_hz: u8,
|
||||
#[config(
|
||||
id = 104,
|
||||
key = "telemetry.heartbeat_hz",
|
||||
@@ -91,7 +91,7 @@ struct OneRecord<C>(Option<C>);
|
||||
impl<C: Clone> ConfigStore<C> for OneRecord<C> {
|
||||
type Error = ();
|
||||
|
||||
fn load(&mut self) -> Result<Option<C>, Self::Error> {
|
||||
fn load(&mut self, _: &C) -> Result<Option<C>, Self::Error> {
|
||||
Ok(self.0.take())
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ fn factory() -> TestUserConfig {
|
||||
log_level_filter: LevelFilter::Info,
|
||||
},
|
||||
telemetry: TelemetryConfig {
|
||||
raw_imu_hz: 20,
|
||||
imu_hz: 20,
|
||||
heartbeat_hz: 2,
|
||||
},
|
||||
driver: DriverConfig { driver_gain: 7 },
|
||||
@@ -123,6 +123,7 @@ struct MalformedProjection {
|
||||
|
||||
impl Config for MalformedProjection {
|
||||
const FIELD_COUNT: usize = TestUserConfig::FIELD_COUNT;
|
||||
const SNAPSHOT_VALUE_BYTES: usize = TestUserConfig::SNAPSHOT_VALUE_BYTES;
|
||||
const SCHEMA_ID: [u8; 16] = TestUserConfig::SCHEMA_ID;
|
||||
|
||||
fn descriptor(index: usize) -> Option<&'static kaptan_config::FieldDescriptor> {
|
||||
@@ -159,7 +160,7 @@ fn mavlink_logging_policy_is_projected_and_validated_independently() {
|
||||
);
|
||||
let mut candidate = UserConfigModel::<TestUserConfig, F722ImmutableConfig>::new(factory());
|
||||
candidate
|
||||
.set_field(FieldId::new(105), ConfigValue::U32(0))
|
||||
.set_field(FieldId::new(105), ConfigValue::U8(0))
|
||||
.unwrap();
|
||||
|
||||
let active = candidate.validate(&IMMUTABLE).unwrap();
|
||||
@@ -168,17 +169,13 @@ fn mavlink_logging_policy_is_projected_and_validated_independently() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_projection_rejects_missing_wrong_kind_and_wide_semantic_values() {
|
||||
fn runtime_projection_rejects_missing_and_wrong_kind_values() {
|
||||
for (system_id, rule) in [
|
||||
(None, kaptan_config::ValidationRule::Inconsistent),
|
||||
(
|
||||
Some(ConfigValue::Bool(true)),
|
||||
kaptan_config::ValidationRule::Inconsistent,
|
||||
),
|
||||
(
|
||||
Some(ConfigValue::U32(256)),
|
||||
kaptan_config::ValidationRule::AboveMaximum,
|
||||
),
|
||||
] {
|
||||
let malformed = MalformedProjection {
|
||||
inner: factory(),
|
||||
@@ -195,7 +192,7 @@ fn runtime_construction_reads_the_persisted_board_owned_user_root() {
|
||||
let factory = UserConfigModel::<TestUserConfig, F722ImmutableConfig>::new(factory());
|
||||
let mut persisted = factory.clone();
|
||||
persisted
|
||||
.set_field(FieldId::new(1000), ConfigValue::U32(42))
|
||||
.set_field(FieldId::new(1000), ConfigValue::U8(42))
|
||||
.expect("driver field must accept a valid persisted value");
|
||||
|
||||
let manager = ConfigManager::recover_compatible_or_factory(
|
||||
@@ -207,7 +204,7 @@ fn runtime_construction_reads_the_persisted_board_owned_user_root() {
|
||||
|
||||
assert_eq!(
|
||||
manager.active().field_value(FieldId::new(1000)),
|
||||
Some(ConfigValue::U32(42)),
|
||||
Some(ConfigValue::U8(42)),
|
||||
"runtime construction must receive the validated persisted field"
|
||||
);
|
||||
}
|
||||
@@ -215,19 +212,19 @@ fn runtime_construction_reads_the_persisted_board_owned_user_root() {
|
||||
#[test]
|
||||
fn committing_a_user_edit_does_not_mutate_the_boot_active_view() {
|
||||
let factory = UserConfigModel::<TestUserConfig, F722ImmutableConfig>::new(factory());
|
||||
let mut manager = ConfigManager::new(factory, IMMUTABLE, OneRecord(None)).unwrap();
|
||||
manager.begin().unwrap();
|
||||
manager
|
||||
.set(FieldId::new(1000), ConfigValue::U32(42))
|
||||
let mut manager = ConfigManager::recover(factory, IMMUTABLE, OneRecord(None)).unwrap();
|
||||
let mut replacement = manager.committed().clone();
|
||||
replacement
|
||||
.set_field(FieldId::new(1000), ConfigValue::U8(42))
|
||||
.unwrap();
|
||||
manager.commit().unwrap();
|
||||
manager.replace(replacement).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
manager.active().field_value(FieldId::new(1000)),
|
||||
Some(ConfigValue::U32(7))
|
||||
Some(ConfigValue::U8(7))
|
||||
);
|
||||
assert_eq!(
|
||||
manager.committed_value(FieldId::new(1000)),
|
||||
Some(ConfigValue::U32(42))
|
||||
manager.committed().field_value(FieldId::new(1000)),
|
||||
Some(ConfigValue::U8(42))
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user