#include "mainwindow.h" #include "ui_mainwindow.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; std::string gstrserverip = "140.143.237.38"; std::string gstrserverport = "9000"; std::string gstruploadinterval = "100"; void * gpa; QMutex gMutexMsg; std::thread * guploadthread; namespace iv { struct msgunit { char mstrmsgname[256]; int mnBufferSize = 10000; int mnBufferCount = 1; void * mpa; std::shared_ptr mpstrmsgdata; int mndatasize = 0; bool mbRefresh = false; bool mbImportant = false; int mnkeeptime = 100; }; } std::vector mvectormsgunit; std::vector mvectorctrlmsgunit; std::string gstrVIN = "AAAAAAAAAAAAAAAAA"; std::string gstrqueryMD5 = "5d41402abc4b2a76b9719d911017c592"; std::string gstrctrlMD5 = "5d41402abc4b2a76b9719d911017c592"; int gindex = 0; void ListenData(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname) { int nsize = mvectorctrlmsgunit.size(); int i; for(i=0;ixclouddata_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 threadquery() { int nsize = mvectormsgunit.size(); int nctrlsize = mvectorctrlmsgunit.size(); int i; qint64 nlasttime = 0; 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::queryreq request; iv::ctrlreq ctrreq; iv::ctrlReply ctrreply; int nid = 0; int nctrlid = 0; // Container for the data we expect from the server. iv::queryReply reply; while(true) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); if(abs(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(); { ClientContext context ; // qint64 time1 = QDateTime::currentMSecsSinceEpoch(); request.set_strquerymd5(gstrqueryMD5); request.set_strvin(gstrVIN); request.set_nlasttime(nlasttime); QDateTime xTime; xTime.fromMSecsSinceEpoch(1607905685318); //1607914763641 // qDebug("time:%s",xTime.toString("yyyy-MM-dd:hh:mm:ss:zzz").toLatin1().data()); qDebug("nlasttime is %ld",nlasttime);//1607905685318 nid++; // The actual RPC. Status status = stub_->query(&context, request, &reply); if (status.ok()) { std::cout<0) { int nbytesize = xmsg.ByteSize(); std::vector pvectordata; pvectordata.resize(nbytesize); if(xmsg.SerializeToArray(pvectordata.data(),nbytesize)) { ClientContext context ; qint64 time1 = QDateTime::currentMSecsSinceEpoch(); ctrreq.set_id(nctrlid);nctrlid++; ctrreq.set_strctrlmd5(gstrctrlMD5); ctrreq.set_strvin(gstrVIN); ctrreq.set_ntime(time1); ctrreq.set_data(pvectordata.data(),pvectordata.size()); ctrreq.set_bimportant(bImportant); ctrreq.set_kepptime(nkeeptime); Status status = stub_->ctrl(&context, ctrreq, &ctrreply); if (status.ok()) { std::cout<<"send id "< 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["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; } */ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); std::string stryamlpath = "./driver_cloud_grpc_pc.yaml"; // dec_yaml(stryamlpath.data()); // int i; // for(i=0;istart(); } MainWindow::~MainWindow() { mgrpcpc->requestInterruption(); while(mgrpcpc->isFinished()); delete ui; }