eive-tmtc/eive_tmtc/tmtc/com/pdec_handler.py

103 lines
3.2 KiB
Python
Raw Normal View History

2021-11-24 15:56:25 +01:00
# -*- coding: utf-8 -*-
"""
@file pdec_handler.py
@brief Test commanding of PDEC Handler
@author J. Meier
@date 22.11.2021
"""
from spacepackets.ecss.tc import PusTelecommand
2022-08-08 16:32:18 +02:00
from tmtccmd.tc import DefaultPusQueueHelper
2021-11-24 15:56:25 +01:00
2023-02-22 14:50:12 +01:00
from tmtccmd.tc.pus_20_fsfw_param import (
create_load_param_cmd
)
from tmtccmd.pus.s20_fsfw_param_defs import (
create_scalar_u8_parameter
)
from tmtccmd.config.tmtc import (
tmtc_definitions_provider,
TmtcDefinitionWrapper,
OpCodeEntry,
)
from eive_tmtc.config.definitions import CustomServiceList
2021-11-24 15:56:25 +01:00
2023-01-16 14:13:06 +01:00
class CommandId:
2021-11-24 15:56:25 +01:00
# prints the clcw to the console. Useful for debugging
2022-01-18 11:57:58 +01:00
PRINT_CLCW = bytearray([0x0, 0x0, 0x0, 0x0])
# Print PDEC monitor register
PRINT_PDEC_MON = bytearray([0x0, 0x0, 0x0, 0x1])
2021-11-24 15:56:25 +01:00
2023-02-22 14:50:12 +01:00
class ParameterId:
POSITIVE_WINDOW = 0
NEGATIVE_WINDOW = 1
class OpCode:
PRINT_CLCW = "print_clcw"
PRINT_MON_REG = "print_mon_reg"
POSITIVE_WINDOW = "positive_window"
NEGATIVE_WINDOW = "negative_window"
class Info:
PRINT_CLCW = "Will cause the OBSW to print the current CLCW to the debug console"
PRINT_MON_REG = "Will cause the OBSW to print the PDEC monitor register to the console"
POSITIVE_WINDOW = "Change positive window parameter for AD frames"
NEGATIVE_WINDOW = "Change negative window parameter for AD frames"
2022-08-08 16:32:18 +02:00
def pack_pdec_handler_test(
object_id: bytearray, q: DefaultPusQueueHelper, op_code: str
):
2022-07-04 15:22:53 +02:00
q.add_log_cmd(f"Testing PDEC handler with object id: {object_id.hex()}")
2023-02-22 14:50:12 +01:00
prefix = "PDEC Handler "
if op_code == OpCode.PRINT_CLCW:
q.add_log_cmd(f"{prefix}: {Info.PRINT_CLCW}")
2023-01-16 14:13:06 +01:00
command = object_id + CommandId.PRINT_CLCW
2022-07-04 15:22:53 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2023-02-22 14:50:12 +01:00
if op_code == OpCode.PRINT_MON_REG:
q.add_log_cmd(f"{prefix}: {Info.PRINT_MON_REG}")
2023-01-16 14:13:06 +01:00
command = object_id + CommandId.PRINT_PDEC_MON
2022-07-04 15:22:53 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2023-02-22 14:50:12 +01:00
if op_code == OpCode.POSITIVE_WINDOW:
q.add_log_cmd(f"{prefix}: {Info.POSITIVE_WINDOW}")
pw = int(input("Specify positive window to set: "))
q.add_pus_tc(
create_load_param_cmd(
create_scalar_u8_parameter(
object_id,
0,
ParameterId.POSITIVE_WINDOW,
pw,
).pack()
)
)
if op_code == OpCode.NEGATIVE_WINDOW:
q.add_log_cmd(f"{prefix}: {Info.NEGATIVE_WINDOW}")
nw = int(input("Specify negative window to set: "))
q.add_pus_tc(
create_load_param_cmd(
create_scalar_u8_parameter(
object_id,
0,
ParameterId.NEGATIVE_WINDOW,
nw,
).pack()
)
)
2023-02-22 14:50:12 +01:00
@tmtc_definitions_provider
def add_pdec_cmds(defs: TmtcDefinitionWrapper):
oce = OpCodeEntry()
oce.add(OpCode.PRINT_CLCW, Info.PRINT_CLCW)
oce.add(OpCode.PRINT_MON_REG, Info.PRINT_MON_REG)
oce.add(OpCode.POSITIVE_WINDOW, Info.POSITIVE_WINDOW)
oce.add(OpCode.NEGATIVE_WINDOW, Info.NEGATIVE_WINDOW)
defs.add_service(CustomServiceList.PDEC_HANDLER.value, "PDEC Handler", oce)