Browse Source

change ADCIntelligentShow and tool_xodrobj. add some code for safety exit.

yuchuli 3 years ago
parent
commit
c26c5bd581

+ 16 - 0
src/driver/driver_can_nvidia_agx/canctrl.cpp

@@ -51,6 +51,20 @@ canctrl::canctrl(const char * strmemsend0,const char * strmemsend1,const char *
     mpcan->startdev();
 }
 
+canctrl::~canctrl()
+{
+    mpcan->stopdev();
+
+    delete mpcan;
+
+    iv::modulecomm::Unregister(mpasend1);
+    iv::modulecomm::Unregister(mpasend0);
+    iv::modulecomm::Unregister(mpcanState);
+    iv::modulecomm::Unregister(mparecv1);
+    iv::modulecomm::Unregister(mparecv0);
+
+}
+
 void canctrl::run()
 {
 
@@ -127,6 +141,8 @@ void canctrl::run()
 //        mpcan->mfault->SetFaultState(0, 0, "ok");
     }
 
+    qDebug("thread canctrl complete.");
+
 }
 
 void canctrl::onCANState(bool bCAN, int nR, const char *strres)

+ 1 - 0
src/driver/driver_can_nvidia_agx/canctrl.h

@@ -19,6 +19,7 @@ class canctrl : public QThread
     Q_OBJECT
 public:
     canctrl(const char * strmemsend0,const char * strmemsend1,const char * strmemrecv0,const char * strmemrecv1);
+    ~canctrl();
 
 private slots:
     void onCANState(bool bCAN,int nR,const char * strres);

+ 21 - 16
src/driver/driver_can_nvidia_agx/main.cpp

@@ -14,26 +14,29 @@
 #include <xmlparam.h>
 
 #include "ivversion.h"
+#include "ivexit.h"
 
 
-//void func()
-//{
-//    int i;
-//    i = 0;
-//    while(1)
-//    {
-//        std::this_thread::sleep_for(std::chrono::milliseconds(1000));
-//        i++;
-//        qDebug("pid is ",getpid());
-//        if(i == 10)break;
-//    }
-//    qDebug("pid is %d ",getpid());
-//    kill(getpid(),SIGINT);
-//}
-
+static canctrl * gpcanctrl;
 
+void exitfunc()
+{
+    qDebug("enter exit func.");
+    gpcanctrl->requestInterruption();
+
+    QTime  xTime;
+    xTime.start();
+    while(xTime.elapsed()<1000)
+    {
+        if(gpcanctrl->isFinished())
+        {
+            qDebug("canctrl complete.");
+            delete gpcanctrl;
+            break;
+        }
+    }
 
-static canctrl * gpcanctrl;
+}
 
 
 int main(int argc, char *argv[])
@@ -58,6 +61,8 @@ int main(int argc, char *argv[])
     gpcanctrl = new canctrl(strmemsend0.data(),strmemsend1.data(),strmemrecv0.data(),strmemrecv1.data());
     gpcanctrl->start();
 
+    iv::ivexit::RegIVExitCall(exitfunc);
+
  //   std::thread b(func);
 
     return a.exec();

+ 5 - 0
src/driver/driver_can_nvidia_agx/nvcan.cpp

@@ -129,6 +129,8 @@ void nvcan::run()
     qint64 nLastRecv = QDateTime::currentMSecsSinceEpoch();
     int nRecvState = 0; // 0 Have Data  1 No Data;
 
+    mbRunning = true;
+
     while((!QThread::isInterruptionRequested())&&(mbCANOpen))
     {
         FD_ZERO(&rdfs);
@@ -271,6 +273,8 @@ void nvcan::run()
     {
         close(s[i]);
     }
+    qDebug("nvcan thread close.");
+    mbRunning = false;
 }
 
 void nvcan::startdev()
@@ -289,6 +293,7 @@ void nvcan::stopdev()
         {
             mfault->SetFaultState(1, 0, "can closed");
             mivlog->error("can is closed at %d",xTime.elapsed());
+            qDebug("can is closed.");
             break;
         }
     }

+ 4 - 0
src/tool/IVSysMan/mainwindow.cpp

@@ -145,7 +145,11 @@ MainWindow::~MainWindow()
         }
     }
 
+#ifdef QT_DEBUG
     iv::ivexit::ExecIVExitCmd(mpivexit,"adcivexit-test");   // test iv exit code. can comment this line.
+#endif
+
+    QThread::msleep(1000);
     
     mPM->requestInterruption();
     qint64 time;

+ 2 - 0
src/tool/ivdiagnosis/main.cpp

@@ -9,6 +9,8 @@
 #include "moduleunit.h"
 #include "QtDBus/QDBusConnection"
 
+#include "I
+
 std::vector<moduleunit> gvecmodule;
 
 

+ 20 - 1
src/tool/tool_xodrobj/main.cpp

@@ -1,16 +1,35 @@
 #include "mainwindow.h"
 #include <QApplication>
+#include <thread>
 
 #include "ivversion.h"
 #include "ivbacktrace.h"
 
+#include "ivexit.h"
+
+QApplication * gApp;
+
+MainWindow *  gw;
+
+
+void ExitFunc()
+{
+    gApp->quit();
+    std::this_thread::sleep_for(std::chrono::milliseconds(900));
+}
+
 int main(int argc, char *argv[])
 {
+    iv::ivexit::RegIVExitCall(ExitFunc);
     RegisterIVBackTrace();
     showversion("tool_xodrobj");
     QApplication a(argc, argv);
+    gApp = &a;
     MainWindow w;
     w.show();
+    gw = &w;
 
-    return a.exec();
+    int rc =  a.exec();
+    qDebug("appliction exit.");
+    return rc;
 }

+ 7 - 0
src/tool/tool_xodrobj/mainwindow.cpp

@@ -221,6 +221,12 @@ MainWindow::MainWindow(QWidget *parent) :
 
 MainWindow::~MainWindow()
 {
+
+    iv::modulecomm::Unregister(mpagpsimu);
+    iv::modulecomm::Unregister(mpatrace);
+    iv::modulecomm::Unregister(mpadst);
+    iv::modulecomm::Unregister(mpasrc);
+    qDebug("MainWindow Exit.");
     delete ui;
 }
 
@@ -1486,3 +1492,4 @@ void MainWindow::UpdateGPSIMU(const char * strdata,const unsigned int nSize,cons
 
 }
 
+

+ 1 - 0
src/tool/tool_xodrobj/mainwindow.h

@@ -49,6 +49,7 @@ public:
     explicit MainWindow(QWidget *parent = 0);
     ~MainWindow();
 
+
 private:
     Ui::MainWindow *ui;
 

+ 24 - 1
src/ui/ui_ads_hmi/ADCIntelligentVehicle.cpp

@@ -377,7 +377,7 @@ ADCIntelligentVehicle::ADCIntelligentVehicle(QWidget *parent)
     shareMapReqMsg();
 
     ModuleFun funvbox = std::bind(&ADCIntelligentVehicle::UpdateVbox,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
-    mpaplantrace = iv::modulecomm::RegisterRecvPlus("vbox",funvbox);
+    mpaVbox = iv::modulecomm::RegisterRecvPlus("vbox",funvbox);
 
 #if 1
     ui->lcdNumber->setDigitCount(3); //设置显示几个数字
@@ -447,6 +447,29 @@ ADCIntelligentVehicle::ADCIntelligentVehicle(QWidget *parent)
     ui->pBtn_high_beam_close->setIcon(QIcon(":/Car-Control-icon/YuanGuang-Guan.svg"));
 }
 
+ADCIntelligentVehicle::~ADCIntelligentVehicle()
+{
+    gIvlog->warn("ADCIntelligentVehchicle Exit.");
+    iv::modulecomm::Unregister(mpaplantrace);
+    iv::modulecomm::Unregister(mpamapreq);
+    iv::modulecomm::Unregister(mpManualCtrl);
+    iv::modulecomm::Unregister(mp_v2xStSend);
+    iv::modulecomm::Unregister(mpaHMI);
+    iv::modulecomm::Unregister(mpaLidar);
+    iv::modulecomm::Unregister(mpaDecition);
+    iv::modulecomm::Unregister(mpaVechicleState);
+    iv::modulecomm::Unregister(mpacanstate);
+    iv::modulecomm::Unregister(mpachassis);
+    iv::modulecomm::Unregister(mparadar);
+    iv::modulecomm::Unregister(mpagpsimu);
+    iv::modulecomm::Unregister(mpa);
+    iv::modulecomm::Unregister(mpafusion);
+    iv::modulecomm::Unregister(mpaplantrace_right);
+    iv::modulecomm::Unregister(mpaplantrace_left);
+    iv::modulecomm::Unregister(mpaVbox);
+    qDebug("~ADCIntelligentVehicle()");
+}
+
 /**
  * @brief ADCIntelligentVehicle::savestabuyEditinfo
  * @param txt

+ 1 - 1
src/ui/ui_ads_hmi/ADCIntelligentVehicle.h

@@ -153,7 +153,7 @@ class ADCIntelligentVehicle : public QMainWindow
 
 public:
     explicit ADCIntelligentVehicle(QWidget *parent = 0);
-    //~ADCIntelligentVehicle();
+    ~ADCIntelligentVehicle();
 
 public slots:
 

+ 15 - 0
src/ui/ui_ads_hmi/main.cpp

@@ -10,18 +10,31 @@ iv::Ivlog * gIvlog;
 
 #include "xmlparam.h"
 
+#include "ivexit.h"
+#include <thread>
+
+QApplication * gApp;
+
 std::string gstrmemgps;
 std::string gstrmemradar;
 std::string gstrmemdecition;
 std::string gstrmembrainstate;
 std::string gstrmemchassis;
 
+void ExitFunc()
+{
+    gApp->quit();
+    std::this_thread::sleep_for(std::chrono::milliseconds(900));
+}
+
 int main(int argc, char *argv[])
 {
     RegisterIVBackTrace();
     showversion("ui_ads_hmi");
     QApplication a(argc, argv);
 
+    gApp = &a;
+
     QString strpath = QCoreApplication::applicationDirPath();
 
    if(argc < 2)
@@ -58,5 +71,7 @@ int main(int argc, char *argv[])
 //    w.showMinimized();  //apollo_fu 20200413
     w.showMaximized();
 
+    iv::ivexit::RegIVExitCall(ExitFunc);
+
     return a.exec();
 }