space_packet_parser.generators.ccsds
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
Classes
Enumeration of the possible sequence flags in a CCSDS packet. |
|
Binary (bytes) representation of a CCSDS packet. |
|
Packet representing parsed data items from CCSDS packet(s). DEPRECATED |
Functions
|
Create a binary CCSDS packet from input values. |
|
A generator that reads raw packet data from a filelike object or a socket. |
Module Contents
- space_packet_parser.generators.ccsds.logger
- class space_packet_parser.generators.ccsds.SequenceFlags
Bases:
enum.IntEnumEnumeration of the possible sequence flags in a CCSDS packet.
- CONTINUATION = 0
- FIRST = 1
- LAST = 2
- UNSEGMENTED = 3
- class space_packet_parser.generators.ccsds.CCSDSPacketBytes
Bases:
bytesBinary (bytes) representation of a CCSDS packet.
Methods to extract the header fields are added to the raw bytes object.
- HEADER_LENGTH_BYTES = 6
- __str__() str
Return str(self).
- property version_number: int
CCSDS Packet Version Number
- property type: int
CCSDS Packet Type
0 = Telemetry Packet 1 = Telecommand Packet
- property secondary_header_flag: int
CCSDS Secondary Header Flag
0 = No secondary header 1 = Secondary header present
- property apid: int
CCSDS Application Process Identifier (APID)
- property sequence_flags: int
CCSDS Packet Sequence Flags
00 = Continuation packet 01 = First packet 10 = Last packet 11 = Unsegmented packet (standalone)
- property sequence_count: int
CCSDS Packet Sequence Count
- property data_length: 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
- property header_values: tuple[int, Ellipsis]
Convenience property for tuple of header values
- property header: bytes
Convenience property returns the CCSDS header bytes
- space_packet_parser.generators.ccsds.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.
- Parameters:
data (bytes) – User data bytes (up to 65536 bytes)
version_number (int) – CCSDS Packet Version Number (3 bits)
type (int) – CCSDS Packet Type (1 bit)
secondary_header_flag (int) – CCSDS Secondary Header Flag (1 bit)
apid (int) – CCSDS Application Process Identifier (APID) (11 bits)
sequence_flags (int) – CCSDS Packet Sequence Flags (2 bits)
sequence_count (int) – CCSDS Packet Sequence Count (14 bits)
- Returns:
Resulting binary packet
- Return type:
Notes
This function is extremely useful for generating test packets for debugging or mocking purposes.
- class space_packet_parser.generators.ccsds.CCSDSPacket(*args, **kwargs)
Bases:
space_packet_parser.common.SpacePacketPacket 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
CCSDSPacketgenerally 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 withCCSDSPacket.header), and the rest of the items make up the user data (accessed withCCSDSPacket.user_data). To access the raw bytes of the packet, use theCCSDSPacket.binary_dataattribute.
- space_packet_parser.generators.ccsds.ccsds_generator(binary_data: BinaryIO | socket.socket | bytes, *, buffer_read_size_bytes: int | None = 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
CCSDSPacketBytesobject 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.- Parameters:
binary_data (Union[BinaryIO, socket.socket, bytes]) – Binary data source containing CCSDSPackets.
buffer_read_size_bytes (int, optional) – 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.
show_progress (bool) – Default False. If True, prints a status bar. Note that for socket sources, the percentage will be zero until the generator ends.
skip_header_bytes (int) – 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.
combine_segmented_packets (bool) – 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.
secondary_header_bytes (int) – 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, …].
- Yields:
CCSDSPacketBytes – The bytes of a single CCSDS packet.