space_packet_parser.packets =========================== .. py:module:: space_packet_parser.packets .. autoapi-nested-parse:: Packet containers and parsing utilities for space packets. Attributes ---------- .. autoapisummary:: space_packet_parser.packets.BuiltinDataTypes space_packet_parser.packets.ParameterDataTypes Classes ------- .. autoapisummary:: space_packet_parser.packets._Parameter space_packet_parser.packets.BinaryParameter space_packet_parser.packets.BoolParameter space_packet_parser.packets.FloatParameter space_packet_parser.packets.IntParameter space_packet_parser.packets.StrParameter space_packet_parser.packets.RawPacketData space_packet_parser.packets.CCSDSPacket space_packet_parser.packets.Parseable space_packet_parser.packets.SequenceContainer Functions --------- .. autoapisummary:: space_packet_parser.packets._extract_bits Module Contents --------------- .. py:data:: BuiltinDataTypes .. py:class:: _Parameter Mixin class for storing access to the raw value of a parsed data item. The raw value is the closest representation of the data item as it appears in the packet. e.g. bytes for binary data, int for integer data, etc. It has not been calibrated or adjusted in any way and is an easy way for user's to debug the transformations that happened after the fact. .. rubric:: Notes We need to override the __new__ method to store the raw value of the data item on immutable built-in types. So this is just a way of allowing us to inject our own attribute into the built-in types. .. py:class:: BinaryParameter Bases: :py:obj:`_Parameter`, :py:obj:`bytes` A class to represent a binary data item. .. py:class:: BoolParameter Bases: :py:obj:`_Parameter`, :py:obj:`int` A class to represent a parsed boolean data item. .. py:method:: __repr__() -> str Return repr(self). .. py:class:: FloatParameter Bases: :py:obj:`_Parameter`, :py:obj:`float` A class to represent a float data item. .. py:class:: IntParameter Bases: :py:obj:`_Parameter`, :py:obj:`int` A class to represent a integer data item. .. py:class:: StrParameter Bases: :py:obj:`_Parameter`, :py:obj:`str` A class to represent a string data item. .. py:data:: ParameterDataTypes .. py:class:: RawPacketData(data: bytes, *, pos: int = 0) Bases: :py:obj:`bytes` A class to represent raw packet data as bytes but whose length is represented by bit length. This class is a subclass of bytes and is used to represent the raw packet data in a more readable way. It is used to store the raw packet data in the Packet class and used to keep track of the current parsing position. :param data: Raw packet data. Full CCSDS packets are always an integer number of bytes. :type data: bytes .. py:attribute:: pos .. py:attribute:: _nbits .. py:method:: __len__() Return len(self). .. py:method:: __repr__() Return repr(self). .. py:method:: read_as_bytes(nbits: int) -> bytes Read a number of bits from the packet data as bytes. Reads minimum number of complete bytes required to capture `nbits`. Moves `pos` cursor `nbits` forward, even if `nbits` is not an integer number of bytes. :param nbits: Number of bits to read :type nbits: int :returns: Raw bytes from the packet data :rtype: bytes .. py:method:: read_as_int(nbits: int) -> int Read a number of bits from the packet data as an integer. :param nbits: Number of bits to read :type nbits: int :returns: Integer representation of the bits read from the packet :rtype: int .. py:class:: CCSDSPacket(*args, raw_data: bytes = b'', **kwargs) Bases: :py:obj:`dict` CCSDS Packet Container that stores the raw packet data (bytes) as an instance attribute and the parsed data items in a dict interface. A ``CCSDSPacket`` generally begins as an empty dictionary that gets filled as the packet is parsed. The first 7 items in the dictionary make up the packet header (accessed with ``CCSDSPacket.header``), and the rest of the items make up the user data (accessed with ``CCSDSPacket.user_data``). To access the raw bytes of the packet, use the ``CCSDSPacket.raw_data`` attribute. :param \*args: Initial items to store in the packet, passed to the dict() constructor. :type \*args: Mapping or Iterable :param raw_data: The binary data for a single packet. :type raw_data: bytes, optional :param \*\*kwargs: Additional packet items to store, passed to the dict() constructor. :type \*\*kwargs: dict .. py:attribute:: raw_data .. py:property:: header :type: dict The header content of the packet. .. py:property:: user_data :type: dict The user data content of the packet. .. py:class:: Parseable Bases: :py:obj:`Protocol` Defines an object that can be parsed from packet data. .. py:method:: parse(packet: CCSDSPacket, **parse_value_kwargs) -> None Parse this entry from the packet data and add the necessary items to the packet. .. py:class:: SequenceContainer Bases: :py:obj:`Parseable` :param name: Container name :type name: str :param entry_list: List of Parameter objects :type entry_list: list :param long_description: Long description of the container :type long_description: str :param base_container_name: Name of the base container from which this may inherit if restriction criteria are met. :type base_container_name: str :param restriction_criteria: A list of MatchCriteria elements that evaluate to determine whether the SequenceContainer should be included. :type restriction_criteria: list :param abstract: True if container has abstract=true attribute. False otherwise. :type abstract: bool :param inheritors: List of SequenceContainer objects that may inherit this one's entry list if their restriction criteria are met. Any SequenceContainers with this container as base_container_name should be listed here. :type inheritors: list, Optional .. py:attribute:: name :type: str .. py:attribute:: entry_list :type: list .. py:attribute:: short_description :type: Optional[str] :value: None .. py:attribute:: long_description :type: Optional[str] :value: None .. py:attribute:: base_container_name :type: Optional[str] :value: None .. py:attribute:: restriction_criteria :type: Optional[list] .. py:attribute:: abstract :type: bool :value: False .. py:attribute:: inheritors :type: Optional[List[SequenceContainer]] .. py:method:: __post_init__() .. py:method:: parse(packet: CCSDSPacket, **parse_value_kwargs) -> None Parse the entry list of parameters/containers in the order they are expected in the packet. This could be recursive if the entry list contains SequenceContainers. .. py:function:: _extract_bits(data: bytes, start_bit: int, nbits: int) Extract nbits from the data starting from the least significant end. If data = 00110101 11001010, start_bit = 2, nbits = 9, then the bits extracted are "110101110". Those bits are turned into a Python integer and returned. :param data: Data to extract bits from :type data: bytes :param start_bit: Starting bit location within the data :type start_bit: int :param nbits: Number of bits to extract :type nbits: int :returns: Extracted bits as an integer :rtype: int