Skip to content

Commit

Permalink
docs now work
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Jan 31, 2025
1 parent 133a7ac commit 56eff02
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 8 deletions.
35 changes: 31 additions & 4 deletions src/tmtccmd/pus/tm/s3_fsfw_hk.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@


class Service3FsfwHkPacket:
"""Housekeeping service HK telemetry parser.
This class can be used to parse the FSFW HK packets for HK packets with the
:py:class:`spacepackets.ecss.pus_3_hk.Subservice` `TM_HK_REPORT` (25) and `TM_DIAGNOSTICS_REPORT`
(26) subservice.
It parses the object ID, set ID fields and the HK data.
Raises
--------
ValueError
Subservice is not correct or the TM source data length is smaller than 8, which is the
minimum required size to unpack object ID and set ID.
"""

def __init__(self, pus_tm: PusTelemetry) -> None:
if (
pus_tm.subservice != Subservice.TM_HK_REPORT
Expand All @@ -19,7 +34,19 @@ def __init__(self, pus_tm: PusTelemetry) -> None:
f"invalid subservice {pus_tm.subservice}, expected {Subservice.TM_HK_REPORT} or "
f"{Subservice.TM_DIAGNOSTICS_REPORT}"
)
self.pus_tm = pus_tm
self.object_id = ComponentIdU32(struct.unpack("!i", pus_tm.source_data[0:4])[0])
self.set_id = struct.unpack("!I", pus_tm.source_data[4:8])[0]
self.hk_data = pus_tm.source_data[8:]

if len(pus_tm.source_data) < 8:
raise ValueError(
f"not enough data available, expected at least 8 bytes, found {len(pus_tm.source_data)}"
)

#: Corresponding PUS TM packet.
self.pus_tm: PusTelemetry = pus_tm
#: Object ID.
self.object_id: ComponentIdU32 = ComponentIdU32(
struct.unpack("!i", pus_tm.source_data[0:4])[0]
)
#: Housekeeping Set ID.
self.set_id: int = struct.unpack("!I", pus_tm.source_data[4:8])[0]
#: Housekeeping Data.
self.hk_data: bytes = pus_tm.source_data[8:]
32 changes: 28 additions & 4 deletions src/tmtccmd/pus/tm/s8_fsfw_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,36 @@


class Service8FsfwDataReply:
"""FSFW Action service data reply telemetry parser.
This class can be used to parse the FSFW action data replies with the
:py:class:`tmtccmd.pus.s8_fsfw_action_defs.CustomSubservice.TM_DATA_REPLY` subservice.
It parses the object ID, the action ID and the reply data.
Raises
--------
ValueError
Subservice is not correct or the TM source data length is smaller than 8, which is the
minimum required size to unpack object ID and action ID.
"""

def __init__(self, pus_tm: PusTelemetry) -> None:
if pus_tm.subservice != CustomSubservice.TM_DATA_REPLY:
raise ValueError(
f"invalid subservice {pus_tm.subservice}, expected {CustomSubservice.TM_DATA_REPLY}"
)
self.pus_tm = pus_tm
self.object_id = ComponentIdU32(struct.unpack("!i", pus_tm.source_data[0:4])[0])
self.action_id = struct.unpack("!I", pus_tm.source_data[4:8])[0]
self.reply_data = pus_tm.source_data[8:]
if len(pus_tm.source_data) < 8:
raise ValueError(
f"not enough data available, expected at least 8 bytes, found {len(pus_tm.source_data)}"
)
#: Corresponding PUS TM packet.
self.pus_tm: PusTelemetry = pus_tm
#: Object ID.
self.object_id: ComponentIdU32 = ComponentIdU32(
struct.unpack("!i", pus_tm.source_data[0:4])[0]
)
#: Action ID.
self.action_id: int = struct.unpack("!I", pus_tm.source_data[4:8])[0]
#: Reply Data.
self.reply_data: bytes = pus_tm.source_data[8:]
2 changes: 2 additions & 0 deletions src/tmtccmd/util/obj_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class ComponentIdU32(ComponentIdBase):
>>> obj_id = ComponentIdU32(42, "Object with the answer to everything")
>>> int(obj_id)
42
>>> obj_id.value
42
>>> obj_id.name
'Object with the answer to everything'
>>> obj_id.as_bytes.hex(sep=",")
Expand Down
12 changes: 12 additions & 0 deletions tests/tm/test_srv3_fsfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ def test_unpack(self):
self.assertEqual(tm_packet.set_id, example_set_id)
self.assertEqual(tm_packet.hk_data, example_hk_data)

def test_unpack_not_enough_data(self):
for i in range(0, 8):
data = bytes([0x01] * i)
with self.assertRaises(ValueError):
tm = PusTelemetry(
service=PusService.S8_FUNC_CMD,
subservice=Subservice.TM_HK_REPORT,
source_data=data,
timestamp=bytes(),
)
Service3FsfwHkPacket(tm)

def test_unpack_invalid_subservice(self):
example_obj_id = 0x01020304
example_action_id = 0x04030201
Expand Down
30 changes: 30 additions & 0 deletions tests/tm/test_srv8_fsfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,36 @@ def test_unpack(self):
self.assertEqual(tm_packet.action_id, example_action_id)
self.assertEqual(tm_packet.reply_data, example_reply_data)

def test_unpack_not_enough_data(self):
for i in range(0, 8):
data = bytes([0x01] * i)
with self.assertRaises(ValueError):
tm = PusTelemetry(
service=PusService.S8_FUNC_CMD,
subservice=CustomSubservice.TM_DATA_REPLY,
source_data=data,
timestamp=bytes(),
)
Service8FsfwDataReply(tm)

def test_unpack_empty_reply_data(self):
example_obj_id = 0x01020304
example_action_id = 0x04030201
example_reply_data = bytes()
tm = PusTelemetry(
service=PusService.S8_FUNC_CMD,
subservice=CustomSubservice.TM_DATA_REPLY,
source_data=self.pack_data_reply_src_data(
example_obj_id, example_action_id, example_reply_data
),
timestamp=bytes(),
)

tm_packet = Service8FsfwDataReply(tm)
self.assertEqual(tm_packet.object_id.value, example_obj_id)
self.assertEqual(tm_packet.action_id, example_action_id)
self.assertEqual(tm_packet.reply_data, example_reply_data)

def test_unpack_invalid_subservice(self):
example_obj_id = 0x01020304
example_action_id = 0x04030201
Expand Down

0 comments on commit 56eff02

Please sign in to comment.