|
@@ -11,9 +11,16 @@ void ListenData(const char * strdata,const unsigned int nSize,const unsigned int
|
|
|
|
|
|
grpcpc::grpcpc(std::string stryamlpath)
|
|
grpcpc::grpcpc(std::string stryamlpath)
|
|
{
|
|
{
|
|
|
|
+
|
|
|
|
+ mstrpicmsgname[0] = "picfront";
|
|
|
|
+ mstrpicmsgname[1] = "picrear";
|
|
|
|
+ mstrpicmsgname[2] = "picleft";
|
|
|
|
+ mstrpicmsgname[3] = "picright";
|
|
|
|
+
|
|
|
|
+
|
|
ggrpcpc = this;
|
|
ggrpcpc = this;
|
|
dec_yaml(stryamlpath.data());
|
|
dec_yaml(stryamlpath.data());
|
|
- int i;
|
|
|
|
|
|
+ unsigned int i;
|
|
for(i=0;i<mvectormsgunit.size();i++)
|
|
for(i=0;i<mvectormsgunit.size();i++)
|
|
{
|
|
{
|
|
mvectormsgunit[i].mpa = iv::modulecomm::RegisterSend(mvectormsgunit[i].mstrmsgname,mvectormsgunit[i].mnBufferSize,mvectormsgunit[i].mnBufferCount);
|
|
mvectormsgunit[i].mpa = iv::modulecomm::RegisterSend(mvectormsgunit[i].mstrmsgname,mvectormsgunit[i].mnBufferSize,mvectormsgunit[i].mnBufferCount);
|
|
@@ -23,6 +30,21 @@ grpcpc::grpcpc(std::string stryamlpath)
|
|
{
|
|
{
|
|
mvectorctrlmsgunit[i].mpa = iv::modulecomm::RegisterRecv(mvectorctrlmsgunit[i].mstrmsgname,ListenData);
|
|
mvectorctrlmsgunit[i].mpa = iv::modulecomm::RegisterRecv(mvectorctrlmsgunit[i].mstrmsgname,ListenData);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ for(i=0;i<NUM_CAM;i++)
|
|
|
|
+ {
|
|
|
|
+ mpaPic[i] = iv::modulecomm::RegisterSend(mstrpicmsgname[i].data(),2000000,1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ for(i=0;i<NUM_CAM;i++)
|
|
|
|
+ {
|
|
|
|
+ unsigned int j;
|
|
|
|
+ for(j=0;j<NUM_THREAD_PERCAM;j++)
|
|
|
|
+ {
|
|
|
|
+ mpThread[i*NUM_THREAD_PERCAM + j] = new std::thread(&grpcpc::threadpicdownload,this,i);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -348,3 +370,104 @@ std::string grpcpc::GetVIN()
|
|
{
|
|
{
|
|
return gstrVIN;
|
|
return gstrVIN;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+void grpcpc::threadpicdownload(int nCamPos)
|
|
|
|
+{
|
|
|
|
+ std::cout<<"thread cam "<<nCamPos<<"run"<<std::endl;
|
|
|
|
+ int nsize = mvectormsgunit.size();
|
|
|
|
+ int i;
|
|
|
|
+
|
|
|
|
+ std::string strcclientid = "test";
|
|
|
|
+
|
|
|
|
+ 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> channel = grpc::CreateCustomChannel(
|
|
|
|
+ target_str, grpc::InsecureChannelCredentials(),cargs);
|
|
|
|
+
|
|
|
|
+ std::unique_ptr<iv::UploadThread::Stub> 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<char> pstr_ptr;
|
|
|
|
+ if((nCamPos<0)||(nCamPos >= NUM_CAM))
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"Cam Pos Error. "<<"Pos: "<<nCamPos<<" TOTAL:"<<NUM_CAM<<std::endl;
|
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ request.set_strclientid(strcclientid);
|
|
|
|
+ request.set_ncampos(nCamPos);
|
|
|
|
+ request.set_strquerymd5(gstrqueryMD5);
|
|
|
|
+ request.set_strvin(gstrVIN);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ ClientContext context ;
|
|
|
|
+ context.set_deadline(timespec);
|
|
|
|
+ qint64 time1 = QDateTime::currentMSecsSinceEpoch();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ nlastsend = xTime.elapsed();
|
|
|
|
+ // The actual RPC.
|
|
|
|
+ Status status = stub_->querypic(&context, request, &reply);
|
|
|
|
+ if (status.ok()) {
|
|
|
|
+
|
|
|
|
+ if(reply.nres() == 1)
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"pic time is "<<reply.npictime()<<std::endl;
|
|
|
|
+// iv::cloud::cloudmsg xmsg;
|
|
|
|
+// if(xmsg.ParseFromArray(reply.xdata().data(),reply.xdata().size()))
|
|
|
|
+// {
|
|
|
|
+// sharectrlmsg(&xmsg);
|
|
|
|
+// }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ std::cout << status.error_code() << ": " << status.error_message()
|
|
|
|
+ << std::endl;
|
|
|
|
+ std::cout<<"RPC failed"<<std::endl;
|
|
|
|
+ if(status.error_code() == 4)
|
|
|
|
+ {
|
|
|
|
+ std::cout<<nCamPos<<" RPC Exceed Time, Create New stub_"<<std::endl;
|
|
|
|
+ channel = grpc::CreateCustomChannel(
|
|
|
|
+ target_str, grpc::InsecureChannelCredentials(),cargs);
|
|
|
|
+
|
|
|
|
+ stub_ = iv::UploadThread::NewStub(channel);
|
|
|
|
+ }
|
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(900));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|