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
|
|
|
|
"""
|
2023-04-14 19:21:51 +02:00
|
|
|
import enum
|
|
|
|
|
2021-11-24 15:56:25 +01:00
|
|
|
from spacepackets.ecss.tc import PusTelecommand
|
2023-11-10 19:23:06 +01:00
|
|
|
from tmtccmd.tmtc import DefaultPusQueueHelper
|
2021-11-24 15:56:25 +01:00
|
|
|
|
2023-11-10 19:23:06 +01:00
|
|
|
from tmtccmd.pus.s20_fsfw_param import create_load_param_cmd
|
|
|
|
from tmtccmd.pus.s8_fsfw_action import create_action_cmd
|
2023-03-02 14:41:23 +01:00
|
|
|
from tmtccmd.pus.s20_fsfw_param_defs import create_scalar_u8_parameter
|
2023-02-22 14:50:12 +01:00
|
|
|
|
|
|
|
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])
|
2021-12-02 12:07:16 +01:00
|
|
|
# Print PDEC monitor register
|
|
|
|
PRINT_PDEC_MON = bytearray([0x0, 0x0, 0x0, 0x1])
|
2021-11-24 15:56:25 +01:00
|
|
|
|
|
|
|
|
2023-04-14 19:21:51 +02:00
|
|
|
class ParameterId(enum.IntEnum):
|
2023-02-22 14:50:12 +01:00
|
|
|
POSITIVE_WINDOW = 0
|
|
|
|
NEGATIVE_WINDOW = 1
|
|
|
|
|
|
|
|
|
2023-04-14 19:21:51 +02:00
|
|
|
class ActionId(enum.IntEnum):
|
|
|
|
RESET_NO_INIT = 2
|
|
|
|
RESET_WITH_INIT = 3
|
|
|
|
|
|
|
|
|
2023-02-22 14:50:12 +01:00
|
|
|
class OpCode:
|
|
|
|
PRINT_CLCW = "print_clcw"
|
|
|
|
PRINT_MON_REG = "print_mon_reg"
|
|
|
|
POSITIVE_WINDOW = "positive_window"
|
|
|
|
NEGATIVE_WINDOW = "negative_window"
|
2023-04-14 19:21:51 +02:00
|
|
|
RESET_WITH_INIT = "reset_with_init"
|
|
|
|
RESET_NO_INIT = "reset_no_init"
|
2023-02-22 14:50:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Info:
|
|
|
|
PRINT_CLCW = "Will cause the OBSW to print the current CLCW to the debug console"
|
2023-03-02 14:41:23 +01:00
|
|
|
PRINT_MON_REG = (
|
|
|
|
"Will cause the OBSW to print the PDEC monitor register to the console"
|
|
|
|
)
|
2023-02-22 14:50:12 +01:00
|
|
|
POSITIVE_WINDOW = "Change positive window parameter for AD frames"
|
|
|
|
NEGATIVE_WINDOW = "Change negative window parameter for AD frames"
|
2023-04-14 19:21:51 +02:00
|
|
|
RESET_WITH_INIT = "Reset with full initialization"
|
|
|
|
RESET_NO_INIT = "Reset with mandatory initialization"
|
2023-02-22 14:50:12 +01:00
|
|
|
|
|
|
|
|
2023-11-22 10:17:05 +01:00
|
|
|
def pack_pdec_handler_commands(
|
|
|
|
object_id: bytes, q: DefaultPusQueueHelper, cmd_str: str
|
2022-08-08 16:32:18 +02:00
|
|
|
):
|
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 "
|
2023-11-22 10:17:05 +01:00
|
|
|
if cmd_str == OpCode.PRINT_CLCW:
|
2023-02-22 14:50:12 +01:00
|
|
|
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-11-22 10:17:05 +01:00
|
|
|
if cmd_str == OpCode.PRINT_MON_REG:
|
2023-02-22 14:50:12 +01:00
|
|
|
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-11-22 10:17:05 +01:00
|
|
|
if cmd_str == OpCode.POSITIVE_WINDOW:
|
2023-02-22 14:50:12 +01:00
|
|
|
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,
|
2023-09-12 13:35:26 +02:00
|
|
|
)
|
2023-02-22 14:50:12 +01:00
|
|
|
)
|
|
|
|
)
|
2023-11-22 10:17:05 +01:00
|
|
|
if cmd_str == OpCode.NEGATIVE_WINDOW:
|
2023-02-23 15:20:46 +01:00
|
|
|
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,
|
2023-09-12 13:35:26 +02:00
|
|
|
)
|
2023-02-23 15:20:46 +01:00
|
|
|
)
|
|
|
|
)
|
2023-11-22 10:17:05 +01:00
|
|
|
if cmd_str == OpCode.RESET_NO_INIT:
|
2023-04-14 19:21:51 +02:00
|
|
|
q.add_log_cmd(f"{prefix}: {Info.RESET_NO_INIT}")
|
|
|
|
q.add_pus_tc(
|
|
|
|
create_action_cmd(object_id=object_id, action_id=ActionId.RESET_NO_INIT)
|
|
|
|
)
|
2023-11-22 10:17:05 +01:00
|
|
|
if cmd_str == OpCode.RESET_WITH_INIT:
|
2023-04-14 19:21:51 +02:00
|
|
|
q.add_log_cmd(f"{prefix}: {Info.RESET_WITH_INIT}")
|
|
|
|
q.add_pus_tc(
|
|
|
|
create_action_cmd(object_id=object_id, action_id=ActionId.RESET_WITH_INIT)
|
|
|
|
)
|
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)
|
2023-04-14 19:21:51 +02:00
|
|
|
oce.add(OpCode.RESET_WITH_INIT, Info.RESET_WITH_INIT)
|
|
|
|
oce.add(OpCode.RESET_NO_INIT, Info.RESET_NO_INIT)
|
2023-02-22 14:50:12 +01:00
|
|
|
defs.add_service(CustomServiceList.PDEC_HANDLER.value, "PDEC Handler", oce)
|