重新构建的批检仪主板程序
This commit is contained in:
88
prot/prot_m4.cpp
Normal file
88
prot/prot_m4.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include "prot_m4.h"
|
||||
#include "QDebug"
|
||||
|
||||
|
||||
|
||||
void prot_m4::init()
|
||||
{
|
||||
if_=interFaceFind("uart_m4");
|
||||
codec_=codecFind("codec_m4");
|
||||
|
||||
if_->set_irq([=](myarray recv){
|
||||
if(codec_->packCheck(recv_data)==true){
|
||||
int cmd,src,dst;
|
||||
myarray data=codec_->decode(src,dst,cmd,recv_data);
|
||||
if(exe_cb_fun(data)==false){
|
||||
qWarning("can not find cb fun with:\"%s\"",data);
|
||||
}
|
||||
recv_data.clear();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void prot_m4::send_data_slot(myarray data)
|
||||
{
|
||||
if((if_!=nullptr)&&(codec_!=nullptr)){
|
||||
myarray send=codec_->encode(0,0,0,data);
|
||||
if_->write(send);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool prot_m4::exe_cb_fun(myarray data)
|
||||
{
|
||||
int left;
|
||||
for (int i=0;i<funs.size();i++){
|
||||
left=funs[i].cmd.size();
|
||||
if(data.left(left)==funs[i].cmd){
|
||||
if(funs[i].fun!=nullptr){
|
||||
funs[i].fun(myarray(data.mid(left)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static prot_m4 *g_protm4;
|
||||
prot_m4 *protM4(){
|
||||
if(g_protm4==nullptr){
|
||||
g_protm4=new prot_m4();
|
||||
g_protm4->init();
|
||||
}
|
||||
return g_protm4;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool prot_m4::set_irq_fun(prot_m4_cb fun,myarray data)
|
||||
{
|
||||
int left;
|
||||
for (int i=0;i<funs.size();i++){
|
||||
left=funs[i].cmd.size();
|
||||
if(data.left(left)==funs[i].cmd){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
HandleM4_def m4_cmd;
|
||||
m4_cmd.cmd=data;
|
||||
m4_cmd.fun=fun;
|
||||
funs.append(m4_cmd);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool prot_m4::del_irq_fun(prot_m4_cb fun,myarray data)
|
||||
{
|
||||
int left;
|
||||
for (int i=0;i<funs.size();i++){
|
||||
left=funs[i].cmd.size();
|
||||
if(data.left(left)==funs[i].cmd){
|
||||
funs.removeAt(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
53
prot/prot_m4.h
Normal file
53
prot/prot_m4.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef PROT_M4_H
|
||||
#define PROT_M4_H
|
||||
|
||||
|
||||
#include "QObject"
|
||||
#include "base/base.h"
|
||||
#include "QList"
|
||||
#include "interface/codec.h"
|
||||
#include "interface/interface.h"
|
||||
#include "base/mycfg.h"
|
||||
#include "QThread"
|
||||
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
typedef std::function<void(myarray data)> prot_m4_cb;
|
||||
|
||||
|
||||
typedef struct{
|
||||
prot_m4_cb fun;
|
||||
myarray cmd;
|
||||
}HandleM4_def;
|
||||
|
||||
|
||||
|
||||
class prot_m4:public QObject
|
||||
{
|
||||
public:
|
||||
prot_m4(){if_=nullptr;}
|
||||
~prot_m4(){}
|
||||
void init();
|
||||
bool set_irq_fun(prot_m4_cb fun,myarray data);
|
||||
bool del_irq_fun(prot_m4_cb fun,myarray data);
|
||||
public slots:
|
||||
void send_data_slot(myarray data);
|
||||
protected:
|
||||
bool exe_cb_fun(myarray data);
|
||||
protected:
|
||||
InterFace *if_;
|
||||
QList<HandleM4_def> funs;
|
||||
Codec *codec_;
|
||||
QThread thread;
|
||||
myarray recv_data;
|
||||
};
|
||||
|
||||
|
||||
prot_m4 *protM4();
|
||||
|
||||
#endif // PROT_M4_H
|
||||
|
||||
|
79
prot/prot_pc.cpp
Normal file
79
prot/prot_pc.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
|
||||
|
||||
#include "prot_pc.h"
|
||||
#include "QDebug"
|
||||
|
||||
|
||||
HandlePc *handlePcFind(int cmd)
|
||||
{
|
||||
extern const int __start_protpc;
|
||||
extern const int __stop_protpc;
|
||||
handlepc_def *start=(handlepc_def *)&__start_protpc;
|
||||
handlepc_def *end=(handlepc_def *)&__stop_protpc;
|
||||
handlepc_def *item = 0;
|
||||
for (item=start;item<end;item++)
|
||||
{
|
||||
if (item != nullptr)
|
||||
{
|
||||
if (item->cmd==cmd)
|
||||
return item->handle_get_fun();
|
||||
}
|
||||
}
|
||||
qWarning("can not find protpc cmd= '%02x'", cmd);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
protpc_export(0xff,nullptr);
|
||||
|
||||
|
||||
void ProtPc::init()
|
||||
{
|
||||
if_=interFaceFind("tcp");
|
||||
codec_=codecFind("codec_ym");
|
||||
|
||||
if_->set_irq([=](myarray recv){
|
||||
recv_data+=recv;
|
||||
if(codec_->packCheck(recv_data)==true){
|
||||
int cmd,src,dst;
|
||||
myarray data=codec_->decode(src,dst,cmd,recv_data);
|
||||
if(handle_!=nullptr){
|
||||
if(handle_->busy==0){
|
||||
disconnect(handle_,&HandlePc::send_data_signal,this,send_data_slot);
|
||||
delete handle_;
|
||||
}else{
|
||||
qWarning("prot_pc is busy.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
handle_=handlePcFind(cmd);
|
||||
if(handle_!=nullptr){
|
||||
connect(handle_,&HandlePc::send_data_signal,this,send_data_slot);
|
||||
handle_->dolater(cmd,data);
|
||||
}
|
||||
recv_data.clear();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void ProtPc::send_data_slot(int cmd,myarray data)
|
||||
{
|
||||
if((if_!=nullptr)&&(codec_!=nullptr)){
|
||||
myarray send=codec_->encode(0,0,cmd,data);
|
||||
if_->write(send);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static ProtPc *g_protpc;
|
||||
ProtPc *protPc(){
|
||||
if(g_protpc==nullptr){
|
||||
g_protpc=new ProtPc();
|
||||
g_protpc->init();
|
||||
}
|
||||
return g_protpc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
75
prot/prot_pc.h
Normal file
75
prot/prot_pc.h
Normal file
@@ -0,0 +1,75 @@
|
||||
|
||||
|
||||
#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"
|
||||
|
||||
|
||||
// 定义处理命令的类
|
||||
class HandlePc:public QObject{
|
||||
Q_OBJECT
|
||||
public:
|
||||
HandlePc(){busy=0;}
|
||||
virtual ~HandlePc(){}
|
||||
virtual int dolater(int cmd,myarray data)=0;
|
||||
int busy;
|
||||
signals:
|
||||
void send_data_signal(int cmd,myarray data);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class ProtPc:public QObject{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProtPc(){if_=nullptr;codec_=nullptr;handle_=nullptr;}
|
||||
~ProtPc(){}
|
||||
void init();
|
||||
protected slots:
|
||||
void send_data_slot(int cmd,myarray data);
|
||||
protected:
|
||||
InterFace *if_;
|
||||
Codec *codec_;
|
||||
HandlePc *handle_;
|
||||
QThread thread;
|
||||
myarray recv_data;
|
||||
};
|
||||
|
||||
|
||||
ProtPc *protPc();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct{
|
||||
int cmd;
|
||||
HandlePc *(*handle_get_fun)();
|
||||
}handlepc_def;
|
||||
|
||||
|
||||
|
||||
#define protpc_export(cmd_,fun_) \
|
||||
__attribute__((used)) static handlepc_def _handlepc_##name_ __attribute__((section("protpc")))={\
|
||||
.cmd=cmd_,\
|
||||
.handle_get_fun=fun_,\
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
77
prot/prot_slave.cpp
Normal file
77
prot/prot_slave.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "prot_slave.h"
|
||||
#include "QDebug"
|
||||
|
||||
|
||||
|
||||
|
||||
void prot_slave::init()
|
||||
{
|
||||
if_=interFaceFind("can");
|
||||
codec_=codecFind("codec_slave");
|
||||
mycfg *cfg_=syscfg();
|
||||
for(int i=0;i<cfg_->slave_num;i++){
|
||||
slaves.append(nullptr);
|
||||
}
|
||||
if_->set_irq([=](myarray recv){
|
||||
if(codec_->packCheck(recv)==true){
|
||||
int cmd,src,dst;
|
||||
HandleSlave *handle=nullptr;
|
||||
myarray data=codec_->decode(src,dst,cmd,recv);
|
||||
if((src>slaves.size())||(src<=0)){
|
||||
qWarning("slave addr err:%d",src);
|
||||
}else{
|
||||
handle=slaves[src-1];
|
||||
if(handle!=nullptr){
|
||||
handle->dolater(cmd,data);
|
||||
}else{
|
||||
qWarning("slave addr=%d not have handle.",src);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
bool prot_slave::set_slave_handle(int addr,HandleSlave *handle)
|
||||
{
|
||||
if((addr>slaves.size())||(addr<=0)){
|
||||
delete handle;
|
||||
return false;
|
||||
}
|
||||
HandleSlave *temp;
|
||||
temp=slaves[addr-1];
|
||||
if(temp!=nullptr){
|
||||
if(temp->busy!=0){
|
||||
delete handle;
|
||||
return false;
|
||||
}else{
|
||||
delete temp;
|
||||
}
|
||||
}
|
||||
connect(handle,&HandleSlave::send_data_signal,this,&prot_slave::send_data_slot);
|
||||
slaves.replace(addr-1,handle);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void prot_slave::send_data_slot(int addr,int cmd,myarray data){
|
||||
if((if_!=nullptr)&&(codec_!=nullptr)){
|
||||
myarray send=codec_->encode(0,addr,cmd,data);
|
||||
if_->write(send);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static prot_slave *g_protslave;
|
||||
prot_slave *protSlave(){
|
||||
if(g_protslave==nullptr){
|
||||
g_protslave=new prot_slave();
|
||||
//g_protslave->init();
|
||||
}
|
||||
return g_protslave;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
60
prot/prot_slave.h
Normal file
60
prot/prot_slave.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#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"
|
||||
|
||||
|
||||
class HandleSlave:public QObject{
|
||||
Q_OBJECT
|
||||
public:
|
||||
HandleSlave(){busy=0;}
|
||||
virtual ~HandleSlave(){}
|
||||
virtual int start(myarray data)=0;
|
||||
virtual int dolater(int cmd,myarray data)=0;
|
||||
int busy;
|
||||
signals:
|
||||
void send_data_signal(int addr,int cmd,myarray data);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class prot_slave:public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
prot_slave(){if_=nullptr;codec_=nullptr;busy=0;addr=0;}
|
||||
~prot_slave(){}
|
||||
void init();
|
||||
bool set_slave_handle(int addr,HandleSlave *handle);
|
||||
int busy;
|
||||
int addr;
|
||||
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
|
Reference in New Issue
Block a user