2021-08-03 15:28:28 +02:00
|
|
|
import enum
|
|
|
|
|
2022-05-24 01:13:21 +02:00
|
|
|
from config.definitions import CustomServiceList
|
2022-08-12 10:18:21 +02:00
|
|
|
from tmtccmd.config import TmtcDefinitionWrapper
|
2022-07-04 17:59:09 +02:00
|
|
|
|
2022-08-08 16:32:18 +02:00
|
|
|
from tmtccmd.tc import DefaultPusQueueHelper
|
2022-05-05 16:15:53 +02:00
|
|
|
from tmtccmd.tc.pus_8_funccmd import generate_action_command
|
2022-04-05 00:51:52 +02:00
|
|
|
from tmtccmd.logging import get_console_logger
|
2022-05-05 16:15:53 +02:00
|
|
|
from tmtccmd.tc.pus_3_fsfw_hk import make_sid, generate_one_hk_command
|
2022-08-12 10:18:21 +02:00
|
|
|
from tmtccmd.config.tmtc import OpCodeEntry, tmtc_definitions_provider
|
2021-08-03 15:28:28 +02:00
|
|
|
from config.object_ids import CORE_CONTROLLER_ID
|
|
|
|
|
2022-07-05 02:12:54 +02:00
|
|
|
|
2021-08-03 15:28:28 +02:00
|
|
|
LOGGER = get_console_logger()
|
|
|
|
|
|
|
|
|
|
|
|
class ActionIds(enum.IntEnum):
|
2022-02-24 10:56:36 +01:00
|
|
|
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
|
2022-05-24 01:13:21 +02:00
|
|
|
XSC_REBOOT = 32
|
|
|
|
FULL_REBOOT = 34
|
2021-08-03 15:28:28 +02:00
|
|
|
|
|
|
|
|
2022-03-13 21:35:12 +01:00
|
|
|
class SetIds(enum.IntEnum):
|
2022-03-14 10:03:50 +01:00
|
|
|
HK = 5
|
2022-03-13 21:35:12 +01:00
|
|
|
|
|
|
|
|
2022-02-24 10:56:36 +01:00
|
|
|
class OpCodes:
|
2022-05-24 01:13:21 +02:00
|
|
|
REBOOT_XSC = ["0", "reboot-xsc"]
|
|
|
|
XSC_REBOOT_SELF = ["1", "reboot-self"]
|
|
|
|
XSC_REBOOT_0_0 = ["2", "reboot-00"]
|
|
|
|
XSC_REBOOT_0_1 = ["3", "reboot-01"]
|
|
|
|
XSC_REBOOT_1_0 = ["4", "reboot-10"]
|
|
|
|
XSC_REBOOT_1_1 = ["5", "reboot-11"]
|
|
|
|
REBOOT_FULL = ["6", "reboot-regular"]
|
|
|
|
GET_HK = ["7", "get-hk"]
|
|
|
|
ENABLE_REBOOT_FILE_HANDLING = ["32", "rbh-off"]
|
|
|
|
DISABLE_REBOOT_FILE_HANDLING = ["33", "rbh-on"]
|
|
|
|
RESET_ALL_REBOOT_COUNTERS = ["34", "rbh-reset-a"]
|
|
|
|
RESET_REBOOT_COUNTER_00 = ["35", "rbh-reset-00"]
|
|
|
|
RESET_REBOOT_COUNTER_01 = ["36", "rbh-reset-01"]
|
|
|
|
RESET_REBOOT_COUNTER_10 = ["37", "rbh-reset-10"]
|
|
|
|
RESET_REBOOT_COUNTER_11 = ["38", "rbh-reset-11"]
|
|
|
|
SET_MAX_REBOOT_CNT = ["39", "rbh-max-cnt"]
|
|
|
|
|
|
|
|
|
|
|
|
class Info:
|
|
|
|
REBOOT_XSC = "XSC reboot with prompt"
|
|
|
|
REBOOT_FULL = "Full regular reboot"
|
2021-08-03 15:28:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Chip(enum.IntEnum):
|
|
|
|
CHIP_0 = 0
|
|
|
|
CHIP_1 = 1
|
|
|
|
NONE = 2
|
|
|
|
|
|
|
|
|
|
|
|
class Copy(enum.IntEnum):
|
|
|
|
COPY_0_NOM = 0
|
|
|
|
COPY_1_GOLD = 1
|
|
|
|
NONE = 2
|
|
|
|
|
|
|
|
|
2022-08-12 10:18:21 +02:00
|
|
|
@tmtc_definitions_provider
|
|
|
|
def add_core_controller_definitions(defs: TmtcDefinitionWrapper):
|
2022-07-05 02:12:54 +02:00
|
|
|
oce = OpCodeEntry()
|
|
|
|
oce.add(keys=OpCodes.REBOOT_XSC, info=Info.REBOOT_XSC)
|
|
|
|
oce.add(keys=OpCodes.REBOOT_XSC, info=Info.REBOOT_XSC)
|
|
|
|
oce.add(keys=OpCodes.REBOOT_FULL, info=Info.REBOOT_FULL)
|
|
|
|
oce.add(keys=OpCodes.XSC_REBOOT_SELF, info="Reboot Self")
|
|
|
|
oce.add(keys=OpCodes.XSC_REBOOT_0_0, info="Reboot 0 0")
|
|
|
|
oce.add(keys=OpCodes.XSC_REBOOT_0_1, info="Reboot 0 1")
|
|
|
|
oce.add(keys=OpCodes.XSC_REBOOT_1_0, info="Reboot 1 0")
|
|
|
|
oce.add(keys=OpCodes.XSC_REBOOT_1_1, info="Reboot 1 1")
|
|
|
|
oce.add(
|
2022-05-24 01:13:21 +02:00
|
|
|
keys=OpCodes.GET_HK,
|
|
|
|
info="Request housekeeping set",
|
|
|
|
)
|
2022-07-05 02:12:54 +02:00
|
|
|
oce.add(
|
2022-05-24 01:13:21 +02:00
|
|
|
keys=OpCodes.ENABLE_REBOOT_FILE_HANDLING,
|
|
|
|
info="Enable reboot file handling",
|
|
|
|
)
|
2022-07-05 02:12:54 +02:00
|
|
|
oce.add(
|
2022-05-24 01:13:21 +02:00
|
|
|
keys=OpCodes.DISABLE_REBOOT_FILE_HANDLING,
|
|
|
|
info="Disable reboot file handling",
|
|
|
|
)
|
2022-07-05 02:12:54 +02:00
|
|
|
oce.add(
|
2022-05-24 01:13:21 +02:00
|
|
|
keys=OpCodes.RESET_ALL_REBOOT_COUNTERS,
|
|
|
|
info="Reset all reboot counters",
|
|
|
|
)
|
2022-07-05 02:12:54 +02:00
|
|
|
oce.add(
|
2022-05-24 01:13:21 +02:00
|
|
|
keys=OpCodes.RESET_REBOOT_COUNTER_00,
|
|
|
|
info="Reset reboot counter 0 0",
|
|
|
|
)
|
2022-07-05 02:12:54 +02:00
|
|
|
oce.add(
|
2022-05-24 01:13:21 +02:00
|
|
|
keys=OpCodes.RESET_REBOOT_COUNTER_01,
|
|
|
|
info="Reset reboot counter 0 1",
|
|
|
|
)
|
2022-07-05 02:12:54 +02:00
|
|
|
oce.add(
|
2022-05-24 01:13:21 +02:00
|
|
|
keys=OpCodes.RESET_REBOOT_COUNTER_10,
|
|
|
|
info="Reset reboot counter 1 0",
|
|
|
|
)
|
2022-07-05 02:12:54 +02:00
|
|
|
oce.add(
|
2022-05-24 01:13:21 +02:00
|
|
|
keys=OpCodes.RESET_REBOOT_COUNTER_11,
|
|
|
|
info="Reset reboot counter 1 1",
|
|
|
|
)
|
2022-08-08 16:47:41 +02:00
|
|
|
defs.add_service(CustomServiceList.CORE.value, "Core Controller", oce)
|
2022-05-24 01:13:21 +02:00
|
|
|
|
|
|
|
|
2022-08-08 16:32:18 +02:00
|
|
|
def pack_core_commands(q: DefaultPusQueueHelper, op_code: str):
|
2022-05-24 01:13:21 +02:00
|
|
|
if op_code in OpCodes.REBOOT_XSC:
|
2021-08-03 15:28:28 +02:00
|
|
|
reboot_self, chip_select, copy_select = determine_reboot_params()
|
|
|
|
perform_reboot_cmd(
|
2022-07-04 17:59:09 +02:00
|
|
|
q=q,
|
2022-01-18 14:03:56 +01:00
|
|
|
reboot_self=reboot_self,
|
|
|
|
chip=chip_select,
|
|
|
|
copy=copy_select,
|
2021-08-03 15:28:28 +02:00
|
|
|
)
|
2022-05-24 01:13:21 +02:00
|
|
|
if op_code in OpCodes.REBOOT_FULL:
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_log_cmd(f"Core Command: {Info.REBOOT_FULL}")
|
|
|
|
q.add_pus_tc(
|
|
|
|
generate_action_command(
|
|
|
|
object_id=CORE_CONTROLLER_ID, action_id=ActionIds.FULL_REBOOT
|
|
|
|
)
|
2022-05-24 17:24:09 +02:00
|
|
|
)
|
2022-05-24 01:13:21 +02:00
|
|
|
if op_code in OpCodes.XSC_REBOOT_SELF:
|
2022-07-04 17:59:09 +02:00
|
|
|
perform_reboot_cmd(q=q, reboot_self=True)
|
2022-05-24 01:13:21 +02:00
|
|
|
if op_code in OpCodes.XSC_REBOOT_0_0:
|
2021-08-03 15:28:28 +02:00
|
|
|
perform_reboot_cmd(
|
2022-07-04 17:59:09 +02:00
|
|
|
q=q, reboot_self=False, chip=Chip.CHIP_0, copy=Copy.COPY_0_NOM
|
2021-08-03 15:28:28 +02:00
|
|
|
)
|
2022-05-24 01:13:21 +02:00
|
|
|
if op_code in OpCodes.XSC_REBOOT_0_1:
|
2021-08-03 15:28:28 +02:00
|
|
|
perform_reboot_cmd(
|
2022-07-04 17:59:09 +02:00
|
|
|
q=q,
|
2022-01-18 14:03:56 +01:00
|
|
|
reboot_self=False,
|
|
|
|
chip=Chip.CHIP_0,
|
|
|
|
copy=Copy.COPY_1_GOLD,
|
2021-08-03 15:28:28 +02:00
|
|
|
)
|
2022-05-24 01:13:21 +02:00
|
|
|
if op_code in OpCodes.XSC_REBOOT_1_0:
|
2021-08-03 15:28:28 +02:00
|
|
|
perform_reboot_cmd(
|
2022-07-04 17:59:09 +02:00
|
|
|
q=q, reboot_self=False, chip=Chip.CHIP_1, copy=Copy.COPY_0_NOM
|
2021-08-03 15:28:28 +02:00
|
|
|
)
|
2022-05-24 01:13:21 +02:00
|
|
|
if op_code in OpCodes.XSC_REBOOT_1_1:
|
2021-08-03 15:28:28 +02:00
|
|
|
perform_reboot_cmd(
|
2022-07-04 17:59:09 +02:00
|
|
|
q=q,
|
2022-01-18 14:03:56 +01:00
|
|
|
reboot_self=False,
|
|
|
|
chip=Chip.CHIP_1,
|
|
|
|
copy=Copy.COPY_1_GOLD,
|
2021-08-03 15:28:28 +02:00
|
|
|
)
|
2022-05-24 01:13:21 +02:00
|
|
|
if op_code in OpCodes.DISABLE_REBOOT_FILE_HANDLING:
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_log_cmd("Disabling reboot file handling")
|
2022-02-24 10:56:36 +01:00
|
|
|
app_data = bytearray([0])
|
|
|
|
generate_action_command(
|
|
|
|
object_id=CORE_CONTROLLER_ID,
|
|
|
|
action_id=ActionIds.SWITCH_REBOOT_FILE_HANDLING,
|
|
|
|
app_data=app_data,
|
|
|
|
)
|
2022-05-24 01:13:21 +02:00
|
|
|
if op_code in OpCodes.ENABLE_REBOOT_FILE_HANDLING:
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_log_cmd("Enabling reboot file handling")
|
2022-02-24 10:56:36 +01:00
|
|
|
app_data = bytearray([1])
|
|
|
|
generate_action_command(
|
|
|
|
object_id=CORE_CONTROLLER_ID,
|
|
|
|
action_id=ActionIds.SWITCH_REBOOT_FILE_HANDLING,
|
|
|
|
app_data=app_data,
|
|
|
|
)
|
2022-05-24 01:13:21 +02:00
|
|
|
if op_code in OpCodes.RESET_ALL_REBOOT_COUNTERS:
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_log_cmd("Resetting all reboot counters")
|
2022-02-24 10:56:36 +01:00
|
|
|
generate_action_command(
|
|
|
|
object_id=CORE_CONTROLLER_ID, action_id=ActionIds.RESET_ALL_REBOOT_COUNTERS
|
|
|
|
)
|
2022-05-24 01:13:21 +02:00
|
|
|
if op_code in OpCodes.RESET_REBOOT_COUNTER_00:
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_log_cmd("Resetting reboot counter 0 0")
|
2022-02-24 10:56:36 +01:00
|
|
|
generate_action_command(
|
|
|
|
object_id=CORE_CONTROLLER_ID, action_id=ActionIds.RESET_REBOOT_COUNTER_00
|
|
|
|
)
|
2022-05-24 01:13:21 +02:00
|
|
|
if op_code in OpCodes.RESET_REBOOT_COUNTER_01:
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_log_cmd("Resetting reboot counter 0 1")
|
2022-02-24 10:56:36 +01:00
|
|
|
generate_action_command(
|
|
|
|
object_id=CORE_CONTROLLER_ID, action_id=ActionIds.RESET_REBOOT_COUNTER_01
|
|
|
|
)
|
2022-05-24 01:13:21 +02:00
|
|
|
if op_code in OpCodes.RESET_REBOOT_COUNTER_10:
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_log_cmd("Resetting reboot counter 1 0")
|
2022-02-24 10:56:36 +01:00
|
|
|
generate_action_command(
|
|
|
|
object_id=CORE_CONTROLLER_ID, action_id=ActionIds.RESET_REBOOT_COUNTER_10
|
|
|
|
)
|
2022-05-24 01:13:21 +02:00
|
|
|
if op_code in OpCodes.RESET_REBOOT_COUNTER_11:
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_log_cmd("Resetting reboot counter 1 1")
|
2022-02-24 10:56:36 +01:00
|
|
|
generate_action_command(
|
|
|
|
object_id=CORE_CONTROLLER_ID, action_id=ActionIds.RESET_REBOOT_COUNTER_11
|
|
|
|
)
|
2022-05-24 01:13:21 +02:00
|
|
|
if op_code in OpCodes.GET_HK:
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_log_cmd("Requesting housekeeping set")
|
2022-03-13 21:35:12 +01:00
|
|
|
sid = make_sid(object_id=CORE_CONTROLLER_ID, set_id=SetIds.HK)
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_pus_tc(generate_one_hk_command(sid))
|
2021-08-03 15:28:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
def determine_reboot_params() -> (bool, Chip, Copy):
|
|
|
|
chip_select = -1
|
|
|
|
copy_select = -1
|
2022-01-18 14:03:56 +01:00
|
|
|
reboot_self = input("Reboot self? [y/n]: ")
|
|
|
|
if reboot_self in ["y", "yes", "1"]:
|
|
|
|
LOGGER.info("Rebooting currently running image")
|
2021-08-03 15:28:28 +02:00
|
|
|
return True, chip_select, copy_select
|
2022-01-18 14:03:56 +01:00
|
|
|
LOGGER.info("Rebooting image specified by chip and copy")
|
2021-08-03 15:28:28 +02:00
|
|
|
while True:
|
2022-01-18 14:03:56 +01:00
|
|
|
chip_select = input("Chip select [0/1]: ")
|
|
|
|
if chip_select in ["0", "1"]:
|
|
|
|
if chip_select == "0":
|
2021-08-03 15:28:28 +02:00
|
|
|
chip_select = Chip.CHIP_0
|
|
|
|
else:
|
|
|
|
chip_select = Chip.CHIP_1
|
|
|
|
break
|
|
|
|
else:
|
2022-01-18 14:03:56 +01:00
|
|
|
LOGGER.warning("Invalid chip select value. Try again")
|
2021-08-03 15:28:28 +02:00
|
|
|
while True:
|
2022-01-18 14:03:56 +01:00
|
|
|
copy_select = input("Copy select [0/1]: ")
|
|
|
|
if copy_select in ["0", "1"]:
|
|
|
|
if copy_select == "0":
|
2021-08-03 15:28:28 +02:00
|
|
|
copy_select = Copy.COPY_0_NOM
|
|
|
|
else:
|
|
|
|
copy_select = Copy.COPY_1_GOLD
|
|
|
|
break
|
|
|
|
else:
|
2022-01-18 14:03:56 +01:00
|
|
|
LOGGER.warning("Invalid copy select value. Try again")
|
2021-08-03 15:28:28 +02:00
|
|
|
return False, chip_select, copy_select
|
|
|
|
|
|
|
|
|
|
|
|
def perform_reboot_cmd(
|
2022-08-08 16:32:18 +02:00
|
|
|
q: DefaultPusQueueHelper,
|
2022-01-18 14:03:56 +01:00
|
|
|
reboot_self: bool,
|
|
|
|
chip: Chip = Chip.NONE,
|
|
|
|
copy: Copy = Copy.NONE,
|
2021-08-03 15:28:28 +02:00
|
|
|
):
|
|
|
|
tc_data = bytearray()
|
|
|
|
if reboot_self:
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_log_cmd("Packing reboot command for current image")
|
2021-08-03 15:28:28 +02:00
|
|
|
tc_data.append(True)
|
|
|
|
else:
|
|
|
|
tc_data.append(False)
|
|
|
|
tc_data.append(chip)
|
|
|
|
tc_data.append(copy)
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_log_cmd(f"Packing reboot command for chip {chip} and copy {copy}")
|
|
|
|
q.add_pus_tc(
|
|
|
|
generate_action_command(
|
|
|
|
object_id=CORE_CONTROLLER_ID,
|
|
|
|
action_id=ActionIds.XSC_REBOOT,
|
|
|
|
app_data=tc_data,
|
|
|
|
ssc=0,
|
2021-08-03 15:28:28 +02:00
|
|
|
)
|
|
|
|
)
|