eive-tmtc/eive_tmtc/pus_tc/devs/rad_sensor.py

98 lines
3.1 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
"""
@file rad_sensor.py
@brief Tests for the radiation sensor handler
@author J. Meier
@date 01.07.2021
"""
2022-03-31 11:36:50 +02:00
import struct
2022-11-29 16:53:29 +01:00
from eive_tmtc.config.definitions import CustomServiceList
2021-10-01 10:55:56 +02:00
from spacepackets.ecss.tc import PusTelecommand
2023-01-16 15:05:33 +01:00
from eive_tmtc.pus_tc.service_200_mode import pack_mode_data, Mode
from tmtccmd.config import TmtcDefinitionWrapper, OpCodeEntry
from tmtccmd.config.tmtc import tmtc_definitions_provider
2022-08-08 16:32:18 +02:00
from tmtccmd.tc import DefaultPusQueueHelper
2022-05-23 18:25:25 +02:00
from tmtccmd.tc.pus_3_fsfw_hk import generate_one_hk_command, make_sid
2022-07-08 16:25:46 +02:00
from tmtccmd.util import ObjectIdU32
2023-01-16 14:13:06 +01:00
class SetId:
2022-05-23 15:49:21 +02:00
HK = 3
2023-01-16 14:13:06 +01:00
class OpCode:
2022-05-23 18:25:25 +02:00
ON = ["0", "on"]
NORMAL = ["1", "normal"]
OFF = ["2", "off"]
REQ_HK_ONCE = ["3", "hk-os"]
DEBUG_ON = ["10", "dbg-on"]
DEBUG_OFF = ["11", "dbg-off"]
class Info:
ON = "Switch Rad Sensor on"
NORMAL = "Switch Rad Sensor normal"
OFF = "Switch Rad sensor off"
REQ_OS_HK = "Request one-shot HK"
DEBUG_ON = "Switch debug output on"
DEBUG_OFF = "Switch debug output off"
2023-01-16 14:13:06 +01:00
class CommandId:
2022-03-31 11:36:50 +02:00
START_CONVERSIONS = 2
READ_CONVERSIONS = 3
ENABLE_DEBUG_OUTPUT = 4
DISABLE_DEBUG_OUTPUT = 5
@tmtc_definitions_provider
def add_rad_sens_cmds(defs: TmtcDefinitionWrapper):
2022-07-05 02:12:54 +02:00
oce = OpCodeEntry()
2023-01-16 14:13:06 +01:00
oce.add(info=Info.ON, keys=OpCode.ON)
oce.add(info=Info.OFF, keys=OpCode.OFF)
oce.add(info=Info.NORMAL, keys=OpCode.NORMAL)
oce.add(info=Info.REQ_OS_HK, keys=OpCode.REQ_HK_ONCE)
oce.add(info=Info.DEBUG_ON, keys=OpCode.DEBUG_ON)
oce.add(info=Info.DEBUG_OFF, keys=OpCode.DEBUG_OFF)
2022-07-05 02:12:54 +02:00
defs.add_service(
2022-05-23 18:25:25 +02:00
name=CustomServiceList.RAD_SENSOR.value,
info="Radiation Sensor",
2022-07-05 02:12:54 +02:00
op_code_entry=oce,
2022-05-23 18:25:25 +02:00
)
2022-03-31 11:36:50 +02:00
2022-08-08 16:32:18 +02:00
def pack_rad_sensor_test_into(
object_id: ObjectIdU32, q: DefaultPusQueueHelper, op_code: str
):
2022-07-04 15:22:53 +02:00
q.add_log_cmd(f"Commanding Radiation sensor handler {object_id}")
2022-03-31 11:36:50 +02:00
2023-01-16 14:13:06 +01:00
if op_code in OpCode.ON:
2023-01-16 15:05:33 +01:00
rad_sensor_mode_cmd(object_id, Mode.ON, Info.ON, q)
2023-01-16 14:13:06 +01:00
if op_code in OpCode.NORMAL:
2023-01-16 15:05:33 +01:00
rad_sensor_mode_cmd(object_id, Mode.NORMAL, Info.NORMAL, q)
2023-01-16 14:13:06 +01:00
if op_code in OpCode.OFF:
2023-01-16 15:05:33 +01:00
rad_sensor_mode_cmd(object_id, Mode.OFF, Info.OFF, q)
2023-01-16 14:13:06 +01:00
if op_code in OpCode.REQ_HK_ONCE:
2022-07-04 15:22:53 +02:00
q.add_log_cmd(f"Rad sensor: {Info.REQ_OS_HK}")
q.add_pus_tc(
2023-01-16 14:13:06 +01:00
generate_one_hk_command(sid=make_sid(object_id.as_bytes, set_id=SetId.HK))
2022-05-23 18:25:25 +02:00
)
2023-01-16 14:13:06 +01:00
if op_code in OpCode.DEBUG_ON:
2022-07-04 15:22:53 +02:00
q.add_log_cmd(f"Rad sensor: {Info.DEBUG_ON}")
2023-01-16 14:13:06 +01:00
command = object_id.as_bytes + struct.pack("!I", CommandId.ENABLE_DEBUG_OUTPUT)
2022-07-04 15:22:53 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2023-01-16 14:13:06 +01:00
if op_code in OpCode.DEBUG_OFF:
2022-07-04 15:22:53 +02:00
q.add_log_cmd(f"Rad sensor: {Info.DEBUG_OFF}")
2023-01-16 14:13:06 +01:00
command = object_id.as_bytes + struct.pack("!I", CommandId.DISABLE_DEBUG_OUTPUT)
2022-07-04 15:22:53 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2022-05-23 18:25:25 +02:00
2022-08-08 16:32:18 +02:00
def rad_sensor_mode_cmd(
2023-01-16 15:05:33 +01:00
object_id: ObjectIdU32, mode: Mode, info: str, q: DefaultPusQueueHelper
2022-08-08 16:32:18 +02:00
):
2022-07-04 15:22:53 +02:00
q.add_log_cmd(f"Rad sensor: {info}")
2022-05-23 18:25:25 +02:00
mode_data = pack_mode_data(object_id.as_bytes, mode, 0)
2022-07-04 15:22:53 +02:00
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data))