fsfw-example-tmtc-common/pus_tc/service_3_housekeeping.py

168 lines
5.3 KiB
Python
Raw Normal View History

2022-07-03 20:58:32 +02:00
from datetime import timedelta
2021-10-13 12:08:50 +02:00
from spacepackets.ecss.tc import PusTelecommand
2022-07-28 15:44:57 +02:00
from deps.spacepackets.spacepackets.ecss import PusServices
from tmtccmd.config import TmTcDefWrapper, OpCodeEntry
2022-07-03 20:58:32 +02:00
from tmtccmd.tc import QueueHelper
2022-05-18 23:40:13 +02:00
from tmtccmd.tc.pus_200_fsfw_modes import pack_mode_data, Modes
from tmtccmd.tc.pus_20_params import (
pack_boolean_parameter_app_data,
pack_fsfw_load_param_cmd,
2021-12-14 15:46:00 +01:00
)
2022-05-18 23:40:13 +02:00
from tmtccmd.tc.pus_3_fsfw_hk import make_sid, generate_one_hk_command
import tmtccmd.tc.pus_3_fsfw_hk as srv3
from tmtccmd.tc.pus_8_funccmd import generate_action_command
2021-07-14 00:28:33 +02:00
from common_tmtc.config.object_ids import TEST_DEVICE_0_ID, TEST_DEVICE_1_ID
# Set IDs
TEST_SET_ID = 0
# Action IDs
TEST_NOTIFICATION_ACTION_ID = 3
# Parameters
PARAM_ACTIVATE_CHANGING_DATASETS = 4
2022-07-28 15:44:57 +02:00
def add_hk_cmds(defs: TmTcDefWrapper):
op_code_entry = OpCodeEntry()
op_code_entry.add(keys=["0", "test"], info="Generic Test")
defs.add_service(
name=str(PusServices.S3_HOUSEKEEPING.value),
info="PUS Service 3 Housekeeping",
op_code_entry=op_code_entry
)
2022-07-03 20:58:32 +02:00
def pack_service_3_commands_into(q: QueueHelper, op_code: str):
2021-07-14 00:28:33 +02:00
current_ssc = 3000
device_idx = 0
if device_idx == 0:
object_id = TEST_DEVICE_0_ID
else:
object_id = TEST_DEVICE_1_ID
if op_code == "0":
# This will pack all the tests
2021-12-14 15:46:00 +01:00
pack_service_3_test_info(
2022-07-03 20:58:32 +02:00
q=q,
2021-12-14 15:46:00 +01:00
object_id=object_id,
device_idx=device_idx,
)
2021-07-14 00:28:33 +02:00
elif op_code == "1":
# Extremely simple, generate one HK packet
2021-12-14 15:46:00 +01:00
pack_gen_one_hk_command(
2022-07-03 20:58:32 +02:00
q=q,
2021-12-14 15:46:00 +01:00
device_idx=device_idx,
object_id=object_id,
)
2021-07-14 00:28:33 +02:00
elif op_code == "2":
# Housekeeping basic test
2022-07-03 20:58:32 +02:00
pack_housekeeping_basic_test(q=q, object_id=object_id)
2021-07-14 00:28:33 +02:00
elif op_code == "3":
# Notification demo
2022-07-03 20:58:32 +02:00
pack_notification_basic_test(q=q, object_id=object_id)
2021-07-14 00:28:33 +02:00
2022-07-03 20:58:32 +02:00
def pack_service_3_test_info(q: QueueHelper, device_idx: int, object_id: bytearray):
q.add_log_cmd("Service 3 (Housekeeping Service): All tests")
pack_gen_one_hk_command(q=q, device_idx=device_idx, object_id=object_id)
pack_housekeeping_basic_test(q=q, object_id=object_id)
pack_notification_basic_test(
q=q,
2021-12-14 15:46:00 +01:00
object_id=object_id,
enable_normal_mode=False,
2021-07-14 00:28:33 +02:00
)
2022-07-03 20:58:32 +02:00
def pack_gen_one_hk_command(q: QueueHelper, device_idx: int, object_id: bytearray):
2021-07-14 00:28:33 +02:00
test_sid = make_sid(object_id=object_id, set_id=TEST_SET_ID)
2022-07-03 20:58:32 +02:00
q.add_log_cmd(
f"Service 3 Test: Generate one test set packet for test device {device_idx}"
2021-07-14 00:28:33 +02:00
)
2022-07-03 20:58:32 +02:00
q.add_pus_tc(generate_one_hk_command(sid=test_sid))
2021-07-14 00:28:33 +02:00
def pack_housekeeping_basic_test(
2022-07-03 20:58:32 +02:00
q: QueueHelper,
2021-12-14 15:46:00 +01:00
object_id: bytearray,
enable_normal_mode: bool = True,
2022-07-03 20:58:32 +02:00
):
2021-07-14 00:28:33 +02:00
"""
This basic test will request one HK packet, then it will enable periodic packets and listen
to the periodic packets for a few seconds. After that, HK packets will be disabled again.
"""
test_sid = make_sid(object_id=object_id, set_id=TEST_SET_ID)
# Enable changing datasets via parameter service (Service 20)
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Service 3 Test: Performing basic HK tests")
2021-07-14 00:28:33 +02:00
if enable_normal_mode:
# Set mode normal so that sets are changed/read regularly
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Service 3 Test: Set Normal Mode")
2021-10-13 12:08:50 +02:00
mode_data = pack_mode_data(object_id, Modes.NORMAL, 0)
2022-07-03 20:58:32 +02:00
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data))
2021-07-14 00:28:33 +02:00
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Enabling changing datasets")
2022-05-18 23:40:13 +02:00
app_data = pack_boolean_parameter_app_data(
2021-12-14 15:46:00 +01:00
object_id=object_id,
domain_id=0,
unique_id=PARAM_ACTIVATE_CHANGING_DATASETS,
parameter=True,
2021-07-14 00:28:33 +02:00
)
2022-07-28 15:44:57 +02:00
q.add_pus_tc(pack_fsfw_load_param_cmd(app_data=app_data))
2021-07-14 00:28:33 +02:00
# Enable periodic reporting
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Enabling periodic thermal sensor packet generation: ")
q.add_pus_tc(
PusTelecommand(
service=3,
subservice=srv3.Subservices.TC_ENABLE_PERIODIC_HK_GEN,
app_data=test_sid,
)
2021-12-14 15:46:00 +01:00
)
2022-07-03 20:58:32 +02:00
q.add_wait(timedelta(seconds=2.0))
2021-07-14 00:28:33 +02:00
# Disable periodic reporting
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Disabling periodic thermal sensor packet generation: ")
q.add_pus_tc(
PusTelecommand(
service=3,
subservice=srv3.Subservices.TC_DISABLE_PERIODIC_HK_GEN,
app_data=test_sid,
)
2021-12-14 15:46:00 +01:00
)
2021-07-14 00:28:33 +02:00
# Disable changing datasets via parameter service (Service 20)
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Disabling changing datasets")
2022-05-18 23:40:13 +02:00
app_data = pack_boolean_parameter_app_data(
2021-12-14 15:46:00 +01:00
object_id=object_id,
domain_id=0,
unique_id=PARAM_ACTIVATE_CHANGING_DATASETS,
parameter=False,
2021-07-14 00:28:33 +02:00
)
2022-07-28 15:44:57 +02:00
q.add_pus_tc(pack_fsfw_load_param_cmd(app_data=app_data))
2021-07-14 00:28:33 +02:00
2021-12-14 15:46:00 +01:00
def pack_notification_basic_test(
2022-07-03 20:58:32 +02:00
q: QueueHelper,
2021-12-14 15:46:00 +01:00
object_id: bytearray,
enable_normal_mode: bool = True,
2022-07-03 20:58:32 +02:00
):
q.add_log_cmd("Service 3 Test: Performing notification tests")
2021-07-14 00:28:33 +02:00
if enable_normal_mode:
# Set mode normal so that sets are changed/read regularly
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Service 3 Test: Set Normal Mode")
2021-10-13 12:08:50 +02:00
mode_data = pack_mode_data(object_id, Modes.NORMAL, 0)
2022-07-03 20:58:32 +02:00
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data))
2021-07-14 00:28:33 +02:00
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Triggering notification")
q.add_pus_tc(
generate_action_command(
object_id=object_id, action_id=TEST_NOTIFICATION_ACTION_ID
)
2021-07-14 00:28:33 +02:00
)