eive-tmtc/eive_tmtc/tmtc/payload/plpcdu.py

705 lines
23 KiB
Python
Raw Normal View History

2022-02-25 19:21:32 +01:00
import enum
2023-02-01 11:17:04 +01:00
import logging
2022-05-24 17:01:35 +02:00
import struct
import time
2022-03-01 18:00:39 +01:00
from typing import Optional
2022-02-25 19:21:32 +01:00
2022-11-29 16:53:29 +01:00
from eive_tmtc.config.definitions import CustomServiceList
2023-02-01 16:25:17 +01:00
from eive_tmtc.pus_tm.defs import PrintWrapper
from tmtccmd.config import TmtcDefinitionWrapper
2022-07-04 17:59:09 +02:00
from tmtccmd.config.tmtc import OpCodeEntry, tmtc_definitions_provider
2023-11-10 19:23:06 +01:00
from tmtccmd.tmtc import DefaultPusQueueHelper
from tmtccmd.pus.tc.s3_fsfw_hk import (
2022-05-24 02:16:54 +02:00
make_sid,
generate_one_diag_command,
2022-10-19 10:11:40 +02:00
enable_periodic_hk_command_with_interval,
disable_periodic_hk_command,
2022-05-24 02:16:54 +02:00
)
2023-11-10 19:23:06 +01:00
from tmtccmd.pus.s11_tc_sched import (
2023-01-18 11:12:07 +01:00
create_enable_tc_sched_cmd,
create_time_tagged_cmd,
2022-05-24 17:01:35 +02:00
)
2023-11-10 19:23:06 +01:00
from tmtccmd.pus.s200_fsfw_mode import Subservice, pack_mode_data, Mode
from tmtccmd.pus.s20_fsfw_param import (
2023-05-24 13:44:45 +02:00
create_scalar_double_parameter,
2023-01-26 15:47:39 +01:00
create_load_param_cmd,
2023-05-24 13:44:45 +02:00
create_scalar_boolean_parameter,
2022-03-01 17:31:36 +01:00
)
2022-02-25 19:21:32 +01:00
from spacepackets.ecss.tc import PusTelecommand
2022-11-29 16:53:29 +01:00
from eive_tmtc.config.object_ids import PL_PCDU_ID
2023-05-25 11:31:06 +02:00
from tmtccmd.fsfw.tmtc_printer import FsfwTmTcPrinter
2022-02-25 19:21:32 +01:00
2023-02-01 11:17:04 +01:00
_LOGGER = logging.getLogger(__name__)
2022-02-25 19:21:32 +01:00
2022-03-01 18:00:39 +01:00
2023-01-16 14:13:06 +01:00
class OpCode:
2022-10-19 09:45:40 +02:00
SWITCH_HPA_ON_PROC = ["0", "proc_hpa"]
2023-10-23 16:30:16 +02:00
SWITCH_ON = "on"
SWITCH_OFF = "off"
NORMAL_SSR = "nml_ssr"
NORMAL_DRO = "nml_dro"
NORMAL_X8 = "nml_x8"
NORMAL_TX = "nml_tx"
NORMAL_MPA = "nml_mpa"
NORMAL_HPA = "nml_hpa"
2023-11-27 12:01:03 +01:00
NORMAL_CUSTOM = "nml_custom"
2023-10-23 16:30:16 +02:00
ENABLE_HK = "enable_hk"
DISABLE_HK = "disable_hk"
REQ_OS_HK = "hk_os"
2023-11-27 12:01:03 +01:00
DISABLE_ORDER_CHECKING = "disable_order_checking"
ENABLE_ORDER_CHECKING = "enable_order_checking"
2023-10-23 16:30:16 +02:00
UPDATE_I_UPPER_LIMIT = "update_i_upper_limit"
UPDATE_V_LOWER_LIMIT = "update_v_lower_limit"
UPDATE_V_UPPER_LIMIT = "update_v_upper_limit"
2022-10-19 09:45:40 +02:00
2023-11-27 12:01:03 +01:00
INJECT_SSR_TO_DRO_FAILURE = "inject_ssr_dro_fault"
INJECT_DRO_TO_X8_FAILURE = "inject_dro_x8_fault"
INJECT_X8_TO_TX_FAILURE = "inject_x8_tx_fault"
INJECT_TX_TO_MPA_FAILURE = "inject_tx_mpa_fault"
INJECT_MPA_TO_HPA_FAILURE = "inject_mpa_hpa_fault"
INJECT_ALL_ON_FAILURE = "inject_all_on_fault"
2022-02-25 19:21:32 +01:00
class Info:
2022-10-19 10:52:29 +02:00
NORMAL = "ADC modules normal"
SWITCH_ON = "Switching on"
SWITCH_OFF = "Switching off"
NORMAL_SSR = f"{NORMAL}, SSR on"
NORMAL_DRO = f"{NORMAL},DRO on"
NORMAL_X8 = f"{NORMAL}, X8 on"
NORMAL_TX = f"{NORMAL}, TX on"
NORMAL_MPA = f"{NORMAL}, MPA on"
NORMAL_HPA = f"{NORMAL}, HPA on"
2023-11-27 12:01:03 +01:00
NORMAL_CUSTOM = f"{NORMAL}, Custom Channel Settings"
2022-05-24 02:16:54 +02:00
REQ_OS_HK = "Request One Shot HK"
2022-10-19 10:52:29 +02:00
SWITCH_HPA_ON_PROC = "Switch HPA on procedure"
2022-10-19 10:11:40 +02:00
ENABLE_HK = "Enable HK"
DISABLE_HK = "Disable HK"
2023-10-23 16:30:16 +02:00
UPDATE_I_UPPER_LIMIT = "Update upper current parameter"
UPDATE_V_LOWER_LIMIT = "Update lower voltage parameter"
UPDATE_V_UPPER_LIMIT = "Update upper voltage parameter"
2023-11-27 12:01:03 +01:00
DISABLE_ORDER_CHECKING = "Disable order checks"
ENABLE_ORDER_CHECKING = "Enable order checks"
2022-05-24 02:16:54 +02:00
2023-01-16 14:13:06 +01:00
class SetId(enum.IntEnum):
2022-05-24 02:16:54 +02:00
ADC = 0
2022-04-04 13:53:26 +02:00
class NormalSubmodesMask(enum.IntEnum):
SOLID_STATE_RELAYS_ADC_ON = 0
DRO_ON = 1
X8_ON = 2
TX_ON = 3
MPA_ON = 4
HPA_ON = 5
2022-02-25 19:21:32 +01:00
2023-08-15 11:51:12 +02:00
class SubmodeForNormalMode(enum.IntEnum):
2023-08-15 13:54:18 +02:00
NONE = 0
2023-08-15 11:50:39 +02:00
SSR_ON = 1 << NormalSubmodesMask.SOLID_STATE_RELAYS_ADC_ON
DRO_ON = 1 << NormalSubmodesMask.DRO_ON | (
1 << NormalSubmodesMask.SOLID_STATE_RELAYS_ADC_ON
)
X8_ON = (
1 << NormalSubmodesMask.DRO_ON
| (1 << NormalSubmodesMask.SOLID_STATE_RELAYS_ADC_ON)
| (1 << NormalSubmodesMask.X8_ON)
)
TX_ON = (
1 << NormalSubmodesMask.DRO_ON
| (1 << NormalSubmodesMask.SOLID_STATE_RELAYS_ADC_ON)
| (1 << NormalSubmodesMask.X8_ON)
| (1 << NormalSubmodesMask.TX_ON)
)
MPA_ON = (
1 << NormalSubmodesMask.DRO_ON
| (1 << NormalSubmodesMask.SOLID_STATE_RELAYS_ADC_ON)
| (1 << NormalSubmodesMask.X8_ON)
| (1 << NormalSubmodesMask.TX_ON)
| (1 << NormalSubmodesMask.MPA_ON)
)
HPA_ON = (
1 << NormalSubmodesMask.DRO_ON
| (1 << NormalSubmodesMask.SOLID_STATE_RELAYS_ADC_ON)
| (1 << NormalSubmodesMask.X8_ON)
| (1 << NormalSubmodesMask.TX_ON)
| (1 << NormalSubmodesMask.MPA_ON)
| (1 << NormalSubmodesMask.HPA_ON)
)
2023-10-23 16:30:16 +02:00
class ParamId(enum.IntEnum):
2022-03-02 11:26:18 +01:00
NEG_V_LOWER_BOUND = 0
NEG_V_UPPER_BOUND = 1
DRO_U_LOWER_BOUND = 2
DRO_U_UPPER_BOUND = 3
DRO_I_UPPER_BOUND = 4
X8_U_LOWER_BOUND = 5
X8_U_UPPER_BOUND = 6
X8_I_UPPER_BOUND = 7
TX_U_LOWER_BOUND = 8
TX_U_UPPER_BOUND = 9
TX_I_UPPER_BOUND = 10
MPA_U_LOWER_BOUND = 11
MPA_U_UPPER_BOUND = 12
MPA_I_UPPER_BOUND = 13
HPA_U_LOWER_BOUND = 14
HPA_U_UPPER_BOUND = 15
HPA_I_UPPER_BOUND = 16
2022-03-01 19:41:24 +01:00
SSR_TO_DRO_WAIT_TIME = 17
DRO_TO_X8_WAIT_TIME = 18
2022-03-02 11:26:18 +01:00
X8_TO_TX_WAIT_TIME = 19
TX_TO_MPA_WAIT_TIME = 20
MPA_TO_HPA_WAIT_TIME = 21
INJECT_SSR_TO_DRO_FAILURE = 30
INJECT_DRO_TO_X8_FAILURE = 31
INJECT_X8_TO_TX_FAILURE = 32
INJECT_TX_TO_MPA_FAILURE = 33
INJECT_MPA_TO_HPA_FAILURE = 34
INJECT_ALL_ON_FAILURE = 35
2022-03-01 17:31:36 +01:00
2023-11-27 12:01:03 +01:00
DISABLE_ORDER_CHECK_CHANNELS = 40
2022-03-01 17:31:36 +01:00
2023-10-23 16:30:16 +02:00
class DevSelect(enum.IntEnum):
SSR_NEG_V = 0
DRO = 1
X8 = 2
TX = 3
MPA = 4
HPA = 5
@tmtc_definitions_provider
def add_pl_pcdu_cmds(defs: TmtcDefinitionWrapper):
2022-07-05 02:12:54 +02:00
oce = OpCodeEntry()
2023-01-16 14:13:06 +01:00
oce.add(keys=OpCode.SWITCH_HPA_ON_PROC, info=Info.SWITCH_HPA_ON_PROC)
oce.add(keys=OpCode.SWITCH_ON, info=Info.SWITCH_ON)
oce.add(keys=OpCode.SWITCH_OFF, info=Info.SWITCH_OFF)
oce.add(keys=OpCode.NORMAL_SSR, info=Info.NORMAL_SSR)
oce.add(keys=OpCode.NORMAL_DRO, info=Info.NORMAL_DRO)
oce.add(keys=OpCode.NORMAL_X8, info=Info.NORMAL_X8)
oce.add(keys=OpCode.NORMAL_TX, info=Info.NORMAL_TX)
oce.add(keys=OpCode.NORMAL_MPA, info=Info.NORMAL_MPA)
oce.add(keys=OpCode.NORMAL_HPA, info=Info.NORMAL_HPA)
2023-11-27 12:01:03 +01:00
oce.add(keys=OpCode.NORMAL_CUSTOM, info=Info.NORMAL_CUSTOM)
2023-01-16 14:13:06 +01:00
oce.add(keys=OpCode.REQ_OS_HK, info=Info.REQ_OS_HK)
oce.add(keys=OpCode.ENABLE_HK, info=Info.ENABLE_HK)
2023-10-23 16:30:16 +02:00
oce.add(keys=OpCode.UPDATE_V_LOWER_LIMIT, info=Info.UPDATE_V_LOWER_LIMIT)
oce.add(keys=OpCode.UPDATE_V_UPPER_LIMIT, info=Info.UPDATE_V_UPPER_LIMIT)
oce.add(keys=OpCode.UPDATE_I_UPPER_LIMIT, info=Info.UPDATE_I_UPPER_LIMIT)
2022-07-05 02:12:54 +02:00
oce.add(
2023-01-16 14:13:06 +01:00
keys=OpCode.INJECT_SSR_TO_DRO_FAILURE,
2022-05-24 02:16:54 +02:00
info="Inject failure SSR to DRO transition",
)
2022-07-05 02:12:54 +02:00
oce.add(
2023-01-16 14:13:06 +01:00
keys=OpCode.INJECT_DRO_TO_X8_FAILURE,
2022-05-24 02:16:54 +02:00
info="Inject failure in DRO to X8 transition",
)
2022-07-05 02:12:54 +02:00
oce.add(
2023-01-16 14:13:06 +01:00
keys=OpCode.INJECT_X8_TO_TX_FAILURE,
2022-05-24 02:16:54 +02:00
info="Inject failure in X8 to TX transition",
)
2022-07-05 02:12:54 +02:00
oce.add(
2023-01-16 14:13:06 +01:00
keys=OpCode.INJECT_TX_TO_MPA_FAILURE,
2022-05-24 02:16:54 +02:00
info="Inject failure in TX to MPA transition",
)
2022-07-05 02:12:54 +02:00
oce.add(
2023-01-16 14:13:06 +01:00
keys=OpCode.INJECT_MPA_TO_HPA_FAILURE,
2022-05-24 02:16:54 +02:00
info="Inject failure in MPA to HPA transition",
)
2023-01-16 14:13:06 +01:00
oce.add(keys=OpCode.INJECT_ALL_ON_FAILURE, info="Inject failure in all on mode")
2023-11-27 12:01:03 +01:00
oce.add(keys=OpCode.DISABLE_ORDER_CHECKING, info=Info.DISABLE_ORDER_CHECKING)
oce.add(keys=OpCode.ENABLE_ORDER_CHECKING, info=Info.ENABLE_ORDER_CHECKING)
2022-08-08 16:47:41 +02:00
defs.add_service(CustomServiceList.PL_PCDU.value, "PL PCDU", oce)
2022-05-24 02:16:54 +02:00
2023-06-19 17:16:00 +02:00
def pack_pl_pcdu_commands( # noqa C901: Complexity is okay here.
q: DefaultPusQueueHelper, op_code: str
): # noqa C901: Complexity is okay here.
2023-10-23 16:30:16 +02:00
if op_code == OpCode.SWITCH_ON:
2023-01-16 15:05:33 +01:00
pack_pl_pcdu_mode_cmd(q=q, info=Info.SWITCH_ON, mode=Mode.ON, submode=0)
2023-10-23 16:30:16 +02:00
if op_code == OpCode.SWITCH_OFF:
2023-01-16 15:05:33 +01:00
pack_pl_pcdu_mode_cmd(q=q, info=Info.SWITCH_OFF, mode=Mode.OFF, submode=0)
2023-01-16 14:13:06 +01:00
if op_code in OpCode.ENABLE_HK:
2022-10-19 10:11:40 +02:00
interval = float(
input("Please enter HK collection interval in floating point seconds: ")
)
cmds = enable_periodic_hk_command_with_interval(
2023-01-16 14:13:06 +01:00
diag=True, sid=make_sid(PL_PCDU_ID, SetId.ADC), interval_seconds=interval
2022-10-19 10:11:40 +02:00
)
q.add_log_cmd(f"Enable PL PCDU HK with interval of {interval} seconds")
for cmd in cmds:
q.add_pus_tc(cmd)
2023-10-23 16:30:16 +02:00
if op_code == OpCode.DISABLE_HK:
2022-10-19 10:11:40 +02:00
cmd = disable_periodic_hk_command(
2023-01-16 14:13:06 +01:00
diag=True, sid=make_sid(PL_PCDU_ID, SetId.ADC)
2022-10-19 10:11:40 +02:00
)
q.add_log_cmd("Disabling PL PCDU HK")
q.add_pus_tc(cmd)
2023-10-23 16:30:16 +02:00
if op_code == OpCode.NORMAL_SSR:
pack_pl_pcdu_mode_cmd(
2022-07-04 17:59:09 +02:00
q=q,
info=Info.NORMAL_SSR,
2023-01-16 15:05:33 +01:00
mode=Mode.NORMAL,
2022-05-24 17:01:35 +02:00
submode=submode_mask_to_submode(
NormalSubmodesMask.SOLID_STATE_RELAYS_ADC_ON
),
2022-03-04 10:44:55 +01:00
)
2023-10-23 16:30:16 +02:00
if op_code == OpCode.NORMAL_DRO:
pack_pl_pcdu_mode_cmd(
2022-07-04 17:59:09 +02:00
q=q,
info=Info.NORMAL_DRO,
2023-01-16 15:05:33 +01:00
mode=Mode.NORMAL,
2022-05-24 17:01:35 +02:00
submode=submode_mask_to_submode(NormalSubmodesMask.DRO_ON),
2022-02-25 19:21:32 +01:00
)
2023-10-23 16:30:16 +02:00
if op_code == OpCode.NORMAL_X8:
pack_pl_pcdu_mode_cmd(
2022-07-04 17:59:09 +02:00
q=q,
info=Info.NORMAL_X8,
2023-01-16 15:05:33 +01:00
mode=Mode.NORMAL,
2022-05-24 17:01:35 +02:00
submode=submode_mask_to_submode(NormalSubmodesMask.X8_ON),
2022-02-25 19:21:32 +01:00
)
2023-10-23 16:30:16 +02:00
if op_code == OpCode.NORMAL_TX:
pack_pl_pcdu_mode_cmd(
2022-07-04 17:59:09 +02:00
q=q,
info=Info.NORMAL_TX,
2023-01-16 15:05:33 +01:00
mode=Mode.NORMAL,
2022-05-24 17:01:35 +02:00
submode=submode_mask_to_submode(NormalSubmodesMask.TX_ON),
2022-03-04 10:44:55 +01:00
)
2023-10-23 16:30:16 +02:00
if op_code == OpCode.NORMAL_MPA:
pack_pl_pcdu_mode_cmd(
2022-07-04 17:59:09 +02:00
q=q,
info=Info.NORMAL_MPA,
2023-01-16 15:05:33 +01:00
mode=Mode.NORMAL,
2022-05-24 17:01:35 +02:00
submode=submode_mask_to_submode(NormalSubmodesMask.MPA_ON),
2022-02-25 19:21:32 +01:00
)
2023-10-23 16:30:16 +02:00
if op_code == OpCode.NORMAL_HPA:
pack_pl_pcdu_mode_cmd(
2022-07-04 17:59:09 +02:00
q=q,
info=Info.NORMAL_HPA,
2023-01-16 15:05:33 +01:00
mode=Mode.NORMAL,
2022-05-24 17:01:35 +02:00
submode=submode_mask_to_submode(NormalSubmodesMask.HPA_ON),
2022-02-25 19:21:32 +01:00
)
2023-11-27 12:01:03 +01:00
if op_code == OpCode.NORMAL_CUSTOM:
pack_pl_pcdu_mode_cmd(
q=q,
info=Info.NORMAL_CUSTOM,
mode=Mode.NORMAL,
submode=prompt_custom_normal_submode(),
)
2023-10-23 16:30:16 +02:00
if op_code == OpCode.REQ_OS_HK:
2022-07-04 17:59:09 +02:00
q.add_log_cmd(f"PL PCDU: {Info.REQ_OS_HK}")
q.add_pus_tc(
generate_one_diag_command(
2023-01-16 14:13:06 +01:00
sid=make_sid(object_id=PL_PCDU_ID, set_id=SetId.ADC)
2022-07-04 17:59:09 +02:00
)
2022-05-24 02:16:54 +02:00
)
2023-11-27 12:01:03 +01:00
if op_code == OpCode.DISABLE_ORDER_CHECKING:
q.add_log_cmd(Info.DISABLE_ORDER_CHECKING)
q.add_pus_tc(
create_load_param_cmd(
create_scalar_boolean_parameter(
2023-11-27 12:18:39 +01:00
PL_PCDU_ID, 0, ParamId.DISABLE_ORDER_CHECK_CHANNELS, True
2023-11-27 12:01:03 +01:00
)
)
)
if op_code == OpCode.ENABLE_ORDER_CHECKING:
q.add_log_cmd(Info.ENABLE_ORDER_CHECKING)
q.add_pus_tc(
create_load_param_cmd(
create_scalar_boolean_parameter(
2023-11-27 12:18:39 +01:00
PL_PCDU_ID, 0, ParamId.DISABLE_ORDER_CHECK_CHANNELS, False
2023-11-27 12:01:03 +01:00
)
)
)
2023-10-23 16:30:16 +02:00
if op_code == OpCode.UPDATE_I_UPPER_LIMIT:
q.add_log_cmd(Info.UPDATE_I_UPPER_LIMIT)
print("Select device to update lower current limit for: ")
2023-10-23 17:16:23 +02:00
param_id = dev_select_to_upper_i_update_param_id(dev_select_prompt(True))
2023-10-23 16:30:16 +02:00
new_param_value = float(
input("Please specify new parameter value as a double: ")
)
q.add_pus_tc(
create_load_param_cmd(
create_scalar_double_parameter(PL_PCDU_ID, 0, param_id, new_param_value)
)
)
if op_code == OpCode.UPDATE_V_LOWER_LIMIT:
q.add_log_cmd(Info.UPDATE_V_LOWER_LIMIT)
print("Select device to update lower voltage limit for: ")
2023-10-23 17:20:04 +02:00
param_id = dev_select_to_lower_u_update_param_id(dev_select_prompt(False))
2023-10-23 16:30:16 +02:00
new_param_value = float(
input("Please specify new parameter value as a double: ")
)
q.add_pus_tc(
create_load_param_cmd(
create_scalar_double_parameter(PL_PCDU_ID, 0, param_id, new_param_value)
)
)
if op_code == OpCode.UPDATE_V_UPPER_LIMIT:
q.add_log_cmd(Info.UPDATE_V_UPPER_LIMIT)
print("Select device to update upper voltage limit for: ")
2023-10-23 17:20:04 +02:00
param_id = dev_select_to_upper_u_update_param_id(dev_select_prompt(False))
2023-10-23 16:30:16 +02:00
new_param_value = float(
input("Please specify new parameter value as a double: ")
)
q.add_pus_tc(
create_load_param_cmd(
create_scalar_double_parameter(PL_PCDU_ID, 0, param_id, new_param_value)
)
)
if op_code == OpCode.SWITCH_HPA_ON_PROC:
2022-07-04 17:59:09 +02:00
hpa_on_procedure(q)
2023-10-23 16:30:16 +02:00
if op_code == OpCode.INJECT_ALL_ON_FAILURE:
2022-03-02 15:06:50 +01:00
pack_failure_injection_cmd(
2022-07-04 17:59:09 +02:00
q=q,
2023-10-23 16:30:16 +02:00
param_id=ParamId.INJECT_ALL_ON_FAILURE,
2022-03-04 10:44:55 +01:00
print_str="All On",
2022-03-02 15:06:50 +01:00
)
2022-03-01 18:00:39 +01:00
2022-08-08 16:32:18 +02:00
def hpa_on_procedure(q: DefaultPusQueueHelper):
2022-05-24 17:04:03 +02:00
delay_dro_to_x8 = request_wait_time()
if delay_dro_to_x8 is None:
delay_dro_to_x8 = 900
2022-07-04 17:59:09 +02:00
q.add_log_cmd(
2023-09-12 13:48:38 +02:00
"Starting procedure to switch on PL PCDU HPA with DRO to X8 "
2022-07-04 17:59:09 +02:00
f"delay of {delay_dro_to_x8} seconds"
2022-05-24 17:04:03 +02:00
)
pl_pcdu_on = PusTelecommand(
service=200,
2023-01-17 18:37:16 +01:00
subservice=Subservice.TC_MODE_COMMAND,
2023-01-16 15:05:33 +01:00
app_data=pack_mode_data(object_id=PL_PCDU_ID, mode=Mode.ON, submode=0),
2022-05-24 17:04:03 +02:00
)
ssr_on = PusTelecommand(
service=200,
2023-01-17 18:37:16 +01:00
subservice=Subservice.TC_MODE_COMMAND,
2022-05-24 17:04:03 +02:00
app_data=pack_mode_data(
object_id=PL_PCDU_ID,
2023-01-16 15:05:33 +01:00
mode=Mode.NORMAL,
2022-05-24 17:04:03 +02:00
submode=submode_mask_to_submode(
NormalSubmodesMask.SOLID_STATE_RELAYS_ADC_ON
),
),
)
dro_on = PusTelecommand(
service=200,
2023-01-17 18:37:16 +01:00
subservice=Subservice.TC_MODE_COMMAND,
2022-05-24 17:04:03 +02:00
app_data=pack_mode_data(
object_id=PL_PCDU_ID,
2023-01-16 15:05:33 +01:00
mode=Mode.NORMAL,
2022-05-24 17:04:03 +02:00
submode=submode_mask_to_submode(NormalSubmodesMask.DRO_ON),
),
)
x8_on = PusTelecommand(
service=200,
2023-01-17 18:37:16 +01:00
subservice=Subservice.TC_MODE_COMMAND,
2022-05-24 17:04:03 +02:00
app_data=pack_mode_data(
object_id=PL_PCDU_ID,
2023-01-16 15:05:33 +01:00
mode=Mode.NORMAL,
2022-05-24 17:04:03 +02:00
submode=submode_mask_to_submode(NormalSubmodesMask.X8_ON),
),
)
tx_on = PusTelecommand(
service=200,
2023-01-17 18:37:16 +01:00
subservice=Subservice.TC_MODE_COMMAND,
2022-05-24 17:04:03 +02:00
app_data=pack_mode_data(
object_id=PL_PCDU_ID,
2023-01-16 15:05:33 +01:00
mode=Mode.NORMAL,
2022-05-24 17:04:03 +02:00
submode=submode_mask_to_submode(NormalSubmodesMask.TX_ON),
),
)
mpa_on = PusTelecommand(
service=200,
2023-01-17 18:37:16 +01:00
subservice=Subservice.TC_MODE_COMMAND,
2022-05-24 17:04:03 +02:00
app_data=pack_mode_data(
object_id=PL_PCDU_ID,
2023-01-16 15:05:33 +01:00
mode=Mode.NORMAL,
2022-05-24 17:04:03 +02:00
submode=submode_mask_to_submode(NormalSubmodesMask.MPA_ON),
),
)
hpa_on = PusTelecommand(
service=200,
2023-01-17 18:37:16 +01:00
subservice=Subservice.TC_MODE_COMMAND,
2022-05-24 17:04:03 +02:00
app_data=pack_mode_data(
object_id=PL_PCDU_ID,
2023-01-16 15:05:33 +01:00
mode=Mode.NORMAL,
2022-05-24 17:04:03 +02:00
submode=submode_mask_to_submode(NormalSubmodesMask.HPA_ON),
),
)
current_time = time.time()
2022-05-24 17:01:35 +02:00
2023-01-18 11:12:07 +01:00
enb_sched = create_enable_tc_sched_cmd()
2022-05-24 17:01:35 +02:00
2022-08-11 15:40:38 +02:00
sched_time = int(round(current_time + 10))
2022-07-04 17:59:09 +02:00
q.add_pus_tc(enb_sched)
2023-01-18 11:12:07 +01:00
tagged_on_cmd = create_time_tagged_cmd(
2022-05-24 17:04:03 +02:00
release_time=struct.pack("!I", sched_time),
tc_to_insert=pl_pcdu_on,
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(tagged_on_cmd)
2022-05-24 17:01:35 +02:00
2022-05-24 17:04:03 +02:00
sched_time += 5
2023-01-18 11:12:07 +01:00
tagged_ssr_cmd = create_time_tagged_cmd(
2022-05-24 17:04:03 +02:00
release_time=struct.pack("!I", sched_time),
tc_to_insert=ssr_on,
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(tagged_ssr_cmd)
2022-05-24 17:01:35 +02:00
2022-05-24 17:04:03 +02:00
sched_time += 5
2023-01-18 11:12:07 +01:00
tagged_dro_cmd = create_time_tagged_cmd(
2022-07-04 17:59:09 +02:00
release_time=struct.pack("!I", sched_time), tc_to_insert=dro_on
2022-05-24 17:04:03 +02:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(tagged_dro_cmd)
2022-05-24 17:01:35 +02:00
2022-05-24 17:04:03 +02:00
sched_time += delay_dro_to_x8
2022-08-11 15:40:38 +02:00
sched_time = int(round(sched_time))
2023-01-18 11:12:07 +01:00
tagged_x8_cmd = create_time_tagged_cmd(
2022-07-04 17:59:09 +02:00
release_time=struct.pack("!I", sched_time), tc_to_insert=x8_on
2022-05-24 17:04:03 +02:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(tagged_x8_cmd)
2022-05-24 17:01:35 +02:00
2022-05-24 17:04:03 +02:00
sched_time += 5
2023-01-18 11:12:07 +01:00
tagged_tx_cmd = create_time_tagged_cmd(
2022-07-04 17:59:09 +02:00
release_time=struct.pack("!I", sched_time), tc_to_insert=tx_on
2022-05-24 17:04:03 +02:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(tagged_tx_cmd)
2022-05-24 17:01:35 +02:00
2022-05-24 17:04:03 +02:00
sched_time += 5
2023-01-18 11:12:07 +01:00
tagged_mpa_cmd = create_time_tagged_cmd(
2022-07-04 17:59:09 +02:00
release_time=struct.pack("!I", sched_time), tc_to_insert=mpa_on
2022-05-24 17:04:03 +02:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(tagged_mpa_cmd)
2022-05-24 17:04:03 +02:00
sched_time += 5
2023-01-18 11:12:07 +01:00
tagged_hpa_cmd = create_time_tagged_cmd(
2022-07-04 17:59:09 +02:00
release_time=struct.pack("!I", sched_time), tc_to_insert=hpa_on
2022-05-24 17:04:03 +02:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(tagged_hpa_cmd)
2022-03-01 18:00:39 +01:00
def request_wait_time() -> Optional[float]:
while True:
2022-03-01 19:41:24 +01:00
wait_time = input("Please enter DRO to X8 wait time in seconds, x to cancel: ")
2022-03-01 18:00:39 +01:00
if wait_time.lower() == "x":
return None
2022-03-01 19:41:24 +01:00
try:
wait_time = float(wait_time)
except ValueError:
2023-02-01 11:17:04 +01:00
_LOGGER.warning("Invalid input")
2022-03-01 18:00:39 +01:00
continue
if wait_time <= 0:
2023-02-01 11:17:04 +01:00
_LOGGER.warning("Invalid input")
2022-03-01 18:00:39 +01:00
else:
return wait_time
2022-03-02 11:44:39 +01:00
2022-05-24 17:04:03 +02:00
def submode_mask_to_submode(on_tgt: NormalSubmodesMask) -> int:
if on_tgt == NormalSubmodesMask.SOLID_STATE_RELAYS_ADC_ON:
2023-08-15 11:51:41 +02:00
return SubmodeForNormalMode.SSR_ON
2022-05-24 17:04:03 +02:00
if on_tgt == NormalSubmodesMask.DRO_ON:
2023-08-15 11:51:41 +02:00
return SubmodeForNormalMode.DRO_ON
2022-05-24 17:04:03 +02:00
if on_tgt == NormalSubmodesMask.X8_ON:
2023-08-15 11:51:41 +02:00
return SubmodeForNormalMode.X8_ON
2022-05-24 17:04:03 +02:00
if on_tgt == NormalSubmodesMask.TX_ON:
2023-08-15 11:51:41 +02:00
return SubmodeForNormalMode.TX_ON
2022-05-24 17:04:03 +02:00
if on_tgt == NormalSubmodesMask.MPA_ON:
2023-08-15 11:51:41 +02:00
return SubmodeForNormalMode.MPA_ON
2022-05-24 17:04:03 +02:00
if on_tgt == NormalSubmodesMask.HPA_ON:
2023-08-15 11:51:41 +02:00
return SubmodeForNormalMode.HPA_ON
2022-05-24 17:04:03 +02:00
2022-08-08 16:32:18 +02:00
def pack_wait_time_cmd(q: DefaultPusQueueHelper, param_id: int, print_str: str):
2022-03-02 11:44:39 +01:00
wait_time = request_wait_time()
2022-07-05 02:12:54 +02:00
q.add_log_cmd(f"Updating {print_str} wait time to {wait_time}")
2022-03-02 11:44:39 +01:00
if wait_time is None:
return
2023-05-24 13:44:45 +02:00
param_data = create_scalar_double_parameter(
2022-03-02 11:44:39 +01:00
object_id=PL_PCDU_ID,
domain_id=0,
unique_id=param_id,
parameter=wait_time,
)
2023-05-24 13:44:45 +02:00
q.add_pus_tc(create_load_param_cmd(param_data))
2022-03-02 15:06:50 +01:00
2022-08-08 16:32:18 +02:00
def pack_failure_injection_cmd(q: DefaultPusQueueHelper, param_id: int, print_str: str):
2022-07-04 17:59:09 +02:00
q.add_log_cmd(f"Inserting {print_str} error")
2023-05-24 13:44:45 +02:00
param_data = create_scalar_boolean_parameter(
2022-03-04 10:44:55 +01:00
object_id=PL_PCDU_ID, domain_id=0, unique_id=param_id, parameter=True
2022-03-02 15:06:50 +01:00
)
2023-05-24 13:44:45 +02:00
q.add_pus_tc(create_load_param_cmd(param_data))
2022-08-08 16:32:18 +02:00
def pack_pl_pcdu_mode_cmd(
2023-01-16 15:05:33 +01:00
q: DefaultPusQueueHelper, info: str, mode: Mode, submode: int
2022-08-08 16:32:18 +02:00
):
2022-07-04 17:59:09 +02:00
q.add_log_cmd(info)
mode_data = pack_mode_data(object_id=PL_PCDU_ID, mode=mode, submode=submode)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(
PusTelecommand(
2023-01-17 18:37:16 +01:00
service=200, subservice=Subservice.TC_MODE_COMMAND, app_data=mode_data
2022-07-04 17:59:09 +02:00
)
)
2023-02-01 16:25:17 +01:00
ADC_CHANNELS_NAMED = [
2023-02-10 15:03:24 +01:00
"U BAT DIV 6 [V]",
"U NEG V FB [V]",
"I HPA [mA]",
"U HPA DIV 6 [V]",
"I MPA [mA]",
"U MPA DIV 6 [V]",
"I TX [mA]",
"U TX DIV 6 [V]",
"I X8 [mA]",
"U X8 DIV 6 [V]",
"I DRO [mA]",
"U DRO DIV 6 [V]",
2023-02-01 16:25:17 +01:00
]
2023-05-24 13:44:45 +02:00
def handle_plpcdu_hk(pw: PrintWrapper, set_id: int, hk_data: bytes):
2023-02-01 16:25:17 +01:00
if set_id == SetId.ADC:
current_idx = 0
pw.dlog("Received PL PCDU ADC HK data")
channels = []
ch_print = "Channels Raw (hex): ["
for i in range(12):
channels.append(
struct.unpack("!H", hk_data[current_idx : current_idx + 2])[0]
)
if i < 11:
ch_print += f"{channels[i]:06x},"
else:
ch_print += f"{channels[i]:06x}]"
current_idx += 2
processed_vals = []
for i in range(12):
processed_vals.append(
struct.unpack("!f", hk_data[current_idx : current_idx + 4])[0]
)
current_idx += 4
temp = struct.unpack("!f", hk_data[current_idx : current_idx + 4])[0]
current_idx += 4
pw.dlog(f"Temperature: {temp} C")
pw.dlog(ch_print)
for i in range(12):
pw.dlog(f"{ADC_CHANNELS_NAMED[i].ljust(24)} | {processed_vals[i]}")
2023-05-24 13:44:45 +02:00
FsfwTmTcPrinter.get_validity_buffer(
validity_buffer=hk_data[current_idx:], num_vars=3
)
2023-10-23 16:30:16 +02:00
def dev_select_prompt(skip_ssr: bool) -> DevSelect:
while True:
for dev in DevSelect:
if skip_ssr and dev == DevSelect.SSR_NEG_V:
continue
print(f"{dev}: {dev.name}")
dev_select = int(input("Select device by index: "))
try:
return DevSelect(dev_select)
except IndexError:
_LOGGER.warn("Invalid paramter index, try again.")
continue
2023-10-23 17:16:23 +02:00
def dev_select_to_upper_i_update_param_id(dev_select: DevSelect) -> ParamId:
2023-10-23 16:30:16 +02:00
param_id = None
if dev_select == DevSelect.DRO:
param_id = ParamId.DRO_I_UPPER_BOUND
elif dev_select == DevSelect.X8:
param_id = ParamId.X8_I_UPPER_BOUND
elif dev_select == DevSelect.TX:
param_id = ParamId.TX_I_UPPER_BOUND
elif dev_select == DevSelect.MPA:
param_id = ParamId.MPA_I_UPPER_BOUND
2023-10-23 17:16:23 +02:00
elif dev_select == DevSelect.HPA:
2023-10-23 16:30:16 +02:00
param_id = ParamId.HPA_I_UPPER_BOUND
if param_id is None:
raise ValueError("invalid parameter ID")
return param_id
def dev_select_to_lower_u_update_param_id(dev_select: DevSelect) -> ParamId:
param_id = None
if dev_select == DevSelect.SSR_NEG_V:
param_id = ParamId.NEG_V_LOWER_BOUND
if dev_select == DevSelect.DRO:
param_id = ParamId.DRO_U_LOWER_BOUND
elif dev_select == DevSelect.X8:
param_id = ParamId.X8_U_LOWER_BOUND
elif dev_select == DevSelect.TX:
param_id = ParamId.TX_U_LOWER_BOUND
elif dev_select == DevSelect.MPA:
param_id = ParamId.MPA_U_LOWER_BOUND
2023-10-23 17:16:23 +02:00
elif dev_select == DevSelect.HPA:
2023-10-23 16:30:16 +02:00
param_id = ParamId.HPA_U_LOWER_BOUND
if param_id is None:
raise ValueError("invalid parameter ID")
return param_id
def dev_select_to_upper_u_update_param_id(dev_select: DevSelect) -> ParamId:
param_id = None
if dev_select == DevSelect.SSR_NEG_V:
param_id = ParamId.NEG_V_UPPER_BOUND
if dev_select == DevSelect.DRO:
param_id = ParamId.DRO_U_UPPER_BOUND
elif dev_select == DevSelect.X8:
param_id = ParamId.X8_U_UPPER_BOUND
elif dev_select == DevSelect.TX:
param_id = ParamId.TX_U_UPPER_BOUND
elif dev_select == DevSelect.MPA:
param_id = ParamId.MPA_U_UPPER_BOUND
2023-10-23 17:16:23 +02:00
elif dev_select == DevSelect.HPA:
2023-10-23 16:30:16 +02:00
param_id = ParamId.HPA_U_UPPER_BOUND
if param_id is None:
raise ValueError("invalid parameter ID")
return param_id
2023-11-27 12:01:03 +01:00
def prompt_custom_normal_submode() -> int:
print("Prompting custom submode.")
submode = 0
def prompt_channel(submode: int, channel_str: str, mask: NormalSubmodesMask) -> int:
while True:
channel_on = input(f" {channel_str} ON? [y/n]: ")
if channel_on in ["y", "1", "yes"]:
submode |= 1 << mask
elif channel_on in ["n", "0", "no"]:
2023-11-27 12:18:39 +01:00
pass
2023-11-27 12:01:03 +01:00
else:
_LOGGER.warning("invalid input, try again")
continue
2023-11-27 12:18:39 +01:00
break
2023-11-27 12:01:03 +01:00
return submode
submode = prompt_channel(
submode, "SSR", NormalSubmodesMask.SOLID_STATE_RELAYS_ADC_ON
)
submode = prompt_channel(submode, "DRO", NormalSubmodesMask.DRO_ON)
submode = prompt_channel(submode, "X8", NormalSubmodesMask.X8_ON)
2023-11-27 12:18:39 +01:00
submode = prompt_channel(submode, "TX", NormalSubmodesMask.TX_ON)
2023-11-27 12:01:03 +01:00
submode = prompt_channel(submode, "MPA", NormalSubmodesMask.MPA_ON)
submode = prompt_channel(submode, "HPA", NormalSubmodesMask.HPA_ON)
return submode