214 lines
9.0 KiB
Python
214 lines
9.0 KiB
Python
import tkinter as tk
|
|
from tkinter import ttk, scrolledtext
|
|
import sys
|
|
import os
|
|
|
|
# 添加当前目录到Python路径,以便能够导入ccuMsg
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
import ccuMsg
|
|
from datetime import datetime
|
|
|
|
class CCUStatusSummaryDialog:
|
|
"""CCU状态汇总弹窗"""
|
|
def __init__(self, parent, ccu_status=None, title="CCU状态汇总"):
|
|
self.parent = parent
|
|
self.ccu_status = ccu_status or ccuMsg.msg_ccUFbMsg()
|
|
|
|
# 创建弹窗
|
|
self.dialog = tk.Toplevel(parent)
|
|
self.dialog.title(title)
|
|
self.dialog.geometry("1000x700")
|
|
self.dialog.transient(parent) # 设置为父窗口的临时窗口
|
|
self.dialog.grab_set() # 模态对话框
|
|
|
|
# 创建主框架
|
|
main_frame = ttk.Frame(self.dialog, padding="10")
|
|
main_frame.pack(fill=tk.BOTH, expand=True)
|
|
|
|
# 标题
|
|
title_label = ttk.Label(main_frame, text="CCU状态详细信息", font=('Arial', 16, 'bold'))
|
|
title_label.pack(pady=10)
|
|
|
|
# 时间标签
|
|
self.time_label = ttk.Label(main_frame, text="", font=('Arial', 10))
|
|
self.time_label.pack(pady=5)
|
|
|
|
# 创建滚动文本框
|
|
self.summary_text = scrolledtext.ScrolledText(main_frame, width=90, height=30, wrap=tk.WORD, font=('Courier', 10))
|
|
self.summary_text.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
|
|
|
|
# 按钮框架
|
|
button_frame = ttk.Frame(main_frame)
|
|
button_frame.pack(pady=10)
|
|
|
|
# 关闭按钮
|
|
close_btn = ttk.Button(button_frame, text="关闭", command=self.dialog.destroy)
|
|
close_btn.pack(side=tk.LEFT, padx=5)
|
|
|
|
# 刷新按钮
|
|
refresh_btn = ttk.Button(button_frame, text="刷新", command=self.update_display)
|
|
refresh_btn.pack(side=tk.LEFT, padx=5)
|
|
|
|
# 初始更新显示
|
|
self.update_display()
|
|
|
|
def update_display(self):
|
|
"""更新显示数据"""
|
|
# 更新时间标签
|
|
self.time_label.config(text=f"更新时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
|
|
|
# 生成汇总信息
|
|
summary = self.generate_summary()
|
|
|
|
# 清空并插入新的汇总信息
|
|
self.summary_text.delete(1.0, tk.END)
|
|
self.summary_text.insert(1.0, summary)
|
|
|
|
def generate_summary(self):
|
|
"""生成汇总信息"""
|
|
return f"""CCU状态汇总 - {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
|
|
|
|
燃料电池状态:
|
|
运行模式: 0x{self.ccu_status.fc_mode:02X}
|
|
运行状态: 0x{self.ccu_status.fc_status:02X}
|
|
故障等级: 0x{self.ccu_status.fc_fault_level:02X}
|
|
输出功率限制: {self.ccu_status.output_power_limit}W
|
|
累计发电时间: {self.ccu_status.total_generation_time * 0.1:.1f}小时
|
|
发电总功率: {self.ccu_status.total_generation_power}W
|
|
故障等级1-4: {self.ccu_status.fault_level_1}, {self.ccu_status.fault_level_2}, {self.ccu_status.fault_level_3}, {self.ccu_status.fault_level_4}
|
|
储氢容量: {self.ccu_status.hydrogen_capacity}%
|
|
液氧容量: {self.ccu_status.liquid_oxygen_capacity}%
|
|
|
|
传感器数据:
|
|
钯膜温度: {self.ccu_status.palladium_temp}℃
|
|
主水路压力: {self.ccu_status.main_pipe_pressure * 0.01:.2f}kPa
|
|
辅水路压力: {self.ccu_status.aux_pipe_pressure * 0.01:.2f}kPa
|
|
舱室压力1/2: {self.ccu_status.cabin_pressure1}/{self.ccu_status.cabin_pressure2}Pa
|
|
舱室温度1/2: {self.ccu_status.cabin_temp1}/{self.ccu_status.cabin_temp2}℃
|
|
舱室湿度1/2: {self.ccu_status.cabin_humidity1}/{self.ccu_status.cabin_humidity2}%
|
|
火焰探测器1/2: 0x{self.ccu_status.flame_detector1:02X}/0x{self.ccu_status.flame_detector2:02X}
|
|
|
|
浓度检测:
|
|
H2浓度1/2/3: {self.ccu_status.h2_concentration1}/{self.ccu_status.h2_concentration2}/{self.ccu_status.h2_concentration3}
|
|
O2浓度1/2: {self.ccu_status.o2_concentration1}/{self.ccu_status.o2_concentration2}
|
|
CH3OH浓度1/2: {self.ccu_status.ch3oh_concentration1}/{self.ccu_status.ch3oh_concentration2}
|
|
|
|
应急电池:
|
|
电池1电压/电流: {self.ccu_status.emergency_battery1_voltage}V/{self.ccu_status.emergency_battery1_current}A
|
|
电池1最高温度: {self.ccu_status.emergency_battery1_max_temp}℃
|
|
电池1故障字: 0x{self.ccu_status.emergency_battery1_fault_word:04X}
|
|
电池2电压/电流: {self.ccu_status.emergency_battery2_voltage}V/{self.ccu_status.emergency_battery2_current}A
|
|
电池2最高温度: {self.ccu_status.emergency_battery2_max_temp}℃
|
|
电池2故障字: 0x{self.ccu_status.emergency_battery2_fault_word:04X}
|
|
|
|
舱室环境:
|
|
舱室氧浓度: {self.ccu_status.cabin_ox_concentration}
|
|
舱室温度: {self.ccu_status.cabin_temperature}℃
|
|
舱室湿度: {self.ccu_status.cabin_humidity}%
|
|
舱室压力: {self.ccu_status.cabin_pressure}Pa
|
|
动力舱氧浓度: {self.ccu_status.power_cabin_ox_concentration}
|
|
动力舱温度: {self.ccu_status.power_cabin_temperature}℃
|
|
动力舱湿度: {self.ccu_status.power_cabin_humidity}%
|
|
动力舱压力: {self.ccu_status.power_cabin_pressure}Pa
|
|
|
|
报警状态:
|
|
动态报警标志: {[flag for flag in self.ccu_status.dyn_alarm_flag]}
|
|
绝缘报警标志: {[flag for flag in self.ccu_status.ins_alarm_flag]}
|
|
动态报警总数: {sum(self.ccu_status.dyn_alarm_flag)}
|
|
绝缘报警总数: {sum(self.ccu_status.ins_alarm_flag)}
|
|
|
|
继电器状态:
|
|
仪表继电器1/2: 0x{self.ccu_status.ins_relay_status1:02X}/0x{self.ccu_status.ins_relay_status2:02X}
|
|
动力继电器1/2: 0x{self.ccu_status.dyn_relay_status1:02X}/0x{self.ccu_status.dyn_relay_status2:02X}
|
|
|
|
功率信息:
|
|
仪表最大放电功率: {self.ccu_status.ins_max_discharge_power}W
|
|
动力最大放电功率: {self.ccu_status.dyn_max_discharge_power}W
|
|
仪表SOC: {self.ccu_status.ins_soc}%
|
|
动力SOC: {self.ccu_status.dyn_soc}%
|
|
仪表总能量: {self.ccu_status.ins_total_energy}Wh
|
|
动力总能量: {self.ccu_status.dyn_total_energy}Wh
|
|
仪表功率输入: {self.ccu_status.ins_power_input}W
|
|
动力功率输入: {self.ccu_status.dyn_power_input}W
|
|
|
|
充电状态:
|
|
仪表充电状态: 0x{self.ccu_status.ins_charge_status:02X}
|
|
动力充电状态: 0x{self.ccu_status.dyn_charge_status:02X}
|
|
|
|
电气参数:
|
|
仪表链路电压: {self.ccu_status.ins_voltage_link * 0.1:.1f}V
|
|
仪表电池电压: {self.ccu_status.ins_voltage_pack * 0.1:.1f}V
|
|
仪表电流: {self.ccu_status.ins_current * 0.1:.1f}A
|
|
仪表正极绝缘电阻: {self.ccu_status.ins_resistance_pos}Ω
|
|
仪表负极绝缘电阻: {self.ccu_status.ins_resistance_neg}Ω
|
|
动力链路电压: {self.ccu_status.dyn_voltage_link * 0.1:.1f}V
|
|
动力电池电压: {self.ccu_status.dyn_voltage_pack * 0.1:.1f}V
|
|
动力电流: {self.ccu_status.dyn_current * 0.1:.1f}A
|
|
动力正极绝缘电阻: {self.ccu_status.dyn_resistance_pos}Ω
|
|
动力负极绝缘电阻: {self.ccu_status.dyn_resistance_neg}Ω
|
|
|
|
紧急状态:
|
|
仪表紧急状态: 0x{self.ccu_status.ins_emergency_status:02X}
|
|
动力紧急状态: 0x{self.ccu_status.dyn_emergency_status:02X}
|
|
|
|
SOC门限值:
|
|
仪表SOC门限1/2/3: {self.ccu_status.ins_soc_threshold1}/{self.ccu_status.ins_soc_threshold2}/{self.ccu_status.ins_soc_threshold3}%
|
|
动力SOC门限1/2/3: {self.ccu_status.dyn_soc_threshold1}/{self.ccu_status.dyn_soc_threshold2}/{self.ccu_status.dyn_soc_threshold3}%
|
|
|
|
功率限制值:
|
|
仪表功率限制1/2: {self.ccu_status.ins_power_limit1}/{self.ccu_status.ins_power_limit2}W
|
|
动力功率限制1/2: {self.ccu_status.dyn_power_limit1}/{self.ccu_status.dyn_power_limit2}W
|
|
|
|
设备在线状态:
|
|
设备在线标志1: 0x{self.ccu_status.device_online_flag1:08X}
|
|
设备在线标志2: 0x{self.ccu_status.device_online_flag2:08X}
|
|
|
|
其他状态:
|
|
动力充电等级: 0x{self.ccu_status.dyn_charge_level:02X}
|
|
动力漏水状态: 0x{self.ccu_status.dyn_water_leak_status:02X}
|
|
仪表漏水DCDC状态: 0x{self.ccu_status.ins_water_leak_dcdc_status:02X}
|
|
心跳计数器: {self.ccu_status.heartbeat}
|
|
"""
|
|
|
|
def set_ccu_status(self, ccu_status):
|
|
"""设置CCU状态数据"""
|
|
self.ccu_status = ccu_status
|
|
self.update_display()
|
|
|
|
|
|
# 测试函数
|
|
def test_ccu_summary_dialog():
|
|
"""测试CCU状态汇总弹窗"""
|
|
root = tk.Tk()
|
|
root.withdraw() # 隐藏主窗口
|
|
|
|
# 设置一些测试数据
|
|
test_status = ccuMsg.msg_ccUFbMsg()
|
|
test_status.fc_mode = 0x02 # 自动模式
|
|
test_status.fc_status = 0x06 # 运行状态
|
|
test_status.output_power_limit = 15000
|
|
test_status.total_generation_time = 100 # 10小时
|
|
test_status.hydrogen_capacity = 80
|
|
test_status.liquid_oxygen_capacity = 75
|
|
test_status.ins_soc = 85
|
|
test_status.dyn_soc = 90
|
|
test_status.heartbeat = 12345
|
|
test_status.palladium_temp = 65
|
|
test_status.main_pipe_pressure = 1500 # 15.00 kPa
|
|
test_status.aux_pipe_pressure = 800 # 8.00 kPa
|
|
|
|
# 设置一些报警标志
|
|
test_status.dyn_alarm_flag[0] = 1
|
|
test_status.ins_alarm_flag[2] = 1
|
|
|
|
# 创建弹窗
|
|
dialog = CCUStatusSummaryDialog(root, test_status)
|
|
|
|
# 等待弹窗关闭
|
|
root.wait_window(dialog.dialog)
|
|
root.destroy()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_ccu_summary_dialog()
|