#include "grpcpc.h" #include static grpcpc * ggrpcpc; grpcpc::grpcpc(std::string stryamlpath) { mstrpicmsgname[0] = "picfront"; mstrpicmsgname[1] = "picrear"; mstrpicmsgname[2] = "picleft"; mstrpicmsgname[3] = "picright"; ggrpcpc = this; unsigned int i; for(i=0;i channel = grpc::CreateCustomChannel( target_str, grpc::InsecureChannelCredentials(),cargs); std::unique_ptr stub_ = iv::UploadThread::NewStub(channel); iv::queryReqThread request; iv::queryReplyThread xreply; int nid = 0; int nctrlid = 0; // Container for the data we expect from the server. // iv::queryReply reply; gpr_timespec timespec; timespec.tv_sec = 30;//设置阻塞时间为2秒 timespec.tv_nsec = 0; timespec.clock_type = GPR_TIMESPAN; qint64 nLastCtrlTime = 0; while(!QThread::isInterruptionRequested()) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); if(abs(xTime.elapsed()-nlastsend)0) { int nbytesize = xmsg.ByteSize(); std::vector pvectordata; pvectordata.resize(nbytesize); if(xmsg.SerializeToArray(pvectordata.data(),nbytesize)) { request.set_xdata(pvectordata.data(),pvectordata.size()); } } } 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_->queryctrl(&context, request, &xreply); if (status.ok()) { // std::cout< channel = grpc::CreateCustomChannel( target_str, grpc::InsecureChannelCredentials(),cargs); std::unique_ptr stub_ = iv::UploadThread::NewStub(channel); iv::PicDownReqThread request; int nid = 0; // Container for the data we expect from the server. iv::PicDownReplyThread reply; gpr_timespec timespec; timespec.tv_sec = 30;//设置阻塞时间为2秒 timespec.tv_nsec = 0; timespec.clock_type = GPR_TIMESPAN; // ClientContext context; while(true) { std::shared_ptr pstr_ptr; if((nCamPos<0)||(nCamPos >= NUM_CAM)) { std::cout<<"Cam Pos Error. "<<"Pos: "<10000) { std::cout<<"not need updata"<querypic(&context, request, &reply); if (status.ok()) { if(reply.nres() == 1) { std::cout<= NUM_CAM))return -1; return mnPicUpLatency[nCamPos]; } int grpcpc::GetFrameRate(int nCamPos) { if((nCamPos < 0)||(nCamPos >= NUM_CAM))return -1; return mnFrameRate[nCamPos]; } qint64 grpcpc::GetPicDownLatency(int nCamPos) { if((nCamPos < 0)||(nCamPos >= NUM_CAM))return -1; return mnPicDownLatency[nCamPos]; } void grpcpc::setserverip(std::string strip) { gstrserverip = strip; } void grpcpc::setserverport(std::string strport) { gstrserverport = strport; } void grpcpc::setqueryinterval(std::string strinterval) { gstruploadinterval = strinterval; } void grpcpc::setVIN(std::string strVIN) { gstrVIN = strVIN; } void grpcpc::setqueryMD5(std::string strmd5) { gstrqueryMD5 = strmd5; } void grpcpc::setctrlMD5(std::string strmd5) { gstrctrlMD5 = strmd5; } int grpcpc::GetRawPic(unsigned int camindex,iv::vision::rawpic & xrawpic) { mnLastGetPicTime = QDateTime::currentMSecsSinceEpoch(); if((camindex >= NUM_CAM))return -1; qint64 now = QDateTime::currentMSecsSinceEpoch(); if((now - mnPicUpdateTime[camindex])>1000) { return 0; } mMutexPic[camindex].lock(); xrawpic.CopyFrom(mRawPic[camindex]); mMutexPic[camindex].unlock(); return 1; } int grpcpc::GetRecvMsg(iv::cloud::cloudmsg & xmsg) { mnLastGetmsgTime = QDateTime::currentMSecsSinceEpoch(); qint64 now = QDateTime::currentMSecsSinceEpoch(); if((now - mnmsgrecvupdatetime) > 1000) { return 0; } mMutexmsgrecv.lock(); xmsg.CopyFrom(mmsgrecv); mMutexmsgrecv.unlock(); return 1; } int grpcpc::SetSendMsg(iv::cloud::cloudmsg & xmsg) { mMutexmsgsend.lock(); mmsgsend.CopyFrom(xmsg); mnmsgsendupdatetime = QDateTime::currentMSecsSinceEpoch(); mMutexmsgsend.unlock(); return 0; }