eive-tmtc/pus_tm/devs/mgms.py

49 lines
1.8 KiB
Python
Raw Normal View History

2022-05-19 14:50:24 +02:00
import struct
from pus_tm.defs import PrintWrapper
from pus_tc.devs.mgms import MgmRm3100SetIds, MgmLis3SetIds
2022-05-19 13:20:22 +02:00
from tmtccmd.utility import ObjectId
from tmtccmd.utility.tmtc_printer import FsfwTmTcPrinter
2022-05-19 14:50:24 +02:00
import config.object_ids as obj_ids
2022-05-19 13:20:22 +02:00
def handle_mgm_hk_data(
object_id: ObjectId, printer: FsfwTmTcPrinter, set_id: int, hk_data: bytes
):
2022-06-03 18:04:59 +02:00
if object_id.as_bytes in [obj_ids.MGM_0_LIS3_HANDLER_ID, obj_ids.MGM_2_LIS3_HANDLER_ID]:
2022-05-19 14:50:24 +02:00
handle_mgm_lis3_hk_data(object_id, printer, set_id, hk_data)
2022-06-03 18:04:59 +02:00
elif object_id.as_bytes in [obj_ids.MGM_1_RM3100_HANDLER_ID, obj_ids.MGM_3_RM3100_HANDLER_ID]:
handle_mgm_rm3100_hk_data(object_id, printer, 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(
object_id: ObjectId, printer: FsfwTmTcPrinter, set_id: int, hk_data: bytes
):
if set_id == MgmLis3SetIds.CORE_HK:
pw = PrintWrapper(printer)
fmt_str = "!ffff"
inc_len = struct.calcsize(fmt_str)
(field_x, field_y, field_z, temp) = struct.unpack(
2022-06-03 18:04:59 +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(
2022-05-19 18:47:23 +02:00
object_id: ObjectId, printer: FsfwTmTcPrinter, set_id: int, hk_data: bytes
2022-05-19 14:50:24 +02:00
):
if set_id == MgmRm3100SetIds.CORE_HK:
pw = PrintWrapper(printer)
fmt_str = f"!fff"
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])
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}"
)