Merge branch 'introduce_tm_db' into bump-tmtccmd
All checks were successful
EIVE/-/pipeline/pr-main This commit looks good
All checks were successful
EIVE/-/pipeline/pr-main This commit looks good
This commit is contained in:
@ -8,32 +8,32 @@
|
||||
import enum
|
||||
import logging
|
||||
import math
|
||||
|
||||
from tmtccmd.config import CmdTreeNode
|
||||
|
||||
from eive_tmtc.pus_tm.defs import PrintWrapper
|
||||
from eive_tmtc.tmtc.com.defs import Mode as ComMode
|
||||
from eive_tmtc.config.definitions import CustomServiceList
|
||||
from tmtccmd.config.tmtc import (
|
||||
tmtc_definitions_provider,
|
||||
TmtcDefinitionWrapper,
|
||||
OpCodeEntry,
|
||||
)
|
||||
from tmtccmd.tmtc import DefaultPusQueueHelper
|
||||
from tmtccmd.pus.tc.s3_fsfw_hk import (
|
||||
make_sid,
|
||||
create_request_one_diag_command,
|
||||
create_request_one_hk_command,
|
||||
create_enable_periodic_hk_command_with_interval_with_diag,
|
||||
create_disable_periodic_hk_command_with_diag,
|
||||
)
|
||||
from spacepackets.ecss.tc import PusTelecommand
|
||||
from tmtccmd.pus.s200_fsfw_mode import Mode, create_mode_command
|
||||
from eive_tmtc.config.object_ids import SYRLINKS_HANDLER_ID
|
||||
import struct
|
||||
|
||||
from tmtccmd.util import ObjectIdU32
|
||||
from spacepackets.ecss.tc import PusTelecommand
|
||||
from tmtccmd.config.tmtc import (
|
||||
CmdTreeNode,
|
||||
OpCodeEntry,
|
||||
TmtcDefinitionWrapper,
|
||||
tmtc_definitions_provider,
|
||||
)
|
||||
from tmtccmd.fsfw.tmtc_printer import FsfwTmTcPrinter
|
||||
from tmtccmd.pus.s200_fsfw_mode import Mode, create_mode_command
|
||||
from tmtccmd.pus.tc.s3_fsfw_hk import (
|
||||
create_disable_periodic_hk_command_with_diag,
|
||||
create_enable_periodic_hk_command_with_interval_with_diag,
|
||||
create_request_one_diag_command,
|
||||
create_request_one_hk_command,
|
||||
make_sid,
|
||||
)
|
||||
from tmtccmd.tmtc import DefaultPusQueueHelper
|
||||
from tmtccmd.util import ObjectIdU32
|
||||
|
||||
from eive_tmtc.config.definitions import CustomServiceList
|
||||
from eive_tmtc.config.object_ids import SYRLINKS_HANDLER_ID
|
||||
from eive_tmtc.pus_tm.defs import PrintWrapper
|
||||
from eive_tmtc.pus_tm.hk import HkTmInfo
|
||||
from eive_tmtc.tmtc.com.defs import Mode as ComMode
|
||||
|
||||
|
||||
class SetId(enum.IntEnum):
|
||||
@ -273,18 +273,24 @@ def pack_syrlinks_command( # noqa C901: Complexity okay here.
|
||||
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
|
||||
|
||||
|
||||
def handle_syrlinks_hk_data(pw: PrintWrapper, set_id: int, hk_data: bytes):
|
||||
if set_id == SetId.RX_REGISTERS_DATASET:
|
||||
return handle_syrlinks_rx_registers_dataset(pw, hk_data)
|
||||
elif set_id == SetId.TX_REGISTERS_DATASET:
|
||||
return handle_syrlinks_tx_registers_dataset(pw, hk_data)
|
||||
elif set_id == SetId.TEMPERATURE_SET_ID:
|
||||
return handle_syrlinks_temp_dataset(pw, hk_data)
|
||||
def handle_syrlinks_hk_data(
|
||||
hk_info: HkTmInfo,
|
||||
pw: PrintWrapper,
|
||||
):
|
||||
if hk_info.set_id == SetId.RX_REGISTERS_DATASET:
|
||||
return handle_syrlinks_rx_registers_dataset(hk_info, pw)
|
||||
elif hk_info.set_id == SetId.TX_REGISTERS_DATASET:
|
||||
return handle_syrlinks_tx_registers_dataset(hk_info, pw)
|
||||
elif hk_info.set_id == SetId.TEMPERATURE_SET_ID:
|
||||
return handle_syrlinks_temp_dataset(hk_info, pw)
|
||||
else:
|
||||
pw.dlog(f"Service 3 TM: Syrlinks handler reply with unknown set ID {set_id}")
|
||||
pw.dlog(
|
||||
f"Service 3 TM: Syrlinks handler reply with unknown set ID {hk_info.set_id}"
|
||||
)
|
||||
|
||||
|
||||
def handle_syrlinks_temp_dataset(pw: PrintWrapper, hk_data: bytes):
|
||||
def handle_syrlinks_temp_dataset(hk_info: HkTmInfo, pw: PrintWrapper):
|
||||
hk_data = hk_info.hk_data
|
||||
if len(hk_data) < 8:
|
||||
raise ValueError("expected at least 8 bytes of HK data")
|
||||
temp_power_amplifier = struct.unpack("!f", hk_data[0:4])[0]
|
||||
@ -294,7 +300,11 @@ def handle_syrlinks_temp_dataset(pw: PrintWrapper, hk_data: bytes):
|
||||
pw.dlog(FsfwTmTcPrinter.get_validity_buffer(hk_data[8:], 2))
|
||||
|
||||
|
||||
def handle_syrlinks_rx_registers_dataset(pw: PrintWrapper, hk_data: bytes):
|
||||
def handle_syrlinks_rx_registers_dataset(
|
||||
hk_info: HkTmInfo,
|
||||
pw: PrintWrapper,
|
||||
):
|
||||
hk_data = hk_info.hk_data
|
||||
header_list = [
|
||||
"RX Status",
|
||||
"RX Sensitivity",
|
||||
@ -357,14 +367,44 @@ def handle_syrlinks_rx_registers_dataset(pw: PrintWrapper, hk_data: bytes):
|
||||
pw.dlog(
|
||||
FsfwTmTcPrinter.get_validity_buffer(validity_buffer=validity_buffer, num_vars=8)
|
||||
)
|
||||
pw.dlog(f"Carrier Detect: {carrier_detect}")
|
||||
pw.dlog(f"Carrier Lock: {carrier_lock}")
|
||||
pw.dlog(f"Data Lock (data clock recovery loop lock status): {data_lock}")
|
||||
pw.dlog(f"Data Valid (valid if TEB < 10e-5): {data_valid}")
|
||||
pw.dlog(f"Data Lock (data clock recovery loop lock status): {data_lock}")
|
||||
pw.dlog(f"RX AGC Inhibit: {rx_agc_inhibit}")
|
||||
pw.dlog(f"RX AGC: {rx_agc}")
|
||||
pw.dlog(f"Eb / E0RX [dB]: {eb_to_n0}")
|
||||
print(f"Carrier Detect: {carrier_detect}")
|
||||
print(f"Carrier Lock: {carrier_lock}")
|
||||
print(f"Data Lock (data clock recovery loop lock status): {data_lock}")
|
||||
print(f"Data Valid (valid if TEB < 10e-5): {data_valid}")
|
||||
print(f"Data Lock (data clock recovery loop lock status): {data_lock}")
|
||||
print(f"RX AGC Inhibit: {rx_agc_inhibit}")
|
||||
print(f"RX AGC: {rx_agc}")
|
||||
print(f"Eb / E0RX [dB]: {eb_to_n0}")
|
||||
cursor = hk_info.db_con.cursor()
|
||||
cursor.execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS syrlinks_rx_regs(
|
||||
packet_uuid TEXT PRIMARY KEY,
|
||||
generation_time TEXT,
|
||||
carrier_detect NUM,
|
||||
carrier_lock NUM,
|
||||
data_lock NUM,
|
||||
data_valid NUM,
|
||||
rx_agc_inhibit NUM,
|
||||
rx_agc NUM,
|
||||
eb_to_e0_rx NUM
|
||||
)"""
|
||||
)
|
||||
cursor.execute(
|
||||
"INSERT INTO syrlinks_rx_regs VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(
|
||||
str(hk_info.packet_uuid),
|
||||
hk_info.hk_packet.pus_tm.time_provider.as_datetime(), # type: ignore
|
||||
carrier_detect,
|
||||
carrier_lock,
|
||||
data_lock,
|
||||
data_valid,
|
||||
rx_agc_inhibit,
|
||||
rx_agc,
|
||||
eb_to_n0,
|
||||
),
|
||||
)
|
||||
hk_info.db_con.commit()
|
||||
|
||||
|
||||
class TxConv(enum.IntEnum):
|
||||
@ -390,11 +430,11 @@ WAVEFORM_STRINGS = ["OFF", "CW", "QPSK", "0QPSK", "PCM/PM", "PSK/PM", "BPSK"]
|
||||
|
||||
|
||||
def handle_syrlinks_tx_registers_dataset(
|
||||
hk_info: HkTmInfo,
|
||||
pw: PrintWrapper,
|
||||
hk_data: bytes,
|
||||
):
|
||||
header_list = ["TX Status Raw", "TX Waveform", "TX AGC value"]
|
||||
tx_status = hk_data[0]
|
||||
tx_status = hk_info.hk_data[0]
|
||||
"""
|
||||
try:
|
||||
tx_conv = TxConv(tx_status & 0b111)
|
||||
@ -412,9 +452,10 @@ def handle_syrlinks_tx_registers_dataset(
|
||||
logging.getLogger(__name__).warning(
|
||||
f"invalid TX conf set {(tx_status >> 2) & 0b11}"
|
||||
)
|
||||
tx_conf_set = -1
|
||||
# Hack to make DB insertion work.
|
||||
tx_conf_set = TxCfgSet.START_WITH_CURRENT_CFG
|
||||
tx_clock_detect = (tx_status >> 4) & 0b1
|
||||
tx_waveform = hk_data[1]
|
||||
tx_waveform = hk_info.hk_data[1]
|
||||
waveform = tx_waveform & 0b1111
|
||||
try:
|
||||
waveform_str = WAVEFORM_STRINGS[waveform]
|
||||
@ -422,11 +463,11 @@ def handle_syrlinks_tx_registers_dataset(
|
||||
logging.getLogger(__name__).warning(f"Unknown waveform value {waveform}")
|
||||
waveform_str = "Unknown"
|
||||
pcm_mode = (tx_waveform >> 4) & 0b1
|
||||
tx_agc_value = struct.unpack("!H", hk_data[2:4])[0]
|
||||
tx_agc_value = struct.unpack("!H", hk_info.hk_data[2:4])[0]
|
||||
tx_agc_inhibit = (tx_agc_value >> 15) & 0b1
|
||||
tx_agc = tx_agc_value & 0xFFF
|
||||
content_list = [tx_status, tx_waveform, tx_agc_value]
|
||||
validity_buffer = hk_data[4:]
|
||||
validity_buffer = hk_info.hk_data[4:]
|
||||
for header, content in zip(header_list, content_list):
|
||||
pw.dlog(f"{header}: {content}")
|
||||
pw.dlog(
|
||||
@ -434,10 +475,46 @@ def handle_syrlinks_tx_registers_dataset(
|
||||
)
|
||||
# pw.dlog(f"TX CONV: {tx_conv!r}")
|
||||
# pw.dlog(f"TX DIFF (differential encoder enable): {tx_diff_encoder_enable}")
|
||||
pw.dlog(f"TX Status: {tx_status_status!r}")
|
||||
pw.dlog(f"TX Config Set: {tx_conf_set!r}")
|
||||
pw.dlog(f"TX Clock Detect: {tx_clock_detect}")
|
||||
pw.dlog(f"Waveform: {waveform_str}")
|
||||
pw.dlog(f"PCM Mode: {pcm_mode}")
|
||||
pw.dlog(f"TX AGC Inhibit: {tx_agc_inhibit}")
|
||||
pw.dlog(f"TX AGC: {tx_agc}")
|
||||
print(f"TX Status: {tx_status_status!r}")
|
||||
print(f"TX Config Set: {tx_conf_set!r}")
|
||||
print(f"TX Clock Detect: {tx_clock_detect}")
|
||||
print(f"Waveform: {waveform_str}")
|
||||
print(f"PCM Mode: {pcm_mode}")
|
||||
print(f"TX AGC Inhibit: {tx_agc_inhibit}")
|
||||
print(f"TX AGC: {tx_agc}")
|
||||
cursor = hk_info.db_con.cursor()
|
||||
cursor.execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS syrlinks_tx_regs(
|
||||
packet_uuid TEXT PRIMARY KEY,
|
||||
generation_time TEXT,
|
||||
tx_status NUM,
|
||||
tx_status_str TEXT,
|
||||
tx_cfg_set NUM,
|
||||
tx_cfg_set_str TEXT,
|
||||
tx_clock_detect NUM,
|
||||
waveform NUM,
|
||||
waveform_str TEXT,
|
||||
pcm_mode NUM,
|
||||
tx_agc_inhibut NUM,
|
||||
tx_agc NUM
|
||||
)"""
|
||||
)
|
||||
cursor.execute(
|
||||
"INSERT INTO syrlinks_tx_regs VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(
|
||||
str(hk_info.packet_uuid),
|
||||
hk_info.hk_packet.pus_tm.time_provider.as_datetime(), # type: ignore
|
||||
tx_status_status,
|
||||
tx_status_status.name,
|
||||
tx_conf_set,
|
||||
tx_conf_set.name,
|
||||
tx_clock_detect,
|
||||
waveform,
|
||||
waveform_str,
|
||||
pcm_mode,
|
||||
tx_agc_inhibit,
|
||||
tx_agc,
|
||||
),
|
||||
)
|
||||
hk_info.db_con.commit()
|
||||
|
Reference in New Issue
Block a user