minsp.core module

The minsp.core module provides the package core functions and classes.

class minsp.core.PacketType(*values)

Bases: int, Enum

Enum to represent a space packet type: telemetry (TM) or telecommand (TC).

TM = 0
TC = 1
TC = 1
TM = 0
class minsp.core.SequenceFlags(*values)

Bases: int, Enum

Enum to represent the sequece flags of a space packet.

CONTINUATION = 0
FIRST = 1
LAST = 2
UNSEGMENTED = 3
CONTINUATION = 0
FIRST = 1
LAST = 2
UNSEGMENTED = 3
class minsp.core.SpacePacket(version: int = 0, type: PacketType = PacketType.TM, secondary_header_flag: int = 0, apid: int = 0, sequence_flags: SequenceFlags = SequenceFlags.UNSEGMENTED, sequence_count: int = 0, data_length: int = 0, secondary_header: bytes | PUSHeader | MALHeader = b'', data_field: bytes = b'')

Bases: object

Represents a CCSDS Space Packet (including primary header, optional secondary header, and data field).

According to the CCSDS standard: * The primary header is 6 bytes long and contains version, packet type, APID, sequence info, and length. * The secondary header can be an custom stream of bytes, and instance of PUSheader or an instance of MALHeader. * The data length field (data_length) defines the number of bytes after the primary header minus one. * This class allows serialization to and from byte streams.

Parameters:
  • version (int) – Packet version, default is 0 (3 bits).

  • type (PacketType) – Packet type, default is PacketType.TM (1 bit).

  • secondary_header_flag (int) – Secondary header flag, default is 0 (1 bit).

  • apid (int) – Application process identifier, default is 0 (11 bits).

  • sequence_flags (SequenceFlag) – Sequence flags, default is SequenceFlag.UNSEGMENTED (2 bits).

  • sequence_count (int) – Sequence count, default is 0 (14 bits).

  • data_length – Packet data field length of the data following

the primary header minus one, defaults is 0 (16 bits). :param secondary_header: Secondary header. :type secondary_header: bytes|`PUSHeader`|`MALHeader` :param data_field: Packet data. :type data_field: bytes

apid: int = 0
as_bytes() bytes

Packs the space packet into a byte stream, including: - Primary header (6 bytes) - Optional secondary header - Data field

Returns:

Space packet bytes.

Return type:

bytes

data_field: bytes = b''
data_length: int = 0
classmethod from_bytes(data: bytes, secondary_header_length: int = 0, pus: bool = False, mal: bool = False) SpacePacket

Unpacks a byte stream into a SpacePacket instance.

Parameters:
  • data (bytes) – The byte stream.

  • secondary_header_length (int) – Secondary header length if present, default is 0.

  • pus (bool) – Secondary header is a PUS header.

  • pus – Secondary header is a MAL header.

Raises:
  • ValueError – Insufficient data for space packet primary header.

  • ValueError – Secondary header flag bit is set to 1, but secondary header length is 0.

Returns:

A new SpacePacket.

Return type:

SpacePacket

classmethod header_from_bytes(data: bytes) dict

Unpacks a space packt header from a byte.

Parameters:

data (bytes) – The byte stream.

Raises:

ValueError – Insufficient data for space packet primary header.

Returns:

A new dict.

Return type:

dict

secondary_header: bytes | PUSHeader | MALHeader = b''
secondary_header_flag: int = 0
sequence_count: int = 0
sequence_flags: SequenceFlags = 3
type: PacketType = 0
version: int = 0
class minsp.core.SpacePacketAssembler

Bases: object

Assembles the payload from segmented space packets.

classmethod from_packets(packets: list[SpacePacket]) bytes | None

Assembles the payload from segmented space packets.

Parameters:

packets (list[SpacePacket]) – A list of SpacePacket.

Returns:

The payload.

Return type:

bytes | None

process_packet(packet: SpacePacket) bytes | None

Process a individual space packet.

Raises:
  • RuntimeError – Continuation received without first segment.

  • RuntimeError – Last segment received without segment.

Returns:

Optional payload found.

Return type:

bytes | None