eive-tmtc/eive_tmtc/tmtc/tcs/tmp1075.py

100 lines
3.0 KiB
Python
Raw Normal View History

2021-01-10 11:42:06 +01:00
# -*- coding: utf-8 -*-
"""
2021-04-11 11:08:52 +02:00
@file tmp1075.py
2021-01-10 11:42:06 +01:00
@brief TMP1075 tests
@author J. Meier
@date 06.01.2021
"""
2023-01-16 17:11:20 +01:00
import enum
2023-06-18 13:30:45 +02:00
import struct
2023-01-16 17:11:20 +01:00
2023-11-28 17:41:46 +01:00
from tmtccmd.config import CmdTreeNode
2023-02-06 14:44:37 +01:00
from eive_tmtc.config.definitions import CustomServiceList
2023-06-18 13:30:45 +02:00
from eive_tmtc.pus_tm.defs import PrintWrapper
2021-10-01 10:55:56 +02:00
from spacepackets.ecss.tc import PusTelecommand
2023-02-06 14:44:37 +01:00
from tmtccmd.config.tmtc import (
tmtc_definitions_provider,
TmtcDefinitionWrapper,
OpCodeEntry,
)
2024-05-08 10:49:20 +02:00
from tmtccmd.fsfw.tmtc_printer import get_validity_buffer_str
2023-11-10 19:23:06 +01:00
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
2022-07-08 16:25:46 +02:00
from tmtccmd.util import ObjectIdU32
2021-01-10 11:42:06 +01:00
2023-11-22 10:17:05 +01:00
class CmdStr:
2023-02-06 14:44:37 +01:00
OFF = "off"
ON = "on"
NML = "nml"
HK = "hk"
2022-01-18 14:03:56 +01:00
2023-02-06 14:44:37 +01:00
2023-11-22 10:17:05 +01:00
class CmdInfo:
2023-02-06 14:44:37 +01:00
OFF = "Off"
ON = "On"
NML = "Normal"
HK = "HK"
2021-01-10 11:42:06 +01:00
2023-01-16 17:11:20 +01:00
class Tmp1075ActionId(enum.IntEnum):
GET_TEMP = 1
START_ADC_CONV = 2
2021-01-10 11:42:06 +01:00
2023-03-16 11:21:40 +01:00
class SetId(enum.IntEnum):
2023-03-06 10:26:58 +01:00
TEMPERATURE = 1
2023-02-06 14:44:37 +01:00
2022-08-08 16:32:18 +02:00
def pack_tmp1075_test_into(
2023-11-22 10:17:05 +01:00
object_id: ObjectIdU32, cmd_str: str, q: DefaultPusQueueHelper
2022-08-08 16:32:18 +02:00
):
2022-07-04 15:22:53 +02:00
q.add_log_cmd(
2023-02-06 14:49:50 +01:00
f"Testing Tmp1075 Temperature Sensor Handler with object id: {object_id}"
2021-03-19 17:50:09 +01:00
)
2022-07-04 15:22:53 +02:00
obyt = object_id.as_bytes
2023-11-22 10:17:05 +01:00
if cmd_str == CmdStr.OFF:
2023-02-06 14:44:37 +01:00
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))
2023-11-22 10:17:05 +01:00
if cmd_str == CmdStr.NML:
2022-07-04 15:22:53 +02:00
q.add_log_cmd("TMP1075: Set Mode Normal")
2023-01-16 15:05:33 +01:00
mode_data = pack_mode_data(obyt, Mode.NORMAL, 0)
2022-07-04 15:22:53 +02:00
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data))
2023-11-22 10:17:05 +01:00
if cmd_str == CmdStr.ON:
2022-07-04 15:22:53 +02:00
q.add_log_cmd("TMP1075: Set Mode On")
2023-01-16 15:05:33 +01:00
mode_data = pack_mode_data(obyt, Mode.ON, 0)
2022-07-04 15:22:53 +02:00
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data))
2023-11-22 10:17:05 +01:00
if cmd_str == CmdStr.HK:
2023-02-06 14:44:37 +01:00
q.add_log_cmd("TMP1075: Request One-Shot HK")
2023-03-06 10:36:08 +01:00
q.add_pus_tc(create_request_one_hk_command(make_sid(obyt, SetId.TEMPERATURE)))
2022-07-04 15:22:53 +02:00
return q
2023-02-06 14:44:37 +01:00
2023-11-28 17:41:46 +01:00
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
2023-02-06 14:44:37 +01:00
@tmtc_definitions_provider
def add_tmp_sens_cmds(defs: TmtcDefinitionWrapper):
oce = OpCodeEntry()
2023-11-22 10:17:05 +01:00
oce.add(CmdStr.OFF, CmdInfo.OFF)
oce.add(CmdStr.ON, CmdInfo.ON)
oce.add(CmdStr.NML, CmdInfo.NML)
oce.add(CmdStr.HK, CmdInfo.HK)
2023-02-06 14:44:37 +01:00
defs.add_service(CustomServiceList.TMP1075.value, "TMP1075 Temperature Sensor", oce)
2023-06-18 13:30:45 +02:00
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}")
2024-05-08 10:49:20 +02:00
pw.dlog(get_validity_buffer_str(hk_data[4:], 1))