2021-08-03 15:28:28 +02:00
|
|
|
import enum
|
|
|
|
|
|
|
|
from tmtccmd.config.definitions import QueueCommands
|
|
|
|
from tmtccmd.tc.definitions import TcQueueT
|
|
|
|
from tmtccmd.tc.service_8_functional_cmd import generate_action_command
|
|
|
|
from tmtccmd.utility.logger import get_console_logger
|
|
|
|
from config.object_ids import CORE_CONTROLLER_ID
|
|
|
|
|
|
|
|
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
|
2021-08-03 15:28:28 +02:00
|
|
|
REBOOT = 32
|
|
|
|
|
|
|
|
|
2022-02-24 10:56:36 +01:00
|
|
|
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"]
|
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
|
|
|
|
|
|
|
|
|
|
|
|
def pack_core_commands(tc_queue: TcQueueT, op_code: str):
|
2022-02-24 10:56:36 +01:00
|
|
|
if op_code in OpCodes.REBOOT:
|
2021-08-03 15:28:28 +02:00
|
|
|
reboot_self, chip_select, copy_select = determine_reboot_params()
|
|
|
|
perform_reboot_cmd(
|
2022-01-18 14:03:56 +01:00
|
|
|
tc_queue=tc_queue,
|
|
|
|
reboot_self=reboot_self,
|
|
|
|
chip=chip_select,
|
|
|
|
copy=copy_select,
|
2021-08-03 15:28:28 +02:00
|
|
|
)
|
2022-02-24 10:56:36 +01:00
|
|
|
elif op_code in OpCodes.REBOOT_SELF:
|
2021-08-03 15:28:28 +02:00
|
|
|
perform_reboot_cmd(tc_queue=tc_queue, reboot_self=True)
|
2022-02-24 10:56:36 +01:00
|
|
|
elif op_code in OpCodes.REBOOT_0_0:
|
2021-08-03 15:28:28 +02:00
|
|
|
perform_reboot_cmd(
|
|
|
|
tc_queue=tc_queue, reboot_self=False, chip=Chip.CHIP_0, copy=Copy.COPY_0_NOM
|
|
|
|
)
|
2022-02-24 10:56:36 +01:00
|
|
|
elif op_code in OpCodes.REBOOT_0_1:
|
2021-08-03 15:28:28 +02:00
|
|
|
perform_reboot_cmd(
|
2022-01-18 14:03:56 +01:00
|
|
|
tc_queue=tc_queue,
|
|
|
|
reboot_self=False,
|
|
|
|
chip=Chip.CHIP_0,
|
|
|
|
copy=Copy.COPY_1_GOLD,
|
2021-08-03 15:28:28 +02:00
|
|
|
)
|
2022-02-24 10:56:36 +01:00
|
|
|
elif op_code in OpCodes.REBOOT_1_0:
|
2021-08-03 15:28:28 +02:00
|
|
|
perform_reboot_cmd(
|
|
|
|
tc_queue=tc_queue, reboot_self=False, chip=Chip.CHIP_1, copy=Copy.COPY_0_NOM
|
|
|
|
)
|
2022-02-24 10:56:36 +01:00
|
|
|
elif op_code in OpCodes.REBOOT_1_1:
|
2021-08-03 15:28:28 +02:00
|
|
|
perform_reboot_cmd(
|
2022-01-18 14:03:56 +01:00
|
|
|
tc_queue=tc_queue,
|
|
|
|
reboot_self=False,
|
|
|
|
chip=Chip.CHIP_1,
|
|
|
|
copy=Copy.COPY_1_GOLD,
|
2021-08-03 15:28:28 +02:00
|
|
|
)
|
2022-02-24 10:56:36 +01:00
|
|
|
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
|
|
|
|
)
|
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-01-18 14:03:56 +01:00
|
|
|
tc_queue: TcQueueT,
|
|
|
|
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-01-18 14:03:56 +01:00
|
|
|
tc_queue.appendleft(
|
|
|
|
(QueueCommands.PRINT, "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)
|
|
|
|
tc_queue.append(
|
2022-01-18 14:03:56 +01:00
|
|
|
(
|
|
|
|
QueueCommands.PRINT,
|
|
|
|
f"Packing reboot command for chip {chip} and copy {copy}",
|
|
|
|
)
|
2021-08-03 15:28:28 +02:00
|
|
|
)
|
|
|
|
action_cmd = generate_action_command(
|
2022-01-18 14:03:56 +01:00
|
|
|
object_id=CORE_CONTROLLER_ID,
|
|
|
|
action_id=ActionIds.REBOOT,
|
|
|
|
app_data=tc_data,
|
|
|
|
ssc=0,
|
2021-08-03 15:28:28 +02:00
|
|
|
)
|
|
|
|
tc_queue.appendleft(action_cmd.pack_command_tuple())
|