#include #include "grpcclient.h" #include "ivversion.h" /* #include #include #include #include #include #include #include #include "modulecomm.h" #include "cloud.pb.h" #include #include #include #include #include "uploadmsg.grpc.pb.h" using grpc::Channel; using grpc::ClientContext; using grpc::Status; void test() { std::string target_str = "0.0.0.0:50051"; auto cargs = grpc::ChannelArguments(); cargs.SetMaxReceiveMessageSize(1024 * 1024 * 1024); // 1 GB cargs.SetMaxSendMessageSize(1024 * 1024 * 1024); std::shared_ptr channel = grpc::CreateCustomChannel( target_str, grpc::InsecureChannelCredentials(),cargs); std::unique_ptr stub_ = iv::Upload::NewStub(channel); iv::UploadRequest request; // Container for the data we expect from the server. iv::UploadReply reply; int nid = 0; nid = 1; while(1) { // Context for the client. It could be used to convey extra information to // the server and/or tweak certain RPC behaviors. ClientContext context ; std::this_thread::sleep_for(std::chrono::milliseconds(100)); qint64 time1 = QDateTime::currentMSecsSinceEpoch(); request.set_id(nid); request.set_ntime(time1); nid++; // The actual RPC. Status status = stub_->upload(&context, request, &reply); if (status.ok()) { std::cout< mvectormsgunit; std::vector mvectorctrlmsgunit; std::string gstrVIN = "AAAAAAAAAAAAAAAAA"; std::string gstrqueryMD5 = "5d41402abc4b2a76b9719d911017c591";//"5d41402abc4b2a76b9719d911017c592"; std::string gstrctrlMD5 = "5d41402abc4b2a76b9719d911017c591"; int gindex = 0; void ListenData(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname) { int nsize = mvectormsgunit.size(); int i; for(i=0;ixclouddata_size(); for(i=0;ixclouddata(i).msgname().data(), mvectorctrlmsgunit[j].mstrmsgname,255) == 0) { // qDebug("size is %d ",pxmsg->xclouddata(i).data().size()); iv::modulecomm::ModuleSendMsg(mvectorctrlmsgunit[j].mpa,pxmsg->xclouddata(i).data().data(),pxmsg->xclouddata(i).data().size()); break; } } } } void threadupload() { int nsize = mvectormsgunit.size(); int i; int ninterval = atoi(gstruploadinterval.data()); if(ninterval<=0)ninterval = 100; QTime xTime; xTime.start(); int nlastsend = xTime.elapsed(); std::string target_str = gstrserverip+":"; target_str = target_str + gstrserverport ;//std::to_string() auto cargs = grpc::ChannelArguments(); cargs.SetMaxReceiveMessageSize(1024 * 1024 * 1024); // 1 GB cargs.SetMaxSendMessageSize(1024 * 1024 * 1024); std::shared_ptr channel = grpc::CreateCustomChannel( target_str, grpc::InsecureChannelCredentials(),cargs); std::unique_ptr stub_ = iv::Upload::NewStub(channel); iv::UploadRequest request; int nid = 0; // Container for the data we expect from the server. iv::UploadReply reply; gpr_timespec timespec; timespec.tv_sec = 30;//设置阻塞时间为2秒 timespec.tv_nsec = 0; timespec.clock_type = GPR_TIMESPAN; // ClientContext context; while(true) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); if((xTime.elapsed()-nlastsend) nkeeptime) { nkeeptime = mvectormsgunit[i].mnkeeptime; } iv::cloud::cloudunit xcloudunit; xcloudunit.set_msgname(mvectormsgunit[i].mstrmsgname); xcloudunit.set_data(mvectormsgunit[i].mpstrmsgdata.get(),mvectormsgunit[i].mndatasize); iv::cloud::cloudunit * pcu = xmsg.add_xclouddata(); pcu->CopyFrom(xcloudunit); } } gMutexMsg.unlock(); int nbytesize = xmsg.ByteSize(); char * strbuf = new char[nbytesize]; std::shared_ptr pstrbuf; pstrbuf.reset(strbuf); if(xmsg.SerializeToArray(strbuf,nbytesize)) { ClientContext context ; context.set_deadline(timespec); qint64 time1 = QDateTime::currentMSecsSinceEpoch(); request.set_id(nid); request.set_ntime(time1); request.set_strquerymd5(gstrqueryMD5); request.set_strctrlmd5(gstrctrlMD5); request.set_strvin(gstrVIN); request.set_xdata(strbuf,nbytesize); request.set_kepptime(nkeeptime); request.set_bimportant(bImportant); nid++; // The actual RPC. Status status = stub_->upload(&context, request, &reply); if (status.ok()) { std::cout< 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(); } else { return; } if(config["ctrlMD5"]) { gstrctrlMD5 = config["ctrlMD5"].as(); } std::string strmsgname; if(config["uploadmessage"]) { for(YAML::const_iterator it= config["uploadmessage"].begin(); it != config["uploadmessage"].end();++it) { std::string strtitle = it->first.as(); std::cout<(); strncpy(xmu.mstrmsgname,strmsgname.data(),255); xmu.mnBufferSize = config["uploadmessage"][strtitle]["buffersize"].as(); xmu.mnBufferCount = config["uploadmessage"][strtitle]["buffercount"].as(); if(config["uploadmessage"][strtitle]["bimportant"]) { std::string strimportant = config["uploadmessage"][strtitle]["bimportant"].as(); if(strimportant == "true") { xmu.mbImportant = true; } } if(config["uploadmessage"][strtitle]["keeptime"]) { std::string strkeep = config["uploadmessage"][strtitle]["keeptime"].as(); xmu.mnkeeptime = atoi(strkeep.data()); } mvectormsgunit.push_back(xmu); } } } else { } if(!config["ctrlMD5"]) { return; } 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(); mvectorctrlmsgunit.push_back(xmu); } } } else { } return; } */ int main(int argc, char *argv[]) { showversion("driver_cloud_grpc_client"); QCoreApplication a(argc, argv); // std::thread * ptest = new std::thread(test); // return a.exec(); char stryamlpath[256]; if(argc<2) { snprintf(stryamlpath,255,"driver_cloud_grpc_client.yaml"); // strncpy(stryamlpath,abs_ymlpath,255); } else { strncpy(stryamlpath,argv[1],255); } // dec_yaml(stryamlpath); grpcclient * pgrpcclient = new grpcclient(stryamlpath); pgrpcclient->start(); // int i; // for(i=0;i