Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions crates/xtce-flight-e2e/tests/against_interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 10 additions & 7 deletions crates/xtce-flight/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, usize> = HashMap::new();
let mut deduplicated: Vec<(FlightField, &Vec<ContextCalibration>)> = Vec::new();
for field in fields {
if let Some(&at) = seen.get(&field.0.ident) {
deduplicated[at] = field;
let mut deduplicated: Vec<(FlightField, &Vec<ContextCalibration>)> =
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));
}
}

Expand Down
53 changes: 53 additions & 0 deletions crates/xtce-flight/tests/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#" <FixedValueEntry name="LEAD" binaryValue="A" sizeInBits="4"/>
<FixedValueEntry name="FILL" binaryValue="001122334455667788" sizeInBits="72"/>"#,
));
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#" <ParameterTypeSet>
<IntegerParameterType name="U8">
<IntegerDataEncoding sizeInBits="8" encoding="unsigned"/>
</IntegerParameterType>
</ParameterTypeSet>
<ParameterSet>
<Parameter name="DUP" parameterTypeRef="U8"/>
<Parameter name="MID" parameterTypeRef="U8"/>
</ParameterSet>
<ContainerSet>
<SequenceContainer name="Only">
<EntryList>
<ParameterRefEntry parameterRef="DUP"/>
<ParameterRefEntry parameterRef="MID"/>
<ParameterRefEntry parameterRef="DUP"/>
</EntryList>
</SequenceContainer>
</ContainerSet>"#;

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);
}
2 changes: 1 addition & 1 deletion probes/nostd/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion probes/nostd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Loading