89 lines
2.6 KiB
Python
89 lines
2.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
@file tmp1075.py
|
|
@brief TMP1075 tests
|
|
@author J. Meier
|
|
@date 06.01.2021
|
|
"""
|
|
import enum
|
|
import struct
|
|
|
|
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 FsfwTmTcPrinter
|
|
from tmtccmd.tc import DefaultPusQueueHelper
|
|
from tmtccmd.tc.pus_200_fsfw_mode import Mode, pack_mode_data
|
|
from tmtccmd.tc.pus_3_fsfw_hk import create_request_one_hk_command, make_sid
|
|
from tmtccmd.util import ObjectIdU32
|
|
|
|
|
|
class OpCode:
|
|
OFF = "off"
|
|
ON = "on"
|
|
NML = "nml"
|
|
HK = "hk"
|
|
|
|
|
|
class Info:
|
|
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, op_code: str, q: DefaultPusQueueHelper
|
|
):
|
|
q.add_log_cmd(
|
|
f"Testing Tmp1075 Temperature Sensor Handler with object id: {object_id}"
|
|
)
|
|
obyt = object_id.as_bytes
|
|
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:
|
|
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 op_code == OpCode.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 op_code == OpCode.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
|
|
|
|
|
|
@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)
|
|
|
|
|
|
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))
|