Files
checker_host/prot/prot_slave.h

88 lines
1.6 KiB
C
Raw Normal View History

2023-11-26 23:05:35 +08:00
#ifndef PROT_SLAVE_H
#define PROT_SLAVE_H
#include "QObject"
#include "base/base.h"
#include "QList"
#include "interface/codec.h"
#include "interface/interface.h"
#include "base/mycfg.h"
#include "QThread"
2023-11-27 14:31:00 +08:00
#include "QTimer"
2023-11-26 23:05:35 +08:00
2023-11-27 14:31:00 +08:00
class HandleSlave : public QObject
{
Q_OBJECT
public:
HandleSlave() {
busy = 0;
addr = 0;
cmd=0;
timer_=nullptr;
}
virtual ~HandleSlave() {
if(timer_!=nullptr){
delete timer_;
}
}
public:
virtual int start(myarray data) = 0;
virtual int dolater(int cmd, myarray data) = 0;
virtual void timeout()=0;
int busy;
int addr;
int cmd;
public:
int send_data(int cmd,myarray data){
emit send_data_signal(addr,cmd,data);
return 0;
}
int end(int ack,myarray data){
emit end_signal(addr,ack,data);
return 0;
}
protected:
void timeout_start(int ms){
if(timer_==nullptr){
timer_=new QTimer();
connect(timer_,&QTimer::timeout,this,&HandleSlave::timeout);
}
timer_->start(ms);
}
void timeout_stop(){
if(timer_!=nullptr){
timer_->stop();
}
}
private:
QTimer *timer_;
signals:
void send_data_signal(int addr, int cmd, myarray data);
void end_signal(int addr,int ack,myarray data);
2023-11-26 23:05:35 +08:00
};
2023-11-27 14:31:00 +08:00
class prot_slave : public QObject
2023-11-26 23:05:35 +08:00
{
2023-11-27 14:31:00 +08:00
Q_OBJECT
2023-11-26 23:05:35 +08:00
public:
2023-11-27 14:31:00 +08:00
prot_slave()
{
if_ = nullptr;
codec_ = nullptr;
}
~prot_slave() {}
void init();
bool set_slave_handle(int addr, HandleSlave *handle);
2023-11-26 23:05:35 +08:00
protected slots:
2023-11-27 14:31:00 +08:00
void send_data_slot(int addr, int cmd, myarray data);
2023-11-26 23:05:35 +08:00
protected:
2023-11-27 14:31:00 +08:00
InterFace *if_;
Codec *codec_;
QList<HandleSlave *> slaves;
2023-11-26 23:05:35 +08:00
};
prot_slave *protSlave();
#endif // PROT_SLAVE_H