diff --git a/Cargo.toml b/Cargo.toml index b69779a..16d7890 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ authors = ["Maciej Myszkiewicz"] [workspace.dependencies] # Without the CLI: a build script that generates code has no use for an argument parser. -xtce-flight = { path = "crates/xtce-flight", version = "0.1.0", default-features = false } +xtce-flight = { path = "crates/xtce-flight", version = "0.1.1", default-features = false } # Pinned to a revision, not a branch. `xtce_codegen::plan` is this project's input format; # a moving dependency would mean an unrelated commit there breaks a build here. diff --git a/crates/xtce-flight-e2e/tests/against_interpreter.rs b/crates/xtce-flight-e2e/tests/against_interpreter.rs index 6c72633..4c41e12 100644 --- a/crates/xtce-flight-e2e/tests/against_interpreter.rs +++ b/crates/xtce-flight-e2e/tests/against_interpreter.rs @@ -307,6 +307,18 @@ fn a_value_that_does_not_fit_is_refused() { ); beacon.ones_odd = i16::MIN + 1; assert!(beacon.encode(&mut buffer).is_ok()); + + // Sign-magnitude has the same symmetric range for the same reason: one bit for the sign + // and two representations of zero leave i16::MIN out of reach of a 16-bit field. + beacon.signmag_odd = i16::MIN; + assert_eq!( + beacon.encode(&mut buffer), + Err(EncodeError::OutOfRange { + parameter: "SIGNMAG_ODD" + }) + ); + beacon.signmag_odd = i16::MIN + 1; + assert!(beacon.encode(&mut buffer).is_ok()); } #[test] diff --git a/crates/xtce-flight/src/layout.rs b/crates/xtce-flight/src/layout.rs index 428f313..5a32642 100644 --- a/crates/xtce-flight/src/layout.rs +++ b/crates/xtce-flight/src/layout.rs @@ -427,14 +427,17 @@ impl Builder { // Two entries may name the same parameter — a container that repeats one, or an // inherited entry re-listed. The decoder collapses them; a struct cannot have the // field twice, so the last one wins, matching what a reader of the packet sees. - let mut seen: HashMap = HashMap::new(); - let mut deduplicated: Vec<(FlightField, &Vec)> = Vec::new(); - for field in fields { - if let Some(&at) = seen.get(&field.0.ident) { - deduplicated[at] = field; + let mut deduplicated: Vec<(FlightField, &Vec)> = + Vec::with_capacity(fields.len()); + for (mut field, contexts) in fields { + field.ident = xtce_codegen::plan::field_ident(&field.xtce_name); + if let Some(existing) = deduplicated + .iter_mut() + .find(|(held, _)| held.ident == field.ident) + { + *existing = (field, contexts); } else { - seen.insert(field.0.ident.clone(), deduplicated.len()); - deduplicated.push(field); + deduplicated.push((field, contexts)); } } diff --git a/crates/xtce-flight/tests/layout.rs b/crates/xtce-flight/tests/layout.rs index 01b8f4e..7621c72 100644 --- a/crates/xtce-flight/tests/layout.rs +++ b/crates/xtce-flight/tests/layout.rs @@ -918,3 +918,56 @@ fn a_wide_fixed_value_off_a_byte_boundary_is_refused() { "unexpected refusal: {error}" ); } + +/// One of whole-byte width that starts off a byte boundary is refused too. +#[test] +fn a_wide_fixed_value_shifted_by_a_preceding_nibble_is_refused() { + let error = refusal(command_layout( + r#" + "#, + )); + assert!( + error.contains("FixedValueEntry") && error.contains("start on a byte"), + "unexpected refusal: {error}" + ); +} + +/// Repeating a parameter in one container keeps the last occurrence in the struct. +#[test] +fn a_repeated_parameter_collapses_to_its_last_occurrence() { + let body = r#" + + + + + + + + + + + + + + + + + "#; + + let layout = layout_of(body).expect("compiles"); + let container = &layout.containers[0]; + assert_eq!(container.len_bytes, 3, "all three entries occupy wire room"); + assert_eq!( + container.fields.len(), + 2, + "a struct cannot carry the same field name twice" + ); + assert_eq!(container.fields[0].ident, "dup"); + assert_eq!(container.fields[0].xtce_name, "DUP"); + assert_eq!( + container.fields[0].bit_offset, 16, + "the last entry wins, matching what a reader of the packet sees" + ); + assert_eq!(container.fields[1].xtce_name, "MID"); + assert_eq!(container.fields[1].bit_offset, 8); +} diff --git a/probes/nostd/Cargo.lock b/probes/nostd/Cargo.lock index 835fc3c..579f20a 100644 --- a/probes/nostd/Cargo.lock +++ b/probes/nostd/Cargo.lock @@ -121,7 +121,7 @@ dependencies = [ [[package]] name = "xtce-flight-nostd-probe" -version = "0.1.0" +version = "0.1.1" dependencies = [ "xtce-flight", "xtce-model", diff --git a/probes/nostd/Cargo.toml b/probes/nostd/Cargo.toml index cda03bb..5891ff9 100644 --- a/probes/nostd/Cargo.toml +++ b/probes/nostd/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "xtce-flight-nostd-probe" description = "Builds the generated flight code for a bare-metal target, with no std and no panic path" -version = "0.1.0" +version = "0.1.1" edition = "2024" rust-version = "1.85" license = "MIT OR Apache-2.0"