From bd40e4c9c0fa029a1d203b8a5a537776eb27f41d Mon Sep 17 00:00:00 2001 From: ranchuan Date: Tue, 12 Mar 2024 17:47:17 +0800 Subject: [PATCH] =?UTF-8?q?V2.07=20=E6=A3=80=E6=B5=8B=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E8=87=AA=E6=A3=80=E5=91=BD=E4=BB=A4=E9=AA=8C=E8=AF=81=E6=88=90?= =?UTF-8?q?=E5=8A=9F?= 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 +- info.json | 4 +- prot/prot_m4.cpp | 1 + prot_cmd/cmd_checkself.cpp | 191 +++++++++++++++++++++++++++++++++++++ prot_cmd/cmd_checkself.h | 77 +++++++++++++++ prot_cmd/cmd_coder.cpp | 2 +- prot_cmd/cmd_coder.h | 7 ++ prot_cmd/cmd_pc.cpp | 2 +- 10 files changed, 285 insertions(+), 5 deletions(-) create mode 100644 prot_cmd/cmd_checkself.cpp create mode 100644 prot_cmd/cmd_checkself.h diff --git a/ReadMe.txt b/ReadMe.txt index eb1cc9e..7a11006 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -66,6 +66,8 @@ 解决tcp不上报心跳的问题 2024.1.29 添加对hmi屏幕的支持,赋码仪按键按下时发送赋码请求 +2024.3.12 + V2.07 检测参数自检命令验证成功 diff --git a/checker_host.pro b/checker_host.pro index 4f94ffe..fd0aa08 100644 --- a/checker_host.pro +++ b/checker_host.pro @@ -46,6 +46,7 @@ SOURCES += \ prot/prot_m4.cpp \ prot/prot_pc.cpp \ prot/prot_slave.cpp \ + prot_cmd/cmd_checkself.cpp \ prot_cmd/cmd_cmdline.cpp \ prot_cmd/cmd_coder.cpp \ prot_cmd/cmd_hmi_coder.cpp \ @@ -81,6 +82,7 @@ HEADERS += \ prot/prot_m4.h \ prot/prot_pc.h \ prot/prot_slave.h \ + prot_cmd/cmd_checkself.h \ prot_cmd/cmd_cmdline.h \ prot_cmd/cmd_coder.h \ prot_cmd/cmd_hmi_coder.h \ diff --git a/complier_info.h b/complier_info.h index 269042a..d977ead 100644 --- a/complier_info.h +++ b/complier_info.h @@ -6,7 +6,7 @@ -#define BUILD_DATE "2024-03-01 11:12:15" +#define BUILD_DATE "2024-03-12 10:30:39" diff --git a/info.json b/info.json index 6ca9155..90b6644 100644 --- a/info.json +++ b/info.json @@ -1,10 +1,10 @@ { - "build_date": "2024-03-01 11:12:15", + "build_date": "2024-03-12 10:30:39", "hard_version": "MHPZ2_V1.00", "private": [ "info.json", "json.lua", "prints.lua" ], - "soft_version": "V2.06" + "soft_version": "V2.07" } diff --git a/prot/prot_m4.cpp b/prot/prot_m4.cpp index 0b4c854..2ca1909 100644 --- a/prot/prot_m4.cpp +++ b/prot/prot_m4.cpp @@ -30,6 +30,7 @@ void prot_m4::init() void prot_m4::send_data_slot(myarray data) { + if(data.size()==0) return; if ((if_ != nullptr) && (codec_ != nullptr)) { myarray send = codec_->encode(0, 0, 0, data); diff --git a/prot_cmd/cmd_checkself.cpp b/prot_cmd/cmd_checkself.cpp new file mode 100644 index 0000000..75d9a7a --- /dev/null +++ b/prot_cmd/cmd_checkself.cpp @@ -0,0 +1,191 @@ +#include "prot_cmd/cmd_checkself.h" + + + + + + +/* + ++-----------------+-------------------------+----------------------------------------+ +|细分指令 |参数说明 |回复结果说明 | ++-----------------+-------------------------+----------------------------------------+ +|电机归零(0x01) |无 |无 | ++-----------------+-------------------------+----------------------------------------+ +|电机下降(0x02) |下降步数(2bytes,小端) |无 | ++-----------------+-------------------------+----------------------------------------+ +|电机上升(0x03) |上升步数(2bytes,小端) |无 | ++-----------------+-------------------------+----------------------------------------+ +|检桥丝电阻(0x04) |无 |小板地址+桥丝阻值(2bytes) | +| | |多块小板数据域追加相应数据 | ++-----------------+-------------------------+----------------------------------------+ +|打开总线(0x05) |总线电压(2bytes,小端) |小板地址+总线电压(2bytes)(单位0.1V) | +| |(单位0.1V) |多块小板数据域追加相应数据 | ++-----------------+-------------------------+----------------------------------------+ +|关闭总线(0x06) |无 |无 | ++-----------------+-------------------------+----------------------------------------+ +|检总线电流(0x07) |无 |小板地址+总线电流(4bytes)(单位0.1uA)| +| | |多块小板数据域追加相应数据 | ++-----------------+-------------------------+----------------------------------------+ + +*/ + + + + +// 电机控制 +int selfdev_checkself::dolater(int cmd, myarray data) +{ + prot_m4 *m4 = protM4(); + mycfg *cfg_=syscfg(); + int subcmd=data[0]; + if(subcmd>=1&&subcmd<=3){ + connect(this, &selfdev_checkself::send_to_m4_signal, m4, &prot_m4::send_data_slot); + switch (subcmd) + { + case 0x01: + emit send_to_m4_signal("moterinit"); + break; + case 0x02: + { + int count=data[1]|(data[2]<<8); + mystring s = mystring("moter %1").arg(count); + emit send_to_m4_signal(myarray(s.data())); + } + break; + case 0x03: + { + int count=data[1]|(data[2]<<8); + mystring s = mystring("moter %1").arg(-count); + emit send_to_m4_signal(myarray(s.data())); + } + break; + default: + break; + } + myarray r; + r.append(char(0)); + r.append(uint8_t(subcmd)); + emit send_data_signal(0,r); + return 0; + }else{ + pc_ret_cmd=0x50; + return selfdev_runtask::dolater(cmd, data); + } +} + + +// 参数检测 +myarray selfdev_checkself::cmd_pc_to_slave(myarray data) +{ + myarray ret; + const task_def *table=nullptr; + uint16_t params[10]={0}; + subcmd=data[0]; + switch (subcmd) + { + case 0x04: + { + myarray d; + params[0]=0; + coder_add_task(d,"测量桥丝阻值",1,1,params); + coder_slave_pack(d,0x1f); + ret+=d; + // 检测模式3,只执行槽任务 + ret.insert(0,uint8_t(3)); + } + break; + case 0x05: + { + myarray d; + params[0]=data[1]|(data[2]<<8); + coder_add_task(d,"设置总线电压",1,1,params); + coder_slave_pack(d,0x1f); + ret+=d; + // 检测模式3,只执行槽任务 + ret.insert(0,uint8_t(3)); + } + break; + case 0x06: + { + myarray d; + params[0]=data[1]|(data[2]<<8); + coder_add_task(d,"关总线",1,1,params); + coder_slave_pack(d,0x1f); + ret+=d; + // 检测模式3,只执行槽任务 + ret.insert(0,uint8_t(3)); + } + break; + case 0x07: + { + myarray d; + params[0]=data[1]|(data[2]<<8); + coder_add_task(d,"获取总线电流",1,1,params); + coder_slave_pack(d,0x1f); + ret+=d; + // 检测模式3,只执行槽任务 + ret.insert(0,uint8_t(3)); + } + break; + default: + break; + } + return ret; +} + + +// 从机返回转pc +myarray selfdev_checkself::ret_slave_to_pc(QList data) +{ + myarray ret; + ret.append(uint8_t(0)); + ret.append(uint8_t(subcmd)); + switch (subcmd) + { + case 0x04:// 测量桥丝阻值 + for (int i=0;i +#include "prot_cmd/cmd_pc.h" +#include "base/check_cfg.h" +#include "elec/elec_judge.h" +#include "prot_cmd/cmd_coder.h" + + + +/* + + 检测参数自检 + +*/ + + + +// 电机 自研批检仪 +class selfdev_checkself : public selfdev_runtask +{ + Q_OBJECT +public: + selfdev_checkself():selfdev_runtask(){ + pc_ret_cmd=0; + } + int dolater(int cmd, myarray data); + // pc指令转从机 + myarray cmd_pc_to_slave(myarray data); + // pc指令生成从机列表 + QList cmd_pc_to_addrs(myarray data){ + QList addr_list; + addrs=0; + int len=syscfg()->slave_num; + for(int i=0;i data); +protected: + int addrs; + int pc_ret_cmd; + int subcmd; +signals: + void send_to_m4_signal(myarray data); +}; + + + + + + +#endif + + diff --git a/prot_cmd/cmd_coder.cpp b/prot_cmd/cmd_coder.cpp index d541421..f09d260 100644 --- a/prot_cmd/cmd_coder.cpp +++ b/prot_cmd/cmd_coder.cpp @@ -14,7 +14,7 @@ static const task_def g_ew_task_table[]={ {"电源准备",0,1,10,0}, {"延时等待",1,1,2,1}, -{"桥丝电阻测试",2,4,1,1}, +{"测量桥丝阻值",2,4,1,1}, {"上电充能",3,2,3,2}, {"设置总线电压",4,1,1,1}, {"获取总线电流",5,1,0,2}, diff --git a/prot_cmd/cmd_coder.h b/prot_cmd/cmd_coder.h index e6e154c..9734627 100644 --- a/prot_cmd/cmd_coder.h +++ b/prot_cmd/cmd_coder.h @@ -76,6 +76,13 @@ typedef struct{ const task_def *coder_find_task(const char *str); +// 添加一个任务,返回0添加成功 +int coder_add_task(myarray &d,const char *name,int slot_index,int task_index,uint16_t params[10]); +// 包装为一个小板的数据,返回0成功 +// 包装前需要先添加任务 +int coder_slave_pack(myarray &d,int addr); +// 找到指定任务序号的数据 +myarray coder_slave_find_ret_data(myarray data,int task_index,int size); // 赋码仪检测命令 diff --git a/prot_cmd/cmd_pc.cpp b/prot_cmd/cmd_pc.cpp index 691b799..48b9031 100644 --- a/prot_cmd/cmd_pc.cpp +++ b/prot_cmd/cmd_pc.cpp @@ -907,7 +907,7 @@ void selfdev_runtask::timeout() busy=0; } -// 排序,再接收了从机数据之后 +// 排序,在接收了从机数据之后 void selfdev_runtask::slave_sort(){ myarray temp; int slave_num=slave_acked.size();