- Introduction
- Getting Started
- Systems and Subsystems
- Parameters
- Encodings
- Containers: Telemetry Packets
- Calibrators
- Alarms
- Commands
- Command Verification
- Algorithms
- Expressions
- CCSDS and CSP Headers
- Structuring Large Models
- Generating XTCE
Appendices
Encodings¶
An encoding describes how a value is laid out in binary when it travels to
or from the remote system: how many bits, signed or unsigned, byte order,
character set, terminators. Encodings are independent of the engineering
type: the same uint8_t encoding can back an IntegerParameter, an
EnumeratedParameter or a BooleanParameter.
An encoding is attached to a parameter, argument or member through its
encoding option. The same encoding object can be reused freely — it
carries no reference to the things that use it.
Predefined encodings¶
The most common cases are available as module-level constants, and most models rarely need anything else:
Constant |
Meaning |
|---|---|
|
Unsigned integers of 1 to 7 bits, for bitfields |
|
Unsigned big-endian integers |
|
Signed (two’s complement) big-endian integers |
|
Unsigned integers of 9 to 15 bits |
|
Little-endian variants |
|
IEEE 754 floats, big endian |
|
IEEE 754 floats, little endian |
|
Alias of |
Y.IntegerParameter(eps, "counter", signed=False, encoding=Y.uint16_t)
Integer encodings¶
For anything not covered by the constants, construct an
IntegerEncoding:
Y.IntegerEncoding(
bits=20,
little_endian=False,
scheme=Y.IntegerEncodingScheme.TWOS_COMPLEMENT,
)
scheme selects the binary representation: UNSIGNED,
TWOS_COMPLEMENT, SIGN_MAGNITUDE, ONES_COMPLEMENT, or STRING
for integers transmitted as text (see the warning below).
Float encodings¶
FloatEncoding takes bits, little_endian and a scheme:
IEEE754_1985 (the default), MILSTD_1750A, or STRING.
Warning
The STRING schemes of IntegerEncoding and FloatEncoding
describe numbers transmitted as text (requiring the string_encoding
option to spell out the text format). They are understood by Yamcs but
are not part of the XTCE standard, so the exported file will not
validate against the XTCE schema. The standard-compliant alternative —
a plain StringEncoding on a numeric parameter — does not support
calibrators.
String encodings¶
StringEncoding covers text values. The size of a string on the wire is
determined by whichever of these options is used:
bitsA fixed size box. The string always occupies exactly this many bits; within the box it may still end early at a terminator.
length_bitsThe string is preceded by a size tag of this many bits, holding the string’s byte length.
terminationThe string ends at this terminator byte (default
b"\0"). Set toNonewhen the size is established by other means.max_bitsFor dynamically sized strings, a hint for the buffer Yamcs allocates (default 1 MB).
charset selects the character set: Charset.US_ASCII (default),
ISO_8859_1, WINDOWS_1252, UTF_8, UTF_16 (plus LE/BE
variants) or UTF_32 (plus LE/BE variants).
# A semicolon-terminated ASCII string
Y.StringParameter(
system=gt,
name="status_text",
encoding=Y.StringEncoding(termination=b"\x3B"),
)
# A length-prefixed UTF-8 string: 16-bit length tag, then the bytes
Y.StringEncoding(length_bits=16, charset=Y.Charset.UTF_8, termination=None)
Binary encodings¶
BinaryEncoding covers raw byte blocks. bits gives a fixed size;
length_bits a leading size tag, as for strings. For anything more
exotic, binary encodings support custom decoders (telemetry direction)
and encoders (commanding direction), written as small algorithms:
Y.BinaryEncoding(decoder=Y.remaining_binary_decoder)
Several ready-made algorithms ship with the library, referring to decoder and encoder implementations built into Yamcs:
|
Consumes all remaining bytes of the packet — useful for a trailing blob without a length indication. |
|
Reverse the byte order. |
|
Reads fixed-size bytes and yields their hex representation as a string value. |
You can also point to your own Java class with UnnamedJavaAlgorithm,
or provide inline script code — see Algorithms.
Time encodings¶
AbsoluteTimeParameter uses one of the two time encodings:
IntegerTimeEncoding or FloatTimeEncoding. They extend the integer
and float encodings with offset and scale, converting the raw count
into seconds since the parameter’s reference epoch:
time in seconds = offset + scale * raw
# 32-bit unsigned count of milliseconds since the mission epoch
Y.AbsoluteTimeParameter(
system=obc,
name="obt",
reference=datetime(2010, 1, 1, tzinfo=timezone.utc),
encoding=Y.IntegerTimeEncoding(bits=32, scale=0.001),
)