space_packet_parser.generators.ccsds ==================================== .. py:module:: space_packet_parser.generators.ccsds .. autoapi-nested-parse:: Packet generator utilities for CCSDS packets. The parsing begins with binary data representing CCSDS Packets. A user can then create a generator from the binary data reading from a filelike object or a socket. The ``ccsds_generator`` function yields ``CCSDSPacketBytes`` objects that are the raw binary data of a single CCSDS packet. The ``CCSDSPacketBytes`` class can be used to inspect the CCSDS header fields of the packet, but it does not have any parsed content from the data field. This generator is useful for debugging and passing off to other parsing functions. Attributes ---------- .. autoapisummary:: space_packet_parser.generators.ccsds.logger Classes ------- .. autoapisummary:: space_packet_parser.generators.ccsds.SequenceFlags space_packet_parser.generators.ccsds.CCSDSPacketBytes space_packet_parser.generators.ccsds.CCSDSPacket Functions --------- .. autoapisummary:: space_packet_parser.generators.ccsds.create_ccsds_packet space_packet_parser.generators.ccsds.ccsds_generator Module Contents --------------- .. py:data:: logger .. py:class:: SequenceFlags Bases: :py:obj:`enum.IntEnum` Enumeration of the possible sequence flags in a CCSDS packet. .. py:attribute:: CONTINUATION :value: 0 .. py:attribute:: FIRST :value: 1 .. py:attribute:: LAST :value: 2 .. py:attribute:: UNSEGMENTED :value: 3 .. py:class:: CCSDSPacketBytes Bases: :py:obj:`bytes` Binary (bytes) representation of a CCSDS packet. Methods to extract the header fields are added to the raw bytes object. .. py:attribute:: HEADER_LENGTH_BYTES :value: 6 .. py:method:: __str__() -> str Return str(self). .. py:property:: version_number :type: int CCSDS Packet Version Number .. py:property:: type :type: int CCSDS Packet Type 0 = Telemetry Packet 1 = Telecommand Packet .. py:property:: secondary_header_flag :type: int CCSDS Secondary Header Flag 0 = No secondary header 1 = Secondary header present .. py:property:: apid :type: int CCSDS Application Process Identifier (APID) .. py:property:: sequence_flags :type: int CCSDS Packet Sequence Flags 00 = Continuation packet 01 = First packet 10 = Last packet 11 = Unsegmented packet (standalone) .. py:property:: sequence_count :type: int CCSDS Packet Sequence Count .. py:property:: data_length :type: int CCSDS Packet Data Length Section 4.1.3.5.3 The length count C shall be expressed as: C = (Total Number of Octets in the Packet Data Field) - 1 .. py:property:: header_values :type: tuple[int, Ellipsis] Convenience property for tuple of header values .. py:property:: header :type: bytes Convenience property returns the CCSDS header bytes .. py:property:: user_data :type: bytes Convenience property returns only the user data bytes (no header) Notes: ------ This includes the secondary header, if present .. py:function:: create_ccsds_packet(data=b'\x00', *, version_number=0, type=0, secondary_header_flag=0, apid=2047, sequence_flags=SequenceFlags.UNSEGMENTED, sequence_count=0) -> CCSDSPacketBytes Create a binary CCSDS packet from input values. Pack the header fields into the proper bit locations and append the data bytes. :param data: User data bytes (up to 65536 bytes) :type data: bytes :param version_number: CCSDS Packet Version Number (3 bits) :type version_number: int :param type: CCSDS Packet Type (1 bit) :type type: int :param secondary_header_flag: CCSDS Secondary Header Flag (1 bit) :type secondary_header_flag: int :param apid: CCSDS Application Process Identifier (APID) (11 bits) :type apid: int :param sequence_flags: CCSDS Packet Sequence Flags (2 bits) :type sequence_flags: int :param sequence_count: CCSDS Packet Sequence Count (14 bits) :type sequence_count: int :returns: Resulting binary packet :rtype: CCSDSPacketBytes .. rubric:: Notes This function is extremely useful for generating test packets for debugging or mocking purposes. .. py:class:: CCSDSPacket(*args, **kwargs) Bases: :py:obj:`space_packet_parser.common.SpacePacket` Packet representing parsed data items from CCSDS packet(s). DEPRECATED This class is deprecated and will be removed in a future release. Use the SpacePacket class instead. In an XTCE representation, there is no guarantee that the CCSDS packet header will be defined as individual elements. If you want to access those elements, you can use the CCSDSPacketBytes class to extract the header fields with specific methods. Container that stores the raw packet data (bytes) as an instance attribute and the parsed data items in a dictionary 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.binary_data`` attribute. .. py:function:: ccsds_generator(binary_data: Union[BinaryIO, socket.socket, bytes], *, buffer_read_size_bytes: Optional[int] = None, show_progress: bool = False, skip_header_bytes: int = 0, combine_segmented_packets: bool = False, secondary_header_bytes: int = 0) -> collections.abc.Iterator[CCSDSPacketBytes] A generator that reads raw packet data from a filelike object or a socket. Each iteration of the generator yields a ``CCSDSPacketBytes`` object that makes up a single CCSDS packet. If combining segmented packets is enabled, the generator will combine segmented packets into a single packet for parsing. This is useful for parsing packets that are split into multiple packets due to size constraints. :param binary_data: Binary data source containing CCSDSPackets. :type binary_data: Union[BinaryIO, socket.socket, bytes] :param buffer_read_size_bytes: Number of bytes to read from e.g. a BufferedReader or socket binary data source on each read attempt. If None, defaults to 4096 bytes from a socket, -1 (full read) from a file. :type buffer_read_size_bytes: int, optional :param show_progress: Default False. If True, prints a status bar. Note that for socket sources, the percentage will be zero until the generator ends. :type show_progress: bool :param skip_header_bytes: Default 0. The parser skips this many bytes at the beginning of every packet. This allows dynamic stripping of additional header data that may be prepended to packets in "raw record" file formats. :type skip_header_bytes: int :param combine_segmented_packets: Default False. If True, combines segmented packets into a single packet for parsing. This is useful for parsing packets that are split into multiple packets due to size constraints. The packet data is combined by concatenating the data from each packet together. The combined packet is then parsed as a single packet. Only the first CCSDS header is kept when concatenating continued packets. CCSDS headers (and secondary headers) from continuation packets are discarded. :type combine_segmented_packets: bool :param secondary_header_bytes: Default 0. The length of the secondary header in bytes. This is used to skip the secondary header of segmented packets. The byte layout within the returned packet has all data concatenated together as follows: [packet0header, packet0secondaryheader, packet0data, packet1data, packet2data, ...]. :type secondary_header_bytes: int :Yields: *CCSDSPacketBytes* -- The bytes of a single CCSDS packet.