eive-tmtc/eive_tmtc/tmtc/syrlinks_hk_handler.py

250 lines
9.9 KiB
Python
Raw Normal View History

2021-02-27 13:09:55 +01:00
# -*- coding: utf-8 -*-
"""
2021-05-17 18:08:43 +02:00
@file syrlinks_hk_handler.py
2021-02-27 13:42:41 +01:00
@brief Syrlinks Hk Handler tests
2021-02-27 13:09:55 +01:00
@author J. Meier
@date 13.12.2020
"""
2023-01-16 14:13:06 +01:00
import enum
2023-01-18 15:43:02 +01:00
from eive_tmtc.pus_tm.defs import PrintWrapper
2022-11-29 16:53:29 +01:00
from eive_tmtc.config.definitions import CustomServiceList
from tmtccmd.config.tmtc import (
tmtc_definitions_provider,
TmtcDefinitionWrapper,
OpCodeEntry,
)
2022-08-08 16:32:18 +02:00
from tmtccmd.tc import DefaultPusQueueHelper
2023-01-18 15:36:09 +01:00
from tmtccmd.tc.pus_3_fsfw_hk import (
make_sid,
create_request_one_diag_command,
)
2021-12-02 09:25:31 +01:00
from spacepackets.ecss.tc import PusTelecommand
2023-01-16 15:05:33 +01:00
from tmtccmd.tc.pus_200_fsfw_modes import pack_mode_data, Mode
2022-03-31 11:36:50 +02:00
import struct
2021-02-27 13:09:55 +01:00
2022-07-08 16:25:46 +02:00
from tmtccmd.util import ObjectIdU32
2023-01-18 15:43:02 +01:00
from tmtccmd.util.tmtc_printer import FsfwTmTcPrinter
2022-07-04 17:59:09 +02:00
2021-02-27 13:09:55 +01:00
2023-01-16 14:13:06 +01:00
class SetId:
2021-03-01 12:14:04 +01:00
RX_REGISTERS_DATASET = 1
TX_REGISTERS_DATASET = 2
2023-01-18 15:36:09 +01:00
TEMPERATURE_SET_ID = 3
2021-02-27 13:09:55 +01:00
2023-01-16 14:13:06 +01:00
class OpCode:
OFF = "off"
ON = "on"
NORMAL = "nml"
2023-01-10 10:27:00 +01:00
STANDBY = "set_tx_standby"
SET_CW = "set_tx_carrier_wave"
MODULATION = "modulation"
2023-01-10 10:27:00 +01:00
HK_RX_REGS = "hk_rx_regs"
HK_TX_REGS = "hk_tx_regs"
TX_STATUS = "tx_status"
RX_STATUS = "rx_status"
class Info:
HK_RX_REGS = "Request RX register set"
HK_TX_REGS = "Request TX register set"
TX_STATUS = "Read TX status (always read in normal mode)"
RX_STATUS = "Read RX status (always read in normal mode)"
SET_CW = "Set TX carrier wave"
2022-05-27 14:29:56 +02:00
2023-01-16 14:13:06 +01:00
class CommandId(enum.IntEnum):
2022-04-04 15:05:38 +02:00
READ_RX_STATUS_REGISTERS = 2
SET_TX_MODE_STANDBY = 3
SET_TX_MODE_MODULATION = 4
SET_TX_MODE_CW = 5
READ_TX_STATUS = 7
READ_TX_WAVEFORM = 8
READ_TX_AGC_VALUE_HIGH_BYTE = 9
READ_TX_AGC_VALUE_LOW_BYTE = 10
2022-03-31 11:36:50 +02:00
WRITE_LCL_CONFIG = 11
READ_LCL_CONFIG_REGISTER = 12
2022-04-04 15:05:38 +02:00
SET_WAVEFORM_OQPSK = 17
SET_WAVEFORM_BPSK = 18
SET_SECOND_CONFIG = 19
ENABLE_DEBUG = 20
2022-04-05 08:42:38 +02:00
DISABLE_DEBUG = 21
2021-02-27 13:09:55 +01:00
2021-12-02 09:25:31 +01:00
@tmtc_definitions_provider
def add_syrlinks_cmds(defs: TmtcDefinitionWrapper):
oce = OpCodeEntry()
2023-01-16 14:13:06 +01:00
oce.add(OpCode.OFF, "Syrlinks Handler: Set mode off")
oce.add(OpCode.ON, "Syrlinks Handler: Set mode on")
oce.add(OpCode.NORMAL, "Syrlinks Handler: Set mode normal")
oce.add(OpCode.STANDBY, "Syrlinks Handler: Set TX standby")
oce.add(OpCode.MODULATION, "Syrlinks Handler: Set TX modulation")
oce.add(OpCode.HK_RX_REGS, Info.HK_RX_REGS)
oce.add(OpCode.HK_TX_REGS, Info.HK_TX_REGS)
oce.add(OpCode.SET_CW, Info.SET_CW)
oce.add(OpCode.TX_STATUS, Info.TX_STATUS)
oce.add(OpCode.RX_STATUS, Info.RX_STATUS)
oce.add("7", "Syrlinks Handler: Read TX waveform")
oce.add("8", "Syrlinks Handler: Read TX AGC value high byte")
oce.add("9", "Syrlinks Handler: Read TX AGC value low byte")
oce.add("12", "Syrlinks Handler: Write LCL config")
oce.add("14", "Syrlinks Handler: Read LCL config register")
oce.add("15", "Syrlinks Handler: Set waveform OQPSK")
oce.add("16", "Syrlinks Handler: Set waveform BPSK")
oce.add("17", "Syrlinks Handler: Set second config")
oce.add("18", "Syrlinks Handler: Enable debug output")
oce.add("19", "Syrlinks Handler: Disable debug output")
defs.add_service(CustomServiceList.SYRLINKS.value, "Syrlinks Handler", oce)
2022-08-08 16:32:18 +02:00
def pack_syrlinks_command(
object_id: ObjectIdU32, q: DefaultPusQueueHelper, op_code: str
):
2022-07-04 17:59:09 +02:00
obyt = object_id.as_bytes
2023-01-10 10:27:00 +01:00
prefix = "Syrlinks"
2022-07-04 17:59:09 +02:00
q.add_log_cmd(f"Testing Syrlinks with object id: {object_id.as_hex_string}")
2023-01-16 14:13:06 +01:00
if op_code == OpCode.OFF:
2023-01-10 10:27:00 +01:00
q.add_log_cmd(f"{prefix}: Set mode off")
2023-01-16 15:05:33 +01:00
data = pack_mode_data(obyt, Mode.OFF, 0)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=data))
2023-01-16 14:13:06 +01:00
if op_code == OpCode.ON:
2023-01-10 10:27:00 +01:00
q.add_log_cmd(f"{prefix}: Set mode on")
2023-01-16 15:05:33 +01:00
data = pack_mode_data(obyt, Mode.ON, 0)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=data))
2023-01-16 14:13:06 +01:00
if op_code == OpCode.NORMAL:
2023-01-10 10:27:00 +01:00
q.add_log_cmd(f"{prefix}: Mode Normal")
2023-01-16 15:05:33 +01:00
data = pack_mode_data(obyt, Mode.NORMAL, 0)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=data))
2023-01-16 14:13:06 +01:00
if op_code == OpCode.STANDBY:
2023-01-10 10:27:00 +01:00
q.add_log_cmd(f"{prefix}: Set TX mode standby")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", CommandId.SET_TX_MODE_STANDBY)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-01-16 14:13:06 +01:00
if op_code == OpCode.MODULATION:
2023-01-10 10:27:00 +01:00
q.add_log_cmd(f"{prefix}: Set TX mode modulation")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", CommandId.SET_TX_MODE_MODULATION)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-01-16 14:13:06 +01:00
if op_code in OpCode.SET_CW:
2023-01-10 10:27:00 +01:00
q.add_log_cmd(f"{prefix}: {Info.SET_CW}")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", CommandId.SET_TX_MODE_CW)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-01-16 14:13:06 +01:00
if op_code in OpCode.HK_RX_REGS:
2023-01-10 10:27:00 +01:00
q.add_log_cmd(f"{prefix}: {Info.HK_RX_REGS}")
2023-01-16 14:13:06 +01:00
sid = make_sid(obyt, SetId.RX_REGISTERS_DATASET)
2023-01-18 15:36:09 +01:00
q.add_pus_tc(create_request_one_diag_command(sid))
2023-01-16 14:13:06 +01:00
if op_code in OpCode.HK_TX_REGS:
2023-01-10 10:27:00 +01:00
q.add_log_cmd(f"{prefix}: {Info.HK_TX_REGS}")
2023-01-16 14:13:06 +01:00
sid = make_sid(obyt, SetId.TX_REGISTERS_DATASET)
2023-01-18 15:36:09 +01:00
q.add_pus_tc(create_request_one_diag_command(sid))
2023-01-16 14:13:06 +01:00
if op_code in OpCode.TX_STATUS:
2023-01-10 10:27:00 +01:00
q.add_log_cmd(f"{prefix}: {Info.TX_STATUS}")
2023-01-16 14:13:06 +01:00
command = obyt + struct.pack("!I", CommandId.READ_TX_STATUS)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2022-03-29 07:03:13 +02:00
if op_code == "9":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Syrlinks: Read TX waveform")
2023-01-16 14:13:06 +01:00
command = obyt + struct.pack("!I", CommandId.READ_TX_WAVEFORM)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2022-03-29 07:03:13 +02:00
if op_code == "10":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Syrlinks: Read TX AGC value high byte")
2023-01-16 14:13:06 +01:00
command = obyt + struct.pack("!I", CommandId.READ_TX_AGC_VALUE_HIGH_BYTE)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2022-03-29 07:03:13 +02:00
if op_code == "11":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Syrlinks: Read TX AGC value low byte")
2023-01-16 14:13:06 +01:00
command = obyt + struct.pack("!I", CommandId.READ_TX_AGC_VALUE_LOW_BYTE)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2022-03-31 11:36:50 +02:00
if op_code == "12":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Syrlinks: Write LCL config")
2023-01-16 14:13:06 +01:00
command = obyt + struct.pack("!I", CommandId.WRITE_LCL_CONFIG)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2022-03-31 11:36:50 +02:00
if op_code == "13":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Syrlinks: Read RX status registers")
2023-01-16 14:13:06 +01:00
command = obyt + struct.pack("!I", CommandId.READ_RX_STATUS_REGISTERS)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2022-03-31 11:36:50 +02:00
if op_code == "14":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Syrlinks: Read LCL config register")
2023-01-16 14:13:06 +01:00
command = obyt + struct.pack("!I", CommandId.READ_LCL_CONFIG_REGISTER)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2022-04-04 15:05:38 +02:00
if op_code == "15":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Syrlinks: Set waveform OQPSK")
2023-01-16 14:13:06 +01:00
command = obyt + struct.pack("!I", CommandId.SET_WAVEFORM_OQPSK)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2022-04-04 15:05:38 +02:00
if op_code == "16":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Syrlinks: Set waveform BPSK")
2023-01-16 14:13:06 +01:00
command = obyt + struct.pack("!I", CommandId.SET_WAVEFORM_BPSK)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2022-04-04 15:05:38 +02:00
if op_code == "17":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Syrlinks: Set second config")
2023-01-16 14:13:06 +01:00
command = obyt + struct.pack("!I", CommandId.SET_SECOND_CONFIG)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2022-04-04 15:05:38 +02:00
if op_code == "18":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Syrlinks: Enable debug printout")
2023-01-16 14:13:06 +01:00
command = obyt + struct.pack("!I", CommandId.ENABLE_DEBUG)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2022-04-04 15:05:38 +02:00
if op_code == "19":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Syrlinks: Disable debug printout")
2023-01-16 14:13:06 +01:00
command = obyt + struct.pack("!I", CommandId.DISABLE_DEBUG)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2023-01-18 15:43:02 +01:00
def handle_syrlinks_hk_data(printer: FsfwTmTcPrinter, set_id: int, hk_data: bytes):
if set_id == SetId.RX_REGISTERS_DATASET:
return handle_syrlinks_rx_registers_dataset(printer, hk_data)
elif set_id == SetId.TX_REGISTERS_DATASET:
return handle_syrlinks_tx_registers_dataset(printer, hk_data)
else:
pw = PrintWrapper(printer)
pw.dlog(f"Service 3 TM: Syrlinks handler reply with unknown set ID {set_id}")
def handle_syrlinks_rx_registers_dataset(printer: FsfwTmTcPrinter, hk_data: bytes):
pw = PrintWrapper(printer)
header_list = [
"RX Status",
"RX Sensitivity",
"RX Frequency Shift",
"RX IQ Power",
"RX AGC Value",
"RX Demod Eb",
"RX Demod N0",
"RX Datarate",
]
rx_status = hk_data[0]
2023-01-18 15:52:35 +01:00
rx_sensitivity = struct.unpack("!I", hk_data[1:5])[0]
rx_frequency_shift = struct.unpack("!I", hk_data[5:9])[0]
rx_iq_power = struct.unpack("!H", hk_data[9:11])[0]
rx_agc_value = struct.unpack("!H", hk_data[11:13])[0]
rx_demod_eb = struct.unpack("!I", hk_data[13:17])[0]
rx_demod_n0 = struct.unpack("!I", hk_data[17:21])[0]
2023-01-18 15:43:02 +01:00
rx_data_rate = hk_data[21]
content_list = [
rx_status,
rx_sensitivity,
rx_frequency_shift,
rx_iq_power,
rx_agc_value,
rx_demod_eb,
rx_demod_n0,
rx_data_rate,
]
validity_buffer = hk_data[22:]
2023-01-18 15:52:35 +01:00
for header, content in zip(header_list, content_list):
pw.dlog(f"{header}: {content}")
2023-01-18 15:43:02 +01:00
printer.print_validity_buffer(validity_buffer=validity_buffer, num_vars=8)
def handle_syrlinks_tx_registers_dataset(
printer: FsfwTmTcPrinter,
hk_data: bytes,
):
pw = PrintWrapper(printer)
header_list = ["TX Status", "TX Waveform", "TX AGC value"]
tx_status = hk_data[0]
tx_waveform = hk_data[1]
tx_agc_value = struct.unpack("!H", hk_data[2:4])
content_list = [tx_status, tx_waveform, tx_agc_value]
validity_buffer = hk_data[4:]
2023-01-18 15:52:35 +01:00
for header, content in zip(header_list, content_list):
pw.dlog(f"{header}: {content}")
2023-01-18 15:43:02 +01:00
printer.print_validity_buffer(validity_buffer=validity_buffer, num_vars=3)