#include "grpcpc.h" static grpcpc * ggrpcpc; void ListenData(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname) { ggrpcpc->UpdateData(strdata,nSize,strmemname); } grpcpc::grpcpc(std::string stryamlpath) { ggrpcpc = this; dec_yaml(stryamlpath.data()); int i; for(i=0;i > writer, bool *pbrun) { int nctrlsize = mvectorctrlmsgunit.size(); int i; int ninterval = atoi(gstruploadinterval.data()); if(ninterval<=0)ninterval = 100; QTime xTime; xTime.start(); int nlastsend = xTime.elapsed(); int nid= 0; while(*pbrun) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); if((xTime.elapsed()-nlastsend) xv = mvectorctrlmsgunit; for(i=0;i nkeeptime) { nkeeptime = mvectorctrlmsgunit[i].mnkeeptime; } iv::cloud::cloudunit xcloudunit; xcloudunit.set_msgname(mvectorctrlmsgunit[i].mstrmsgname); xcloudunit.set_data(mvectorctrlmsgunit[i].mpstrmsgdata.get(),mvectorctrlmsgunit[i].mndatasize); iv::cloud::cloudunit * pcu = xmsg.add_xclouddata(); pcu->CopyFrom(xcloudunit); } } gMutexMsg.unlock(); request.set_strquerymd5(gstrqueryMD5); request.set_strvin(gstrVIN); // request.set_ntime(QDateTime::currentMSecsSinceEpoch()); request.set_ntype(0); if(xmsg.xclouddata_size()>0) { int nbytesize = xmsg.ByteSize(); std::vector pvectordata; pvectordata.resize(nbytesize); if(xmsg.SerializeToArray(pvectordata.data(),nbytesize)) { // request.set_id(nctrlid);nctrlid++; request.set_strctrlmd5(gstrctrlMD5); request.set_nsuggestframerate(mframerate); request.set_xdata(pvectordata.data(),pvectordata.size()); request.set_bimportant(bImportant); request.set_kepptime(nkeeptime); request.set_ntype(1); } } nlastsend = xTime.elapsed(); bool bsend = writer->Write(request); std::cout<<"send msg. rtn is "< channel = grpc::CreateCustomChannel( target_str, grpc::InsecureChannelCredentials(),cargs); std::unique_ptr stub_ = iv::UploadStream::NewStub(channel); int nfail = 0; while(!QThread::isInterruptionRequested()) { ClientContext context ; std::shared_ptr<::grpc::ClientReaderWriter > writerRead(stub_->queryctrl(&context)); bool bRun = true; std::thread * pthread = new std::thread(&grpcpc::threadsend,this,writerRead,&bRun); (void )pthread; iv::queryReplyStream reply; while (writerRead->Read(&reply)) { nfail = 0; // std::cout << "接收到回复:" << reply.remsg()<<"--\n" << std::endl; if(reply.nres() == 1) { std::cout<<"data size is "<join(); nfail++; if(nfail > 100)std::this_thread::sleep_for(std::chrono::milliseconds(3000)); else std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::cout<<"reconnnect to server. nfail is "< vecmodulename; if(config["server"]) { gstrserverip = config["server"].as(); } if(config["port"]) { gstrserverport = config["port"].as(); } if(config["uploadinterval"]) { gstruploadinterval = config["uploadinterval"].as(); } if(config["VIN"]) { gstrVIN = config["VIN"].as(); } if(config["queryMD5"]) { gstrqueryMD5 = config["queryMD5"].as(); } if(config["ctrlMD5"]) { gstrctrlMD5 = config["ctrlMD5"].as(); } std::string strmsgname; if(config["querymessage"]) { for(YAML::const_iterator it= config["querymessage"].begin(); it != config["querymessage"].end();++it) { std::string strtitle = it->first.as(); std::cout<(); strncpy(xmu.mstrmsgname,strmsgname.data(),255); xmu.mnBufferSize = config["querymessage"][strtitle]["buffersize"].as(); xmu.mnBufferCount = config["querymessage"][strtitle]["buffercount"].as(); mvectormsgunit.push_back(xmu); } } } else { } if(config["ctrlmessage"]) { std::string strnodename = "ctrlmessage"; for(YAML::const_iterator it= config[strnodename].begin(); it != config[strnodename].end();++it) { std::string strtitle = it->first.as(); std::cout<(); strncpy(xmu.mstrmsgname,strmsgname.data(),255); xmu.mnBufferSize = config[strnodename][strtitle]["buffersize"].as(); xmu.mnBufferCount = config[strnodename][strtitle]["buffercount"].as(); if(config[strnodename][strtitle]["bimportant"]) { std::string strimportant = config[strnodename][strtitle]["bimportant"].as(); if(strimportant == "true") { xmu.mbImportant = true; } } if(config[strnodename][strtitle]["keeptime"]) { std::string strkeep = config[strnodename][strtitle]["keeptime"].as(); xmu.mnkeeptime = atoi(strkeep.data()); } mvectorctrlmsgunit.push_back(xmu); } } } else { } return; } void grpcpc::sharequerymsg(iv::cloud::cloudmsg *pxmsg) { int i; int nsize = pxmsg->xclouddata_size(); for(i=0;ixclouddata(i).msgname().data(), mvectormsgunit[j].mstrmsgname,255) == 0) { qDebug("size is %d ",pxmsg->xclouddata(i).data().size()); iv::modulecomm::ModuleSendMsg(mvectormsgunit[j].mpa,pxmsg->xclouddata(i).data().data(),pxmsg->xclouddata(i).data().size()); break; } } } } void grpcpc::UpdateData(const char *strdata, const unsigned int nSize,const char * strmemname) { int nsize = mvectorctrlmsgunit.size(); int i; for(i=0;i