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

141 lines
5.2 KiB
Python
Raw Permalink Normal View History

2023-01-27 15:42:00 +01:00
import enum
from tmtccmd.config.tmtc import (
2023-11-22 13:51:33 +01:00
CmdTreeNode,
2023-01-27 15:42:00 +01:00
)
2023-11-22 13:51:33 +01:00
from tmtccmd.pus.s20_fsfw_param import (
create_load_param_cmd,
create_scalar_u32_parameter,
)
from tmtccmd.pus.s20_fsfw_param_defs import create_scalar_u8_parameter
2023-11-10 19:23:06 +01:00
from tmtccmd.pus.s200_fsfw_mode import (
2023-02-08 11:51:55 +01:00
create_announce_mode_command,
create_announce_mode_recursive_command,
2023-11-22 13:51:33 +01:00
create_mode_command,
create_read_mode_command,
2023-02-08 11:51:55 +01:00
)
2023-11-22 13:51:33 +01:00
from tmtccmd.tmtc import DefaultPusQueueHelper
2023-01-28 14:30:51 +01:00
2023-11-22 13:51:33 +01:00
from eive_tmtc.config.object_ids import COM_SUBSYSTEM_ID
from eive_tmtc.tmtc.com.syrlinks_handler import Datarate
from .defs import Mode as ComMode
2023-01-28 14:30:51 +01:00
class ParameterId(enum.IntEnum):
DATARATE = 0
TRANSMITTER_TIMEOUT = 1
2023-01-27 15:42:00 +01:00
class OpCode:
RX_ONLY = "rx_only"
2023-01-27 20:23:41 +01:00
TX_AND_RX_DEF_RATE = "rx_and_tx_default_rate"
2023-01-27 15:42:00 +01:00
TX_AND_RX_LOW_RATE = "rx_and_tx_low_rate"
TX_AND_RX_HIGH_RATE = "rx_and_tx_high_rate"
TX_AND_RX_CARRIER_WAVE = "rx_and_tx_carrier_wave"
2023-01-28 14:30:51 +01:00
UPDATE_DEFAULT_DATARATE_LOW = "update_default_rate_low"
UPDATE_DEFAULT_DATARATE_HIGH = "update_default_rate_high"
CHANGE_TRANSMITTER_TIMEOUT = "change_transmitter_timeout"
2023-02-08 01:29:38 +01:00
READ_MODE = "read_mode"
ANNOUNCE_MODE = "announce_mode"
ANNOUNCE_MODE_RECURSIVE = "announce_mode_recursive"
2023-01-27 15:42:00 +01:00
class Info:
RX_ONLY = "Syrlinks RX Only"
2023-11-22 13:51:33 +01:00
TX_AND_RX_DEF_RATE = "Syrlinks with TX default datarate"
TX_AND_RX_LOW_RATE = "Syrlinks with TX low datarate (BPSK modulation)"
TX_AND_RX_HIGH_RATE = "Syrlinks with TX high datarate (0QPSK modulation)"
2023-01-27 15:42:00 +01:00
TX_AND_RX_CARRIER_WAVE = "Syrlinks with TX carrier wave"
2023-01-28 14:30:51 +01:00
UPDATE_DEFAULT_DATARATE_LOW = "Configure default low datarate (BPSK modulation)"
UPDATE_DEFAULT_DATARATE_HIGH = "Configure default high datarate (0QPSK modulation)"
CHANGE_TRANSMITTER_TIMEOUT = "Changes the transmitter timeout"
2023-02-08 01:29:38 +01:00
READ_MODE = "Read Mode"
2023-02-08 11:51:55 +01:00
ANNOUNCE_MODE = "Announce Mode"
2023-02-08 01:29:38 +01:00
ANNOUNCE_MODE_RECURSIVE = "Announce mode recursively"
2023-01-27 15:42:00 +01:00
2023-11-22 19:38:04 +01:00
def build_com_subsystem_procedure(q: DefaultPusQueueHelper, cmd_str: str): # noqa C901
2023-01-28 14:30:51 +01:00
prefix = "COM Subsystem"
2023-11-22 13:51:33 +01:00
if cmd_str == OpCode.RX_ONLY:
2023-01-27 15:42:00 +01:00
q.add_log_cmd(Info.RX_ONLY)
2023-03-26 20:00:34 +02:00
q.add_pus_tc(create_mode_command(COM_SUBSYSTEM_ID, ComMode.RX_ONLY, 0))
2023-11-22 13:51:33 +01:00
elif cmd_str == OpCode.TX_AND_RX_DEF_RATE:
2023-11-22 19:38:04 +01:00
q.add_log_cmd(Info.TX_AND_RX_DEF_RATE)
2023-01-27 20:23:41 +01:00
q.add_pus_tc(
2023-03-26 20:00:34 +02:00
create_mode_command(COM_SUBSYSTEM_ID, ComMode.RX_AND_TX_DEF_DATARATE, 0)
2023-01-27 20:23:41 +01:00
)
2023-11-22 13:51:33 +01:00
elif cmd_str == OpCode.TX_AND_RX_LOW_RATE:
2023-11-22 19:38:04 +01:00
q.add_log_cmd(Info.TX_AND_RX_LOW_RATE)
2023-01-27 15:42:00 +01:00
q.add_pus_tc(
2023-03-26 20:00:34 +02:00
create_mode_command(COM_SUBSYSTEM_ID, ComMode.RX_AND_TX_LOW_DATARATE, 0)
2023-01-27 15:42:00 +01:00
)
2023-11-22 13:51:33 +01:00
elif cmd_str == OpCode.TX_AND_RX_HIGH_RATE:
2023-11-22 19:38:04 +01:00
q.add_log_cmd(Info.TX_AND_RX_HIGH_RATE)
2023-01-27 15:42:00 +01:00
q.add_pus_tc(
2023-03-26 20:00:34 +02:00
create_mode_command(COM_SUBSYSTEM_ID, ComMode.RX_AND_TX_HIGH_DATARATE, 0)
2023-01-27 15:42:00 +01:00
)
2023-11-22 13:51:33 +01:00
if cmd_str == OpCode.UPDATE_DEFAULT_DATARATE_LOW:
2023-01-28 14:30:51 +01:00
q.add_log_cmd(f"{prefix}: {Info.UPDATE_DEFAULT_DATARATE_LOW}")
q.add_pus_tc(
create_load_param_cmd(
2023-09-12 13:35:26 +02:00
create_scalar_u8_parameter(
2023-01-28 14:30:51 +01:00
COM_SUBSYSTEM_ID,
0,
ParameterId.DATARATE,
Datarate.LOW_RATE_MODULATION_BPSK,
)
)
)
2023-11-22 13:51:33 +01:00
if cmd_str == OpCode.UPDATE_DEFAULT_DATARATE_HIGH:
2023-01-28 14:30:51 +01:00
q.add_log_cmd(f"{prefix}: {Info.UPDATE_DEFAULT_DATARATE_HIGH}")
q.add_pus_tc(
create_load_param_cmd(
2023-09-12 13:35:26 +02:00
create_scalar_u8_parameter(
2023-01-28 14:30:51 +01:00
COM_SUBSYSTEM_ID,
0,
ParameterId.DATARATE,
Datarate.HIGH_RATE_MODULATION_0QPSK,
)
)
)
2023-11-22 13:51:33 +01:00
elif cmd_str == OpCode.TX_AND_RX_CARRIER_WAVE:
2023-01-27 15:42:00 +01:00
q.add_log_cmd(Info.TX_AND_RX_CARRIER_WAVE)
q.add_pus_tc(
2023-03-26 20:00:34 +02:00
create_mode_command(COM_SUBSYSTEM_ID, ComMode.RX_AND_TX_CARRIER_WAVE, 0)
2023-01-27 15:42:00 +01:00
)
2023-11-22 13:51:33 +01:00
elif cmd_str == OpCode.CHANGE_TRANSMITTER_TIMEOUT:
timeout = int(input("Specify timeout to set [ms]: "))
q.add_log_cmd(Info.CHANGE_TRANSMITTER_TIMEOUT)
q.add_pus_tc(
create_load_param_cmd(
create_scalar_u32_parameter(
COM_SUBSYSTEM_ID,
0,
ParameterId.TRANSMITTER_TIMEOUT,
timeout,
2023-09-12 13:35:26 +02:00
)
)
)
2023-11-22 13:51:33 +01:00
elif cmd_str == OpCode.READ_MODE:
2023-02-08 01:29:38 +01:00
q.add_log_cmd(Info.READ_MODE)
q.add_pus_tc(create_read_mode_command(COM_SUBSYSTEM_ID))
2023-11-22 13:51:33 +01:00
elif cmd_str == OpCode.ANNOUNCE_MODE:
2023-02-08 01:29:38 +01:00
q.add_log_cmd(Info.ANNOUNCE_MODE)
q.add_pus_tc(create_announce_mode_command(COM_SUBSYSTEM_ID))
2023-11-22 13:51:33 +01:00
elif cmd_str == OpCode.ANNOUNCE_MODE_RECURSIVE:
2023-02-08 01:29:38 +01:00
q.add_log_cmd(Info.ANNOUNCE_MODE_RECURSIVE)
q.add_pus_tc(create_announce_mode_recursive_command(COM_SUBSYSTEM_ID))
2023-01-27 15:42:00 +01:00
2023-11-22 13:51:33 +01:00
def create_com_subsystem_node() -> CmdTreeNode:
op_code_strs = [
getattr(OpCode, key) for key in dir(OpCode) if not key.startswith("__")
]
info_strs = [getattr(Info, key) for key in dir(OpCode) if not key.startswith("__")]
combined_dict = dict(zip(op_code_strs, info_strs))
node = CmdTreeNode("com", "COM Subsystem", hide_children_which_are_leaves=True)
2023-11-22 13:51:33 +01:00
for op_code, info in combined_dict.items():
node.add_child(CmdTreeNode(op_code, info))
return node