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

83 lines
3.4 KiB
Python
Raw Normal View History

2021-07-14 00:28:33 +02:00
import struct
2021-10-13 12:08:50 +02:00
from spacepackets.ecss.tc import PusTelecommand
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_20_params import pack_type_and_matrix_data, pack_parameter_id
from tmtccmd.tc.pus_200_fsfw_modes import pack_mode_data, Modes
from tmtccmd.logging import get_console_logger
2021-07-14 00:28:33 +02:00
from common_tmtc.config.object_ids import TEST_DEVICE_0_ID
LOGGER = get_console_logger()
2022-07-03 20:58:32 +02:00
def pack_service20_commands_into(q: QueueHelper, op_code: str):
2021-07-14 00:28:33 +02:00
if op_code == "0":
2022-07-03 20:58:32 +02:00
pack_service20_test_into(q=q)
2021-07-14 00:28:33 +02:00
2022-07-03 20:58:32 +02:00
def pack_service20_test_into(q: QueueHelper, called_externally: bool = False):
2021-07-14 00:28:33 +02:00
if called_externally is False:
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Testing Service 20")
2021-07-14 00:28:33 +02:00
object_id = TEST_DEVICE_0_ID
# set mode normal
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Testing Service 20: Set Normal Mode")
2022-05-18 23:40:13 +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
load_param_0_simple_test_commands(q)
load_param_1_simple_test_commands(q)
load_param_2_simple_test_commands(q)
2021-07-14 00:28:33 +02:00
2022-07-03 20:58:32 +02:00
def load_param_0_simple_test_commands(q: QueueHelper):
2021-07-14 00:28:33 +02:00
object_id = TEST_DEVICE_0_ID
parameter_id_0 = pack_parameter_id(domain_id=0, unique_id=0, linear_index=0)
# test checking Load for uint32_t
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Testing Service 20: Load uint32_t")
2021-07-14 00:28:33 +02:00
type_and_matrix_data = pack_type_and_matrix_data(3, 14, 1, 1)
parameter_data = struct.pack("!I", 42)
payload = object_id + parameter_id_0 + type_and_matrix_data + parameter_data
2022-07-03 20:58:32 +02:00
q.add_pus_tc(PusTelecommand(service=20, subservice=128, app_data=payload))
2021-07-14 00:28:33 +02:00
# test checking Dump for uint32_t
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Testing Service 20: Dump uint32_t")
2021-07-14 00:28:33 +02:00
payload = object_id + parameter_id_0
2022-07-03 20:58:32 +02:00
q.add_pus_tc(PusTelecommand(service=20, subservice=129, app_data=payload))
2021-07-14 00:28:33 +02:00
2022-07-03 20:58:32 +02:00
def load_param_1_simple_test_commands(q: QueueHelper):
2021-07-14 00:28:33 +02:00
object_id = TEST_DEVICE_0_ID
parameter_id_1 = pack_parameter_id(domain_id=0, unique_id=1, linear_index=0)
# test checking Load for int32_t
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Testing Service 20: Load int32_t")
2021-07-14 00:28:33 +02:00
type_and_matrix_data = pack_type_and_matrix_data(4, 14, 1, 1)
parameter_data = struct.pack("!i", -42)
payload = object_id + parameter_id_1 + type_and_matrix_data + parameter_data
2022-07-03 20:58:32 +02:00
q.add_pus_tc(PusTelecommand(service=20, subservice=128, app_data=payload))
2021-07-14 00:28:33 +02:00
# test checking Dump for int32_t
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Testing Service 20: Dump int32_t")
2021-07-14 00:28:33 +02:00
payload = object_id + parameter_id_1
2022-07-03 20:58:32 +02:00
q.add_pus_tc(PusTelecommand(service=20, subservice=129, app_data=payload))
2021-07-14 00:28:33 +02:00
2022-07-03 20:58:32 +02:00
def load_param_2_simple_test_commands(q: QueueHelper):
2021-07-14 00:28:33 +02:00
object_id = TEST_DEVICE_0_ID
parameter_id_2 = pack_parameter_id(domain_id=0, unique_id=2, linear_index=0)
# test checking Load for float
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Testing Service 20: Load float")
2021-07-14 00:28:33 +02:00
type_and_matrix_data = pack_type_and_matrix_data(ptc=5, pfc=1, rows=1, columns=3)
parameter_data = struct.pack("!fff", 4.2, -4.2, 49)
payload = object_id + parameter_id_2 + type_and_matrix_data + parameter_data
2022-07-03 20:58:32 +02:00
q.add_pus_tc(PusTelecommand(service=20, subservice=128, app_data=payload))
2021-07-14 00:28:33 +02:00
# test checking Dump for float
# Skip dump for now, still not properly implemented
# tc_queue.appendleft((QueueCommands.PRINT, "Testing Service 20: Dump float"))
# payload = object_id + parameter_id_2
# command = PusTelecommand(service=20, subservice=129, ssc=2060, app_data=payload)
# tc_queue.appendleft(command.pack_command_tuple())