88 lines
1.6 KiB
C++
88 lines
1.6 KiB
C++
#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"
|
|
#include "QTimer"
|
|
|
|
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);
|
|
};
|
|
|
|
class prot_slave : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
prot_slave()
|
|
{
|
|
if_ = nullptr;
|
|
codec_ = nullptr;
|
|
}
|
|
~prot_slave() {}
|
|
void init();
|
|
bool set_slave_handle(int addr, HandleSlave *handle);
|
|
protected slots:
|
|
void send_data_slot(int addr, int cmd, myarray data);
|
|
|
|
protected:
|
|
InterFace *if_;
|
|
Codec *codec_;
|
|
QList<HandleSlave *> slaves;
|
|
};
|
|
|
|
prot_slave *protSlave();
|
|
|
|
#endif // PROT_SLAVE_H
|