eive-tmtc/config/hook_implementations.py

227 lines
12 KiB
Python
Raw Normal View History

2021-03-19 17:39:52 +01:00
import argparse
from typing import Union, Dict, Tuple
2021-05-17 18:01:55 +02:00
from tmtccmd.config.definitions import ServiceOpCodeDictT
from tmtccmd.tm.service_3_base import Service3Base
2021-04-10 22:59:51 +02:00
from tmtccmd.ecss.tm import PusTelemetry
from tmtccmd.tc.definitions import TcQueueT
2021-03-23 13:44:33 +01:00
from tmtccmd.com_if.com_interface_base import CommunicationInterface
from tmtccmd.core.backend import TmTcHandler
2021-05-17 17:42:04 +02:00
from tmtccmd.config.hook import TmTcHookBase
2021-03-19 17:39:52 +01:00
from tmtccmd.utility.tmtc_printer import TmTcPrinter
2021-05-17 17:59:24 +02:00
from tmtccmd.config.globals import OpCodeDictKeys
2021-06-29 16:10:03 +02:00
from config.object_ids import RW1_ID
2021-05-17 17:59:24 +02:00
from config.definitions import CustomServiceList
2021-03-19 17:39:52 +01:00
2021-03-19 17:42:36 +01:00
class EiveHookObject(TmTcHookBase):
2021-03-19 17:39:52 +01:00
2021-05-17 17:42:04 +02:00
def get_service_op_code_dictionary(self) -> ServiceOpCodeDictT:
from tmtccmd.config.globals import get_default_service_op_code_dict
2021-05-17 17:59:24 +02:00
service_op_code_dict = get_default_service_op_code_dict()
2021-08-03 15:28:28 +02:00
op_code_dict = {
'reboot': ('Reboot with Prompt', {OpCodeDictKeys.TIMEOUT: 2.0}),
'reboot_self': ('Reboot Self', {OpCodeDictKeys.TIMEOUT: 4.0}),
'reboot_0_0': ('Reboot 0 0', {OpCodeDictKeys.TIMEOUT: 4.0}),
'reboot_0_1': ('Reboot 0 1', {OpCodeDictKeys.TIMEOUT: 4.0}),
'reboot_1_0': ('Reboot 1 0', {OpCodeDictKeys.TIMEOUT: 4.0}),
'reboot_1_1': ('Reboot 1 1', {OpCodeDictKeys.TIMEOUT: 4.0}),
}
service_tuple = ('Core Controller', op_code_dict)
service_op_code_dict[CustomServiceList.CORE.value] = service_tuple
op_code_dict = {
2021-05-17 17:59:24 +02:00
"0": ("ACU Tests", {OpCodeDictKeys.TIMEOUT: 2.0}),
}
2021-08-03 15:28:28 +02:00
service_tuple = ("ACU Devices", op_code_dict)
service_op_code_dict[CustomServiceList.ACU.value] = service_tuple
2021-05-17 17:59:24 +02:00
2021-08-03 15:28:28 +02:00
op_code_dict = {
2021-05-17 17:59:24 +02:00
"0": ("TMP1075 Tests", {OpCodeDictKeys.TIMEOUT: 2.2}),
}
2021-08-03 15:28:28 +02:00
service_tuple = ("TMP1075 1", op_code_dict)
service_op_code_dict[CustomServiceList.TMP1075_1.value] = service_tuple
service_tuple = ("TMP1075 2", op_code_dict)
service_op_code_dict[CustomServiceList.TMP1075_2.value] = service_tuple
2021-05-17 17:59:24 +02:00
op_code_dict_srv_p60 = {
"0": ("P60 Tests", {OpCodeDictKeys.TIMEOUT: 2.0}),
}
service_p60_tuple = ("P60 Device", op_code_dict_srv_p60)
op_code_dict_srv_pdu1 = {
"0": ("PDU1 Tests", {OpCodeDictKeys.TIMEOUT: 2.0}),
}
service_pdu1_tuple = ("PDU1 Device", op_code_dict_srv_pdu1)
op_code_dict_srv_pdu2 = {
"0": ("PDU2 Tests", {OpCodeDictKeys.TIMEOUT: 2.0}),
}
service_pdu2_tuple = ("PDU2 Device", op_code_dict_srv_pdu2)
op_code_dict_srv_heater = {
"0": ("Heater Tests", {OpCodeDictKeys.TIMEOUT: 2.0}),
}
service_heater_tuple = ("Heater Device", op_code_dict_srv_heater)
2021-06-12 13:49:25 +02:00
op_code_dict_srv_imtq = {
"0": ("IMTQ Tests All", {OpCodeDictKeys.TIMEOUT: 2.0}),
"1": ("IMTQ perform pos X self test", {OpCodeDictKeys.TIMEOUT: 2.0}),
2021-06-15 15:23:27 +02:00
"2": ("IMTQ perform neg X self test", {OpCodeDictKeys.TIMEOUT: 2.0}),
"3": ("IMTQ perform pos Y self test", {OpCodeDictKeys.TIMEOUT: 2.0}),
"4": ("IMTQ perform neg Y self test", {OpCodeDictKeys.TIMEOUT: 2.0}),
"5": ("IMTQ perform pos Z self test", {OpCodeDictKeys.TIMEOUT: 2.0}),
"6": ("IMTQ perform neg Z self test", {OpCodeDictKeys.TIMEOUT: 2.0}),
"7": ("IMTQ command dipole", {OpCodeDictKeys.TIMEOUT: 2.0}),
"8": ("IMTQ get commanded dipole", {OpCodeDictKeys.TIMEOUT: 2.0}),
2021-06-12 13:49:25 +02:00
}
service_imtq_tuple = ("IMTQ Device", op_code_dict_srv_imtq)
2021-06-25 12:07:16 +02:00
op_code_dict_srv_rw = {
"0": ("Reaction Wheel: Run all commands", {OpCodeDictKeys.TIMEOUT: 2.0}),
"1": ("Reaction Wheel: Set speed", {OpCodeDictKeys.TIMEOUT: 2.0}),
2021-06-29 16:10:03 +02:00
"2": ("Reaction Wheel: Set mode on", {OpCodeDictKeys.TIMEOUT: 2.0}),
"3": ("Reaction Wheel: Set mode normal", {OpCodeDictKeys.TIMEOUT: 2.0}),
"4": ("Reaction Wheel: Set mode off", {OpCodeDictKeys.TIMEOUT: 2.0}),
2021-06-30 15:08:43 +02:00
"5": ("Reaction Wheel: Send get-telemetry-command", {OpCodeDictKeys.TIMEOUT: 2.0}),
2021-06-25 12:07:16 +02:00
}
service_rw_tuple = ("Reaction Wheel", op_code_dict_srv_rw)
op_code_dict_srv_rad_sensor = {
"0": ("Radiation Sensor: Set mode on", {OpCodeDictKeys.TIMEOUT: 2.0}),
"1": ("Radiation Sensor: Set mode normal", {OpCodeDictKeys.TIMEOUT: 2.0}),
"2": ("Radiation Sensor: Set mode off", {OpCodeDictKeys.TIMEOUT: 2.0}),
}
service_rad_sensor_tuple = ("Radiation Sensor", op_code_dict_srv_rad_sensor)
2021-07-11 14:29:11 +02:00
op_code_dict_srv_ploc_supv = {
"0": ("PLOC Supervisor: Set mode on", {OpCodeDictKeys.TIMEOUT: 2.0}),
"1": ("PLOC Supervisor: Set mode normal", {OpCodeDictKeys.TIMEOUT: 2.0}),
"2": ("PLOC Supervisor: Set mode off", {OpCodeDictKeys.TIMEOUT: 2.0}),
"3": ("PLOC Supervisor: Get HK Report", {OpCodeDictKeys.TIMEOUT: 2.0}),
2021-07-23 13:40:27 +02:00
"4": ("PLOC Supervisor: Restart MPSoC", {OpCodeDictKeys.TIMEOUT: 2.0}),
"5": ("PLOC Supervisor: Start MPSoC", {OpCodeDictKeys.TIMEOUT: 2.0}),
"6": ("PLOC Supervisor: Shutdown MPSoC", {OpCodeDictKeys.TIMEOUT: 2.0}),
"7": ("PLOC Supervisor: Select MPSoC boot image", {OpCodeDictKeys.TIMEOUT: 2.0}),
"8": ("PLOC Supervisor: Set max restart tries", {OpCodeDictKeys.TIMEOUT: 2.0}),
"9": ("PLOC Supervisor: Reset MPSoC", {OpCodeDictKeys.TIMEOUT: 2.0}),
"10": ("PLOC Supervisor: Set time reference", {OpCodeDictKeys.TIMEOUT: 2.0}),
"11": ("PLOC Supervisor: Set boot timeout", {OpCodeDictKeys.TIMEOUT: 2.0}),
"12": ("PLOC Supervisor: Disable Hk", {OpCodeDictKeys.TIMEOUT: 2.0}),
"13": ("PLOC Supervisor: Request boot status report", {OpCodeDictKeys.TIMEOUT: 2.0}),
"14": ("PLOC Supervisor: Update available", {OpCodeDictKeys.TIMEOUT: 2.0}),
"15": ("PLOC Supervisor: Watchdogs enable", {OpCodeDictKeys.TIMEOUT: 2.0}),
2021-07-28 19:35:46 +02:00
"16": ("PLOC Supervisor: Watchdog Configure Timeout", {OpCodeDictKeys.TIMEOUT: 2.0}),
"17": ("PLOC Supervisor: Enable latchup alert", {OpCodeDictKeys.TIMEOUT: 2.0}),
"18": ("PLOC Supervisor: Disable latchup alert", {OpCodeDictKeys.TIMEOUT: 2.0}),
"19": ("PLOC Supervisor: Auto calibrate alert", {OpCodeDictKeys.TIMEOUT: 2.0}),
"20": ("PLOC Supervisor: Set alert limit", {OpCodeDictKeys.TIMEOUT: 2.0}),
"21": ("PLOC Supervisor: Set alert irq filter", {OpCodeDictKeys.TIMEOUT: 2.0}),
"22": ("PLOC Supervisor: Set ADC sweep period", {OpCodeDictKeys.TIMEOUT: 2.0}),
"23": ("PLOC Supervisor: Set ADC enabled channels", {OpCodeDictKeys.TIMEOUT: 2.0}),
"24": ("PLOC Supervisor: Set ADC window and stride", {OpCodeDictKeys.TIMEOUT: 2.0}),
"25": ("PLOC Supervisor: Set ADC threshold", {OpCodeDictKeys.TIMEOUT: 2.0}),
"26": ("PLOC Supervisor: Request latchup status report", {OpCodeDictKeys.TIMEOUT: 2.0}),
"27": ("PLOC Supervisor: Copy ADC data to MRAM", {OpCodeDictKeys.TIMEOUT: 2.0}),
"28": ("PLOC Supervisor: Enable/Disable NVM0/1/3", {OpCodeDictKeys.TIMEOUT: 2.0}),
"29": ("PLOC Supervisor: Select NVM", {OpCodeDictKeys.TIMEOUT: 2.0}),
"30": ("PLOC Supervisor: Run auto EM tests", {OpCodeDictKeys.TIMEOUT: 2.0}),
"31": ("PLOC Supervisor: MRAM Wipe", {OpCodeDictKeys.TIMEOUT: 2.0}),
"32": ("PLOC Supervisor: MRAM Dump", {OpCodeDictKeys.TIMEOUT: 2.0}),
2021-08-02 11:27:34 +02:00
"33": ("PLOC Supervisor: Print CPU stats", {OpCodeDictKeys.TIMEOUT: 2.0}),
"34": ("PLOC Supervisor: Set debug verbosity", {OpCodeDictKeys.TIMEOUT: 2.0}),
2021-08-02 15:28:34 +02:00
"35": ("PLOC Supervisor: Set GPIO", {OpCodeDictKeys.TIMEOUT: 2.0}),
"36": ("PLOC Supervisor: Read GPIO", {OpCodeDictKeys.TIMEOUT: 2.0}),
"37": ("PLOC Supervisor: Restart supervisor", {OpCodeDictKeys.TIMEOUT: 2.0}),
"38": ("PLOC Supervisor: Factory reset clear all", {OpCodeDictKeys.TIMEOUT: 2.0}),
"39": ("PLOC Supervisor: Factory reset clear mirror entries", {OpCodeDictKeys.TIMEOUT: 2.0}),
"40": ("PLOC Supervisor: Factory reset clear circular entries", {OpCodeDictKeys.TIMEOUT: 2.0}),
2021-08-08 10:58:14 +02:00
"41": ("PLOC Supervisor: CAN loopback test", {OpCodeDictKeys.TIMEOUT: 2.0}),
2021-07-11 14:29:11 +02:00
}
service_ploc_supv_tuple = ("PLOC Supervisor", op_code_dict_srv_ploc_supv)
2021-08-07 14:34:26 +02:00
op_code_dict_srv_ploc_updater = {
"0": ("Ploc Updater: Update partion A on NVM0", {OpCodeDictKeys.TIMEOUT: 2.0}),
"1": ("Ploc Updater: Update partion B on NVM0", {OpCodeDictKeys.TIMEOUT: 2.0}),
"2": ("Ploc Updater: Update partion A on NVM1", {OpCodeDictKeys.TIMEOUT: 2.0}),
"3": ("Ploc Updater: Update partion B on NVM1", {OpCodeDictKeys.TIMEOUT: 2.0}),
}
service_ploc_updater_tuple = ("Ploc Updater", op_code_dict_srv_ploc_updater)
2021-05-17 17:59:24 +02:00
service_op_code_dict[CustomServiceList.P60DOCK.value] = service_p60_tuple
service_op_code_dict[CustomServiceList.PDU1.value] = service_pdu1_tuple
service_op_code_dict[CustomServiceList.PDU1.value] = service_pdu2_tuple
service_op_code_dict[CustomServiceList.HEATER.value] = service_heater_tuple
2021-06-12 13:49:25 +02:00
service_op_code_dict[CustomServiceList.IMTQ.value] = service_imtq_tuple
2021-06-29 16:10:03 +02:00
service_op_code_dict[CustomServiceList.REACTION_WHEEL_1.value] = service_rw_tuple
service_op_code_dict[CustomServiceList.REACTION_WHEEL_2.value] = service_rw_tuple
service_op_code_dict[CustomServiceList.REACTION_WHEEL_3.value] = service_rw_tuple
service_op_code_dict[CustomServiceList.REACTION_WHEEL_4.value] = service_rw_tuple
service_op_code_dict[CustomServiceList.RAD_SENSOR.value] = service_rad_sensor_tuple
2021-07-11 14:29:11 +02:00
service_op_code_dict[CustomServiceList.PLOC_SUPV.value] = service_ploc_supv_tuple
2021-08-07 14:34:26 +02:00
service_op_code_dict[CustomServiceList.PLOC_UPDATER.value] = service_ploc_updater_tuple
2021-05-17 17:59:24 +02:00
return service_op_code_dict
2021-05-17 17:42:04 +02:00
def get_json_config_file_path(self) -> str:
2021-08-16 14:20:22 +02:00
"""The user can specify a path and filename for the JSON configuration file by overriding
this function.
2021-05-17 17:42:04 +02:00
:return:
"""
return "config/tmtc_config.json"
2021-03-19 17:39:52 +01:00
def add_globals_pre_args_parsing(self, gui: bool = False):
2021-03-19 17:50:09 +01:00
from config.globals_config import set_globals_pre_args_parsing
set_globals_pre_args_parsing(gui=gui)
2021-03-19 17:39:52 +01:00
def add_globals_post_args_parsing(self, args: argparse.Namespace):
from config.globals_config import add_globals_post_args_parsing
2021-05-17 17:42:04 +02:00
add_globals_post_args_parsing(args=args, json_cfg_path=self.get_json_config_file_path())
2021-03-19 17:39:52 +01:00
2021-05-17 17:42:04 +02:00
def assign_communication_interface(self, com_if_key: str, tmtc_printer: TmTcPrinter) -> \
2021-03-19 17:39:52 +01:00
Union[CommunicationInterface, None]:
2021-05-17 17:42:04 +02:00
from tmtccmd.config.com_if import create_communication_interface_default
return create_communication_interface_default(
2021-06-21 17:30:37 +02:00
com_if_key=com_if_key, tmtc_printer=tmtc_printer,
2021-08-02 11:30:20 +02:00
json_cfg_path=self.get_json_config_file_path(), space_packet_id=0x0865
2021-05-17 17:42:04 +02:00
)
2021-03-19 17:39:52 +01:00
def perform_mode_operation(self, tmtc_backend: TmTcHandler, mode: int):
from config.custom_mode_op import custom_mode_operation
custom_mode_operation(mode=mode, tmtc_backend=tmtc_backend)
def pack_service_queue(self, service: int, op_code: str, service_queue: TcQueueT):
from pus_tc.tc_packer_hook import pack_service_queue_user
pack_service_queue_user(service=service, op_code=op_code, service_queue=service_queue)
2021-05-17 17:42:04 +02:00
def get_object_ids(self) -> Dict[bytes, list]:
from config.object_ids import get_object_ids
return get_object_ids()
2021-03-19 17:39:52 +01:00
@staticmethod
def handle_service_8_telemetry(
2021-05-17 17:42:04 +02:00
object_id: bytes, action_id: int, custom_data: bytearray
2021-03-19 17:39:52 +01:00
) -> Tuple[list, list]:
from pus_tm.service_8_hook import user_analyze_service_8_data
return user_analyze_service_8_data(
object_id=object_id, action_id=action_id, custom_data=custom_data
)
@staticmethod
def handle_service_3_housekeeping(
2021-06-12 13:48:31 +02:00
object_id: bytes, set_id: int, hk_data: bytearray, service3_packet: Service3Base
2021-03-19 17:39:52 +01:00
) -> Tuple[list, list, bytearray, int]:
from pus_tm.hk_handling import handle_user_hk_packet
return handle_user_hk_packet(
object_id=object_id, set_id=set_id, hk_data=hk_data, service3_packet=service3_packet
2021-03-19 17:43:18 +01:00
)
2021-06-29 16:10:03 +02:00
@staticmethod
def handle_service_5_event(
object_id: bytes, event_id: int, param_1: int, param_2: int
) -> str:
if object_id == RW1_ID:
if event_id == 1:
return ""
return ""