eive-tmtc/eive_tmtc/tmtc/acs/mgms.py

116 lines
3.5 KiB
Python
Raw Normal View History

2023-02-01 15:58:34 +01:00
import enum
2022-05-19 14:50:24 +02:00
import struct
2023-02-28 01:24:47 +01:00
from eive_tmtc.config.definitions import CustomServiceList
from tmtccmd.config import OpCodeEntry
2023-02-01 16:25:17 +01:00
import eive_tmtc.config.object_ids as obj_ids
2023-03-02 14:41:23 +01:00
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,
)
2023-02-01 15:58:34 +01:00
2022-11-29 16:53:29 +01:00
from eive_tmtc.pus_tm.defs import PrintWrapper
2023-02-28 01:24:47 +01:00
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
2022-07-08 16:25:46 +02:00
from tmtccmd.util import ObjectIdU32
2023-02-01 15:58:34 +01:00
2023-02-28 01:24:47 +01:00
class OpCode:
NORMAL = "normal"
OFF = "off"
2023-02-01 15:58:34 +01:00
class MgmLis3SetId(enum.IntEnum):
CORE_HK = 0
class MgmRm3100SetId(enum.IntEnum):
CORE_HK = 0
2022-05-19 13:20:22 +02:00
2023-02-28 01:24:47 +01:00
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")
2023-07-13 11:30:43 +02:00
for k, v in MGM_SEL_DICT.items():
2023-02-28 01:24:47 +01:00
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))
2022-05-19 13:20:22 +02:00
def handle_mgm_hk_data(
2023-05-24 13:44:45 +02:00
object_id: ObjectIdU32, pw: PrintWrapper, set_id: int, hk_data: bytes
2022-05-19 13:20:22 +02:00
):
2022-07-04 15:22:53 +02:00
if object_id.as_bytes in [
obj_ids.MGM_0_LIS3_HANDLER_ID,
obj_ids.MGM_2_LIS3_HANDLER_ID,
]:
2023-05-24 13:44:45 +02:00
handle_mgm_lis3_hk_data(object_id, pw, set_id, hk_data)
2022-07-04 15:22:53 +02:00
elif object_id.as_bytes in [
obj_ids.MGM_1_RM3100_HANDLER_ID,
obj_ids.MGM_3_RM3100_HANDLER_ID,
]:
2023-05-24 13:44:45 +02:00
handle_mgm_rm3100_hk_data(object_id, pw, set_id, hk_data)
2022-05-19 13:20:22 +02:00
pass
2022-05-19 14:50:24 +02:00
def handle_mgm_lis3_hk_data(
2023-05-24 13:44:45 +02:00
object_id: ObjectIdU32, pw: PrintWrapper, set_id: int, hk_data: bytes
2022-05-19 14:50:24 +02:00
):
2023-01-16 14:13:06 +01:00
if set_id == MgmLis3SetId.CORE_HK:
2022-05-19 14:50:24 +02:00
fmt_str = "!ffff"
inc_len = struct.calcsize(fmt_str)
(field_x, field_y, field_z, temp) = struct.unpack(
2022-07-04 15:22:53 +02:00
fmt_str, hk_data[0 : 0 + inc_len]
2022-05-19 14:50:24 +02:00
)
pw.dlog(f"Received MGM LIS3 from object {object_id}")
2022-05-19 18:47:23 +02:00
pw.dlog(
f"Field strengths in micro Tesla X {field_x} | Y {field_y} | Z {field_z}"
)
2022-05-19 14:50:24 +02:00
pw.dlog(f"Temperature {temp} C")
def handle_mgm_rm3100_hk_data(
2023-05-24 13:44:45 +02:00
object_id: ObjectIdU32, pw: PrintWrapper, set_id: int, hk_data: bytes
2022-05-19 14:50:24 +02:00
):
2023-01-16 14:13:06 +01:00
if set_id == MgmRm3100SetId.CORE_HK:
2023-06-19 17:16:00 +02:00
fmt_str = "!fff"
2022-05-19 14:50:24 +02:00
inc_len = struct.calcsize(fmt_str)
2022-05-19 18:47:23 +02:00
(field_x, field_y, field_z) = struct.unpack(fmt_str, hk_data[0 : 0 + inc_len])
2023-02-21 14:29:40 +01:00
pw.dlog(f"Received MGM RM3100 from object {object_id}")
2022-05-19 18:47:23 +02:00
pw.dlog(
f"Field strengths in micro Tesla X {field_x} | Y {field_y} | Z {field_z}"
)
2023-02-28 01:24:47 +01:00
@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)