added another helper/wrapper type
All checks were successful
EIVE/-/pipeline/pr-main This commit looks good

This commit is contained in:
Robin Müller 2023-11-13 14:50:49 +01:00
parent 6e87a0249c
commit 7cb5766a7a
Signed by: muellerr
GPG Key ID: A649FB78196E3849
4 changed files with 178 additions and 78 deletions

21
eive_tmtc/pus_tm/hk.py Normal file
View File

@ -0,0 +1,21 @@
import uuid
import dataclasses
import datetime
import sqlite3
from tmtccmd.pus.tm.s3_fsfw_hk import Service3FsfwTm
@dataclasses.dataclass
class HkTmInfo:
packet_uuid: uuid.UUID
hk_packet: Service3FsfwTm
db_con: sqlite3.Connection
hk_data: bytes
@property
def packet_datetime(self) -> datetime.datetime:
return self.hk_packet.pus_tm.time_provider.as_datetime()
@property
def set_id(self) -> int:
return self.hk_packet.set_id

View File

@ -4,6 +4,7 @@ import logging
import sqlite3
from typing import List, cast
from uuid import UUID
from eive_tmtc.pus_tm.hk import HkTmInfo
from eive_tmtc.tmtc.acs.acs_ctrl import handle_acs_ctrl_hk_data
from eive_tmtc.tmtc.internal_err_reporter import handle_ier_hk_data
@ -112,6 +113,9 @@ def handle_regular_hk_print( # noqa C901: Complexity okay here
):
objb = object_id.as_bytes
set_id = hk_packet.set_id
hk_info = HkTmInfo(
packet_uuid=packet_uuid, hk_packet=hk_packet, db_con=db, hk_data=hk_data
)
assert hk_packet.pus_tm.time_provider is not None
packet_dt = hk_packet.pus_tm.time_provider.as_date_time()
pw = PrintWrapper(printer.file_logger)
@ -119,12 +123,18 @@ def handle_regular_hk_print( # noqa C901: Complexity okay here
if objb in [obj_ids.RW1_ID, obj_ids.RW2_ID, obj_ids.RW3_ID, obj_ids.RW4_ID]:
return handle_rw_hk_data(pw, object_id, set_id, hk_data)
elif objb == obj_ids.SYRLINKS_HANDLER_ID:
return handle_syrlinks_hk_data(pw=pw, hk_data=hk_data, set_id=set_id)
return handle_syrlinks_hk_data(
hk_info=hk_info,
pw=pw,
)
elif objb == obj_ids.IMTQ_HANDLER_ID:
return handle_imtq_hk(pw=pw, hk_data=hk_data, set_id=set_id)
elif objb == obj_ids.GPS_CONTROLLER:
return handle_gps_data(
pw=pw, set_id=set_id, hk_data=hk_data, packet_time=packet_dt
pw=pw,
set_id=set_id,
hk_data=hk_data,
packet_time=packet_dt,
)
elif objb == obj_ids.PCDU_HANDLER_ID:
return handle_pcdu_hk(pw=pw, set_id=set_id, hk_data=hk_data)
@ -134,9 +144,7 @@ def handle_regular_hk_print( # noqa C901: Complexity okay here
return handle_core_hk_data(pw=pw, hk_data=hk_data, set_id=set_id)
elif objb == obj_ids.PDU_1_HANDLER_ID:
return handle_pdu_data(
packet_uuid=packet_uuid,
hk_packet=hk_packet,
con=db,
hk_info=hk_info,
pw=pw,
pdu_idx=1,
set_id=set_id,
@ -144,9 +152,7 @@ def handle_regular_hk_print( # noqa C901: Complexity okay here
)
elif objb == obj_ids.PDU_2_HANDLER_ID:
return handle_pdu_data(
packet_uuid=packet_uuid,
hk_packet=hk_packet,
con=db,
hk_info=hk_info,
pw=pw,
pdu_idx=2,
set_id=set_id,

View File

@ -8,30 +8,34 @@
import enum
import logging
import math
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 (
OpCodeEntry,
TmtcDefinitionWrapper,
tmtc_definitions_provider,
)
from eive_tmtc.pus_tm.hk import HkTmInfo
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.tmtc.com.defs import Mode as ComMode
_LOGGER = logging.getLogger(__name__)
class SetId(enum.IntEnum):
@ -258,18 +262,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]
@ -279,7 +289,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",
@ -342,14 +356,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):
@ -375,11 +419,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)
@ -397,9 +441,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]
@ -407,11 +452,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(
@ -419,10 +464,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()

View File

@ -1,10 +1,9 @@
import dataclasses
from datetime import datetime
import struct
import logging
import sqlite3
from typing import List, Tuple
from uuid import UUID
from eive_tmtc.pus_tm.hk import HkTmInfo
from eive_tmtc.tmtc.power.acu import acu_config_table_handler
from eive_tmtc.tmtc.power.common_power import (
@ -13,7 +12,6 @@ from eive_tmtc.tmtc.power.common_power import (
OBC_ENDIANNESS,
)
from eive_tmtc.tmtc.power.power import PcduSetIds
from tmtccmd.pus.tm.s3_fsfw_hk import Service3FsfwTm
from tmtccmd.util import ObjectIdBase
from tmtccmd.fsfw.tmtc_printer import FsfwTmTcPrinter
from eive_tmtc.pus_tm.defs import PrintWrapper
@ -168,9 +166,7 @@ class PduData:
def handle_pdu_data(
hk_data: bytes,
hk_packet: Service3FsfwTm,
packet_uuid: UUID,
con: sqlite3.Connection,
hk_info: HkTmInfo,
pw: PrintWrapper,
pdu_idx: int,
set_id: int,
@ -249,9 +245,7 @@ def handle_pdu_data(
)
try:
handle_pdu_db_insertion(
con,
packet_uuid,
hk_packet.pus_tm.time_provider.as_datetime(), # type: ignore
hk_info,
pdu_idx,
PduData(
boot_count,
@ -270,13 +264,11 @@ def handle_pdu_data(
def handle_pdu_db_insertion(
con: sqlite3.Connection,
packet_uuid: UUID,
packet_dt: datetime,
hk_info: HkTmInfo,
pdu_idx: int,
pdu_data: PduData,
):
cursor = con.cursor()
cursor = hk_info.db_con.cursor()
if pdu_idx == 1:
tbl_base_name = "pdu1"
channel_list = PDU1_CHANNELS_NAMES
@ -298,8 +290,8 @@ def handle_pdu_db_insertion(
cursor.execute(
f"INSERT INTO {tbl_base_name} VALUES(?, ?, ?, ?, ?, ?, ?)",
(
str(packet_uuid),
packet_dt,
str(hk_info.packet_uuid),
hk_info.packet_datetime,
pdu_data.boot_count,
pdu_data.batt_mode,
pdu_data.temperature,
@ -323,14 +315,14 @@ def handle_pdu_db_insertion(
)"""
)
value_tuple = (
str(packet_uuid),
packet_dt,
str(hk_info.packet_uuid),
hk_info.packet_datetime,
pdu_data.out_enables[idx],
pdu_data.voltages[idx],
pdu_data.currents[idx],
)
cursor.execute(f"INSERT INTO {tbl_name} VALUES(?, ?, ?, ?, ?)", value_tuple)
con.commit()
hk_info.db_con.commit()
def handle_p60_hk_data(pw: PrintWrapper, set_id: int, hk_data: bytes):