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

89 lines
2.6 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-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,
)
2023-06-18 13:30:45 +02:00
from tmtccmd.fsfw.tmtc_printer import FsfwTmTcPrinter
2022-08-08 16:32:18 +02:00
from tmtccmd.tc import DefaultPusQueueHelper
2023-02-01 19:48:30 +01:00
from tmtccmd.tc.pus_200_fsfw_mode import Mode, pack_mode_data
2023-02-06 14:44:37 +01:00
from tmtccmd.tc.pus_3_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-02-06 14:44:37 +01:00
class OpCode:
OFF = "off"
ON = "on"
NML = "nml"
HK = "hk"
2022-01-18 14:03:56 +01:00
2023-02-06 14:44:37 +01:00
class Info:
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(
object_id: ObjectIdU32, op_code: str, q: DefaultPusQueueHelper
):
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-02-06 14:44:37 +01:00
if op_code == OpCode.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 op_code == OpCode.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-02-06 14:44:37 +01:00
if op_code == OpCode.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-02-06 14:44:37 +01:00
if op_code == OpCode.HK:
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
@tmtc_definitions_provider
def add_tmp_sens_cmds(defs: TmtcDefinitionWrapper):
oce = OpCodeEntry()
oce.add(OpCode.OFF, Info.OFF)
oce.add(OpCode.ON, Info.ON)
oce.add(OpCode.NML, Info.NML)
oce.add(OpCode.HK, Info.HK)
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}")
pw.dlog(FsfwTmTcPrinter.get_validity_buffer(hk_data[4:], 1))