升级小板添加结果返回,升级脚本可以修改波特率

This commit is contained in:
ranchuan
2023-08-18 18:53:09 +08:00
parent 337b970b93
commit 8d779a68f3
9 changed files with 116 additions and 31 deletions

Binary file not shown.

View File

@@ -280,7 +280,8 @@ class protu(QObject):
if(s[0]=="utcp"): if(s[0]=="utcp"):
self.ser = utcp(int(s[1])) self.ser = utcp(int(s[1]))
else: else:
self.ser = serial.Serial(port=s[0], baudrate=115200,bytesize=serial.EIGHTBITS,parity=serial.PARITY_NONE, bsp=int(s[1])
self.ser = serial.Serial(port=s[0], baudrate=bsp,bytesize=serial.EIGHTBITS,parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,timeout=None) stopbits=serial.STOPBITS_ONE,timeout=None)
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
@@ -310,7 +311,7 @@ class protu(QObject):
self.str_err="recv data len too less." self.str_err="recv data len too less."
return bytearray() return bytearray()
if(data[0]!=0x59 or data[1]!=0x6d or data[2]!=0x43): if(data[0]!=0x59 or data[1]!=0x6d or data[2]!=0x43):
print("frame head not 0x59 0x6d.") # print("frame head not 0x59 0x6d.")
self.str_err="frame head not 0x59 0x6d." self.str_err="frame head not 0x59 0x6d."
return bytearray() return bytearray()
length=data[3]|(data[4]<<8) length=data[3]|(data[4]<<8)
@@ -331,9 +332,30 @@ class protu(QObject):
self.cmd_no=data[6]|(data[7]<<8) self.cmd_no=data[6]|(data[7]<<8)
self.cmd=data[5] self.cmd=data[5]
if(self.is_big_data==False): if(self.is_big_data==False):
return data[8:-2] return bytearray(data[8:-2])
else: else:
return data[12:-2] return bytearray(data[12:-2])
# 不带校验的接收函数
def recv_(self):
while(self.ser.is_open):
try:
data=self.ser.read(500)
except Exception as a:
# print("err:",str(a))
print("port closed")
return
if(len(data)>0):
t=self.decode(data)
if(self.str_err=="ok"):
self.recv_data+=t
# print("recv",t.hex(","))
# print(type(self.cmd),type(t),type(self.str_err))
self.recv_signal.emit(self.cmd,t,self.str_err)
# self.send_file_next(self.cmd,t,self.str_err)
# print("sent signal---")
else:
print(data.decode("utf-8"))
# 带帧校验的接收函数
def recv(self): def recv(self):
# self.recv_signal.connect(self.send_file_next) # self.recv_signal.connect(self.send_file_next)
data=bytearray() data=bytearray()
@@ -381,7 +403,7 @@ class protu(QObject):
# print("send:",data.hex(",")) # print("send:",data.hex(","))
self.ser.write(self.encode(data)) self.ser.write(self.encode(data))
def send_str(self,txt:str): def send_str(self,txt:str):
self.ser.write(txt) self.ser.write(txt.encode("utf-8"))
def start_recv(self): def start_recv(self):
self.thread_ = threading.Thread(target=self.recv, args=()) self.thread_ = threading.Thread(target=self.recv, args=())
self.thread_.start() self.thread_.start()

View File

@@ -78,14 +78,15 @@ class updata_dlg(QObject):
self.widget = QWidget() self.widget = QWidget()
self.widget.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose) self.widget.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
self.widget.resize(703, 409) self.widget.resize(703, 409)
self.widget.setWindowTitle("批检仪程序升级") self.widget.setWindowTitle("赋码仪程序升级")
self.file_list_init() self.file_list_init()
self.save_but_init()
self.cmd_but_init()
self.sstate_but_init()
self.updatas_but_init()
self.com_but_init() self.com_but_init()
self.save_but_init()
# self.updatas_but_init()
# self.cmd_but_init()
# self.sstate_but_init()
self.com_init() self.com_init()
self.combsp_init()
self.widget.destroyed.connect(self.quit) self.widget.destroyed.connect(self.quit)
self.failed_signal.connect(self.updata_failed) self.failed_signal.connect(self.updata_failed)
self.cmd=0 self.cmd=0
@@ -112,7 +113,7 @@ class updata_dlg(QObject):
def com_but_init(self): def com_but_init(self):
self.com_but = QPushButton(self.widget) self.com_but = QPushButton(self.widget)
self.com_but.setObjectName(u"com_but") self.com_but.setObjectName(u"com_but")
self.com_but.setGeometry(QRect(450, 10, 93, 28)) self.com_but.setGeometry(QRect(590, 10, 93, 28))
self.com_but.setText("打开端口") self.com_but.setText("打开端口")
self.com_but.clicked.connect(self.com_but_clicked) self.com_but.clicked.connect(self.com_but_clicked)
@@ -133,6 +134,14 @@ class updata_dlg(QObject):
self.cmd_but.setText("升级MCU") self.cmd_but.setText("升级MCU")
self.cmd_but.clicked.connect(self.cmd_but_clicked) self.cmd_but.clicked.connect(self.cmd_but_clicked)
# 初始化升级小板按钮
def updatas_but_init(self):
self.updatas_but = QPushButton(self.widget)
self.updatas_but.setObjectName(u"updatas_but")
self.updatas_but.setGeometry(QRect(590, 100, 93, 28))
self.updatas_but.setText("升级小板")
self.updatas_but.clicked.connect(self.updatas_but_clicked)
# 初始化在线状态按钮 # 初始化在线状态按钮
def sstate_but_init(self): def sstate_but_init(self):
self.sstate_but = QPushButton(self.widget) self.sstate_but = QPushButton(self.widget)
@@ -141,19 +150,11 @@ class updata_dlg(QObject):
self.sstate_but.setText("MCU在线状态") self.sstate_but.setText("MCU在线状态")
self.sstate_but.clicked.connect(self.sstate_but_clicked) self.sstate_but.clicked.connect(self.sstate_but_clicked)
# 初始化升级小板按钮
def updatas_but_init(self):
self.updatas_but = QPushButton(self.widget)
self.updatas_but.setObjectName(u"updatas_but")
self.updatas_but.setGeometry(QRect(590, 180, 93, 28))
self.updatas_but.setText("升级小板")
self.updatas_but.clicked.connect(self.updatas_but_clicked)
# com口 # com口
def com_init(self): def com_init(self):
self.com = QComboBox(self.widget) self.com = QComboBox(self.widget)
self.com.setObjectName(u"com") self.com.setObjectName(u"com")
self.com.setGeometry(QRect(100, 10, 300, 21)) self.com.setGeometry(QRect(85, 10, 300, 25))
self.com.setEditable(True) self.com.setEditable(True)
self.com.currentIndexChanged.connect(self.com_changed) self.com.currentIndexChanged.connect(self.com_changed)
self.com.addItem("utcp:7777") self.com.addItem("utcp:7777")
@@ -163,9 +164,22 @@ class updata_dlg(QObject):
self.com.addItem(comport.name+":"+comport.description) self.com.addItem(comport.name+":"+comport.description)
self.com_label = QLabel(self.widget) self.com_label = QLabel(self.widget)
self.com_label.setObjectName(u"label") self.com_label.setObjectName(u"label")
self.com_label.setGeometry(QRect(30, 10, 72, 15)) self.com_label.setGeometry(QRect(30, 16, 72, 15))
self.com_label.setText("COM口:") self.com_label.setText("COM口:")
# 选择波特率
def combsp_init(self):
self.combsp = QComboBox(self.widget)
self.combsp.setObjectName(u"combsp")
self.combsp.setGeometry(QRect(470, 10, 80, 25))
self.combsp.setEditable(True)
self.combsp.addItem("115200")
self.combsp.addItem("9600")
self.combsp_label = QLabel(self.widget)
self.combsp_label.setObjectName(u"label")
self.combsp_label.setGeometry(QRect(410, 16, 72, 15))
self.combsp_label.setText("波特率:")
# 显示消息框 # 显示消息框
def show_msg(self,msg:str): def show_msg(self,msg:str):
m=QMessageBox(self.widget) m=QMessageBox(self.widget)
@@ -261,6 +275,7 @@ class updata_dlg(QObject):
self.port.send(self.cmd,d) self.port.send(self.cmd,d)
except Exception as e: except Exception as e:
print("com not open") print("com not open")
self.show_msg("端口未打开")
del self.handle_ del self.handle_
w.close() w.close()
return return
@@ -301,8 +316,10 @@ class updata_dlg(QObject):
def updatas_but_clicked(self): def updatas_but_clicked(self):
print("updatas_but clicked.") print("updatas_but clicked.")
try: try:
self.port.send_str("updatas 1,2,3,4,5,6,7,8,9,10".encode("utf-8")) self.port.send_str("updatas 1,2,3,4,5,6,7,8,9,10")
self.show_msg("已发送升级指令,请留意小板升级情况")
except Exception as e: except Exception as e:
self.show_msg("命令发送失败")
print("com not open") print("com not open")
print(str(e)) print(str(e))
@@ -353,6 +370,10 @@ class updata_dlg(QObject):
def com_thread(self): def com_thread(self):
self.port=prottcp.protu() self.port=prottcp.protu()
item=self.com.itemText(self.com.currentIndex()) item=self.com.itemText(self.com.currentIndex())
bsp=self.combsp.itemText(self.combsp.currentIndex())
com=item.split(":")[0]
if(com!="utcp"):
item=com+":"+bsp
print("item text:",item) print("item text:",item)
if(self.port.init(item)==False): if(self.port.init(item)==False):
print("init port failed.") print("init port failed.")

View File

@@ -148,4 +148,9 @@
2023.8.4 2023.8.4
添加注码错误偏移 添加注码错误偏移
2023.8.9 2023.8.9
解决注码成功返回0xc0的问题 解决注码成功返回0xc0的问题
2023.8.17
修改一些通信逻辑,上报数据不自增流水号,使用上位机下发的流水号
与20230817V3.28X以前的程序不兼容
2023.8.18
升级小板增加命令行返回

View File

@@ -74,6 +74,7 @@ array_def *protu_decode(protu_def *p,array_def *data)
// DBG_WARN("duplicate sequence number."); // DBG_WARN("duplicate sequence number.");
// str_set(p->str_err,"duplicate sequence number."); // str_set(p->str_err,"duplicate sequence number.");
// } // }
p->cmd_no=cmd_no;
p->cmd=arr_get(data,4); p->cmd=arr_get(data,4);
// 数据负载 // 数据负载
arr_delete(r); arr_delete(r);

View File

@@ -6,7 +6,7 @@
#define BUILD_DATE "2023-08-09 13:54:50" #define BUILD_DATE "2023-08-18 10:34:08"
#define SOFT_VERSION "0.10" #define SOFT_VERSION "0.10"

View File

@@ -129,7 +129,10 @@ commend_export(scheme,scheme_info,"print scheme info")
typedef struct{
int updata_run;
}updata_def;
static updata_def g_updata;
static int updata_slave(list_def *argv) static int updata_slave(list_def *argv)
{ {
void *ptr=flash_get_slave(); void *ptr=flash_get_slave();
@@ -150,13 +153,44 @@ static int updata_slave(list_def *argv)
{ {
int addr=list_get_int(addrs,i); int addr=list_get_int(addrs,i);
port_mcu *mcu=tran_get_portm(tran,addr-1); port_mcu *mcu=tran_get_portm(tran,addr-1);
if(mcu) if(mcu){
port_start(mcu,updata_creat(data,file->file_size)); port_start(mcu,updata_creat(data,file->file_size));
g_updata.updata_run++;
}
} }
cmd_print("start updata,addr=%s",str_temp(list_string(addrs))); cmd_print("start updata,addr=%s",str_temp(list_string(addrs)));
return 0; return 0;
} }
static void cmd_end_slot(void *obj,port_mcu *src,void *data,int ack,char *err_str)
{
updata_def *self=obj;
if(self->updata_run>0)
{
cmd_print("addr:%d %s",port_get_addr(src),err_str);
self->updata_run--;
}
}
// 挂载命令行槽函数
static int cmd_slot_init(void)
{
void *tr=app_variable("tran",0,0);
if(tr){
for(int i=0;i<20;i++){
port_mcu *mcu=tran_get_portm(tr,i);
// 连接操作结束信号
if(mcu)
connect(mcu,port_end_signal,0,&g_updata,cmd_end_slot);
}
}
else{
app_valid_call("tran",(void (*)(void *))cmd_slot_init,0);
}
return 0;
}
app_init_export(cmd_slot_init);
commend_export(updatas,updata_slave,"updata slave") commend_export(updatas,updata_slave,"updata slave")

View File

@@ -281,7 +281,7 @@ void protu_send_call(protu_def *p,uint8_t cmd,array_def *data)
if(cmd!=0){ if(cmd!=0){
p->cmd=cmd; p->cmd=cmd;
// 上报数据不增加流水号 2023.7.14 // 上报数据不增加流水号 2023.7.14
p->cmd_no++; //p->cmd_no++;
if(p->codec) if(p->codec)
t=p->codec->encode(p,data); t=p->codec->encode(p,data);
}else if(p->cmd==0) }else if(p->cmd==0)

View File

@@ -199,6 +199,8 @@ static ucport_def *write_uid(tran_def *t, uint8_t cmd,array_def *data)
port_start(mcu,code_creat(8,4,u->item[i].uid_pw_hex)); port_start(mcu,code_creat(8,4,u->item[i].uid_pw_hex));
}else{ }else{
// 管壳码无效,不注码,此时默认已ack // 管壳码无效,不注码,此时默认已ack
// 管壳码无效不视为失败
ret=0;
write_uid_fillret(u,i+1,0xff); write_uid_fillret(u,i+1,0xff);
} }
} }
@@ -210,14 +212,14 @@ static ucport_def *write_uid(tran_def *t, uint8_t cmd,array_def *data)
array_def *a=arr_creat(); array_def *a=arr_creat();
arr_append(a,u->addrs_num); arr_append(a,u->addrs_num);
if(g_self.step==1){ // if(g_self.step==1){
if(ret==0) if(ret==0)
arr_append(a,TRAN_ERR_NONE); arr_append(a,TRAN_ERR_NONE);
else else
arr_append(a,TRAN_ERR_PARAM); arr_append(a,TRAN_ERR_PARAM);
}else{ // }else{
arr_append(a,TRAN_ERR_STEP); // arr_append(a,TRAN_ERR_STEP);
} // }
emit tran_reply_signal(u->u.p,arr_temp(a)); emit tran_reply_signal(u->u.p,arr_temp(a));
// test:稍后返回成功 // test:稍后返回成功