all import changes

This commit is contained in:
2023-02-01 16:25:17 +01:00
parent 6b657b5623
commit c8ea75b2ad
22 changed files with 203 additions and 212 deletions

115
eive_tmtc/tmtc/tcs/rtd.py Normal file
View File

@ -0,0 +1,115 @@
from typing import Optional
import struct
from eive_tmtc.config.definitions import CustomServiceList
from spacepackets.ecss import PusTelecommand
from tmtccmd.config import TmtcDefinitionWrapper, OpCodeEntry
from tmtccmd.config.tmtc import tmtc_definitions_provider
from tmtccmd.tc import DefaultPusQueueHelper
from tmtccmd.util import ObjectIdU32
from tmtccmd.tc.pus_200_fsfw_mode import Mode, pack_mode_data, Subservice
import eive_tmtc.config.object_ids as oids
from eive_tmtc.config.object_ids import get_object_ids
RTD_IDS = [
oids.RTD_0_PLOC_HSPD,
oids.RTD_1_PLOC_MISSIONBRD,
oids.RTD_2_4K_CAM,
oids.RTD_3_DAC_HSPD,
oids.RTD_4_STR,
oids.RTD_5_RW1_MX_MY,
oids.RTD_6_DRO,
oids.RTD_7_SCEX,
oids.RTD_8_X8,
oids.RTD_9_HPA,
oids.RTD_10_PL_TX,
oids.RTD_11_MPA,
oids.RTD_12_ACU,
oids.RTD_13_PLPCDU_HSPD,
oids.RTD_14_TCS_BRD,
oids.RTD_15_IMTQ,
]
class CommandId:
WRITE_CONFIG = 6
class OpCode:
ON = ["0", "on"]
OFF = ["1", "off"]
NORMAL = ["2", "normal"]
WRITE_CONFIG = ["3", "Write config"]
class Info:
ON = "Switch handler on"
OFF = "Switch handler off"
NORMAL = "Switch handler normal"
WRITE_CONFIG = "Write config"
@tmtc_definitions_provider
def specify_rtd_cmds(defs: TmtcDefinitionWrapper):
oce = OpCodeEntry()
oce.add(keys=OpCode.ON, info=Info.ON)
oce.add(keys=OpCode.NORMAL, info=Info.NORMAL)
oce.add(keys=OpCode.OFF, info=Info.OFF)
oce.add(keys=OpCode.WRITE_CONFIG, info=Info.WRITE_CONFIG)
defs.add_service(
name=CustomServiceList.RTD.value, info="RTD commands", op_code_entry=oce
)
def pack_rtd_commands(
op_code: str, object_id: Optional[ObjectIdU32], q: DefaultPusQueueHelper
):
if object_id is not None and object_id not in RTD_IDS:
print("Specified object ID not a valid RTD ID")
object_id = None
if object_id is None:
tgt_rtd_idx = prompt_rtd_idx()
object_id_dict = get_object_ids()
object_id = object_id_dict.get(RTD_IDS[tgt_rtd_idx])
if op_code in OpCode.ON:
app_data = pack_mode_data(object_id=object_id.as_bytes, mode=Mode.ON, submode=0)
q.add_pus_tc(
PusTelecommand(
service=200, subservice=Subservice.TC_MODE_COMMAND, app_data=app_data
)
)
if op_code in OpCode.NORMAL:
app_data = pack_mode_data(
object_id=object_id.as_bytes, mode=Mode.NORMAL, submode=0
)
q.add_pus_tc(
PusTelecommand(
service=200, subservice=Subservice.TC_MODE_COMMAND, app_data=app_data
)
)
if op_code in OpCode.OFF:
app_data = pack_mode_data(
object_id=object_id.as_bytes, mode=Mode.OFF, submode=0
)
q.add_pus_tc(
PusTelecommand(
service=200, subservice=Subservice.TC_MODE_COMMAND, app_data=app_data
)
)
if op_code in OpCode.WRITE_CONFIG:
command = object_id.as_bytes + struct.pack("!I", CommandId.WRITE_CONFIG)
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
def prompt_rtd_idx():
while True:
rtd_idx = input("Please specify RTD index [0-15]: ")
if not rtd_idx.isdigit():
print("Invalid input")
continue
rtd_idx = int(rtd_idx)
if rtd_idx < 0 or rtd_idx > 15:
print("Invalid device index")
continue
return rtd_idx

View File

@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-
"""
@file tmp1075.py
@brief TMP1075 tests
@author J. Meier
@date 06.01.2021
"""
import enum
from spacepackets.ecss.tc import PusTelecommand
from eive_tmtc.pus_tc.service_200_mode import pack_mode_data
from tmtccmd.tc import DefaultPusQueueHelper
from tmtccmd.tc.pus_200_fsfw_mode import Mode
from tmtccmd.pus.s8_fsfw_funccmd import make_action_id
from tmtccmd.util import ObjectIdU32
class Tmp1075TestProcedure:
"""
@brief Use this class to define the tests to perform for the Tmp1075.
@details Setting all to True will run all tests.
Setting all to False will only run the tests set to True.
"""
all = False
start_adc_conversion = False
get_temp = False
set_mode_normal = (
True # Setting mode to normal starts continuous temperature reading
)
set_mode_on = False # If mode is MODE_ON, temperature will only be read on command
class Tmp1075ActionId(enum.IntEnum):
GET_TEMP = 1
START_ADC_CONV = 2
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.as_hex_string}"
)
obyt = object_id.as_bytes
if Tmp1075TestProcedure.all or Tmp1075TestProcedure.start_adc_conversion:
q.add_log_cmd("TMP1075: Starting new temperature conversion")
command = obyt + make_action_id(Tmp1075ActionId.GET_TEMP)
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
if Tmp1075TestProcedure.all or Tmp1075TestProcedure.get_temp:
q.add_log_cmd("TMP1075: Read temperature")
command = obyt + make_action_id(Tmp1075ActionId.START_ADC_CONV)
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
if Tmp1075TestProcedure.set_mode_normal:
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 Tmp1075TestProcedure.set_mode_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))
return q