Browse Source

change ADCIntelligentSHow_grpc.

yuchuli 4 years ago
parent
commit
e3125d0dc8

+ 15 - 3
src/driver/driver_group_grpc_server/groupdb.cpp

@@ -545,7 +545,7 @@ int groupdb::getfilepath(qint64 nrecordid, std::string strvehid,std::string & st
     return nres;
 }
 
-int groupdb::GetFileData(std::string strfilename, qint64 nPos, qint64 nFilesize, QByteArray &ba)
+int groupdb::GetFileData(std::string strfilename, qint64 nPos, qint64 nSize, qint64 & nFilesize, QByteArray &ba)
 {
     QString strpath;
     if(GetFilePathDir(strpath)!= 0)
@@ -555,6 +555,15 @@ int groupdb::GetFileData(std::string strfilename, qint64 nPos, qint64 nFilesize,
     }
     strpath = strpath + "/"+ strfilename.data();
 
+    if(nPos<0)
+    {
+        QFile xFile;
+        xFile.setFileName(strpath);
+        xFile.remove();
+        nFilesize = 0;
+        return 0;
+    }
+
     QFile xFile;
     xFile.setFileName(strpath);
     if(!xFile.open(QIODevice::ReadOnly))
@@ -569,7 +578,10 @@ int groupdb::GetFileData(std::string strfilename, qint64 nPos, qint64 nFilesize,
         return -3;
     }
     ba.clear();
-    ba = xFile.read(nFilesize);
-    return ba.size();
+    ba = xFile.read(nSize);
+    nFilesize = xFile.size();
+    xFile.close();
+    int nrtn = ba.size();
+    return nrtn;
 
 }

+ 1 - 1
src/driver/driver_group_grpc_server/groupdb.h

@@ -55,7 +55,7 @@ public:
 
     int getfilepath(qint64 nrecordid,std::string strvehid,std::string & strfilename,int & nfilesize);
 
-    int GetFileData(std::string strfilename,qint64 nPos,qint64 nFilesize,QByteArray & ba);
+    int GetFileData(std::string strfilename,qint64 nPos,qint64 nSize, qint64 & nFilesize,QByteArray & ba);
 
 private:
     std::vector<iv::groupdbmsg> mvectordbmsg;

+ 5 - 2
src/driver/driver_group_grpc_server/groupmsgbuf.cpp

@@ -179,12 +179,15 @@ int groupmsgbuf::ProcDBFileReqMsg(const iv::db::dataRequest *preq, iv::db::dataR
 int groupmsgbuf::ProcDBFileDownMsg(const iv::db::Filedbreq *preq, iv::db::FiledbReply *preply)
 {
     QByteArray ba;
-    int nSize = mpgroupdb->GetFileData(preq->strfilename(),preq->npos(),preq->nsize(),ba);
+    qint64 nfilesize;
+    int nSize = mpgroupdb->GetFileData(preq->strfilename(),preq->npos(),preq->nsize(),nfilesize,ba);
     preply->set_nsize(nSize);
     if(nSize >= 0)
     {
-        preply->set_xdata(ba.data(),ba.size());
+        if(nSize > 0)preply->set_xdata(ba.data(),ba.size());
+        preply->set_nfilesize(nfilesize);
     }
+
     return 0;
 }
 

+ 1 - 1
src/include/proto3/grpcdb.proto

@@ -61,7 +61,7 @@ message dataReply {
 message Filedbreq
 {
   string strfilename = 1;
-  int64 nPos = 2;
+  int64 nPos = 2;  //if nPos < 0, Tell Server delete File.
   int64 nSize = 3;
 }
 

+ 53 - 0
src/tool/tool_grpcdb_query/grpcdbclient.cpp

@@ -103,6 +103,42 @@ void grpcdbclient::run()
         }
 
 
+        if(mbfilerequpdate)
+        {
+            iv::db::Filedbreq xfilereq;
+            iv::db::FiledbReply xfilereply;
+            mMutexFileReq.lock();
+            xfilereq.CopyFrom(mfilereq);
+            mbfilerequpdate = false;
+            mMutexFileReq.unlock();
+
+            ClientContext context ;
+            context.set_deadline(timespec);
+
+            Status status = stub_->downdbfile(&context, xfilereq, &xfilereply);
+            if (status.ok()) {
+             std::cout<<"get file data ok"<<std::endl;
+             mfilereply.CopyFrom(xfilereply);
+             emit filereqres(0);
+            } else {
+              std::cout << status.error_code() << ": " << status.error_message()
+                        << std::endl;
+              std::cout<<"RPC failed"<<std::endl;
+              emit filereqres(-1);
+              if(status.error_code() == 4)
+              {
+                  std::cout<<" RPC Exceed Time, Create New stub_"<<std::endl;
+                  channel = grpc::CreateCustomChannel(
+                           target_str, grpc::InsecureChannelCredentials(),cargs);
+
+                  stub_ = iv::db::dbservice::NewStub(channel);
+              }
+              std::this_thread::sleep_for(std::chrono::milliseconds(900));
+
+            }
+
+        }
+
     }
 
 }
@@ -139,3 +175,20 @@ int grpcdbclient::getdatareply(iv::db::dataReply &xdatareply)
     xdatareply.CopyFrom(mdatareply);
     return 0;
 }
+
+void grpcdbclient::requestfiledata(std::string filename, int npos, int nsize)
+{
+    mMutexFileReq.lock();
+    mfilereq.set_strfilename(filename);
+    mfilereq.set_npos(npos);
+    mfilereq.set_nsize(nsize);
+    mbfilerequpdate = true;
+    mMutexFileReq.unlock();
+    mwc.wakeAll();
+}
+
+int grpcdbclient::getfilereply(iv::db::FiledbReply &xfilereply)
+{
+    xfilereply.CopyFrom(mfilereply);
+    return 0;
+}

+ 9 - 0
src/tool/tool_grpcdb_query/grpcdbclient.h

@@ -20,6 +20,7 @@ public:
 signals:
     void reqres(int);
     void datareqres(int);
+    void filereqres(int);
 
 private:
     std::string mstrserverip = "127.0.0.1";
@@ -35,6 +36,11 @@ private:
     bool mbdatarequpdate = false;
     QMutex mMutexDataReq;
 
+    iv::db::Filedbreq mfilereq;
+    iv::db::FiledbReply mfilereply;
+    bool mbfilerequpdate = false;
+    QMutex mMutexFileReq;
+
     QMutex mWaitMutex;
     QWaitCondition mwc;
 
@@ -47,6 +53,9 @@ public:
 
     void requestfilename(qint64 recordid,std::string strvehid);
     int getdatareply(iv::db::dataReply & xdatareply);
+
+    void requestfiledata(std::string filename,int npos,int nsize);
+    int getfilereply(iv::db::FiledbReply & xfilereply);
 };
 
 #endif // GRPCDBCLIENT_H

+ 112 - 0
src/tool/tool_grpcdb_query/mainwindow.cpp

@@ -3,6 +3,8 @@
 
 #include <QMessageBox>
 
+#include <QFileDialog>
+
 #include <QDateTime>
 
 MainWindow::MainWindow(QWidget *parent)
@@ -15,10 +17,13 @@ MainWindow::MainWindow(QWidget *parent)
     mpdbclient->start();
     connect(mpdbclient,SIGNAL(reqres(int)),this,SLOT(onreqres(int)));
     connect(mpdbclient,SIGNAL(datareqres(int)),this,SLOT(ondatareqres(int)));
+    connect(mpdbclient,SIGNAL(filereqres(int)),this,SLOT(onfilereqres(int)));
 
     mpitemmodel = new QStandardItemModel(this);
 
     ui->listView->setModel(mpitemmodel);
+    ui->progressBar->setVisible(false);
+    ui->progressBar->setRange(0,100);
 
     setWindowTitle("Query grpcdb");
 }
@@ -166,6 +171,8 @@ void MainWindow::on_pushButton_DownLoad_clicked()
 
     mpdbclient->requestfilename(nrecordid,strvehid);
 
+    ui->pushButton_DownLoad->setEnabled(false);
+
 }
 
 void MainWindow::ondatareqres(int nres)
@@ -180,5 +187,110 @@ void MainWindow::ondatareqres(int nres)
 
     mpdbclient->getdatareply(xdatareply);
 
+    mstrfilename = xdatareply.strfilename();
+
     qDebug("file name is %s, size is %d",xdatareply.strfilename().data(),xdatareply.nfilesize());
+
+    QString str = QFileDialog::getSaveFileName(this,"Save ivd",".","*.ivd");
+
+    if(str.isEmpty())
+    {
+        mpdbclient->requestfiledata(mstrfilename,-1,0);
+        ui->pushButton_DownLoad->setEnabled(true);
+        return;
+    }
+
+
+
+
+    if(str.indexOf(".ivd")<0)str = str + ".ivd";
+
+    mFileIVD.setFileName(str);
+
+    if(!mFileIVD.open(QIODevice::ReadWrite))
+    {
+        QMessageBox::warning(this,"Warning","Can't Save IVD File.",QMessageBox::YesAll);
+        mpdbclient->requestfiledata(mstrfilename,-1,0);
+        ui->pushButton_DownLoad->setEnabled(true);
+        return;
+    }
+
+    mbFileIVD = true;
+
+    mnFilePos = 0;
+
+    ui->progressBar->setVisible(true);
+    ui->progressBar->setValue(0);
+
+    qint64 npos = 0;
+    qint64 nsize = 5000000;
+    if((npos + nsize)>((qint64)xdatareply.nfilesize()))
+    {
+        nsize = ((qint64)xdatareply.nfilesize()) - npos;
+    }
+
+    mpdbclient->requestfiledata(mstrfilename,(int)npos,(int)nsize);
+}
+
+void MainWindow::onfilereqres(int nres)
+{
+    if(nres == -1)
+    {
+        QMessageBox::warning(this,"Warning","Download File Fail.",QMessageBox::YesAll);
+        ui->pushButton_DownLoad->setEnabled(true);
+        return;
+    }
+
+    iv::db::FiledbReply xfilereply;
+
+    mpdbclient->getfilereply(xfilereply);
+
+    if(xfilereply.nfilesize() == 0)
+    {
+        ui->progressBar->setVisible(false);
+        ui->pushButton_DownLoad->setEnabled(true);
+        return;
+    }
+
+    if(xfilereply.nfilesize() > 0)
+    {
+        qint64 nProg = ((mnFilePos + xfilereply.nsize())*100/xfilereply.nfilesize());
+        ui->progressBar->setValue(nProg);
+    }
+
+    if(xfilereply.nsize()>0)
+    {
+        if(mbFileIVD)
+        {
+            mFileIVD.write(xfilereply.xdata().data(),xfilereply.xdata().size());
+        }
+    }
+
+    if((mnFilePos + xfilereply.nsize())>= xfilereply.nfilesize())
+    {
+        QMessageBox::information(this,"Info","SuccessFully DownLoad File.",QMessageBox::YesAll);
+        ui->progressBar->setVisible(false);
+        ui->pushButton_DownLoad->setEnabled(true);
+
+        if(mbFileIVD)
+        {
+            mFileIVD.close();
+            mbFileIVD = false;
+        }
+
+        mpdbclient->requestfiledata(mstrfilename,-1,0);
+    }
+    else
+    {
+        mnFilePos = mnFilePos + xfilereply.nsize();
+        qint64 npos = mnFilePos ;
+        qint64 nsize = 5000000;
+        if((npos + nsize)>((qint64)xfilereply.nfilesize()))
+        {
+            nsize = ((qint64)xfilereply.nfilesize()) - npos;
+        }
+
+        mpdbclient->requestfiledata(mstrfilename,(int)npos,(int)nsize);
+
+    }
 }

+ 10 - 0
src/tool/tool_grpcdb_query/mainwindow.h

@@ -5,6 +5,8 @@
 
 #include <QStandardItemModel>
 
+#include <QFile>
+
 #include "grpcdbclient.h"
 
 QT_BEGIN_NAMESPACE
@@ -32,11 +34,19 @@ private slots:
 
     void ondatareqres(int nres);
 
+    void onfilereqres(int nres);
+
 private:
     Ui::MainWindow *ui;
 
     grpcdbclient * mpdbclient;
 
     QStandardItemModel * mpitemmodel;
+
+    std::string mstrfilename;
+    qint64 mnFilePos;
+
+    QFile mFileIVD;
+    bool mbFileIVD;
 };
 #endif // MAINWINDOW_H

+ 24 - 17
src/ui/ADCIntelligentShow_grpc/gps_nbtype.h

@@ -38,29 +38,36 @@ namespace iv {
 
         int speed_mode = 0;
         int mode2 = 0;
-        double speed = 3.5;			//速度  若导航点则为导航预设速度  若为当前点则为当前车速
+        double speed = 0;			//速度  若导航点则为导航预设速度  若为当前点则为当前车速
 
         int roadMode;
         int runMode;
         int roadSum;
         int roadOri;
 
-    double mfLaneWidth = 3.5; // Current Lane Width
-
-    double mfDisToLaneLeft = 1.8; //Distance to Lane Left
-    int mnLaneChangeMark = 0; //1 to Left 0 not change   -1 to right
-    double mfDisToRoadLeft = 1.8; //Distance to Road Left
-    double mfRoadWidth = 3.5; // Road Width
-
-    bool mbInLaneAvoid = false; //if true suport In Lane Avoid
-    double gps_lat_avoidleft;
-    double gps_lng_avoidleft;
-    double gps_lat_avoidright;
-    double gps_lng_avoidright;
-    double gps_x_avoidleft = 0;
-    double gps_y_avoidleft = 0;
-    double gps_x_avoidright = 0;
-    double gps_y_avoidright = 0;
+        double mfLaneWidth = 3.5; // Current Lane Width
+
+        double mfDisToLaneLeft = 1.8; //Distance to Lane Left
+        int mnLaneChangeMark = 0; //1 to Left 0 not change   -1 to right
+        double mfDisToRoadLeft = 1.8; //Distance to Road Left
+        double mfRoadWidth = 3.5; // Road Width
+
+        bool mbInLaneAvoid = false; //if true suport In Lane Avoid
+        double gps_lat_avoidleft;
+        double gps_lng_avoidleft;
+        double gps_lat_avoidright;
+        double gps_lng_avoidright;
+        double gps_x_avoidleft = 0;
+        double gps_y_avoidleft = 0;
+        double gps_x_avoidright = 0;
+        double gps_y_avoidright = 0;
+
+        bool mbnoavoid = false; //If true this point is no avoid.
+        double mfCurvature = 0.0;
+
+        char mcreserved[10];
+        int mnreserved[5];
+        double mfreserved[2];