From 265077a758afdb5eac49e4f00f705a11e2610000 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 19 Feb 2024 12:17:34 +0100 Subject: [PATCH 1/5] add command for second slot update --- eive_tmtc/tmtc/acs/star_tracker.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/eive_tmtc/tmtc/acs/star_tracker.py b/eive_tmtc/tmtc/acs/star_tracker.py index 28e9936..1923613 100644 --- a/eive_tmtc/tmtc/acs/star_tracker.py +++ b/eive_tmtc/tmtc/acs/star_tracker.py @@ -95,7 +95,10 @@ class StarTrackerActionId(enum.IntEnum): LOGLEVEL = 81 LOG_SUBSCRIPTION = 82 DEBUG_CAMERA = 83 + # Legacy variable. FIRMWARE_UPDATE = 84 + FIRMWARE_UPDATE_MAIN = 84 + FIRMWARE_UPDATE_BACKUP = 101 SET_TIME_FROM_SYS_TIME = 87 ADD_SECONDARY_TM_TO_NORMAL_MODE = 95 RESET_SECONDARY_TM_SET = 96 @@ -119,9 +122,10 @@ class OpCode: UPLOAD_IMAGE = "upload_image" DOWNLOAD_IMAGE = "download_image" SET_IMG_PROCESSOR_MODE = "set_img_proc_mode" - FW_UPDATE = "fw_update" + FW_UPDATE_MAIN = "fw_update_main" SET_TIME_FROM_SYS_TIME = "set_time" RELOAD_JSON_CFG_FILE = "reload_json_cfg" + FW_UPDATE_BACKUP = "fw_update_backup" class Info: @@ -135,7 +139,8 @@ class Info: DOWNLOAD_IMAGE = "Download Optical Image" TAKE_IMAGE = "Take Image" SET_IMG_PROCESSOR_MODE = "Set Image Processor Mode" - FW_UPDATE = "Firmware Update" + FW_UPDATE_MAIN = "Update Main Firmware Slot" + FW_UPDATE_BACKUP = "Update Backup Firmware Slot" SET_TIME_FROM_SYS_TIME = "Set time from system time" RELOAD_JSON_CFG_FILE = "Reload JSON configuration file. Reboot still required." @@ -642,12 +647,21 @@ def pack_star_tracker_commands( # noqa C901 + bytearray(json_file, "utf-8") ) q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) - if cmd_str == OpCode.FW_UPDATE: - q.add_log_cmd(Info.FW_UPDATE) + if cmd_str == OpCode.FW_UPDATE_MAIN: + q.add_log_cmd(Info.FW_UPDATE_MAIN) firmware = get_firmware() data = ( obyt - + struct.pack("!I", StarTrackerActionId.FIRMWARE_UPDATE) + + struct.pack("!I", StarTrackerActionId.FIRMWARE_UPDATE_MAIN) + + firmware.encode() + ) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) + if cmd_str == OpCode.FW_UPDATE_BACKUP: + q.add_log_cmd(Info.FW_UPDATE_BACKUP) + firmware = get_firmware() + data = ( + obyt + + struct.pack("!I", StarTrackerActionId.FIRMWARE_UPDATE_BACKUP) + firmware.encode() ) q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) @@ -1185,7 +1199,7 @@ def create_str_node() -> CmdTreeNode: node.add_child( CmdTreeNode(OpCode.RESET_SECONDARY_TM_SET, Info.RESET_SECONDARY_TM_SET) ) - node.add_child(CmdTreeNode(OpCode.FW_UPDATE, Info.FW_UPDATE)) + node.add_child(CmdTreeNode(OpCode.FW_UPDATE_MAIN, Info.FW_UPDATE_MAIN)) node.add_child( CmdTreeNode(OpCode.SET_TIME_FROM_SYS_TIME, Info.SET_TIME_FROM_SYS_TIME) ) @@ -1212,7 +1226,7 @@ def add_str_cmds(defs: TmtcDefinitionWrapper): ) oce.add(OpCode.READ_SECONDARY_TM_SET, Info.READ_SECONDARY_TM_SET) oce.add(OpCode.RESET_SECONDARY_TM_SET, Info.RESET_SECONDARY_TM_SET) - oce.add(OpCode.FW_UPDATE, Info.FW_UPDATE) + oce.add(OpCode.FW_UPDATE_MAIN, Info.FW_UPDATE_MAIN) oce.add(OpCode.SET_TIME_FROM_SYS_TIME, Info.SET_TIME_FROM_SYS_TIME) oce.add(OpCode.RELOAD_JSON_CFG_FILE, Info.RELOAD_JSON_CFG_FILE) defs.add_service(CustomServiceList.STAR_TRACKER.value, "Star Tracker", oce) From d811735b8d8bbb599b15c6c2bb4ee2796fa3261c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 19 Feb 2024 12:20:32 +0100 Subject: [PATCH 2/5] add som enums --- eive_tmtc/tmtc/acs/star_tracker.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/eive_tmtc/tmtc/acs/star_tracker.py b/eive_tmtc/tmtc/acs/star_tracker.py index 1923613..4c0b02a 100644 --- a/eive_tmtc/tmtc/acs/star_tracker.py +++ b/eive_tmtc/tmtc/acs/star_tracker.py @@ -33,6 +33,15 @@ from eive_tmtc.config.object_ids import STR_ASSEMBLY, STAR_TRACKER_ID _LOGGER = logging.getLogger(__name__) +class FirmwareTarget(enum.IntEnum): + MAIN = 1 + BACKUP = 10 + + +class ParamId(enum.IntEnum): + FIRMWARE_TARGET = 1 + + class StarTrackerActionId(enum.IntEnum): PING = 0 BOOT = 1 @@ -126,6 +135,8 @@ class OpCode: SET_TIME_FROM_SYS_TIME = "set_time" RELOAD_JSON_CFG_FILE = "reload_json_cfg" FW_UPDATE_BACKUP = "fw_update_backup" + SELECT_TARGET_FIRMWARE_MAIN = "select_fw_target_main" + SELECT_TARGET_FIRMWARE_BACKUP = "select_fw_target_backup" class Info: @@ -143,6 +154,8 @@ class Info: FW_UPDATE_BACKUP = "Update Backup Firmware Slot" SET_TIME_FROM_SYS_TIME = "Set time from system time" RELOAD_JSON_CFG_FILE = "Reload JSON configuration file. Reboot still required." + SELECT_TARGET_FIRMWARE_MAIN = "Select main slot firmware" + SELECT_TARGET_FIRMWARE_BACKUP = "Select backup slot firmware" class SetId(enum.IntEnum): From d35bc013979c5bfc62e3eb733eb4578910401d3e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 19 Feb 2024 15:27:27 +0100 Subject: [PATCH 3/5] added command to select STR slot --- eive_tmtc/tmtc/acs/star_tracker.py | 76 +++++++++++++++++------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/eive_tmtc/tmtc/acs/star_tracker.py b/eive_tmtc/tmtc/acs/star_tracker.py index 4c0b02a..429f275 100644 --- a/eive_tmtc/tmtc/acs/star_tracker.py +++ b/eive_tmtc/tmtc/acs/star_tracker.py @@ -10,12 +10,10 @@ import enum import logging import struct -from eive_tmtc.config.definitions import CustomServiceList from eive_tmtc.pus_tm.defs import PrintWrapper from eive_tmtc.utility.input_helper import InputHelper from spacepackets.ecss.tc import PusTelecommand -from tmtccmd.config import CmdTreeNode, TmtcDefinitionWrapper, OpCodeEntry -from tmtccmd.config.tmtc import tmtc_definitions_provider +from tmtccmd.config import CmdTreeNode from tmtccmd.pus.tc.s3_fsfw_hk import ( create_request_one_diag_command, create_request_one_hk_command, @@ -23,6 +21,7 @@ from tmtccmd.pus.tc.s3_fsfw_hk import ( disable_periodic_hk_command, make_sid, ) +from tmtccmd.pus.s20_fsfw_param import create_load_param_cmd, create_scalar_u8_parameter from tmtccmd.pus.s8_fsfw_action import create_action_cmd from tmtccmd.tmtc import DefaultPusQueueHelper from tmtccmd.pus.s200_fsfw_mode import pack_mode_data, Mode @@ -40,6 +39,7 @@ class FirmwareTarget(enum.IntEnum): class ParamId(enum.IntEnum): FIRMWARE_TARGET = 1 + FIRMWARE_TARGET_PERSISTENT = 2 class StarTrackerActionId(enum.IntEnum): @@ -135,8 +135,10 @@ class OpCode: SET_TIME_FROM_SYS_TIME = "set_time" RELOAD_JSON_CFG_FILE = "reload_json_cfg" FW_UPDATE_BACKUP = "fw_update_backup" - SELECT_TARGET_FIRMWARE_MAIN = "select_fw_target_main" - SELECT_TARGET_FIRMWARE_BACKUP = "select_fw_target_backup" + SELECT_TARGET_FIRMWARE_MAIN = "fw_main" + SELECT_TARGET_FIRMWARE_BACKUP = "fw_backup" + SELECT_TARGET_FIRMWARE_MAIN_PERSISTENT = "fw_main_persistent" + SELECT_TARGET_FIRMWARE_BACKUP_PERSISTENT = "fw_backup_persistent" class Info: @@ -154,8 +156,12 @@ class Info: FW_UPDATE_BACKUP = "Update Backup Firmware Slot" SET_TIME_FROM_SYS_TIME = "Set time from system time" RELOAD_JSON_CFG_FILE = "Reload JSON configuration file. Reboot still required." - SELECT_TARGET_FIRMWARE_MAIN = "Select main slot firmware" - SELECT_TARGET_FIRMWARE_BACKUP = "Select backup slot firmware" + SELECT_TARGET_FIRMWARE_MAIN = "Select main firmware slot" + SELECT_TARGET_FIRMWARE_BACKUP = "Select backup firmware slot" + SELECT_TARGET_FIRMWARE_MAIN_PERSISTENT = "Select main firmware slot persistently" + SELECT_TARGET_FIRMWARE_BACKUP_PERSISTENT = ( + "Select backup firmware slot persistently" + ) class SetId(enum.IntEnum): @@ -710,6 +716,35 @@ def pack_star_tracker_commands( # noqa C901 q.add_pus_tc( create_action_cmd(STAR_TRACKER_ID, StarTrackerActionId.RELOAD_JSON_CFG_FILE) ) + if cmd_str == OpCode.SELECT_TARGET_FIRMWARE_MAIN: + q.add_log_cmd(Info.SELECT_TARGET_FIRMWARE_MAIN) + q.add_pus_tc(create_update_firmware_target_cmd(False, FirmwareTarget.MAIN)) + if cmd_str == OpCode.SELECT_TARGET_FIRMWARE_BACKUP: + q.add_log_cmd(Info.SELECT_TARGET_FIRMWARE_BACKUP) + q.add_pus_tc(create_update_firmware_target_cmd(False, FirmwareTarget.BACKUP)) + if cmd_str == OpCode.SELECT_TARGET_FIRMWARE_MAIN_PERSISTENT: + q.add_log_cmd(Info.SELECT_TARGET_FIRMWARE_BACKUP) + q.add_pus_tc(create_update_firmware_target_cmd(True, FirmwareTarget.MAIN)) + if cmd_str == OpCode.SELECT_TARGET_FIRMWARE_BACKUP_PERSISTENT: + q.add_log_cmd(Info.SELECT_TARGET_FIRMWARE_BACKUP) + q.add_pus_tc(create_update_firmware_target_cmd(True, FirmwareTarget.BACKUP)) + + +def create_update_firmware_target_cmd( + persistent: bool, fw_target: FirmwareTarget +) -> PusTelecommand: + if persistent: + param_id = ParamId.FIRMWARE_TARGET_PERSISTENT + else: + param_id = ParamId.FIRMWARE_TARGET + return create_load_param_cmd( + create_scalar_u8_parameter( + STAR_TRACKER_ID, + 0, + param_id, + fw_target, + ) + ) def request_dataset(q: DefaultPusQueueHelper, req_type: DataSetRequest): @@ -1213,33 +1248,8 @@ def create_str_node() -> CmdTreeNode: CmdTreeNode(OpCode.RESET_SECONDARY_TM_SET, Info.RESET_SECONDARY_TM_SET) ) node.add_child(CmdTreeNode(OpCode.FW_UPDATE_MAIN, Info.FW_UPDATE_MAIN)) + node.add_child(CmdTreeNode(OpCode.FW_UPDATE_BACKUP, Info.FW_UPDATE_BACKUP)) node.add_child( CmdTreeNode(OpCode.SET_TIME_FROM_SYS_TIME, Info.SET_TIME_FROM_SYS_TIME) ) return node - - -@tmtc_definitions_provider -def add_str_cmds(defs: TmtcDefinitionWrapper): - oce = OpCodeEntry() - oce.add(OpCode.ON_BOOTLOADER, "Mode On, Submode Bootloader") - oce.add(OpCode.ON_FIRMWARE, "Mode On, Submode Firmware") - oce.add(OpCode.NORMAL, "Mode Normal") - oce.add(OpCode.OFF, "Mode Off") - oce.add(OpCode.PING, "Star Tracker: Ping") - oce.add(OpCode.TAKE_IMAGE, "Take Image") - oce.add(OpCode.UPLOAD_IMAGE, Info.UPLOAD_IMAGE) - oce.add(OpCode.DOWNLOAD_IMAGE, Info.DOWNLOAD_IMAGE) - oce.add(OpCode.ONE_SHOOT_HK, Info.ONE_SHOOT_HK) - oce.add(OpCode.ENABLE_HK, Info.ENABLE_HK) - oce.add(OpCode.DISABLE_HK, Info.DISABLE_HK) - oce.add(OpCode.SET_IMG_PROCESSOR_MODE, Info.SET_IMG_PROCESSOR_MODE) - oce.add( - OpCode.ADD_SECONDARY_TM_TO_NORMAL_MODE, Info.ADD_SECONDARY_TM_TO_NORMAL_MODE - ) - oce.add(OpCode.READ_SECONDARY_TM_SET, Info.READ_SECONDARY_TM_SET) - oce.add(OpCode.RESET_SECONDARY_TM_SET, Info.RESET_SECONDARY_TM_SET) - oce.add(OpCode.FW_UPDATE_MAIN, Info.FW_UPDATE_MAIN) - oce.add(OpCode.SET_TIME_FROM_SYS_TIME, Info.SET_TIME_FROM_SYS_TIME) - oce.add(OpCode.RELOAD_JSON_CFG_FILE, Info.RELOAD_JSON_CFG_FILE) - defs.add_service(CustomServiceList.STAR_TRACKER.value, "Star Tracker", oce) From 85fc106a9b0e6d4256e6243200b9c0a3b910f67c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 19 Feb 2024 15:58:34 +0100 Subject: [PATCH 4/5] add commanding nodes --- eive_tmtc/tmtc/acs/star_tracker.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/eive_tmtc/tmtc/acs/star_tracker.py b/eive_tmtc/tmtc/acs/star_tracker.py index 429f275..85fd63f 100644 --- a/eive_tmtc/tmtc/acs/star_tracker.py +++ b/eive_tmtc/tmtc/acs/star_tracker.py @@ -1249,6 +1249,28 @@ def create_str_node() -> CmdTreeNode: ) node.add_child(CmdTreeNode(OpCode.FW_UPDATE_MAIN, Info.FW_UPDATE_MAIN)) node.add_child(CmdTreeNode(OpCode.FW_UPDATE_BACKUP, Info.FW_UPDATE_BACKUP)) + node.add_child( + CmdTreeNode( + OpCode.SELECT_TARGET_FIRMWARE_MAIN, Info.SELECT_TARGET_FIRMWARE_MAIN + ) + ) + node.add_child( + CmdTreeNode( + OpCode.SELECT_TARGET_FIRMWARE_BACKUP, Info.SELECT_TARGET_FIRMWARE_BACKUP + ) + ) + node.add_child( + CmdTreeNode( + OpCode.SELECT_TARGET_FIRMWARE_MAIN_PERSISTENT, + Info.SELECT_TARGET_FIRMWARE_MAIN_PERSISTENT, + ) + ) + node.add_child( + CmdTreeNode( + OpCode.SELECT_TARGET_FIRMWARE_BACKUP_PERSISTENT, + Info.SELECT_TARGET_FIRMWARE_BACKUP_PERSISTENT, + ) + ) node.add_child( CmdTreeNode(OpCode.SET_TIME_FROM_SYS_TIME, Info.SET_TIME_FROM_SYS_TIME) ) From bbde4b5b2045056ad7fc64664dbf9147c1763f45 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 19 Feb 2024 17:25:06 +0100 Subject: [PATCH 5/5] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fafd6ae..fdc4667 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ list yields a list of all related PRs for each release. # [unreleased] +## Added + +- Added commands to unlock and use STR secondary firmware slot. + # [v6.0.0] 2024-02-08 ## Changed