diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cde35c..729c27c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,10 @@ list yields a list of all related PRs for each release. - Correction for ACS CTRL raw data requests HK type - Fixed diag related ACS hk cmds +## Added + +- Basic MGM commanding (modes) + # [v2.16.1] 2023-02-24 - Updated CSVs for new persistent TM store diff --git a/eive_tmtc/config/definitions.py b/eive_tmtc/config/definitions.py index c0eaee1..a3cf5c3 100644 --- a/eive_tmtc/config/definitions.py +++ b/eive_tmtc/config/definitions.py @@ -37,6 +37,7 @@ class CustomServiceList(str, enum.Enum): ACU = "acu" ACS = "acs" GYRO = "gyro" + MGMS = "mgms" COM_SS = "com" BPX_BATTERY = "bpx" HEATER = "heater" diff --git a/eive_tmtc/pus_tc/procedure_packer.py b/eive_tmtc/pus_tc/procedure_packer.py index 7560ca9..1c2376e 100644 --- a/eive_tmtc/pus_tc/procedure_packer.py +++ b/eive_tmtc/pus_tc/procedure_packer.py @@ -4,6 +4,7 @@ import logging from typing import cast from eive_tmtc.tmtc.acs.gyros import handle_gyr_cmd +from eive_tmtc.tmtc.acs.mgms import handle_mgm_cmd from eive_tmtc.tmtc.power.power import pack_power_commands from eive_tmtc.tmtc.tcs.rtd import pack_rtd_commands from eive_tmtc.tmtc.payload.scex import pack_scex_cmds @@ -135,6 +136,8 @@ def handle_default_procedure( return pack_single_rw_test_into( object_id=RW4_ID, rw_idx=4, q=queue_helper, op_code=op_code ) + if service == CustomServiceList.MGMS.value: + return handle_mgm_cmd(q=queue_helper, op_code=op_code) if service == CustomServiceList.RAD_SENSOR.value: object_id = cast(ObjectIdU32, obj_id_man.get(RAD_SENSOR_ID)) return pack_rad_sensor_test_into( diff --git a/eive_tmtc/tmtc/acs/gyros.py b/eive_tmtc/tmtc/acs/gyros.py index 612b37b..3e21a59 100644 --- a/eive_tmtc/tmtc/acs/gyros.py +++ b/eive_tmtc/tmtc/acs/gyros.py @@ -2,7 +2,10 @@ import enum import logging import struct +from spacepackets.ecss import PusTelecommand from tmtccmd.tc import DefaultPusQueueHelper +from tmtccmd.tc.pus_201_fsfw_health import pack_set_health_cmd_data, FsfwHealth +from tmtccmd.pus.s201_fsfw_health import Subservice import eive_tmtc.config.object_ids as obj_ids from tmtccmd.tc.pus_200_fsfw_mode import create_mode_command, Mode @@ -30,6 +33,7 @@ class OpCode: OFF = "off" CORE_HK = "core_hk" CFG_HK = "cfg_hk" + SET_FAULTY = "set_faulty" class AdisGyroSetId(enum.IntEnum): @@ -85,6 +89,15 @@ def handle_gyr_cmd(q: DefaultPusQueueHelper, op_code: str): q.add_pus_tc( create_request_one_hk_command(make_sid(gyr_obj_id, AdisGyroSetId.CFG_HK)) ) + elif op_code == OpCode.SET_FAULTY: + q.add_log_cmd(f"Gyro {gyr_info[0]} set faulty") + q.add_pus_tc( + PusTelecommand( + service=201, + subservice=Subservice.TC_SET_HEALTH, + app_data=pack_set_health_cmd_data(object_id=gyr_obj_id, health=FsfwHealth.FAULTY) + ) + ) else: logging.getLogger(__name__).warning( f"invalid op code {op_code} for gyro command" @@ -177,4 +190,5 @@ def add_gyr_cmd_defs(defs: TmtcDefinitionWrapper): oce.add(keys=OpCode.CFG_HK, info="Request CFG HK") oce.add(keys=OpCode.NML, info="Normal Mode") oce.add(keys=OpCode.OFF, info="Off Mode") + oce.add(keys=OpCode.SET_FAULTY, info="Set Faulty") defs.add_service(CustomServiceList.GYRO, info="Gyro", op_code_entry=oce) diff --git a/eive_tmtc/tmtc/acs/imtq.py b/eive_tmtc/tmtc/acs/imtq.py index c0caf24..9ca9eb5 100644 --- a/eive_tmtc/tmtc/acs/imtq.py +++ b/eive_tmtc/tmtc/acs/imtq.py @@ -61,6 +61,7 @@ class ImtqSetId: NEGATIVE_Y_TEST = 13 POSITIVE_Z_TEST = 14 NEGATIVE_Z_TEST = 15 + SELF_TEST_SET = 16 class ImtqActionId: @@ -307,7 +308,7 @@ ENG_HK_HEADERS = [ def handle_imtq_hk(printer: FsfwTmTcPrinter, hk_data: bytes, set_id: int): - if (set_id >= ImtqSetId.POSITIVE_X_TEST) and (set_id <= ImtqSetId.NEGATIVE_Z_TEST): + if set_id == ImtqSetId.SELF_TEST_SET: return handle_self_test_data(printer, hk_data) elif set_id == ImtqSetId.ENG_HK_NO_TORQUE: _LOGGER.info("Found engineering HK without torque") diff --git a/eive_tmtc/tmtc/acs/mgms.py b/eive_tmtc/tmtc/acs/mgms.py index 908df55..5d7ecc2 100644 --- a/eive_tmtc/tmtc/acs/mgms.py +++ b/eive_tmtc/tmtc/acs/mgms.py @@ -1,13 +1,25 @@ import enum import struct +from eive_tmtc.config.definitions import CustomServiceList +from tmtccmd.config import OpCodeEntry + import eive_tmtc.config.object_ids as obj_ids +from eive_tmtc.config.object_ids import MGM_0_LIS3_HANDLER_ID, MGM_1_RM3100_HANDLER_ID, MGM_2_LIS3_HANDLER_ID, MGM_3_RM3100_HANDLER_ID from eive_tmtc.pus_tm.defs import PrintWrapper +from tmtccmd.config.tmtc import tmtc_definitions_provider, TmtcDefinitionWrapper +from tmtccmd.tc import DefaultPusQueueHelper +from tmtccmd.tc.pus_200_fsfw_mode import create_mode_command, Mode from tmtccmd.util import ObjectIdU32 from tmtccmd.util.tmtc_printer import FsfwTmTcPrinter +class OpCode: + NORMAL = "normal" + OFF = "off" + + class MgmLis3SetId(enum.IntEnum): CORE_HK = 0 @@ -16,6 +28,36 @@ class MgmRm3100SetId(enum.IntEnum): CORE_HK = 0 +class MgmSel(enum.IntEnum): + MGM_0_LIS3 = 0 + MGM_1_RM3100 = 1 + MGM_2_LIS3 = 2 + MGM_3_RM3100 = 3 + + +MGM_SEL_DICT = { + MgmSel.MGM_0_LIS3: ("MGM_0_LIS3", MGM_0_LIS3_HANDLER_ID), + MgmSel.MGM_1_RM3100: ("MGM_1_RM3100", MGM_1_RM3100_HANDLER_ID), + MgmSel.MGM_2_LIS3: ("MGM_2_LIS3", MGM_2_LIS3_HANDLER_ID), + MgmSel.MGM_3_RM3100: ("MGM_3_RM3100", MGM_3_RM3100_HANDLER_ID), +} + + +def handle_mgm_cmd(q: DefaultPusQueueHelper, op_code: str): + print("Please select the MGM Device") + for (k, v) in MGM_SEL_DICT.items(): + print(f"{k}: {v[0]}") + sel_idx = int(input("Select MGM device by index: ")) + mgm_info = MGM_SEL_DICT[MgmSel(sel_idx)] + mgm_obj_id = mgm_info[1] + if op_code == OpCode.NORMAL: + q.add_log_cmd(f"Gyro {mgm_info[0]} NORMAL mode") + q.add_pus_tc(create_mode_command(mgm_obj_id, Mode.NORMAL, 0)) + if op_code == OpCode.OFF: + q.add_log_cmd(f"Gyro {mgm_info[0]} OFF mode") + q.add_pus_tc(create_mode_command(mgm_obj_id, Mode.OFF, 0)) + + def handle_mgm_hk_data( object_id: ObjectIdU32, printer: FsfwTmTcPrinter, set_id: int, hk_data: bytes ): @@ -61,3 +103,11 @@ def handle_mgm_rm3100_hk_data( pw.dlog( f"Field strengths in micro Tesla X {field_x} | Y {field_y} | Z {field_z}" ) + + +@tmtc_definitions_provider +def add_mgm_cmd_defs(defs: TmtcDefinitionWrapper): + oce = OpCodeEntry() + oce.add(keys=OpCode.NORMAL, info="Normal Mode") + oce.add(keys=OpCode.OFF, info="Off Mode") + defs.add_service(CustomServiceList.MGMS, info="MGMs", op_code_entry=oce) diff --git a/eive_tmtc/tmtc/power/power.py b/eive_tmtc/tmtc/power/power.py index 7430f34..c748b00 100644 --- a/eive_tmtc/tmtc/power/power.py +++ b/eive_tmtc/tmtc/power/power.py @@ -45,7 +45,7 @@ class SetId(enum.IntEnum): SWITCHER_SET = 0 -class PcduSetIds: +class PcduSetIds(enum.IntEnum): SWITCHER_SET = 0