From bf4b4b45ead2b88056816bd9373fdd6ed775a423 Mon Sep 17 00:00:00 2001 From: ranchuan Date: Tue, 19 Dec 2023 18:14:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=B6=E5=AE=9A=E4=BB=BB=E5=8A=A1=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ReadMe.txt | 2 + checker_host.pro | 2 + complier_info.h | 2 +- elec/elec_judge.cpp | 11 ++++ elec/elec_judge.h | 2 +- info.json | 2 +- prot_cmd/cmd_coder.cpp | 124 +++++++++++++++++++++++++++++++++++++++++ prot_cmd/cmd_coder.h | 91 ++++++++++++++++++++++++++++++ prot_cmd/cmd_pc.cpp | 29 ++++++---- prot_cmd/cmd_pc.h | 20 +++++++ prot_cmd/cmd_slave.cpp | 42 ++++++++++++-- prot_cmd/cmd_slave.h | 10 +++- 12 files changed, 315 insertions(+), 22 deletions(-) create mode 100644 prot_cmd/cmd_coder.cpp create mode 100644 prot_cmd/cmd_coder.h diff --git a/ReadMe.txt b/ReadMe.txt index 0cd90c1..6cc0f5a 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -18,3 +18,5 @@ 广播命令已接收的回复不再触发回调 检测命令0x0c只能使用单播方式,广播方式因为不能即时回复停止信号,回复会出错 添加电阻测试命令,添加自检命令 +2023.12.19 + 制定任务执行命令 diff --git a/checker_host.pro b/checker_host.pro index e801ad2..dc35b3b 100644 --- a/checker_host.pro +++ b/checker_host.pro @@ -43,6 +43,7 @@ SOURCES += \ prot/prot_pc.cpp \ prot/prot_slave.cpp \ prot_cmd/cmd_cmdline.cpp \ + prot_cmd/cmd_coder.cpp \ prot_cmd/cmd_m4.cpp \ prot_cmd/cmd_pc.cpp \ prot_cmd/cmd_slave.cpp @@ -71,6 +72,7 @@ HEADERS += \ prot/prot_pc.h \ prot/prot_slave.h \ prot_cmd/cmd_cmdline.h \ + prot_cmd/cmd_coder.h \ prot_cmd/cmd_m4.h \ prot_cmd/cmd_pc.h \ prot_cmd/cmd_slave.h diff --git a/complier_info.h b/complier_info.h index 008a94c..151c96d 100644 --- a/complier_info.h +++ b/complier_info.h @@ -6,7 +6,7 @@ -#define BUILD_DATE "2023-12-13 17:50:37" +#define BUILD_DATE "2023-12-19 18:08:48" diff --git a/elec/elec_judge.cpp b/elec/elec_judge.cpp index d06bac8..8b77a86 100644 --- a/elec/elec_judge.cpp +++ b/elec/elec_judge.cpp @@ -248,6 +248,12 @@ elec_task_judge, elec_task_judge, elec_task_judge, elec_task_judge, +elec_task_judge, +elec_task_judge, +elec_task_judge, +elec_task_judge, +elec_task_judge, +elec_task_judge, 0, }; @@ -344,6 +350,11 @@ elec_task_judge, //35 检测过程中注码 elec_task_judge, //36 验证注码 elec_task_judge, //37 模块在线检测 elec_task_judge, //38 升级 +elec_task_judge, +elec_task_judge, +elec_task_judge, +elec_task_judge, +elec_task_judge, 0, }; diff --git a/elec/elec_judge.h b/elec/elec_judge.h index 7af68d0..08e6c65 100644 --- a/elec/elec_judge.h +++ b/elec/elec_judge.h @@ -32,7 +32,7 @@ typedef struct _elec_judge_def{ void elec_judge(const scheme_def *s,int task_num,uint8_t *exe_ack, uint8_t *exe_flag,uint8_t *data,uint8_t *marerr,uint8_t *suberr); - +int elec_extract_chip(int id); #endif diff --git a/info.json b/info.json index c9d599c..1ba1af1 100644 --- a/info.json +++ b/info.json @@ -1,5 +1,5 @@ { - "build_date": "2023-12-13 17:50:37", + "build_date": "2023-12-19 18:08:48", "hard_version": "MHPZ2_V1.00", "private": [ "info.json", diff --git a/prot_cmd/cmd_coder.cpp b/prot_cmd/cmd_coder.cpp new file mode 100644 index 0000000..2494a05 --- /dev/null +++ b/prot_cmd/cmd_coder.cpp @@ -0,0 +1,124 @@ +#include "cmd_coder.h" + + + +static const char *g_ew_task_table[]={ +"电源准备", +"延时等待", +"桥丝电阻测试", +"上电充能", +"设置总线电压", +"获取总线电流", +"使能MTP", +"扫描UID", +"写配置参数", +"检测配置", +"验证配置", +"模拟注码", +"验证模拟注码", +"芯片自检", +"状态检测", +"充电", +"放电", +"写延时", +"读延时", +"时钟校准", +"设置通信地址", +"状态巡检", +"起爆使能", +"起爆检测", +"缓存数据写入MTP", +"验证缓存数据", +"关总线", +"升级", +"充能统计", +"计算异常", +"重新执行任务", +"写入三码数据", +"验证三码数据", +"配置三码数据到小板", +"任务插槽", +nullptr, +}; + + + + + +static const char *g_jq_task_table[]={ +"电源准备", +"上电充能", +"设置总线电压", +"获取总线电流", +"扫描UID", +"密码验证", +"读取芯片代码", +"OTP检测", +"工厂测试检测", +"读取状态", +"写工厂信息", +"充能统计", +"充电电压检测", +"延时等待", +"设置延时", +"读取延时", +"时钟校准", +"放电", +"复位", +"起爆使能", +"起爆充能", +"使能通讯末电流采集", +"获取通讯末电流", +"写OTP", +"读OTP", +"清除起爆计数", +"关总线", +"将缓存区数据写入OTP", +"三码写入错误", +"三码验证错误", +"测量电容压差", +"测量桥丝阻值", +"使能OTP写", +"写模块版本", +"读取版本号", +"写缓存数据", +"验证缓存数据", +"读取延时值和OTP数据相比", +"切换总线极性", +"计算异常", +"重新执行任务", +"配置三码数据到小板", +"任务插槽", +nullptr, +}; + + +// 根据字符找到任务id,失败返回-1 +int coder_find_task_id(const char *str) +{ + int chip=elec_extract_chip(check_plan()->get_plan_id()); + const char **table=nullptr; + if(chip==0){ + table=g_jq_task_table; + }else if(chip==2){ + table=g_ew_task_table; + } + if(table==nullptr){ + return -1; + } + for(int i=0;i<100;i++){ + if(qstrcmp(str,table[i])==0){ + return i; + } + } + return -1; +} + + + + + + + + + diff --git a/prot_cmd/cmd_coder.h b/prot_cmd/cmd_coder.h new file mode 100644 index 0000000..51ddfc4 --- /dev/null +++ b/prot_cmd/cmd_coder.h @@ -0,0 +1,91 @@ +#ifndef CMD_CODER_H +#define CMD_CODER_H + +#include +#include "prot_cmd/cmd_pc.h" +#include "base/check_cfg.h" +#include "elec/elec_judge.h" + + +/* + +执行任务命令格式 +[0...1]=总字节数,[2]=当前包数(0开始),[3]=当前包字节数 +[4...n]=数据 + +数据域格式 +[0]=小板地址,[1]=数据长度,[2...n]=数据 + +单个任务数据格式 +[0]=插槽序号,[1]=任务id,[2]=参数个数(u16) +[3]=返回值个数(u16),[4]=异常代码,[5]=任务序号 +[6...n]=参数 + + + +返回数据域格式 +[0]=任务序号,[1]=返回数据长度(u16) +[2...n]=参数 + + +*/ + +int coder_find_task_id(const char *str); + + +// 赋码仪检测命令 +class cmd_coder_check : public selfdev_runtask +{ + Q_OBJECT +public: + cmd_coder_check():selfdev_runtask(){ + } + // pc指令转从机 + myarray cmd_pc_to_slave(myarray data){ + + } + // pc指令生成从机列表 + QList cmd_pc_to_addrs(myarray data){ + QList addr_list; + addrs=data[0]|(data[1]<<8)|(data[2]<<16); + for(int i=0;i<20;i++){ + if((addrs&(1<>8)&0xff)); + r.append(uint8_t((addrs>>16)&0xff)); + r.append(uint8_t(0)); + return r; + } + // pc回复命令,返回0不回复 + int cmd_pc_ret(){ + return 0x90; + } + // 从机返回转pc + myarray ret_slave_to_pc(QList data){ + + } +protected: + int addrs; +}; + + + + + +#endif // CMD_CODER_H diff --git a/prot_cmd/cmd_pc.cpp b/prot_cmd/cmd_pc.cpp index 2d7c669..df6b27b 100644 --- a/prot_cmd/cmd_pc.cpp +++ b/prot_cmd/cmd_pc.cpp @@ -821,18 +821,22 @@ int selfdev_runtask::dolater(int cmd, myarray data) qDebug("set_rescv."); emit send_data_signal(cmd,myarray(1,0)); HandleBoardCast *b=new slave_cmd(); - bool ack=slave->set_boardcast_handle(cfg_->calc_slave_addrs(),b); + addrs=cmd_pc_to_addrs(data); + bool ack=slave->set_boardcast_handle(addrs,b); if(ack==false){ qWarning("handle is busy."); busy=0; }else{ connect(b,&HandleBoardCast::end_signal,this,&selfdev_runtask::slave_end_slot); // 广播设置校准值,需使用新增命令 - b->cmd=0x13; - b->start(data); + b->cmd=cmd_slave(); + b->start(cmd_pc_to_slave(data)); + if(cmd_pc_recv()!=0){ + emit send_data_signal(cmd_pc_recv(),cmd_pc_recv_to_pc()); + } } slave_acked.clear(); - for(int i=0;islave_num;i++){ + for(int i=0;i cmd_pc_to_addrs(myarray data)=0; + // 从机发起命令 + virtual int cmd_slave()=0; + // pc收到回复,返回0不回复 + virtual int cmd_pc_recv()=0; + // 生成接收回复到pc + virtual myarray cmd_pc_recv_to_pc()=0; + // pc回复命令,返回0不回复 + virtual int cmd_pc_ret()=0; + // 从机返回转pc + virtual myarray ret_slave_to_pc(QList data)=0; public slots: void slave_end_slot(int addr,int ack, slave_data data); protected: QList slave_acked; int slave_acked_num; + QList addrs; signals: void send_to_m4_signal(myarray data); }; @@ -279,4 +294,9 @@ signals: + + + + + #endif diff --git a/prot_cmd/cmd_slave.cpp b/prot_cmd/cmd_slave.cpp index 63f4591..25e5212 100644 --- a/prot_cmd/cmd_slave.cpp +++ b/prot_cmd/cmd_slave.cpp @@ -475,14 +475,42 @@ int slave_bootinfo::dolater(int cmd, myarray data) int slave_cmd::start(myarray data) { - int timeout=5000; + int timeout; busy=1; + timeout=check_plan()->get_check_time_out()*1000; qDebug("addr %d start ,timeout=%d",addr,timeout); - send_data(cmd,data,3); + this->data=data; + send_pack_num=0; + send_bytes=0; + send_next(); timeout_start(timeout); return 0; } +// 发送下一包,返回true完成 +bool slave_cmd::send_next() +{ + int pack_size=236; + int data_size=data.size(); + if(send_bytesdata_size-send_bytes){ + pack_size=data_size-send_bytes; + } + myarray d; + d.append(uint8_t(data_size&0xff)); + d.append(uint8_t((data_size>>8)&0xff)); + d.append(uint8_t((send_pack_num)&0xff)); + d.append(uint8_t(pack_size&0xff)); + d.append(data.mid(send_bytes,pack_size)); + send_data(cmd,d,3); + send_bytes+=pack_size; + send_pack_num++; + return false; + }else{ + return true; + } +} + void slave_cmd::timeout() { timeout_stop(); @@ -496,10 +524,12 @@ int slave_cmd::dolater(int cmd, myarray data) this->addr_response=0; timeout_stop_retry(); if(cmd==this->cmd){ - qDebug("cmd end success."); - busy=0; - end(0,ret_data); - timeout_stop(); + if(send_next()==true){ + qDebug("cmd end success."); + busy=0; + end(0,ret_data); + timeout_stop(); + } }else{ qWarning("cmd:%02x err.",cmd); } diff --git a/prot_cmd/cmd_slave.h b/prot_cmd/cmd_slave.h index c009448..990cea4 100644 --- a/prot_cmd/cmd_slave.h +++ b/prot_cmd/cmd_slave.h @@ -150,10 +150,18 @@ public: class slave_cmd:public HandleBoardCast { public: - slave_cmd():HandleBoardCast(){} + slave_cmd():HandleBoardCast(){ + send_bytes=0; + send_pack_num=0; + } int start(myarray data); int dolater(int cmd, myarray data); void timeout(); + bool send_next(); +protected: + int send_bytes; + int send_pack_num; + myarray data; };