ECSS Package

The following classes can be used to create and read ECSS PUS-C packets:

  • spacepackets.ecss.PusTc

  • spacepackets.ecss.PusTm

ECSS Fields

class spacepackets.ecss.fields.PacketFieldBase(ptc: 'int', pfc: 'int')

Bases: object

pfc: int
ptc: int
class spacepackets.ecss.fields.PacketFieldEnum(pfc: int, val: int)

Bases: PacketFieldBase

static check_pfc(pfc: int) int

Check for byte alignment of the PFC. Do not use this if to plan to pack multiple enumerations into one byte

len() int

Return the length in bytes. This will raise a ValueError for non-byte-aligned PFC values.

pack() bytearray
classmethod unpack(data: bytes | bytearray, pfc: int) PacketFieldEnum

Construct from a raw bytestream.

Raises:

BytesTooShortError – Raw bytestream too short.

classmethod with_byte_size(num_bytes: int, val: int) PacketFieldEnum
class spacepackets.ecss.fields.PacketFieldU16(val: int)

Bases: PacketFieldEnum

class spacepackets.ecss.fields.PacketFieldU32(val: int)

Bases: PacketFieldEnum

class spacepackets.ecss.fields.PacketFieldU8(val: int)

Bases: PacketFieldEnum

class spacepackets.ecss.fields.PfcReal(value)

Bases: IntEnum

An enumeration.

DOUBLE_PRECISION_IEEE = 2
DOUBLE_PRECISION_MIL_STD_6_OCTETS = 4
FLOAT_PRECISION_MIL_STD_4_OCTETS = 3
FLOAT_SIMPLE_PRECISION_IEEE = 1
class spacepackets.ecss.fields.PfcSigned(value)

Bases: IntEnum

An enumeration.

EIGHT_BYTES = 16
ELEVEN_BIT = 7
FIFTEEN_BIT = 11
FIVE_BIT = 1
FOURTEEN_BIT = 10
FOUR_BIT = 0
FOUR_BYTES = 14
NINE_BIT = 5
ONE_BYTE = 4
SEVEN_BIT = 3
SIX_BIT = 2
SIX_BYTES = 15
TEN_BIT = 6
THIRTEEN_BIT = 9
THREE_BYTES = 13
TWELVE_BIT = 8
TWO_BYTES = 12
class spacepackets.ecss.fields.PfcUnsigned(value)

Bases: IntEnum

An enumeration.

EIGHT_BYTES = 16
ELEVEN_BIT = 7
FIFTEEN_BIT = 11
FIVE_BIT = 1
FOURTEEN_BIT = 10
FOUR_BIT = 0
FOUR_BYTES = 14
NINE_BIT = 5
ONE_BIT = 17
ONE_BYTE = 4
SEVEN_BIT = 3
SIX_BIT = 2
SIX_BYTES = 15
TEN_BIT = 6
THIRTEEN_BIT = 9
THREE_BIT = 19
THREE_BYTES = 13
TWELVE_BIT = 8
TWO_BIT = 18
TWO_BYTES = 12
class spacepackets.ecss.fields.Ptc(value)

Bases: IntEnum

An enumeration.

ABSOLUTE_TIME = 9
BIT_STRING = 6
BOOLEAN = 1
CHARACTER_STRING = 8
DEDUCED = 11
ENUMERATED = 2
OCTET_STRING = 7
PACKET = 12
REAL = 5
RELATIVE_TIME = 10
SIGNED = 4
UNSIGNED = 3

ECSS TC Submodule

This module contains the PUS telecommand class representation to pack telecommands, most notably the PusTelecommand class.

exception spacepackets.ecss.tc.InvalidTcCrc16Error(tc: PusTc | None)

Bases: Exception

class spacepackets.ecss.tc.PusTc(service: int, message_subtype: int | None = None, has_checksum: bool = True, apid: int = 0, app_data: bytes | bytearray = b'', seq_count: int = 0, source_id: int = 0, ack_flags: int = 15, subservice: int | None = None)

Bases: AbstractSpacePacket

Class representation of a PUS telecommand. Can be converted to the raw byte representation but also unpacked from a raw byte stream. Only PUS C telecommands are supported.

>>> ping_tc = PusTc(service=17, message_subtype=1, seq_count=22, apid=0x01)
>>> ping_tc.service
17
>>> ping_tc.message_subtype
1
>>> ping_tc.pack().hex(sep=',')
'18,01,c0,16,00,06,2f,11,01,00,00,ab,62'

Initiate a PUS telecommand from the given parameters. The raw byte representation can then be retrieved with the pack() function.

Parameters:
  • service – PUS service number

  • message_subtype – PUS message subtype number

  • apid – Application Process ID as specified by CCSDS

  • seq_count – Source Sequence Count. Application should take care of incrementing this. Limited to 2 to the power of 14 by the number of bits in the header

  • app_data – Application data in the Packet Data Field

  • source_id – Source ID will be supplied as well. Can be used to distinguish different packet sources (e.g. different ground stations)

Raises:

ValueError – Invalid input parameters

property apid: int
property app_data: bytes
calc_crc() None

Can be called to calculate the CRC16. Also sets the internal CRC16 field.

property ccsds_version: int
property crc16: bytes | None

Will be the raw CRC16 if the telecommand was created using unpack(), pack() was called at least once or calc_crc() was called at least once.

classmethod empty() PusTc
classmethod from_composite_fields(sp_header: SpacePacketHeader, sec_header: PusTcDataFieldHeader, app_data: bytes = b'', has_checksum: bool = True) PusTc
classmethod from_sp_header(sp_header: SpacePacketHeader, service: int, message_subtype: int | None = None, app_data: bytes = b'', source_id: int = 0, ack_flags: int = 15, has_checksum: bool = True, subservice: int | None = None) PusTc
static get_data_length(app_data_len: int, secondary_header_len: int, has_checksum: bool) int

Retrieve size of TC packet in bytes. Formula according to PUS Standard: C = (Number of octets in packet data field) - 1. The size of the TC packet is the size of the packet secondary header with source ID + the length of the application data + length of the CRC16 checksum - 1

property has_checksum: bool
property message_subtype: int
pack(recalc_crc: bool = True) bytearray

Serializes the TC data fields into a bytearray.

Parameters:

recalc_crc – Can be set to False if the CRC was previous calculated and no fields were changed. This is set to True by default to ensure the CRC is always valid by default, even if the user changes arbitrary fields after TC creation.

pack_command_tuple() tuple[bytearray, PusTc]

Pack a tuple consisting of the raw packet as the first entry and the class representation as the second entry

Deprecated since version v0.14.0rc3: use pack and the class itself to build this instead

property packet_id: PacketId
property packet_len: int

Retrieve the full packet size when packed :return: Size of the TM packet based on the space packet header data length field. The space packet data field is the full length of data field minus one without the space packet header.

property packet_seq_control: PacketSeqCtrl
property seq_count: int
property service: int
property source_id: int
property subservice: int

Deprecated since version v0.32.0: use message_subtype property instead

to_space_packet() SpacePacket

Retrieve the generic CCSDS space packet representation. This also calculates the CRC16 before converting the PUS TC to a generic Space Packet

classmethod unpack(data: bytes | bytearray) PusTc

Create an instance from a raw bytestream, expecting a checksum and verifying it as well.

Raises:
classmethod unpack_generic(data: bytes | bytearray, has_checksum: bool, verify_checksum: bool) PusTc

Create an instance from a raw bytestream.

Raises:
classmethod unpack_no_checksum(data: bytes | bytearray) PusTc

Create an instance from a raw bytestream with no checksum.

Raises:
class spacepackets.ecss.tc.PusTcDataFieldHeader(service: int, message_subtype: int | None = None, source_id: int = 0, ack_flags: int = 15, subservice: int | None = None)

Bases: object

Create a PUS TC data field header instance

Parameters:
  • service

  • message_subtype

  • source_id

  • ack_flags

PUS_C_SEC_HEADER_LEN = 5
classmethod get_header_size() int
pack() bytearray
property subservice: int

Deprecated since version v0.32.0: use message_subtype property instead

classmethod unpack(data: bytes | bytearray) PusTcDataFieldHeader

Unpack a TC data field header.

Parameters:

data – Start of raw data belonging to the TC data field header

Raises:

BytesTooShortError – Passed data too short.

Returns:

spacepackets.ecss.tc.PusTelecommand

alias of PusTc

spacepackets.ecss.tc.generate_crc(data: bytearray) bytes

Takes the application data, appends the CRC16 checksum and returns resulting bytearray

spacepackets.ecss.tc.generate_packet_crc(tc_packet: bytearray) bytes

Removes current Packet Error Control, calculates new CRC16 checksum and adds it as correct Packet Error Control Code. Reference: ECSS-E70-41A p. 207-212

ECSS TM Submodule

This module contains import PUS TM packet classes, most notably the spacepackets.ecss.tm.PusTelemetry class.

class spacepackets.ecss.tm.AbstractPusTm

Bases: AbstractSpacePacket

Generic abstraction for PUS TM packets

get_sp_header() SpacePacketHeader

Deprecated since version v0.14.0rc2: use sp_header property instead

property message_subtype: int
abstract property service: int
abstract property source_data: bytes
abstract property sp_header: SpacePacketHeader
property subservice: int
abstract property timestamp: bytes
exception spacepackets.ecss.tm.InvalidTmCrc16Error(tm: PusTm)

Bases: Exception

class spacepackets.ecss.tm.ManagedParams(timestamp_len: int, has_checksum: bool = True, verify_checksum: bool = True)

Bases: object

Managed parameters are used defined and are usually fixed for a given mission.

has_checksum: bool = True
timestamp_len: int
verify_checksum: bool = True
class spacepackets.ecss.tm.MiscParams(spacecraft_time_ref: 'int' = 0, packet_version: 'int' = 0)

Bases: object

packet_version: int = 0
spacecraft_time_ref: int = 0
spacepackets.ecss.tm.PusTelemetry

alias of PusTm

class spacepackets.ecss.tm.PusTm(service: int, message_subtype: int | None = None, timestamp: bytes | bytearray = b'', has_checksum: bool = True, source_data: bytes | bytearray = b'', apid: int = 0, seq_count: int = 0, message_counter: int = 0, destination_id: int = 0, misc_params: MiscParams | None = None, subservice: int | None = None)

Bases: AbstractPusTm

Generic PUS telemetry class representation.

Can be used to generate TM packets using a high level interface with the default constructor, or to deserialize TM packets from a raw byte stream using the unpack() method. This implementation only supports PUS C.

Deserialization of PUS telemetry requires the timestamp length to be known. If the size of the timestamp is variable but can be determined from the data, a look-ahead should be performed on the raw data. The PUS_TM_TIMESTAMP_OFFSET (13) can be used to do this, assuming that the timestamp length can be extracted from the timestamp itself.

The following doc example cuts off the timestamp (7 byte CDS Short) and the CRC16 from the ping packet because those change regularly.

>>> ping_tm = PusTm(service=17, message_subtype=2, seq_count=5, apid=0x01, timestamp=CdsShortTimestamp.now().pack())
>>> ping_tm.service
17
>>> ping_tm.message_subtype
2
>>> ping_tm.pack()[:-9].hex(sep=',')
'08,01,c0,05,00,0f,20,11,02,00,00,00,00'
CDS_SHORT_SIZE = 7
PUS_TIMESTAMP_SIZE = 7
property apid: int
calc_crc() None

Can be called to calculate the CRC16

property ccsds_version: int
property crc16: bytes | None

Will be the raw CRC16 if the telecommand was created using unpack() or pack() was called at least once.

static data_len_from_src_len_timestamp_len(timestamp_len: int, source_data_len: int, has_checksum: bool) int

Retrieve size of TM packet data header in bytes. Only support PUS C Formula according to PUS Standard: C = (Number of octets in packet source data field) - 1. The size of the TM packet is the size of the packet secondary header with the timestamp + the length of the application data + PUS timestamp size + length of the CRC16 checksum - 1

Parameters:
  • source_data_len – Length of the source (user) data

  • timestamp_len – Length of the used timestamp

classmethod empty() PusTm
classmethod from_composite_fields(sp_header: SpacePacketHeader, sec_header: PusTmSecondaryHeader, tm_data: bytes, has_checksum: bool = True) PusTm
get_full_packet_string(print_format: PrintFormats = PrintFormats.HEX) str

Deprecated since version 0.14.0rc3: use pack and get_printable_data_string or the hex method on bytearray instead

get_source_data_string(print_format: PrintFormats = PrintFormats.HEX) str

Returns the source data string

Deprecated since version 0.14.0rc3: use the source_data property and the hex method on bytearray instead

property has_checksum: bool
property message_subtype: int

Get the message subtype ID :return: Message subtype ID

pack(recalc_crc: bool = True) bytearray

Serializes the packet into a raw bytearray.

Parameters:

recalc_crc – Can be set to False if the CRC was previous calculated and no fields were changed. This is set to True by default to ensure the CRC is always valid by default, even if the user changes arbitrary fields after TM creation.

property packet_id: PacketId
property packet_len: int

Retrieve the full packet size when packed :return: Size of the TM packet based on the space packet header data length field. The space packet data field is the full length of data field minus one without the space packet header.

property packet_seq_control: PacketSeqCtrl
print_full_packet_string(print_format: PrintFormats = PrintFormats.HEX) None

Print the full TM packet in a clean format.

Deprecated since version 0.14.0rc3: use pack and get_printable_data_string or the hex method on bytearray instead

print_source_data(print_format: PrintFormats = PrintFormats.HEX) None

Prints the TM source data in a clean format

Deprecated since version 0.14.0rc3: use print, the source_data property and the hex method on bytearray instead

property seq_count: int

Get the source sequence count :return: Source Sequence Count (see below, or PUS documentation)

property seq_flags: SequenceFlags
property service: int

Get the service type ID :return: Service ID

static service_from_bytes(raw_bytearray: bytearray) int

Determine the service ID from a raw packet, which can be used for packet deserialization.

It is assumed that the user already checked that the raw bytearray contains a PUS packet and only basic sanity checks will be performed. :raise ValueError: If raw bytearray is too short

property source_data: bytes
property sp_header: SpacePacketHeader
property subservice: int

Get the subservice ID :return: Subservice ID

Deprecated since version v0.32.0: use message_subtype property instead

property timestamp: bytes
property tm_data: bytes

TM source data (raw)

Type:

return

to_space_packet() SpacePacket

Retrieve the generic CCSDS space packet representation. This also calculates the CRC16 before converting the PUS TC to a generic Space Packet

classmethod unpack(data: bytes | bytearray, timestamp_len: int) PusTm

Attempts to construct a generic PusTelemetry class given a raw bytearray. This unpacker method expects a checksum and also verifies it.

Parameters:
  • data – Raw bytes containing the PUS telemetry packet.

  • time_reader – Time provider to read the timestamp. If the timestamp field is empty, you can supply None here.

Raises:
classmethod unpack_generic(data: bytes | bytearray, managed_params: ManagedParams) PusTm

Attempts to construct a generic PusTelemetry class given a raw bytearray.

Parameters:
  • data – Raw bytes containing the PUS telemetry packet.

  • time_reader – Time provider to read the timestamp. If the timestamp field is empty, you can supply None here.

Raises:
classmethod unpack_no_checksum(data: bytes | bytearray, timestamp_len: int) PusTm

Attempts to construct a generic PusTelemetry class given a raw bytearray without a checksum.

Parameters:
  • data – Raw bytes containing the PUS telemetry packet.

  • time_reader – Time provider to read the timestamp. If the timestamp field is empty, you can supply None here.

Raises:
class spacepackets.ecss.tm.PusTmSecondaryHeader(service: int, message_subtype: int | None = None, timestamp: bytes | bytearray = b'', message_counter: int = 0, dest_id: int = 0, spacecraft_time_ref: int = 0, subservice: int | None = None)

Bases: object

Unpacks the PUS telemetry packet secondary header. Currently only supports CDS short timestamps and PUS C

Create a PUS telemetry secondary header object.

Parameters:
  • service

  • message_subtype

  • time_provider – Time field provider which can provide or read a time field

  • message_counter – 8 bit counter for PUS A, 16 bit counter for PUS C

  • dest_id – Destination ID if PUS C is used

  • spacecraft_time_ref – Space time reference if PUS C is used

MIN_LEN = 7
property header_size: int
pack() bytearray
property subservice: int

Deprecated since version v0.32.0: use message_subtype property instead

classmethod unpack(data: bytes | bytearray, timestamp_len: int) PusTmSecondaryHeader

Unpack the PUS TM secondary header from the raw packet starting at the header index.

Parameters:
  • data – Raw data. Please note that the passed buffer should start where the actual header start is.

  • timestamp_len – Expected timestamp length.

Raises:

ValueError – bytearray too short or PUS version missmatch.

Returns:

ECSS Request ID Submodule

class spacepackets.ecss.req_id.RequestId(tc_packet_id: PacketId, tc_psc: PacketSeqCtrl, ccsds_version: int = 0)

Bases: object

The request ID which is used to identify PUS telecommands. The request ID consists of the first two bytes of the CCSDS primary header. It is primarily used to verify the execution of sent telecommands.

>>> from spacepackets.ccsds import PacketType, SequenceFlags
>>> packet_id = PacketId(ptype=PacketType.TC, sec_header_flag=False, apid=0x22)
>>> psc = PacketSeqCtrl(seq_flags=SequenceFlags.UNSEGMENTED, seq_count=17)
>>> req_id = RequestId(packet_id, psc)
>>> req_id
RequestId(tc_packet_id=PacketId(ptype=<PacketType.TC: 1>, sec_header_flag=False, apid=34), tc_psc=PacketSeqCtrl(seq_flags=<SequenceFlags.UNSEGMENTED: 3>, seq_count=17), ccsds_version=0)
>>> struct.pack("!I", req_id.as_u32()).hex(sep=",")
'10,22,c0,11'
as_u32() int
classmethod empty() RequestId
classmethod from_pus_tc(pus_tc: PusTc) RequestId
classmethod from_sp_header(header: SpacePacketHeader) RequestId
pack() bytes
classmethod unpack(tm_data: bytes | bytearray) RequestId

ECSS PUS 1 Verification Service Submodule

ECSS PUS Service 1 Verification

class spacepackets.ecss.pus_1_verification.FailureNotice(code: PacketFieldEnum, data: bytes)

Bases: object

len() int
pack() bytes
classmethod unpack(data: bytes | bytearray, num_bytes_err_code: int, num_bytes_data: int | None = None) FailureNotice
exception spacepackets.ecss.pus_1_verification.InvalidVerifParamsError

Bases: Exception

class spacepackets.ecss.pus_1_verification.ManagedParamsVerification(bytes_step_id: 'int' = 1, bytes_err_code: 'int' = 1)

Bases: object

bytes_err_code: int = 1
bytes_step_id: int = 1
class spacepackets.ecss.pus_1_verification.MessageSubtype(value)

Bases: IntEnum

An enumeration.

INVALID = 0
TM_ACCEPTANCE_FAILURE = 2
TM_ACCEPTANCE_SUCCESS = 1
TM_COMPLETION_FAILURE = 8
TM_COMPLETION_SUCCESS = 7
TM_START_FAILURE = 4
TM_START_SUCCESS = 3
TM_STEP_FAILURE = 6
TM_STEP_SUCCESS = 5
class spacepackets.ecss.pus_1_verification.Service1Tm(apid: int, message_subtype: MessageSubtype | int | None = None, timestamp: bytes | bytearray = b'', verif_params: VerificationParams | None = None, seq_count: int = 0, destination_id: int = 0, misc_params: MiscParams | None = None, subservice: MessageSubtype | int | None = None)

Bases: AbstractPusTm

Service 1 TM class representation.

property ccsds_version: int
property error_code: PacketFieldEnum | None
property failure_notice: FailureNotice | None
classmethod from_tm(tm: PusTm, verif_params: ManagedParamsVerification) Service1Tm
property has_failure_notice: bool
property is_step_reply: bool
property message_subtype: int
pack() bytearray
property packet_id: PacketId
property packet_seq_control: PacketSeqCtrl
property service: int
property source_data: bytes
property sp_header: SpacePacketHeader
property step_id: PacketFieldEnum | None

Retrieve the step number. Returns NONE if this packet does not have a step ID

property subservice: int

Deprecated since version v0.32.0: use message_subtype property instead

property tc_req_id: RequestId
property timestamp: bytes
classmethod unpack(data: bytes, managed_params: ManagedParams, verif_params: ManagedParamsVerification) Service1Tm

Parse a service 1 telemetry packet.

Parameters:
  • params

  • data

Raises:
  • ValueError – MessageSubtype invalid.

  • BytesTooShortError – passed data too short

  • TmSourceDataTooShortError – TM source data too short.

Returns:

spacepackets.ecss.pus_1_verification.Subservice

alias of MessageSubtype

class spacepackets.ecss.pus_1_verification.VerificationParams(req_id: 'RequestId', step_id: 'StepId | None' = None, failure_notice: 'FailureNotice | None' = None)

Bases: object

failure_notice: FailureNotice | None = None
len() int
pack() bytearray
req_id: RequestId
step_id: PacketFieldEnum | None = None
verify_against_message_subtype(message_subtype: MessageSubtype) None
verify_against_subservice(subservice: MessageSubtype) None

Deprecated since version v0.32.0: use verify_against_message_subtype instead

spacepackets.ecss.pus_1_verification.create_acceptance_failure_tm(apid: int, pus_tc: PusTc, failure_notice: FailureNotice, timestamp: bytes) Service1Tm
spacepackets.ecss.pus_1_verification.create_acceptance_success_tm(apid: int, pus_tc: PusTc, timestamp: bytes) Service1Tm
spacepackets.ecss.pus_1_verification.create_completion_failure_tm(apid: int, pus_tc: PusTc, failure_notice: FailureNotice, timestamp: bytes) Service1Tm
spacepackets.ecss.pus_1_verification.create_completion_success_tm(apid: int, pus_tc: PusTc, timestamp: bytes) Service1Tm
spacepackets.ecss.pus_1_verification.create_start_failure_tm(apid: int, pus_tc: PusTc, failure_notice: FailureNotice, timestamp: bytes) Service1Tm
spacepackets.ecss.pus_1_verification.create_start_success_tm(apid: int, pus_tc: PusTc, timestamp: bytes) Service1Tm
spacepackets.ecss.pus_1_verification.create_step_failure_tm(apid: int, pus_tc: PusTc, step_id: PacketFieldEnum, failure_notice: FailureNotice, timestamp: bytes) Service1Tm
spacepackets.ecss.pus_1_verification.create_step_success_tm(apid: int, pus_tc: PusTc, step_id: PacketFieldEnum, timestamp: bytes) Service1Tm

ECSS PUS 3 Housekeeping Service Submodule

class spacepackets.ecss.pus_3_hk.MessageSubtype(value)

Bases: IntEnum

An enumeration.

TC_DISABLE_PERIODIC_DIAGNOSTICS_GEN = 8
TC_DISABLE_PERIODIC_HK_GEN = 6
TC_ENABLE_PERIODIC_DIAGNOSTICS_GEN = 7
TC_ENABLE_PERIODIC_HK_GEN = 5
TC_GENERATE_ONE_DIAGNOSTICS_REPORT = 28
TC_GENERATE_ONE_PARAMETER_REPORT = 27
TC_MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL = 32
TC_MODIFY_PARAMETER_REPORT_COLLECTION_INTERVAL = 31
TM_DIAGNOSTICS_REPORT = 26
TM_DIAG_DEFINITION_REPORT = 12
TM_HK_DEFINITIONS_REPORT = 10
TM_HK_REPORT = 25
TM_REPORT_DIAG_REPORT_STRUCTURES = 11
TM_REPORT_HK_REPORT_STRUCTURES = 9

ECSS TC PUS A Submodule

This module contains the PUS telecommand class representation to pack telecommands, most notably the PusTelecommand class for the PUS A standard (version number 0b001).

exception spacepackets.ecss.tc_pus_a.InvalidTcCrc16Error(tc: PusTc)

Bases: Exception

class spacepackets.ecss.tc_pus_a.PusTc(service: int, subservice: int, apid: int = 0, app_data: bytes | bytearray = b'', source_id: UnsignedByteField | None = None, seq_count: int = 0, ack_flags: int = 15)

Bases: AbstractSpacePacket

Class representation of a PUS telecommand. Can be converted to the raw byte representation but also unpacked from a raw byte stream.

>>> ping_tc = PusTc(service=17, subservice=1, seq_count=22, apid=0x01)
>>> ping_tc.service
17
>>> ping_tc.subservice
1
>>> ping_tc.pack().hex(sep=',')
'18,01,c0,16,00,04,1f,11,01,41,10'

Initiate a PUS telecommand from the given parameters. The raw byte representation can then be retrieved with the pack() function.

Parameters:
  • service – PUS service number

  • subservice – PUS subservice number

  • apid – Application Process ID as specified by CCSDS

  • seq_count – Source Sequence Count. Application should take care of incrementing this. Limited to 2 to the power of 14 by the number of bits in the header

  • app_data – Application data in the Packet Data Field

  • source_id – Source ID can be supplied as well. Can be used to distinguish different packet sources (e.g. different ground stations)

Raises:

ValueError – Invalid input parameters

property apid: int
property app_data: bytes
calc_crc() None

Can be called to calculate the CRC16. Also sets the internal CRC16 field.

property ccsds_version: int
property crc16: bytes | None

Will be the raw CRC16 if the telecommand was created using unpack(), pack() was called at least once or calc_crc() was called at least once.

classmethod empty() PusTc
classmethod from_composite_fields(sp_header: SpacePacketHeader, sec_header: PusTcDataFieldHeader, app_data: bytes = b'') PusTc
classmethod from_sp_header(sp_header: SpacePacketHeader, service: int, subservice: int, app_data: bytes = b'', source_id: UnsignedByteField | None = None, spare_bytes: int = 0, ack_flags: int = 15) PusTc
static get_data_length(app_data_len: int, secondary_header_len: int) int

Retrieve size of TC packet in bytes. Formula according to PUS Standard: C = (Number of octets in packet data field) - 1. The size of the TC packet is the size of the packet secondary header with source ID + the length of the application data + length of the CRC16 checksum - 1

pack(recalc_crc: bool = True) bytearray

Serializes the TC data fields into a bytearray.

Parameters:

recalc_crc – Can be set to False if the CRC was previous calculated and no fields were changed. This is set to True by default to ensure the CRC is always valid by default, even if the user changes arbitrary fields after TC creation.

pack_command_tuple() tuple[bytearray, PusTc]

Pack a tuple consisting of the raw packet as the first entry and the class representation as the second entry

Deprecated since version v0.14.0rc3: use pack and the class itself to build this instead

property packet_id: PacketId
property packet_len: int

Retrieve the full packet size when packed :return: Size of the TM packet based on the space packet header data length field. The space packet data field is the full length of data field minus one without the space packet header.

property packet_seq_control: PacketSeqCtrl
property seq_count: int
property service: int
property source_id: UnsignedByteField | None
property subservice: int
to_space_packet() SpacePacket

Retrieve the generic CCSDS space packet representation. This also calculates the CRC16 before converting the PUS TC to a generic Space Packet

classmethod unpack(data: bytes | bytearray, source_id_len: int | None = None, spare_bytes: int = 0) PusTc

Create an instance from a raw bytestream.

Raises:
class spacepackets.ecss.tc_pus_a.PusTcDataFieldHeader(service: int, subservice: int, source_id: UnsignedByteField | None, ack_flags: int = 15, spare_bytes: int = 0)

Bases: object

Create a PUS A TC data field header instance

header_size() int
classmethod header_size_for_config(source_id_len: int | None, spare_bytes: int = 0) int
pack() bytearray
classmethod unpack(data: bytes | bytearray, source_id_len: int | None = None, spare_bytes: int = 0) PusTcDataFieldHeader

Unpack a PUS A TC data field header.

Parameters:

data – Start of raw data belonging to the TC data field header

Raises:
Returns:

spacepackets.ecss.tc_pus_a.PusTelecommand

alias of PusTc

ECSS TM PUS A Submodule

This module contains import PUS TM packet classes, most notably the spacepackets.ecss.tm.PusTelemetry class.

exception spacepackets.ecss.tm_pus_a.InvalidTmCrc16Error(tm: PusTm)

Bases: Exception

spacepackets.ecss.tm_pus_a.PusTelemetry

alias of PusTm

class spacepackets.ecss.tm_pus_a.PusTm(service: int, subservice: int, timestamp: bytes | bytearray, source_data: bytes | bytearray = b'', apid: int = 0, seq_count: int = 0, message_counter: int | None = None, destination_id: UnsignedByteField | None = None, packet_version: int = 0, sec_header_spare_bytes: int = 0)

Bases: AbstractPusTm

Generic PUS telemetry class representation.

Can be used to generate TM packets using a high level interface with the default constructor, or to deserialize TM packets from a raw byte stream using the unpack() method. This implementation only supports PUS C.

Deserialization of PUS telemetry requires the timestamp length to be known. If the size of the timestamp is variable but can be determined from the data, a look-ahead should be performed on the raw data. The PUS_TM_TIMESTAMP_OFFSET (13) can be used to do this, assuming that the timestamp length can be extracted from the timestamp itself.

The following doc example cuts off the timestamp (7 byte CDS Short) and the CRC16 from the ping packet because those change regularly.

>>> ping_tm = PusTm(service=17, subservice=2, seq_count=5, apid=0x01, timestamp=CdsShortTimestamp.now().pack())
>>> ping_tm.service
17
>>> ping_tm.subservice
2
>>> ping_tm.pack()[:-9].hex(sep=',')
'08,01,c0,05,00,0b,10,11,02'
CDS_SHORT_SIZE = 7
PUS_TIMESTAMP_SIZE = 7
property apid: int
calc_crc() None

Can be called to calculate the CRC16

property ccsds_version: int
property crc16: bytes | None

Will be the raw CRC16 if the telecommand was created using unpack() or pack() was called at least once.

static data_len_from_src_len_timestamp_len(timestamp_len: int, source_data_len: int, has_message_counter: bool, dest_id_len: None | int) int

Retrieve size of TM packet data header in bytes. Only support PUS C Formula according to PUS Standard: C = (Number of octets in packet source data field) - 1. The size of the TM packet is the size of the packet secondary header with the timestamp + the length of the application data + PUS timestamp size + length of the CRC16 checksum - 1

Parameters:
  • source_data_len – Length of the source (user) data

  • timestamp_len – Length of the used timestamp

classmethod empty() PusTm
classmethod from_composite_fields(sp_header: SpacePacketHeader, sec_header: PusTmSecondaryHeader, tm_data: bytes) PusTm
get_full_packet_string(print_format: PrintFormats = PrintFormats.HEX) str

Deprecated since version 0.14.0rc3: use pack and get_printable_data_string or the hex method on bytearray instead

get_source_data_string(print_format: PrintFormats = PrintFormats.HEX) str

Returns the source data string

Deprecated since version 0.14.0rc3: use the source_data property and the hex method on bytearray instead

pack(recalc_crc: bool = True) bytearray

Serializes the packet into a raw bytearray.

Parameters:

recalc_crc – Can be set to False if the CRC was previous calculated and no fields were changed. This is set to True by default to ensure the CRC is always valid by default, even if the user changes arbitrary fields after TM creation.

property packet_id: PacketId
property packet_len: int

Retrieve the full packet size when packed :return: Size of the TM packet based on the space packet header data length field. The space packet data field is the full length of data field minus one without the space packet header.

property packet_seq_control: PacketSeqCtrl
print_full_packet_string(print_format: PrintFormats = PrintFormats.HEX) None

Print the full TM packet in a clean format.

Deprecated since version 0.14.0rc3: use pack and get_printable_data_string or the hex method on bytearray instead

print_source_data(print_format: PrintFormats = PrintFormats.HEX) None

Prints the TM source data in a clean format

Deprecated since version 0.14.0rc3: use print, the source_data property and the hex method on bytearray instead

property seq_count: int

Get the source sequence count :return: Source Sequence Count (see below, or PUS documentation)

property seq_flags: SequenceFlags
property service: int

Get the service type ID :return: Service ID

static service_from_bytes(raw_bytearray: bytearray) int

Determine the service ID from a raw packet, which can be used for packet deserialization.

It is assumed that the user already checked that the raw bytearray contains a PUS packet and only basic sanity checks will be performed. :raise ValueError: If raw bytearray is too short

property source_data: bytes
property sp_header: SpacePacketHeader
property subservice: int

Get the subservice type ID :return: Subservice ID

property timestamp: bytes
property tm_data: bytes

TM source data (raw)

Type:

return

to_space_packet() SpacePacket

Retrieve the generic CCSDS space packet representation. This also calculates the CRC16 before converting the PUS TC to a generic Space Packet

classmethod unpack(data: bytes | bytearray, timestamp_len: int, has_message_counter: bool, dest_id_len: int | None) PusTm

Attempts to construct a generic PusTelemetry class given a raw bytearray.

Parameters:
  • data – Raw bytes containing the PUS telemetry packet.

  • time_reader – Time provider to read the timestamp. If the timestamp field is empty, you can supply None here.

Raises:
class spacepackets.ecss.tm_pus_a.PusTmSecondaryHeader(service: int, subservice: int, timestamp: bytes | bytearray, message_counter: int | None, dest_id: UnsignedByteField | None = None, spare_bytes: int = 0)

Bases: object

Unpacks the PUS telemetry packet secondary header. Currently only supports CDS short timestamps and PUS C

Create a PUS telemetry secondary header object.

Parameters:
  • service

  • subservice

  • time_provider – Time field provider which can provide or read a time field

  • message_counter – 8 bit counter for PUS A, 16 bit counter for PUS C

  • dest_id – Destination ID if PUS C is used

  • spacecraft_time_ref – Space time reference if PUS C is used

MIN_LEN = 3
property header_size: int
pack() bytearray
classmethod unpack(data: bytes | bytearray, timestamp_len: int, has_message_counter: bool = False, dest_id_len: int | None = None, spare_bytes: int = 0) PusTmSecondaryHeader

Unpack the PUS TM secondary header from the raw packet starting at the header index.

Parameters:
  • data – Raw data. Please note that the passed buffer should start where the actual header start is.

  • timestamp_len – Expected timestamp length.

Raises:

ValueError – bytearray too short or PUS version missmatch.

Returns: