From ae972b21aa6563edd7db4055f9b7d4a8911c6c61 Mon Sep 17 00:00:00 2001 From: ranchuan Date: Thu, 30 Nov 2023 10:50:05 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B1=BB=E6=9E=90=E6=9E=84=E6=97=B6=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E5=85=B6=E8=AE=BE=E7=BD=AE=E7=9A=84=E5=9B=9E=E8=B0=83?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prot/prot_m4.cpp | 1 + prot/prot_slave.cpp | 2 +- prot_cmd/cmd_pc.cpp | 53 ++++++++++++++++++++++++++++++++++++++------- prot_cmd/cmd_pc.h | 36 ++++++++++++++++++++++++++++-- 4 files changed, 81 insertions(+), 11 deletions(-) diff --git a/prot/prot_m4.cpp b/prot/prot_m4.cpp index 56a495d..f40fb9d 100644 --- a/prot/prot_m4.cpp +++ b/prot/prot_m4.cpp @@ -76,6 +76,7 @@ prot_m4 *protM4() bool prot_m4::set_irq_fun(prot_m4_cb fun, myarray data) { + if(fun==nullptr) return false; int left; for (int i = 0; i < funs.size(); i++) { diff --git a/prot/prot_slave.cpp b/prot/prot_slave.cpp index e651c3d..e9c1d74 100644 --- a/prot/prot_slave.cpp +++ b/prot/prot_slave.cpp @@ -26,7 +26,7 @@ void prot_slave::init() if((broadcast_!=nullptr)&&(broadcast_->busy)){ broadcast_->addr_response|=1<<(src-1); if(broadcast_->check_response()==true) - broadcast_->dolater(cmd,data); + broadcast_->dolater(broadcast_->cmd,data); }else{ handle=slaves[src-1]; if(handle!=nullptr){ diff --git a/prot_cmd/cmd_pc.cpp b/prot_cmd/cmd_pc.cpp index d4d56f4..b4c7513 100644 --- a/prot_cmd/cmd_pc.cpp +++ b/prot_cmd/cmd_pc.cpp @@ -62,6 +62,11 @@ myarray moter_ctrl(myarray op) } + + + + + // 自研批检仪检测 int selfdev_check::dolater(int cmd, myarray data) { @@ -70,9 +75,9 @@ int selfdev_check::dolater(int cmd, myarray data) mycfg *cfg=syscfg(); busy=1; connect(this, &selfdev_check::send_to_m4_signal, m4, &prot_m4::send_data_slot); - prot_m4_cb moter_down_cb=[=](myarray data) + moter_down_cb_fun=[=](myarray data) { - m4->del_irq_fun(moter_down_cb,"moter "); + m4->del_irq_fun(moter_down_cb_fun,"moter "); if(data=="down"){ // 这里开始检测 QList addrs=cfg->calc_slave_addrs(); @@ -87,7 +92,7 @@ int selfdev_check::dolater(int cmd, myarray data) } } }; - m4->set_irq_fun(moter_down_cb,"moter "); + m4->set_irq_fun(moter_down_cb_fun,"moter "); emit send_to_m4_signal(moter_ctrl("down")); slave_acked.clear(); for(int i=0;islave_num;i++){ @@ -128,7 +133,6 @@ static myarray tran_slave_to_selfdev_check(myarray &data) return r; } - void selfdev_check::slave_end_slot(int addr,int ack, myarray data) { if(addr<=0||addr>slave_acked.size()){ @@ -146,13 +150,17 @@ void selfdev_check::slave_end_slot(int addr,int ack, myarray data) } } - - static HandlePc *get_selfdev_check(){ return new selfdev_check(); } protpc_export(0x30, get_selfdev_check); + + + + + + int selfdev_moter::dolater(int cmd, myarray data) { prot_m4 *m4 = protM4(); @@ -170,8 +178,6 @@ void selfdev_moter::timeout(){ } - - static HandlePc *get_selfdev_moter(){ return new selfdev_moter(); } @@ -180,3 +186,34 @@ protpc_export(0x40, get_selfdev_moter); + + + + +int selfdev_slaveupdate::dolater(int cmd, myarray data) +{ + prot_m4 *m4 = protM4(); + connect(this, &selfdev_slaveupdate::send_to_m4_signal, m4, &prot_m4::send_data_slot); + if(data[0]==0x02){ + emit send_to_m4_signal(moter_ctrl("up")); + }else if(data[0]==0x03){ + emit send_to_m4_signal(moter_ctrl("down")); + } + emit send_data_signal(0x40,myarray(1,char(0))); + return 0; +} + +void selfdev_slaveupdate::timeout(){ + +} + +static HandlePc *get_selfdev_slaveupdate(){ + return new selfdev_slaveupdate(); +} + +protpc_export(0x40, get_selfdev_slaveupdate); + + + + + diff --git a/prot_cmd/cmd_pc.h b/prot_cmd/cmd_pc.h index 11b7482..639d42e 100644 --- a/prot_cmd/cmd_pc.h +++ b/prot_cmd/cmd_pc.h @@ -9,8 +9,19 @@ class selfdev_check : public HandlePc { Q_OBJECT public: - selfdev_check() : HandlePc() {slave_acked_num=0;} - ~selfdev_check() {} + selfdev_check() : HandlePc() { + slave_acked_num=0; + moter_down_cb_fun=nullptr; + } + ~selfdev_check() { + if(moter_down_cb_fun!=nullptr){ + // 取消电机下降到位回调 + prot_m4 *m4 = protM4(); + if(m4!=nullptr) { + m4->del_irq_fun(moter_down_cb_fun,"moter "); + } + } + } int dolater(int cmd, myarray data); void timeout(); public slots: @@ -18,6 +29,7 @@ public slots: protected: QList slave_acked; int slave_acked_num; + prot_m4_cb moter_down_cb_fun; signals: void send_to_m4_signal(myarray data); }; @@ -40,4 +52,24 @@ signals: + +// 小板升级 +class selfdev_slaveupdate : public HandlePc +{ + Q_OBJECT +public: + selfdev_slaveupdate() : HandlePc() {} + ~selfdev_slaveupdate() {} + int dolater(int cmd, myarray data); + void timeout(); +signals: + void send_to_m4_signal(myarray data); +}; + + + + + + + #endif