eive-tmtc/pus_tc/ploc_supervisor.py

115 lines
5.3 KiB
Python
Raw Normal View History

2021-07-11 14:29:11 +02:00
# -*- coding: utf-8 -*-
"""
@file ploc_supervisor.py
@brief Tests for commanding the supervisor of the PLOC.
The supervisor is programmed by Thales.
@author J. Meier
@date 10.07.2021
"""
import struct
from tmtccmd.config.definitions import QueueCommands
from tmtccmd.tc.packer import TcQueueT
2021-07-11 14:29:11 +02:00
from tmtccmd.ecss.tc import PusTelecommand
class SupvActionIds:
HK_REPORT = 1
2021-07-23 13:40:27 +02:00
RESTART_MPSOC = 2
START_MPSOC = 3
SHUTWOWN_MPSOC = 4
SEL_MPSOC_BOOT_IMAGE = 5
SET_BOOT_TIMEOUT = 6
SET_MAX_RESTART_TRIES = 7
RESET_MPSOC = 8
SET_TIME_REF = 9
DISABLE_HK = 10
2021-07-11 14:29:11 +02:00
class SupvHkIds:
HK_REPORT = 52
def pack_ploc_supv_test_into(object_id: bytearray, tc_queue: TcQueueT, op_code: str) -> TcQueueT:
tc_queue.appendleft(
(QueueCommands.PRINT,
"Testing PLOC Supervisor with object id: 0x" + object_id.hex())
)
if op_code == "3":
tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: TC Get Hk Report"))
command = object_id + struct.pack('!I', SupvActionIds.HK_REPORT)
command = PusTelecommand(service=8, subservice=128, ssc=20, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-07-23 13:40:27 +02:00
elif op_code == "4":
tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Restart MPSoC"))
command = object_id + struct.pack('!I', SupvActionIds.RESTART_MPSOC)
command = PusTelecommand(service=8, subservice=128, ssc=21, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
elif op_code == "5":
tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Start MPSoC"))
command = object_id + struct.pack('!I', SupvActionIds.START_MPSOC)
command = PusTelecommand(service=8, subservice=128, ssc=22, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
elif op_code == "6":
tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Shutdown MPSoC"))
command = object_id + struct.pack('!I', SupvActionIds.SHUTWOWN_MPSOC)
command = PusTelecommand(service=8, subservice=128, ssc=23, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
elif op_code == "7":
tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Select MPSoC boot image"))
mem = int(input("MEM (NVM0 - 0 or NVM1 - 1):"))
bp0 = int(input("BP0 (0 or 1):"))
bp1 = int(input("BP1 (0 or 1):"))
bp2 = int(input("BP2 (0 or 1):"))
command = pack_sel_boot_image_cmd(object_id, mem, bp0, bp1, bp2)
command = PusTelecommand(service=8, subservice=128, ssc=24, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
elif op_code == "8":
tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Set max restart tries"))
restart_tries = int(input("Set maximum restart tries:"))
command = object_id + struct.pack('!I', SupvActionIds.SET_MAX_RESTART_TRIES) + struct.pack('!B', restart_tries)
command = PusTelecommand(service=8, subservice=128, ssc=25, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
elif op_code == "9":
tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Reset MPSoC"))
command = object_id + struct.pack('!I', SupvActionIds.RESET_MPSOC)
command = PusTelecommand(service=8, subservice=128, ssc=26, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
elif op_code == "10":
tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Set time reference"))
command = object_id + struct.pack('!I', SupvActionIds.SET_TIME_REF)
command = PusTelecommand(service=8, subservice=128, ssc=27, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
elif op_code == "11":
tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Set boot timeout"))
boot_timeout = int(input("Specify boot timeout [ms]:"))
command = object_id + struct.pack('!I', SupvActionIds.SET_BOOT_TIMEOUT) + struct.pack('!I', boot_timeout)
command = PusTelecommand(service=8, subservice=128, ssc=28, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
elif op_code == "12":
tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Disable HK"))
command = object_id + struct.pack('!I', SupvActionIds.DISABLE_HK)
command = PusTelecommand(service=8, subservice=128, ssc=28, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-07-11 14:29:11 +02:00
return tc_queue
2021-07-23 13:40:27 +02:00
def pack_sel_boot_image_cmd(object_id: bytearray, mem: int, bp0: int, bp1: int, bp2: int) -> bytearray:
""" This function can be used to generate the command to select the image from which the MPSoC will boot
@param object_id The object id of the PLOC supervisor handler.
@param mem The memory from which the MPSoC shall boot (NVM0 - 0, NVM1 - 1)
@param bp0 Partition pin 0
@param bp1 Partition pin 1
@param bp2 Partition pin 2
"""
command = bytearray()
command = object_id + struct.pack('!I', SupvActionIds.SEL_MPSOC_BOOT_IMAGE)
command = command + struct.pack('!B', mem)
command = command + struct.pack('!B', bp0)
command = command + struct.pack('!B', bp1)
command = command + struct.pack('!B', bp2)
return command