space_packet_parser.xtce.encodings

DataEncoding definitions

Attributes

logger

Classes

DataEncoding

Abstract base class for XTCE data encodings

StringDataEncoding

<xtce:StringDataEncoding>

NumericDataEncoding

Abstract class that is inherited by IntegerDataEncoding and FloatDataEncoding

IntegerDataEncoding

<xtce:IntegerDataEncoding>

FloatDataEncoding

<xtce:FloatDataEncoding>

BinaryDataEncoding

<xtce:BinaryDataEncoding>

Module Contents

space_packet_parser.xtce.encodings.logger
class space_packet_parser.xtce.encodings.DataEncoding

Bases: space_packet_parser.common.AttrComparable, space_packet_parser.common.XmlObject

Abstract base class for XTCE data encodings

static get_default_calibrator(data_encoding_element: lxml.etree.Element) space_packet_parser.xtce.calibrators.Calibrator | None

Gets the default_calibrator for the data encoding element

Parameters:

data_encoding_element (ElementTree.Element) – The data encoding element which should contain the default_calibrator

Return type:

Union[Calibrator, None]

static get_context_calibrators(data_encoding_element: lxml.etree.Element) list[space_packet_parser.xtce.calibrators.ContextCalibrator] | None

Get the context default_calibrator(s) for the data encoding element

Parameters:

data_encoding_element (ElementTree.Element) – XML element

Returns:

List of ContextCalibrator objects or None if there are no context calibrators

Return type:

Union[List[ContextCalibrator], None]

static _get_linear_adjuster(parent_element: lxml.etree.Element) callable | None

Examine a parent (e.g. a <xtce:DynamicValue>) element and find a LinearAdjustment if present, creating and returning a function that evaluates the adjustment.

Parameters:

parent_element (ElementTree.Element) – Parent element which may contain a LinearAdjustment

Returns:

adjuster – Function object that adjusts a SizeInBits value by a linear function or None if no adjuster present

Return type:

Union[callable, None]

_calculate_size(packet: space_packet_parser.SpacePacket) int

Calculate the size of the data item in bits.

Parameters:

packet (SpacePacket) – Binary representation of the packet used to get the coming bits and any previously parsed data items to infer field lengths.

Returns:

Size of the data item in bits.

Return type:

int

parse_value(packet: space_packet_parser.SpacePacket) space_packet_parser.common.ParameterDataTypes

Parse a value from packet data, possibly using previously parsed data items to inform parsing.

Parameters:

packet (SpacePacket) – Binary representation of the packet used to get the coming bits and any previously parsed data items to infer field lengths.

Returns:

Derived value with a raw_value attribute that can be used to get the original packet data.

Return type:

common.ParameterDataTypes

class space_packet_parser.xtce.encodings.StringDataEncoding(*, encoding: str = 'UTF-8', byte_order: str | None = None, fixed_raw_length: int | None = None, dynamic_length_reference: str | None = None, discrete_lookup_length: list[space_packet_parser.xtce.comparisons.DiscreteLookup] | None = None, use_calibrated_value: bool | None = True, length_linear_adjuster: callable | None = None, termination_character: str | None = None, leading_length_size: int | None = None)

Bases: DataEncoding

<xtce:StringDataEncoding>

_supported_encodings = ('US-ASCII', 'ISO-8859-1', 'Windows-1252', 'UTF-8', 'UTF-16', 'UTF-16LE', 'UTF-16BE', 'UTF-32',...
encoding = 'UTF-8'
termination_character = None
fixed_length = None
leading_length_size = None
dynamic_length_reference = None
use_calibrated_value = True
discrete_lookup_length = None
length_linear_adjuster = None
_calculate_size(packet: space_packet_parser.SpacePacket) int

Calculate the size of the raw string buffer field

Parameters:

packet (SpacePacket) – Partially parsed packet for referencing previous data fields.

Returns:

Size, in bits, of the raw string buffer.

Return type:

int

_get_raw_buffer(packet: space_packet_parser.SpacePacket) bytes

Get the raw string buffer as bytes. This will include any leading size or termination characters.

Notes

If the buffer size is not an integer number of bytes, the bytestring is padded at the end with zeros.

Parameters:

packet (SpacePacket) – Packet parsed so far, for referencing previous values

Returns:

The raw string buffer, padded on the RHS to a byte boundary if the raw length specified is not an integer number of bytes.

Return type:

bytes

parse_value(packet: space_packet_parser.SpacePacket) space_packet_parser.common.StrParameter

Parse a string value from packet data, possibly using previously parsed data items to inform parsing.

Parameters:

packet (SpacePacket) – Binary representation of the packet used to get the coming bits and any previously parsed data items to infer field lengths.

Returns:

Parsed string value. The raw_value attribute contains the raw string bytes buffer. This includes any leading size or termination character and may be a non-integer number of bytes, padded on the RHS.

Return type:

StrParameter

classmethod from_xml(element: lxml.etree.Element, *, tree: lxml.etree.Element | None = None, parameter_lookup: dict[str, any] | None = None, parameter_type_lookup: dict[str, any] | None = None, container_lookup: dict[str, any] | None = None) StringDataEncoding

Create a data encoding object from an <xtce:StringDataEncoding> XML element.

Notes

Raw strings in XTCE can be described in two ways:

  1. Using a SizeInBits/Fixed/FixedSize element that specifies the length of the raw string, including any termination character or leading size integer. This is sometimes referred to as the “container” or “memory allocation” for the string.

  2. Using a Variable element that contains either a DynamicValue or a DiscreteLookup to other parameters that specify the length of the raw string, including any termination character or leading size integer.

Derived strings in XTCE can be specified in two ways:

  1. Via a TerminationCharacter element that contains the hex value of the termination character in the specified encoding (e.g. UTF-16BE).

  2. Via a LeadingSize element that specifies the number of bits allocated at the beginning of the raw string for an integer that specifies the subsequent length, in bits, of the derived string.

Parameters:
  • element (ElementTree.Element) – XML element

  • tree (Optional[ElementTree.Element]) – Ignored

  • parameter_lookup (Optional[dict]) – Ignored

  • parameter_type_lookup (Optional[dict]) – Ignored

  • container_lookup (Optional[dict[str, SequenceContainer]]) – Ignored

Return type:

cls

to_xml(*, elmaker: lxml.builder.ElementMaker) lxml.etree.Element

Create a data encoding XML element

Parameters:

elmaker (ElementMaker) – Element factory with predefined namespace

Return type:

ElementTree.Element

class space_packet_parser.xtce.encodings.NumericDataEncoding(size_in_bits: int, encoding: str, *, byte_order: str = 'mostSignificantByteFirst', default_calibrator: space_packet_parser.xtce.calibrators.Calibrator | None = None, context_calibrators: list[space_packet_parser.xtce.calibrators.ContextCalibrator] | None = None)

Bases: DataEncoding

Abstract class that is inherited by IntegerDataEncoding and FloatDataEncoding

_data_return_class
size_in_bits
encoding
byte_order = 'mostSignificantByteFirst'
default_calibrator = None
context_calibrators = None
_calculate_size(packet: space_packet_parser.SpacePacket) int

Calculate the size of the data item in bits.

Parameters:

packet (SpacePacket) – Binary representation of the packet used to get the coming bits and any previously parsed data items to infer field lengths.

Returns:

Size of the data item in bits.

Return type:

int

abstract _get_raw_value(packet: space_packet_parser.SpacePacket) int | float

Read the raw value from the packet data

Parameters:

packet (SpacePacket) – Binary representation of the packet used to get the coming bits and any previously parsed data items to infer field lengths.

Returns:

Raw value

Return type:

int

static _twos_complement(val: int, bit_width: int) int

Take the twos complement of val Used when parsing ints and some floats

parse_value(packet: space_packet_parser.SpacePacket) space_packet_parser.common.FloatParameter | space_packet_parser.common.IntParameter

Parse a value from packet data, possibly using previously parsed data items to inform parsing.

Parameters:

packet (SpacePacket) – Binary representation of the packet used to get the coming bits and any previously parsed data items to infer field lengths.

Returns:

Parsed data item as either a float or integer depending on the type of encoding.

Return type:

common.FloatParameter or common.IntParameter

to_xml(*, elmaker: lxml.builder.ElementMaker) lxml.etree.Element

Create a data encoding XML element

Parameters:

elmaker (ElementMaker) – Element factory with predefined namespace

Return type:

ElementTree.Element

class space_packet_parser.xtce.encodings.IntegerDataEncoding(size_in_bits: int, encoding: str, *, byte_order: str = 'mostSignificantByteFirst', default_calibrator: space_packet_parser.xtce.calibrators.Calibrator | None = None, context_calibrators: list[space_packet_parser.xtce.calibrators.ContextCalibrator] | None = None)

Bases: NumericDataEncoding

<xtce:IntegerDataEncoding>

_encodings = ('unsigned', 'signed', 'twosCompliment', 'twosComplement')
_byte_orders = ('leastSignificantByteFirst', 'mostSignificantByteFirst')
_data_return_class
_get_raw_value(packet: space_packet_parser.SpacePacket) int

Read the raw value from the packet data

Parameters:

packet (SpacePacket) – Binary representation of the packet used to get the coming bits and any previously parsed data items to infer field lengths.

Returns:

Raw value

Return type:

int

classmethod from_xml(element: lxml.etree.Element, *, tree: lxml.etree.Element | None = None, parameter_lookup: dict[str, any] | None = None, parameter_type_lookup: dict[str, any] | None = None, container_lookup: dict[str, any] | None = None) IntegerDataEncoding

Create a data encoding object from an <xtce:IntegerDataEncoding> XML element.

Parameters:
  • element (ElementTree.Element) – XML element

  • tree (Optional[ElementTree.Element]) – Ignored

  • parameter_lookup (Optional[dict]) – Ignored

  • parameter_type_lookup (Optional[dict]) – Ignored

  • container_lookup (Optional[dict[str, SequenceContainer]]) – Ignored

Return type:

cls

class space_packet_parser.xtce.encodings.FloatDataEncoding(size_in_bits: int, *, encoding: str = 'IEEE754', byte_order: str = 'mostSignificantByteFirst', default_calibrator: space_packet_parser.xtce.calibrators.Calibrator | None = None, context_calibrators: list[space_packet_parser.xtce.calibrators.ContextCalibrator] | None = None)

Bases: NumericDataEncoding

<xtce:FloatDataEncoding>

_allowed_encodings = ['IEEE754_1985', 'IEEE754', 'MILSTD_1750A', 'DEC', 'IBM', 'TI']
_supported_encodings = ['IEEE754_1985', 'IEEE754', 'MILSTD_1750A']
_data_return_class
_get_raw_value(packet)

Read the data in as bytes and return a float representation.

classmethod from_xml(element: lxml.etree.Element, *, tree: lxml.etree.Element | None = None, parameter_lookup: dict[str, any] | None = None, parameter_type_lookup: dict[str, any] | None = None, container_lookup: dict[str, any] | None = None) FloatDataEncoding

Create a data encoding object from an <xtce:FloatDataEncoding> XML element.

Parameters:
  • element (ElementTree.Element) – XML element

  • tree (Optional[ElementTree.Element]) – Ignored

  • parameter_lookup (Optional[dict]) – Ignored

  • parameter_type_lookup (Optional[dict]) – Ignored

  • container_lookup (Optional[dict[str, SequenceContainer]]) – Ignored

Return type:

cls

class space_packet_parser.xtce.encodings.BinaryDataEncoding(*, fixed_size_in_bits: int | None = None, size_reference_parameter: str | None = None, use_calibrated_value: bool = True, size_discrete_lookup_list: list[space_packet_parser.xtce.comparisons.DiscreteLookup] | None = None, linear_adjuster: callable | None = None)

Bases: DataEncoding

<xtce:BinaryDataEncoding>

fixed_size_in_bits = None
size_reference_parameter = None
use_calibrated_value = True
size_discrete_lookup_list = None
linear_adjuster = None
_calculate_size(packet: space_packet_parser.SpacePacket) int

Determine the number of bits in the binary field.

Returns:

Format string in the bitstring format. e.g. bin:1024

Return type:

Union[str, None]

parse_value(packet: space_packet_parser.SpacePacket) space_packet_parser.common.BinaryParameter

Parse a value from packet data, possibly using previously parsed data items to inform parsing.

Parameters:

packet (SpacePacket) – Binary representation of the packet used to get the coming bits and any previously parsed data items to infer field lengths.

Returns:

Parsed binary data item.

Return type:

common.BinaryParameter

classmethod from_xml(element: lxml.etree.Element, *, tree: lxml.etree.Element | None = None, parameter_lookup: dict[str, any] | None = None, parameter_type_lookup: dict[str, any] | None = None, container_lookup: dict[str, any] | None = None) BinaryDataEncoding

Create a data encoding object from an <xtce:BinaryDataEncoding> XML element.

Parameters:
  • element (ElementTree.Element) – XML element

  • tree (Optional[ElementTree.Element]) – Ignored

  • parameter_lookup (Optional[dict]) – Ignored

  • parameter_type_lookup (Optional[dict]) – Ignored

  • container_lookup (Optional[dict[str, SequenceContainer]]) – Ignored

Return type:

BinaryDataEncoding

to_xml(*, elmaker: lxml.builder.ElementMaker) lxml.etree.Element

Create a data encoding XML element

Parameters:

elmaker (ElementMaker) – Element factory with predefined namespace

Return type:

ElementTree.Element