ECSS Package
The following classes can be used to create and read ECSS PUS-C packets:
spacepackets.ecss.PusTcspacepackets.ecss.PusTm
ECSS Fields
- 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.
- 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:
IntEnumAn 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:
IntEnumAn 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:
IntEnumAn 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
ECSS TC Submodule
This module contains the PUS telecommand class representation to pack telecommands, most notably
the PusTelecommand class.
- 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:
AbstractSpacePacketClass 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 crc16: bytes | None
Will be the raw CRC16 if the telecommand was created using
unpack(),pack()was called at least once orcalc_crc()was called at least once.
- 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
- 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_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
- 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:
BytesTooShortError – Passed bytestream too short.
ValueError – Unsupported PUS version.
InvalidTcCrc16Error – Invalid CRC16 checksum.
- classmethod unpack_generic(data: bytes | bytearray, has_checksum: bool, verify_checksum: bool) PusTc
Create an instance from a raw bytestream.
- Raises:
BytesTooShortError – Passed bytestream too short.
ValueError – Unsupported PUS version.
InvalidTcCrc16Error – Invalid CRC16.
- classmethod unpack_no_checksum(data: bytes | bytearray) PusTc
Create an instance from a raw bytestream with no checksum.
- Raises:
BytesTooShortError – Passed bytestream too short.
ValueError – Unsupported PUS version.
InvalidTcCrc16Error – Invalid CRC16.
- 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:
objectCreate a PUS TC data field header instance
- Parameters:
service
message_subtype
source_id
ack_flags
- PUS_C_SEC_HEADER_LEN = 5
- 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:
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:
AbstractSpacePacketGeneric abstraction for PUS TM packets
- get_sp_header() SpacePacketHeader
Deprecated since version v0.14.0rc2: use sp_header property instead
- abstract property sp_header: SpacePacketHeader
- class spacepackets.ecss.tm.ManagedParams(timestamp_len: int, has_checksum: bool = True, verify_checksum: bool = True)
Bases:
objectManaged parameters are used defined and are usually fixed for a given mission.
- class spacepackets.ecss.tm.MiscParams(spacecraft_time_ref: 'int' = 0, packet_version: 'int' = 0)
Bases:
object
- 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:
AbstractPusTmGeneric 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 crc16: bytes | None
Will be the raw CRC16 if the telecommand was created using
unpack()orpack()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 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
- 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_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
- 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 sp_header: SpacePacketHeader
- property subservice: int
Get the subservice ID :return: Subservice ID
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, 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:
BytesTooShortError – Passed bytestream too short.
ValueError – Unsupported PUS version.
InvalidTmCrc16Error – Invalid CRC16.
- 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:
BytesTooShortError – Passed bytestream too short.
ValueError – Unsupported PUS version.
InvalidTmCrc16Error – Invalid CRC16.
- 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:
BytesTooShortError – Passed bytestream too short.
ValueError – Unsupported PUS version.
InvalidTmCrc16Error – Invalid CRC16.
- 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:
objectUnpacks 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
- 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:
objectThe 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'
- classmethod from_sp_header(header: SpacePacketHeader) 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
- class spacepackets.ecss.pus_1_verification.ManagedParamsVerification(bytes_step_id: 'int' = 1, bytes_err_code: 'int' = 1)
Bases:
object
- class spacepackets.ecss.pus_1_verification.MessageSubtype(value)
Bases:
IntEnumAn 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:
AbstractPusTmService 1 TM class representation.
- property error_code: PacketFieldEnum | None
- property failure_notice: FailureNotice | None
- classmethod from_tm(tm: PusTm, verif_params: ManagedParamsVerification) Service1Tm
- property packet_seq_control: PacketSeqCtrl
- property sp_header: SpacePacketHeader
- property step_id: PacketFieldEnum | None
Retrieve the step number. Returns NONE if this packet does not have a step ID
- 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
- 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:
IntEnumAn 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).
- 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:
AbstractSpacePacketClass 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 crc16: bytes | None
Will be the raw CRC16 if the telecommand was created using
unpack(),pack()was called at least once orcalc_crc()was called at least once.
- 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_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 source_id: UnsignedByteField | None
- 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:
BytesTooShortError – Passed bytestream too short.
ValueError – Unsupported PUS version.
InvalidTcCrc16Error – Invalid CRC16.
- class spacepackets.ecss.tc_pus_a.PusTcDataFieldHeader(service: int, subservice: int, source_id: UnsignedByteField | None, ack_flags: int = 15, spare_bytes: int = 0)
Bases:
objectCreate a PUS A TC data field header instance
- 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:
ValueError – Invalid PUS standard field which is not PUS A.
BytesTooShortError – Passed data too short.
- Returns:
ECSS TM PUS A Submodule
This module contains import PUS TM packet classes, most notably the
spacepackets.ecss.tm.PusTelemetry class.
- 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:
AbstractPusTmGeneric 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 crc16: bytes | None
Will be the raw CRC16 if the telecommand was created using
unpack()orpack()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 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_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
- 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 sp_header: SpacePacketHeader
- 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:
BytesTooShortError – Passed bytestream too short.
ValueError – Unsupported PUS version.
InvalidTmCrc16Error – Invalid CRC16.
- 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:
objectUnpacks 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
- 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: