From 7e24589184bb7bbd427c66ed55b3c29bbeba927f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 24 Feb 2022 10:56:36 +0100 Subject: [PATCH] added new core controller commands --- config/cmd_definitions.py | 48 +++++++++++++++++++--- pus_tc/core.py | 83 +++++++++++++++++++++++++++++++++------ pus_tc/pdu1.py | 8 +++- 3 files changed, 119 insertions(+), 20 deletions(-) diff --git a/config/cmd_definitions.py b/config/cmd_definitions.py index 589e581..3402dfa 100644 --- a/config/cmd_definitions.py +++ b/config/cmd_definitions.py @@ -38,12 +38,50 @@ def add_bpx_cmd_definitions(cmd_dict: ServiceOpCodeDictT): def add_core_controller_definitions(cmd_dict: ServiceOpCodeDictT): + from pus_tc.core import OpCodes + od = dict() - add_op_code_entry(op_code_dict=od, keys=["0", "reboot"], info="Reboot with Prompt") - add_op_code_entry(op_code_dict=od, keys=["1", "reboot_0_0"], info="Reboot 0 0") - add_op_code_entry(op_code_dict=od, keys=["2", "reboot_0_1"], info="Reboot 0 1") - add_op_code_entry(op_code_dict=od, keys=["3", "reboot_1_0"], info="Reboot 1 0") - add_op_code_entry(op_code_dict=od, keys=["4", "reboot_1_1"], info="Reboot 1 1") + add_op_code_entry(op_code_dict=od, keys=OpCodes.REBOOT, info="Reboot with Prompt") + add_op_code_entry(op_code_dict=od, keys=OpCodes.REBOOT_SELF, info="Reboot Self") + add_op_code_entry(op_code_dict=od, keys=OpCodes.REBOOT_0_0, info="Reboot 0 0") + add_op_code_entry(op_code_dict=od, keys=OpCodes.REBOOT_0_1, info="Reboot 0 1") + add_op_code_entry(op_code_dict=od, keys=OpCodes.REBOOT_1_0, info="Reboot 1 0") + add_op_code_entry(op_code_dict=od, keys=OpCodes.REBOOT_1_1, info="Reboot 1 1") + add_op_code_entry( + op_code_dict=od, + keys=OpCodes.ENABLE_REBOOT_FILE_HANDLING, + info="Enable reboot file handling", + ) + add_op_code_entry( + op_code_dict=od, + keys=OpCodes.DISABLE_REBOOT_FILE_HANDLING, + info="Disable reboot file handling", + ) + add_op_code_entry( + op_code_dict=od, + keys=OpCodes.RESET_ALL_REBOOT_COUNTERS, + info="Reset all reboot counters", + ) + add_op_code_entry( + op_code_dict=od, + keys=OpCodes.RESET_REBOOT_COUNTER_00, + info="Reset reboot counter 0 0", + ) + add_op_code_entry( + op_code_dict=od, + keys=OpCodes.RESET_REBOOT_COUNTER_01, + info="Reset reboot counter 0 1", + ) + add_op_code_entry( + op_code_dict=od, + keys=OpCodes.RESET_REBOOT_COUNTER_10, + info="Reset reboot counter 1 0", + ) + add_op_code_entry( + op_code_dict=od, + keys=OpCodes.RESET_REBOOT_COUNTER_11, + info="Reset reboot counter 1 1", + ) add_service_op_code_entry( srv_op_code_dict=cmd_dict, name=CustomServiceList.CORE.value, diff --git a/pus_tc/core.py b/pus_tc/core.py index a30d528..338337b 100644 --- a/pus_tc/core.py +++ b/pus_tc/core.py @@ -10,16 +10,32 @@ LOGGER = get_console_logger() class ActionIds(enum.IntEnum): + LIST_DIR_INTO_FILE = 0 + SWITCH_REBOOT_FILE_HANDLING = 5 + RESET_ALL_REBOOT_COUNTERS = 6 + RESET_REBOOT_COUNTER_00 = 7 + RESET_REBOOT_COUNTER_01 = 8 + RESET_REBOOT_COUNTER_10 = 9 + RESET_REBOOT_COUNTER_11 = 10 + SET_MAX_REBOOT_CNT = 11 REBOOT = 32 -class OpCodes(enum.Enum): - REBOOT = "reboot" - REBOOT_SELF = "reboot_self" - REBOOT_0_0 = "reboot_0_0" - REBOOT_0_1 = "reboot_0_1" - REBOOT_1_0 = "reboot_1_0" - REBOOT_1_1 = "reboot_1_1" +class OpCodes: + REBOOT = ["0", "reboot"] + REBOOT_SELF = ["1", "reboot_self"] + REBOOT_0_0 = ["2", "reboot_0_0"] + REBOOT_0_1 = ["3", "reboot_0_1"] + REBOOT_1_0 = ["4", "reboot_1_0"] + REBOOT_1_1 = ["5", "reboot_1_1"] + ENABLE_REBOOT_FILE_HANDLING = ["6", "rbh-off"] + DISABLE_REBOOT_FILE_HANDLING = ["7", "rbh-on"] + RESET_ALL_REBOOT_COUNTERS = ["8", "rbh-reset-a"] + RESET_REBOOT_COUNTER_00 = ["9", "rbh-reset-00"] + RESET_REBOOT_COUNTER_01 = ["10", "rbh-reset-01"] + RESET_REBOOT_COUNTER_10 = ["11", "rbh-reset-10"] + RESET_REBOOT_COUNTER_11 = ["12", "rbh-reset-11"] + SET_MAX_REBOOT_CNT = ["13", "rbh-max-cnt"] class Chip(enum.IntEnum): @@ -35,7 +51,7 @@ class Copy(enum.IntEnum): def pack_core_commands(tc_queue: TcQueueT, op_code: str): - if op_code == OpCodes.REBOOT.value: + if op_code in OpCodes.REBOOT: reboot_self, chip_select, copy_select = determine_reboot_params() perform_reboot_cmd( tc_queue=tc_queue, @@ -43,30 +59,71 @@ def pack_core_commands(tc_queue: TcQueueT, op_code: str): chip=chip_select, copy=copy_select, ) - elif op_code == OpCodes.REBOOT_SELF.value: + elif op_code in OpCodes.REBOOT_SELF: perform_reboot_cmd(tc_queue=tc_queue, reboot_self=True) - elif op_code == OpCodes.REBOOT_0_0.value: + elif op_code in OpCodes.REBOOT_0_0: perform_reboot_cmd( tc_queue=tc_queue, reboot_self=False, chip=Chip.CHIP_0, copy=Copy.COPY_0_NOM ) - elif op_code == OpCodes.REBOOT_0_1.value: + elif op_code in OpCodes.REBOOT_0_1: perform_reboot_cmd( tc_queue=tc_queue, reboot_self=False, chip=Chip.CHIP_0, copy=Copy.COPY_1_GOLD, ) - elif op_code == OpCodes.REBOOT_1_0.value: + elif op_code in OpCodes.REBOOT_1_0: perform_reboot_cmd( tc_queue=tc_queue, reboot_self=False, chip=Chip.CHIP_1, copy=Copy.COPY_0_NOM ) - elif op_code == OpCodes.REBOOT_1_1.value: + elif op_code in OpCodes.REBOOT_1_1: perform_reboot_cmd( tc_queue=tc_queue, reboot_self=False, chip=Chip.CHIP_1, copy=Copy.COPY_1_GOLD, ) + elif op_code in OpCodes.DISABLE_REBOOT_FILE_HANDLING: + tc_queue.appendleft((QueueCommands.PRINT, "Disabling reboot file handling")) + app_data = bytearray([0]) + generate_action_command( + object_id=CORE_CONTROLLER_ID, + action_id=ActionIds.SWITCH_REBOOT_FILE_HANDLING, + app_data=app_data, + ) + elif op_code in OpCodes.ENABLE_REBOOT_FILE_HANDLING: + tc_queue.appendleft((QueueCommands.PRINT, "Enabling reboot file handling")) + app_data = bytearray([1]) + generate_action_command( + object_id=CORE_CONTROLLER_ID, + action_id=ActionIds.SWITCH_REBOOT_FILE_HANDLING, + app_data=app_data, + ) + elif op_code in OpCodes.RESET_ALL_REBOOT_COUNTERS: + tc_queue.appendleft((QueueCommands.PRINT, "Resetting all reboot counters")) + generate_action_command( + object_id=CORE_CONTROLLER_ID, action_id=ActionIds.RESET_ALL_REBOOT_COUNTERS + ) + elif op_code in OpCodes.RESET_REBOOT_COUNTER_00: + tc_queue.appendleft((QueueCommands.PRINT, "Resetting reboot counter 0 0")) + generate_action_command( + object_id=CORE_CONTROLLER_ID, action_id=ActionIds.RESET_REBOOT_COUNTER_00 + ) + elif op_code in OpCodes.RESET_REBOOT_COUNTER_01: + tc_queue.appendleft((QueueCommands.PRINT, "Resetting reboot counter 0 1")) + generate_action_command( + object_id=CORE_CONTROLLER_ID, action_id=ActionIds.RESET_REBOOT_COUNTER_01 + ) + elif op_code in OpCodes.RESET_REBOOT_COUNTER_10: + tc_queue.appendleft((QueueCommands.PRINT, "Resetting reboot counter 1 0")) + generate_action_command( + object_id=CORE_CONTROLLER_ID, action_id=ActionIds.RESET_REBOOT_COUNTER_10 + ) + elif op_code in OpCodes.RESET_REBOOT_COUNTER_11: + tc_queue.appendleft((QueueCommands.PRINT, "Resetting reboot counter 1 1")) + generate_action_command( + object_id=CORE_CONTROLLER_ID, action_id=ActionIds.RESET_REBOOT_COUNTER_11 + ) def determine_reboot_params() -> (bool, Chip, Copy): diff --git a/pus_tc/pdu1.py b/pus_tc/pdu1.py index 95419f6..1df00fe 100644 --- a/pus_tc/pdu1.py +++ b/pus_tc/pdu1.py @@ -134,7 +134,9 @@ def pack_pdu1_commands(object_id: bytearray, tc_queue: TcQueueT, op_code: str): ) tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu1OpCodes.SCEX_ON.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn Solar Cell Experiment on")) + tc_queue.appendleft( + (QueueCommands.PRINT, "PDU1: Turn Solar Cell Experiment on") + ) command = pack_set_param_command( object_id, PDUConfigTable.out_en_5.parameter_address, @@ -143,7 +145,9 @@ def pack_pdu1_commands(object_id: bytearray, tc_queue: TcQueueT, op_code: str): ) tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu1OpCodes.SCEX_OFF.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn Solar Cell Experiment off")) + tc_queue.appendleft( + (QueueCommands.PRINT, "PDU1: Turn Solar Cell Experiment off") + ) command = pack_set_param_command( object_id, PDUConfigTable.out_en_5.parameter_address,