space_packet_parser.encodings
DataEncoding definitions
Attributes
Classes
Abstract base class for XTCE data encodings |
|
<xtce:StringDataEncoding> |
|
Abstract class that is inherited by IntegerDataEncoding and FloatDataEncoding |
|
<xtce:IntegerDataEncoding> |
|
<xtce:FloatDataEncoding> |
|
<xtce:BinaryDataEncoding> |
Module Contents
- space_packet_parser.encodings.logger
- class space_packet_parser.encodings.DataEncoding
Bases:
space_packet_parser.comparisons.AttrComparableAbstract base class for XTCE data encodings
- classmethod from_data_encoding_xml_element(element: lxml.etree.Element, ns: dict) DataEncoding
- Abstractmethod:
Abstract classmethod to create a data encoding object from an XML element.
- Parameters:
element (ElementTree.Element) – XML element
ns (dict) – XML namespace dict
- Return type:
- static get_default_calibrator(data_encoding_element: lxml.etree.Element, ns: dict) space_packet_parser.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
ns (dict) – XML namespace dict
- Return type:
Union[Calibrator, None]
- static get_context_calibrators(data_encoding_element: lxml.etree.Element, ns: dict) List[space_packet_parser.calibrators.ContextCalibrator] | None
Get the context default_calibrator(s) for the data encoding element
- Parameters:
data_encoding_element (ElementTree.Element) – XML element
ns (dict) – XML namespace dict
- 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, ns: dict) 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
ns (dict) – XML namespace dict
- Returns:
adjuster – Function object that adjusts a SizeInBits value by a linear function or None if no adjuster present
- Return type:
Union[callable, None]
- abstract _calculate_size(packet: space_packet_parser.packets.CCSDSPacket) int
Calculate the size of the data item in bits.
- Parameters:
packet (CCSDSPacket) – 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 parse_value(packet: space_packet_parser.packets.CCSDSPacket, **kwargs) space_packet_parser.packets.ParameterDataTypes
Parse a value from packet data, possibly using previously parsed data items to inform parsing.
- Parameters:
packet (CCSDSPacket) – 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:
packets.ParameterDataTypes
- class space_packet_parser.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.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
- buffer_length_specs
- termination_character
- fixed_length
- leading_length_size
- dynamic_length_reference
- use_calibrated_value
- discrete_lookup_length
- length_linear_adjuster
- _calculate_size(packet: space_packet_parser.packets.CCSDSPacket) int
Calculate the size of the raw string buffer field
- Parameters:
packet (packets.CCSDSPacket) – 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.packets.CCSDSPacket) 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 (packets.CCSDSPacket) – 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.packets.CCSDSPacket, **kwargs) space_packet_parser.packets.StrParameter
Parse a string value from packet data, possibly using previously parsed data items to inform parsing.
- Parameters:
packet (CCSDSPacket) – 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:
- classmethod from_data_encoding_xml_element(element: lxml.etree.Element, ns: dict) StringDataEncoding
Create a data encoding object from an <xtce:StringDataEncoding> XML element.
Notes
Raw strings in XTCE can be described in two ways:
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.
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:
Via a TerminationCharacter element that contains the hex value of the termination character in the specified encoding (e.g. UTF-16BE).
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
ns (dict) – XML namespace dict
- Return type:
cls
- class space_packet_parser.encodings.NumericDataEncoding(size_in_bits: int, encoding: str, *, byte_order: str = 'mostSignificantByteFirst', default_calibrator: space_packet_parser.calibrators.Calibrator | None = None, context_calibrators: List[space_packet_parser.calibrators.ContextCalibrator] | None = None)
Bases:
DataEncodingAbstract class that is inherited by IntegerDataEncoding and FloatDataEncoding
- _data_return_class
- size_in_bits
- encoding
- byte_order
- default_calibrator
- context_calibrators
- _calculate_size(packet: space_packet_parser.packets.CCSDSPacket) int
Calculate the size of the data item in bits.
- Parameters:
packet (CCSDSPacket) – 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.packets.CCSDSPacket) int | float
Read the raw value from the packet data
- Parameters:
packet (CCSDSPacket) – 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.packets.CCSDSPacket, **kwargs) space_packet_parser.packets.FloatParameter | space_packet_parser.packets.IntParameter
Parse a value from packet data, possibly using previously parsed data items to inform parsing.
- Parameters:
packet (CCSDSPacket) – 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:
- class space_packet_parser.encodings.IntegerDataEncoding(size_in_bits: int, encoding: str, *, byte_order: str = 'mostSignificantByteFirst', default_calibrator: space_packet_parser.calibrators.Calibrator | None = None, context_calibrators: List[space_packet_parser.calibrators.ContextCalibrator] | None = None)
Bases:
NumericDataEncoding<xtce:IntegerDataEncoding>
- _data_return_class
- _get_raw_value(packet: space_packet_parser.packets.CCSDSPacket) int
Read the raw value from the packet data
- Parameters:
packet (CCSDSPacket) – 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_data_encoding_xml_element(element: lxml.etree.Element, ns: dict) IntegerDataEncoding
Create a data encoding object from an <xtce:IntegerDataEncoding> XML element.
- Parameters:
element (ElementTree.Element) – XML element
ns (dict) – XML namespace dict
- Return type:
cls
- class space_packet_parser.encodings.FloatDataEncoding(size_in_bits: int, *, encoding: str = 'IEEE-754', byte_order: str = 'mostSignificantByteFirst', default_calibrator: space_packet_parser.calibrators.Calibrator | None = None, context_calibrators: List[space_packet_parser.calibrators.ContextCalibrator] | None = None)
Bases:
NumericDataEncoding<xtce:FloatDataEncoding>
- _supported_encodings = ['IEEE-754', 'MIL-1750A']
- _data_return_class
- _get_raw_value(packet)
Read the data in as bytes and return a float representation.
- classmethod from_data_encoding_xml_element(element: lxml.etree.Element, ns: dict) FloatDataEncoding
Create a data encoding object from an <xtce:FloatDataEncoding> XML element.
- Parameters:
element (ElementTree.Element) – XML element
ns (dict) – XML namespace dict
- Return type:
cls
- class space_packet_parser.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.comparisons.DiscreteLookup] | None = None, linear_adjuster: callable | None = None)
Bases:
DataEncoding<xtce:BinaryDataEncoding>
- fixed_size_in_bits
- size_reference_parameter
- use_calibrated_value
- size_discrete_lookup_list
- linear_adjuster
- _calculate_size(packet: space_packet_parser.packets.CCSDSPacket) 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.packets.CCSDSPacket, **kwargs) space_packet_parser.packets.BinaryParameter
Parse a value from packet data, possibly using previously parsed data items to inform parsing.
- Parameters:
packet (CCSDSPacket) – 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:
- classmethod from_data_encoding_xml_element(element: lxml.etree.Element, ns: dict) BinaryDataEncoding
Create a data encoding object from an <xtce:BinaryDataEncoding> XML element.
- Parameters:
element (ElementTree.Element) – XML element
ns (dict) – XML namespace dict
- Return type: