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-28 15:37:19 +02:00
|
|
|
from spacepackets.ecss import PusServices
|
2021-10-13 12:08:50 +02:00
|
|
|
|
2022-08-17 17:23:02 +02:00
|
|
|
from tmtccmd.config import TmtcDefinitionWrapper, OpCodeEntry
|
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
|
2022-07-28 16:37:01 +02:00
|
|
|
from tmtccmd.tc.queue import DefaultPusQueueHelper
|
2021-07-14 00:28:33 +02:00
|
|
|
|
|
|
|
LOGGER = get_console_logger()
|
|
|
|
|
|
|
|
|
2022-08-17 17:23:02 +02:00
|
|
|
def add_param_cmds(defs: TmtcDefinitionWrapper):
|
2022-07-28 15:37:19 +02:00
|
|
|
op_code_entry = OpCodeEntry()
|
|
|
|
op_code_entry.add(keys=["0", "test"], info="Generic Test")
|
|
|
|
defs.add_service(
|
|
|
|
name=str(PusServices.S20_PARAMETER.value),
|
2022-07-28 15:44:57 +02:00
|
|
|
info="PUS Service 20 Parameters",
|
2022-07-28 16:37:01 +02:00
|
|
|
op_code_entry=op_code_entry,
|
2022-07-28 15:37:19 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-07-28 16:37:01 +02:00
|
|
|
def pack_service20_commands_into(q: DefaultPusQueueHelper, 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-28 16:37:01 +02:00
|
|
|
def pack_service20_test_into(q: DefaultPusQueueHelper, 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
|
|
|
|
|
2022-07-28 15:37:19 +02:00
|
|
|
# set mode on
|
|
|
|
q.add_log_cmd("Testing Service 20: Set Mode On")
|
|
|
|
mode_data = pack_mode_data(object_id, Modes.ON, 0)
|
|
|
|
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data))
|
2021-07-14 00:28:33 +02:00
|
|
|
# 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-28 16:37:01 +02:00
|
|
|
def load_param_0_simple_test_commands(q: DefaultPusQueueHelper):
|
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-28 16:37:01 +02:00
|
|
|
def load_param_1_simple_test_commands(q: DefaultPusQueueHelper):
|
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-28 16:37:01 +02:00
|
|
|
def load_param_2_simple_test_commands(q: DefaultPusQueueHelper):
|
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())
|