this seems to work well
All checks were successful
EIVE/-/pipeline/head This commit looks good

This commit is contained in:
2023-11-13 11:12:18 +01:00
parent b3c3363591
commit ce363e3785
5 changed files with 229 additions and 196 deletions

View File

@ -1,6 +1,7 @@
import struct
import sqlite3
from typing import List, Optional, Tuple
from uuid import UUID
from eive_tmtc.tmtc.power.acu import acu_config_table_handler
from eive_tmtc.tmtc.power.common_power import (
@ -149,12 +150,13 @@ class DevicesInfoParser:
def handle_pdu_data(
hk_data: bytes,
hk_packet: Service3FsfwTm,
packet_uuid: UUID,
con: Optional[sqlite3.Connection],
pw: PrintWrapper,
pdu_idx: int,
set_id: int,
hk_data: bytes,
):
current_idx = 0
priv_idx = pdu_idx - 1
@ -229,27 +231,54 @@ def handle_pdu_data(
f"Temperature {temperature} | VCC {vcc} | VBAT {vbat}"
)
if con is not None:
packet_dt = hk_packet.pus_tm.time_provider.as_datetime() # type: ignore
cursor = con.cursor()
if pdu_idx == 1:
tbl_name = "Pdu1"
tbl_base_name = "Pdu1_"
channel_list = PDU1_CHANNELS_NAMES
else:
tbl_name = "Pdu2"
tbl_base_name = "Pdu2_"
channel_list = PDU2_CHANNELS_NAMES
cursor.execute(
f"""
CREATE TABLE IF NOT EXISTS {tbl_base_name}BootCount(
packet_uuid TEXT PRIMARY KEY,
generation_time TEXT,
Count NUM
)"""
)
cursor.execute(
f"INSERT INTO {tbl_base_name}BootCount VALUES(?, ?, ?)",
(str(packet_uuid), packet_dt, boot_count),
)
for idx, name in enumerate(channel_list):
words = name.split()
camel_case_name = "".join(word.capitalize() for word in words)
tbl_name = f"{tbl_base_name}{camel_case_name}"
print(f"creating table {tbl_name}")
cursor.execute(
f"CREATE TABLE {tbl_name}{name} IF NOT EXISTS "
f"(GenerationTime, OutEnable, Voltage, Current)"
f"""
CREATE TABLE IF NOT EXISTS {tbl_name}(
packet_uuid TEXT PRIMARY KEY,
generation_time TEXT,
out_enable NUM,
voltage NUM,
current NUM
)"""
)
value_list = [
hk_packet.pus_tm.time_provider.as_datetime(), # type: ignore
value_tuple = (
str(packet_uuid),
packet_dt,
output_enb_list[idx],
voltage_list[idx],
current_list[idx],
]
cursor.execute(
f"INSERT INTO {tbl_name}{name} VALUES(?, ?, ?, ?)", value_list
)
print(value_tuple)
cursor.execute(
f"INSERT INTO {tbl_name} VALUES(?, ?, ?, ?, ?)", value_tuple
)
con.commit()
pw.dlog(info)