类析构时取消其设置的回调函数

This commit is contained in:
ranchuan
2023-11-30 10:50:05 +08:00
parent e34b8111dc
commit ae972b21aa
4 changed files with 81 additions and 11 deletions

View File

@@ -76,6 +76,7 @@ prot_m4 *protM4()
bool prot_m4::set_irq_fun(prot_m4_cb fun, myarray data) bool prot_m4::set_irq_fun(prot_m4_cb fun, myarray data)
{ {
if(fun==nullptr) return false;
int left; int left;
for (int i = 0; i < funs.size(); i++) for (int i = 0; i < funs.size(); i++)
{ {

View File

@@ -26,7 +26,7 @@ void prot_slave::init()
if((broadcast_!=nullptr)&&(broadcast_->busy)){ if((broadcast_!=nullptr)&&(broadcast_->busy)){
broadcast_->addr_response|=1<<(src-1); broadcast_->addr_response|=1<<(src-1);
if(broadcast_->check_response()==true) if(broadcast_->check_response()==true)
broadcast_->dolater(cmd,data); broadcast_->dolater(broadcast_->cmd,data);
}else{ }else{
handle=slaves[src-1]; handle=slaves[src-1];
if(handle!=nullptr){ if(handle!=nullptr){

View File

@@ -62,6 +62,11 @@ myarray moter_ctrl(myarray op)
} }
// 自研批检仪检测 // 自研批检仪检测
int selfdev_check::dolater(int cmd, myarray data) int selfdev_check::dolater(int cmd, myarray data)
{ {
@@ -70,9 +75,9 @@ int selfdev_check::dolater(int cmd, myarray data)
mycfg *cfg=syscfg(); mycfg *cfg=syscfg();
busy=1; busy=1;
connect(this, &selfdev_check::send_to_m4_signal, m4, &prot_m4::send_data_slot); 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"){ if(data=="down"){
// 这里开始检测 // 这里开始检测
QList<int> addrs=cfg->calc_slave_addrs(); QList<int> 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")); emit send_to_m4_signal(moter_ctrl("down"));
slave_acked.clear(); slave_acked.clear();
for(int i=0;i<cfg->slave_num;i++){ for(int i=0;i<cfg->slave_num;i++){
@@ -128,7 +133,6 @@ static myarray tran_slave_to_selfdev_check(myarray &data)
return r; return r;
} }
void selfdev_check::slave_end_slot(int addr,int ack, myarray data) void selfdev_check::slave_end_slot(int addr,int ack, myarray data)
{ {
if(addr<=0||addr>slave_acked.size()){ 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(){ static HandlePc *get_selfdev_check(){
return new selfdev_check(); return new selfdev_check();
} }
protpc_export(0x30, get_selfdev_check); protpc_export(0x30, get_selfdev_check);
int selfdev_moter::dolater(int cmd, myarray data) int selfdev_moter::dolater(int cmd, myarray data)
{ {
prot_m4 *m4 = protM4(); prot_m4 *m4 = protM4();
@@ -170,8 +178,6 @@ void selfdev_moter::timeout(){
} }
static HandlePc *get_selfdev_moter(){ static HandlePc *get_selfdev_moter(){
return new 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);

View File

@@ -9,8 +9,19 @@ class selfdev_check : public HandlePc
{ {
Q_OBJECT Q_OBJECT
public: public:
selfdev_check() : HandlePc() {slave_acked_num=0;} selfdev_check() : HandlePc() {
~selfdev_check() {} 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); int dolater(int cmd, myarray data);
void timeout(); void timeout();
public slots: public slots:
@@ -18,6 +29,7 @@ public slots:
protected: protected:
QList<myarray> slave_acked; QList<myarray> slave_acked;
int slave_acked_num; int slave_acked_num;
prot_m4_cb moter_down_cb_fun;
signals: signals:
void send_to_m4_signal(myarray data); 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 #endif