|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|