添加自研批检仪检测命令

This commit is contained in:
ranchuan
2023-11-27 14:31:00 +08:00
parent b3a0d7b57c
commit a0b0f41c39
45 changed files with 3778 additions and 2628 deletions

View File

@@ -1,88 +1,91 @@
#include "prot_m4.h"
#include "QDebug"
void prot_m4::init()
{
if_=interFaceFind("uart_m4");
codec_=codecFind("codec_m4");
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();
}
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.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);
}
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;
}
}
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(data.mid(left));
return true;
}
}
return false;
}
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)
prot_m4 *protM4()
{
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;
if (g_protm4 == nullptr)
{
g_protm4 = new prot_m4();
g_protm4->init();
}
return g_protm4;
}
bool prot_m4::del_irq_fun(prot_m4_cb fun,myarray data)
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){
funs.removeAt(i);
return true;
}
int left;
for (int i = 0; i < funs.size(); i++)
{
left = funs[i].cmd.size();
if (data.left(left) == funs[i].cmd)
{
return false;
}
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;
}

View File

@@ -1,7 +1,6 @@
#ifndef PROT_M4_H
#define PROT_M4_H
#include "QObject"
#include "base/base.h"
#include "QList"
@@ -10,44 +9,39 @@
#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;
typedef struct{
prot_m4_cb fun;
myarray cmd;
}HandleM4_def;
class prot_m4:public QObject
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);
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;
};
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

View File

@@ -3,19 +3,18 @@
#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;
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++)
for (item = start; item < end; item++)
{
if (item != nullptr)
{
if (item->cmd==cmd)
if (item->cmd == cmd)
return item->handle_get_fun();
}
}
@@ -23,57 +22,53 @@ HandlePc *handlePcFind(int cmd)
return nullptr;
}
protpc_export(0xff,nullptr);
void ProtPc::init()
{
if_=interFaceFind("tcp");
codec_=codecFind("codec_ym");
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();
}
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,&ProtPc::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,&ProtPc::send_data_slot);
handle_->dolater(cmd,data);
}
recv_data.clear();
}
});
}
void ProtPc::send_data_slot(int cmd,myarray data)
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);
}
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;
ProtPc *protPc()
{
if (g_protpc == nullptr)
{
g_protpc = new ProtPc();
g_protpc->init();
}
return g_protpc;
}

View File

@@ -10,33 +10,59 @@
#include "interface/interface.h"
#include "base/mycfg.h"
#include "QThread"
#include "QTimer"
// 定义处理命令的类
class HandlePc:public QObject{
class HandlePc : public QObject
{
Q_OBJECT
public:
HandlePc(){busy=0;}
virtual ~HandlePc(){}
virtual int dolater(int cmd,myarray data)=0;
HandlePc() {
busy = 0;
timer_ = nullptr;
}
virtual ~HandlePc() {
if(timer_!=nullptr){
delete timer_;
}
}
virtual int dolater(int cmd, myarray data) = 0;
virtual void timeout()=0;
int busy;
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_;
signals:
void send_data_signal(int cmd,myarray data);
void send_data_signal(int cmd, myarray data);
};
class ProtPc:public QObject{
class ProtPc : public QObject
{
Q_OBJECT
public:
ProtPc(){if_=nullptr;codec_=nullptr;handle_=nullptr;}
~ProtPc(){}
ProtPc()
{
if_ = nullptr;
codec_ = nullptr;
handle_ = nullptr;
}
~ProtPc() {}
void init();
protected slots:
void send_data_slot(int cmd,myarray data);
void send_data_slot(int cmd, myarray data);
protected:
InterFace *if_;
Codec *codec_;
@@ -45,31 +71,18 @@ protected:
myarray recv_data;
};
ProtPc *protPc();
typedef struct
{
int cmd;
HandlePc *(*handle_get_fun)();
} handlepc_def;
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_,\
}
#define protpc_export(cmd_, fun_) \
__attribute__((used)) static handlepc_def _handlepc_##name_ __attribute__((section("protpc"))) = { \
.cmd = cmd_, \
.handle_get_fun = fun_, \
}
#endif

View File

@@ -1,77 +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);
}
}
}
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)
bool prot_slave::set_slave_handle(int addr, HandleSlave *handle)
{
if((addr>slaves.size())||(addr<=0)){
delete handle;
return false;
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;
}
HandleSlave *temp;
temp=slaves[addr-1];
if(temp!=nullptr){
if(temp->busy!=0){
delete handle;
return false;
}else{
delete temp;
}
else
{
delete temp;
}
connect(handle,&HandleSlave::send_data_signal,this,&prot_slave::send_data_slot);
slaves.replace(addr-1,handle);
return true;
}
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);
}
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;
prot_slave *protSlave()
{
if (g_protslave == nullptr)
{
g_protslave = new prot_slave();
// g_protslave->init();
}
return g_protslave;
}

View File

@@ -1,7 +1,6 @@
#ifndef PROT_SLAVE_H
#define PROT_SLAVE_H
#include "QObject"
#include "base/base.h"
#include "QList"
@@ -9,52 +8,80 @@
#include "interface/interface.h"
#include "base/mycfg.h"
#include "QThread"
#include "QTimer"
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
class HandleSlave : public QObject
{
Q_OBJECT
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);
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:
InterFace *if_;
Codec *codec_;
QList<HandleSlave *> slaves;
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