Skip to content
Snippets Groups Projects
Forked from an inaccessible project.
obsw_image_handler.py 1.77 KiB
from tmtc_core.tc.obsw_pus_tc_base import PusTelecommand, Deque
from  tc.obsw_tc_service8 import make_action_id
from tmtc_core.utility.obsw_logger import get_logger
from config.obsw_config import SW_IMAGE_HANDLER_ID

LOGGER = get_logger()


def generate_copy_bl_sdc_to_flash_packet(ssc: int, from_fram: bool = False,
                                         object_id: bytearray = SW_IMAGE_HANDLER_ID):
    app_data = bytearray(object_id)
    app_data += make_action_id(11)
    app_data.append(from_fram)
    return PusTelecommand(service=8, subservice=128, ssc=ssc, app_data=app_data)


# Slot values: 0 -> Slot 0, 1 -> Slot 1, 2 -> Update Slot
def generate_copy_obsw_sdc_to_flash_packet(ssc:int, slot: int,
                                           object_id: bytearray = SW_IMAGE_HANDLER_ID):
    app_data = bytearray(object_id)
    app_data += make_action_id(4)
    if slot != 0 or slot != 1 or slot != 2:
        LOGGER.error("generate_copy_obsw_sdc_to_flash_packet: Invalid slot number!")
        return None
    app_data.append(slot)
    return PusTelecommand(service=8, subservice=128, ssc=ssc, app_data=app_data)


def generate_img_handler_packet(service_queue: Deque, op_code: int):
    # Action ID 4 (Copy SDC to Flash, Software Update Image)
    if op_code == "A4U":
        service_queue.appendleft(("print", "Generating command to copy SDC OBSW to flash."))
        command = generate_copy_obsw_sdc_to_flash_packet(ssc=0, slot=2)
        service_queue.appendleft(command.pack_command_tuple())

    # Action ID 11 (Copy bootloader from SDC to flash
    elif op_code == "A11S":
        service_queue.appendleft(("print", "Generating command to copy SDC bootloader to flash."))
        command = generate_copy_bl_sdc_to_flash_packet(0)
        service_queue.appendleft(command.pack_command_tuple())