浏览代码

Change IVSysMan And Controller_changan_shenlan. for unactivate.

yuchuli 1 年之前
父节点
当前提交
9ce0c613af

+ 49 - 20
src/controller/controller_changan_shenlan_v2/main.cpp

@@ -20,34 +20,40 @@
 
 #include <thread>
 
-void * gpacansend;
-void * gpadecition;
-void * gpachassis;
+#ifdef Q_OS_LINUX
+#include <signal.h>
+#endif
+
+static void * gpacansend;
+static void * gpadecition;
+static void * gpachassis;
 
-std::string gstrmemdecition;
-std::string gstrmemcansend;
-std::string gstrmemchassis;
-bool gbSendRun = true;
+static std::string gstrmemdecition;
+static std::string gstrmemcansend;
+static std::string gstrmemchassis;
+static bool gbSendRun = true;
 
-bool gbChassisEPS = false;
+static bool gbChassisEPS = false;
 
-iv::brain::decition gdecition_def;
-iv::brain::decition gdecition;
+static iv::brain::decition gdecition_def;
+static iv::brain::decition gdecition;
 
-QTime gTime;
-int gnLastSendTime = 0;
-int gnLastRecvDecTime = -1000;
-int gnDecitionNum = 0; //when is zero,send default;
+static QTime gTime;
+static int gnLastSendTime = 0;
+static int gnLastRecvDecTime = -1000;
+static int gnDecitionNum = 0; //when is zero,send default;
 const int gnDecitionNumMax = 100;
-int gnIndex = 0;
+static int gnIndex = 0;
 
 static bool gbHaveVehSpd = false;
 static double gfVehSpd = 0.0;
 
-boost::shared_ptr<iv::control::Controller> gcontroller;	//实际车辆控制器
+static boost::shared_ptr<iv::control::Controller> gcontroller;	//实际车辆控制器
 
 static QMutex gMutex;
 
+static std::thread * gpsendthread = NULL;
+
 
 // signal: @ACC_LatAngReq    //更改CANid
 #define ECU_1C4_ACC_LatAngReq_CovFactor (0.1)
@@ -325,7 +331,7 @@ void Activate()
 //    for(int j=0;j<100000;j++)
 //    {
         std::cout<<" run "<<std::endl;
-    for(int i = 0; i < 10; i++){
+    for(int i = 0; i < 3; i++){
         xdecition.set_wheelangle(0.0);
         xdecition.set_angle_mode(0);
         xdecition.set_angle_active(0);
@@ -338,7 +344,7 @@ void Activate()
         ExecSend();
         std::this_thread::sleep_for(std::chrono::milliseconds(10));
     }
-    for(int i = 0; i < 10; i++){
+    for(int i = 0; i < 3; i++){
         xdecition.set_wheelangle(0.0);
         xdecition.set_angle_mode(1);
         xdecition.set_angle_active(1);
@@ -357,7 +363,7 @@ void Activate()
 void UnAcitvate()
 {
     iv::brain::decition xdecition;
-    for(int i = 0; i < 10; i++){
+    for(int i = 0; i < 3; i++){
         xdecition.set_wheelangle(0);
         xdecition.set_angle_mode(1);
         xdecition.set_angle_active(1);
@@ -370,7 +376,7 @@ void UnAcitvate()
         ExecSend();
         std::this_thread::sleep_for(std::chrono::milliseconds(10));
     }
-    for(int i = 0; i < 10; i++){
+    for(int i = 0; i < 3; i++){
         xdecition.set_wheelangle(0);
         xdecition.set_angle_mode(0);
         xdecition.set_angle_active(0);
@@ -563,8 +569,24 @@ void sendthread()
         if(gbChassisEPS == false) ExecSend();
         std::this_thread::sleep_for(std::chrono::milliseconds(10));
     }
+    UnAcitvate();
 }
 
+#ifdef Q_OS_LINUX
+void sig_int(int signo)
+{
+    gbSendRun = false;
+    gpsendthread->join();
+
+    iv::modulecomm::Unregister(gpacansend);
+    iv::modulecomm::Unregister(gpachassis);
+    iv::modulecomm::Unregister(gpadecition);
+
+    std::cout<<" controller exit."<<std::endl;
+    exit(0);
+}
+#endif
+
 int main(int argc, char *argv[])
 {
     RegisterIVBackTrace();
@@ -619,5 +641,12 @@ int main(int argc, char *argv[])
 
     std::thread xthread(sendthread);
 
+    gpsendthread = &xthread;
+
+#ifdef Q_OS_LINUX
+   signal(SIGINT, sig_int);
+   signal(SIGTERM,sig_int);
+#endif
+
     return a.exec();
 }

+ 12 - 1
src/tool/IVSysMan/mainwindow.cpp

@@ -134,6 +134,15 @@ MainWindow::~MainWindow()
     {
         mPM->mvectorprog[i].mbautostart = false;
     }
+
+    for(i=0;i<mPM->mvectorprog.size();i++)
+    {
+        if(mPM->mvectorprog[i].mbRun)
+        {
+            mPM->mvectorprog[i].mProcess->terminate();
+        }
+    }
+
     for(i=0;i<mPM->mvectorprog.size();i++)
     {
         if(mPM->mvectorprog[i].mbRun)
@@ -146,6 +155,8 @@ MainWindow::~MainWindow()
         }
     }
 
+  //  QThread::msleep(300);
+
 #ifdef QT_DEBUG
     iv::ivexit::ExecIVExitCmd(mpivexit,"adcivexit-test");   // test iv exit code. can comment this line.
 #endif
@@ -154,7 +165,7 @@ MainWindow::~MainWindow()
 
     mPM->requestInterruption();
 
-    QThread::msleep(1000);
+//    QThread::msleep(1000);
 
     qint64 time;
     time = QDateTime::currentMSecsSinceEpoch();

+ 13 - 1
src/tool/IVSysMan/progmon.cpp

@@ -33,6 +33,15 @@ ProgMon::~ProgMon()
     std::cout<<"~ProgMon"<<std::endl;
     unsigned int i;
     for(i=0;i<mvectorprog.size();i++)
+    {
+        if(mvectorprog[i].mProcess != 0)
+        {
+            mvectorprog[i].mProcess->terminate();
+  //          mvectorprog[i].mProcess->close();
+        }
+    }
+    QThread::msleep(300);
+    for(i=0;i<mvectorprog.size();i++)
     {
         if(mvectorprog[i].mProcess != 0)
         {
@@ -553,7 +562,10 @@ void ProgMon::StopProc(ProgUnit *pu)
         qDebug("process %s is not running. not need stop.",pu->strappname.data());
         return;
     }
+    pu->mProcess->terminate();
+    std::this_thread::sleep_for(std::chrono::milliseconds(300));
     pu->mProcess->kill();
+
     if(!checkStartState(pu)){
         return;
     }
@@ -651,7 +663,7 @@ void ProgMon::run()
         qint64 nNow = QDateTime::currentMSecsSinceEpoch();
         if((nNow - nLastUpdate)< interval)
         {
-            msleep(100);
+            msleep(10);
             continue;
         }
         QString strsysinfo;

+ 1 - 1
src/tool/view_group_grpc/groupqueryclient.h

@@ -16,7 +16,7 @@
 
 #include <thread>
 
-#include "modulecommext.h"
+//#include "modulecommext.h"
 
 #include <iostream>
 #include <memory>