方案生成字节数据修改
This commit is contained in:
@@ -98,3 +98,6 @@
|
||||
updata 文件列表添加右键菜单,查看文件详情
|
||||
2023.10.29
|
||||
使用选项卡来选择两种升级方式
|
||||
2023.10.30
|
||||
prottcp 方案生成字节数据添加减少内存占用的转化函数,与此日期之前的MCU程序不兼容
|
||||
|
||||
|
@@ -142,6 +142,19 @@ def scheme_to_byte(j:json):
|
||||
# int转数组
|
||||
def arr_from_int(num:int):
|
||||
return bytearray([num&0xff,(num>>8)&0xff,(num>>16)&0xff,(num>>24)&0xff])
|
||||
# uchar转数组
|
||||
def arr_from_uchar(num:int):
|
||||
return bytearray([num&0xff])
|
||||
# u16转数组
|
||||
def arr_from_u16(num:int):
|
||||
return bytearray([num&0xff,(num>>8)&0xff])
|
||||
# 填充指定个数的byte
|
||||
def arr_byte_copy(byte:int,num:int):
|
||||
t=bytearray()
|
||||
for i in range(num):
|
||||
t.append(byte)
|
||||
return t
|
||||
|
||||
|
||||
|
||||
# 提取方案中的范围数据, 先max后min
|
||||
@@ -168,14 +181,59 @@ def scheme_get_task_range(j:json):
|
||||
t+=arr_from_int(0)
|
||||
return t
|
||||
|
||||
|
||||
|
||||
# 提取方案中的范围数据, 先max后min
|
||||
# 这个减少了存储空间占用
|
||||
def scheme_get_task_range_small(j:json):
|
||||
t=bytearray()
|
||||
t+=arr_from_uchar(j["TaskID"])
|
||||
t+=arr_from_uchar(j["TaskIndex"])
|
||||
t+=arr_from_uchar(j["ReturnCount"])
|
||||
t+=arr_from_uchar(j["ExecuteErrCode"])
|
||||
index=0
|
||||
for i in j["TestStandard"]:
|
||||
t+=arr_from_u16(i["Max"])
|
||||
t+=arr_from_u16(i["Min"])
|
||||
if (index<len(j["ResultErrCode"])):
|
||||
t+=arr_from_uchar(j["ResultErrCode"][index])
|
||||
else:
|
||||
t+=arr_from_uchar(0)
|
||||
index+=1
|
||||
# 不足16的部分填充为16
|
||||
n=16-len(j["TestStandard"])
|
||||
for i in range(n):
|
||||
t+=arr_from_u16(65535)
|
||||
t+=arr_from_u16(0)
|
||||
t+=arr_from_uchar(0)
|
||||
return t
|
||||
|
||||
|
||||
# 提取方案中的错误码
|
||||
def scheme_get_errinfo(j:json):
|
||||
t=bytearray()
|
||||
t+=arr_from_uchar(j["MajorErrCode"])
|
||||
t+=arr_from_uchar(len(j["SubErrCode"]))
|
||||
for i in j["SubErrCode"]:
|
||||
t+=arr_from_uchar(i)
|
||||
n=30-len(j["SubErrCode"])
|
||||
for i in range(n):
|
||||
t+=arr_from_uchar(0)
|
||||
return t
|
||||
|
||||
# 根据方案生成主板用的字节数据
|
||||
def scheme_to_host(j:json):
|
||||
t=bytearray()
|
||||
t+=arr_from_int(j["PlanID"])
|
||||
t+=arr_from_int(j["TimeOutM"])
|
||||
t+=arr_from_int(len(j["TaskArray"]))
|
||||
t+=arr_from_int(len(j["MajorErrInfo"]))
|
||||
for i in j["MajorErrInfo"]:
|
||||
t+=scheme_get_errinfo(i)
|
||||
n=21-len(j["MajorErrInfo"])
|
||||
t+=arr_byte_copy(0,n*32)
|
||||
for i in j["TaskArray"]:
|
||||
t+=scheme_get_task_range(i)
|
||||
t+=scheme_get_task_range_small(i)
|
||||
return t
|
||||
|
||||
|
||||
@@ -244,7 +302,8 @@ class handle:
|
||||
d=scheme_to_byte(json_obj)
|
||||
# print("len=",len(d),d.hex(","))
|
||||
d+=scheme_to_host(json_obj)
|
||||
# print("len=",len(d),d.hex(","))
|
||||
# print("scheme data:",d.hex(","))
|
||||
print("scheme size:{d}".format(d=len(d)))
|
||||
self.data=d
|
||||
self.name=f.name.split('/')[-1]
|
||||
self.stat=0
|
||||
|
@@ -48,7 +48,9 @@ class updata_dlg(QWidget):
|
||||
icon = QIcon()
|
||||
icon.addPixmap(Logo, QIcon.Mode.Normal, QIcon.State.Off)
|
||||
self.setWindowIcon(icon)
|
||||
|
||||
def closeEvent(self,e:QCloseEvent):
|
||||
print("close clicked.")
|
||||
QWidget.closeEvent(self,e)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -56,3 +58,4 @@ if __name__ == "__main__":
|
||||
dlg=updata_dlg()
|
||||
dlg.show()
|
||||
app.exec()
|
||||
sys.exit(0)
|
||||
|
@@ -108,6 +108,8 @@ class updata_dlg(QWidget):
|
||||
end_signal = pyqtSignal([str,bool,str])
|
||||
# 数据库下载文件结束信号
|
||||
sql_download_end_signal =pyqtSignal([])
|
||||
# 扫描从机结束信号
|
||||
scan_slave_end_signal=pyqtSignal([list])
|
||||
|
||||
def __init__(self):
|
||||
QWidget.__init__(self)
|
||||
@@ -143,6 +145,7 @@ class updata_dlg(QWidget):
|
||||
self.infotext_init()
|
||||
self.widget.destroyed.connect(self.quit)
|
||||
self.sql_download_end_signal.connect(self.scan_file)
|
||||
self.scan_slave_end_signal.connect(self.scan_slave_end_slot)
|
||||
|
||||
Logo = QPixmap()
|
||||
Logo.loadFromData(base64.b64decode(memory_pic.icon_ico))
|
||||
@@ -710,14 +713,22 @@ class updata_dlg(QWidget):
|
||||
# 扫描从机
|
||||
def scan_slave(self):
|
||||
self.set_infotext("正在刷新主板IP地址")
|
||||
u=udp.myudp(1,255)
|
||||
ip_prefix=self.ip_prefix.text()
|
||||
t=threading.Thread(target=self.scan_slave_thread, args=(ip_prefix,))
|
||||
t.start()
|
||||
def scan_slave_thread(self,ip_prefix:str):
|
||||
u=udp.myudp(1,255)
|
||||
u.find(ip_prefix)
|
||||
self.scan_slave_end_signal.emit(u.dst_ip_list)
|
||||
|
||||
def scan_slave_end_slot(self,ips:list):
|
||||
list_str=[]
|
||||
for i in u.dst_ip_list:
|
||||
for i in ips:
|
||||
list_str.append(i[0]+','+i[1])
|
||||
if(len(list_str)==0):
|
||||
self.set_infotext("未找到主板IP地址,请确保主板已正常连接并运行")
|
||||
else:
|
||||
self.set_infotext("找到 {d} 个设备ip地址".format(d=len(ips)))
|
||||
self.slave_list.addItems(list_str)
|
||||
|
||||
# 添加单个从机地址
|
||||
|
@@ -99,7 +99,7 @@ class updata_dlg(QWidget):
|
||||
self.port_is_open=False
|
||||
self.scan_file()
|
||||
self.infotext_init()
|
||||
|
||||
|
||||
# 提示信息
|
||||
def infotext_init(self):
|
||||
self.infotext=QLabel(self.widget)
|
||||
@@ -112,6 +112,7 @@ class updata_dlg(QWidget):
|
||||
pass
|
||||
|
||||
def quit(self):
|
||||
print("quit")
|
||||
self.close_port()
|
||||
# 程序退出
|
||||
qApp.exit(1)
|
||||
@@ -518,7 +519,7 @@ class updata_dlg(QWidget):
|
||||
self.port.recv_signal.connect(self.recv_slot)
|
||||
self.port.recv_str_signal.connect(self.recv_str_slot)
|
||||
self.port.start_recv()
|
||||
self.port.wait()
|
||||
# self.port.wait()
|
||||
def close_port(self):
|
||||
print("close port")
|
||||
self.set_port_state(False)
|
||||
|
Reference in New Issue
Block a user