重新构建的批检仪主板程序

This commit is contained in:
andy
2023-11-26 23:05:35 +08:00
parent b1b69d307f
commit 4a70f64693
29 changed files with 2565 additions and 64 deletions

79
prot/prot_pc.cpp Normal file
View 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;
}