Browse Source

change ota logic, use ui_ads_hmi confirm. next version use ota.

yuchuli 1 year ago
parent
commit
6b67ca1df6

+ 94 - 0
src/driver/driver_ota_client/otaclient.cpp

@@ -143,6 +143,97 @@ void otaclient::run()
        return;
     }
 
+    QString strignorefilepath = "./otaignore";
+    QString strupdatesigpath = "./otaupdate.sig";
+    QString strupdateconfirm = "./otaconfirm";
+
+    if(bNeedUpdate)
+    {
+        QFile xFileignore;
+        xFileignore.setFileName(strignorefilepath);
+        if(xFileignore.open(QIODevice::ReadOnly))
+        {
+            char strline[256];
+            int nread = xFileignore.readLine(strline,256);
+            xFileignore.close();
+            if(nread >0)
+            {
+                if(strline[nread-1] == '\n')
+                {
+                    nread = nread -1;
+                }
+                if(nread >0)
+                {
+                    strline[nread] = 0;
+                    std::string strignoreversion = strline;
+                    if(strignoreversion == xReply.strversion())
+                    {
+                        std::cout<<" version: "<<strignoreversion<<" is ignore. not need update";
+                        return;
+                    }
+                }
+            }
+        }
+    }
+
+    if(bNeedUpdate)
+    {
+        QFile xFileconfirm;
+        xFileconfirm.setFileName(strupdateconfirm);
+        if(xFileconfirm.exists())
+        {
+            bNeedUpdate = true;
+        }
+        else
+        {
+            bNeedUpdate = false;
+            QFile xFilesig;
+            xFilesig.setFileName(strupdatesigpath);
+            bool bNeedWriteSig = true;
+            if(xFilesig.open(QIODevice::ReadOnly))
+            {
+                char strline[256];
+                int nread = xFilesig.readLine(strline,256);
+                xFilesig.close();
+
+                if(nread >0)
+                {
+                    if(strline[nread-1] == '\n')
+                    {
+                        nread = nread -1;
+                    }
+                    if(nread >0)
+                    {
+                        strline[nread] = 0;
+                        std::string strsigversion = strline;
+                        if(strsigversion == xReply.strversion())
+                        {
+                            bNeedWriteSig = false;
+                        }
+                    }
+                }
+            }
+            if(bNeedWriteSig)
+            {
+                if(xFilesig.open(QIODevice::ReadWrite))
+                {
+                    xFilesig.write(xReply.strversion().data());
+                    xFilesig.close();
+                }
+            }
+
+        }
+    }
+
+    if(bNeedUpdate == false)
+    {
+        std::cout<<"no confirm file. so not update."<<std::endl;
+        return;
+
+    }
+
+
+
 
     std::cout<<"version:"<<xReply.strversion()<<std::endl;
     std::cout<<"   file  size : "<<xReply.nfilesize()<<std::endl;
@@ -252,6 +343,9 @@ void otaclient::run()
                         if(bRename)
                         {
                             qDebug("Successfully  rename to update.zip.");
+                            xDir.remove(strignorefilepath);
+                            xDir.remove(strupdateconfirm);
+                            xDir.remove(strupdatesigpath);
 #ifndef UBUNTU1604
                             givlog->verbose("Successfully  rename to update.zip.");
 #endif

+ 85 - 1
src/driver/driver_ota_server/dialogadd.cpp

@@ -4,6 +4,12 @@
 #include <QFileDialog>
 #include <QMessageBox>
 
+#include <QProcess>
+
+#include <chrono>
+#include <iostream>
+
+
 DialogAdd::DialogAdd(std::vector<iv::vehiclefile> * pvectorfile,QWidget *parent) :
     QDialog(parent),
     ui(new Ui::DialogAdd)
@@ -11,6 +17,9 @@ DialogAdd::DialogAdd(std::vector<iv::vehiclefile> * pvectorfile,QWidget *parent)
     mpvectorfile = pvectorfile;
     ui->setupUi(this);
 
+    ui->lineEdit_version->setReadOnly(true);
+    ui->lineEdit_FilePath->setReadOnly(true);
+
     unsigned int i;
     for(i=0;i<mpvectorfile->size();i++)
     {
@@ -27,11 +36,83 @@ DialogAdd::~DialogAdd()
 
 void DialogAdd::on_pushButton_SelectFile_clicked()
 {
+
+    ui->lineEdit_version->setText("");
+    ui->lineEdit_FilePath->setText("");
     QString str = QFileDialog::getOpenFileName(this,"Sel File",".","*.*");
 
     if(str.isEmpty())return;
 
-    ui->lineEdit_FilePath->setText(str);
+    QFile xFile;
+    int64_t nTime = std::chrono::system_clock::now().time_since_epoch().count();
+    char strtem[256];
+    snprintf(strtem,256,"/tmp/%lld",nTime);
+    QDir xDir;
+    if(xDir.mkdir(strtem))
+    {
+        char strcmd[256];
+
+        snprintf(strcmd,256,"unzip %s \"app/vin.xml\" -d %s",str.toLatin1().data(),strtem);
+        QProcess::execute(strcmd);
+        char strvinpath[256];
+        snprintf(strvinpath,256,"%s/app/vin.xml",strtem);
+        xFile.setFileName(strvinpath);
+        if(xFile.exists())
+        {
+            QMessageBox::warning(this,tr("Warning"),tr("Please delete vin.xml in zip file."),QMessageBox::YesAll);
+        }
+        else
+        {
+
+            snprintf(strcmd,256,"unzip %s \"app/version\" -d %s",str.toLatin1().data(),strtem);
+            QProcess::execute(strcmd);
+            char strversionpath[256];
+            snprintf(strversionpath,256,"%s/app/version",strtem);
+            xFile.setFileName(strversionpath);
+            if(xFile.exists())
+            {
+                if(xFile.open(QIODevice::ReadOnly))
+                {
+                    char strversion[256];
+                    int nread = 0;
+                    if((nread =xFile.readLine(strversion,256))>0)
+                    {
+                        if(strversion[nread-1] == '\n')nread = nread -1;
+                        if(nread > 0)
+                        {
+                            strversion[nread] = 0;
+                            ui->lineEdit_version->setText(strversion);
+                            ui->lineEdit_FilePath->setText(str);
+                        }
+                        else
+                        {
+                            QMessageBox::warning(this,tr("Warning"),tr("No Valid Version."),QMessageBox::YesAll);
+                        }
+                    }
+                    else
+                    {
+
+                        QMessageBox::warning(this,tr("Warning"),tr("Read Version File Fail."),QMessageBox::YesAll);
+                    }
+                    xFile.close();
+                }
+            }
+            else
+            {
+                QMessageBox::warning(this,tr("Warning"),tr("No Version File."),QMessageBox::YesAll);
+                std::cout<<" Vesion File Not Exist."<<std::endl;
+            }
+        }
+
+        snprintf(strcmd,256,"rm -r %s",strtem);
+        QProcess::execute(strcmd);
+    }
+    else
+    {
+        QMessageBox::warning(this,tr("Warning"),tr("Make tmp fail."),QMessageBox::YesAll);
+    }
+
+
 }
 
 void DialogAdd::on_comboBox_vehicletype_currentIndexChanged(int index)
@@ -75,6 +156,9 @@ void DialogAdd::on_pushButton_OK_clicked()
     mbChange = true;
     mpvectorfile->at(index).mstrFilePath = ui->lineEdit_FilePath->text().toStdString();
     mpvectorfile->at(index).mstrVersion = ui->lineEdit_version->text().toStdString();
+
+ //   std::vector<iv::vehiclefile> * pp = mpvectorfile;
+
     accept();
 }
 

+ 1 - 1
src/driver/driver_ota_server/mainwindow.cpp

@@ -54,8 +54,8 @@ void MainWindow::on_actionAdd_triggered()
         if(da.IsChange())
         {
             updatevehicle();
-            savexml();
             mpotaserver->SetVehicleFile(mvectorvehiclefile);
+            savexml();
         }
     }
 }

+ 2 - 2
src/driver/driver_ota_server/otaserver.cpp

@@ -129,7 +129,7 @@ Status OTAServiceImpl::downfile(grpc::ServerContext *context, const iv::ota::Fil
     return Status::OK;
 }
 
-void OTAServiceImpl::SetVehicleFile(std::vector<iv::vehiclefile> xvectorvf)
+void OTAServiceImpl::SetVehicleFile(std::vector<iv::vehiclefile> & xvectorvf)
 {
     mMutexVF.lock();
     unsigned int i;
@@ -194,7 +194,7 @@ void otaserver::run()
     server->Wait();
 }
 
-void otaserver::SetVehicleFile(std::vector<iv::vehiclefile> xvectorvf)
+void otaserver::SetVehicleFile(std::vector<iv::vehiclefile> & xvectorvf)
 {
     mpOTAService->SetVehicleFile(xvectorvf);
 }

+ 2 - 2
src/driver/driver_ota_server/otaserver.h

@@ -35,7 +35,7 @@ public:
 
     Status downfile(grpc::ServerContext *context, const iv::ota::Filereq *request, iv::ota::FileReply *response);
 
-    void SetVehicleFile(std::vector<iv::vehiclefile> xvectorvf);
+    void SetVehicleFile(std::vector<iv::vehiclefile> & xvectorvf);
 
 private:
     std::vector<iv::vehiclefile> mvectorvf;
@@ -56,7 +56,7 @@ private:
     void run();
 
 public:
-    void SetVehicleFile(std::vector<iv::vehiclefile> xvectorvf);
+    void SetVehicleFile(std::vector<iv::vehiclefile> & xvectorvf);
 };
 
 #endif // OTASERVER_H

+ 224 - 0
src/ui/ui_ads_hmi/ADCIntelligentVehicle.cpp

@@ -4,7 +4,19 @@
 #include "xmlparam.h"
 
 
+#ifdef OS_UNIX
+#include "sys/statfs.h"
+#endif
+
+
+#ifdef  OS_WIN
+#include  <windows.h>
+
+#endif
+
 #include <thread>
+#include <QMessageBox>
+#include <QFile>
 
 #define qtcout qDebug() << "[ " << __FILE__ << ":" << __LINE__<< " ]";
 
@@ -502,10 +514,25 @@ ADCIntelligentVehicle::ADCIntelligentVehicle(QWidget *parent)
         ui->groupBox_11->setVisible(false);
     }
 
+    mnHDDSpaceMB = get_path_availspace("./");
+    std::cout<<" HDD Space: "<<mnHDDSpaceMB<<"MB"<<std::endl;
+
+    if(mnHDDSpaceMB<2000)
+    {
+        QMessageBox::warning(this,tr("Warning"),tr("没有足够硬盘空间。请删除回收站文件,log文件夹文件等等,释放足够空间。"),QMessageBox::YesAll);
+    }
+
+    connect(this,SIGNAL(otaversion(const char*)),this,SLOT(onotaversion(const char*)));
+
+    mpthreadota = new std::thread(&ADCIntelligentVehicle::threadotacheck,this);
+
+
 }
 
 ADCIntelligentVehicle::~ADCIntelligentVehicle()
 {
+    mbotacheckclose = true;
+    mpthreadota->join();
     gIvlog->warn("ADCIntelligentVehchicle Exit.");
     iv::modulecomm::Unregister(mpaplantrace);
     iv::modulecomm::Unregister(mpamapreq);
@@ -2705,3 +2732,200 @@ void ADCIntelligentVehicle::UpdateMapDomain(std::vector<iv::GPSData> &xvectorMap
     }
 
 }
+
+
+int ADCIntelligentVehicle::get_path_availspace(const QString & path)
+{
+
+#ifdef OS_UNIX
+    struct statfs diskInfo;
+    std::cout<<" run hea1r. "<<std::endl;
+
+    statfs(path.toLatin1().data(), &diskInfo);
+    std::cout<<" run hear. "<<std::endl;
+
+    qDebug("%s 总大小:%.0lfMB 可用大小:%.0lfMB",path.toLatin1().data(),(diskInfo.f_blocks * diskInfo.f_bsize)/1024.0/1024.0,(diskInfo.f_bavail * diskInfo.f_bsize)/1024.0/1024.0);
+    return (diskInfo.f_bavail * diskInfo.f_bsize)/1024.0/1024.0;
+#endif
+
+#ifdef OS_WIN
+    LPCWSTR lpcwstrDriver=(LPCWSTR)path.utf16();
+
+        ULARGE_INTEGER liFreeBytesAvailable, liTotalBytes, liTotalFreeBytes;
+
+        if( !GetDiskFreeSpaceEx( lpcwstrDriver, &liFreeBytesAvailable, &liTotalBytes, &liTotalFreeBytes) )
+        {
+            qDebug() << "ERROR: Call to GetDiskFreeSpaceEx() failed.";
+            return 0;
+        }
+        return (quint64) liTotalFreeBytes.QuadPart/1024/1024;
+
+#endif
+}
+
+void ADCIntelligentVehicle::threadotacheck()
+{
+    int npresleep = 0;
+    while((mbotacheckclose == false)&&(npresleep<3000))
+    {
+        npresleep++;
+        std::this_thread::sleep_for(std::chrono::milliseconds(1));
+    }
+    if(mbotacheckclose)
+    {
+        return;
+    }
+
+    QString strignorefilepath = "./otaignore";
+    QString strupdatesigpath = "./otaupdate.sig";
+    QString strupdateconfirm = "./otaconfirm";
+
+    QFile xFileConfirm;
+    xFileConfirm.setFileName(strupdateconfirm);
+    if(xFileConfirm.exists())
+    {
+        std::cout<<" confirm file is exist. not need check"<<std::endl;
+        return;
+    }
+
+    std::string strversion = "";
+    bool bNeedUpdate = false;
+    QFile xFilesig;
+    xFilesig.setFileName(strupdatesigpath);
+    if(xFilesig.open(QIODevice::ReadOnly))
+    {
+        char strline[256];
+        int nread = xFilesig.readLine(strline,256);
+        xFilesig.close();
+        if(nread >0)
+        {
+            if(strline[nread-1] == '\n')
+            {
+                nread = nread -1;
+            }
+            if(nread >0)
+            {
+                strline[nread] = 0;
+                strversion = strline;
+                bNeedUpdate = true;
+            }
+        }
+    }
+    else
+    {
+        std::cout<<" no update ."<<std::endl;
+        return;
+    }
+
+    if(bNeedUpdate == false)
+    {
+        std::cout<<" have update sig. but no version."<<std::endl;
+    }
+
+    QFile xFileignore;
+    xFileignore.setFileName(strignorefilepath);
+    if(xFileignore.open(QIODevice::ReadOnly))
+    {
+        char strline[256];
+        int nread = xFileignore.readLine(strline,256);
+        xFileignore.close();
+        if(nread >0)
+        {
+            if(strline[nread-1] == '\n')
+            {
+                nread = nread -1;
+            }
+            if(nread >0)
+            {
+                strline[nread] = 0;
+                std::string strignoreversion = strline;
+                if(strignoreversion == strversion)
+                {
+                    bNeedUpdate = false;
+                    std::cout<<" update sig equal ignore. so not need update"<<std::endl;
+                }
+            }
+        }
+    }
+
+    if(bNeedUpdate)
+    {
+        emit otaversion(strversion.data());
+    }
+
+    npresleep = 0;
+    while((mbotacheckclose == false)&&(npresleep<10000))
+    {
+        npresleep++;
+        std::this_thread::sleep_for(std::chrono::milliseconds(1));
+    }
+
+
+}
+
+void ADCIntelligentVehicle::onotaversion(const char * strversion)
+{
+    QString strignorefilepath = "./otaignore";
+    QString strupdatesigpath = "./otaupdate.sig";
+    QString strupdateconfirm = "./otaconfirm";
+    QMessageBox::StandardButton button;
+    char strquery[1000];
+    snprintf(strquery,1000,"Have new firmware,version %s. Do you want update?",strversion);
+    bool bignore = false;
+    bool bupdateconfirm = false;
+    button=QMessageBox::question(this,tr("OTA"),QString(strquery),QMessageBox::Yes|QMessageBox::No);
+    if(button==QMessageBox::Yes)
+    {
+        bupdateconfirm  = true;
+    }
+    else
+    {
+        button=QMessageBox::question(this,tr("OTA"),QString("Do you ignore this version?"),QMessageBox::Yes|QMessageBox::No);
+        if(button == QMessageBox::Yes)
+        {
+            bignore = true;
+        }
+    }
+
+    if(bupdateconfirm)
+    {
+        if(mnHDDSpaceMB > 2000)
+        {
+
+
+            QFile xFileconfirm;
+            xFileconfirm.setFileName(strupdateconfirm);
+            if(!xFileconfirm.exists())
+            {
+                if(xFileconfirm.open(QIODevice::ReadWrite))
+                {
+                    xFileconfirm.close();
+                    QMessageBox::information(this,tr("OTA"),tr("OTA in background."),QMessageBox::YesAll);
+                }
+                else
+                {
+                    QMessageBox::information(this,tr("OTA"),tr("Write Confirm File Fail."),QMessageBox::YesAll);
+                }
+            }
+        }
+        else
+        {
+            QMessageBox::warning(this,tr("OTA"),tr("No Enough HDD Space for ota."),QMessageBox::YesAll);
+        }
+    }
+
+    if(bignore)
+    {
+        QFile xFileignore;
+        xFileignore.setFileName(strignorefilepath);
+        if(xFileignore.open(QIODevice::ReadWrite))
+        {
+            xFileignore.write(strversion);
+            xFileignore.close();
+        }
+        else
+        {
+            QMessageBox::warning(this,tr("OTA"),tr("Write ignore fail."),QMessageBox::YesAll);
+        }
+    }
+}

+ 12 - 0
src/ui/ui_ads_hmi/ADCIntelligentVehicle.h

@@ -55,6 +55,7 @@
 #include "modulecomm.h"
 
 #include <QMutex>
+#include <thread>
 
 //#include <platform/platform.h>
 
@@ -170,6 +171,9 @@ public:
     explicit ADCIntelligentVehicle(QWidget *parent = 0);
     ~ADCIntelligentVehicle();
 
+signals:
+    void otaversion(const char * strversion);
+
 public slots:
 
     void savestabuyEditinfo(const QString &txt);
@@ -200,6 +204,9 @@ public slots:
     void onStateTimer();
     void onStateTimerMap();
     void onStateTimer1();
+
+    void onotaversion(const char * strversion);
+
 protected:
 
     void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;// 加/减键进行缩放
@@ -415,7 +422,12 @@ private:
     std::vector<double> mDraw_x0,mDraw_y0,mDraw_x1,mDraw_y1,mDraw_x2,mDraw_y2;  //Save Draw Point
     QMutex mMutexDraw;
 
+    int get_path_availspace(const QString & path);
+    int mnHDDSpaceMB;
 
+    void threadotacheck();
+    bool mbotacheckclose = false;
+    std::thread * mpthreadota;
 
 };
 

+ 6 - 0
src/ui/ui_ads_hmi/ui_ads_hmi.pro

@@ -80,6 +80,12 @@ unix:!macx: DEPENDPATH += $$PWD/.
     error( "Couldn't find the ivboost.pri file!" )
 }
 
+contains(QMAKE_HOST.os, Windows){
+    DEFINES += OS_WIN
+}else{
+    DEFINES +=  OS_UNIX
+}
+
 if(contains(DEFINES,SYSTEM_AGX)){
 
 LIBS += -lQt5WebEngine -lQt5WebEngineWidgets