eive-tmtc/eive_tmtc/tmtc/tcs/tmp1075.py
Robin Mueller dccbf89da1
All checks were successful
EIVE/-/pipeline/head This commit looks good
some more fixes
2024-05-08 10:49:20 +02:00

100 lines
3.0 KiB
Python

# -*- coding: utf-8 -*-
"""
@file tmp1075.py
@brief TMP1075 tests
@author J. Meier
@date 06.01.2021
"""
import enum
import struct
from tmtccmd.config import CmdTreeNode
from eive_tmtc.config.definitions import CustomServiceList
from eive_tmtc.pus_tm.defs import PrintWrapper
from spacepackets.ecss.tc import PusTelecommand
from tmtccmd.config.tmtc import (
tmtc_definitions_provider,
TmtcDefinitionWrapper,
OpCodeEntry,
)
from tmtccmd.fsfw.tmtc_printer import get_validity_buffer_str
from tmtccmd.tmtc import DefaultPusQueueHelper
from tmtccmd.pus.s200_fsfw_mode import Mode, pack_mode_data
from tmtccmd.pus.tc.s3_fsfw_hk import create_request_one_hk_command, make_sid
from tmtccmd.util import ObjectIdU32
class CmdStr:
OFF = "off"
ON = "on"
NML = "nml"
HK = "hk"
class CmdInfo:
OFF = "Off"
ON = "On"
NML = "Normal"
HK = "HK"
class Tmp1075ActionId(enum.IntEnum):
GET_TEMP = 1
START_ADC_CONV = 2
class SetId(enum.IntEnum):
TEMPERATURE = 1
def pack_tmp1075_test_into(
object_id: ObjectIdU32, cmd_str: str, q: DefaultPusQueueHelper
):
q.add_log_cmd(
f"Testing Tmp1075 Temperature Sensor Handler with object id: {object_id}"
)
obyt = object_id.as_bytes
if cmd_str == CmdStr.OFF:
q.add_log_cmd("TMP1075: Set Normal Off")
mode_data = pack_mode_data(obyt, Mode.OFF, 0)
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data))
if cmd_str == CmdStr.NML:
q.add_log_cmd("TMP1075: Set Mode Normal")
mode_data = pack_mode_data(obyt, Mode.NORMAL, 0)
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data))
if cmd_str == CmdStr.ON:
q.add_log_cmd("TMP1075: Set Mode On")
mode_data = pack_mode_data(obyt, Mode.ON, 0)
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data))
if cmd_str == CmdStr.HK:
q.add_log_cmd("TMP1075: Request One-Shot HK")
q.add_pus_tc(create_request_one_hk_command(make_sid(obyt, SetId.TEMPERATURE)))
return q
def create_tmp_sens_node() -> CmdTreeNode:
node = CmdTreeNode("tmp_1075", "TMP1075 Temperatur Sensors")
node.add_child(CmdTreeNode(CmdStr.OFF, CmdInfo.OFF))
node.add_child(CmdTreeNode(CmdStr.ON, CmdInfo.ON))
node.add_child(CmdTreeNode(CmdStr.NML, CmdInfo.NML))
node.add_child(CmdTreeNode(CmdStr.HK, CmdInfo.HK))
return node
@tmtc_definitions_provider
def add_tmp_sens_cmds(defs: TmtcDefinitionWrapper):
oce = OpCodeEntry()
oce.add(CmdStr.OFF, CmdInfo.OFF)
oce.add(CmdStr.ON, CmdInfo.ON)
oce.add(CmdStr.NML, CmdInfo.NML)
oce.add(CmdStr.HK, CmdInfo.HK)
defs.add_service(CustomServiceList.TMP1075.value, "TMP1075 Temperature Sensor", oce)
def handle_tmp_1075_hk_data(set_id: int, hk_data: bytes, pw: PrintWrapper):
if set_id == SetId.TEMPERATURE:
temp = struct.unpack("!f", hk_data[0:4])[0]
pw.dlog(f"TMP1075 Temperature: {temp}")
pw.dlog(get_validity_buffer_str(hk_data[4:], 1))