Skip to content

Commit

Permalink
Merge pull request #32 from us-irs/prep_v0.18.0rc1
Browse files Browse the repository at this point in the history
Prep v0.18.0rc1
  • Loading branch information
robamu authored Sep 4, 2023
2 parents 85cef39 + befee57 commit 291724f
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Renamed `MessageToUserTlv.is_standard_proxy_dir_ops_msg` to `is_reserved_cfdp_message`
- `ProxyPutRequest` constructor now expects a `ProxyPutRequestParams` instance.
- Swapped `FileDataPdu`, `KeepAlivePdu`, `EofPdu`, `FinishedPdu`, `PromptPdu` and `AckPdu`
constructor argument order : `PduConfig` is the first parameter now while
`FileDataParams` is the second parameter. `PduConfig` is the only common parameter, so it makes
more sense to have it as the first argument.

## Fixed

Expand Down
73 changes: 73 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,77 @@ Output:

Space packet header (hex): [10,01,c0,00,00,00]

CFDP Packets
-----------------

This example shows how to generate the 3 CFDP PDUs which constitute of full
small file transfer.

.. testcode:: cfdp

from typing import Deque
from spacepackets.cfdp.conf import ByteFieldU8
from spacepackets.cfdp.defs import ChecksumType, TransmissionMode
from spacepackets.cfdp.pdu import (
MetadataParams,
MetadataPdu,
FileDataPdu,
EofPdu,
PduConfig,
)
from spacepackets.cfdp.pdu.file_data import FileDataParams
from crcmod.predefined import PredefinedCrc

LOCAL_ID = ByteFieldU8(1)
REMOTE_ID = ByteFieldU8(2)

file_transfer_queue = Deque()
src_name = "/tmp/src-file.txt"
dest_name = "/tmp/dest-file.txt"
file_data = "Hello World!"
seq_num = ByteFieldU8(0)
pdu_conf = PduConfig(LOCAL_ID, REMOTE_ID, seq_num, TransmissionMode.UNACKNOWLEDGED)
metadata_params = MetadataParams(
True, ChecksumType.CRC_32, len(file_data), src_name, dest_name
)
metadata_pdu = MetadataPdu(pdu_conf, metadata_params)

file_transfer_queue.append(metadata_pdu)

params = FileDataParams(file_data.encode(), 0)
fd_pdu = FileDataPdu(pdu_conf, params)

file_transfer_queue.append(fd_pdu)

crc_calculator = PredefinedCrc("crc32")
crc_calculator.update(file_data.encode())
crc_32 = crc_calculator.digest()
eof_pdu = EofPdu(pdu_conf, crc_32, len(file_data))
file_transfer_queue.append(eof_pdu)

for idx, pdu in enumerate(file_transfer_queue):
print(f"--- PDU {idx} REPR ---")
print(pdu)
print(f"--- PDU {idx} RAW ---")
print(f"0x[{pdu.pack().hex(sep=',')}]")

Output

.. testoutput:: cfdp

--- PDU 0 REPR ---
MetadataPdu(params=MetadataParams(closure_requested=True, checksum_type=<ChecksumType.CRC_32: 3>, file_size=12, source_file_name='/tmp/src-file.txt', dest_file_name='/tmp/dest-file.txt'), options=None, pdu_conf=PduConfig(source_entity_id=ByteFieldU8(val=1, byte_len=1), dest_entity_id=ByteFieldU8(val=2, byte_len=1), transaction_seq_num=ByteFieldU8(val=0, byte_len=1), trans_mode=<TransmissionMode.UNACKNOWLEDGED: 1>, file_flag=<LargeFileFlag.NORMAL: 0>, crc_flag=<CrcFlag.NO_CRC: 0>, direction=<Direction.TOWARDS_RECEIVER: 0>, seg_ctrl=<SegmentationControl.NO_RECORD_BOUNDARIES_PRESERVATION: 0>))
--- PDU 0 RAW ---
0x[24,00,2b,00,01,00,02,07,43,00,00,00,0c,11,2f,74,6d,70,2f,73,72,63,2d,66,69,6c,65,2e,74,78,74,12,2f,74,6d,70,2f,64,65,73,74,2d,66,69,6c,65,2e,74,78,74]
--- PDU 1 REPR ---
FileDataPdu(params=FileDataParams(file_data=b'Hello World!', offset=0, segment_metadata_flag=<SegmentMetadataFlag.NOT_PRESENT: 0>, record_cont_state=None, segment_metadata=None), pdu_conf=PduConfig(source_entity_id=ByteFieldU8(val=1, byte_len=1), dest_entity_id=ByteFieldU8(val=2, byte_len=1), transaction_seq_num=ByteFieldU8(val=0, byte_len=1), trans_mode=<TransmissionMode.UNACKNOWLEDGED: 1>, file_flag=<LargeFileFlag.NORMAL: 0>, crc_flag=<CrcFlag.NO_CRC: 0>, direction=<Direction.TOWARDS_RECEIVER: 0>, seg_ctrl=<SegmentationControl.NO_RECORD_BOUNDARIES_PRESERVATION: 0>))
--- PDU 1 RAW ---
0x[34,00,10,00,01,00,02,00,00,00,00,48,65,6c,6c,6f,20,57,6f,72,6c,64,21]
--- PDU 2 REPR ---
EofPdu(file_checksum=b'\x1c)\x1c\xa3',file_size=12, pdu_conf=PduConfig(source_entity_id=ByteFieldU8(val=1, byte_len=1), dest_entity_id=ByteFieldU8(val=2, byte_len=1), transaction_seq_num=ByteFieldU8(val=0, byte_len=1), trans_mode=<TransmissionMode.UNACKNOWLEDGED: 1>, file_flag=<LargeFileFlag.NORMAL: 0>, crc_flag=<CrcFlag.NO_CRC: 0>, direction=<Direction.TOWARDS_RECEIVER: 0>, seg_ctrl=<SegmentationControl.NO_RECORD_BOUNDARIES_PRESERVATION: 0>),fault_location=None,condition_code=0)
--- PDU 2 RAW ---
0x[24,00,0a,00,01,00,02,04,00,1c,29,1c,a3,00,00,00,0c]

USLP Frames
-------------------

Expand Down Expand Up @@ -109,3 +180,5 @@ Output:

USLP variable length frame without FECF containing a simple space packet
Contained space packet (hex): [c0,07,30,20,00,00,00,e0,10,73,c0,00,00,03,01,02,03,04]


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.18.0rc0"
version = "0.18.0rc1"
requires-python = ">=3.8"
license = {text = "Apache-2.0"}
authors = [
Expand Down
7 changes: 3 additions & 4 deletions release_checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ Checklist for new releases
1. Make sure the docs build with Sphinx, using `make html` inside the
`docs` directory with `sphinx` and `sphinx_rtd_theme` installed. Also test the examples with
`make doctest`.
2. Bump version inside the `spacepackets/__init__.py` file.
2. Bump version inside the `pyproject.toml` file.
3. Update `CHANGELOG.md`: Convert `unreleased` section into version section
with date and new `unreleased`section.
4. Run tests with `pytest .`
5. Run auto-formatter with `black .`
6. Run linter script `./lint.py`
7. Wait for CI/CD results. This also runs the tests on different
operating systems
6. Run linter script `flake8 .`
7. Wait for CI/CD results. This also runs the tests on different operating systems

# Post-Release

Expand Down
2 changes: 1 addition & 1 deletion spacepackets/cfdp/pdu/ack.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class AckPdu(AbstractFileDirectiveBase):

def __init__(
self,
pdu_conf: PduConfig,
directive_code_of_acked_pdu: DirectiveType,
condition_code_of_acked_pdu: ConditionCode,
transaction_status: TransactionStatus,
pdu_conf: PduConfig,
):
"""Construct a ACK PDU object
Expand Down
2 changes: 1 addition & 1 deletion spacepackets/cfdp/pdu/eof.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class EofPdu(AbstractFileDirectiveBase):

def __init__(
self,
pdu_conf: PduConfig,
file_checksum: bytes,
file_size: int,
pdu_conf: PduConfig,
fault_location: Optional[EntityIdTlv] = None,
condition_code: ConditionCode = ConditionCode.NO_ERROR,
):
Expand Down
2 changes: 1 addition & 1 deletion spacepackets/cfdp/pdu/file_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def empty(cls) -> FileDataParams:


class FileDataPdu(AbstractPduBase):
def __init__(self, params: FileDataParams, pdu_conf: PduConfig):
def __init__(self, pdu_conf: PduConfig, params: FileDataParams):
self._params = params
if isinstance(params.segment_metadata_flag, bool):
self._params.segment_metadata_flag = SegmentMetadataFlag(
Expand Down
2 changes: 1 addition & 1 deletion spacepackets/cfdp/pdu/file_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ class FileDirectivePduBase(AbstractFileDirectiveBase):

def __init__(
self,
pdu_conf: PduConfig,
directive_code: DirectiveType,
directive_param_field_len: int,
pdu_conf: PduConfig,
):
"""Generic constructor for a file directive PDU. Most arguments are passed on the
to build the generic PDU header.
Expand Down
2 changes: 1 addition & 1 deletion spacepackets/cfdp/pdu/finished.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class FinishedPdu(AbstractFileDirectiveBase):

def __init__(
self,
params: FinishedParams,
pdu_conf: PduConfig,
params: FinishedParams,
):
self.pdu_file_directive = FileDirectivePduBase(
directive_code=DirectiveType.FINISHED_PDU,
Expand Down
2 changes: 1 addition & 1 deletion spacepackets/cfdp/pdu/keep_alive.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class KeepAlivePdu(AbstractFileDirectiveBase):
"""Encapsulates the Keep Alive file directive PDU, see CCSDS 727.0-B-5 p.85"""

def __init__(self, progress: int, pdu_conf: PduConfig):
def __init__(self, pdu_conf: PduConfig, progress: int):
directive_param_field_len = 4
if pdu_conf.file_flag == LargeFileFlag.LARGE:
directive_param_field_len = 8
Expand Down
2 changes: 1 addition & 1 deletion spacepackets/cfdp/pdu/nak.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class NakPdu(AbstractFileDirectiveBase):

def __init__(
self,
pdu_conf: PduConfig,
start_of_scope: int,
end_of_scope: int,
pdu_conf: PduConfig,
segment_requests: Optional[List[Tuple[int, int]]] = None,
):
"""Create a NAK PDU object instance
Expand Down
2 changes: 1 addition & 1 deletion spacepackets/cfdp/pdu/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ResponseRequired(enum.IntEnum):
class PromptPdu(AbstractFileDirectiveBase):
"""Encapsulates the Prompt file directive PDU, see CCSDS 727.0-B-5 p.84"""

def __init__(self, response_required: ResponseRequired, pdu_conf: PduConfig):
def __init__(self, pdu_conf: PduConfig, response_required: ResponseRequired):
self.pdu_file_directive = FileDirectivePduBase(
directive_code=DirectiveType.PROMPT_PDU,
pdu_conf=pdu_conf,
Expand Down
2 changes: 2 additions & 0 deletions spacepackets/cfdp/tlv.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ def create_cfdp_proxy_and_dir_op_message_marker() -> bytes:

class MessageToUserTlv(AbstractTlvBase):
"""Message to User TLV implementation as specified in CCSDS 727.0-B-5 5.4.3"""

TLV_TYPE = TlvType.MESSAGE_TO_USER

def __init__(self, msg: bytes):
Expand Down Expand Up @@ -728,6 +729,7 @@ class ProxyMessageType(enum.IntEnum):

class ReservedCfdpMessage(AbstractTlvBase):
"""Reserved CFDP message implementation as specified in CCSDS 727.0-B-5 6.1"""

def __init__(self, msg_type: int, value: bytes):
assert msg_type < pow(2, 8) - 1
full_value = bytearray("cfdp".encode())
Expand Down
2 changes: 1 addition & 1 deletion tests/cfdp/pdus/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_factory_file_directive_getter(self):

def test_factory_file_directive_on_file_data(self):
fd_params = FileDataParams(file_data=bytes(), offset=0)
file_data_pdu = FileDataPdu(fd_params, self.pdu_conf)
file_data_pdu = FileDataPdu(self.pdu_conf, fd_params)
fd_pdu_raw = file_data_pdu.pack()
self.assertEqual(self.pdu_factory.pdu_directive_type(fd_pdu_raw), None)

Expand Down

0 comments on commit 291724f

Please sign in to comment.