Files
checker_host/prot/prot_pc.cpp

75 lines
1.7 KiB
C++
Raw Normal View History

2023-11-26 23:05:35 +08:00
#include "prot_pc.h"
#include "QDebug"
HandlePc *handlePcFind(int cmd)
{
2023-11-27 14:31:00 +08:00
extern const int __start_protpc;
extern const int __stop_protpc;
handlepc_def *start = (handlepc_def *)&__start_protpc;
handlepc_def *end = (handlepc_def *)&__stop_protpc;
2023-11-26 23:05:35 +08:00
handlepc_def *item = 0;
2023-11-27 14:31:00 +08:00
for (item = start; item < end; item++)
2023-11-26 23:05:35 +08:00
{
if (item != nullptr)
{
2023-11-27 14:31:00 +08:00
if (item->cmd == cmd)
2023-11-26 23:05:35 +08:00
return item->handle_get_fun();
}
}
qWarning("can not find protpc cmd= '%02x'", cmd);
return nullptr;
}
void ProtPc::init()
{
2023-11-27 14:31:00 +08:00
if_ = interFaceFind("tcp");
codec_ = codecFind("codec_ym");
2023-11-26 23:05:35 +08:00
2023-11-27 14:31:00 +08:00
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();
}
2023-11-26 23:05:35 +08:00
});
}
2023-11-27 14:31:00 +08:00
void ProtPc::send_data_slot(int cmd, myarray data)
2023-11-26 23:05:35 +08:00
{
2023-11-27 14:31:00 +08:00
if ((if_ != nullptr) && (codec_ != nullptr))
{
myarray send = codec_->encode(0, 0, cmd, data);
if_->write(send);
}
2023-11-26 23:05:35 +08:00
}
static ProtPc *g_protpc;
2023-11-27 14:31:00 +08:00
ProtPc *protPc()
{
if (g_protpc == nullptr)
{
g_protpc = new ProtPc();
g_protpc->init();
}
return g_protpc;
2023-11-26 23:05:35 +08:00
}