xtce_model/commands.rs
1//! Telecommands: `<CommandMetaData>` and what it defines.
2//!
3//! # Why a command is a container here
4//!
5//! XTCE describes a telecommand with its own vocabulary — a `<MetaCommand>` with an
6//! `<ArgumentList>`, an inheritance link that carries `<ArgumentAssignment>`s, and a
7//! `<CommandContainer>` whose entry list may name arguments, parameters and fixed values.
8//! None of that is a new *shape*. It is a container of fields, selected by fixed values, and
9//! that is exactly what a telemetry container is.
10//!
11//! So it is lowered into the machinery that already exists:
12//!
13//! * an `<Argument>` becomes a [`crate::Parameter`], qualified under the command that owns it
14//! — the schema says an argument reference "is always resolved locally to the metacommand",
15//! and two commands may each have a `MODE`;
16//! * a `<CommandContainer>` becomes a [`crate::Container`];
17//! * an `<ArgumentAssignment>` becomes a [`crate::MatchCriteria`] on the container, because
18//! assigning a value to an inherited argument is how a command is specialised, and
19//! comparing that same value is how an arriving packet is recognised as this command;
20//! * a `<FixedValueEntry>` becomes an [`crate::EntryKind::FixedValue`].
21//!
22//! What is left over — which commands exist, what each one is called, which container packs
23//! it and which arguments it takes — is [`MetaCommand`]. The interpreter and both code
24//! generators need none of it: by the time they run, a command *is* a container. It is here
25//! so that a caller can ask what commands a database defines, and so `xtce info` can say.
26//!
27//! # What the reference does with all this
28//!
29//! Nothing. `space_packet_parser` has no command support at all — the string
30//! `CommandMetaData` does not appear in its source, and a definition carrying one loads with
31//! the command half silently ignored. So unlike almost everything else in this crate, none of
32//! this is checked against it. The oracle is the schema, quoted where it decides something.
33
34use crate::ids::{ContainerId, MetaCommandId, ParamId, SpaceSystemId};
35use crate::intern::NameId;
36
37/// A `<xtce:MetaCommand>`.
38#[derive(Clone, Debug)]
39pub struct MetaCommand {
40 /// Command name as written.
41 pub name: NameId,
42 /// Fully qualified name.
43 pub qualified_name: NameId,
44 /// The space system that owns this definition.
45 pub space_system: SpaceSystemId,
46 /// `abstract="true"`: the command is only a base for others and is never sent itself.
47 pub is_abstract: bool,
48 /// The command this one specialises, from `<BaseMetaCommand metaCommandRef=..>`.
49 pub base: Option<MetaCommandId>,
50 /// The container that packs it, from `<CommandContainer>`.
51 ///
52 /// Optional in the schema: a `MetaCommand` may be an abstract carrier of arguments with
53 /// no packaging of its own.
54 pub container: Option<ContainerId>,
55 /// The arguments this command declares itself, in document order.
56 ///
57 /// Not the ones it inherits. Each is a parameter in the arena, named
58 /// `{space system}/{command}/{argument}`, and deliberately absent from the unqualified
59 /// name index so that an argument cannot shadow a telemetry parameter of the same name.
60 pub arguments: Vec<ParamId>,
61 /// `shortDescription`, if present.
62 pub short_description: Option<NameId>,
63 /// `<LongDescription>`, if present.
64 pub long_description: Option<NameId>,
65}