2023-11-26 23:05:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef prot_pc_h__
|
|
|
|
#define prot_pc_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 HandlePc : public QObject
|
|
|
|
{
|
2023-11-26 23:05:35 +08:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2023-11-27 14:31:00 +08:00
|
|
|
HandlePc() {
|
|
|
|
busy = 0;
|
|
|
|
timer_ = nullptr;
|
|
|
|
}
|
|
|
|
virtual ~HandlePc() {
|
|
|
|
if(timer_!=nullptr){
|
|
|
|
delete timer_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virtual int dolater(int cmd, myarray data) = 0;
|
2023-12-29 09:41:37 +08:00
|
|
|
virtual void timeout(){busy=0;}
|
2023-11-26 23:05:35 +08:00
|
|
|
int busy;
|
2023-11-27 14:31:00 +08:00
|
|
|
protected:
|
|
|
|
void timeout_start(int ms){
|
|
|
|
if(timer_==nullptr){
|
|
|
|
timer_=new QTimer();
|
|
|
|
connect(timer_,&QTimer::timeout,this,&HandlePc::timeout);
|
|
|
|
}
|
|
|
|
timer_->start(ms);
|
|
|
|
}
|
|
|
|
void timeout_stop(){
|
|
|
|
if(timer_!=nullptr){
|
|
|
|
timer_->stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
QTimer *timer_;
|
2023-11-26 23:05:35 +08:00
|
|
|
signals:
|
2023-11-27 14:31:00 +08:00
|
|
|
void send_data_signal(int cmd, myarray data);
|
2023-11-26 23:05:35 +08:00
|
|
|
};
|
|
|
|
|
2023-12-29 09:41:37 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
HandlePc 重载示例
|
|
|
|
class ChildPc:public HandlePc
|
|
|
|
{
|
|
|
|
// 重载此函数用于接收上位机命令
|
|
|
|
int dolater(int cmd, myarray data);
|
|
|
|
// (可选)重载此函数处理超时的情况
|
|
|
|
void timeout();
|
|
|
|
// 此变量不为0则忙
|
|
|
|
int busy;
|
|
|
|
// 调用此函数开始超时计时
|
|
|
|
void timeout_start(int ms);
|
|
|
|
// 调用此函数停止超时计时
|
|
|
|
void timeout_stop();
|
|
|
|
// 调用此函数给上位机发送数据
|
|
|
|
void send_data_signal(int cmd, myarray data);
|
|
|
|
}
|
|
|
|
|
|
|
|
// .cpp 文件中做以下声明以启用
|
|
|
|
static HandlePc *get_ChidlPc(){
|
|
|
|
return new ChildPc();}
|
|
|
|
protpc_export(0x30, get_ChidlPc);
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-01-29 18:05:23 +08:00
|
|
|
QList<int> handlePcList();
|
2023-12-29 09:41:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-27 14:31:00 +08:00
|
|
|
class ProtPc : public QObject
|
|
|
|
{
|
2023-11-26 23:05:35 +08:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2023-11-27 14:31:00 +08:00
|
|
|
ProtPc()
|
|
|
|
{
|
|
|
|
if_ = nullptr;
|
|
|
|
codec_ = nullptr;
|
|
|
|
handle_ = nullptr;
|
|
|
|
}
|
|
|
|
~ProtPc() {}
|
2023-11-26 23:05:35 +08:00
|
|
|
void init();
|
2023-12-07 18:29:49 +08:00
|
|
|
bool docmd(int cmd,myarray data);
|
2023-12-29 09:41:37 +08:00
|
|
|
bool busy(){return ((handle_!=nullptr)&&(handle_->busy!=0));}
|
2023-12-07 18:29:49 +08:00
|
|
|
public slots:
|
2023-11-27 14:31:00 +08:00
|
|
|
void send_data_slot(int cmd, myarray data);
|
|
|
|
|
2023-11-26 23:05:35 +08:00
|
|
|
protected:
|
|
|
|
InterFace *if_;
|
|
|
|
Codec *codec_;
|
|
|
|
HandlePc *handle_;
|
|
|
|
QThread thread;
|
|
|
|
myarray recv_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
ProtPc *protPc();
|
|
|
|
|
2023-11-27 14:31:00 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int cmd;
|
|
|
|
HandlePc *(*handle_get_fun)();
|
|
|
|
} handlepc_def;
|
2023-11-26 23:05:35 +08:00
|
|
|
|
2023-11-27 14:31:00 +08:00
|
|
|
#define protpc_export(cmd_, fun_) \
|
2023-11-29 15:36:45 +08:00
|
|
|
__attribute__((used)) static handlepc_def _handlepc_##cmd_ __attribute__((section("protpc"))) = { \
|
2023-11-27 14:31:00 +08:00
|
|
|
.cmd = cmd_, \
|
|
|
|
.handle_get_fun = fun_, \
|
|
|
|
}
|
2023-11-26 23:05:35 +08:00
|
|
|
|
|
|
|
#endif
|