瀏覽代碼

change pilot_apollo_bridge_gui. add some IVSysMan code, for manage launch, not complete.

yuchuli 1 月之前
父節點
當前提交
dfd81b66bf

+ 179 - 0
src/apollo/code/pilot_apollo_bridge_gui/centerview.cpp

@@ -0,0 +1,179 @@
+#include "centerview.h"
+
+
+std::string gCompClass[] = {"ADC Launch"};
+
+CenterView::CenterView(QTabWidget * pTab,ProgMon * pPM)
+{
+    mTabMain = pTab;
+    mpPM = pPM;
+    int i;
+    for(i=0;i<1;i++)
+    {
+        GroupUnit * gu = new GroupUnit();
+        QGroupBox * p = CreateGroup(mTabMain,gCompClass[i]);
+        gu->mpGroup = p;
+        gu->mstrgroupname = gCompClass[i];
+        gu->mpPM = mpPM;
+        gu->CreateView();
+        connect(gu,SIGNAL(ProgClick(ProgUnit*,ProgramViewUnit *,bool)),this,SLOT(onProgClick(ProgUnit*,ProgramViewUnit *,bool)));
+        connect(gu,SIGNAL(ProgLogClick(ProgUnit*,ProgramViewUnit *,bool)),this,SLOT(onProgLogClick(ProgUnit*,ProgramViewUnit *,bool)));
+        mvectorGropup.push_back(gu);
+    }
+
+    QGroupBox * p = CreateInfoGroup(mTabMain,"Info");
+
+    QTimer * timer = new QTimer();
+    connect(timer,SIGNAL(timeout()),this,SLOT(onTimer()));
+    timer->start(1000);
+}
+
+CenterView::~CenterView()
+{
+    while(mTabMain->count()>0)mTabMain->removeTab(mTabMain->count()-1);
+}
+
+void CenterView::ResetView()
+{
+
+    static bool bFirstReset = true;
+    while(mTabMain->count()>1)
+    {
+        qDebug("count is %d",mTabMain->count());
+        mTabMain->removeTab(mTabMain->count()-1);
+
+    }
+    if(bFirstReset)
+    {
+        mvectorGropup[0]->mpGroup->setVisible(false);
+        bFirstReset = false;
+    }
+    mvectorGropup.clear();
+
+//    mTabMain->clear();
+
+    int i;
+    for(i=0;i<5;i++)
+    {
+        GroupUnit * gu = new GroupUnit();
+        QGroupBox * p = CreateGroup(mTabMain,gCompClass[i]);
+        gu->mpGroup = p;
+        gu->mstrgroupname = gCompClass[i];
+        gu->mpPM = mpPM;
+
+        connect(gu,SIGNAL(ProgClick(ProgUnit*,ProgramViewUnit *,bool)),this,SLOT(onProgClick(ProgUnit*,ProgramViewUnit *,bool)));
+        mvectorGropup.push_back(gu);
+    }
+
+
+    QGroupBox * p = CreateInfoGroup(mTabMain,"Info");
+
+
+
+    for(i=0;i<5;i++)
+    {
+        mvectorGropup[i]->CreateView();
+    }
+
+    mTabMain->removeTab(0);
+
+
+//    int i;
+//    for(i=0;i<5;i++)
+//    {
+//        GroupUnit * gu = new GroupUnit();
+//        QGroupBox * p = CreateGroup(mTabMain,gCompClass[i]);
+//        gu->mpGroup = p;
+//        gu->mstrgroupname = gCompClass[i];
+//        gu->mpPM = mpPM;
+//        gu->CreateView();
+//        connect(gu,SIGNAL(ProgClick(ProgUnit*,ProgramViewUnit *,bool)),this,SLOT(onProgClick(ProgUnit*,ProgramViewUnit *,bool)));
+//        mvectorGropup.push_back(gu);
+//    }
+//    int i;
+//    for(i=0;i<5;i++)
+//    {
+//        mvectorGropup[i]->DeleteView();
+//        mvectorGropup[i]->ReCreateView();
+
+//    }
+
+
+}
+
+QGroupBox * CenterView::CreateInfoGroup(QTabWidget * p,std::string strtab)
+{
+    QGroupBox * pGroup = new QGroupBox();
+    pGroup->setGeometry(0,0,1800,1000);
+
+    QScrollArea * pScroll = new QScrollArea();
+    pScroll->setWidget(pGroup);
+
+    p->addTab(pScroll,strtab.data());
+
+    mpPTE = new QPlainTextEdit(pGroup);
+    mpPTE->setGeometry(30,30,800,600);
+
+    return pGroup;
+}
+
+QGroupBox * CenterView::CreateGroup(QTabWidget * p,std::string strtab)
+{
+    QGroupBox * pGroup = new QGroupBox();
+    pGroup->setGeometry(0,0,1800,5000);
+
+    QScrollArea * pScroll = new QScrollArea();
+    pScroll->setWidget(pGroup);
+
+    p->addTab(pScroll,strtab.data());
+
+    return pGroup;
+}
+
+void CenterView::onProgClick(ProgUnit * pu,ProgramViewUnit * pvu,bool bClick)
+{
+    emit ProgClick(pu,pvu,bClick);
+}
+
+void CenterView::onProgLogClick(ProgUnit * pu,ProgramViewUnit * pvu,bool bClick)
+{
+    emit ProgLogClick(pu,pvu,bClick);
+}
+
+void CenterView::ProcStarted(ProgUnit *pu)
+{
+    int i;
+    int nsize = mvectorGropup.size();
+    for(i=0;i<nsize;i++)
+    {
+        mvectorGropup.at(i)->ProcStarted(pu);
+    }
+}
+
+void CenterView::ProcStopted(ProgUnit *pu)
+{
+    int i;
+    int nsize = mvectorGropup.size();
+    for(i=0;i<nsize;i++)
+    {
+        mvectorGropup.at(i)->ProcStopted(pu);
+    }
+}
+
+void CenterView::UpdateState()
+{
+    int i;
+    int nsize = mvectorGropup.size();
+    for(i=0;i<nsize;i++)
+    {
+        mvectorGropup.at(i)->UpdateState();
+    }
+}
+
+void CenterView::onTimer()
+{
+
+    QString strsysinfo = mpPM->GetSysInfo();
+//    qDebug(strsysinfo.toLatin1().data());
+    mpPTE->setPlainText(strsysinfo);
+}

+ 60 - 0
src/apollo/code/pilot_apollo_bridge_gui/centerview.h

@@ -0,0 +1,60 @@
+#ifndef CENTERVIEW_H
+#define CENTERVIEW_H
+
+#include <QTabWidget>
+#include <QGroupBox>
+#include <QScrollArea>
+#include <QPlainTextEdit>
+
+#include <vector>
+
+#include "progmon.h"
+#include "groupunit.h"
+
+
+class CenterView : public QObject
+{
+    Q_OBJECT
+public:
+    CenterView(QTabWidget * pTab,ProgMon * pPM);
+    ~CenterView();
+
+public:
+    QTabWidget * mTabMain;
+
+    ProgMon * mpPM;
+    std::vector<GroupUnit * > mvectorGropup;
+private:
+    QGroupBox *  CreateGroup(QTabWidget * p,std::string strtab);//设置模块按钮_tjc
+    QGroupBox *  CreateInfoGroup(QTabWidget * p,std::string strtab);
+
+private slots:
+    void onProgClick(ProgUnit * pu,ProgramViewUnit * pvu,bool bClick);
+    void onProgLogClick(ProgUnit * pu,ProgramViewUnit * pvu,bool bClick);
+
+    void onTimer();
+
+signals:
+    void ProgClick(ProgUnit *, ProgramViewUnit * ,bool);
+    void ProgLogClick(ProgUnit *, ProgramViewUnit * ,bool);
+
+public:
+    /* Processs Started  Update view if need */
+    void ProcStarted(ProgUnit * pu);
+
+    /* Process Stoped Update view if need */
+    void ProcStopted(ProgUnit * pu);
+
+    /* Update CPU Mem PID State */
+    void UpdateState();
+
+
+    void ResetView();
+
+private:
+    QPlainTextEdit * mpPTE;
+
+
+};
+
+#endif // CENTERVIEW_H

+ 426 - 0
src/apollo/code/pilot_apollo_bridge_gui/cpumem.cpp

@@ -0,0 +1,426 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <string.h>
+#include <stdlib.h>
+
+//#define VMRSS_LINE 17
+#define VMRSS_LINE 21
+#define VMSIZE_LINE 13
+#define PROCESS_ITEM 14
+#define THREAD_LINE 34
+
+#include <QFile>
+
+#ifndef nullptr
+#define nullptr 0
+#endif
+
+typedef struct {
+    unsigned long user;
+    unsigned long nice;
+    unsigned long system;
+    unsigned long idle;
+    unsigned long iowait;
+    unsigned long irq;
+    unsigned long softirg;
+}Total_Cpu_Occupy_t;
+
+
+typedef struct {
+    unsigned int pid;
+    unsigned long utime;  //user time
+    unsigned long stime;  //kernel time
+    unsigned long cutime; //all user time
+        unsigned long cstime; //all dead time
+}Proc_Cpu_Occupy_t;
+
+
+//获取第N项开始的指针
+const char* get_items(const char*buffer ,unsigned int item){
+
+    const char *p =buffer;
+
+    int len = strlen(buffer);
+    int count = 0;
+
+    for (int i=0; i<len;i++){
+        if (' ' == *p){
+            count ++;
+            if(count == item -1){
+                p++;
+                break;
+            }
+        }
+        p++;
+    }
+
+    return p;
+}
+
+
+//获取总的CPU时间
+unsigned long get_cpu_total_occupy(){
+#ifdef IV_OS_UNIX
+    FILE *fd;
+    char buff[1024]={0};
+    Total_Cpu_Occupy_t t;
+
+    fd =fopen("/proc/stat","r");
+    if (nullptr == fd){
+        return 0;
+    }
+
+    fgets(buff,sizeof(buff),fd);
+    char name[64]={0};
+    sscanf(buff,"%s %ld %ld %ld %ld %ld %ld %ld",name,&t.user,&t.nice,&t.system,&t.idle,
+          &t.iowait,&t.irq,&t.softirg);
+    fclose(fd);
+
+    return (t.user + t.nice + t.system + t.idle+t.iowait+t.irq+t.softirg);
+#endif
+
+#ifdef IV_OS_WIN
+    return 0;
+#endif
+}
+
+
+bool get_proc_brun(unsigned int pid)
+{
+    char file_name[64]={0};
+    Proc_Cpu_Occupy_t t;
+    FILE *fd;
+
+    sprintf(file_name,"/proc/%d/stat",pid);
+
+    fd = fopen(file_name,"r");
+    if(nullptr == fd){
+        return false;
+    }
+
+    fclose(fd);
+    return true;
+
+}
+//获取进程的CPU时间
+unsigned long get_cpu_proc_occupy(unsigned int pid){
+#ifdef IV_OS_UNIX
+    char file_name[64]={0};
+    Proc_Cpu_Occupy_t t;
+    FILE *fd;
+    char line_buff[1024]={0};
+    sprintf(file_name,"/proc/%d/stat",pid);
+
+    fd = fopen(file_name,"r");
+    if(nullptr == fd){
+        return 0;
+    }
+
+    fgets(line_buff,sizeof(line_buff),fd);
+
+    sscanf(line_buff,"%u",&t.pid);
+    const char *q =get_items(line_buff,PROCESS_ITEM);
+    sscanf(q,"%ld %ld %ld %ld",&t.utime,&t.stime,&t.cutime,&t.cstime);
+    fclose(fd);
+
+    return (t.utime + t.stime + t.cutime + t.cstime);
+#endif
+
+#ifdef IV_OS_WIN
+    return 0;
+#endif
+}
+
+
+//获取CPU占用率
+float get_proc_cpu(unsigned int pid,unsigned long & nLastProcTotal,unsigned long & nLastAllTotal){
+#ifdef IV_OS_UNIX
+    unsigned long totalcputime1;//totalcputime2;
+    unsigned long procputime1;//procputime2;
+
+    totalcputime1=get_cpu_total_occupy();
+    procputime1=get_cpu_proc_occupy(pid);
+
+    float pcpu = 0.0;
+    if(nLastAllTotal == 0)
+    {
+        nLastProcTotal = procputime1;
+        nLastAllTotal = totalcputime1;
+        return 0.0; //if First,Not Count;
+    }
+    else
+    {
+
+        if(totalcputime1 != nLastAllTotal)
+        {
+            pcpu=100.0 * (procputime1-nLastProcTotal)/(totalcputime1-nLastAllTotal);
+        }
+
+        //Save Last For calculation.
+        nLastProcTotal = procputime1;
+        nLastAllTotal = totalcputime1;
+    }
+
+//    usleep(200000);
+
+//    totalcputime2=get_cpu_total_occupy();
+//    procputime2=get_cpu_proc_occupy(pid);
+
+//    float pcpu = 0.0;
+//    if(0 != totalcputime2-totalcputime1){
+//        pcpu=100.0 * (procputime2-procputime1)/(totalcputime2-totalcputime1);
+//    }
+
+    return pcpu;
+#endif
+
+#ifdef IV_OS_WIN
+    return 0;
+#endif
+}
+
+//获取CPU占用率
+float get_proc_cpu(unsigned int pid){
+#ifdef IV_OS_UNIX
+    unsigned long totalcputime1,totalcputime2;
+    unsigned long procputime1,procputime2;
+
+    totalcputime1=get_cpu_total_occupy();
+    procputime1=get_cpu_proc_occupy(pid);
+
+
+    usleep(200000);
+
+    totalcputime2=get_cpu_total_occupy();
+    procputime2=get_cpu_proc_occupy(pid);
+
+    float pcpu = 0.0;
+    if(0 != totalcputime2-totalcputime1){
+        pcpu=100.0 * (procputime2-procputime1)/(totalcputime2-totalcputime1);
+    }
+
+    return pcpu;
+#endif
+
+#ifdef IV_OS_WIN
+    return 0;
+#endif
+}
+
+
+//获取进程占用内存
+unsigned int  get_proc_mem(unsigned int pid){
+#ifdef IV_OS_UNIX
+    char file_name[64]={0};
+    FILE *fd;
+    char line_buff[512]={0};
+    sprintf(file_name,"/proc/%d/status",pid);
+
+    fd =fopen(file_name,"r");
+    if(nullptr == fd){
+        return 0;
+    }
+
+    char name[64];
+    int vmrss;
+    for (int i=0; i<VMRSS_LINE-1;i++){
+        fgets(line_buff,sizeof(line_buff),fd);
+    }
+
+    fgets(line_buff,sizeof(line_buff),fd);
+    sscanf(line_buff,"%s %d",name,&vmrss);
+    fclose(fd);
+
+    return vmrss;
+#endif
+#ifdef IV_OS_WIN
+    return  0;
+#endif
+}
+
+//获取进程占用内存
+unsigned int get_proc_threadnum(unsigned int pid){
+#ifdef IV_OS_UNIX
+    char file_name[64]={0};
+    FILE *fd;
+    bool bRead= false;
+    char line_buff[512]={0};
+    sprintf(file_name,"/proc/%d/status",pid);
+
+    fd =fopen(file_name,"r");
+    if(nullptr == fd){
+        return 0;
+    }
+
+    char name[64];
+    int threadnum;
+ //   for (int i=0; i<THREAD_LINE-1;i++){
+    for (int i=0; i<50;i++){
+        if(NULL == fgets(line_buff,sizeof(line_buff),fd))
+        {
+            break;
+        }
+        if(strstr(line_buff,"Threads:")!=NULL)
+        {
+            break;
+        }
+    }
+
+ //   fgets(line_buff,sizeof(line_buff),fd);
+    sscanf(line_buff,"%s %d",name,&threadnum);
+    fclose(fd);
+
+    return threadnum;
+#endif
+
+#ifdef IV_OS_WIN
+    return 0;
+#endif
+}
+
+
+//获取进程占用虚拟内存
+unsigned int get_proc_virtualmem(unsigned int pid){
+
+    char file_name[64]={0};
+    FILE *fd;
+    char line_buff[512]={0};
+    sprintf(file_name,"/proc/%d/status",pid);
+
+    fd =fopen(file_name,"r");
+    if(nullptr == fd){
+        return 0;
+    }
+
+    char name[64];
+    int vmsize;
+    for (int i=0; i<VMSIZE_LINE-1;i++){
+        fgets(line_buff,sizeof(line_buff),fd);
+    }
+
+    fgets(line_buff,sizeof(line_buff),fd);
+    sscanf(line_buff,"%s %d",name,&vmsize);
+    fclose(fd);
+
+    return vmsize;
+}
+
+
+//进程本身
+int get_pid(const char* process_name, const char* user = nullptr)
+{
+#ifdef IV_OS_UNIX
+    if(user == nullptr){
+        user = getlogin();
+    }
+
+    char cmd[512];
+    if (user){
+        sprintf(cmd, "pgrep %s -u %s", process_name, user);
+    }
+
+    FILE *pstr = popen(cmd,"r");
+
+    if(pstr == nullptr){
+        return 0;
+    }
+
+    char buff[512];
+    ::memset(buff, 0, sizeof(buff));
+    if(NULL == fgets(buff, 512, pstr)){
+        return 0;
+    }
+
+    return atoi(buff);
+#endif
+
+#ifdef IV_OS_WIN
+    return -1;
+#endif
+}
+
+
+
+int get_proc_mem_thread(unsigned  int pid,unsigned int & nmem,unsigned int & nthread)
+{
+#ifdef IV_OS_UNIX
+    QFile xFile;
+    char strfilename[256];
+    snprintf(strfilename,256,"/proc/%d/status",pid);
+    xFile.setFileName(strfilename);
+    bool bMem = false;
+    bool bthread = false;
+    if(xFile.open(QIODevice::ReadOnly))
+    {
+        QByteArray ba = xFile.readAll();
+        QList<QByteArray> xlist = ba.split('\n');
+        int nsize = xlist.size();
+
+        if(nsize >=34)
+        {
+            QString strline(xlist.at(22));
+            QStringList baitem = strline.split(QRegExp("[\t ,;]+"));
+            if(baitem.size() >=2)
+            {
+                if(baitem[0] == "RssAnon:")
+                {
+                    nmem = QString(baitem[1]).toLong();
+                    bMem = true;
+                }
+            }
+            strline = QString(xlist.at(33));
+            baitem = strline.split(QRegExp("[\t ,;]+"));
+            if(baitem.size() >=2)
+            {
+                if(baitem[0] == "Threads:")
+                {
+                    nthread = QString(baitem[1]).toLong();
+                    bthread = true;
+                }
+            }
+
+        }
+
+
+        if((bthread == false) || (bMem == false))
+        {
+            unsigned int i;
+            for(i=0;i<nsize;i++)
+            {
+                QString strline(xlist.at(i));
+                QStringList baitem = strline.split(QRegExp("[\t ,;]+"));
+                if(baitem.size() >=2)
+                {
+                    if(baitem[0] == "RssAnon:")
+                    {
+                        nmem = QString(baitem[1]).toLong();
+                        bMem = true;
+                    }
+                    if(baitem[0] == "Thread:")
+                    {
+                        nthread = QString(baitem[1]).toLong();
+                        bthread = true;
+                    }
+                }
+                if(bMem && bthread)
+                {
+                    break;
+                }
+            }
+
+        }
+    }
+    xFile.close();
+
+    return 0;
+#endif
+
+#ifdef IV_OS_WIN
+    return 0;
+#endif
+    return 0;
+}
+
+
+

+ 13 - 0
src/apollo/code/pilot_apollo_bridge_gui/cpumem.h

@@ -0,0 +1,13 @@
+#ifndef CPUMEM_H
+#define CPUMEM_H
+
+float get_proc_cpu(unsigned int pid,unsigned long & nLastProcTotal,unsigned long & nLastAllTotal);
+float get_proc_cpu(unsigned int pid);
+unsigned int get_proc_mem(unsigned int pid);
+unsigned int get_proc_threadnum(unsigned int pid);
+
+bool get_proc_brun(unsigned int pid);
+
+int get_proc_mem_thread(unsigned  int pid,unsigned int & nmem,unsigned int & nthread);
+
+#endif // CPUMEM_H

+ 154 - 0
src/apollo/code/pilot_apollo_bridge_gui/groupunit.cpp

@@ -0,0 +1,154 @@
+#include "groupunit.h"
+
+GroupUnit::GroupUnit()
+{
+
+}
+
+void GroupUnit ::CreateView()
+{
+
+    unsigned int i= 0;
+    int j=0;
+    CreateTitle();
+    for(i=0;i<mpPM->mvectorprog.size();i++)
+    {
+        ProgUnit * pu = &(mpPM->mvectorprog.at(i));
+        if(pu->strgroup == mstrgroupname)
+        {
+            ProgramViewUnit * pvu = new ProgramViewUnit(mpGroup,pu,30,80+j*50);
+            connect(pvu,SIGNAL(progclick(ProgUnit*,ProgramViewUnit * ,bool)),this,SLOT(onProgClick(ProgUnit*,ProgramViewUnit * ,bool)));
+            connect(pvu,SIGNAL(ProgLogClick(ProgUnit*,ProgramViewUnit*,bool)),this,SLOT(onProgLogClick(ProgUnit*,ProgramViewUnit * ,bool)));
+            mvectorProgramViewUnit.push_back(pvu);
+            j++;
+        }
+    }
+}
+
+void GroupUnit::DeleteView()
+{
+    while(mvectorProgramViewUnit.size()>0)
+    {
+        ProgramViewUnit * pvu = mvectorProgramViewUnit[0];
+        delete pvu;
+        mvectorProgramViewUnit.erase(mvectorProgramViewUnit.begin());
+    }
+}
+
+void GroupUnit::ReCreateView()
+{
+    int i= 0;
+    int j=0;
+    int nsize = mpPM->mvectorprog.size();
+    qDebug("size is %d",nsize);
+    for(i=0;i<mpPM->mvectorprog.size();i++)
+    {
+        ProgUnit * pu = &(mpPM->mvectorprog.at(i));
+        if(pu->strgroup == mstrgroupname)
+        {
+            ProgramViewUnit * pvu = new ProgramViewUnit(mpGroup,pu,30,80+j*50);
+            connect(pvu,SIGNAL(progclick(ProgUnit*,ProgramViewUnit * ,bool)),this,SLOT(onProgClick(ProgUnit*,ProgramViewUnit * ,bool)));
+            connect(pvu,SIGNAL(ProgLogClick(ProgUnit*,ProgramViewUnit*,bool)),this,SLOT(onProgLogClick(ProgUnit*,ProgramViewUnit * ,bool)));
+            mvectorProgramViewUnit.push_back(pvu);
+            j++;
+
+
+        }
+    }
+}
+
+void GroupUnit::onProgClick(ProgUnit *pu, ProgramViewUnit * pvu,bool bClick)
+{
+    emit ProgClick(pu,pvu,bClick);
+}
+
+void GroupUnit::onProgLogClick(ProgUnit *pu, ProgramViewUnit *pvu, bool bClick)
+{
+    emit ProgLogClick(pu,pvu,bClick);
+}
+
+void GroupUnit::ProcStarted(ProgUnit *pu)
+{
+    int i;
+    int nsize = mvectorProgramViewUnit.size();
+    for(i=0;i<nsize;i++)
+    {
+        mvectorProgramViewUnit.at(i)->ProcStarted(pu);
+    }
+}
+
+void GroupUnit::ProcStopted(ProgUnit *pu)
+{
+    int i;
+    int nsize = mvectorProgramViewUnit.size();
+    for(i=0;i<nsize;i++)
+    {
+        mvectorProgramViewUnit.at(i)->ProcStopted(pu);
+    }
+}
+
+void GroupUnit::UpdateState()
+{
+    int i;
+    int nsize = mvectorProgramViewUnit.size();
+    for(i=0;i<nsize;i++)
+    {
+        mvectorProgramViewUnit.at(i)->UpdateState();
+    }
+}
+
+void GroupUnit::CreateTitle()
+{
+    QLabel * pLA;
+
+    int nXPos = 30;
+    int nYPos = 30;
+    int nHgt = 30;
+
+    pLA = new QLabel(mpGroup);
+    pLA->setText("Module");
+    pLA->setGeometry(nXPos,nYPos,190,nHgt);
+    nXPos = nXPos + 200;
+
+    pLA = new QLabel(mpGroup);
+    pLA->setText("Args");
+    pLA->setGeometry(nXPos,nYPos,290,nHgt);
+    nXPos = nXPos + 300;
+
+    pLA = new QLabel(mpGroup);
+    pLA->setText("Switch");
+    pLA->setGeometry(nXPos,nYPos,90,nHgt);
+    nXPos = nXPos + 100;
+
+    pLA = new QLabel(mpGroup);
+    pLA->setText("Count");
+    pLA->setGeometry(nXPos,nYPos,90,nHgt);
+    nXPos = nXPos + 100;
+
+    pLA = new QLabel(mpGroup);
+    pLA->setText("PID");
+    pLA->setGeometry(nXPos,nYPos,90,nHgt);
+    nXPos = nXPos + 100;
+
+    pLA = new QLabel(mpGroup);
+    pLA->setText("CPU");
+    pLA->setGeometry(nXPos,nYPos,90,nHgt);
+    nXPos = nXPos + 100;
+
+    pLA = new QLabel(mpGroup);
+    pLA->setText("Mem");
+    pLA->setGeometry(nXPos,nYPos,90,nHgt);
+    nXPos = nXPos + 100;
+
+    pLA = new QLabel(mpGroup);
+    pLA->setText("Thread");
+    pLA->setGeometry(nXPos,nYPos,90,nHgt);
+    nXPos = nXPos + 100;
+
+    pLA = new QLabel(mpGroup);
+    pLA->setText("log(stdout)");
+    pLA->setGeometry(nXPos,nYPos,90,nHgt);
+    nXPos = nXPos + 100;
+
+
+}

+ 59 - 0
src/apollo/code/pilot_apollo_bridge_gui/groupunit.h

@@ -0,0 +1,59 @@
+#ifndef GROUPUNIT_H
+#define GROUPUNIT_H
+
+#include <QGroupBox>
+#include <programviewunit.h>
+
+#include <string>
+#include <vector>
+
+#include "progmon.h"
+
+class GroupUnit : public QObject
+{
+    Q_OBJECT
+public:
+    GroupUnit();
+
+    std::string mstrgroupname;
+    QGroupBox * mpGroup;
+    ProgMon * mpPM;
+
+    std::vector<ProgramViewUnit * > mvectorProgramViewUnit;
+
+public:
+    //Create View
+    void CreateView();
+
+    void DeleteView();
+
+    void ReCreateView();
+
+private slots:
+    void onProgClick(ProgUnit * pu,ProgramViewUnit * pvu,bool bClick);
+    void onProgLogClick(ProgUnit * pu,ProgramViewUnit * pvu,bool bClick);
+
+
+signals:
+    void ProgClick(ProgUnit *,ProgramViewUnit * , bool);
+    void ProgLogClick(ProgUnit *,ProgramViewUnit * , bool);
+
+public:
+    /* Processs Started  Update view if need */
+    void ProcStarted(ProgUnit * pu);
+
+    /* Process Stoped Update view if need */
+    void ProcStopted(ProgUnit * pu);
+
+    /* Update CPU Mem PID State */
+    void UpdateState();
+
+
+
+private:
+    /* Title for view */
+    void CreateTitle();
+
+};
+
+#endif // GROUPUNIT_H

+ 38 - 0
src/apollo/code/pilot_apollo_bridge_gui/mainwindow.cpp

@@ -32,6 +32,25 @@ MainWindow::MainWindow(QWidget *parent)
     connect(&mProcStopMonitor,SIGNAL(readyReadStandardError()),this,SLOT(onReadStandardError()));
     connect(&mProcStopMonitor,SIGNAL(finished(int)),this,SLOT(onProcessFinished(int)));
 
+
+    std::string strxmlpath = "";
+
+    //从配置文件中读取当前系统包含的所有模块信息-tjc
+    mPM = new ProgMon(strxmlpath.data());
+
+//    connect(mPM,SIGNAL(SigProcStarted(ProgUnit*)),this,SLOT(onProcessStarted(ProgUnit*)));
+//    connect(mPM,SIGNAL(SigProcStoped(ProgUnit*)),this,SLOT(onProcessEnd(ProgUnit*)));
+
+    setGeometry(0,0,800,600);
+
+    QTabWidget * p = new QTabWidget(ui->centralwidget);
+    p->setGeometry(30,150,800,450);
+
+    mTabMain = p;
+
+    CenterView * pcv = new CenterView(p,mPM);
+    mpCV = pcv;
+
     setWindowTitle("Pilot Apollo Bridge GUI");
 }
 
@@ -80,6 +99,7 @@ void MainWindow::on_pushButton_StartApollo_clicked()
     mbMonitorRunning = true;
 
     mProcNode.start("cyber_node",QStringList() <<"list");
+    mnNodeListRetry = 3;
 
     ui->pushButton_StartApollo->setEnabled(false);
 }
@@ -108,6 +128,7 @@ void MainWindow::onReadStandardOutput()
                     {
    //                     std::cout<<" find hmi "<<i<<" nodename"<<strnodename.toLatin1().data()<<std::endl;
                         ui->pushButton_StopApollo->setEnabled(true);
+                        mnNodeListRetry = 0;
                         break;
                     }
                 }
@@ -144,6 +165,12 @@ void MainWindow::onProcessFinished(int nStatus)
     if(proc == &mProcNode)
     {
         std::cout<<"Process Node Finished."<<std::endl;
+        if((!ui->pushButton_StopApollo->isEnabled())  && (mnNodeListRetry > 0))
+        {
+            std::cout<<"Process Node List Retry. Because Not Enable"<<std::endl;
+            mProcNode.start("cyber_node",QStringList() <<"list");
+            mnNodeListRetry--;
+        }
     }
 
     if(proc == &mProcStopMonitor)
@@ -167,5 +194,16 @@ void MainWindow::onProcessFinished(int nStatus)
     }
 }
 
+void MainWindow::resizeEvent(QResizeEvent *event)
+{
+    (void)event;
+    QSize sizemain = ui->centralwidget->size();
+    mTabMain->setGeometry(30,100,sizemain.width()-60,sizemain.height()-130);
+
+
+}
+
+
+
 
 

+ 20 - 0
src/apollo/code/pilot_apollo_bridge_gui/mainwindow.h

@@ -7,6 +7,10 @@
 #include "cyber/time/rate.h"
 #include "cyber/time/time.h"
 
+#include "sysman.h"
+#include "progmon.h"
+#include "centerview.h"
+
 #include  <thread>
 
 #include <QProcess>
@@ -23,6 +27,9 @@ public:
     MainWindow(QWidget *parent = nullptr);
     ~MainWindow();
 
+public:
+     void resizeEvent(QResizeEvent *event);
+
 private slots:
     void on_pushButton_StartApollo_clicked();
 
@@ -38,12 +45,15 @@ private:
 private:
     void threadtest();
 
+
 private:
     std::unique_ptr<apollo::cyber::Node> pilot_node;
 
     std::thread * mpthreadtest;
     bool mbtestrun = true;
 
+    int mnNodeListRetry = 0;
+
 
     QProcess mProc;
     bool mbDreamviewRunning = false;
@@ -58,6 +68,16 @@ private:
     QProcess mProcStopMonitor;
     bool mbProcStopApolloRunning = false;
 
+    SysMan * mpSysMan;
+
+    /* Program Monitor */
+    ProgMon * mPM;
+
+    /* Center View */
+    CenterView * mpCV;
+
+    QTabWidget * mTabMain;
+
 
 
 };

+ 21 - 3
src/apollo/code/pilot_apollo_bridge_gui/pilot_apollo_bridge_gui.pro

@@ -1,4 +1,4 @@
-QT       += core gui
+QT       += core gui xml dbus
 
 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 
@@ -16,11 +16,29 @@ DEFINES += QT_DEPRECATED_WARNINGS
 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
 
 SOURCES += \
+    centerview.cpp \
+    cpumem.cpp \
+    groupunit.cpp \
     main.cpp \
-    mainwindow.cpp
+    mainwindow.cpp \
+    procmemstat.cpp \
+    progmon.cpp \
+    programviewunit.cpp \
+    progunit.cpp \
+    switchbutton.cpp \
+    sysman.cpp
 
 HEADERS += \
-    mainwindow.h
+    centerview.h \
+    cpumem.h \
+    groupunit.h \
+    mainwindow.h \
+    procmemstat.h \
+    progmon.h \
+    programviewunit.h \
+    progunit.h \
+    switchbutton.h \
+    sysman.h
 
 FORMS += \
     mainwindow.ui

+ 164 - 0
src/apollo/code/pilot_apollo_bridge_gui/procmemstat.cpp

@@ -0,0 +1,164 @@
+#include "procmemstat.h"
+
+#include  <QFile>
+
+#include <iostream>
+
+ProcMemStat::ProcMemStat()
+{
+
+}
+
+void ProcMemStat::UpdateCPUMemStat(QString & strInfo)
+{
+#define MAX_CPU 256   //Support 256 cpu core
+    static bool bFirst = true;
+    static int nNowCPUCore = 0;
+    static qint64 nLastCPUTotal,nLastIdleTotal,nLastIrqCount;
+    static qint64 nVectorLastCPU[MAX_CPU];
+    static qint64 nVectorLastIdle[MAX_CPU];
+    static qint64 nVectorLastIrq[MAX_CPU];
+    qint64 nNowCPUTotal,nNowIdleTotal,nIrqCount;
+    float fcputotal;
+    float firqtotal;
+    float fVectorCPU[MAX_CPU];
+    float fVectorIrq[MAX_CPU];
+    qint64 nTotalDiff = 0;
+    int ncpunum;
+
+//    qint64 tuser,tnice,tsys,tidle,tiowait,tirq,tsoftirq;
+    qint64 titem[7];
+
+    QFile xFileStat;
+    xFileStat.setFileName("/proc/stat");
+    if(xFileStat.open(QIODevice::ReadOnly))
+    {
+        QByteArray ba = xFileStat.readAll();
+        QList<QByteArray> xlist = ba.split('\n');
+        int nsize = xlist.size();
+        if(nsize > 1)
+        {
+            QString strline(xlist.at(0));
+            QStringList baitem = strline.split(QRegExp("[\t ,;]+"));
+            if(baitem.size()>=8)
+            {
+                unsigned int i;
+                nNowCPUTotal = 0;
+                for(i=0;i<7;i++)
+                {
+                    titem[i] = QString(baitem[i+1]).toLongLong();
+                    nNowCPUTotal = nNowCPUTotal + titem[i];
+                }
+                nNowIdleTotal = titem[3];
+                nIrqCount = titem[5] + titem[6];
+                nTotalDiff = nNowCPUTotal - nLastCPUTotal;
+                if((bFirst == false)&&(nTotalDiff > 0))
+                {
+                    fcputotal = 100.0 - 100.0*(nNowIdleTotal - nLastIdleTotal)/nTotalDiff;
+                    firqtotal = 100.0*(nIrqCount - nLastIrqCount)/nTotalDiff;
+                }
+                else
+                {
+                    fcputotal = 0;
+                    firqtotal = 0;
+                }
+
+                int ncpuindex = 0;
+                for(i=1;i<xlist.size();i++)
+                {
+
+                    QString strcpu(xlist.at(i));
+                    if(strcpu.left(3) == "cpu")
+                    {
+                        baitem = strcpu.split(QRegExp("[\t ,;]+"));
+                        if(baitem.size() >= 8)
+                        {
+                            unsigned int j;
+                            qint64 evCPUTotal = 0;
+                            for(j=0;j<7;j++)
+                            {
+                                titem[j] = QString(baitem[j+1]).toLongLong();
+                                evCPUTotal = evCPUTotal + titem[j];
+                            }
+                            qint64 evIdleTotal = titem[3];
+                            qint64 evIrqCount = titem[5] + titem[6];
+                            if(ncpuindex < MAX_CPU)
+                            {
+                                qint64 nevDiff = evCPUTotal - nVectorLastCPU[ncpuindex];
+
+                                if((nevDiff >0)&&(bFirst == false))
+                                {
+                                    fVectorCPU[ncpuindex] = 100.0 - 100.0*(evIdleTotal - nVectorLastIdle[ncpuindex])/nevDiff;
+                                    fVectorIrq[ncpuindex] = 100.0*(evIrqCount - nVectorLastIrq[ncpuindex])/nevDiff;
+                                }
+                                else
+                                {
+                                    fVectorCPU[ncpuindex] = 0;
+                                    fVectorIrq[ncpuindex] = 0;
+                                }
+
+                                nVectorLastCPU[ncpuindex] = evCPUTotal;
+                                nVectorLastIdle[ncpuindex] = evIdleTotal;
+                                nVectorLastIrq[ncpuindex] = evIrqCount;
+                            }
+                        }
+
+                        ncpuindex++;
+                    }
+                }
+                ncpunum = ncpuindex;
+                nLastCPUTotal = nNowCPUTotal;
+                nLastIdleTotal = nNowIdleTotal;
+                nLastIrqCount = nIrqCount;
+            }
+
+            if(bFirst)bFirst = false;
+        }
+    }
+    xFileStat.close();
+
+    strInfo.clear();
+    strInfo = strInfo + QString("CPU: Used ") + QString::number(fcputotal,'f',3)
+            +QString(" Irq Used : ")+ QString::number(firqtotal,'f',3)
+            +QString(" Core Count: ")+QString::number(ncpunum)+QString("\n");
+    std::cout<<"  CPU: Used "<<fcputotal<<" Irq used: "<<firqtotal<<"  Core Count: "<<ncpunum<<std::endl;
+
+    unsigned int i;
+    for(i=0;i<ncpunum;i++)
+    {
+        strInfo = strInfo + QString("      core ")+QString::number(i)
+                +QString("  Used: ")+ QString::number(fVectorCPU[i],'f',3)
+                +QString(" Irq used: ") + QString::number(fVectorIrq[i],'f',3)+QString("\n");
+        std::cout<<"        core "<<i<<" Used: "<<fVectorCPU[i]<<" Irq used: "<<fVectorIrq[i]<<std::endl;
+    }
+
+    QFile xFileMem;
+    xFileMem.setFileName("/proc/meminfo");
+    if(xFileMem.open(QIODevice::ReadOnly))
+    {
+        QByteArray ba = xFileMem.readAll();
+        QList<QByteArray> xlist = ba.split('\n');
+        int nsize = xlist.size();
+        if(nsize > 1)
+        {
+            QString strline(xlist.at(0));
+            QStringList baitem = strline.split(QRegExp("[\t ,;]+"));
+            if(baitem.size()>= 2)
+            {
+                qint64 memtotal = QString(baitem[1]).toLongLong()/1024;
+                strInfo = strInfo + QString("Mem Total: ") + QString::number(memtotal)+ QString(" MB\n");
+                std::cout<<"    Mem Total "<< memtotal<<" MB"<<std::endl;
+            }
+            strline = QString(xlist.at(1));
+            baitem = strline.split(QRegExp("[\t ,;]+"));
+            if(baitem.size()>= 2)
+            {
+                qint64 memfree = QString(baitem[1]).toLongLong()/1024;
+                strInfo = strInfo + QString("Mem Free: ") + QString::number(memfree)+ QString(" MB\n");
+                std::cout<<"    Mem Free "<< memfree<<" MB"<<std::endl;
+            }
+        }
+
+    }
+    xFileMem.close();
+}

+ 20 - 0
src/apollo/code/pilot_apollo_bridge_gui/procmemstat.h

@@ -0,0 +1,20 @@
+#ifndef PROCMEMSTAT_H
+#define PROCMEMSTAT_H
+
+
+#include <QThread>
+#include <vector>
+
+class ProcMemStat
+{
+public:
+    ProcMemStat();
+    qint64 mPhyMemTotal;
+    qint64 mPhyMemAvail;
+    qint64 mMemTotal;
+    float mfCPULoad;
+    std::vector<float> mvectorcpuload;
+    void UpdateCPUMemStat(QString & strInfo);
+};
+
+#endif // PROCMEMSTAT_H

+ 1085 - 0
src/apollo/code/pilot_apollo_bridge_gui/progmon.cpp

@@ -0,0 +1,1085 @@
+#include "progmon.h"
+#include <QFile>
+
+#include <iostream>
+
+#ifdef OS_UNIX
+#include "sys/statfs.h"
+#endif
+
+
+#ifdef  OS_WIN
+#include  <windows.h>
+
+#endif
+
+//extern iv::Ivlog * ivlog;
+//extern iv::Ivfault * ivfault;
+
+ProgMon::ProgMon(std::string path)
+{
+   UpdateCPUMemStat();
+
+    mvectorprog = loadprogunit(path);
+
+    InitLog();
+
+    mpthread_stdout = new std::thread(&ProgMon::threadstdout,this);
+    mpthread_errout = new std::thread(&ProgMon::threaderrout,this);
+}
+
+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)
+        {
+            mvectorprog[i].mProcess->kill();
+  //          mvectorprog[i].mProcess->close();
+        }
+    }
+    std::cout<<"End Std out thread."<<std::endl;
+    mbstdoutrun = false;
+    mpthread_stdout->join();
+
+    std::cout<<"End Err out thread."<<std::endl;
+    mberroutrun = false;
+    mpthread_errout->join();
+
+    if(mbFileStdLog)
+    {
+        mbFileStdLog = false;
+        qint64 nsize = mFileStdLog.size();
+        mFileStdLog.close();
+
+        if(nsize == 0)
+        {
+            std::cout<<"Because no std log, delete std log. "<<std::endl;
+            mFileStdLog.remove();
+        }
+
+    }
+
+    if(mbFileLog)
+    {
+        mbFileLog = false;
+        qint64 nsize = mFileLog.size();
+        mFileLog.close();
+
+        if(nsize == 0)
+        {
+            std::cout<<"Because no error log, delete error log. "<<std::endl;
+            mFileLog.remove();
+        }
+
+    }
+
+//    mvectorprog.clear();
+}
+
+std::vector<ProgUnit> ProgMon::loadprogunit(std::string path)
+{
+    std::vector<ProgUnit> xvectorprog;
+    QDomDocument doc;
+
+    qDebug()<<"path: "<<path.data();
+    QFile file(path.data());
+    if (!file.open(QIODevice::ReadOnly))
+        return xvectorprog;
+    if (!doc.setContent(&file)) {
+        file.close();
+        return xvectorprog;
+    }
+    file.close();
+
+    //遍历节点,从配置文件中获取当前有哪些模块,并拼接启动命令和启动参数_tjc
+    QDomElement docElem = doc.documentElement();
+    QDomNode n = docElem.firstChild();
+
+    std::string defdir = "./";
+    while(!n.isNull())
+    {
+        QDomElement e = n.toElement(); // 尝试将节点转换为元素
+        std::string name = e.nodeName().toStdString();
+        if(name == "setting")
+        {
+            QString str1 = e.attribute("defaultpath","./");
+            defdir = e.attribute("defaultpath","./").toStdString();
+            break;
+        }
+        n = n.nextSibling();
+    }
+    n = docElem.firstChild();
+    while(!n.isNull())
+    {
+        QDomElement e = n.toElement(); // 尝试将节点转换为元素
+        std::string name = e.nodeName().toStdString();
+
+        if(name == "module")
+        {
+            std::string appname = e.attribute("app","").toStdString();
+            std::string strdir = e.attribute("dir","").toStdString();
+            std::string strargs = e.attribute("args","").toStdString();
+            std::string strbstart = e.attribute("autostart","false").toStdString();
+            std::string strgroup = e.attribute("group","unknown").toStdString();
+            std::string strsavestd = e.attribute("savestd","false").toStdString();
+
+            ProgUnit x;
+            if(strbstart == "true")x.mbautostart = true;
+            else x.mbautostart = false;
+            x.strappdir = strdir;
+            x.strappname = appname;
+            x.strargs = strargs;
+            x.strgroup = strgroup;
+            x.mProcess = 0;
+            x.mbSavestdout = false;
+            if(strsavestd == "true")x.mbSavestdout = true;
+
+
+
+            if(x.strappname.length() > 0)
+            {
+                x.strcmd = x.strappdir;
+                if(x.strcmd.length()<1)
+                {
+                    x.strcmd = defdir;
+                }
+                if(x.strcmd.length() > 0)
+                {
+                    if(x.strcmd.at(x.strcmd.length() -1) != '/')
+                    {
+                        x.strcmd.append("/");
+                    }
+                }
+                x.strcmd.append(x.strappname);
+                if(x.strargs.length() > 0)
+                {
+                    x.strcmd.append(" ");
+                    x.strcmd.append(x.strargs);
+                }
+
+
+                xvectorprog.push_back(x);
+            }
+
+        }
+
+         n = n.nextSibling();
+    }
+
+    return xvectorprog;
+}
+
+void ProgMon::updatexml(std::string path)
+{
+    mMutex.lock();
+    std::vector<ProgUnit> xvectorprog = loadprogunit(path);
+    int i;
+    int nsize = mvectorprog.size();
+    int nnewsize = xvectorprog.size();
+    //Start new xml have program.
+    for(i=0;i<nnewsize;i++)
+    {
+        ProgUnit * pnewPU = &(xvectorprog[i]);
+        int j;
+        bool bNew = true;
+        nsize = mvectorprog.size();
+        int noldpos = -1;
+        (void)noldpos;
+        for(j=0;j<nsize;j++)
+        {
+            if(strncmp(mvectorprog[j].strcmd.data(),pnewPU->strcmd.data(),255) == 0)
+            {
+                bNew = false;
+                noldpos = j;
+                break;
+            }
+        }
+        if(bNew == true)
+        {
+            mvectorprog.push_back(*pnewPU);
+            if(pnewPU->mbautostart) StartProc(&mvectorprog[mvectorprog.size() -1]);
+        }
+        else
+        {
+            std::cout<<pnewPU->strcmd.data()<<" is exist. "<<std::endl;
+        }
+    }
+
+
+    //Stop And Delete new xml not have item.
+    nsize = mvectorprog.size();
+    for(i=0;i<static_cast<int>(mvectorprog.size()) ;i++)
+    {
+        int j;
+        bool bNewHave = false;
+        for(j=0;j<nnewsize;j++)
+        {
+            if(strncmp(mvectorprog[i].strcmd.data(),xvectorprog[j].strcmd.data(),255) == 0)
+            {
+                bNewHave = true;
+                break;
+            }
+        }
+        if(bNewHave == false)
+        {
+            if(mvectorprog[i].mbRun)
+            {
+                StopProc(&mvectorprog[i]);
+            }
+            mvectorprog.erase(mvectorprog.begin()+i);
+            i--;
+        }
+    }
+    mMutex.unlock();
+//    nsize = mvectorprog.size();
+//    nsize = nsize +1-1;
+}
+
+
+void ProgMon::onProcessStarted()
+{
+//    qDebug("started.");
+    QProcess * proc = (QProcess *)sender();
+
+    int nsize = mvectorprog.size();
+    int i;
+    for(i=0;i<nsize;i++)
+    {
+        if(proc == mvectorprog.at(i).mProcess)
+        {
+            mvectorprog.at(i).mbRun = true;
+#ifdef IV_OS_UNIX
+            mvectorprog.at(i).mpid = proc->processId();
+//            mvectorprog.at(i).mpid = proc->pid();
+#endif
+#ifdef IV_OS_WIN
+
+            mvectorprog.at(i).mpid = proc->pid()->dwProcessId;
+#endif
+            mvectorprog.at(i).mnStartCount++;
+ //           qDebug("program id is %ld",mvectorprog.at(i).mpid);
+            emit SigProcStarted(&(mvectorprog.at(i)));
+            break;
+ //           qDebug("find procname is %s",mvectorprog.at(i).strcmd.data());
+        }
+    }
+}
+
+//add tjc
+void ProgMon::onProcessErrorStarted(QProcess::ProcessError error){
+    qDebug("Process Error Started.");
+    std::string desc;
+    int code;
+    QProcess * proc = (QProcess*)sender();
+    int nsize = mvectorprog.size();
+    int i;
+    for(i=0;i<nsize;i++)
+    {
+        if(proc == mvectorprog.at(i).mProcess)
+        {
+            if(error == QProcess::ProcessError::FailedToStart){
+                //启动错误 启动失败
+                code = 0x0001;
+            }else{
+                //未知错误 启动失败
+                code = 0x0002;
+            }
+            desc = mvectorprog.at(i).strappname + ":FailedToStart";
+            //记录故障状态,模块启动失败
+ //           ivfault->SetFaultState(2,code,desc.c_str());
+        }
+    }
+
+}
+
+
+void ProgMon::onReadStandardOutput()
+{
+    QProcess * proc = (QProcess *)sender();
+    QByteArray ba = proc->readAllStandardOutput();
+
+
+    if(mbAllNoLog == false)
+    {
+        mMutex_stdout.lock();
+        if(mvectorstdout.size()<1000) mvectorstdout.push_back(stdoutunit(proc,ba));
+        mMutex_stdout.unlock();
+    }
+//    qDebug("process out: %s ",ba.data());
+}
+
+void ProgMon::onReadStandardError()
+{
+    QProcess * proc = (QProcess *)sender();
+    QByteArray ba = proc->readAllStandardError();
+
+
+    mMutex_errout.lock();
+    if(mvectorerrout.size()<1000) mvectorerrout.push_back(stdoutunit(proc,ba));
+    mMutex_errout.unlock();
+
+    return;
+
+    if(ba.size() == 0)return;
+    LogError(proc,ba);
+
+//    if(mbAllNoLog == false)
+//    {
+//        mMutex_stdout.lock();
+//        if(mvectorstdout.size()<1000) mvectorstdout.push_back(stdoutunit(proc,ba));
+//        mMutex_stdout.unlock();
+//    }
+//    qDebug("process error: %s ",ba.data());
+}
+
+void ProgMon::onProcessEnd()
+{
+    qDebug("process end.");
+    QProcess * proc = (QProcess *)sender();
+    int nsize = mvectorprog.size();
+    int i;
+    for(i=0;i<nsize;i++)
+    {
+        ProgUnit *pu = &(mvectorprog.at(i));
+        if(proc == pu->mProcess)
+        {
+            pu->mbRun = false;
+            emit SigProcStoped(pu);
+
+            if(mbquit)
+            {
+                std::cout<<"Program "<<pu->strappname<<" quit."<<std::endl;
+                break;
+            }
+
+ //           delete pu->mProcess;
+
+            if(pu->mbautostart)
+            {
+    //            ivfault->SetFaultState(1,0x0003,(pu->strappname + " abnormal stop").data());
+    //            ivlog->warn("%s : process abnormal stop", pu->strappname.data());
+                StartProc(&(mvectorprog.at(i)));
+            }
+            //if autostart
+            //modify tjc
+//            if(pu->mbautostart && pu->state && proc->exitCode() != 0)
+//            {
+//                //警告 进程异常关闭
+//                ivfault->SetFaultState(1,0x0003,(pu->strappname + " abnormal stop").data());
+//                ivlog->warn("%s : process abnormal stop", pu->strappname.data());
+
+//                //两分钟内重启三次则终止该模块
+//                if(pu->timeRec.isNull()){
+//                    pu->timeRec = QTime::currentTime();
+//                }
+
+//                int elapsed = pu->timeRec.msecsTo(QTime::currentTime());
+//                if(elapsed > 1000 * 60 * 2){
+//                    pu->timeRec = QTime::currentTime();
+//                    pu->count = 0;
+//                }else{
+//                    if(pu->count <= 3){
+//                        pu->count++;
+//                    }else{
+//                        //停止该模块的启动并报故障
+//                        pu->state = 0;
+//                        //故障 进程多次异常关闭,不再启动该进程
+//                        ivfault->SetFaultState(2,0x0004,(pu->strappname + " exception stop").data());
+//                        ivlog->error("%s : process exception stop", pu->strappname.data());
+//                        return;
+//                    }
+//                }
+
+//                StartProc(&(mvectorprog.at(i)));
+//            }
+
+
+            break;
+ //           qDebug("find procname is %s",mvectorprog.at(i).strcmd.data());
+        }
+    }
+
+
+}
+
+void ProgMon::onChRead()
+{
+    QProcess * proc = (QProcess *)sender();
+    QByteArray ba = proc->readAll();
+
+    int ncha = proc->currentWriteChannel();
+    (void)ncha;
+
+    if(proc->currentWriteChannel() == 1)
+    {
+        std::cout<<"Receive a Error Output."<<std::endl;
+        LogError(proc,ba);
+    }
+
+
+
+#ifdef QT_DEBUG
+//    qDebug("process INFO: %s ", ba.data());
+#endif
+
+    if(mbAllNoLog == false)
+    {
+        mMutex_stdout.lock();
+        if(mvectorstdout.size()<1000) mvectorstdout.push_back(stdoutunit(proc,ba));
+        mMutex_stdout.unlock();
+    }
+
+//    qDebug("read chanel count is :%d ",proc->readChannelCount());
+}
+
+void ProgMon::restartProc(ProgUnit *pu){
+    if(pu == 0)return;
+
+    //判断项目当前是否启动状态
+    if(checkStartState(pu)){
+        return;
+    }
+
+
+    if(pu->mProcess == 0){
+        StartProc(pu);
+    }
+    pu->mProcess->start();
+    pu->state = 1;
+ //   ivlog->info("start program: AppGroup - %s; AppDir - %s; AppName - %s; StartArgs - %s;", pu->strgroup.c_str(), pu->strappdir.c_str(), pu->strappname.c_str(), pu->strargs.c_str());
+}
+
+ProgUnit * ProgMon::FindProcByName(std::string strappname, std::string strargs)
+{
+    ProgUnit * pu = 0;
+    int i;
+    int nsize =  mvectorprog.size();
+    for(i=0;i<nsize;i++)
+    {
+        ProgUnit * putem = &mvectorprog.at(i);
+        if(strargs.size()<1)
+        {
+            if(strappname == putem->strappname)
+            {
+                pu = putem;
+                break;
+            }
+        }
+        else
+        {
+            if((strappname == putem->strappname)&&(strargs == putem->strargs))
+            {
+                pu = putem;
+                break;
+            }
+        }
+    }
+
+    return pu;
+}
+
+void ProgMon::StartProc(std::string strappname, std::string strargs)
+{
+    ProgUnit * pu = FindProcByName(strappname,strargs);
+
+    if(pu == 0)
+    {
+        qDebug("StartProc can't find app = %s args = %s",strappname.data(),strargs.data());
+        return;
+    }
+
+    pu->mbautostart = false;
+    StartProc(pu);
+}
+
+void ProgMon::StopProc(std::string strappname, std::string strargs)
+{
+    ProgUnit * pu = FindProcByName(strappname,strargs);
+
+    if(pu == 0)
+    {
+        qDebug("StopProc can't find app = %s args = %s",strappname.data(),strargs.data());
+        return;
+    }
+
+    pu->mbautostart = false;
+    StopProc(pu);
+}
+
+
+
+void ProgMon::StartProc(ProgUnit *pu)
+{
+    if(pu->mbRun)
+    {
+        qDebug("process %s is running. not need start.",pu->strappname.data());
+        return;
+    }
+    pu->mProcess = new QProcess(this);
+
+
+    connect(pu->mProcess,SIGNAL(started()),this,SLOT(onProcessStarted()));
+    connect(pu->mProcess,SIGNAL(finished(int)),this,SLOT(onProcessEnd()));
+//    connect(pu->mProcess,SIGNAL(readyRead()),this,SLOT(onChRead()));
+    connect(pu->mProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(onReadStandardOutput()));
+    connect(pu->mProcess,SIGNAL(readyReadStandardError()),this,SLOT(onReadStandardError()));
+
+
+    connect(pu->mProcess,SIGNAL(error(QProcess::ProcessError)),this,SLOT(onProcessErrorStarted(QProcess::ProcessError)));
+
+
+
+    pu->mProcess->start(pu->strcmd.data());
+    pu->state = 1;
+
+
+//    ivlog->info("start program: AppGroup - %s; AppDir - %s; AppName - %s; StartArgs - %s;", pu->strgroup.c_str(), pu->strappdir.c_str(), pu->strappname.c_str(), pu->strargs.c_str());
+
+
+}
+
+//test
+void ProgMon::StopProcTest(){
+    int nsize = mvectorprog.size();
+    for (int i = 0; i < nsize; i++) {
+        ProgUnit * ppu = &(mvectorprog.at(i));
+        StopProc(ppu);
+    }
+}
+
+void ProgMon::StopProc(ProgUnit *pu)
+{
+    if(pu == 0)return;
+    if(pu->mProcess == 0)return;
+    if(!pu->mbRun)
+    {
+        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;
+    }
+
+    //modify tjc
+    //发送dbus信号使程序退出
+    QDBusMessage msg = QDBusMessage::createSignal("/catarc/adc",  "adciv.sys.stop.interface", pu->strappname.data());
+    QDBusConnection::sessionBus().send(msg);
+//    ivlog->info("dispatch %s exit", pu->strappname.c_str());
+    pu->state = 0;
+    emit checkExit(pu);
+}
+
+void ProgMon::ForceStopProc(ProgUnit *pu){
+    if(pu == 0)return;
+    if(pu->mProcess == 0)return;
+    pu->mProcess->kill();
+    return;
+
+    if(!checkStartState(pu)){
+        return;
+    }
+
+    //modify tjc
+    //发送dbus信号使程序退出
+    QDBusMessage msg = QDBusMessage::createSignal("/catarc/adc",  "adciv.sys.stop.interface", pu->strappname.data());
+    QDBusConnection::sessionBus().send(msg);
+//    ivlog->info("dispatch %s exit", pu->strappname.c_str());
+    pu->state = 0;
+    emit checkExit(pu);
+}
+
+//void ProgMon::ForceStopProc(ProgUnit *pu){
+//    if(pu == 0)return;
+//    if(pu->mProcess == 0)return;
+//    pu->mProcess->kill();
+//}
+
+bool ProgMon::onCheckExit(ProgUnit *pu){
+    int count = 0;
+    while(!pu->state){
+
+        if(checkStartState(pu)){
+            count++;
+            QThread::msleep(200);
+            if(count >= 5){
+                //退出延迟警告
+ //               ivfault->SetFaultState(1,0x0005,(pu->strappname + ": process exit exception").data());
+ //               ivlog->warn("%s : process exit exception", pu->strappname.data());
+
+                return false;
+            }
+            if(count >= 15){
+                //模块退出故障,未能正常退出,取消退出
+//                ivfault->SetFaultState(2,0x0006,(pu->strappname + ": process exit exception").data());
+ //               ivlog->error("%s : process exit exception", pu->strappname.data());
+            }
+        }else{
+            pu->mbRun = false;
+            pu->UpdateResState();
+            return true;
+        }
+
+    }
+
+}
+
+bool ProgMon::checkStartState(ProgUnit *pu){
+//    Q_PID pid = pu->mProcess->pid();
+
+    unsigned int npid;
+#ifdef IV_OS_UNIX
+    npid = pu->mProcess->processId();
+//    npid =  pu->mProcess->pid();
+#endif
+
+#ifdef IV_OS_WIN
+    npid = pu->mProcess->pid()->dwProcessId;
+#endif
+    float cput = get_proc_cpu(npid);
+    unsigned int memt = get_proc_mem(npid);
+    unsigned int threadnumt = get_proc_threadnum(npid);
+    if(threadnumt || memt || cput){
+        return true;
+    }else{
+        return false;
+    }
+}
+
+void ProgMon::run()
+{
+    qint64 interval = 1000;
+    qint64 nLastUpdate = 0;
+    while(!QThread::isInterruptionRequested())
+    {
+        qint64 nNow = QDateTime::currentMSecsSinceEpoch();
+        if((nNow - nLastUpdate)< interval)
+        {
+            msleep(10);
+            continue;
+        }
+        QString strsysinfo;
+        mPMS.UpdateCPUMemStat(strsysinfo);
+        mMutexSysinfo.lock();
+        mstrsysInfo = strsysinfo;
+        mMutexSysinfo.unlock();
+        nLastUpdate = nNow;
+        int i;
+
+        for(i=0;i<static_cast<int>(mvectorprog.size()) ;i++)
+        {
+            mMutex.lock();
+            mvectorprog[i].UpdateResState();
+            if(QThread::isInterruptionRequested())
+            {
+                mMutex.unlock();
+                break;
+            }
+            mMutex.unlock();
+        }
+
+
+    }
+}
+
+void ProgMon::setquit()
+{
+    mbquit = true;
+}
+
+void ProgMon::threaderrout()
+{
+    QString strhomepath = getenv("HOME");
+
+    int nNeedCheckSpace = 0;
+
+    bool bHaveHDDSpace = true;
+
+    unsigned int i;
+
+    while(mberroutrun)
+    {
+
+
+        std::vector<stdoutunit> xvectorerrout;
+        mMutex_errout.lock();
+        xvectorerrout= mvectorerrout;
+        mvectorerrout.clear();
+        mMutex_errout.unlock();
+        if(xvectorerrout.size() == 0)
+        {
+            std::this_thread::sleep_for(std::chrono::milliseconds(10));
+        }
+        else
+        {
+
+            if(bHaveHDDSpace == false)
+            {
+                continue;
+            }
+            for(i=0;i<xvectorerrout.size();i++)
+            {
+                unsigned int j;
+                std::string strappname;
+                std::string strarg;
+                bool bFind = false;
+                mMutex.lock();
+                for(j=0;j<mvectorprog.size();j++)
+                {
+                    ProgUnit *pu = &(mvectorprog.at(j));
+                    if(xvectorerrout[i].mpProc == pu->mProcess)
+                    {
+                        strappname =  pu->strappname;
+                        strarg = pu->strargs;
+                        bFind = true;
+                        break;
+                    }
+                }
+                mMutex.unlock();
+
+                if(bFind)
+                {
+
+                        if(nNeedCheckSpace <= 0)
+                        {
+ //                           std::cout<<"check space."<<std::endl;
+                            nNeedCheckSpace = 1000;
+                            int nSpace = get_path_availspace(strhomepath);
+
+ //                           std::cout<<"hard space is "<<nSpace<<" MB."<<std::endl;
+                            if(nSpace<1000)
+                            {
+                                std::cout<<"Hard Disk No space to save std log."<<std::endl;
+                                bHaveHDDSpace = false;
+                            }
+                        }
+                        nNeedCheckSpace--;
+                        if(bHaveHDDSpace)
+                        {
+                            QString strlog;
+                            strlog = QDateTime::currentDateTime().toString("(yyyy/MM/dd hh:mm:ss:zzz")
+                                    + " | " + strappname.data() + " "+ strarg.data() + ")"
+                                    +xvectorerrout[i].mba.data();
+                            WriteLog(strlog.toLatin1().data());
+                        }
+
+                }
+                else
+                {
+                    std::cout<<"not found a std out 's process."<<std::endl;
+                }
+            }
+
+        }
+    }
+
+    std::cout<<"threaderrout complete."<<std::endl;
+}
+
+void ProgMon::threadstdout()
+{
+
+    QString strhomepath = getenv("HOME");
+
+    int nNeedCheckSpace = 0;
+
+    bool bHaveHDDSpace = true;
+
+    while(mbstdoutrun)
+    {
+        bool bAllNoLog = true;
+        unsigned int i;
+        mMutex.lock();
+        for(i=0;i<mvectorprog.size();i++)
+        {
+            if(mvectorprog[i].mbSavestdout)
+            {
+                bAllNoLog = false;
+                break;
+            }
+        }
+        mMutex.unlock();
+
+        if(mbAllNoLog != bAllNoLog)
+        {
+            mbAllNoLog = bAllNoLog;
+            if(bAllNoLog == true)
+            {
+                mMutex_stdout.lock();
+                mvectorstdout.clear();
+                mMutex_stdout.unlock();
+            }
+        }
+
+        if(mbAllNoLog == true)
+        {
+            msleep(100);
+            continue;
+        }
+
+        std::vector<stdoutunit> xvectorstdout;
+        mMutex_stdout.lock();
+        xvectorstdout= mvectorstdout;
+        mvectorstdout.clear();
+        mMutex_stdout.unlock();
+        if(xvectorstdout.size() == 0)
+        {
+            msleep(10);
+        }
+        else
+        {
+
+            if(bHaveHDDSpace == false)
+            {
+                continue;
+            }
+            for(i=0;i<xvectorstdout.size();i++)
+            {
+                unsigned int j;
+                std::string strappname;
+                std::string strarg;
+                bool bFind = false;
+                bool bSave = false;
+                mMutex.lock();
+                for(j=0;j<mvectorprog.size();j++)
+                {
+                    ProgUnit *pu = &(mvectorprog.at(j));
+                    if(xvectorstdout[i].mpProc == pu->mProcess)
+                    {
+                        strappname =  pu->strappname;
+                        strarg = pu->strargs;
+                        bFind = true;
+                        bSave = pu->mbSavestdout;
+                        break;
+                    }
+                }
+                mMutex.unlock();
+
+                if(bFind)
+                {
+                    if(bSave)
+                    {
+                        if(nNeedCheckSpace <= 0)
+                        {
+ //                           std::cout<<"check space."<<std::endl;
+                            nNeedCheckSpace = 1000;
+                            int nSpace = get_path_availspace(strhomepath);
+
+ //                           std::cout<<"hard space is "<<nSpace<<" MB."<<std::endl;
+                            if(nSpace<1000)
+                            {
+                                std::cout<<"Hard Disk No space to save std log."<<std::endl;
+                                bHaveHDDSpace = false;
+                            }
+                        }
+                        nNeedCheckSpace--;
+                        if(bHaveHDDSpace)
+                        {
+                            QString strlog;
+                            strlog = QDateTime::currentDateTime().toString("(yyyy/MM/dd hh:mm:ss:zzz")
+                                    + " | " + strappname.data() + " "+ strarg.data() + ")"
+                                    +xvectorstdout[i].mba.data();
+                            WriteStdLog(strlog.toLatin1().data());
+                        }
+                    }
+                }
+                else
+                {
+                    std::cout<<"not found a std out 's process."<<std::endl;
+                }
+            }
+
+        }
+    }
+
+    std::cout<<"threadstdout complete."<<std::endl;
+}
+
+void ProgMon::LogError(QProcess *proc, QByteArray &ba)
+{
+//    std::cout<<"error is "<<ba.data()<<std::endl;
+
+    static int nCheckSpace = 0;
+    static bool bSave = true;
+    if(bSave == false)return;
+    if(nCheckSpace<=0)
+    {
+        nCheckSpace = 10000;
+        QString strhomepath = getenv("HOME");
+        if(get_path_availspace(strhomepath)<100)
+        {
+            bSave = false;
+            return;
+        }
+
+    }
+    nCheckSpace--;
+    unsigned int i;
+    std::string strappname;
+    std::string strarg;
+    bool bFind = false;
+    mMutex.lock();
+    for(i=0;i<mvectorprog.size();i++)
+    {
+        ProgUnit *pu = &(mvectorprog.at(i));
+        if(proc == pu->mProcess)
+        {
+            strappname =  pu->strappname;
+            strarg = pu->strargs;
+            bFind = true;
+            break;
+        }
+    }
+    mMutex.unlock();
+
+    if(bFind)
+    {
+        QString strlog;
+        strlog = QDateTime::currentDateTime().toString("(yyyy/MM/dd hh:mm:ss:zzz")
+                + " | " + strappname.data() + " "+ strarg.data() + ")"
+                +ba.data();
+        WriteLog(strlog.toLatin1().data());
+    }
+
+}
+
+void ProgMon::InitLog()
+{
+    QString strpath = getenv("HOME");
+
+    strpath = strpath + "/log";
+    QDir xDir(strpath);
+    if(xDir.exists() == false)
+    {
+        std::cout<<"dir "<<strpath.toLatin1().data()<<" not exist . Create it."<<std::endl;
+        if(xDir.mkdir(strpath) == false)
+        {
+            std::cout<<"make dir faile . dir is "<<strpath.toLatin1().data()<<std::endl;
+            mbFileLog = false;
+            return;
+        }
+    }
+
+    QString strname = "IVSysMan-errlog-" + QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz.log");
+    QString strstdname = "IVSysMan-stdlog-" + QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz.log");
+    QString strstdpath = strpath + "/" + strstdname;
+    strpath = strpath +"/" + strname;
+
+    mFileLog.setFileName(strpath);
+
+    if(mFileLog.open(QIODevice::ReadWrite))
+    {
+        mbFileLog = true;
+    }
+    else
+    {
+        std::cout<<" Create error log File Fail. File Path is "<<strpath.toLatin1().data()<<std::endl;
+        mbFileLog = false;
+    }
+
+
+
+
+    mFileStdLog.setFileName(strstdpath);
+
+    if(mFileStdLog.open(QIODevice::ReadWrite))
+    {
+        mbFileStdLog = true;
+    }
+    else
+    {
+        std::cout<<" Create std log File Fail. File Path is "<<strpath.toLatin1().data()<<std::endl;
+        mbFileStdLog = false;
+    }
+
+}
+
+void ProgMon::WriteLog(const char *strlog)
+{
+    if(mbFileLog)
+    {
+        mFileLog.write(strlog,strnlen(strlog,100000));
+//        mFileLog.flush();
+    }
+}
+
+
+void  ProgMon::WriteStdLog(const char *strlog)
+{
+    if(mbFileStdLog)
+    {
+        mFileStdLog.write(strlog,strnlen(strlog,100000));
+    }
+}
+
+int ProgMon::get_path_availspace(const QString & path)
+{
+#ifdef OS_UNIX
+    struct statfs diskInfo;
+    statfs(path.toUtf8().data(), &diskInfo);
+
+    qDebug("%s 总大小:%.0lfMB 可用大小:%.0lfMB",path.toStdString().c_str(),(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 ProgMon::UpdateCPUMemStat()
+{
+    return;
+    static qint64 nLastCPUTotal,nLastIdleTotal;
+    (void)nLastCPUTotal;
+    (void)nLastIdleTotal;
+    static std::vector<qint64> nVectorLastCPU;
+    static std::vector<qint64> nVectorLastIdle;
+
+    QFile xFileStat;
+    xFileStat.setFileName("/proc/stat");
+    if(xFileStat.open(QIODevice::ReadOnly))
+    {
+        QByteArray ba = xFileStat.readAll();
+        QList<QByteArray> xlist = ba.split('\n');
+        int nsize = xlist.size();
+        (void)nsize;
+    }
+    xFileStat.close();
+
+}
+
+QString ProgMon::GetSysInfo()
+{
+    QString strsysinfo;
+    mMutexSysinfo.lock();
+    strsysinfo = mstrsysInfo;
+    mMutexSysinfo.unlock();
+    return strsysinfo;
+}
+

+ 157 - 0
src/apollo/code/pilot_apollo_bridge_gui/progmon.h

@@ -0,0 +1,157 @@
+#ifndef PROGMON_H
+#define PROGMON_H
+
+#include <string>
+#include <vector>
+#include <thread>
+
+#include <QProcess>
+
+#include <QtXml>
+
+#include <QMutex>
+// Used For Program Monitor
+
+#include "cpumem.h"
+#include "QtDBus/QDBusMessage"
+#include "QtDBus/QDBusConnection"
+#include "progunit.h"
+
+#include "procmemstat.h"
+
+#ifdef IV_OS_WIN
+#include <windows.h>
+#endif
+
+
+class stdoutunit
+{
+public:
+    QProcess * mpProc;
+    QByteArray mba;
+public:
+    stdoutunit(QProcess * pProc,QByteArray & ba)
+    {
+        mpProc = pProc;
+        mba = ba;
+    }
+};
+
+class ProgMon : public QThread
+{
+    Q_OBJECT
+
+private slots:
+    void onProcessStarted();
+    void onProcessEnd();
+    void onChRead();
+    //add tjc
+    void onProcessErrorStarted(QProcess::ProcessError error);
+    //test
+    void StopProcTest();
+
+    void onReadStandardOutput();
+    void onReadStandardError();
+
+public slots:
+    bool onCheckExit(ProgUnit * pu);
+
+public:
+    /* From A XML Load Program List */
+    ProgMon(std::string path);
+    ~ProgMon();
+
+    /* Program List */
+    std::vector<ProgUnit> mvectorprog;
+
+    /* Start A Process */
+    void StartProc(ProgUnit * pu);
+
+    /* Stop A Process */
+    void StopProc(ProgUnit * pu);
+
+    /* fault stop process */
+    void ForceStopProc(ProgUnit * pu);
+    void restartProc(ProgUnit *pu);
+
+    //判断启动状态
+    bool checkStartState(ProgUnit *pu);
+
+    void updatexml(std::string path);
+
+    std::vector<ProgUnit> loadprogunit(std::string path);
+
+    void StartProc(std::string strappname,std::string strargs="");
+    void StopProc(std::string strappname,std::string strargs="");
+
+private:
+    QMutex mMutex;
+
+    ProgUnit * FindProcByName(std::string strappname,std::string strargs);
+
+signals:
+    /* Signal when proc started */
+    void SigProcStarted(ProgUnit * pu);
+    /* Signal When proc stoped */
+    void SigProcStoped(ProgUnit * pu);
+    void checkExit(ProgUnit * pu);
+
+private:
+    void run();
+
+    bool mbquit = false;
+
+public:
+    void setquit();
+
+private:
+    void threadstdout();
+    void threaderrout();
+
+    std::vector<stdoutunit> mvectorstdout;
+    QMutex mMutex_stdout;
+    bool mbstdoutrun = true;
+
+    std::vector<stdoutunit> mvectorerrout;
+    QMutex mMutex_errout;
+    bool mberroutrun = true;
+
+    bool mbAllNoLog = true;
+
+    std::thread * mpthread_stdout;
+    std::thread * mpthread_errout;
+
+private:
+    inline void LogError(QProcess * proc,QByteArray & ba);
+
+    QFile mFileLog;
+    bool mbFileLog = false;
+    void InitLog();
+
+    void WriteLog(const char * strlog);
+
+    QFile mFileStdLog;
+    bool mbFileStdLog = false;
+
+    void WriteStdLog(const char * strlog);
+
+    int get_path_availspace(const QString & path);
+
+private:
+    qint64 mPhyMemTotal;
+    qint64 mPhyMemAvail;
+    qint64 mMemTotal;
+    float mfCPULoad;
+    std::vector<float> mvectorcpuload;
+    void UpdateCPUMemStat();
+
+    ProcMemStat mPMS;
+
+    QString mstrsysInfo = "";
+    QMutex mMutexSysinfo;
+
+public:
+    QString GetSysInfo();
+};
+
+#endif // PROGMON_H

+ 145 - 0
src/apollo/code/pilot_apollo_bridge_gui/programviewunit.cpp

@@ -0,0 +1,145 @@
+#include "programviewunit.h"
+
+ProgramViewUnit::ProgramViewUnit(QGroupBox * pGroup,ProgUnit * pu, int x,int y)
+{
+    QLabel * pLabel;
+    QLineEdit * pLE;
+    SwitchButton * pswitch;
+
+    int nXPos = x;
+    int nHgt = 30;
+    pLabel = new QLabel(pGroup);
+    pLabel->setText(pu->strappname.data());
+    pLabel->setGeometry(nXPos,y,190,nHgt);
+    nXPos = nXPos + 200;
+
+
+    pLE = new QLineEdit(pGroup);
+    pLE->setText(pu->strargs.data());
+    pLE->setReadOnly(true);
+    pLE->setGeometry(nXPos,y,290,nHgt);
+    nXPos = nXPos + 300;
+
+    pswitch = new SwitchButton(pGroup);
+    pswitch->setGeometry(nXPos,y,90,nHgt);
+    nXPos = nXPos + 100;
+
+    mpLabelName = pLabel;
+    mpLEArgs = pLE;
+    mpSwich = pswitch;
+
+    pLE = new QLineEdit(pGroup);
+    pLE->setReadOnly(true);
+    pLE->setGeometry(nXPos,y,90,nHgt);
+    nXPos = nXPos + 100;
+    mpLECount = pLE;
+
+    pLE = new QLineEdit(pGroup);
+    pLE->setReadOnly(true);
+    pLE->setGeometry(nXPos,y,90,nHgt);
+    nXPos = nXPos + 100;
+    mpLEPID = pLE;
+
+    pLE = new QLineEdit(pGroup);
+    pLE->setReadOnly(true);
+    pLE->setGeometry(nXPos,y,90,nHgt);
+    nXPos = nXPos + 100;
+    mpLECPU = pLE;
+
+    pLE = new QLineEdit(pGroup);
+    pLE->setReadOnly(true);
+    pLE->setGeometry(nXPos,y,90,nHgt);
+    nXPos = nXPos + 100;
+    mpLEMem = pLE;
+
+    pLE = new QLineEdit(pGroup);
+    pLE->setReadOnly(true);
+    pLE->setGeometry(nXPos,y,90,nHgt);
+    nXPos = nXPos + 100;
+    mpLEThread = pLE;
+
+    pswitch = new SwitchButton(pGroup);
+    pswitch->setGeometry(nXPos,y,90,nHgt);
+    nXPos = nXPos + 100;
+    pswitch->setChecked(false);
+    if(pu->mbSavestdout)pswitch->setChecked(true);
+    mpLogStd = pswitch;
+
+    mPU = pu;
+
+    if(pu->mbRun)
+    {
+        pswitch->setChecked(true);
+    }
+
+    connect(mpSwich,SIGNAL(clicked(bool)),this,SLOT(onSwitchClick(bool)));
+    connect(mpLogStd,SIGNAL(clicked(bool)),this,SLOT(onLogSwitchClick(bool)));
+}
+
+ProgramViewUnit::~ProgramViewUnit()
+{
+    delete mpLogStd;
+    delete mpLabelName;
+    delete mpSwich;
+    delete mpLEArgs;
+    delete mpLECount;
+    delete mpLECPU;
+    delete mpLEMem;
+    delete mpLEPID;
+    delete mpLEThread;
+}
+
+void ProgramViewUnit::onSwitchClick(bool bClick)
+{
+    emit progclick(mPU,this,bClick);
+
+}
+
+void ProgramViewUnit::onLogSwitchClick(bool bClick)
+{
+    emit ProgLogClick(mPU,this,bClick);
+}
+
+void ProgramViewUnit::ProcStarted(ProgUnit *pu)
+{
+    if(pu == mPU)
+    {
+        if(!mpSwich->isChecked())
+        {
+            mpSwich->setChecked(true);
+        }
+    }
+}
+
+void ProgramViewUnit::ProcStopted(ProgUnit *pu)
+{
+    if(pu == mPU)
+    {
+        if(mpSwich->isChecked())
+        {
+            mpSwich->setChecked(false);
+        }
+    }
+}
+
+void ProgramViewUnit::UpdateState()
+{
+    if(mPU->mbRun == false)
+    {
+        mpLEPID->setText("");
+        mpLECPU->setText("");
+        mpLEMem->setText("");
+        mpLEThread->setText("");
+        return;
+    }
+
+//    mPU->UpdateResState();
+
+    mpLECount->setText(QString::number(mPU->mnStartCount));
+    mpLEPID->setText(QString::number(mPU->mpid));
+    mpLECPU->setText(QString::number(mPU->mfCPU));
+    mpLEMem->setText(QString::number(mPU->mfMem));
+    mpLEThread->setText(QString::number(mPU->mnThread));
+
+
+}

+ 68 - 0
src/apollo/code/pilot_apollo_bridge_gui/programviewunit.h

@@ -0,0 +1,68 @@
+#ifndef PROGRAMVIEWUNIT_H
+#define PROGRAMVIEWUNIT_H
+
+#include <QLabel>
+#include <QPushButton>
+#include <QLineEdit>
+#include <QGroupBox>
+#include <switchbutton.h>
+
+#include <progmon.h>
+
+class ProgramViewUnit : public QObject
+{
+    Q_OBJECT
+public:
+    ProgramViewUnit(QGroupBox * pGroup,ProgUnit * pu, int x,int y);
+    ~ProgramViewUnit();
+
+
+    /* Moudle Name */
+    QLabel * mpLabelName;
+    /* Module Args */
+    QLineEdit * mpLEArgs;
+    /* Module Switch */
+    SwitchButton * mpSwich;
+    /* Module Start Count */
+    QLineEdit * mpLECount;
+    /* Module PID */
+    QLineEdit * mpLEPID;
+    /* Moudle CPU */
+    QLineEdit * mpLECPU;
+    /* Module Mem */
+    QLineEdit * mpLEMem;
+    /* Module Thread Number */
+    QLineEdit * mpLEThread;
+    /* Module Log std Switch */
+    SwitchButton * mpLogStd;
+
+
+
+private slots:
+    void onSwitchClick(bool bClick);
+    void onLogSwitchClick(bool bClick);
+
+signals:
+    void progclick(ProgUnit *,ProgramViewUnit * , bool);
+
+    void ProgLogClick(ProgUnit * ,ProgramViewUnit * ,bool);
+
+private:
+    ProgUnit * mPU;
+
+public:
+    /* Processs Started  Update view if need */
+    void ProcStarted(ProgUnit * pu);
+
+    /* Process Stoped Update view if need */
+    void ProcStopted(ProgUnit * pu);
+
+    /* Update CPU Mem PID State */
+    void UpdateState();
+
+
+
+
+};
+
+#endif // PROGRAMVIEWUNIT_H

+ 22 - 0
src/apollo/code/pilot_apollo_bridge_gui/progunit.cpp

@@ -0,0 +1,22 @@
+#include "progunit.h"
+
+
+
+
+void ProgUnit::UpdateResState()
+{
+    if(mbRun)
+    {
+        mfCPU = get_proc_cpu(mpid,mnLastProcTotal,mnLastCPUTotal);
+        unsigned int nMem,nThread;
+        nMem = 0;
+        nThread = 0;
+        get_proc_mem_thread(mpid,nMem,nThread);
+        mfMem = nMem;
+        mnThread = nThread;
+ //       mfMem = get_proc_mem(mpid);
+        mfMem = mfMem/1000.0;
+ //       mnThread = get_proc_threadnum(mpid);
+    }
+}
+

+ 69 - 0
src/apollo/code/pilot_apollo_bridge_gui/progunit.h

@@ -0,0 +1,69 @@
+#ifndef PROGUNIT_H
+#define PROGUNIT_H
+
+#include <QProcess>
+#include <QThread>
+#include <vector>
+
+#include <QtXml>
+// Used For Program Monitor
+
+#include "cpumem.h"
+#include "QtDBus/QDBusMessage"
+#include "QtDBus/QDBusConnection"
+
+class ProgUnit
+{
+public:
+
+    /* App Name */
+    std::string strappname;
+    /* App Directory */
+    std::string strappdir;
+    /* App Arg */
+    std::string strargs;
+    /* Is Auto Start */
+    bool mbautostart;
+    /* App Execution Command */
+    std::string strcmd;
+    /* Group Name */
+    std::string strgroup;
+    /* Process */
+    QProcess * mProcess;
+    /* run state */
+    bool mbRun = false;
+    /* processid */
+    qint64 mpid;
+
+    /* Start Count */
+    int mnStartCount = 0;
+    /* CPU */
+    float mfCPU;
+    /* Mem (Unit M)*/
+    float mfMem;
+    /* Thread Num */
+    int mnThread;
+
+    int state;//模块调度设定运行状态:0 停止,1 启动
+    QTime timeRec;//当前时间
+    int count;//次数
+
+    bool mbSavestdout = false;
+
+
+    unsigned long mnLastCPUTotal = 0;
+    unsigned long mnLastProcTotal = 0;
+
+
+
+
+public:
+    /* Get CPU Mem Thread */
+    void UpdateResState();
+
+
+
+};
+
+
+#endif // PROGUNIT_H

+ 62 - 0
src/apollo/code/pilot_apollo_bridge_gui/switchbutton.cpp

@@ -0,0 +1,62 @@
+#include <QPainter>
+#include <QPaintEvent>
+#include <QStyleOption>
+#include "switchbutton.h"
+
+SwitchButton::SwitchButton(QWidget* parent) : QPushButton(parent) {
+    setCheckable(true);
+    // Set default colors and labels
+    setColors();
+    setLabels();
+}
+
+void SwitchButton::setColors(const QColor on, const QColor off) {
+    onColor=on;
+    offColor=off;
+    if (on.red()+on.green()+on.blue()>500) {
+        onLabelColor=Qt::black;
+    }
+    else {
+        onLabelColor=Qt::white;
+    }
+    if (off.red()+off.green()+off.blue()>500) {
+        offLabelColor=Qt::black;
+    }
+    else {
+        offLabelColor=Qt::white;
+    }
+}
+
+void SwitchButton::setLabels(const QString on, const QString off) {
+    onLabel=on;
+    offLabel=off;
+    setMinimumWidth(fontMetrics().width(offLabel)+fontMetrics().width(onLabel)+fontMetrics().height()*2);
+}
+
+void SwitchButton::paintEvent(QPaintEvent* paint) {
+    QPushButton::paintEvent(paint);
+    QPainter p(this);
+    p.save();
+    int rectWidth=paint->rect().width()/2;
+    #ifdef Q_OS_ANDROID
+        // On Android, the buttons are much smaller than paint->rect().
+        int rectMargin=10;
+    #else
+        int rectMargin=4;
+    #endif
+    if (isChecked()) {
+        QRect rect=paint->rect().adjusted(rectWidth,rectMargin,-rectMargin,-rectMargin);
+        p.fillRect(rect,QBrush(onColor));
+        QPoint textPosi=rect.center()-QPoint(fontMetrics().width(onLabel)/2,1-fontMetrics().ascent()/2);
+        p.setPen(onLabelColor);
+        p.drawText(textPosi,onLabel);
+    }
+    else {
+        QRect rect=paint->rect().adjusted(rectMargin,rectMargin,-rectWidth,-rectMargin);
+        p.fillRect(rect,QBrush(offColor));
+        QPoint textPosi=rect.center()-QPoint(fontMetrics().width(offLabel)/2,1-fontMetrics().ascent()/2);
+        p.setPen(offLabelColor);
+        p.drawText(textPosi,offLabel);
+    }
+    p.restore();
+}

+ 75 - 0
src/apollo/code/pilot_apollo_bridge_gui/switchbutton.h

@@ -0,0 +1,75 @@
+#ifndef SWITCHBUTTON_H
+#define SWITCHBUTTON_H
+
+#include <QPushButton>
+
+/**
+ * This is a button which can be switched on and off.
+ * It looks similar as the on/off switches of Android.
+ * <p>
+ * The method isChecked() return the on/off state.
+ */
+
+class SwitchButton : public QPushButton {
+    Q_OBJECT
+
+public:
+    /** Constructor */
+    explicit SwitchButton(QWidget* parent = 0);
+
+    /** Set the color for on and off status. */
+    void setColors(const QColor on=Qt::blue, const QColor off=Qt::gray);
+
+    /** Set the labels for on and off status. */
+    void setLabels(const QString on=QString(tr("on")), const QString off=QString(tr("off")));
+
+protected:
+
+    void paintEvent(QPaintEvent* paint);
+
+    /** Color for on state */
+    QColor onColor;
+
+    /** Color for off state */
+    QColor offColor;
+
+    /** Label for on state */
+    QString onLabel;
+
+    /** Label for off state */
+    QString offLabel;
+
+    /** Color of the label in on state */
+    QColor onLabelColor;
+
+    /** Color of the label in off state */
+    QColor offLabelColor;
+
+};
+
+#endif // SWITCHBUTTON_H
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 37 - 0
src/apollo/code/pilot_apollo_bridge_gui/sysman.cpp

@@ -0,0 +1,37 @@
+#include "sysman.h"
+
+SysMan::SysMan(std::string strxmlpath)
+{
+    mbLogOn = false;
+    mstrxmlpath = strxmlpath;
+    mbSysRunning = false;
+}
+
+SysMan::~SysMan()
+{
+    if(mbLogOn)SetLogOff();
+    if(mbSysRunning)StopSys();
+}
+
+bool SysMan::StartSys()
+{
+    mbSysRunning = true;
+    return true;
+}
+
+void SysMan::StopSys()
+{
+    mbSysRunning = false;
+    return;
+}
+
+bool SysMan::SetLogOn(std::string strlogpath)
+{
+    mbLogOn = true;
+    return true;
+}
+
+void SysMan::SetLogOff()
+{
+    mbLogOn = false;
+}

+ 27 - 0
src/apollo/code/pilot_apollo_bridge_gui/sysman.h

@@ -0,0 +1,27 @@
+#ifndef SYSMAN_H
+#define SYSMAN_H
+
+#include <QObject>
+#include <QFile>
+
+class SysMan : public QObject
+{
+     Q_OBJECT
+public:
+    SysMan(std::string strxmlpath);
+    ~SysMan();
+private:
+    std::string mstrxmlpath;
+    std::string mstrlogpath;
+    QFile mFileLog;
+    bool mbLogOn;
+    bool mbSysRunning;
+public:
+    bool SetLogOn(std::string strlogpath);
+    void SetLogOff();
+    bool StartSys();
+    void StopSys();
+
+};
+
+#endif // SYSMAN_H