diff --git a/python/file/Ym_Coder 2023-8-16.bin b/python/file/Ym_Coder 2023-8-16.bin new file mode 100644 index 0000000..8ce5ef2 Binary files /dev/null and b/python/file/Ym_Coder 2023-8-16.bin differ diff --git a/python/prottcp.py b/python/prottcp.py index 61b37cc..fed91dc 100644 --- a/python/prottcp.py +++ b/python/prottcp.py @@ -280,7 +280,8 @@ class protu(QObject): if(s[0]=="utcp"): self.ser = utcp(int(s[1])) 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) except Exception as e: print(str(e)) @@ -310,7 +311,7 @@ class protu(QObject): self.str_err="recv data len too less." return bytearray() 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." return bytearray() length=data[3]|(data[4]<<8) @@ -331,9 +332,30 @@ class protu(QObject): self.cmd_no=data[6]|(data[7]<<8) self.cmd=data[5] if(self.is_big_data==False): - return data[8:-2] + return bytearray(data[8:-2]) 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): # self.recv_signal.connect(self.send_file_next) data=bytearray() @@ -381,7 +403,7 @@ class protu(QObject): # print("send:",data.hex(",")) self.ser.write(self.encode(data)) def send_str(self,txt:str): - self.ser.write(txt) + self.ser.write(txt.encode("utf-8")) def start_recv(self): self.thread_ = threading.Thread(target=self.recv, args=()) self.thread_.start() diff --git a/python/updata.py b/python/updata.py index 96f6b31..ed6798a 100644 --- a/python/updata.py +++ b/python/updata.py @@ -78,14 +78,15 @@ class updata_dlg(QObject): self.widget = QWidget() self.widget.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose) self.widget.resize(703, 409) - self.widget.setWindowTitle("批检仪程序升级") + self.widget.setWindowTitle("赋码仪程序升级") 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.save_but_init() + # self.updatas_but_init() + # self.cmd_but_init() + # self.sstate_but_init() self.com_init() + self.combsp_init() self.widget.destroyed.connect(self.quit) self.failed_signal.connect(self.updata_failed) self.cmd=0 @@ -112,7 +113,7 @@ class updata_dlg(QObject): def com_but_init(self): self.com_but = QPushButton(self.widget) 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.clicked.connect(self.com_but_clicked) @@ -133,6 +134,14 @@ class updata_dlg(QObject): self.cmd_but.setText("升级MCU") 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): self.sstate_but = QPushButton(self.widget) @@ -141,19 +150,11 @@ class updata_dlg(QObject): self.sstate_but.setText("MCU在线状态") 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口 def com_init(self): self.com = QComboBox(self.widget) 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.currentIndexChanged.connect(self.com_changed) self.com.addItem("utcp:7777") @@ -163,9 +164,22 @@ class updata_dlg(QObject): self.com.addItem(comport.name+":"+comport.description) self.com_label = QLabel(self.widget) 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口:") + # 选择波特率 + 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): m=QMessageBox(self.widget) @@ -261,6 +275,7 @@ class updata_dlg(QObject): self.port.send(self.cmd,d) except Exception as e: print("com not open") + self.show_msg("端口未打开") del self.handle_ w.close() return @@ -301,8 +316,10 @@ class updata_dlg(QObject): def updatas_but_clicked(self): print("updatas_but clicked.") 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: + self.show_msg("命令发送失败") print("com not open") print(str(e)) @@ -353,6 +370,10 @@ class updata_dlg(QObject): def com_thread(self): self.port=prottcp.protu() 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) if(self.port.init(item)==False): print("init port failed.") diff --git a/source/ReadMe.txt b/source/ReadMe.txt index dc83686..46495bf 100644 --- a/source/ReadMe.txt +++ b/source/ReadMe.txt @@ -148,4 +148,9 @@ 2023.8.4 添加注码错误偏移 2023.8.9 - 解决注码成功返回0xc0的问题 \ No newline at end of file + 解决注码成功返回0xc0的问题 +2023.8.17 + 修改一些通信逻辑,上报数据不自增流水号,使用上位机下发的流水号 + 与20230817V3.28X以前的程序不兼容 +2023.8.18 + 升级小板增加命令行返回 \ No newline at end of file diff --git a/source/codec/codec.c b/source/codec/codec.c index 82f1d55..58d92a8 100644 --- a/source/codec/codec.c +++ b/source/codec/codec.c @@ -74,6 +74,7 @@ array_def *protu_decode(protu_def *p,array_def *data) // DBG_WARN("duplicate sequence number."); // str_set(p->str_err,"duplicate sequence number."); // } + p->cmd_no=cmd_no; p->cmd=arr_get(data,4); // 数据负载 arr_delete(r); diff --git a/source/main/compiler_info.h b/source/main/compiler_info.h index 9760f69..2d42916 100644 --- a/source/main/compiler_info.h +++ b/source/main/compiler_info.h @@ -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" diff --git a/source/main/main.c b/source/main/main.c index fd3ae3d..07020e4 100644 --- a/source/main/main.c +++ b/source/main/main.c @@ -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) { void *ptr=flash_get_slave(); @@ -150,13 +153,44 @@ static int updata_slave(list_def *argv) { int addr=list_get_int(addrs,i); port_mcu *mcu=tran_get_portm(tran,addr-1); - if(mcu) + if(mcu){ port_start(mcu,updata_creat(data,file->file_size)); + g_updata.updata_run++; + } } cmd_print("start updata,addr=%s",str_temp(list_string(addrs))); 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") diff --git a/source/task/prot_uc.c b/source/task/prot_uc.c index dd15158..b925058 100644 --- a/source/task/prot_uc.c +++ b/source/task/prot_uc.c @@ -281,7 +281,7 @@ void protu_send_call(protu_def *p,uint8_t cmd,array_def *data) if(cmd!=0){ p->cmd=cmd; // 上报数据不增加流水号 2023.7.14 - p->cmd_no++; + //p->cmd_no++; if(p->codec) t=p->codec->encode(p,data); }else if(p->cmd==0) diff --git a/source/task/tran_for_coder2.c b/source/task/tran_for_coder2.c index 037a8bb..3c35668 100644 --- a/source/task/tran_for_coder2.c +++ b/source/task/tran_for_coder2.c @@ -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)); }else{ // 管壳码无效,不注码,此时默认已ack + // 管壳码无效不视为失败 + ret=0; 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(); arr_append(a,u->addrs_num); - if(g_self.step==1){ +// if(g_self.step==1){ if(ret==0) arr_append(a,TRAN_ERR_NONE); else arr_append(a,TRAN_ERR_PARAM); - }else{ - arr_append(a,TRAN_ERR_STEP); - } +// }else{ +// arr_append(a,TRAN_ERR_STEP); +// } emit tran_reply_signal(u->u.p,arr_temp(a)); // test:稍后返回成功