1064 lines
53 KiB
Plaintext
1064 lines
53 KiB
Plaintext
import tkinter as tk
|
|
from tkinter import ttk
|
|
import socket
|
|
import threading
|
|
import time
|
|
from udpMsg import (
|
|
msg_disHighVolBusFbMsg,
|
|
msg_disHighAVolBusFbMsg,
|
|
msg_disLowMainBusFbMsg,
|
|
msg_disLowBusFbMsg,
|
|
msg_disHVBCmdMsg,
|
|
msg_disHVBACmdMsg,
|
|
msg_disLVMBCmdMsg,
|
|
msg_disLVBCmdMsg
|
|
)
|
|
|
|
class PowerManagerApp:
|
|
def __init__(self, root):
|
|
self.root = root
|
|
|
|
# 解决字体模糊问题
|
|
style = ttk.Style()
|
|
style.configure('.', font=('Microsoft YaHei', 10))
|
|
|
|
self.root.title("电源管理系统")
|
|
self.root.geometry("1200x800")
|
|
self.root.tk.call('tk', 'scaling', 1.5) # 适配高DPI显示
|
|
|
|
# UDP通信配置
|
|
self.udp_ip = "127.0.0.1"
|
|
self.udp_port = 5000
|
|
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
self.sock.bind((self.udp_ip, self.udp_port))
|
|
|
|
# 状态数据 - 完全匹配udpMsg.py中的定义
|
|
self.status_data = {
|
|
"high_vol_bus": {
|
|
"breakers": {
|
|
"燃料电池断路器": 0,
|
|
"动力锂电池断路器": 0,
|
|
"推进电机断路器": 0,
|
|
"锂电池组仪表断路器": 0,
|
|
"DC/DC模块断路器": 0,
|
|
"艏高压配电盒断路器": 0,
|
|
"艉FT设备45断路器": 0,
|
|
"艉舵机开关1断路器": 0,
|
|
"艉舵机开关2断路器": 0,
|
|
"FB备用断路器": 0,
|
|
"TYZ备用断路器": 0,
|
|
"备用断路器": 0
|
|
},
|
|
"faults": {
|
|
"DC/DC故障1": 0,
|
|
"DC/DC故障2": 0
|
|
},
|
|
"insulation": {
|
|
"动力母线绝缘状态": 0,
|
|
"A母线绝缘状态": 0
|
|
},
|
|
"alarms": {
|
|
"仪表电源丢失信号": 0,
|
|
"应急电源丢失信号": 0
|
|
},
|
|
"voltage": {
|
|
"动力母线电压": 0.0,
|
|
"A母线电压": 0.0
|
|
},
|
|
"current": {
|
|
"动力母线电流": 0.0,
|
|
"DC/DC5模块电流": 0.0,
|
|
"推进电机控制箱电流": 0.0,
|
|
"A母线电流": 0.0,
|
|
"锂电池组仪表电流": 0.0,
|
|
"艏高压配电盒电流": 0.0,
|
|
"艉FT设备45电流": 0.0,
|
|
"TYZ备用开关电流": 0.0,
|
|
"艉舵机开关1电流": 0.0,
|
|
"备用电流1": 0.0,
|
|
"艉舵机开关2电流": 0.0,
|
|
"备用电流2": 0.0,
|
|
"FB备用开关电流": 0.0,
|
|
"备用电流3": 0.0
|
|
},
|
|
"cool_water_pressure": 0.0
|
|
},
|
|
"high_a_vol_bus": {
|
|
"breakers": {
|
|
"艏FT设备123断路器": 0,
|
|
"执行机构断路器": 0,
|
|
"桅舵机控制箱断路器": 0,
|
|
"XCZ断路器": 0,
|
|
"艏舵控制箱断路器": 0,
|
|
"开盖启动气缸断路器": 0
|
|
},
|
|
"alarms": {
|
|
"仪表电源故障": 0,
|
|
"应急电源故障": 0,
|
|
"进水报警": 0
|
|
},
|
|
"voltage": {
|
|
"B母线电压": 0.0
|
|
},
|
|
"current": {
|
|
"B母线电流": 0.0,
|
|
"艏FT设备123电流": 0.0,
|
|
"执行机构电流": 0.0,
|
|
"桅舵机控制箱电流": 0.0,
|
|
"XCZ电流": 0.0,
|
|
"艏舵控制箱电流": 0.0,
|
|
"开盖启动气缸电流": 0.0
|
|
}
|
|
},
|
|
"low_main_bus": {
|
|
"breakers": {
|
|
"锂电池组仪表断路器": 0,
|
|
"艏低压配电盒断路器": 0,
|
|
"单元4仪表48V断路器": 0,
|
|
"DC/C1直流配电板断路器": 0,
|
|
"备用断路器1": 0,
|
|
"备用断路器2": 0,
|
|
"应急锂电池组2断路器": 0
|
|
},
|
|
"alarms": {
|
|
"仪表电源故障": 0,
|
|
"应急电源故障": 0
|
|
},
|
|
"insulation": 0,
|
|
"voltage": {
|
|
"仪表母线电压": 0.0,
|
|
"应急2母线电压": 0.0
|
|
},
|
|
"current": {
|
|
"艏低压配电盒电流": 0.0,
|
|
"DC/C1仪表48V电流": 0.0,
|
|
"备用电流1": 0.0,
|
|
"应急锂电池组2电流": 0.0,
|
|
"锂电池组仪表电流": 0.0,
|
|
"单元4仪表48V电流": 0.0,
|
|
"备用电流2": 0.0,
|
|
"综合能量管理系统应急DC48V电流": 0.0,
|
|
"燃料电池安全系统应急DC48V电流": 0.0,
|
|
"PLC控制电源电流": 0.0
|
|
}
|
|
},
|
|
"low_bus": {
|
|
"breakers": {
|
|
"单元1断路器": 0,
|
|
"单元2断路器": 0,
|
|
"单元3断路器": 0,
|
|
"单元5断路器": 0,
|
|
"艏PZ设备断路器": 0,
|
|
"备用断路器1": 0,
|
|
"备用断路器2": 0,
|
|
"应急锂电池组1断路器": 0
|
|
},
|
|
"alarms": {
|
|
"电源故障信号": 0,
|
|
"进水报警": 0
|
|
},
|
|
"voltage": {
|
|
"仪表母线电压": 0.0,
|
|
"应急1母线电压": 0.0
|
|
},
|
|
"current": {
|
|
"仪表母线电流": 0.0,
|
|
"单元1电流": 0.0,
|
|
"单元2电流": 0.0,
|
|
"单元3电流": 0.0,
|
|
"单元5电流": 0.0,
|
|
"艏PZ设备电流": 0.0,
|
|
"应急锂电池组1电流": 0.0
|
|
}
|
|
}
|
|
}
|
|
|
|
# 初始化界面
|
|
self.setup_ui()
|
|
|
|
# 启动UDP接收线程
|
|
self.running = True
|
|
self.recv_thread = threading.Thread(target=self.udp_receive_loop)
|
|
self.recv_thread.daemon = True
|
|
self.recv_thread.start()
|
|
|
|
# 启动状态更新定时器
|
|
self.update_ui()
|
|
|
|
def setup_ui(self):
|
|
"""初始化用户界面"""
|
|
# 主框架
|
|
main_frame = ttk.Frame(self.root, padding="10")
|
|
main_frame.pack(fill=tk.BOTH, expand=True)
|
|
|
|
# 状态显示区
|
|
status_frame = ttk.LabelFrame(main_frame, text="系统状态", padding="10")
|
|
status_frame.pack(fill=tk.X, pady=5)
|
|
|
|
# 状态显示区 - 使用Notebook组织不同母线状态
|
|
self.notebook = ttk.Notebook(status_frame)
|
|
self.notebook.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
|
|
|
|
# 高压母线状态页
|
|
high_vol_frame = ttk.Frame(self.notebook)
|
|
self.notebook.add(high_vol_frame, text="高压母线")
|
|
self.setup_high_vol_ui(high_vol_frame)
|
|
|
|
# 高压A母线状态页
|
|
high_a_vol_frame = ttk.Frame(self.notebook)
|
|
self.notebook.add(high_a_vol_frame, text="高压A母线")
|
|
self.setup_high_a_vol_ui(high_a_vol_frame)
|
|
|
|
# 仪表主母线状态页
|
|
low_main_frame = ttk.Frame(self.notebook)
|
|
self.notebook.add(low_main_frame, text="仪表主母线")
|
|
self.setup_low_main_ui(low_main_frame)
|
|
|
|
# 仪表母线状态页
|
|
low_bus_frame = ttk.Frame(self.notebook)
|
|
self.notebook.add(low_bus_frame, text="仪表母线")
|
|
self.setup_low_bus_ui(low_bus_frame)
|
|
|
|
# 控制区
|
|
control_frame = ttk.LabelFrame(main_frame, text="控制面板", padding="10")
|
|
control_frame.pack(fill=tk.BOTH, expand=True, pady=5)
|
|
|
|
# 状态显示区 - 使用Notebook组织不同母线状态
|
|
self.notebook_c = ttk.Notebook(control_frame)
|
|
self.notebook_c.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
|
|
|
|
high_vol_control_frame = ttk.Frame(self.notebook_c)
|
|
self.notebook_c.add(high_vol_control_frame, text="高压母线")
|
|
self.setup_hvb_control(high_vol_control_frame)
|
|
|
|
high_a_vol_control_frame = ttk.Frame(self.notebook_c)
|
|
self.notebook_c.add(high_a_vol_control_frame, text="高压A母线")
|
|
self.setup_hvba_control(high_a_vol_control_frame)
|
|
|
|
low_main_control_frame = ttk.Frame(self.notebook_c)
|
|
self.notebook_c.add(low_main_control_frame, text="仪表主母线")
|
|
self.setup_lvmb_control(low_main_control_frame)
|
|
|
|
low_bus_control_frame = ttk.Frame(self.notebook_c)
|
|
self.notebook_c.add(low_bus_control_frame, text="仪表母线")
|
|
self.setup_lvb_control(low_bus_control_frame)
|
|
|
|
# 日志区
|
|
log_frame = ttk.LabelFrame(main_frame, text="系统日志", padding="10")
|
|
log_frame.pack(fill=tk.BOTH, expand=True, pady=5)
|
|
|
|
self.log_text = tk.Text(log_frame, height=10, state=tk.DISABLED)
|
|
self.log_text.pack(fill=tk.BOTH, expand=True)
|
|
|
|
scrollbar = ttk.Scrollbar(log_frame, orient=tk.VERTICAL, command=self.log_text.yview)
|
|
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
|
|
self.log_text.config(yscrollcommand=scrollbar.set)
|
|
|
|
def setup_hvb_control(self, parent):
|
|
"""设置动力母线配电指令控制面板"""
|
|
frame = ttk.LabelFrame(parent, text="动力母线配电指令", padding="10")
|
|
frame.pack(fill=tk.X, pady=5)
|
|
|
|
# 断路器控制按钮
|
|
breaker_names = [
|
|
"燃料电池断路器", "动力锂电池断路器", "推进电机断路器",
|
|
"锂电池组仪表断路器", "DC/DC模块断路器", "艏高压配电盒断路器",
|
|
"艉FT设备45断路器", "艉舵机开关1断路器", "艉舵机开关2断路器",
|
|
"FB备用断路器", "TYZ备用断路器", "备用断路器"
|
|
]
|
|
|
|
for i, name in enumerate(breaker_names):
|
|
row = i // 3
|
|
col = i % 3
|
|
btn_frame = ttk.Frame(frame)
|
|
btn_frame.grid(row=row, column=col, padx=5, pady=2, sticky=tk.W)
|
|
|
|
ttk.Label(btn_frame, text=name).pack(side=tk.LEFT)
|
|
on_btn = ttk.Button(btn_frame, text="合", width=3,
|
|
command=lambda n=name: self.send_hvb_cmd(n, 1))
|
|
on_btn.pack(side=tk.LEFT, padx=2)
|
|
off_btn = ttk.Button(btn_frame, text="分", width=3,
|
|
command=lambda n=name: self.send_hvb_cmd(n, 0))
|
|
off_btn.pack(side=tk.LEFT, padx=2)
|
|
|
|
def setup_hvba_control(self, parent):
|
|
"""设置动力汇流排A配电指令控制面板"""
|
|
frame = ttk.LabelFrame(parent, text="动力汇流排A配电指令", padding="10")
|
|
frame.pack(fill=tk.X, pady=5)
|
|
|
|
# 断路器控制按钮
|
|
breaker_names = [
|
|
"艏FT设备123断路器", "执行机构断路器", "桅舵机控制箱断路器",
|
|
"XCZ断路器", "艏舵控制箱断路器", "开盖启动气缸断路器"
|
|
]
|
|
|
|
for i, name in enumerate(breaker_names):
|
|
row = i // 3
|
|
col = i % 3
|
|
btn_frame = ttk.Frame(frame)
|
|
btn_frame.grid(row=row, column=col, padx=5, pady=2, sticky=tk.W)
|
|
|
|
ttk.Label(btn_frame, text=name).pack(side=tk.LEFT)
|
|
on_btn = ttk.Button(btn_frame, text="合", width=3,
|
|
command=lambda n=name: self.send_hvba_cmd(n, 1))
|
|
on_btn.pack(side=tk.LEFT, padx=2)
|
|
off_btn = ttk.Button(btn_frame, text="分", width=3,
|
|
command=lambda n=name: self.send_hvba_cmd(n, 0))
|
|
off_btn.pack(side=tk.LEFT, padx=2)
|
|
|
|
def setup_lvmb_control(self, parent):
|
|
"""设置仪表母线配电指令控制面板"""
|
|
frame = ttk.LabelFrame(parent, text="仪表母线配电指令", padding="10")
|
|
frame.pack(fill=tk.X, pady=5)
|
|
|
|
# 断路器控制按钮
|
|
breaker_names = [
|
|
"锂电池组仪表断路器", "艏低压配电盒断路器", "单元4仪表48V断路器",
|
|
"DC/C1直流配电板断路器", "备用断路器1", "备用断路器2",
|
|
"应急锂电池组2断路器"
|
|
]
|
|
|
|
for i, name in enumerate(breaker_names):
|
|
row = i // 3
|
|
col = i % 3
|
|
btn_frame = ttk.Frame(frame)
|
|
btn_frame.grid(row=row, column=col, padx=5, pady=2, sticky=tk.W)
|
|
|
|
ttk.Label(btn_frame, text=name).pack(side=tk.LEFT)
|
|
on_btn = ttk.Button(btn_frame, text="合", width=3,
|
|
command=lambda n=name: self.send_lvmb_cmd(n, 1))
|
|
on_btn.pack(side=tk.LEFT, padx=2)
|
|
off_btn = ttk.Button(btn_frame, text="分", width=3,
|
|
command=lambda n=name: self.send_lvmb_cmd(n, 0))
|
|
off_btn.pack(side=tk.LEFT, padx=2)
|
|
|
|
def setup_lvb_control(self, parent):
|
|
"""设置仪表汇流排配电指令控制面板"""
|
|
frame = ttk.LabelFrame(parent, text="仪表汇流排配电指令", padding="10")
|
|
frame.pack(fill=tk.X, pady=5)
|
|
|
|
# 断路器控制按钮
|
|
breaker_names = [
|
|
"单元1断路器", "单元2断路器", "单元3断路器",
|
|
"单元5断路器", "艏PZ设备断路器", "备用断路器1",
|
|
"备用断路器2", "应急锂电池组1断路器"
|
|
]
|
|
|
|
for i, name in enumerate(breaker_names):
|
|
row = i // 3
|
|
col = i % 3
|
|
btn_frame = ttk.Frame(frame)
|
|
btn_frame.grid(row=row, column=col, padx=5, pady=2, sticky=tk.W)
|
|
|
|
ttk.Label(btn_frame, text=name).pack(side=tk.LEFT)
|
|
on_btn = ttk.Button(btn_frame, text="合", width=3,
|
|
command=lambda n=name: self.send_lvb_cmd(n, 1))
|
|
on_btn.pack(side=tk.LEFT, padx=2)
|
|
off_btn = ttk.Button(btn_frame, text="分", width=3,
|
|
command=lambda n=name: self.send_lvb_cmd(n, 0))
|
|
off_btn.pack(side=tk.LEFT, padx=2)
|
|
|
|
def send_hvb_cmd(self, breaker_name, state):
|
|
"""发送动力母线配电指令"""
|
|
cmd = msg_disHVBCmdMsg()
|
|
if breaker_name == "燃料电池断路器":
|
|
cmd.fuelCellCircuitBreaker = state
|
|
elif breaker_name == "动力锂电池断路器":
|
|
cmd.powerLithiumBatteryCircuitBreaker = state
|
|
elif breaker_name == "推进电机断路器":
|
|
cmd.propulsionMotorCircuitBreaker = state
|
|
elif breaker_name == "锂电池组仪表断路器":
|
|
cmd.lithiumBatteryGroupInstrumentCircuitBreaker = state
|
|
elif breaker_name == "DC/DC模块断路器":
|
|
cmd.dcDc5ModuleCircuitBreaker = state
|
|
elif breaker_name == "艏高压配电盒断路器":
|
|
cmd.bowHighVoltageDistributionBoxCircuitBreaker = state
|
|
elif breaker_name == "艉FT设备45断路器":
|
|
cmd.sternFTDevice45CircuitBreaker = state
|
|
elif breaker_name == "艉舵机开关1断路器":
|
|
cmd.sternRudderSwitch1CircuitBreaker = state
|
|
elif breaker_name == "艉舵机开关2断路器":
|
|
cmd.sternRudderSwitch2CircuitBreaker = state
|
|
elif breaker_name == "FB备用断路器":
|
|
cmd.fbReservedCircuitBreaker = state
|
|
elif breaker_name == "TYZ备用断路器":
|
|
cmd.tyzReservedCircuitBreaker = state
|
|
elif breaker_name == "备用断路器":
|
|
cmd.reservedCircuitBreaker = state
|
|
|
|
self.send_udp_command(cmd.pack())
|
|
self.log_message(f"发送动力母线配电指令: {breaker_name} {'合' if state else '分'}")
|
|
|
|
def send_hvba_cmd(self, breaker_name, state):
|
|
"""发送动力汇流排A配电指令"""
|
|
cmd = msg_disHVBACmdMsg()
|
|
if breaker_name == "艏FT设备123断路器":
|
|
cmd.bowFTDevice123CircuitBreaker = state
|
|
elif breaker_name == "执行机构断路器":
|
|
cmd.actuatorCircuitBreaker = state
|
|
elif breaker_name == "桅舵机控制箱断路器":
|
|
cmd.mastSteeringGearControlBoxCircuitBreaker = state
|
|
elif breaker_name == "XCZ断路器":
|
|
cmd.xczCircuitBreaker = state
|
|
elif breaker_name == "艏舵控制箱断路器":
|
|
cmd.bowRudderControlBoxCircuitBreaker = state
|
|
elif breaker_name == "开盖启动气缸断路器":
|
|
cmd.openWaterCoverStartCylinderCircuitBreaker = state
|
|
|
|
self.send_udp_command(cmd.pack())
|
|
self.log_message(f"发送动力汇流排A配电指令: {breaker_name} {'合' if state else '分'}")
|
|
|
|
def send_lvmb_cmd(self, breaker_name, state):
|
|
"""发送仪表母线配电指令"""
|
|
cmd = msg_disLVMBCmdMsg()
|
|
if breaker_name == "锂电池组仪表断路器":
|
|
cmd.lithiumBatteryGroupInstrumentCircuitBreaker = state
|
|
elif breaker_name == "艏低压配电盒断路器":
|
|
cmd.bowLowVoltageDistributionBoxCircuitBreaker = state
|
|
elif breaker_name == "单元4仪表48V断路器":
|
|
cmd.unit4InstrumentDC48VCircuitBreaker = state
|
|
elif breaker_name == "DC/C1直流配电板断路器":
|
|
cmd.dcC1DCDistributionPanelCircuitBreaker = state
|
|
elif breaker_name == "备用断路器1":
|
|
cmd.reservedCircuitBreaker1 = state
|
|
elif breaker_name == "备用断路器2":
|
|
cmd.reservedCircuitBreaker2 = state
|
|
elif breaker_name == "应急锂电池组2断路器":
|
|
cmd.emergencyLithiumBatteryGroup2CircuitBreaker = state
|
|
|
|
self.send_udp_command(cmd.pack())
|
|
self.log_message(f"发送仪表母线配电指令: {breaker_name} {'合' if state else '分'}")
|
|
|
|
def send_lvb_cmd(self, breaker_name, state):
|
|
"""发送仪表汇流排配电指令"""
|
|
cmd = msg_disLVBCmdMsg()
|
|
if breaker_name == "单元1断路器":
|
|
cmd.unit1CircuitBreaker = state
|
|
elif breaker_name == "单元2断路器":
|
|
cmd.unit2CircuitBreaker = state
|
|
elif breaker_name == "单元3断路器":
|
|
cmd.unit3CircuitBreaker = state
|
|
elif breaker_name == "单元5断路器":
|
|
cmd.unit5CircuitBreaker = state
|
|
elif breaker_name == "艏PZ设备断路器":
|
|
cmd.bowPZDeviceCircuitBreaker = state
|
|
elif breaker_name == "备用断路器1":
|
|
cmd.reservedCircuitBreaker1 = state
|
|
elif breaker_name == "备用断路器2":
|
|
cmd.reservedCircuitBreaker2 = state
|
|
elif breaker_name == "应急锂电池组1断路器":
|
|
cmd.emergencyLithiumBatteryGroup1CircuitBreaker = state
|
|
|
|
self.send_udp_command(cmd.pack())
|
|
self.log_message(f"发送仪表汇流排配电指令: {breaker_name} {'合' if state else '分'}")
|
|
|
|
def udp_receive_loop(self):
|
|
"""UDP接收消息循环"""
|
|
while self.running:
|
|
try:
|
|
data, addr = self.sock.recvfrom(1024)
|
|
self.process_udp_message(data)
|
|
except Exception as e:
|
|
self.log_message(f"接收错误: {str(e)}")
|
|
|
|
def setup_high_vol_ui(self, parent):
|
|
"""设置高压母线状态界面"""
|
|
# 初始化故障位列表
|
|
self.high_vol_dcdc_fault1_bits = []
|
|
self.high_vol_dcdc_fault2_bits = []
|
|
|
|
frame = ttk.LabelFrame(parent, text="高压母线状态")
|
|
frame.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
|
|
|
|
# 使用网格布局管理器
|
|
frame.grid_columnconfigure(0, weight=1)
|
|
frame.grid_columnconfigure(1, weight=1)
|
|
frame.grid_columnconfigure(2, weight=1)
|
|
|
|
# 电压显示
|
|
ttk.Label(frame, text="动力母线电压(V):").grid(row=0, column=0, sticky=tk.W)
|
|
self.high_vol_power_voltage = ttk.Label(frame, text="0.0")
|
|
self.high_vol_power_voltage.grid(row=0, column=1, sticky=tk.W)
|
|
|
|
ttk.Label(frame, text="A母线电压(V):").grid(row=0, column=2, sticky=tk.W)
|
|
self.high_vol_a_voltage = ttk.Label(frame, text="0.0")
|
|
self.high_vol_a_voltage.grid(row=0, column=3, sticky=tk.W)
|
|
|
|
# 电流显示
|
|
ttk.Label(frame, text="动力母线电流(A):").grid(row=1, column=0, sticky=tk.W)
|
|
self.high_vol_power_current = ttk.Label(frame, text="0.0")
|
|
self.high_vol_power_current.grid(row=1, column=1, sticky=tk.W)
|
|
|
|
ttk.Label(frame, text="A母线电流(A):").grid(row=1, column=2, sticky=tk.W)
|
|
self.high_vol_a_current = ttk.Label(frame, text="0.0")
|
|
self.high_vol_a_current.grid(row=1, column=3, sticky=tk.W)
|
|
|
|
# 断路器状态
|
|
ttk.Label(frame, text="断路器状态:").grid(row=2, column=0, columnspan=4, sticky=tk.W)
|
|
self.high_vol_breakers = {}
|
|
breaker_names = list(self.status_data["high_vol_bus"]["breakers"].keys())
|
|
|
|
for i, name in enumerate(breaker_names):
|
|
ttk.Label(frame, text=name).grid(row=3+i//3, column=(i%3)*2, sticky=tk.W)
|
|
canvas = tk.Canvas(frame, width=20, height=20, bg="white")
|
|
canvas.grid(row=3+i//3, column=(i%3)*2+1, sticky=tk.W)
|
|
self.high_vol_breakers[name] = canvas
|
|
|
|
# 绝缘状态
|
|
ttk.Label(frame, text="动力母线绝缘:").grid(row=9, column=0, sticky=tk.W)
|
|
self.high_vol_power_insulation = ttk.Label(frame, text="正常")
|
|
self.high_vol_power_insulation.grid(row=9, column=1, sticky=tk.W)
|
|
|
|
ttk.Label(frame, text="A母线绝缘:").grid(row=9, column=2, sticky=tk.W)
|
|
self.high_vol_a_insulation = ttk.Label(frame, text="正常")
|
|
self.high_vol_a_insulation.grid(row=9, column=3, sticky=tk.W)
|
|
|
|
# 故障状态 - 扩展显示所有故障位
|
|
fault_labels1 = ["过压", "欠压", "过流", "过热", "通讯", "硬件", "软件", "保留"]
|
|
fault_labels2 = ["模块1", "模块2", "模块3", "模块4", "模块5", "保留", "保留", "保留"]
|
|
|
|
ttk.Label(frame, text="DC/DC故障字1:").grid(row=10, column=0, sticky=tk.W)
|
|
for i, label in enumerate(fault_labels1):
|
|
ttk.Label(frame, text=label).grid(row=11+i//4, column=(i%4)*2, sticky=tk.W)
|
|
canvas = tk.Canvas(frame, width=20, height=20, bg="white")
|
|
canvas.grid(row=11+i//4, column=(i%4)*2+1, sticky=tk.W)
|
|
self.high_vol_dcdc_fault1_bits.append(canvas)
|
|
|
|
ttk.Label(frame, text="DC/DC故障字2:").grid(row=13, column=0, sticky=tk.W)
|
|
for i, label in enumerate(fault_labels2):
|
|
ttk.Label(frame, text=label).grid(row=14+i//4, column=(i%4)*2, sticky=tk.W)
|
|
canvas = tk.Canvas(frame, width=20, height=20, bg="white")
|
|
canvas.grid(row=14+i//4, column=(i%4)*2+1, sticky=tk.W)
|
|
self.high_vol_dcdc_fault2_bits.append(canvas)
|
|
|
|
# 绝缘状态 - 详细显示
|
|
ttk.Label(frame, text="动力母线绝缘:").grid(row=16, column=0, sticky=tk.W)
|
|
self.high_vol_power_insulation = ttk.Label(frame, text="正常(0.0MΩ)")
|
|
self.high_vol_power_insulation.grid(row=16, column=1, sticky=tk.W)
|
|
|
|
ttk.Label(frame, text="A母线绝缘:").grid(row=16, column=2, sticky=tk.W)
|
|
self.high_vol_a_insulation = ttk.Label(frame, text="正常(0.0MΩ)")
|
|
self.high_vol_a_insulation.grid(row=16, column=3, sticky=tk.W)
|
|
|
|
# 电流值显示
|
|
current_labels = [
|
|
("动力母线电流(A):", "powerBusCurrent"),
|
|
("A母线电流(A):", "busbarACurrent"),
|
|
("DC/DC5模块电流(A):", "dcDc5ModuleCurrent"),
|
|
("推进电机控制箱电流(A):", "propulsionMotorControlBoxCurrent"),
|
|
("锂电池组表电流(A):", "lithiumBatteryGroupMeterCurrent"),
|
|
("艏高压配电箱电流(A):", "bowHighVoltageDistributionBoxCurrent"),
|
|
("艉FT设备45电流(A):", "sternFTDevice45Current"),
|
|
("TYZ备用开关电流(A):", "tyzReservedSwitchCurrent"),
|
|
("艉舵机开关1电流(A):", "sternRudderSwitch1Current"),
|
|
("艉舵机开关2电流(A):", "sternRudderSwitch2Current"),
|
|
("FB备用开关电流(A):", "fbReservedSwitchCurrent")
|
|
]
|
|
|
|
for i, (label, _) in enumerate(current_labels):
|
|
ttk.Label(frame, text=label).grid(row=17+i//2, column=(i%2)*2, sticky=tk.W)
|
|
label_var = ttk.Label(frame, text="0.0")
|
|
label_var.grid(row=17+i//2, column=(i%2)*2+1, sticky=tk.W)
|
|
setattr(self, f"high_vol_{current_labels[i][1]}", label_var)
|
|
|
|
# 冷却水压力
|
|
ttk.Label(frame, text="冷却水压力(MPa):").grid(row=23, column=0, sticky=tk.W)
|
|
self.high_vol_cool_water_pressure = ttk.Label(frame, text="0.00")
|
|
self.high_vol_cool_water_pressure.grid(row=23, column=1, sticky=tk.W)
|
|
|
|
def setup_high_a_vol_ui(self, parent):
|
|
"""设置高压A母线状态界面"""
|
|
frame = ttk.LabelFrame(parent, text="高压A母线状态")
|
|
frame.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
|
|
|
|
# 使用网格布局管理器
|
|
frame.grid_columnconfigure(0, weight=1)
|
|
frame.grid_columnconfigure(1, weight=1)
|
|
frame.grid_columnconfigure(2, weight=1)
|
|
|
|
# 电压显示 - 添加详细说明
|
|
ttk.Label(frame, text="高压B母线电压(V):").grid(row=0, column=0, sticky=tk.W)
|
|
self.high_a_vol_voltage = ttk.Label(frame, text="0.0")
|
|
self.high_a_vol_voltage.grid(row=0, column=1, sticky=tk.W)
|
|
|
|
# 电流显示 - 统一格式
|
|
ttk.Label(frame, text="高压B母线电流(A):").grid(row=1, column=0, sticky=tk.W)
|
|
self.high_a_vol_current = ttk.Label(frame, text="0.0")
|
|
self.high_a_vol_current.grid(row=1, column=1, sticky=tk.W)
|
|
|
|
ttk.Label(frame, text="艏部FT设备123电流(A):").grid(row=2, column=0, sticky=tk.W)
|
|
self.high_a_vol_bow_ft_current = ttk.Label(frame, text="0.0")
|
|
self.high_a_vol_bow_ft_current.grid(row=2, column=1, sticky=tk.W)
|
|
|
|
ttk.Label(frame, text="执行机构工作电流(A):").grid(row=3, column=0, sticky=tk.W)
|
|
self.high_a_vol_actuator_current = ttk.Label(frame, text="0.0")
|
|
self.high_a_vol_actuator_current.grid(row=3, column=1, sticky=tk.W)
|
|
|
|
# 断路器状态 - 添加详细说明
|
|
ttk.Label(frame, text="高压A母线断路器状态:").grid(row=4, column=0, columnspan=4, sticky=tk.W)
|
|
self.high_a_vol_breakers = {}
|
|
breaker_names = list(self.status_data["high_a_vol_bus"]["breakers"].keys())
|
|
|
|
for i, name in enumerate(breaker_names):
|
|
ttk.Label(frame, text=f"{name}状态:").grid(row=5+i//2, column=(i%2)*2, sticky=tk.W)
|
|
canvas = tk.Canvas(frame, width=20, height=20, bg="white")
|
|
canvas.grid(row=5+i//2, column=(i%2)*2+1, sticky=tk.W)
|
|
self.high_a_vol_breakers[name] = canvas
|
|
|
|
# 报警状态 - 更详细描述
|
|
ttk.Label(frame, text="仪表电源故障状态:").grid(row=8, column=0, sticky=tk.W)
|
|
self.high_a_vol_instrument_power_fault = ttk.Label(frame, text="正常")
|
|
self.high_a_vol_instrument_power_fault.grid(row=8, column=1, sticky=tk.W)
|
|
|
|
ttk.Label(frame, text="应急电源故障状态:").grid(row=8, column=2, sticky=tk.W)
|
|
self.high_a_vol_emergency_power_fault = ttk.Label(frame, text="正常")
|
|
self.high_a_vol_emergency_power_fault.grid(row=8, column=3, sticky=tk.W)
|
|
|
|
ttk.Label(frame, text="进水报警:").grid(row=9, column=0, sticky=tk.W)
|
|
self.high_a_vol_water_alarm = ttk.Label(frame, text="无")
|
|
self.high_a_vol_water_alarm.grid(row=9, column=1, sticky=tk.W)
|
|
|
|
def process_udp_message(self, data):
|
|
"""处理接收到的UDP消息"""
|
|
try:
|
|
msg_id = int.from_bytes(data[2:4], byteorder='little')
|
|
|
|
if msg_id == 0x0005: # 高压母线状态
|
|
msg = msg_disHighVolBusFbMsg()
|
|
if msg.unpack(data):
|
|
bus = self.status_data["high_vol_bus"]
|
|
bus["voltage"]["动力母线电压"] = msg.powerBusVoltage / 10.0
|
|
bus["voltage"]["A母线电压"] = msg.busbarAVoltage / 10.0
|
|
bus["current"]["动力母线电流"] = msg.powerBusCurrent / 10.0
|
|
bus["current"]["DC/DC5模块电流"] = msg.dcDc5ModuleCurrent / 10.0
|
|
bus["current"]["推进电机控制箱电流"] = msg.propulsionMotorControlBoxCurrent / 10.0
|
|
bus["current"]["A母线电流"] = msg.busbarACurrent / 10.0
|
|
bus["current"]["锂电池组仪表电流"] = msg.lithiumBatteryGroupMeterCurrent / 10.0
|
|
bus["current"]["艏高压配电盒电流"] = msg.bowHighVoltageDistributionBoxCurrent / 10.0
|
|
bus["current"]["艉FT设备45电流"] = msg.sternFTDevice45Current / 10.0
|
|
bus["current"]["TYZ备用开关电流"] = msg.tyzReservedSwitchCurrent / 10.0
|
|
bus["current"]["艉舵机开关1电流"] = msg.sternRudderSwitch1Current / 10.0
|
|
bus["current"]["备用电流1"] = msg.reservedCurrent1 / 10.0
|
|
bus["current"]["艉舵机开关2电流"] = msg.sternRudderSwitch2Current / 10.0
|
|
bus["current"]["备用电流2"] = msg.reservedCurrent2 / 10.0
|
|
bus["current"]["FB备用开关电流"] = msg.fbReservedSwitchCurrent / 10.0
|
|
bus["current"]["备用电流3"] = msg.reservedCurrent3 / 10.0
|
|
|
|
bus["breakers"]["燃料电池断路器"] = msg.fuelCellCircuitBreaker
|
|
bus["breakers"]["动力锂电池断路器"] = msg.powerLithiumBatteryCircuitBreaker
|
|
bus["breakers"]["推进电机断路器"] = msg.propulsionMotorCircuitBreaker
|
|
bus["breakers"]["锂电池组仪表断路器"] = msg.lithiumBatteryGroupInstrumentCircuitBreaker
|
|
bus["breakers"]["DC/DC模块断路器"] = msg.dcDc5ModuleCircuitBreaker
|
|
bus["breakers"]["艏高压配电盒断路器"] = msg.bowHighVoltageDistributionBoxCircuitBreaker
|
|
bus["breakers"]["艉FT设备45断路器"] = msg.sternFTDevice45CircuitBreaker
|
|
bus["breakers"]["艉舵机开关1断路器"] = msg.sternRudderSwitch1CircuitBreaker
|
|
bus["breakers"]["艉舵机开关2断路器"] = msg.sternRudderSwitch2CircuitBreaker
|
|
bus["breakers"]["FB备用断路器"] = msg.fbReservedCircuitBreaker
|
|
bus["breakers"]["TYZ备用断路器"] = msg.tyzReservedCircuitBreaker
|
|
bus["breakers"]["备用断路器"] = msg.reservedCircuitBreaker
|
|
|
|
bus["faults"]["DC/DC故障1"] = msg.dcDcFaultWord1
|
|
bus["faults"]["DC/DC故障2"] = msg.dcDcFaultWord2
|
|
bus["insulation"]["动力母线绝缘状态"] = msg.powerBusInsulationStatus
|
|
bus["insulation"]["A母线绝缘状态"] = msg.aBusInsulationStatus
|
|
bus["alarms"]["仪表电源丢失信号"] = msg.meterPowerLossSignal
|
|
bus["alarms"]["应急电源丢失信号"] = msg.emergencyPowerLossSignal
|
|
bus["cool_water_pressure"] = msg.coolWaterPressure / 10.0
|
|
|
|
# 更新UI显示
|
|
self.update_high_vol_ui(bus)
|
|
self.log_message("收到高压母线状态更新")
|
|
|
|
elif msg_id == 0x0006: # 高压A母线状态
|
|
msg = msg_disHighAVolBusFbMsg()
|
|
if msg.unpack(data):
|
|
bus = self.status_data["high_a_vol_bus"]
|
|
bus["voltage"]["B母线电压"] = msg.busbarBVoltage / 10.0
|
|
bus["current"]["B母线电流"] = msg.busbarBCurrent / 10.0
|
|
bus["current"]["艏FT设备123电流"] = msg.bowFTDevice123Current / 10.0
|
|
bus["current"]["执行机构电流"] = msg.actuatorCurrent / 10.0
|
|
bus["current"]["桅舵机控制箱电流"] = msg.mastSteeringGearControlBoxCurrent / 10.0
|
|
bus["current"]["XCZ电流"] = msg.xczCurrent / 10.0
|
|
bus["current"]["艏舵控制箱电流"] = msg.bowRudderControlBoxCurrent / 10.0
|
|
bus["current"]["开盖启动气缸电流"] = msg.openWaterCoverStartCylinderCurrent / 10.0
|
|
|
|
bus["breakers"]["艏FT设备123断路器"] = msg.bowFTDevice123CircuitBreaker
|
|
bus["breakers"]["执行机构断路器"] = msg.actuatorCircuitBreaker
|
|
bus["breakers"]["桅舵机控制箱断路器"] = msg.mastSteeringGearControlBoxCircuitBreaker
|
|
bus["breakers"]["XCZ断路器"] = msg.xczCircuitBreaker
|
|
bus["breakers"]["艏舵控制箱断路器"] = msg.bowRudderControlBoxCircuitBreaker
|
|
bus["breakers"]["开盖启动气缸断路器"] = msg.openWaterCoverStartCylinderCircuitBreaker
|
|
|
|
bus["alarms"]["仪表电源故障"] = msg.instrumentPowerFailureSignal
|
|
bus["alarms"]["应急电源故障"] = msg.emergencyPowerFailureSignal
|
|
bus["alarms"]["进水报警"] = msg.waterIngressionAlarm
|
|
|
|
self.log_message("收到高压A母线状态更新")
|
|
|
|
elif msg_id == 0x0007: # 仪表主母线状态
|
|
msg = msg_disLowMainBusFbMsg()
|
|
if msg.unpack(data):
|
|
bus = self.status_data["low_main_bus"]
|
|
bus["voltage"]["仪表母线电压"] = msg.instrumentBusbarVoltage / 10.0
|
|
bus["voltage"]["应急2母线电压"] = msg.emergency2BusbarVoltage / 10.0
|
|
bus["current"]["艏低压配电盒电流"] = msg.bowLowVoltageDistributionBoxCurrent / 10.0
|
|
bus["current"]["DC/C1仪表48V电流"] = msg.dcC1InstrumentDC48VCurrent / 10.0
|
|
bus["current"]["备用电流1"] = msg.reservedCurrent1 / 10.0
|
|
bus["current"]["应急锂电池组2电流"] = msg.emergencyLithiumBatteryGroup2Current / 10.0
|
|
bus["current"]["锂电池组仪表电流"] = msg.lithiumBatteryGroupInstrumentCurrent / 10.0
|
|
bus["current"]["单元4仪表48V电流"] = msg.unit4InstrumentDC48VCurrent / 10.0
|
|
bus["current"]["备用电流2"] = msg.reservedCurrent2 / 10.0
|
|
bus["current"]["综合能量管理系统应急DC48V电流"] = msg.compositeEnergyManagementSystemEmergencyDC48VCurrent / 10.0
|
|
bus["current"]["燃料电池安全系统应急DC48V电流"] = msg.fuelCellSecuritySystemEmergencyDC48VCurrent / 10.0
|
|
bus["current"]["PLC控制电源电流"] = msg.plcControlPowerCurrent / 10.0
|
|
|
|
bus["breakers"]["锂电池组仪表断路器"] = msg.lithiumBatteryGroupInstrumentCircuitBreaker
|
|
bus["breakers"]["艏低压配电盒断路器"] = msg.bowLowVoltageDistributionBoxCircuitBreaker
|
|
bus["breakers"]["单元4仪表48V断路器"] = msg.unit4InstrumentDC48VCircuitBreaker
|
|
bus["breakers"]["DC/C1直流配电板断路器"] = msg.dcC1DCDistributionPanelCircuitBreaker
|
|
bus["breakers"]["备用断路器1"] = msg.reservedCircuitBreaker1
|
|
bus["breakers"]["备用断路器2"] = msg.reservedCircuitBreaker2
|
|
bus["breakers"]["应急锂电池组2断路器"] = msg.emergencyLithiumBatteryGroup2CircuitBreaker
|
|
|
|
bus["alarms"]["仪表电源故障"] = msg.instrumentPowerFailureSignal
|
|
bus["alarms"]["应急电源故障"] = msg.emergencyPowerFailureSignal
|
|
bus["insulation"] = msg.instrumentBusbarInsulationLow
|
|
|
|
self.log_message("收到仪表主母线状态更新")
|
|
|
|
elif msg_id == 0x0008: # 仪表母线状态
|
|
msg = msg_disLowBusFbMsg()
|
|
if msg.unpack(data):
|
|
bus = self.status_data["low_bus"]
|
|
bus["voltage"]["仪表母线电压"] = msg.instrumentBusbarVoltage / 10.0
|
|
bus["voltage"]["应急1母线电压"] = msg.emergency1BusbarVoltage / 10.0
|
|
bus["current"]["仪表母线电流"] = msg.instrumentBusbarCurrent / 10.0
|
|
bus["current"]["单元1电流"] = msg.unit1Current / 10.0
|
|
bus["current"]["单元2电流"] = msg.unit2Current / 10.0
|
|
bus["current"]["单元3电流"] = msg.unit3Current / 10.0
|
|
bus["current"]["单元5电流"] = msg.unit5Current / 10.0
|
|
bus["current"]["艏PZ设备电流"] = msg.bowPZDeviceCurrent / 10.0
|
|
bus["current"]["应急锂电池组1电流"] = msg.emergencyLithiumBatteryGroup1Current / 10.0
|
|
|
|
bus["breakers"]["单元1断路器"] = msg.unit1CircuitBreaker
|
|
bus["breakers"]["单元2断路器"] = msg.unit2CircuitBreaker
|
|
bus["breakers"]["单元3断路器"] = msg.unit3CircuitBreaker
|
|
bus["breakers"]["单元5断路器"] = msg.unit5CircuitBreaker
|
|
bus["breakers"]["艏PZ设备断路器"] = msg.bowPZDeviceCircuitBreaker
|
|
bus["breakers"]["备用断路器1"] = msg.reservedCircuitBreaker1
|
|
bus["breakers"]["备用断路器2"] = msg.reservedCircuitBreaker2
|
|
bus["breakers"]["应急锂电池组1断路器"] = msg.emergencyLithiumBatteryGroup1CircuitBreaker
|
|
|
|
bus["alarms"]["电源故障信号"] = msg.powerFailureSignal
|
|
bus["alarms"]["进水报警"] = msg.waterIngressionAlarm
|
|
|
|
self.log_message("收到仪表母线状态更新")
|
|
|
|
except Exception as e:
|
|
self.log_message(f"消息处理错误: {str(e)}")
|
|
|
|
def update_high_vol_ui(self, status):
|
|
"""更新高压母线UI显示"""
|
|
# 更新电压值
|
|
self.high_vol_power_voltage.config(text=f"{status['voltage']['动力母线电压']:.1f}")
|
|
self.high_vol_a_voltage.config(text=f"{status['voltage']['A母线电压']:.1f}")
|
|
|
|
# 更新故障位显示
|
|
for i in range(8):
|
|
color = "red" if (status['faults']['DC/DC故障1'] & (1 << i)) else "green"
|
|
self.high_vol_dcdc_fault1_bits[i].delete("all")
|
|
self.high_vol_dcdc_fault1_bits[i].create_oval(2, 2, 18, 18, fill=color)
|
|
|
|
color = "red" if (status['faults']['DC/DC故障2'] & (1 << i)) else "green"
|
|
self.high_vol_dcdc_fault2_bits[i].delete("all")
|
|
self.high_vol_dcdc_fault2_bits[i].create_oval(2, 2, 18, 18, fill=color)
|
|
|
|
# 更新绝缘状态
|
|
power_insul = "正常" if status['insulation']['动力母线绝缘状态'] == 0 else "异常"
|
|
a_insul = "正常" if status['insulation']['A母线绝缘状态'] == 0 else "异常"
|
|
self.high_vol_power_insulation.config(text=f"{power_insul}")
|
|
self.high_vol_a_insulation.config(text=f"{a_insul}")
|
|
|
|
# 更新电流值
|
|
for current_name in status['current']:
|
|
if hasattr(self, f"high_vol_{current_name}"):
|
|
getattr(self, f"high_vol_{current_name}").config(text=f"{status['current'][current_name]:.1f}")
|
|
|
|
# 更新冷却水压力
|
|
self.high_vol_cool_water_pressure.config(text=f"{status['cool_water_pressure']:.2f}")
|
|
|
|
def setup_low_main_ui(self, parent):
|
|
"""设置仪表主母线状态界面"""
|
|
frame = ttk.LabelFrame(parent, text="仪表主母线状态")
|
|
frame.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
|
|
|
|
# 电压显示
|
|
ttk.Label(frame, text="仪表母线电压(V):").grid(row=0, column=0, sticky=tk.W)
|
|
self.low_main_instrument_voltage = ttk.Label(frame, text="0.0")
|
|
self.low_main_instrument_voltage.grid(row=0, column=1, sticky=tk.W)
|
|
|
|
ttk.Label(frame, text="应急2母线电压(V):").grid(row=0, column=2, sticky=tk.W)
|
|
self.low_main_emergency2_voltage = ttk.Label(frame, text="0.0")
|
|
self.low_main_emergency2_voltage.grid(row=0, column=3, sticky=tk.W)
|
|
|
|
# 电流显示
|
|
ttk.Label(frame, text="艏低压配电盒电流(A):").grid(row=1, column=0, sticky=tk.W)
|
|
self.low_main_bow_current = ttk.Label(frame, text="0.0")
|
|
self.low_main_bow_current.grid(row=1, column=1, sticky=tk.W)
|
|
|
|
ttk.Label(frame, text="锂电池组仪表电流(A):").grid(row=1, column=2, sticky=tk.W)
|
|
self.low_main_battery_current = ttk.Label(frame, text="0.0")
|
|
self.low_main_battery_current.grid(row=1, column=3, sticky=tk.W)
|
|
|
|
# 断路器状态
|
|
ttk.Label(frame, text="断路器状态:").grid(row=2, column=0, columnspan=4, sticky=tk.W)
|
|
self.low_main_breakers = {}
|
|
breaker_names = list(self.status_data["low_main_bus"]["breakers"].keys())
|
|
|
|
for i, name in enumerate(breaker_names):
|
|
row = 3 + i//2
|
|
col = (i%2)*2
|
|
ttk.Label(frame, text=name).grid(row=row, column=col, sticky=tk.W)
|
|
canvas = tk.Canvas(frame, width=20, height=20, bg="white")
|
|
canvas.grid(row=row, column=col+1, sticky=tk.W)
|
|
self.low_main_breakers[name] = canvas
|
|
|
|
# 报警状态
|
|
ttk.Label(frame, text="仪表电源故障:").grid(row=8, column=0, sticky=tk.W)
|
|
self.low_main_instrument_fault = ttk.Label(frame, text="无")
|
|
self.low_main_instrument_fault.grid(row=8, column=1, sticky=tk.W)
|
|
|
|
ttk.Label(frame, text="应急电源故障:").grid(row=8, column=2, sticky=tk.W)
|
|
self.low_main_emergency_fault = ttk.Label(frame, text="无")
|
|
self.low_main_emergency_fault.grid(row=8, column=3, sticky=tk.W)
|
|
|
|
# 报警状态
|
|
ttk.Label(frame, text="仪表电源故障:").grid(row=8, column=0, sticky=tk.W)
|
|
self.low_main_instrument_fault = ttk.Label(frame, text="无")
|
|
self.low_main_instrument_fault.grid(row=8, column=1, sticky=tk.W)
|
|
|
|
ttk.Label(frame, text="应急电源故障:").grid(row=8, column=2, sticky=tk.W)
|
|
self.low_main_emergency_fault = ttk.Label(frame, text="无")
|
|
self.low_main_emergency_fault.grid(row=8, column=3, sticky=tk.W)
|
|
|
|
# 绝缘状态
|
|
ttk.Label(frame, text="绝缘状态:").grid(row=9, column=0, sticky=tk.W)
|
|
self.low_main_insulation = ttk.Label(frame, text="正常")
|
|
self.low_main_insulation.grid(row=9, column=1, sticky=tk.W)
|
|
|
|
return frame
|
|
|
|
def setup_low_bus_ui(self, parent):
|
|
"""设置仪表母线状态界面"""
|
|
frame = ttk.LabelFrame(parent, text="仪表母线状态")
|
|
frame.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
|
|
|
|
# 电压显示
|
|
ttk.Label(frame, text="仪表母线电压(V):").grid(row=0, column=0, sticky=tk.W)
|
|
self.low_bus_instrument_voltage = ttk.Label(frame, text="0.0")
|
|
self.low_bus_instrument_voltage.grid(row=0, column=1, sticky=tk.W)
|
|
|
|
ttk.Label(frame, text="应急1母线电压(V):").grid(row=0, column=2, sticky=tk.W)
|
|
self.low_bus_emergency1_voltage = ttk.Label(frame, text="0.0")
|
|
self.low_bus_emergency1_voltage.grid(row=0, column=3, sticky=tk.W)
|
|
|
|
# 电流显示
|
|
ttk.Label(frame, text="单元1电流(A):").grid(row=1, column=0, sticky=tk.W)
|
|
self.low_bus_unit1_current = ttk.Label(frame, text="0.0")
|
|
self.low_bus_unit1_current.grid(row=1, column=1, sticky=tk.W)
|
|
|
|
ttk.Label(frame, text="单元2电流(A):").grid(row=1, column=2, sticky=tk.W)
|
|
self.low_bus_unit2_current = ttk.Label(frame, text="0.0")
|
|
self.low_bus_unit2_current.grid(row=1, column=3, sticky=tk.W)
|
|
|
|
# 断路器状态
|
|
ttk.Label(frame, text="断路器状态:").grid(row=2, column=0, columnspan=4, sticky=tk.W)
|
|
self.low_bus_breakers = {}
|
|
breaker_names = list(self.status_data["low_bus"]["breakers"].keys())
|
|
|
|
for i, name in enumerate(breaker_names):
|
|
row = 3 + i//2
|
|
col = (i%2)*2
|
|
ttk.Label(frame, text=name).grid(row=row, column=col, sticky=tk.W)
|
|
canvas = tk.Canvas(frame, width=20, height=20, bg="white")
|
|
canvas.grid(row=row, column=col+1, sticky=tk.W)
|
|
self.low_bus_breakers[name] = canvas
|
|
|
|
# 报警状态
|
|
ttk.Label(frame, text="电源故障信号:").grid(row=8, column=0, sticky=tk.W)
|
|
self.low_bus_power_fault = ttk.Label(frame, text="无")
|
|
self.low_bus_power_fault.grid(row=8, column=1, sticky=tk.W)
|
|
|
|
ttk.Label(frame, text="进水报警:").grid(row=8, column=2, sticky=tk.W)
|
|
self.low_bus_water_alarm = ttk.Label(frame, text="无")
|
|
self.low_bus_water_alarm.grid(row=8, column=3, sticky=tk.W)
|
|
|
|
# 报警状态
|
|
ttk.Label(frame, text="电源故障信号:").grid(row=8, column=0, sticky=tk.W)
|
|
self.low_bus_power_fault = ttk.Label(frame, text="无")
|
|
self.low_bus_power_fault.grid(row=8, column=1, sticky=tk.W)
|
|
|
|
ttk.Label(frame, text="进水报警:").grid(row=8, column=2, sticky=tk.W)
|
|
self.low_bus_water_alarm = ttk.Label(frame, text="无")
|
|
self.low_bus_water_alarm.grid(row=8, column=3, sticky=tk.W)
|
|
|
|
return frame
|
|
|
|
def send_udp_command(self, data):
|
|
"""发送UDP命令"""
|
|
try:
|
|
self.sock.sendto(data, (self.udp_ip, self.udp_port + 1))
|
|
except Exception as e:
|
|
self.log_message(f"发送命令失败: {str(e)}")
|
|
|
|
def update_ui(self):
|
|
"""更新界面状态"""
|
|
# 更新高压母线状态
|
|
high_vol = self.status_data["high_vol_bus"]
|
|
self.high_vol_power_voltage.config(text=f"{high_vol['voltage']['动力母线电压']:.1f} V")
|
|
self.high_vol_a_voltage.config(text=f"{high_vol['voltage']['A母线电压']:.1f} V")
|
|
self.high_vol_power_current.config(text=f"{high_vol['current']['动力母线电流']:.1f} A")
|
|
self.high_vol_a_current.config(text=f"{high_vol['current']['A母线电流']:.1f} A")
|
|
|
|
for name, canvas in self.high_vol_breakers.items():
|
|
state = high_vol["breakers"].get(name, 0)
|
|
color = "green" if state else "red"
|
|
canvas.create_oval(2, 2, 18, 18, fill=color, outline="black")
|
|
|
|
self.high_vol_power_insulation.config(
|
|
text="正常" if high_vol["insulation"]["动力母线绝缘状态"] == 0 else "异常"
|
|
)
|
|
self.high_vol_a_insulation.config(
|
|
text="正常" if high_vol["insulation"]["A母线绝缘状态"] == 0 else "异常"
|
|
)
|
|
|
|
faults = []
|
|
if high_vol["faults"]["DC/DC故障1"]:
|
|
faults.append("DC/DC故障1")
|
|
if high_vol["faults"]["DC/DC故障2"]:
|
|
faults.append("DC/DC故障2")
|
|
|
|
# 更新故障位显示
|
|
for i in range(8):
|
|
color = "red" if (high_vol["faults"]["DC/DC故障1"] & (1 << i)) else "green"
|
|
self.high_vol_dcdc_fault1_bits[i].delete("all")
|
|
self.high_vol_dcdc_fault1_bits[i].create_oval(2, 2, 18, 18, fill=color)
|
|
|
|
color = "red" if (high_vol["faults"]["DC/DC故障2"] & (1 << i)) else "green"
|
|
self.high_vol_dcdc_fault2_bits[i].delete("all")
|
|
self.high_vol_dcdc_fault2_bits[i].create_oval(2, 2, 18, 18, fill=color)
|
|
|
|
# 更新高压A母线状态
|
|
high_a_vol = self.status_data["high_a_vol_bus"]
|
|
self.high_a_vol_voltage.config(text=f"{high_a_vol['voltage']['B母线电压']:.1f} V")
|
|
self.high_a_vol_current.config(text=f"{high_a_vol['current']['B母线电流']:.1f} A")
|
|
|
|
for name, canvas in self.high_a_vol_breakers.items():
|
|
state = high_a_vol["breakers"].get(name, 0)
|
|
color = "green" if state else "red"
|
|
canvas.create_oval(2, 2, 18, 18, fill=color, outline="black")
|
|
|
|
# 更新仪表主母线状态
|
|
low_main = self.status_data["low_main_bus"]
|
|
for name, canvas in self.low_main_breakers.items():
|
|
state = low_main["breakers"].get(name, 0)
|
|
color = "green" if state else "red"
|
|
canvas.create_oval(2, 2, 18, 18, fill=color, outline="black")
|
|
|
|
# 更新仪表母线状态
|
|
low_bus = self.status_data["low_bus"]
|
|
for name, canvas in self.low_bus_breakers.items():
|
|
state = low_bus["breakers"].get(name, 0)
|
|
color = "green" if state else "red"
|
|
canvas.create_oval(2, 2, 18, 18, fill=color, outline="black")
|
|
|
|
self.high_a_vol_instrument_power_fault.config(
|
|
text="无" if not high_a_vol["alarms"]["仪表电源故障"] else "有"
|
|
)
|
|
self.high_a_vol_emergency_power_fault.config(
|
|
text="无" if not high_a_vol["alarms"]["应急电源故障"] else "有"
|
|
)
|
|
self.high_a_vol_water_alarm.config(
|
|
text="无" if not high_a_vol["alarms"]["进水报警"] else "有"
|
|
)
|
|
|
|
# 更新仪表主母线状态
|
|
low_main = self.status_data["low_main_bus"]
|
|
self.low_main_instrument_voltage.config(text=f"{low_main['voltage']['仪表母线电压']:.1f}")
|
|
self.low_main_emergency2_voltage.config(text=f"{low_main['voltage']['应急2母线电压']:.1f}")
|
|
self.low_main_bow_current.config(text=f"{low_main['current']['艏低压配电盒电流']:.1f}")
|
|
self.low_main_battery_current.config(text=f"{low_main['current']['锂电池组仪表电流']:.1f}")
|
|
|
|
for name, canvas in self.low_main_breakers.items():
|
|
state = low_main["breakers"].get(name, 0)
|
|
color = "green" if state else "red"
|
|
canvas.create_oval(2, 2, 18, 18, fill=color, outline="black")
|
|
|
|
self.low_main_instrument_fault.config(
|
|
text="无" if not low_main["alarms"]["仪表电源故障"] else "有"
|
|
)
|
|
self.low_main_emergency_fault.config(
|
|
text="无" if not low_main["alarms"]["应急电源故障"] else "有"
|
|
)
|
|
self.low_main_insulation.config(
|
|
text="正常" if not low_main["insulation"] else "异常"
|
|
)
|
|
|
|
# 更新仪表母线状态
|
|
low_bus = self.status_data["low_bus"]
|
|
self.low_bus_instrument_voltage.config(text=f"{low_bus['voltage']['仪表母线电压']:.1f}")
|
|
self.low_bus_emergency1_voltage.config(text=f"{low_bus['voltage']['应急1母线电压']:.1f}")
|
|
self.low_bus_unit1_current.config(text=f"{low_bus['current']['单元1电流']:.1f}")
|
|
self.low_bus_unit2_current.config(text=f"{low_bus['current']['单元2电流']:.1f}")
|
|
|
|
for name, canvas in self.low_bus_breakers.items():
|
|
state = low_bus["breakers"].get(name, 0)
|
|
color = "green" if state else "red"
|
|
canvas.create_oval(2, 2, 18, 18, fill=color, outline="black")
|
|
|
|
self.low_bus_power_fault.config(
|
|
text="无" if not low_bus["alarms"]["电源故障信号"] else "有"
|
|
)
|
|
self.low_bus_water_alarm.config(
|
|
text="无" if not low_bus["alarms"]["进水报警"] else "有"
|
|
)
|
|
|
|
# 每500ms更新一次
|
|
self.root.after(500, self.update_ui)
|
|
|
|
def log_message(self, message):
|
|
"""记录日志消息"""
|
|
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
|
self.log_text.config(state=tk.NORMAL)
|
|
self.log_text.insert(tk.END, f"[{timestamp}] {message}\n")
|
|
self.log_text.config(state=tk.DISABLED)
|
|
self.log_text.see(tk.END)
|
|
|
|
def on_closing(self):
|
|
"""窗口关闭事件处理"""
|
|
self.running = False
|
|
self.sock.close()
|
|
self.root.destroy()
|
|
if __name__ == "__main__":
|
|
root = tk.Tk()
|
|
app = PowerManagerApp(root)
|
|
|
|
root.protocol("WM_DELETE_WINDOW", app.on_closing)
|
|
root.mainloop()
|
|
while True:
|
|
app.status_data["high_vol_bus"]["voltage"]["动力母线电压"] += 0.1
|
|
app.status_data["high_vol_bus"]["voltage"]["A母线电压"] += 0.1
|
|
app.status_data["high_vol_bus"]["current"]["动力母线电流"] += 0.1
|
|
app.status_data["high_vol_bus"]["current"]["A母线电流"] += 0.1
|
|
# app.status_data["insulation"]["动力母线绝缘状态"] =0
|
|
app.status_data["high_vol_bus"]["insulation"]["A母线绝缘状态"] = 1
|
|
app.status_data["high_vol_bus"]["faults"]["DC/DC故障1"] = 1
|
|
app.status_data["high_vol_bus"]["faults"]["DC/DC故障2"] = 1
|
|
app.status_data["high_vol_bus"]["breakers"]["燃料电池断路器"] = 1
|
|
app.status_data["high_vol_bus"]["breakers"]["动力锂电池断路器"] = 1
|
|
app.status_data["high_vol_bus"]["breakers"]["推进电机断路器"] = 1
|
|
app.status_data["high_vol_bus"]["breakers"]["锂电池组仪表断路器"] = 1
|
|
app.update_ui()
|
|
time.sleep(1)
|
|
pass
|