diff --git a/deps/tmtccmd b/deps/tmtccmd index f7e7e4f..022f772 160000 --- a/deps/tmtccmd +++ b/deps/tmtccmd @@ -1 +1 @@ -Subproject commit f7e7e4f49b6f92be803bf5ff30204b22a6256c34 +Subproject commit 022f7729b841006f8573e16f573051cc763786df diff --git a/pus_tc/cmd_definitions.py b/pus_tc/cmd_definitions.py index 4a56413..11f1f3e 100644 --- a/pus_tc/cmd_definitions.py +++ b/pus_tc/cmd_definitions.py @@ -230,64 +230,9 @@ def add_ploc_mpsoc_cmds(defs: TmtcDefinitionWrapper): defs.add_service(CustomServiceList.PLOC_MPSOC.value, "Ploc MPSoC", oce) -@tmtc_definitions_provider -def add_ploc_supv_cmds(defs: TmtcDefinitionWrapper): - oce = OpCodeEntry() - oce.add("0", "PLOC Memory Dumper: MRAM dump") - defs.add_service( - CustomServiceList.PLOC_MEMORY_DUMPER.value, "PLOC Memory Dumper", oce - ) - oce = OpCodeEntry() - oce.add("1", "PLOC Supervisor: Set mode off") - oce.add("2", "PLOC Supervisor: Set mode normal") - oce.add("3", "PLOC Supervisor: Get HK Report") - oce.add("5", "PLOC Supervisor: Start MPSoC") - oce.add("6", "PLOC Supervisor: Shutdown MPSoC") - oce.add("7", "PLOC Supervisor: Select MPSoC boot image") - oce.add("8", "PLOC Supervisor: Set max restart tries") - oce.add("9", "PLOC Supervisor: Reset MPSoC") - oce.add("10", "PLOC Supervisor: Set time reference") - oce.add("11", "PLOC Supervisor: Set boot timeout") - oce.add("12", "PLOC Supervisor: Disable Hk") - oce.add("13", "PLOC Supervisor: Request boot status report") - oce.add("17", "PLOC Supervisor: Enable latchup alert") - oce.add("18", "PLOC Supervisor: Disable latchup alert") - oce.add("20", "PLOC Supervisor: Set alert limit") - oce.add("23", "PLOC Supervisor: Set ADC enabled channels") - oce.add("24", "PLOC Supervisor: Set ADC window and stride") - oce.add("25", "PLOC Supervisor: Set ADC threshold") - oce.add("26", "PLOC Supervisor: Request latchup status report") - oce.add("27", "PLOC Supervisor: Copy ADC data to MRAM") - oce.add("30", "PLOC Supervisor: Run auto EM tests") - oce.add("31", "PLOC Supervisor: MRAM Wipe") - oce.add("35", "PLOC Supervisor: Set GPIO") - oce.add("36", "PLOC Supervisor: Read GPIO") - oce.add("37", "PLOC Supervisor: Restart supervisor") - oce.add("38", "PLOC Supervisor: Factory reset clear all") - oce.add("39", "PLOC Supervisor: Factory reset clear mirror entries") - oce.add("40", "PLOC Supervisor: Factory reset clear circular entries") - oce.add("42", "PLOC Supervisor: Perform update") - oce.add("43", "PLOC Supervisor: Terminate supervisor process") - oce.add("44", "PLOC Supervisor: Start MPSoC quiet") - oce.add("45", "PLOC Supervisor: Set shutdown timeout") - oce.add("46", "PLOC Supervisor: Factory flash") - oce.add("47", "PLOC Supervisor: Enable auto TM") - oce.add("48", "PLOC Supervisor: Disable auto TM") - oce.add("51", "PLOC Supervisor: Logging request event buffers") - oce.add("52", "PLOC Supervisor: Logging clear counters") - oce.add("53", "PLOC Supervisor: Logging set topic") - oce.add("54", "PLOC Supervisor: Logging request counters") - oce.add("55", "PLOC Supervisor: Request ADC Report") - oce.add("56", "PLOC Supervisor: Reset PL") - oce.add("57", "PLOC Supervisor: Enable NVMs") - oce.add("58", "PLOC Supervisor: Continue update") - defs.add_service(CustomServiceList.PLOC_SUPV.value, "PLOC Supervisor", oce) - - @tmtc_definitions_provider def add_system_cmds(defs: TmtcDefinitionWrapper): from pus_tc.system.acs import AcsOpCodes, SusOpCodes - import pus_tc.system.tcs as tcs import pus_tc.system.controllers as controllers oce = OpCodeEntry() diff --git a/pus_tc/devs/bpx_batt.py b/pus_tc/devs/bpx_batt.py index 306bc3b..b331b7a 100644 --- a/pus_tc/devs/bpx_batt.py +++ b/pus_tc/devs/bpx_batt.py @@ -1,7 +1,8 @@ from config.definitions import CustomServiceList from config.object_ids import BPX_HANDLER_ID -from tmtccmd import DefaultProcedureInfo +from tmtccmd import DefaultProcedureInfo, TcHandlerBase from tmtccmd.tc import DefaultPusQueueHelper, service_provider +from tmtccmd.tc.decorator import ServiceProviderParams from tmtccmd.tc.pus_8_funccmd import generate_action_command from tmtccmd.tc.pus_3_fsfw_hk import generate_one_hk_command, make_sid @@ -27,9 +28,9 @@ class BpxOpCodes: @service_provider(CustomServiceList.BPX_BATTERY.value) -def pack_bpx_commands( - _info: DefaultProcedureInfo, q: DefaultPusQueueHelper, op_code: str -): +def pack_bpx_commands(p: ServiceProviderParams): + op_code = p.op_code + q = p.queue_helper if op_code in BpxOpCodes.HK: q.add_log_cmd("Requesting BPX battery HK set") sid = make_sid(object_id=BPX_HANDLER_ID, set_id=BpxSetIds.GET_HK_SET) diff --git a/pus_tc/devs/scex.py b/pus_tc/devs/scex.py index f2a9c06..f02e30c 100644 --- a/pus_tc/devs/scex.py +++ b/pus_tc/devs/scex.py @@ -2,9 +2,10 @@ import enum import json from config.definitions import CustomServiceList -from tmtccmd import DefaultProcedureInfo +from tmtccmd import DefaultProcedureInfo, TcHandlerBase from tmtccmd.config.tmtc import tmtc_definitions_provider from tmtccmd.tc import DefaultPusQueueHelper, service_provider +from tmtccmd.tc.decorator import ServiceProviderParams from tmtccmd.tc.pus_8_funccmd import generate_action_command from tmtccmd.config import OpCodeEntry, TmtcDefinitionWrapper from config.object_ids import SCEX_HANDLER_ID @@ -64,7 +65,9 @@ def add_scex_cmds(defs: TmtcDefinitionWrapper): @service_provider(CustomServiceList.SCEX.value) -def pack_scex_cmds(_info: DefaultProcedureInfo, q: DefaultPusQueueHelper, op_code: str): +def pack_scex_cmds(p: ServiceProviderParams): + op_code = p.op_code + q = p.queue_helper if op_code in OpCodes.PING: q.add_log_cmd(Info.PING) app_data = bytes([0]) @@ -75,7 +78,6 @@ def pack_scex_cmds(_info: DefaultProcedureInfo, q: DefaultPusQueueHelper, op_cod q.add_pus_tc( generate_action_command(SCEX_HANDLER_ID, ActionIds.ION_CMD, app_data) ) - if op_code in OpCodes.TEMP_CMD: q.add_log_cmd(Info.TEMP_CMD) app_data = bytes([0]) diff --git a/pus_tc/procedure_packer.py b/pus_tc/procedure_packer.py index 9924a55..1a3376a 100644 --- a/pus_tc/procedure_packer.py +++ b/pus_tc/procedure_packer.py @@ -9,11 +9,14 @@ from pus_tc.system.controllers import ( pack_cmd_ctrl_to_prompted_mode, get_object_from_op_code, ) -from tmtccmd import DefaultProcedureInfo +from tmtccmd import DefaultProcedureInfo, TcHandlerBase from tmtccmd.config import CoreServiceList from tmtccmd.logging import get_console_logger from tmtccmd.tc import DefaultPusQueueHelper -from tmtccmd.tc.decorator import route_to_registered_service_handlers +from tmtccmd.tc.decorator import ( + route_to_registered_service_handlers, + ServiceProviderParams, +) from tmtccmd.tc.pus_5_event import ( pack_generic_service_5_test_into, ) @@ -28,7 +31,6 @@ from pus_tc.devs.solar_array_deployment import pack_solar_array_deployment_test_ from pus_tc.devs.imtq import pack_imtq_test_into from pus_tc.devs.tmp1075 import pack_tmp1075_test_into from pus_tc.devs.ploc_mpsoc import pack_ploc_mpsoc_commands -from pus_tc.devs.ploc_supervisor import pack_ploc_supv_commands from pus_tc.devs.heater import pack_heater_cmds from pus_tc.devs.reaction_wheels import pack_single_rw_test_into, pack_rw_ass_cmds from pus_tc.devs.rad_sensor import pack_rad_sensor_test_into @@ -78,7 +80,9 @@ LOGGER = get_console_logger() def handle_default_procedure( - info: DefaultProcedureInfo, queue_helper: DefaultPusQueueHelper, gui: bool + tc_base: TcHandlerBase, + info: DefaultProcedureInfo, + queue_helper: DefaultPusQueueHelper, ): service = info.service op_code = info.op_code @@ -152,11 +156,6 @@ def handle_default_procedure( return pack_rad_sensor_test_into( object_id=object_id, q=queue_helper, op_code=op_code ) - if service == CustomServiceList.PLOC_SUPV.value: - object_id = cast(ObjectIdU32, obj_id_man.get(PLOC_SUPV_ID)) - return pack_ploc_supv_commands( - object_id=object_id, q=queue_helper, op_code=op_code - ) if service == CustomServiceList.STAR_TRACKER.value: object_id = cast(ObjectIdU32, obj_id_man.get(STAR_TRACKER_ID)) return pack_star_tracker_commands( @@ -214,10 +213,23 @@ def handle_default_procedure( if service == CustomServiceList.RW_ASSEMBLY.value: return pack_rw_ass_cmds(q=queue_helper, object_id=RW_ASSEMBLY, op_code=op_code) if service == CustomServiceList.CONTROLLERS.value: + from tmtcc import TcHandler + + tc_handler = cast(TcHandler, tc_base) return pack_cmd_ctrl_to_prompted_mode( - q=queue_helper, object_id=get_object_from_op_code(op_code), gui=gui + q=queue_helper, + object_id=get_object_from_op_code(op_code), + gui=tc_handler.gui, ) if service == CustomServiceList.SCEX.value: return pack_scex_cmds(q=queue_helper, op_code=op_code) - if not route_to_registered_service_handlers(info, queue_helper, op_code): + if not route_to_registered_service_handlers( + service, + ServiceProviderParams( + handler_base=tc_base, + op_code=op_code, + info=info, + queue_helper=queue_helper, + ), + ): LOGGER.warning(f"Invalid Service {service}") diff --git a/pus_tc/system/time.py b/pus_tc/system/time.py index 0c6268e..d1ba341 100644 --- a/pus_tc/system/time.py +++ b/pus_tc/system/time.py @@ -2,10 +2,11 @@ from datetime import datetime from config.definitions import CustomServiceList from spacepackets.ecss import PusTelecommand -from tmtccmd import DefaultProcedureInfo +from tmtccmd import DefaultProcedureInfo, TcHandlerBase from tmtccmd.logging import get_console_logger from tmtccmd.tc import DefaultPusQueueHelper, service_provider +from tmtccmd.tc.decorator import ServiceProviderParams LOGGER = get_console_logger() @@ -19,9 +20,8 @@ class Info: @service_provider(CustomServiceList.TIME.value) -def pack_set_current_time_ascii_command( - _info: DefaultProcedureInfo, q: DefaultPusQueueHelper, _op_code: str -): +def pack_set_current_time_ascii_command(p: ServiceProviderParams): + q = p.queue_helper time_test_current_time = datetime.utcnow().isoformat() + "Z" + "\0" current_time_ascii = time_test_current_time.encode("ascii") LOGGER.info(f"Current time in ASCII format: {current_time_ascii}") diff --git a/pus_tm/action_reply_handler.py b/pus_tm/action_reply_handler.py index 009efc2..8f1f21c 100644 --- a/pus_tm/action_reply_handler.py +++ b/pus_tm/action_reply_handler.py @@ -2,7 +2,7 @@ import struct from config.object_ids import * from pus_tc.devs.imtq import ImtqActionIds from pus_tc.devs.ploc_mpsoc import PlocReplyIds -from pus_tc.devs.ploc_supervisor import SupvActionIds +from tmtc.ploc_supervisor import SupvActionIds from pus_tc.devs.star_tracker import StarTrackerActionIds from gomspace.gomspace_common import GomspaceDeviceActionIds from tmtccmd.logging import get_console_logger diff --git a/pus_tm/verification_handler.py b/pus_tm/verification_handler.py index dcf03d2..ab81958 100644 --- a/pus_tm/verification_handler.py +++ b/pus_tm/verification_handler.py @@ -27,8 +27,10 @@ def handle_service_1_packet(wrapper: VerificationWrapper, raw_tm: bytes): if tm_packet.has_failure_notice: retval_info = retval_dict.get(tm_packet.error_code.val) if retval_info is None: + raw_err = tm_packet.error_code.val LOGGER.info( - f"No returnvalue information found for error code {tm_packet.error_code}" + f"No returnvalue information found for error code with subsystem ID" + f" {(raw_err >> 8) & 0xff} and unique ID {raw_err & 0xff}" ) else: retval_string = ( diff --git a/tmtc/acs_ctrl.py b/tmtc/acs_ctrl.py index c9c6aa2..6a7f900 100644 --- a/tmtc/acs_ctrl.py +++ b/tmtc/acs_ctrl.py @@ -7,13 +7,14 @@ from typing import Tuple, Optional from config.definitions import CustomServiceList from config.object_ids import ACS_CONTROLLER from pus_tm.defs import PrintWrapper -from tmtccmd import DefaultProcedureInfo, get_console_logger +from tmtccmd import get_console_logger from tmtccmd.config.tmtc import ( tmtc_definitions_provider, TmtcDefinitionWrapper, OpCodeEntry, ) -from tmtccmd.tc import DefaultPusQueueHelper, service_provider +from tmtccmd.tc import service_provider +from tmtccmd.tc.decorator import ServiceProviderParams from tmtccmd.tc.pus_3_fsfw_hk import ( generate_one_hk_command, make_sid, @@ -65,9 +66,9 @@ def acs_cmd_defs(defs: TmtcDefinitionWrapper): @service_provider(CustomServiceList.ACS_CTRL.value) -def pack_acs_ctrl_command( - _info: DefaultProcedureInfo, q: DefaultPusQueueHelper, op_code: str -): +def pack_acs_ctrl_command(p: ServiceProviderParams): + op_code = p.op_code + q = p.queue_helper sid = make_sid(ACS_CONTROLLER, SetIds.MGM_SET) if op_code in OpCodes.REQUEST_MGM_HK: q.add_log_cmd(Info.REQUEST_MGM_HK) diff --git a/pus_tc/devs/ploc_supervisor.py b/tmtc/ploc_supervisor.py similarity index 87% rename from pus_tc/devs/ploc_supervisor.py rename to tmtc/ploc_supervisor.py index 2f5717b..7df428a 100644 --- a/pus_tc/devs/ploc_supervisor.py +++ b/tmtc/ploc_supervisor.py @@ -8,11 +8,15 @@ """ import struct +from config.object_ids import PLOC_SUPV_ID, get_object_ids +from config.definitions import CustomServiceList from spacepackets.ecss.tc import PusTelecommand +from tmtccmd.config import TmtcDefinitionWrapper +from tmtccmd.config.tmtc import tmtc_definitions_provider, OpCodeEntry from tmtccmd.logging import get_console_logger -from tmtccmd.tc import DefaultPusQueueHelper +from tmtccmd.tc import service_provider +from tmtccmd.tc.decorator import ServiceProviderParams from tmtccmd.tc.pus_200_fsfw_modes import pack_mode_data, Modes -from tmtccmd.util import ObjectIdU32 from utility.input_helper import InputHelper LOGGER = get_console_logger() @@ -106,20 +110,83 @@ class SupvHkIds: BOOT_STATUS_REPORT = 53 -def pack_ploc_supv_commands( - object_id: ObjectIdU32, q: DefaultPusQueueHelper, op_code: str -): +class OpCodes: + OFF = ["0", "off"] + ON = ["1", "on"] + NORMAL = ["2", "nml"] + + +@tmtc_definitions_provider +def add_ploc_supv_cmds(defs: TmtcDefinitionWrapper): + oce = OpCodeEntry() + oce.add("0", "PLOC Memory Dumper: MRAM dump") + defs.add_service( + CustomServiceList.PLOC_MEMORY_DUMPER.value, "PLOC Memory Dumper", oce + ) + oce = OpCodeEntry() + oce.add(OpCodes.OFF, "Mode Off") + oce.add(OpCodes.ON, "Mode On") + oce.add(OpCodes.NORMAL, "Mode Normal") + oce.add("3", "PLOC Supervisor: Get HK Report") + oce.add("5", "PLOC Supervisor: Start MPSoC") + oce.add("6", "PLOC Supervisor: Shutdown MPSoC") + oce.add("7", "PLOC Supervisor: Select MPSoC boot image") + oce.add("8", "PLOC Supervisor: Set max restart tries") + oce.add("9", "PLOC Supervisor: Reset MPSoC") + oce.add("10", "PLOC Supervisor: Set time reference") + oce.add("11", "PLOC Supervisor: Set boot timeout") + oce.add("12", "PLOC Supervisor: Disable Hk") + oce.add("13", "PLOC Supervisor: Request boot status report") + oce.add("17", "PLOC Supervisor: Enable latchup alert") + oce.add("18", "PLOC Supervisor: Disable latchup alert") + oce.add("20", "PLOC Supervisor: Set alert limit") + oce.add("23", "PLOC Supervisor: Set ADC enabled channels") + oce.add("24", "PLOC Supervisor: Set ADC window and stride") + oce.add("25", "PLOC Supervisor: Set ADC threshold") + oce.add("26", "PLOC Supervisor: Request latchup status report") + oce.add("27", "PLOC Supervisor: Copy ADC data to MRAM") + oce.add("30", "PLOC Supervisor: Run auto EM tests") + oce.add("31", "PLOC Supervisor: MRAM Wipe") + oce.add("35", "PLOC Supervisor: Set GPIO") + oce.add("36", "PLOC Supervisor: Read GPIO") + oce.add("37", "PLOC Supervisor: Restart supervisor") + oce.add("38", "PLOC Supervisor: Factory reset clear all") + oce.add("39", "PLOC Supervisor: Factory reset clear mirror entries") + oce.add("40", "PLOC Supervisor: Factory reset clear circular entries") + oce.add("42", "PLOC Supervisor: Perform update") + oce.add("43", "PLOC Supervisor: Terminate supervisor process") + oce.add("44", "PLOC Supervisor: Start MPSoC quiet") + oce.add("45", "PLOC Supervisor: Set shutdown timeout") + oce.add("46", "PLOC Supervisor: Factory flash") + oce.add("47", "PLOC Supervisor: Enable auto TM") + oce.add("48", "PLOC Supervisor: Disable auto TM") + oce.add("51", "PLOC Supervisor: Logging request event buffers") + oce.add("52", "PLOC Supervisor: Logging clear counters") + oce.add("53", "PLOC Supervisor: Logging set topic") + oce.add("54", "PLOC Supervisor: Logging request counters") + oce.add("55", "PLOC Supervisor: Request ADC Report") + oce.add("56", "PLOC Supervisor: Reset PL") + oce.add("57", "PLOC Supervisor: Enable NVMs") + oce.add("58", "PLOC Supervisor: Continue update") + defs.add_service(CustomServiceList.PLOC_SUPV.value, "PLOC Supervisor", oce) + + +@service_provider(CustomServiceList.PLOC_SUPV) +def pack_ploc_supv_commands(p: ServiceProviderParams): + q = p.queue_helper + op_code = p.op_code + object_id = get_object_ids().get(PLOC_SUPV_ID) q.add_log_cmd(f"Testing PLOC Supervisor with object id: {object_id.as_hex_string}") obyt = object_id.as_bytes - if op_code == "0": + if op_code in OpCodes.OFF: q.add_log_cmd("PLOC Supervisor: Set mode off") command = pack_mode_data(object_id.as_bytes, Modes.OFF, 0) q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=command)) - if op_code == "1": + if op_code in OpCodes.ON: q.add_log_cmd("PLOC Supervisor: Set mode on") command = pack_mode_data(object_id.as_bytes, Modes.ON, 0) q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=command)) - if op_code == "2": + if op_code in OpCodes.NORMAL: q.add_log_cmd("PLOC Supervisor: Mode Normal") command = pack_mode_data(object_id.as_bytes, Modes.NORMAL, 0) q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=command)) diff --git a/tmtcc.py b/tmtcc.py index 934837e..16b122a 100755 --- a/tmtcc.py +++ b/tmtcc.py @@ -112,9 +112,7 @@ class TcHandler(TcHandlerBase): def feed_cb(self, info: ProcedureHelper, wrapper: FeedWrapper): self.queue_helper.queue_wrapper = wrapper.queue_wrapper if info.proc_type == TcProcedureType.DEFAULT: - handle_default_procedure( - info.to_def_procedure(), self.queue_helper, self.gui - ) + handle_default_procedure(self, info.to_def_procedure(), self.queue_helper) def send_cb(self, send_params: SendCbParams): entry_helper = send_params.entry