Skip to content

Commit

Permalink
Merge pull request #3 from robamu-org/develop
Browse files Browse the repository at this point in the history
PR for release 0.4.0
  • Loading branch information
robamu authored Oct 12, 2021
2 parents b5068ce + 5e69239 commit e9b66f6
Show file tree
Hide file tree
Showing 31 changed files with 1,410 additions and 506 deletions.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,65 @@ py -m pip install spacepackets
```

# Examples

You can find all examples listed here in the `example` folder as well.

## ECSS PUS Packets

This examples shows how to generate PUS packets using the PUS ping telecommand and a PUS
ping telemetry reply.

```py
from spacepackets.ecss.tc import PusTelecommand
from spacepackets.ecss.tm import PusTelemetry
from spacepackets.util import get_printable_data_string, PrintFormats


def main():
ping_cmd = PusTelecommand(
service=17,
subservice=1,
apid=0x01
)
cmd_as_bytes = ping_cmd.pack()
print_string = get_printable_data_string(print_format=PrintFormats.HEX, data=cmd_as_bytes)
print(f'Ping telecommand [17,1]: {print_string}')

ping_reply = PusTelemetry(
service=17,
subservice=2,
apid=0x01
)
tm_as_bytes = ping_reply.pack()
print_string = get_printable_data_string(print_format=PrintFormats.HEX, data=tm_as_bytes)
print(f'Ping reply [17,2]: {print_string}')


if __name__ == "__main__":
main()
```

## CCSDS Space Packet

This example shows how to generate a space packet header

```py
from spacepackets.ccsds.spacepacket import SpacePacketHeader, PacketTypes
from spacepackets.util import get_printable_data_string, PrintFormats


def main():
spacepacket_header = SpacePacketHeader(
packet_type=PacketTypes.TC,
apid=0x01,
source_sequence_count=0,
data_length=0
)
header_as_bytes = spacepacket_header.pack()
print_string = get_printable_data_string(print_format=PrintFormats.HEX, data=header_as_bytes)
print(f'Space packet header: {print_string}')


if __name__ == "__main__":
main()
```
66 changes: 66 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Examples
=========

You can find all examples listed here in the ``example`` folder of the project as well.

ECSS PUS packets
-----------------

This examples shows how to generate PUS packets using the PUS ping telecommand and a PUS
ping telemetry reply.

.. code-block::
from spacepackets.ecss.tc import PusTelecommand
from spacepackets.ecss.tm import PusTelemetry
from spacepackets.util import get_printable_data_string, PrintFormats
def main():
ping_cmd = PusTelecommand(
service=17,
subservice=1,
apid=0x01
)
cmd_as_bytes = ping_cmd.pack()
print_string = get_printable_data_string(print_format=PrintFormats.HEX, data=cmd_as_bytes)
print(f'Ping telecommand [17,1]: {print_string}')
ping_reply = PusTelemetry(
service=17,
subservice=2,
apid=0x01
)
tm_as_bytes = ping_reply.pack()
print_string = get_printable_data_string(print_format=PrintFormats.HEX, data=tm_as_bytes)
print(f'Ping reply [17,2]: {print_string}')
if __name__ == "__main__":
main()
CCSDS Space Packet
-------------------

This example shows how to generate a generic CCSDS Space Packet Header

.. code-block::
from spacepackets.ccsds.spacepacket import SpacePacketHeader, PacketTypes
from spacepackets.util import get_printable_data_string, PrintFormats
def main():
spacepacket_header = SpacePacketHeader(
packet_type=PacketTypes.TC,
apid=0x01,
source_sequence_count=0,
data_length=0
)
header_as_bytes = spacepacket_header.pack()
print_string = get_printable_data_string(print_format=PrintFormats.HEX, data=header_as_bytes)
print(f'Space packet header: {print_string}')
if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Currently, this includes the following components:
`CCSDS Blue Book 727.0-B-5`_.

Other pages (online)
---------------------

- `project page on GitHub`_
- This page, when viewed online is at https://spacepackets.readthedocs.io/en/latest
Expand All @@ -35,6 +36,7 @@ Other pages (online)
.. toctree::
:maxdepth: 4

examples
packets
api

Expand Down
27 changes: 27 additions & 0 deletions examples/example_pus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from spacepackets.ecss.tc import PusTelecommand
from spacepackets.ecss.tm import PusTelemetry
from spacepackets.util import get_printable_data_string, PrintFormats


def main():
ping_cmd = PusTelecommand(
service=17,
subservice=1,
apid=0x01
)
cmd_as_bytes = ping_cmd.pack()
print_string = get_printable_data_string(print_format=PrintFormats.HEX, data=cmd_as_bytes)
print(f'Ping telecommand [17,1]: {print_string}')

ping_reply = PusTelemetry(
service=17,
subservice=2,
apid=0x01
)
tm_as_bytes = ping_reply.pack()
print_string = get_printable_data_string(print_format=PrintFormats.HEX, data=tm_as_bytes)
print(f'Ping reply [17,2]: {print_string}')


if __name__ == "__main__":
main()
18 changes: 18 additions & 0 deletions examples/example_spacepacket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from spacepackets.ccsds.spacepacket import SpacePacketHeader, PacketTypes
from spacepackets.util import get_printable_data_string, PrintFormats


def main():
spacepacket_header = SpacePacketHeader(
packet_type=PacketTypes.TC,
apid=0x01,
source_sequence_count=0,
data_length=0
)
header_as_bytes = spacepacket_header.pack()
print_string = get_printable_data_string(print_format=PrintFormats.HEX, data=header_as_bytes)
print(f'Space packet header: {print_string}')


if __name__ == "__main__":
main()
10 changes: 7 additions & 3 deletions spacepackets/ccsds/spacepacket.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ def pack(self) -> bytearray:
header.append(self.data_length & 0xff)
return header

def get_packet_size(self) -> int:
@property
def header_length(self) -> int:
return SPACE_PACKET_HEADER_SIZE

@property
def packet_length(self) -> int:
"""Retrieve the full space 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
Expand Down Expand Up @@ -215,8 +220,7 @@ def parse_space_packets(
If a packet is detected and the
Any broken tail packets will be reinserted into the given deque
:param analysis_queue:
:param packet_id:
:param max_len: Maximum allowed packet length
:param packet_ids:
:return:
"""
tm_list = []
Expand Down
33 changes: 32 additions & 1 deletion spacepackets/cfdp/conf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
from __future__ import annotations
from dataclasses import dataclass
from typing import TypedDict, Tuple
from spacepackets.cfdp.definitions import FileSize

from spacepackets.cfdp.definitions import FileSize, TransmissionModes, CrcFlag, \
SegmentationControl, Direction
from spacepackets.log import get_console_logger


@dataclass
class PduConfig:
"""Common configuration fields for a PDU.
The default values for source entity ID and destination entity ID are the the GLOBAL_CONFIG
equivalent which should cause the header implementation to assume a globally configured
default value.
"""
transaction_seq_num: bytes
trans_mode: TransmissionModes
file_size: FileSize = FileSize.GLOBAL_CONFIG
crc_flag: CrcFlag = CrcFlag.GLOBAL_CONFIG
direction: Direction = Direction.TOWARDS_RECEIVER
seg_ctrl: SegmentationControl = SegmentationControl.NO_RECORD_BOUNDARIES_PRESERVATION
source_entity_id: bytes = bytes()
dest_entity_id: bytes = bytes()

@classmethod
def empty(cls) -> PduConfig:
return PduConfig(
transaction_seq_num=bytes([0]),
trans_mode=TransmissionModes.ACKNOWLEDGED,
source_entity_id=bytes([0]),
dest_entity_id=bytes([0])
)


class CfdpDict(TypedDict):
source_dest_entity_ids: Tuple[bytes, bytes]
with_crc: bool
Expand Down
33 changes: 33 additions & 0 deletions spacepackets/cfdp/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,39 @@
import struct


class PduType(enum.IntEnum):
FILE_DIRECTIVE = 0
FILE_DATA = 1


class Direction(enum.IntEnum):
TOWARDS_RECEIVER = 0
TOWARDS_SENDER = 1


class TransmissionModes(enum.IntEnum):
ACKNOWLEDGED = 0
UNACKNOWLEDGED = 1


class CrcFlag(enum.IntEnum):
NO_CRC = 0
WITH_CRC = 1
GLOBAL_CONFIG = 2


class SegmentMetadataFlag(enum.IntEnum):
"""Aways 0 and ignored for File Directive PDUs (CCSDS 727.0-B-5 p.75)"""
NOT_PRESENT = 0
PRESENT = 1


class SegmentationControl(enum.IntEnum):
"""Always 0 and ignored for File Directive PDUs (CCSDS 727.0-B-5 p.75)"""
NO_RECORD_BOUNDARIES_PRESERVATION = 0
RECORD_BOUNDARIES_PRESERVATION = 1


class LenInBytes(enum.IntEnum):
ONE_BYTE = 1
TWO_BYTES = 2
Expand Down
3 changes: 2 additions & 1 deletion spacepackets/cfdp/lv.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def __init__(self, value: bytes):
self.len = len(value)
self.value = value

def get_total_len(self):
@property
def packet_len(self):
"""Returns length of full LV packet"""
return self.len + 1

Expand Down
5 changes: 2 additions & 3 deletions spacepackets/cfdp/pdu/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .header import PduHeader, PduType, Direction, TransmissionModes, CrcFlag, SegmentMetadataFlag, \
SegmentationControl
from .file_directive import FileDirectivePduBase, ConditionCode, DirectiveCodes
from .header import PduHeader, PduType, SegmentMetadataFlag
from .file_directive import FileDirectivePduBase, ConditionCode, DirectiveCodes, IsFileDirective
from .ack import TransactionStatus, AckPdu
from .eof import EofPdu
from .finished import FinishedPdu
Expand Down
Loading

0 comments on commit e9b66f6

Please sign in to comment.