串口控制台根据文件后缀自动识别文件类型,其中配置文件为cfg.json,
方案文件后缀为scheme.json
This commit is contained in:
@@ -50,5 +50,8 @@
|
||||
2023.9.20
|
||||
updata添加dhcp功能,cfg.json 视为配置文件
|
||||
updata添加串口控制台功能,配合U盘,自动把文件复制到设备中
|
||||
2023.9.20
|
||||
串口控制台根据文件后缀自动识别文件类型,其中配置文件为cfg.json,
|
||||
方案文件后缀为scheme.json
|
||||
|
||||
|
||||
|
@@ -8,11 +8,13 @@ import threading
|
||||
import serial
|
||||
import serial.tools.list_ports
|
||||
import time
|
||||
import re
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
UPDATA_PATH="/run/media/sda/updata"
|
||||
# UPDATA_PATH="/"
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +26,8 @@ class console_dlg(QObject):
|
||||
QObject.__init__(self)
|
||||
self.ser=None
|
||||
self.cmd_list=[]
|
||||
self.ls_cmd=False
|
||||
self.file_list=[]
|
||||
self.w=QDialog(father)
|
||||
self.w.resize(1200,500)
|
||||
self.w.setWindowTitle(title)
|
||||
@@ -33,6 +37,14 @@ class console_dlg(QObject):
|
||||
self.text_init()
|
||||
self.com_but_init()
|
||||
self.runcmd_but_init()
|
||||
self.str_list=["ATK-MP157 login: root",
|
||||
"Booting fw image checker_m4.axf",
|
||||
"# ls",
|
||||
"root@ATK-MP157:",
|
||||
"removable disk",
|
||||
"cd: can't cd to "+UPDATA_PATH,
|
||||
"No such file or directory"
|
||||
]
|
||||
def text_init(self):
|
||||
self.console_text = QTextBrowser(self.w)
|
||||
self.console_text.setObjectName(u"str_list")
|
||||
@@ -81,7 +93,7 @@ class console_dlg(QObject):
|
||||
bsp=int(115200)
|
||||
self.ser = serial.Serial(port=com, baudrate=bsp,bytesize=serial.EIGHTBITS,parity=serial.PARITY_NONE,
|
||||
stopbits=serial.STOPBITS_ONE,timeout=None)
|
||||
print(str(self.ser))
|
||||
# print(str(self.ser))
|
||||
t = threading.Thread(target=self._recv, args=())
|
||||
t.start()
|
||||
except Exception as e:
|
||||
@@ -114,15 +126,22 @@ class console_dlg(QObject):
|
||||
self.ser.write(text.encode("utf-8")+b"\r\n")
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
# 添加文字到显示区
|
||||
def item_append(self,text:str):
|
||||
index,ack=self.type_of_str(text)
|
||||
if(index==0):
|
||||
print("linux started.")
|
||||
self.start_send_cmds()
|
||||
# self.start_send_cmds()
|
||||
elif(index==1):
|
||||
print("app started.")
|
||||
if(index!=-1):
|
||||
if(index==2):
|
||||
# 文件列表
|
||||
self.ls_cmd=True
|
||||
txt="<font color=blue>" +text+ "</font> <font color=black> </font>"
|
||||
else:
|
||||
if(self.ls_cmd==True):
|
||||
txt=self.decode_file_list(text)
|
||||
else:
|
||||
txt=text
|
||||
try:
|
||||
@@ -130,18 +149,45 @@ class console_dlg(QObject):
|
||||
self.console_text.moveCursor(QTextCursor.MoveOperation.End)
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
if((index==2) or (index==3))and (ack==True):
|
||||
if(index==3) and (ack==True):
|
||||
# 准备好接收下一个指令
|
||||
if(self.ls_cmd==True):
|
||||
self.ls_cmd=False
|
||||
self._pack_cmd_list()
|
||||
self.send_cmdlist()
|
||||
# 查找字幕类型,如果完全相等则返回True
|
||||
if(index==4):
|
||||
# 已识别到U盘
|
||||
self._item_append_green_str("已识别到U盘.")
|
||||
if(index==5):
|
||||
# 打开目录失败
|
||||
self._item_append_red_str("打开目录失败,其插入U盘并且在根目录建立 'updata' 文件夹.")
|
||||
self.cmd_list.clear()
|
||||
if(index==6):
|
||||
# 找不到相应文件
|
||||
self._item_append_red_str("找不到需要的文件,请把相应文件复制到U盘中.")
|
||||
self.cmd_list.clear()
|
||||
|
||||
|
||||
def _clear_irc_color(self, string):
|
||||
pattern = r'\x1b(\[.*?[@-~]|\].*?(\x07|\x1b\\))'
|
||||
return re.sub(pattern, '', string)
|
||||
|
||||
def decode_file_list(self,file_list:str):
|
||||
s=self._clear_irc_color(file_list)
|
||||
s_list=s.split()
|
||||
for i in s_list:
|
||||
self._item_append_green_str('|----|'+i)
|
||||
self.file_list.append(i)
|
||||
# print(self.file_list)
|
||||
return ""
|
||||
# 查找字幕类型,如果末尾是'#'则返回True
|
||||
def type_of_str(self,text:str):
|
||||
str_list=["ATK-MP157 login: root","Booting fw image checker_m4.axf","root@ATK-MP157:~#","root@ATK-MP157:/run/media/sda1/updata#","sda: sda1"]
|
||||
for i in range(len(str_list)):
|
||||
if(text.find(str_list[i])!=-1):
|
||||
if(str_list[i]==text):
|
||||
return i,True
|
||||
else:
|
||||
return i,False
|
||||
# print("type",text)
|
||||
for i in range(len(self.str_list)):
|
||||
if(text.find(self.str_list[i])!=-1):
|
||||
ack=('#'[0]==text[-1])
|
||||
# print(text,ack,i)
|
||||
return i,ack
|
||||
return -1,False
|
||||
def _item_append_green_str(self,text:str):
|
||||
txt="<font color=green>" +text+ "</font> <font color=black> </font>"
|
||||
@@ -150,23 +196,45 @@ class console_dlg(QObject):
|
||||
self.console_text.moveCursor(QTextCursor.MoveOperation.End)
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
def _item_append_red_str(self,text:str):
|
||||
txt="<font color=red>" +text+ "</font> <font color=black> </font>"
|
||||
try:
|
||||
self.console_text.append(txt)
|
||||
self.console_text.moveCursor(QTextCursor.MoveOperation.End)
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
def file_file_by_type(self,type:str):
|
||||
for i in self.file_list:
|
||||
if(i[-len(type):]==type):
|
||||
return i
|
||||
print("diff:",self.file_list,type)
|
||||
return "unknown"
|
||||
def start_send_cmds(self):
|
||||
self.cmd_list.clear()
|
||||
self.file_list.clear()
|
||||
self._item_append_green_str("开始发送命令行,请不要关闭窗口。")
|
||||
self.cmd_list.append("cd /run/media/sda1/updata")
|
||||
self.cmd_list.append("cd "+UPDATA_PATH)
|
||||
self.cmd_list.append("ls")
|
||||
self.send_cmdlist()
|
||||
|
||||
# 组装命令列表
|
||||
def _pack_cmd_list(self):
|
||||
self.cmd_list.append("systemctl stop atk-qtapp-start.service")
|
||||
self.cmd_list.append("mkdir /home/root/config")
|
||||
self.cmd_list.append("cp checker_host.elf /usr/local/QDesktop-fb")
|
||||
self.cmd_list.append("cp "+self.file_file_by_type(".elf")+" /usr/local/QDesktop-fb")
|
||||
self.cmd_list.append("chmod 777 /usr/local/QDesktop-fb")
|
||||
self.cmd_list.append("cp checker_slave_app_can.bin /home/root/config/checker_slave.bin")
|
||||
self.cmd_list.append("cp "+self.file_file_by_type(".bin")+" /home/root/config/checker_slave.bin")
|
||||
self.cmd_list.append("cp "+self.file_file_by_type("scheme.json")+" /home/root/config/checker_ye_cfg.json")
|
||||
self.cmd_list.append("cp cfg.json /home/root/config/cfg.json")
|
||||
self.cmd_list.append("cp checker_m4.axf /lib/firmware/checker_m4.axf")
|
||||
self.cmd_list.append("cp stm32mp157d-atk.dtb /boot/stm32mp157d-atk.dtb")
|
||||
self.cmd_list.append("cp "+self.file_file_by_type(".axf")+" /lib/firmware/checker_m4.axf")
|
||||
self.cmd_list.append("cp "+self.file_file_by_type(".dtb")+" /boot/stm32mp157d-atk.dtb")
|
||||
self.cmd_list.append("sync")
|
||||
self.cmd_list.append("systemctl restart atk-qtapp-start.service")
|
||||
self.send_cmdlist()
|
||||
|
||||
def send_cmdlist(self):
|
||||
if(len(self.cmd_list)>0):
|
||||
self._item_append_green_str("发送下一个命令,还剩 "+str(len(self.cmd_list)))
|
||||
print("send cmd:",self.cmd_list[0])
|
||||
self.send_str(self.cmd_list[0])
|
||||
self.cmd_list.pop(0)
|
||||
else:
|
||||
|
Reference in New Issue
Block a user