Skip to content

Commit

Permalink
some more improvements for structure
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Apr 23, 2024
1 parent e51be34 commit 0eb1fe8
Show file tree
Hide file tree
Showing 17 changed files with 172 additions and 159 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- ECSS PUS telemetry time handling is now more generic and low level: Constructors expect
a simple `bytes` type while unpackers/readers expect the length of the timestamp. Determining
or knowing the size of the timestamp is now the task of the user.
or knowing the size of the timestamp is now the task of the user, but a helper constant
is expose which can help with this.
- `CdsShortTimestamp.from_now` renamed to `now`.
- The ECSS TMTC APID field must not be set explicitely in the class constructors.

## Added

Expand All @@ -24,6 +26,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
determine the timestamp length from a raw PUS TM packet.
- `spacepackets.ccsds.CCSDS_HEADER_LEN` constant.

## Removed

- Global configuration module for TC and TM APID was removed.

# [v0.23.1] 2024-04-22

## Added
Expand Down
18 changes: 6 additions & 12 deletions docs/api/ecss.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ ECSS Package
:undoc-members:
:show-inheritance:

.. automodule:: spacepackets.ecss.defs
:members:
:undoc-members:
:show-inheritance:

ECSS PUS Telecommand Module
--------------------------------
----------------------------

:ref:`api/ecss_tc:ECSS Telecommand Module`

Expand All @@ -16,17 +21,6 @@ ECSS PUS Telemetry Module

:ref:`api/ecss_tm:ECSS Telemetry Module`

ECSS Configuration Submodule
----------------------------------

This module can be used to configure common default values so these don't have to be specified
each time anymore when creating ECSS packets

.. automodule:: spacepackets.ecss.conf
:members:
:undoc-members:
:show-inheritance:

ECSS Fields Submodule
----------------------------------

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
name = "spacepackets"
description = "Various CCSDS and ECSS packet implementations"
readme = "README.md"
version = "0.23.1"
version = "0.24.0"
requires-python = ">=3.8"
license = {text = "Apache-2.0"}
authors = [
Expand Down
22 changes: 12 additions & 10 deletions spacepackets/ccsds/spacepacket.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

from spacepackets.exceptions import BytesTooShortError

SPACE_PACKET_HEADER_SIZE: Final = 6
CCSDS_HEADER_LEN: Final = SPACE_PACKET_HEADER_SIZE
SEQ_FLAG_MASK = 0xC000
APID_MASK = 0x7FF
PACKET_ID_MASK = 0x1FFF
CCSDS_HEADER_LEN: Final[int] = 6
SPACE_PACKET_HEADER_SIZE: Final[int] = CCSDS_HEADER_LEN
SEQ_FLAG_MASK: Final[int] = 0xC000
APID_MASK: Final[int] = 0x7FF
PACKET_ID_MASK: Final[int] = 0x1FFF
MAX_SEQ_COUNT: Final[int] = pow(2, 14) - 1
MAX_APID: Final[int] = pow(2, 11) - 1


class PacketType(enum.IntEnum):
Expand All @@ -35,7 +37,7 @@ class PacketSeqCtrl:
"""

def __init__(self, seq_flags: SequenceFlags, seq_count: int):
if seq_count > pow(2, 14) - 1 or seq_count < 0:
if seq_count > MAX_SEQ_COUNT or seq_count < 0:
raise ValueError(
f"Sequence count larger than allowed {pow(2, 14) - 1} or negative"
)
Expand Down Expand Up @@ -206,7 +208,7 @@ def __init__(
:param data_len: Contains a length count C that equals one fewer than the length of the
packet data field. Should not be larger than 65535 bytes
:param ccsds_version:
:param sec_header_flag: Secondary header flag, 1 or True by default
:param sec_header_flag: Secondary header flag, or False by default.
:param seq_flags:
:raises ValueError: On invalid parameters
"""
Expand Down Expand Up @@ -300,7 +302,7 @@ def seq_flags(self, value):

@property
def header_len(self) -> int:
return SPACE_PACKET_HEADER_SIZE
return CCSDS_HEADER_LEN

@apid.setter
def apid(self, apid):
Expand All @@ -312,7 +314,7 @@ def packet_len(self) -> int:
:return: Size of the TM packet based on the space packet header data length field.
"""
return SPACE_PACKET_HEADER_SIZE + self.data_len + 1
return CCSDS_HEADER_LEN + self.data_len + 1

@classmethod
def unpack(cls, data: bytes) -> SpacePacketHeader:
Expand Down Expand Up @@ -501,7 +503,7 @@ def parse_space_packets(
# Packet ID detected
while True:
# Can't even parse CCSDS header. Wait for more data to arrive.
if current_idx + SPACE_PACKET_HEADER_SIZE >= len(concatenated_packets):
if current_idx + CCSDS_HEADER_LEN >= len(concatenated_packets):
break
current_packet_id = (
struct.unpack("!H", concatenated_packets[current_idx : current_idx + 2])[0]
Expand Down
4 changes: 2 additions & 2 deletions spacepackets/ecss/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from crcmod.predefined import mkPredefinedCrcFun

from .tc import PusVersion, PusTelecommand, PusTc, PusTcDataFieldHeader
from .tc import PusTc, PusTelecommand, PusTcDataFieldHeader
from .tm import PusTm, PusTelemetry, PusTmSecondaryHeader
from .fields import (
PacketFieldEnum,
Expand All @@ -13,7 +13,7 @@
PfcSigned,
PfcUnsigned,
)
from .defs import PusService
from .defs import PusService, PusVersion
from .req_id import RequestId
from .pus_verificator import PusVerificator

Expand Down
46 changes: 0 additions & 46 deletions spacepackets/ecss/conf.py

This file was deleted.

9 changes: 9 additions & 0 deletions spacepackets/ecss/defs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import enum


class PusVersion(enum.IntEnum):
# ESA PSS-07-101. Not supported by this package!
ESA_PUS = 0
# ECSS-E-70-41A
PUS_A = 1
# ECSS-E-ST-70-41C
PUS_C = 2


class PusService(enum.IntEnum):
S1_VERIFICATION = 1
S2_RAW_CMD = 2
Expand Down
5 changes: 2 additions & 3 deletions spacepackets/ecss/pus_17_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from spacepackets import SpacePacketHeader
from spacepackets.ccsds.spacepacket import PacketId, PacketSeqCtrl
from spacepackets.ecss.conf import FETCH_GLOBAL_APID
from spacepackets.ecss.defs import PusService
from spacepackets.ecss.tm import PusTm, AbstractPusTm

Expand All @@ -16,11 +15,11 @@ class Subservice(enum.IntEnum):
class Service17Tm(AbstractPusTm):
def __init__(
self,
apid: int,
subservice: int,
timestamp: bytes,
ssc: int = 0,
source_data: bytes = bytes(),
apid: int = FETCH_GLOBAL_APID,
packet_version: int = 0b000,
space_time_ref: int = 0b0000,
destination_id: int = 0,
Expand Down Expand Up @@ -74,7 +73,7 @@ def pack(self) -> bytearray:

@classmethod
def __empty(cls) -> Service17Tm:
return cls(subservice=0, timestamp=bytes())
return cls(apid=0, subservice=0, timestamp=bytes())

@classmethod
def unpack(cls, data: bytes, timestamp_len: int) -> Service17Tm:
Expand Down
28 changes: 22 additions & 6 deletions spacepackets/ecss/pus_1_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from spacepackets.ccsds import SpacePacketHeader
from spacepackets.ccsds.spacepacket import PacketId, PacketSeqCtrl
from spacepackets.ecss import PusTc
from spacepackets.ecss.conf import FETCH_GLOBAL_APID
from spacepackets.ecss.defs import PusService
from spacepackets.ecss.fields import PacketFieldEnum
from spacepackets.ecss.tm import PusTm, AbstractPusTm
Expand Down Expand Up @@ -122,11 +121,11 @@ class Service1Tm(AbstractPusTm):

def __init__(
self,
apid: int,
subservice: Subservice,
timestamp: bytes,
verif_params: Optional[VerificationParams] = None,
seq_count: int = 0,
apid: int = FETCH_GLOBAL_APID,
packet_version: int = 0b000,
space_time_ref: int = 0b0000,
destination_id: int = 0,
Expand Down Expand Up @@ -154,7 +153,7 @@ def pack(self) -> bytearray:

@classmethod
def __empty(cls) -> Service1Tm:
return cls(subservice=Subservice.INVALID, timestamp=bytes())
return cls(apid=0, subservice=Subservice.INVALID, timestamp=bytes())

@classmethod
def from_tm(cls, tm: PusTm, params: UnpackParams) -> Service1Tm:
Expand Down Expand Up @@ -303,20 +302,25 @@ def __eq__(self, other: object):
return False


def create_acceptance_success_tm(pus_tc: PusTc, timestamp: bytes) -> Service1Tm:
def create_acceptance_success_tm(
apid: int, pus_tc: PusTc, timestamp: bytes
) -> Service1Tm:
return Service1Tm(
apid=apid,
subservice=Subservice.TM_ACCEPTANCE_SUCCESS,
verif_params=VerificationParams(RequestId.from_sp_header(pus_tc.sp_header)),
timestamp=timestamp,
)


def create_acceptance_failure_tm(
apid: int,
pus_tc: PusTc,
failure_notice: FailureNotice,
timestamp: bytes,
) -> Service1Tm:
return Service1Tm(
apid=apid,
subservice=Subservice.TM_ACCEPTANCE_FAILURE,
verif_params=VerificationParams(
req_id=RequestId.from_sp_header(pus_tc.sp_header),
Expand All @@ -326,20 +330,23 @@ def create_acceptance_failure_tm(
)


def create_start_success_tm(pus_tc: PusTc, timestamp: bytes) -> Service1Tm:
def create_start_success_tm(apid: int, pus_tc: PusTc, timestamp: bytes) -> Service1Tm:
return Service1Tm(
apid=apid,
subservice=Subservice.TM_START_SUCCESS,
verif_params=VerificationParams(RequestId.from_sp_header(pus_tc.sp_header)),
timestamp=timestamp,
)


def create_start_failure_tm(
apid: int,
pus_tc: PusTc,
failure_notice: FailureNotice,
timestamp: bytes,
) -> Service1Tm:
return Service1Tm(
apid=apid,
subservice=Subservice.TM_START_FAILURE,
verif_params=VerificationParams(
req_id=RequestId.from_sp_header(pus_tc.sp_header),
Expand All @@ -350,11 +357,13 @@ def create_start_failure_tm(


def create_step_success_tm(
apid: int,
pus_tc: PusTc,
step_id: PacketFieldEnum,
timestamp: bytes,
) -> Service1Tm:
return Service1Tm(
apid=apid,
subservice=Subservice.TM_STEP_SUCCESS,
verif_params=VerificationParams(
req_id=RequestId.from_sp_header(pus_tc.sp_header), step_id=step_id
Expand All @@ -364,12 +373,14 @@ def create_step_success_tm(


def create_step_failure_tm(
apid: int,
pus_tc: PusTc,
step_id: PacketFieldEnum,
failure_notice: FailureNotice,
timestamp: bytes,
) -> Service1Tm:
return Service1Tm(
apid=apid,
subservice=Subservice.TM_STEP_FAILURE,
verif_params=VerificationParams(
req_id=RequestId.from_sp_header(pus_tc.sp_header),
Expand All @@ -380,20 +391,25 @@ def create_step_failure_tm(
)


def create_completion_success_tm(pus_tc: PusTc, timestamp: bytes) -> Service1Tm:
def create_completion_success_tm(
apid: int, pus_tc: PusTc, timestamp: bytes
) -> Service1Tm:
return Service1Tm(
apid=apid,
subservice=Subservice.TM_COMPLETION_SUCCESS,
verif_params=VerificationParams(RequestId.from_sp_header(pus_tc.sp_header)),
timestamp=timestamp,
)


def create_completion_failure_tm(
apid: int,
pus_tc: PusTc,
failure_notice: FailureNotice,
timestamp: bytes,
) -> Service1Tm:
return Service1Tm(
apid=apid,
subservice=Subservice.TM_COMPLETION_FAILURE,
verif_params=VerificationParams(
req_id=RequestId.from_sp_header(pus_tc.sp_header),
Expand Down

0 comments on commit 0eb1fe8

Please sign in to comment.