Skip to content

Commit

Permalink
Merge pull request #71 from us-irs/add-countdown-utility
Browse files Browse the repository at this point in the history
add some more documentation
  • Loading branch information
robamu authored Jan 23, 2024
2 parents f4267f5 + 4044548 commit a9ee6ff
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Added

- Added `ByteFieldU64` variant.
- Added `spacepackets.countdown` utility module. This class was moved from
`tmtccmd.util.countdown` and contains the `Countdown` class. It was moved here so it can
be re-used more easily.

# [v0.22.0] 2023-12-22

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ Currently, this includes the following components:

It also contains various helper modules

- `PusVerificator` module to track the verification of sent telecommands
- [PTC and PFC definitions](https://spacepackets.readthedocs.io/en/latest/api/ecss.html#module-spacepackets.ecss.fields) for ECSS packets
- `PusVerificator` module to track the verification of sent telecommands.
- [PTC and PFC definitions](https://spacepackets.readthedocs.io/en/latest/api/ecss.html#module-spacepackets.ecss.fields) for ECSS packets.
- `Countdown` utility class.

# Install

Expand Down
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ This package also uses the :py:mod:`logging` package to emit warnings.
api/cfdp_pdu
api/cfdp_tlv
api/uslp
api/countdown
api/util
7 changes: 7 additions & 0 deletions docs/api/countdown.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Countdown Module
================

.. automodule:: spacepackets.countdown
:members:
:undoc-members:
:show-inheritance:
6 changes: 3 additions & 3 deletions docs/api/util.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ Utility Module
================

.. automodule:: spacepackets.util
:members:
:undoc-members:
:show-inheritance:
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ It also contains various helper modules

- :py:class:`spacepackets.ecss.pus_verificator.PusVerificator` class to track the verification of sent telecommands
- PTC and PFC definitions for ECSS packets inside the :py:mod:`spacepackets.ecss.fields` module
- :py:class:`spacepackets.countdown.Countdown` utility class

Other pages (online)
---------------------
Expand Down
4 changes: 4 additions & 0 deletions spacepackets/countdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@


def time_ms() -> int:
"""Returns the current :py:func:`time.time` as milliseconds."""
return round(time.time() * 1000)


class Countdown:
"""Utility class for counting down time. Exposes a simple API to initiate
it with an initial timeout and to check whether is has expired."""

def __init__(self, init_timeout: Optional[timedelta]):
if init_timeout is not None:
self._timeout_ms = int(init_timeout / timedelta(milliseconds=1))
Expand Down
4 changes: 3 additions & 1 deletion tests/cfdp/pdus/test_ack_pdu.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def test_ack_pdu(self):
transaction_seq_num=ByteFieldU32.from_u32_bytes(
bytes([0x50, 0x00, 0x10, 0x01])
),
source_entity_id=ByteFieldU32.from_u32_bytes(bytes([0x10, 0x00, 0x01, 0x02])),
source_entity_id=ByteFieldU32.from_u32_bytes(
bytes([0x10, 0x00, 0x01, 0x02])
),
dest_entity_id=ByteFieldU32.from_u32_bytes(bytes([0x30, 0x00, 0x01, 0x03])),
crc_flag=CrcFlag.WITH_CRC,
trans_mode=TransmissionMode.UNACKNOWLEDGED,
Expand Down
4 changes: 3 additions & 1 deletion tests/cfdp/test_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ def test_with_prompt_pdu(self):
self._switch_cfg()
self.pdu_conf.source_entity_id = ByteFieldU8(0)
self.pdu_conf.dest_entity_id = ByteFieldU8(0)
self.pdu_conf.transaction_seq_num = ByteFieldU16.from_u16_bytes(bytes([0x00, 0x2C]))
self.pdu_conf.transaction_seq_num = ByteFieldU16.from_u16_bytes(
bytes([0x00, 0x2C])
)
prompt_pdu = PromptPdu(
response_required=ResponseRequired.KEEP_ALIVE, pdu_conf=self.pdu_conf
)
Expand Down

0 comments on commit a9ee6ff

Please sign in to comment.