1. 增加无网络环境使用的逻辑 2. 优化EC指令发送的逻辑

This commit is contained in:
gitea 2025-03-31 11:21:13 +08:00
parent 676eb49679
commit 671db5b1db
5 changed files with 86 additions and 73 deletions

39
aio.py
View File

@ -4,7 +4,6 @@ import os
import re import re
import sqlite3 import sqlite3
import sys import sys
import threading
import time import time
from urllib import request from urllib import request
import os.path import os.path
@ -12,11 +11,10 @@ import matplotlib
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import pandas import pandas
from matplotlib.widgets import Slider from matplotlib.widgets import Slider
matplotlib.use('QtAgg')
from PySide6.QtCore import Qt, QThread, Signal, QObject, QTimer from PySide6.QtCore import Qt, QThread, Signal, QObject, QTimer
from PySide6.QtGui import QTextCursor, QFont, QPixmap, QColor, QBrush, QIcon from PySide6.QtGui import QTextCursor, QFont, QPixmap, QColor, QBrush, QIcon
from PySide6.QtWidgets import QMessageBox, QCheckBox, QSplashScreen, QApplication, QFrame, QLabel, QTreeWidgetItem, QFileDialog, QHeaderView, QDialog, QVBoxLayout, QPlainTextEdit from PySide6.QtWidgets import QMessageBox, QCheckBox, QSplashScreen, QApplication, QLabel, QTreeWidgetItem, QFileDialog, QHeaderView, QDialog, QVBoxLayout, QPlainTextEdit
import codes.common.clibs as clibs import codes.common.clibs as clibs
import codes.common.openapi as openapi import codes.common.openapi as openapi
@ -24,6 +22,7 @@ import codes.ui.main_window as main_window
from codes.analysis import brake, current, wavelogger, iso from codes.analysis import brake, current, wavelogger, iso
from codes.autotest import do_current, do_brake from codes.autotest import do_current, do_brake
from codes.durable import factory_test from codes.durable import factory_test
matplotlib.use('QtAgg')
class ContentDialog(QDialog): class ContentDialog(QDialog):
@ -135,6 +134,10 @@ class MainWindow(main_window.Ui_MainWindow):
self.run = RunProg() self.run = RunProg()
self.run.moveToThread(self.t) self.run.moveToThread(self.t)
self.run.completed.connect(prog_done) self.run.completed.connect(prog_done)
try:
self.action.disconnect()
except TypeError:
pass
self.action.connect(self.run.program) self.action.connect(self.run.program)
self.t.start() self.t.start()
self.action.emit((prog, idx, reserved)) self.action.emit((prog, idx, reserved))
@ -447,7 +450,7 @@ class MainWindow(main_window.Ui_MainWindow):
self.run_program_thread(do_next, -98, self.prog_done_next, None) self.run_program_thread(do_next, -98, self.prog_done_next, None)
def show_item_content(self, item, column): def show_item_content(self, item, column):
content = " | ".join([item.text(i) for i in range(self.treew_log.columnCount())]) content = "\n".join([item.text(i) for i in range(self.treew_log.columnCount())])
dialog = ContentDialog(content, self) dialog = ContentDialog(content, self)
dialog.exec() dialog.exec()
@ -880,9 +883,9 @@ class MainWindow(main_window.Ui_MainWindow):
return return
elif content[0].strip().startswith("ctrl"): elif content[0].strip().startswith("ctrl"):
for item in content[1:]: for item in content[1:]:
try:
addr = int(item.split(":")[0].strip()) addr = int(item.split(":")[0].strip())
value = int(item.split(":")[1].strip()) value = int(item.split(":")[1].strip())
try:
clibs.c_md.c.write_register(addr, value) clibs.c_md.c.write_register(addr, value)
time.sleep(clibs.INTERVAL/4) time.sleep(clibs.INTERVAL/4)
except Exception as err: except Exception as err:
@ -893,20 +896,27 @@ class MainWindow(main_window.Ui_MainWindow):
else: else:
QMessageBox.critical(self, "格式错误", "非法的发送内容,自定义发送需参考已有的格式!") QMessageBox.critical(self, "格式错误", "非法的发送内容,自定义发送需参考已有的格式!")
def prog_done_ec_send(self, results):
flag, result, ret, error, idx, cmd = results
print(f"res = {results}")
if ret[1] == "error":
clibs.logger("ERROR", "openapi", f"{ret[0]}", "red")
else:
self.pte_ec_recv.appendPlainText(str(ret))
def ec_send(self): def ec_send(self):
def ec_send_thread():
return clibs.c_ec.sr_string(cmd)
if clibs.status["ec"] == 0: if clibs.status["ec"] == 0:
QMessageBox.critical(self, "错误", "使用该功能之前,需要先打开 EC 连接!") QMessageBox.critical(self, "错误", "使用该功能之前,需要先打开 EC 连接!")
return return
if self.pte_ec_send.toPlainText() == "": if self.pte_ec_send.toPlainText() == "":
return return
self.pte_ec_recv.clear()
cmd = self.pte_ec_send.toPlainText().strip() cmd = self.pte_ec_send.toPlainText().strip()
try: self.pte_ec_recv.clear()
result = clibs.c_ec.sr_string(cmd) self.run_program_thread(ec_send_thread, -99, self.prog_done_ec_send, cmd)
self.pte_ec_recv.appendPlainText(str(result))
except Exception as err:
self.pte_ec_recv.appendPlainText(f"操作失败:{err}")
def hmi_cb_change(self): def hmi_cb_change(self):
cmd = self.cb_hmi_cmd.currentText() cmd = self.cb_hmi_cmd.currentText()
@ -1103,6 +1113,9 @@ class SplashScreen(QApplication):
self.splash.show() self.splash.show()
self.splash.showMessage("正在加载资源.....", Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignHCenter, Qt.GlobalColor.white) self.splash.showMessage("正在加载资源.....", Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignHCenter, Qt.GlobalColor.white)
with open(f"{clibs.PREFIX}/files/version/IS_VALIDATE", mode="r", encoding="utf-8") as f_validate:
is_validate = f_validate.read()
if is_validate == "1":
# with validation of server version # with validation of server version
self.t = QThread(self) self.t = QThread(self)
self.run = InitWork() self.run = InitWork()
@ -1111,9 +1124,9 @@ class SplashScreen(QApplication):
self.action.connect(self.run.program) self.action.connect(self.run.program)
self.t.start() self.t.start()
self.action.emit(1) self.action.emit(1)
else:
# without validation of server version # without validation of server version
# self.prog_done("true") self.prog_done("true")
def prog_done(self, result): def prog_done(self, result):
if result == "false" or result == "": if result == "false" or result == "":

View File

@ -0,0 +1 @@
1

View File

@ -2,8 +2,6 @@ import os
import os.path import os.path
import threading import threading
import sqlite3 import sqlite3
import time
from PySide6.QtCore import Signal, QThread from PySide6.QtCore import Signal, QThread

View File

@ -1753,7 +1753,7 @@ class ExternalCommunication(QThread):
clibs.c_hr.execution("socket.set_params", enable=True, ip="0.0.0.0", port=str(self.port), suffix="\r", type=1) clibs.c_hr.execution("socket.set_params", enable=True, ip="0.0.0.0", port=str(self.port), suffix="\r", type=1)
# time.sleep(clibs.INTERVAL*2) # time.sleep(clibs.INTERVAL*2)
self.c = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.c.settimeout(clibs.INTERVAL*5) self.c.settimeout(clibs.INTERVAL*3)
try: try:
self.c.connect((self.ip, self.port)) self.c.connect((self.ip, self.port))
self.logger("INFO", "openapi", f"ec: 外部通信连接成功...", "green") self.logger("INFO", "openapi", f"ec: 外部通信连接成功...", "green")
@ -1782,7 +1782,8 @@ class ExternalCommunication(QThread):
try: try:
char = self.c.recv(1).decode(encoding="unicode_escape") char = self.c.recv(1).decode(encoding="unicode_escape")
except Exception as err: except Exception as err:
self.logger("ERROR", "openapi", f"ec: 获取请求指令 {directive} 的返回数据超时,需确认指令发送格式以及内容正确!具体报错信息如下 {err}", "red") result = [f"ec: 获取请求指令 {directive} 的返回数据超时,需确认指令发送格式以及内容正确!具体报错信息如下 {err}", "error"]
return result
result = "".join([result, char]) result = "".join([result, char])
return result return result
@ -2033,6 +2034,7 @@ class PreDos(object):
self.ssh_port = ssh_port self.ssh_port = ssh_port
self.username = username self.username = username
self.password = password self.password = password
self.logger = clibs.logger
def __ssh2server(self): def __ssh2server(self):
try: try:
@ -2041,8 +2043,7 @@ class PreDos(object):
self.__ssh.connect(hostname=self.ip, port=self.ssh_port, username=self.username, password=self.password) self.__ssh.connect(hostname=self.ip, port=self.ssh_port, username=self.username, password=self.password)
self.__sftp = self.__ssh.open_sftp() self.__sftp = self.__ssh.open_sftp()
except Exception as err: except Exception as err:
print(f"predos: SSH 无法连接到 {self.ip}:{self.ssh_port},需检查网络连通性或者登录信息是否正确 {err}") self.logger("ERROR", "openapi", f"predos: SSH 无法连接到 {self.ip}:{self.ssh_port},需检查网络连通性或者登录信息是否正确 {err}", "red")
raise Exception("SshConnFailed")
def push_prj_to_server(self, prj_file): def push_prj_to_server(self, prj_file):
# prj_file本地工程完整路径 # prj_file本地工程完整路径

View File

@ -9,8 +9,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1006</width> <width>1004</width>
<height>568</height> <height>563</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -1846,8 +1846,8 @@
<slot>curve_draw()</slot> <slot>curve_draw()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>326</x> <x>700</x>
<y>80</y> <y>144</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>701</x> <x>701</x>
@ -1862,8 +1862,8 @@
<slot>durable_cb_change()</slot> <slot>durable_cb_change()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>326</x> <x>586</x>
<y>80</y> <y>142</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>546</x> <x>546</x>
@ -1878,8 +1878,8 @@
<slot>pre_page()</slot> <slot>pre_page()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>326</x> <x>408</x>
<y>266</y> <y>523</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>307</x> <x>307</x>
@ -1894,8 +1894,8 @@
<slot>realtime_page()</slot> <slot>realtime_page()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>326</x> <x>489</x>
<y>266</y> <y>523</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>435</x> <x>435</x>
@ -1910,8 +1910,8 @@
<slot>next_page()</slot> <slot>next_page()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>326</x> <x>570</x>
<y>266</y> <y>523</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>520</x> <x>520</x>
@ -1926,8 +1926,8 @@
<slot>search_keyword()</slot> <slot>search_keyword()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>326</x> <x>731</x>
<y>266</y> <y>523</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>688</x> <x>688</x>
@ -1942,8 +1942,8 @@
<slot>search_keyword()</slot> <slot>search_keyword()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>326</x> <x>837</x>
<y>266</y> <y>521</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>932</x> <x>932</x>
@ -1958,7 +1958,7 @@
<slot>hmi_cb_change()</slot> <slot>hmi_cb_change()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>475</x> <x>810</x>
<y>89</y> <y>89</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
@ -1974,7 +1974,7 @@
<slot>hmi_send()</slot> <slot>hmi_send()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>335</x> <x>891</x>
<y>89</y> <y>89</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
@ -1990,8 +1990,8 @@
<slot>hmi_page()</slot> <slot>hmi_page()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>326</x> <x>982</x>
<y>80</y> <y>85</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>744</x> <x>744</x>
@ -2006,8 +2006,8 @@
<slot>md_page()</slot> <slot>md_page()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>326</x> <x>982</x>
<y>80</y> <y>124</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>784</x> <x>784</x>
@ -2022,8 +2022,8 @@
<slot>ec_page()</slot> <slot>ec_page()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>326</x> <x>982</x>
<y>80</y> <y>163</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>969</x> <x>969</x>
@ -2038,8 +2038,8 @@
<slot>md_cb_change()</slot> <slot>md_cb_change()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>466</x> <x>808</x>
<y>80</y> <y>89</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>612</x> <x>612</x>
@ -2054,8 +2054,8 @@
<slot>md_send()</slot> <slot>md_send()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>326</x> <x>889</x>
<y>80</y> <y>89</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>795</x> <x>795</x>
@ -2086,7 +2086,7 @@
<slot>hmi_conn()</slot> <slot>hmi_conn()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>335</x> <x>545</x>
<y>89</y> <y>89</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
@ -2102,8 +2102,8 @@
<slot>md_conn()</slot> <slot>md_conn()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>326</x> <x>545</x>
<y>80</y> <y>89</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>398</x> <x>398</x>
@ -2123,7 +2123,7 @@
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>412</x> <x>412</x>
<y>-1</y> <y>0</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
@ -2134,12 +2134,12 @@
<slot>check_interval()</slot> <slot>check_interval()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>326</x> <x>637</x>
<y>80</y> <y>109</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>821</x> <x>821</x>
<y>-3</y> <y>0</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
@ -2155,7 +2155,7 @@
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>540</x> <x>540</x>
<y>-2</y> <y>0</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
@ -2166,8 +2166,8 @@
<slot>hmi_conn()</slot> <slot>hmi_conn()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>385</x> <x>464</x>
<y>89</y> <y>87</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>216</x> <x>216</x>
@ -2246,11 +2246,11 @@
<slot>file_browser()</slot> <slot>file_browser()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>326</x> <x>985</x>
<y>80</y> <y>75</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>1004</x> <x>1003</x>
<y>56</y> <y>56</y>
</hint> </hint>
</hints> </hints>
@ -2262,11 +2262,11 @@
<slot>file_browser()</slot> <slot>file_browser()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>326</x> <x>983</x>
<y>80</y> <y>76</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>1004</x> <x>1003</x>
<y>88</y> <y>88</y>
</hint> </hint>
</hints> </hints>