Bläddra i källkod

change driver_cloud_grpc_client. add system sentence to protoc.

yuchuli 3 år sedan
förälder
incheckning
b73e784022

+ 2 - 0
src/driver/driver_cloud_grpc_client/driver_cloud_grpc_client.pro

@@ -11,6 +11,8 @@ QMAKE_LFLAGS += -no-pie
 # deprecated API in order to know how to port your code away from it.
 # deprecated API in order to know how to port your code away from it.
 DEFINES += QT_DEPRECATED_WARNINGS
 DEFINES += QT_DEPRECATED_WARNINGS
 
 
+system(protoc -I=./../../include/proto3 --cpp_out=./../../include/msgtype   ./../../include/proto3/uploadmsg.proto)
+
 # You can also make your code fail to compile if it uses deprecated APIs.
 # You can also make your code fail to compile if it uses deprecated APIs.
 # In order to do so, uncomment the following line.
 # In order to do so, uncomment the following line.
 # You can also select to disable deprecated APIs only up to a certain version of Qt.
 # You can also select to disable deprecated APIs only up to a certain version of Qt.

+ 1 - 1
src/driver/driver_cloud_grpc_client/prototocpp.txt

@@ -1,3 +1,3 @@
 protoc -I . --plugin=protoc-gen-grpc=/home/yuchuli/git/grpc-framework/build2/grpc_cpp_plugin --grpc_out=. uploadmsg.proto
 protoc -I . --plugin=protoc-gen-grpc=/home/yuchuli/git/grpc-framework/build2/grpc_cpp_plugin --grpc_out=. uploadmsg.proto
 
 
-protoc -I . --cpp_out=. uploadmsg.proto 
+protoc -I=./../../include/proto3 --cpp_out=./../../include/msgtype   ./../../include/proto3/uploadmsg.proto 

+ 198 - 0
src/driver/driver_cloud_grpc_server_thread/cumsgbuffer.cpp

@@ -0,0 +1,198 @@
+#include "cumsgbuffer.h"
+
+cumsgbuffer::cumsgbuffer()
+{
+
+}
+
+void cumsgbuffer::addmsg(int id, qint64 ntime, std::string strVIN, std::string strqueryMD5, std::string strctrlMD5, std::vector<char> *pxdata,bool bImportant,int nkeeptime)
+{
+    qDebug("ntime is %lld",ntime);
+    mMutex.lock();
+    iv::cumsg * pmsg = 0;
+    int nsize = mvectormsg.size();
+    int i;
+    for(i=0;i<nsize;i++)
+    {
+        if(strncmp(mvectormsg[i].strVIN.data(),strVIN.data(),255) == 0)
+        {
+            pmsg = &mvectormsg[i];
+            break;
+        }
+    }
+    if(pmsg == 0)
+    {
+        iv::cumsg cmsg;
+        cmsg.id = id;
+        cmsg.ntime = ntime;
+        cmsg.strVIN = strVIN;
+        cmsg.strqueryMD5 = strqueryMD5;
+        cmsg.strctrlMD5 = strctrlMD5;
+        if(pxdata->size() > 0)
+        {
+            cmsg.xdata.resize(pxdata->size());
+            memcpy(cmsg.xdata.data(),pxdata->data(),pxdata->size());
+        }
+        cmsg.mlastuptime = QDateTime::currentMSecsSinceEpoch();
+        cmsg.mbImportant = bImportant;
+        cmsg.mkeeptime = nkeeptime;
+        cmsg.mbhavequery = false;
+        mvectormsg.push_back(cmsg);
+        mMutex.unlock();
+        return;
+    }
+
+    if((pmsg->mbImportant != true)||(pmsg->mbhavequery)||((QDateTime::currentMSecsSinceEpoch() - pmsg->mlastuptime)>=pmsg->mkeeptime))
+    {
+        pmsg->id = id;
+        pmsg->ntime = ntime;
+        pmsg->mbImportant = bImportant;
+        pmsg->mbhavequery = false;
+        pmsg->mlastuptime = QDateTime::currentMSecsSinceEpoch();
+        pmsg->mkeeptime = nkeeptime;
+        pmsg->strqueryMD5 = strqueryMD5;
+        pmsg->strctrlMD5 = strctrlMD5;
+        pmsg->xdata.clear();
+        if(pxdata->size()>0)
+        {
+            pmsg->xdata.resize(pxdata->size());
+            memcpy(pmsg->xdata.data(),pxdata->data(),pxdata->size());
+        }
+    }
+
+    mMutex.unlock();
+}
+
+
+int cumsgbuffer::getmsg(std::string strVIN,std::string strqueryMD5, qint64 nlasttime, int &id, qint64 &ntime,   std::vector<char> *pxdata)
+{
+    mMutex.lock();
+    iv::cumsg * pmsg = 0;
+    int nsize = mvectormsg.size();
+    int i;
+    for(i=0;i<nsize;i++)
+    {
+        if(strncmp(mvectormsg[i].strVIN.data(),strVIN.data(),255) == 0)
+        {
+            pmsg = &mvectormsg[i];
+            break;
+        }
+    }
+
+    if(pmsg == 0)
+    {
+        std::cout<<" no this vin data"<<std::endl;;
+        mMutex.unlock();
+        return -1;
+    }
+
+    if(strqueryMD5 != pmsg->strqueryMD5)
+    {
+        std::cout<<" query error."<<std::endl;
+        mMutex.unlock();
+        return -2;
+    }
+    pmsg->mbhavequery = true;
+    if(nlasttime == pmsg->ntime)
+    {
+        mMutex.unlock();
+        return 0;
+    }
+    id = pmsg->id;
+    ntime = pmsg->ntime;
+    pxdata->clear();
+    int ndatasize = pmsg->xdata.size();
+    pxdata->resize(ndatasize);
+    memcpy(pxdata->data(),pmsg->xdata.data(),ndatasize);
+    mMutex.unlock();
+    return 1;
+}
+
+void cumsgbuffer::addPicData(std::string strVIN, const char *strdata, const unsigned int ndatasize,
+                             qint64 npictime, int nCamPos)
+{
+    mMutex.lock();
+    iv::cumsg * pmsg = 0;
+    int nsize = mvectormsg.size();
+    int i;
+    for(i=0;i<nsize;i++)
+    {
+        if(strncmp(mvectormsg[i].strVIN.data(),strVIN.data(),255) == 0)
+        {
+            pmsg = &mvectormsg[i];
+            break;
+        }
+    }
+    if(pmsg == 0)
+    {
+        std::cout<<" Not Found buf. Need Data Prepare."<<std::endl;
+    }
+    else
+    {
+        if((nCamPos<0)||(nCamPos>= CAM_NUM))
+        {
+            std::cout<<"Camera Postion error . nCamPos = "<<nCamPos<<std::endl;
+        }
+        else
+        {
+            iv::PicData xPicData;
+            xPicData.mdata_ptr = std::shared_ptr<char>(new char[ndatasize]);
+            memcpy(xPicData.mdata_ptr.get(),strdata,ndatasize);
+            xPicData.mdatasize = ndatasize;
+            xPicData.mnMsgTime = npictime;
+            pmsg->mpicbuf[nCamPos].AddData(xPicData);
+        }
+    }
+
+    mMutex.unlock();
+}
+
+int cumsgbuffer::getPicData(std::string strVIN, std::string strqueryMD5,std::shared_ptr<char> &pdata_ptr,
+                            unsigned int &ndatasize, qint64 &nLastPicTime, int nCamPos)
+{
+    mMutex.lock();
+    iv::cumsg * pmsg = 0;
+    int nsize = mvectormsg.size();
+    int i;
+    for(i=0;i<nsize;i++)
+    {
+        if(strncmp(mvectormsg[i].strVIN.data(),strVIN.data(),255) == 0)
+        {
+            pmsg = &mvectormsg[i];
+            break;
+        }
+    }
+
+    if(pmsg == 0)
+    {
+        std::cout<<" no this vin data"<<std::endl;;
+        mMutex.unlock();
+        return -1;
+    }
+
+    if(strqueryMD5 != pmsg->strqueryMD5)
+    {
+        std::cout<<" query error."<<std::endl;
+        mMutex.unlock();
+        return -2;
+    }
+
+    if((nCamPos<0)||(nCamPos>= CAM_NUM))
+    {
+        std::cout<<"cumsgbuffer::getPicData Camera Postion error . nCamPos = "<<nCamPos<<std::endl;
+        mMutex.unlock();
+        return -3;
+    }
+
+    iv::PicData xPicData;
+    int nrtn = pmsg->mpicbuf[nCamPos].GetData(nLastPicTime,xPicData);
+    if(nrtn == 1)
+    {
+        pdata_ptr = xPicData.mdata_ptr;
+        ndatasize = xPicData.mdatasize;
+    }
+
+
+    mMutex.unlock();
+    return nrtn;
+}

+ 67 - 0
src/driver/driver_cloud_grpc_server_thread/cumsgbuffer.h

@@ -0,0 +1,67 @@
+#ifndef CUMSGBUFFER_H
+#define CUMSGBUFFER_H
+
+#include <QDateTime>
+#include <QMutex>
+#include <string>
+#include <iostream>
+#include <vector>
+
+#include <memory>
+
+
+#include <picbuf.h>
+
+#define CAM_NUM 4
+
+namespace iv {
+struct cumsg
+{
+
+public:
+
+    int id;
+    qint64 ntime;
+    std::string strVIN;
+    std::string strqueryMD5;
+    std::string strctrlMD5;
+    std::vector<char> xdata;
+    qint64 mlastuptime;  //更新时间
+    bool mbImportant = false;
+    int mkeeptime;
+    bool mbhavequery = false;
+    PicBuf mpicbuf[CAM_NUM];
+};
+}
+
+class cumsgbuffer
+{
+public:
+    cumsgbuffer();
+
+private:
+    std::vector<iv::cumsg> mvectormsg;
+
+    QMutex mMutex;
+
+public:
+    void addmsg(int id,qint64 ntime,std::string strVIN,std::string strqueryMD5,
+                std::string strctrlMD5,std::vector<char> * pxdata,bool bImportant,int nkeeptime);
+
+
+    //if no new msg return 0
+    // -1 no this vin
+    // -2 queryMD5 error
+    int getmsg(std::string strVIN,std::string strqueryMD5,qint64 nlasttime, int & id,qint64 & ntime,
+                std::vector<char> * pxdata);
+
+
+    void addPicData(std::string strVIN,const char * strdata,const unsigned int ndatasize,qint64 npictime,int nCamPos);
+
+    int getPicData(std::string strVIN,std::string strqueryMD5,std::shared_ptr<char> & pdata_ptr,unsigned int & ndatasize,qint64 & nLastPicTime
+                   ,int nCamPos);
+
+
+};
+
+#endif // CUMSGBUFFER_H

+ 190 - 0
src/driver/driver_cloud_grpc_server_thread/main.cpp

@@ -0,0 +1,190 @@
+#include <QCoreApplication>
+#include <QDateTime>
+#include <iostream>
+#include <vector>
+
+#include "cumsgbuffer.h"
+#include "pcmsgbuffer.h"
+
+#include <iostream>
+#include <memory>
+#include <string>
+
+#include <grpcpp/grpcpp.h>
+#include <grpcpp/health_check_service_interface.h>
+#include <grpcpp/ext/proto_server_reflection_plugin.h>
+
+#include "uploadthreadmsg.grpc.pb.h"
+
+using grpc::Server;
+using grpc::ServerBuilder;
+using grpc::ServerContext;
+using grpc::Status;
+
+
+
+#include <QDateTime>
+
+
+
+
+
+
+static cumsgbuffer gcumsgbuf;
+static pcmsgbuffer gpcmsgbuf;
+
+
+// Logic and data behind the server's behavior.
+class UploadServiceImpl final : public iv::UploadThread::Service {
+  Status uploaddata(ServerContext* context, const iv::UploadRequestThread* request,
+                  iv::UploadReplyThread* reply) override {
+
+    std::vector<char> xvectordata;
+    qDebug("size is %d",request->xdata().size());
+    if(request->xdata().size()>0)
+    {
+
+        xvectordata.resize(request->xdata().size());
+        memcpy(xvectordata.data(),request->xdata().data(),request->xdata().size());
+    }
+
+    gcumsgbuf.addmsg(request->id(),request->ntime(),request->strvin(),request->strquerymd5(),request->strctrlmd5(),
+                     &xvectordata,request->bimportant(),request->kepptime());
+
+ //   std::string strVIN,strctrlMD5;
+    int id;
+    qint64 ntime;
+
+    std::vector<char > xvectorctrldata;
+
+    int nres = gpcmsgbuf.getmsg(request->strvin(),request->strctrlmd5(),id,ntime,&xvectorctrldata);
+
+    reply->set_nres(nres);
+
+    if(nres == 1)
+    {
+
+        reply->set_xdata(xvectorctrldata.data(),xvectorctrldata.size());
+    }
+
+
+
+//    char * strdata = new char[10000000];
+//    qint64 time = QDateTime::currentMSecsSinceEpoch();
+//    memcpy(strdata,&time,8);
+//    reply->set_data(strdata,10000000);
+//    delete strdata;
+    return Status::OK;
+  }
+
+  Status queryctrl(ServerContext* context, const iv::queryReqThread* request,
+                  iv::queryReplyThread* reply) override {
+
+      int id;
+      qint64 ntime;
+      std::vector<char > xvectorquerydata;
+
+      std::vector<char> xvectordata;
+      if(request->xdata().size()>0)
+      {
+          xvectordata.resize(request->xdata().size());
+          memcpy(xvectordata.data(),request->xdata().data(),request->xdata().size());
+          gpcmsgbuf.addmsg(request->id(),request->ntime(),request->strvin(),request->strctrlmd5(),&xvectordata,
+                                     request->bimportant(),request->kepptime());
+      }
+
+
+
+      int nres = gcumsgbuf.getmsg(request->strvin(),request->strquerymd5(),request->nlasttime(),id,ntime,&xvectorquerydata);
+
+      reply->set_nres(nres);
+      if(nres > 0)
+      {
+          reply->set_xdata(xvectorquerydata.data(),xvectorquerydata.size());
+          reply->set_id(id);
+          reply->set_ntime(ntime);
+      }
+
+      return Status::OK;
+
+
+  }
+
+  Status uploadpic(ServerContext* context, const iv::PicUpRequestThread* request,
+                  iv::PicUpReplyThread* reply) override {
+      gcumsgbuf.addPicData(request->strvin(),request->xdata().data(),
+                           request->xdata().size(),request->npictime(),request->ncampos());
+      reply->set_nres(0);
+
+      return Status::OK;
+
+  }
+
+//  Status ctrl(ServerContext* context, const iv::ctrlreq* request,
+//                  iv::ctrlReply * reply) override {
+
+//      std::vector<char> xvectordata;
+//      if(request->data().size()>0)
+//      {
+//          xvectordata.resize(request->data().size());
+//          memcpy(xvectordata.data(),request->data().data(),request->data().size());
+//      }
+
+//      int nid = gpcmsgbuf.addmsg(request->id(),request->ntime(),request->strvin(),request->strctrlmd5(),&xvectordata,
+//                                 request->bimportant(),request->kepptime());
+
+//      reply->set_nsendid(nid);
+
+
+//      return Status::OK;
+
+
+//  }
+
+
+};
+
+void RunServer() {
+  std::string server_address("0.0.0.0:50051");
+  UploadServiceImpl service;
+
+  grpc::EnableDefaultHealthCheckService(true);
+//  grpc::reflection::InitProtoReflectionServerBuilderPlugin();
+  ServerBuilder builder;
+  // Listen on the given address without any authentication mechanism.
+  builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
+
+  builder.SetMaxReceiveMessageSize(300000000);
+ // builder.SetMaxMessageSize(100000000);
+
+
+//  builder.SetMaxSendMessageSize(100000000);
+  // Register "service" as the instance through which we'll communicate with
+  // clients. In this case it corresponds to an *synchronous* service.
+  builder.RegisterService(&service);
+  // Finally assemble the server.
+  std::unique_ptr<Server> server(builder.BuildAndStart());
+  std::cout << "Server listening on " << server_address << std::endl;
+
+  // Wait for the server to shutdown. Note that some other thread must be
+  // responsible for shutting down the server for this call to ever return.
+  server->Wait();
+}
+
+
+
+
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication a(argc, argv);
+
+    gpcmsgbuf.start();
+
+    RunServer();
+
+
+
+
+    return a.exec();
+}

+ 171 - 0
src/driver/driver_cloud_grpc_server_thread/pcmsgbuffer.cpp

@@ -0,0 +1,171 @@
+#include "pcmsgbuffer.h"
+
+pcmsgbuffer::pcmsgbuffer()
+{
+
+}
+
+void pcmsgbuffer::run()
+{
+    while(!QThread::isInterruptionRequested())
+    {
+        mMutex.lock();
+        qint64 nowtime = QDateTime::currentMSecsSinceEpoch();
+        int i;
+        for(i=0;i<mvectorpcmsgstate.size();i++)
+        {
+            if((nowtime - mvectorpcmsgstate[i].nsendtime) > OVERTIME)
+            {
+                mvectorpcmsgstate.erase(mvectorpcmsgstate.begin() + i);
+                i--;
+            }
+        }
+        mMutex.unlock();
+        msleep(100);
+    }
+}
+
+unsigned int pcmsgbuffer::addmsg(int id, qint64 ntime, std::string strVIN, std::string strctrlMD5, std::vector<char> *pxdata,bool bImportant,int nkeeptime)
+{
+    unsigned int nrtn;
+    mMutex.lock();
+    iv::pcmsg * pmsg = 0;
+    int nsize = mvectormsg.size();
+    int i;
+    for(i=0;i<nsize;i++)
+    {
+        if(strncmp(mvectormsg[i].strVIN.data(),strVIN.data(),255) == 0)
+        {
+            pmsg = &mvectormsg[i];
+            break;
+        }
+    }
+    if(pmsg == 0)
+    {
+        iv::pcmsg cmsg;
+        cmsg.id = id;
+        cmsg.ntime = ntime;
+        cmsg.strVIN = strVIN;
+        cmsg.strctrlMD5 = strctrlMD5;
+        if(pxdata->size() > 0)
+        {
+            cmsg.xdata.resize(pxdata->size());
+            memcpy(cmsg.xdata.data(),pxdata->data(),pxdata->size());
+        }
+        cmsg.mlastuptime = QDateTime::currentMSecsSinceEpoch();
+        cmsg.nsendid = muid;
+        cmsg.mbImportant = bImportant;
+        cmsg.mkeeptime = nkeeptime;
+        nrtn = muid;
+        muid++;
+        mvectormsg.push_back(cmsg);
+        iv::pcmsgstate xpms;xpms.nsendid = cmsg.nsendid;
+        xpms.nsendtime = QDateTime::currentMSecsSinceEpoch();
+        mvectorpcmsgstate.push_back(xpms);
+        mMutex.unlock();
+        return nrtn;
+    }
+
+    if((pmsg->mbImportant != true)||((QDateTime::currentMSecsSinceEpoch() - pmsg->mlastuptime)>=pmsg->mkeeptime))
+    {
+        changesendstate(pmsg->nsendid,-2);
+        pmsg->mbImportant = bImportant;
+        pmsg->mkeeptime = nkeeptime;
+        pmsg->id = id;
+        pmsg->ntime = ntime;
+        pmsg->strctrlMD5 = strctrlMD5;
+        pmsg->xdata.clear();
+        pmsg->nsendid = muid;
+ //       cmsg.mlastuptime = QDateTime::currentMSecsSinceEpoch();
+        nrtn = muid;
+        iv::pcmsgstate xpms;xpms.nsendid = pmsg->nsendid;
+        pmsg->mlastuptime = QDateTime::currentMSecsSinceEpoch();
+        mvectorpcmsgstate.push_back(xpms);
+        muid++;
+        if(pxdata->size()>0)
+        {
+            pmsg->xdata.resize(pxdata->size());
+            memcpy(pmsg->xdata.data(),pxdata->data(),pxdata->size());
+        }
+    }
+
+
+    mMutex.unlock();
+    return nrtn;
+}
+
+int pcmsgbuffer::getmsg(std::string strVIN, std::string strctrlMD5, int &id, qint64 &ntime, std::vector<char> *pxdata)
+{
+    mMutex.lock();
+    iv::pcmsg * pmsg = 0;
+    int nsize = mvectormsg.size();
+    int i;
+    int npos;
+    for(i=0;i<nsize;i++)
+    {
+        if(strncmp(mvectormsg[i].strVIN.data(),strVIN.data(),255) == 0)
+        {
+            pmsg = &mvectormsg[i];
+            npos = i;
+            break;
+        }
+    }
+
+    if(pmsg == 0)
+    {
+        std::cout<<" no this vin data"<<std::endl;;
+        mMutex.unlock();
+        return 0;
+    }
+    if(strctrlMD5 != pmsg->strctrlMD5)
+    {
+        std::cout<<" ctrl error."<<std::endl;
+        changesendstate(pmsg->nsendid,-1);
+        mMutex.unlock();
+        return -2;
+    }
+
+    id = pmsg->id;
+    ntime = pmsg->ntime;
+    pxdata->clear();
+    int ndatasize = pmsg->xdata.size();
+    pxdata->resize(ndatasize);
+    memcpy(pxdata->data(),pmsg->xdata.data(),ndatasize);
+    changesendstate(pmsg->nsendid,1);
+
+    mvectormsg.erase(mvectormsg.begin()+npos);
+    mMutex.unlock();
+    return 1;
+}
+
+void pcmsgbuffer::changesendstate(int nsendid, int nstate)
+{
+    int nstatesize = mvectorpcmsgstate.size();
+    int i;
+    for(i=0;i<nstatesize;i++)
+    {
+        if(nsendid == mvectorpcmsgstate[i].nsendid)
+        {
+            mvectorpcmsgstate[i].nstate = nstate; //Send OK
+            break;
+        }
+    }
+}
+
+int pcmsgbuffer::querysendstate(int nsendid)
+{
+    int nrtn = -2;
+    mMutex.lock();
+    int nstatesize = mvectorpcmsgstate.size();
+    int i;
+    for(i=0;i<nstatesize;i++)
+    {
+        if(nsendid == mvectorpcmsgstate[i].nsendid)
+        {
+            nrtn = mvectorpcmsgstate[i].nstate;
+            break;
+        }
+    }
+    mMutex.unlock();
+    return nrtn;
+}

+ 66 - 0
src/driver/driver_cloud_grpc_server_thread/pcmsgbuffer.h

@@ -0,0 +1,66 @@
+#ifndef PCMSGBUFFER_H
+#define PCMSGBUFFER_H
+
+#include <QDateTime>
+#include <QMutex>
+#include <string>
+#include <iostream>
+
+#include <QThread>
+
+namespace iv {
+struct pcmsg
+{
+    int id;
+    qint64 ntime;
+    std::string strVIN;
+    std::string strctrlMD5;
+    std::vector<char> xdata;
+    qint64 mlastuptime;  //更新时间
+    unsigned int nsendid; //send id
+    bool mbImportant = false;
+    int mkeeptime;
+    bool mbhavequery = false;
+};
+}
+
+namespace  iv {
+struct pcmsgstate
+{
+    qint64 nsendtime;
+    unsigned int nsendid;
+    int nstate = 0; //0 wait send 1 send ok -1 md5 error -2 timeout.
+};
+}
+
+class pcmsgbuffer:public QThread
+{
+public:
+    pcmsgbuffer();
+
+private:
+    std::vector<iv::pcmsg> mvectormsg;
+    std::vector<iv::pcmsgstate> mvectorpcmsgstate;
+    QMutex mMutex;
+    const int OVERTIME = 60000; //60 seconds
+    unsigned int muid = 0;
+
+public:
+
+    unsigned int addmsg(int id,qint64 ntime,std::string strVIN,
+                std::string strctrlMD5,std::vector<char> * pxdata,bool bImportant,int nkeeptime);
+
+    //if no new msg return 0
+    // -2 queryMD5 error
+    int getmsg(std::string strVIN,std::string strctrlMD5,int & id,qint64 & ntime,
+                std::vector<char> * pxdata);
+
+    int querysendstate(int nsendid);
+private:
+    void changesendstate(int nsendid,int nstate);
+
+private:
+    void run();
+};
+
+#endif // PCMSGBUFFER_H

+ 109 - 0
src/driver/driver_cloud_grpc_server_thread/picbuf.cpp

@@ -0,0 +1,109 @@
+#include "picbuf.h"
+
+#include <iostream>
+
+PicBuf::PicBuf()
+{
+
+}
+
+void PicBuf::AddData(iv::PicData xPicData)
+{
+    static int nunusual = 0;
+    mMutexBuf.lock();
+
+    if((xPicData.mnMsgTime + mBufTime*30) < mLastBufTime)
+    {
+        nunusual++;
+    }
+    else
+    {
+        nunusual = 0;
+    }
+
+    if(nunusual > 10)
+    {
+        std::cout<<" Time Unusual.Reset Buffer"<<std::endl;
+        mvectordata_ptr.clear();
+    }
+
+
+    if(mvectordata_ptr.size() == 0)
+    {
+        mvectordata_ptr.push_back(xPicData);
+        mLastBufTime = xPicData.mnMsgTime;
+        mMutexBuf.unlock();
+        return;
+    }
+
+
+
+    if(xPicData.mnMsgTime > mLastBufTime)
+    {
+        mvectordata_ptr.push_back(xPicData);
+        mLastBufTime = xPicData.mnMsgTime;
+
+    }
+    else
+    {
+        unsigned int j;
+        for(j=0;j<mvectordata_ptr.size();j++)
+        {
+            if(mvectordata_ptr.at(j).mnMsgTime > xPicData.mnMsgTime)
+            {
+                mvectordata_ptr.insert(mvectordata_ptr.begin()+j,xPicData);
+                break;
+            }
+        }
+    }
+
+    int i;
+    for(i=0;i<(int)(mvectordata_ptr.size());i++)
+    {
+        if(abs(mLastBufTime - mvectordata_ptr.at(i).mnMsgTime) > mBufTime)
+        {
+            mvectordata_ptr.erase(mvectordata_ptr.begin() + i);
+            i--;
+        }
+    }
+
+    mMutexBuf.unlock();
+}
+
+int PicBuf::GetData(qint64 &nLastTime, iv::PicData &xPicData)
+{
+    int nrtn = 0;
+    mMutexBuf.lock();
+    if(nLastTime > mLastBufTime)
+    {
+        nLastTime = mLastBufTime;
+        mMutexBuf.unlock();
+        return 0;
+    }
+
+    unsigned int i;
+    for(i=0;i<mvectordata_ptr.size();i++)
+    {
+        if(mvectordata_ptr.at(i).mnMsgTime > (mLastBufTime - mnReceiveBufTime ))
+        {
+            break; //becuase in this time Data not complete.
+        }
+        if(mvectordata_ptr.at(i).mnMsgTime > nLastTime)
+        {
+            nLastTime = mvectordata_ptr.at(i).mnMsgTime;
+            xPicData = mvectordata_ptr.at(i);
+            nrtn = 1;
+            break;
+        }
+    }
+    mMutexBuf.unlock();
+    return nrtn;
+}
+
+PicBuf::PicBuf(const PicBuf &other)
+{
+    mvectordata_ptr = other.mvectordata_ptr;
+    mBufTime = other.mBufTime;
+    mnReceiveBufTime = other.mnReceiveBufTime;
+    mLastBufTime = other.mLastBufTime;
+}

+ 34 - 0
src/driver/driver_cloud_grpc_server_thread/picbuf.h

@@ -0,0 +1,34 @@
+#ifndef PICBUF_H
+#define PICBUF_H
+
+#include <memory>
+#include <vector>
+#include <QMutex>
+
+namespace iv {
+struct PicData
+{
+public:
+    qint64 mnMsgTime;
+    std::shared_ptr<char> mdata_ptr;
+    unsigned int mdatasize;
+};
+
+}
+
+class PicBuf
+{
+private:
+    std::vector<iv::PicData> mvectordata_ptr;
+    qint64 mBufTime = 200;
+    qint64 mnReceiveBufTime = 100;
+    qint64 mLastBufTime = 0;
+    QMutex mMutexBuf;
+public:
+    PicBuf();
+    PicBuf(const PicBuf & other);
+    void AddData(iv::PicData xPicData);
+    int GetData(qint64 & nLastTime,iv::PicData & xPicData);  //0 No Data  1 Have Data
+};
+
+#endif // PICBUF_H

+ 2 - 0
src/driver/driver_cloud_grpc_thread/driver_cloud_grpc_thread.pro

@@ -11,6 +11,8 @@ QMAKE_LFLAGS += -no-pie
 # deprecated API in order to know how to port your code away from it.
 # deprecated API in order to know how to port your code away from it.
 DEFINES += QT_DEPRECATED_WARNINGS
 DEFINES += QT_DEPRECATED_WARNINGS
 
 
+system(protoc -I=./../../include/proto3 --cpp_out=./../../include/msgtype   ./../../include/proto3/uploadthreadmsg.proto)
+
 # You can also make your code fail to compile if it uses deprecated APIs.
 # You can also make your code fail to compile if it uses deprecated APIs.
 # In order to do so, uncomment the following line.
 # In order to do so, uncomment the following line.
 # You can also select to disable deprecated APIs only up to a certain version of Qt.
 # You can also select to disable deprecated APIs only up to a certain version of Qt.

+ 5 - 1
src/include/proto3/uploadthreadmsg.proto

@@ -82,6 +82,10 @@ message queryReqThread {
   bool mbCamRear = 14;    
   bool mbCamRear = 14;    
   bool mbCamLeft = 15;
   bool mbCamLeft = 15;
   bool mbCamRight = 16;
   bool mbCamRight = 16;
+  string strClientID = 17; ///
+  int64 nlasttime = 18;
+  int32 id = 19;
+  
 }
 }
 
 
 message queryReplyThread {
 message queryReplyThread {
@@ -110,7 +114,7 @@ message PicDownReqThread{
   string strVIN = 1;
   string strVIN = 1;
   string strqueryMD5 = 2;
   string strqueryMD5 = 2;
   int32 nCamPos = 3; //0 front 1 rear 2 left 3 right
   int32 nCamPos = 3; //0 front 1 rear 2 left 3 right
-  int64 nPicTime = 4;  // > this PicTime
+  string strClientID = 4; ///
 }
 }
 
 
 message PicDownReplyThread{
 message PicDownReplyThread{