Merge pull request 'STR secondary firmware slot commands' (#276) from str-secondary-fw-slot-update into main
All checks were successful
EIVE/-/pipeline/head This commit looks good

Reviewed-on: #276
Reviewed-by: Marius Eggert <eggertm@irs.uni-stuttgart.de>
This commit is contained in:
Marius Eggert 2024-02-26 14:01:34 +01:00
commit 1d982785e6
2 changed files with 98 additions and 35 deletions

View File

@ -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

View File

@ -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
@ -33,6 +32,16 @@ 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
FIRMWARE_TARGET_PERSISTENT = 2
class StarTrackerActionId(enum.IntEnum):
PING = 0
BOOT = 1
@ -95,7 +104,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 +131,14 @@ 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"
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:
@ -135,9 +152,16 @@ 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."
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):
@ -642,12 +666,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))
@ -683,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):
@ -1185,34 +1247,31 @@ 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.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)
)
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, Info.FW_UPDATE)
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)