let's try a DB
All checks were successful
EIVE/-/pipeline/head This commit looks good

This commit is contained in:
2023-11-13 08:50:51 +01:00
parent 99c6c8bbd0
commit 3fe51b08a6
5 changed files with 92 additions and 37 deletions

View File

@ -1,5 +1,6 @@
import struct
from typing import List, Tuple
import sqlite3
from typing import List, Optional, Tuple
from eive_tmtc.tmtc.power.acu import acu_config_table_handler
from eive_tmtc.tmtc.power.common_power import (
@ -8,6 +9,7 @@ from eive_tmtc.tmtc.power.common_power import (
OBC_ENDIANNESS,
)
from eive_tmtc.tmtc.power.power import PcduSetIds
from tmtccmd.tm.pus_3_fsfw_hk import Service3FsfwTm
from tmtccmd.util import ObjectIdBase
from tmtccmd.fsfw.tmtc_printer import FsfwTmTcPrinter
from eive_tmtc.pus_tm.defs import PrintWrapper
@ -146,7 +148,14 @@ class DevicesInfoParser:
return "Unknown Type"
def handle_pdu_data(pw: PrintWrapper, pdu_idx: int, set_id: int, hk_data: bytes):
def handle_pdu_data(
hk_packet: Service3FsfwTm,
con: Optional[sqlite3.Connection],
pw: PrintWrapper,
pdu_idx: int,
set_id: int,
hk_data: bytes,
):
current_idx = 0
priv_idx = pdu_idx - 1
if set_id == SetId.AUX or set_id == SetId.AUX:
@ -219,6 +228,28 @@ def handle_pdu_data(pw: PrintWrapper, pdu_idx: int, set_id: int, hk_data: bytes)
f"Boot Count {boot_count} | Battery Mode {batt_mode} | "
f"Temperature {temperature} | VCC {vcc} | VBAT {vbat}"
)
if con is not None:
cursor = con.cursor()
if pdu_idx == 1:
tbl_name = "Pdu1"
channel_list = PDU1_CHANNELS_NAMES
else:
tbl_name = "Pdu2"
channel_list = PDU2_CHANNELS_NAMES
for idx, name in enumerate(channel_list):
cursor.execute(
f"CREATE TABLE {tbl_name}{name} IF NOT EXISTS "
f"(GenerationTime, OutEnable, Voltage, Current)"
)
value_list = [
hk_packet.pus_tm.time_provider.as_datetime(), # type: ignore
output_enb_list[idx],
voltage_list[idx],
current_list[idx],
]
cursor.execute(
f"INSERT INTO {tbl_name}{name} VALUES(?, ?, ?, ?)", value_list
)
pw.dlog(info)