space_packet_parser.xtce.encodings ================================== .. py:module:: space_packet_parser.xtce.encodings .. autoapi-nested-parse:: DataEncoding definitions Attributes ---------- .. autoapisummary:: space_packet_parser.xtce.encodings.logger Classes ------- .. autoapisummary:: space_packet_parser.xtce.encodings.DataEncoding space_packet_parser.xtce.encodings.StringDataEncoding space_packet_parser.xtce.encodings.NumericDataEncoding space_packet_parser.xtce.encodings.IntegerDataEncoding space_packet_parser.xtce.encodings.FloatDataEncoding space_packet_parser.xtce.encodings.BinaryDataEncoding Module Contents --------------- .. py:data:: logger .. py:class:: DataEncoding Bases: :py:obj:`space_packet_parser.common.AttrComparable`, :py:obj:`space_packet_parser.common.XmlObject` Abstract base class for XTCE data encodings .. py:method:: get_default_calibrator(data_encoding_element: lxml.etree.Element) -> space_packet_parser.xtce.calibrators.Calibrator | None :staticmethod: Gets the default_calibrator for the data encoding element :param data_encoding_element: The data encoding element which should contain the default_calibrator :type data_encoding_element: ElementTree.Element :rtype: Union[Calibrator, None] .. py:method:: get_context_calibrators(data_encoding_element: lxml.etree.Element) -> list[space_packet_parser.xtce.calibrators.ContextCalibrator] | None :staticmethod: Get the context default_calibrator(s) for the data encoding element :param data_encoding_element: XML element :type data_encoding_element: ElementTree.Element :returns: List of ContextCalibrator objects or None if there are no context calibrators :rtype: Union[List[ContextCalibrator], None] .. py:method:: _get_linear_adjuster(parent_element: lxml.etree.Element) -> collections.abc.Callable | None :staticmethod: Examine a parent (e.g. a ) element and find a LinearAdjustment if present, creating and returning a function that evaluates the adjustment. :param parent_element: Parent element which may contain a LinearAdjustment :type parent_element: ElementTree.Element :returns: **adjuster** -- Function object that adjusts a SizeInBits value by a linear function or None if no adjuster present :rtype: Union[Callable, None] .. py:method:: _calculate_size(packet: space_packet_parser.SpacePacket) -> int Calculate the size of the data item in bits. :param packet: Binary representation of the packet used to get the coming bits and any previously parsed data items to infer field lengths. :type packet: SpacePacket :returns: Size of the data item in bits. :rtype: int .. py:method:: 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. :param packet: Binary representation of the packet used to get the coming bits and any previously parsed data items to infer field lengths. :type packet: SpacePacket :returns: Derived value with a `raw_value` attribute that can be used to get the original packet data. :rtype: common.ParameterDataTypes .. py:class:: 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: collections.abc.Callable | None = None, termination_character: str | None = None, leading_length_size: int | None = None) Bases: :py:obj:`DataEncoding` .. py:attribute:: _supported_encodings :value: ('US-ASCII', 'ISO-8859-1', 'Windows-1252', 'UTF-8', 'UTF-16', 'UTF-16LE', 'UTF-16BE', 'UTF-32',... .. py:attribute:: encoding :value: 'UTF-8' .. py:attribute:: termination_character :value: None .. py:attribute:: fixed_length :value: None .. py:attribute:: leading_length_size :value: None .. py:attribute:: dynamic_length_reference :value: None .. py:attribute:: use_calibrated_value :value: True .. py:attribute:: discrete_lookup_length :value: None .. py:attribute:: length_linear_adjuster :value: None .. py:method:: _calculate_size(packet: space_packet_parser.SpacePacket) -> int Calculate the size of the raw string buffer field :param packet: Partially parsed packet for referencing previous data fields. :type packet: SpacePacket :returns: Size, in bits, of the raw string buffer. :rtype: int .. py:method:: _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. .. rubric:: Notes If the buffer size is not an integer number of bytes, the bytestring is padded at the end with zeros. :param packet: Packet parsed so far, for referencing previous values :type packet: SpacePacket :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. :rtype: bytes .. py:method:: 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. :param packet: Binary representation of the packet used to get the coming bits and any previously parsed data items to infer field lengths. :type packet: SpacePacket :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. :rtype: StrParameter .. py:method:: 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 :classmethod: Create a data encoding object from an XML element. .. rubric:: 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. :param element: XML element :type element: ElementTree.Element :param tree: Ignored :type tree: Optional[ElementTree.Element] :param parameter_lookup: Ignored :type parameter_lookup: Optional[dict] :param parameter_type_lookup: Ignored :type parameter_type_lookup: Optional[dict] :param container_lookup: Ignored :type container_lookup: Optional[dict[str, SequenceContainer]] :rtype: cls .. py:method:: to_xml(*, elmaker: lxml.builder.ElementMaker) -> lxml.etree.Element Create a data encoding XML element :param elmaker: Element factory with predefined namespace :type elmaker: ElementMaker :rtype: ElementTree.Element .. py:class:: 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: :py:obj:`DataEncoding` Abstract class that is inherited by IntegerDataEncoding and FloatDataEncoding .. py:attribute:: _data_return_class .. py:attribute:: size_in_bits .. py:attribute:: encoding .. py:attribute:: byte_order :value: 'mostSignificantByteFirst' .. py:attribute:: default_calibrator :value: None .. py:attribute:: context_calibrators :value: None .. py:method:: _calculate_size(packet: space_packet_parser.SpacePacket) -> int Calculate the size of the data item in bits. :param packet: Binary representation of the packet used to get the coming bits and any previously parsed data items to infer field lengths. :type packet: SpacePacket :returns: Size of the data item in bits. :rtype: int .. py:method:: _get_raw_value(packet: space_packet_parser.SpacePacket) -> int | float :abstractmethod: Read the raw value from the packet data :param packet: Binary representation of the packet used to get the coming bits and any previously parsed data items to infer field lengths. :type packet: SpacePacket :returns: Raw value :rtype: int .. py:method:: _twos_complement(val: int, bit_width: int) -> int :staticmethod: Take the twos complement of val Used when parsing ints and some floats .. py:method:: 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. :param packet: Binary representation of the packet used to get the coming bits and any previously parsed data items to infer field lengths. :type packet: SpacePacket :returns: Parsed data item as either a float or integer depending on the type of encoding. :rtype: common.FloatParameter or common.IntParameter .. py:method:: to_xml(*, elmaker: lxml.builder.ElementMaker) -> lxml.etree.Element Create a data encoding XML element :param elmaker: Element factory with predefined namespace :type elmaker: ElementMaker :rtype: ElementTree.Element .. py:class:: 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: :py:obj:`NumericDataEncoding` .. py:attribute:: _encodings :value: ('unsigned', 'signed', 'twosCompliment', 'twosComplement') .. py:attribute:: _byte_orders :value: ('leastSignificantByteFirst', 'mostSignificantByteFirst') .. py:attribute:: _data_return_class .. py:method:: _get_raw_value(packet: space_packet_parser.SpacePacket) -> int Read the raw value from the packet data :param packet: Binary representation of the packet used to get the coming bits and any previously parsed data items to infer field lengths. :type packet: SpacePacket :returns: Raw value :rtype: int .. py:method:: 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 :classmethod: Create a data encoding object from an XML element. :param element: XML element :type element: ElementTree.Element :param tree: Ignored :type tree: Optional[ElementTree.Element] :param parameter_lookup: Ignored :type parameter_lookup: Optional[dict] :param parameter_type_lookup: Ignored :type parameter_type_lookup: Optional[dict] :param container_lookup: Ignored :type container_lookup: Optional[dict[str, SequenceContainer]] :rtype: cls .. py:class:: 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: :py:obj:`NumericDataEncoding` .. py:attribute:: _allowed_encodings :value: ['IEEE754_1985', 'IEEE754', 'MILSTD_1750A', 'DEC', 'IBM', 'TI'] .. py:attribute:: _supported_encodings :value: ['IEEE754_1985', 'IEEE754', 'MILSTD_1750A'] .. py:attribute:: _data_return_class .. py:method:: _get_raw_value(packet) Read the data in as bytes and return a float representation. .. py:method:: 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 :classmethod: Create a data encoding object from an XML element. :param element: XML element :type element: ElementTree.Element :param tree: Ignored :type tree: Optional[ElementTree.Element] :param parameter_lookup: Ignored :type parameter_lookup: Optional[dict] :param parameter_type_lookup: Ignored :type parameter_type_lookup: Optional[dict] :param container_lookup: Ignored :type container_lookup: Optional[dict[str, SequenceContainer]] :rtype: cls .. py:class:: 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: collections.abc.Callable | None = None) Bases: :py:obj:`DataEncoding` .. py:attribute:: fixed_size_in_bits :value: None .. py:attribute:: size_reference_parameter :value: None .. py:attribute:: use_calibrated_value :value: True .. py:attribute:: size_discrete_lookup_list :value: None .. py:attribute:: linear_adjuster :value: None .. py:method:: _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 :rtype: Union[str, None] .. py:method:: 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. :param packet: Binary representation of the packet used to get the coming bits and any previously parsed data items to infer field lengths. :type packet: SpacePacket :returns: Parsed binary data item. :rtype: common.BinaryParameter .. py:method:: 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 :classmethod: Create a data encoding object from an XML element. :param element: XML element :type element: ElementTree.Element :param tree: Ignored :type tree: Optional[ElementTree.Element] :param parameter_lookup: Ignored :type parameter_lookup: Optional[dict] :param parameter_type_lookup: Ignored :type parameter_type_lookup: Optional[dict] :param container_lookup: Ignored :type container_lookup: Optional[dict[str, SequenceContainer]] :rtype: BinaryDataEncoding .. py:method:: to_xml(*, elmaker: lxml.builder.ElementMaker) -> lxml.etree.Element Create a data encoding XML element :param elmaker: Element factory with predefined namespace :type elmaker: ElementMaker :rtype: ElementTree.Element