Browse Source

add IVSysMan_grpc.

yuchuli 2 years ago
parent
commit
706d2c85e7

+ 1 - 1
src/tool/IVSysMan/cpumem.cpp

@@ -261,7 +261,7 @@ unsigned int get_proc_threadnum(unsigned int pid){
         {
             break;
         }
-        if(strstr(line_buff,"Threads:")>0)
+        if(strstr(line_buff,"Threads:")!=NULL)
         {
             break;
         }

+ 34 - 0
src/tool/IVSysMan_grpc/IVSysMan_grpc.pro

@@ -0,0 +1,34 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2022-12-13T14:12:51
+#
+#-------------------------------------------------
+
+QT       += core gui
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = IVSysMan_grpc
+TEMPLATE = app
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which has been marked as deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+
+SOURCES += \
+        main.cpp \
+        mainwindow.cpp
+
+HEADERS += \
+        mainwindow.h
+
+FORMS += \
+        mainwindow.ui

+ 181 - 0
src/tool/IVSysMan_grpc/main.cpp

@@ -0,0 +1,181 @@
+#include "mainwindow.h"
+#include <QApplication>
+#include <QFile>
+#include <QStringList>
+
+#ifdef Android_IVSYSMAN
+#include <QAndroidJniEnvironment>
+#include <QtAndroid>
+//#include <QAndr
+#include <QAndroidJniObject>
+
+#endif
+
+#include <iostream>
+#include "xmlparam.h"
+
+#include "grpcclientthread.h"
+
+
+#ifdef Android_IVSYSMAN
+    grpcclientthread * ggt;
+#endif
+
+std::string gstrmode = "false";
+std::string gstrserverip = "192.168.1.102";
+std::string gstrserverport = "30061";
+std::string gstrqueryinterval = "1000";
+std::string gstrdefaultlane = "1";
+
+void LoadServerIP()
+{
+    QString strpath = "IVSysMan_grpc_android_server.txt";
+#ifdef Android_IVSYSMAN
+    strpath = "/storage/emulated/0/IVSysMan_grpc_android_server.txt";
+#endif
+    QFile xFile;
+    xFile.setFileName(strpath);
+    if(!xFile.open(QIODevice::ReadOnly))
+    {
+        return;
+    }
+    std::string strip = xFile.readAll().toStdString();
+    xFile.close();
+    if(strip.length()<7)
+    {
+        return;
+    }
+    gstrserverip = strip;
+
+}
+
+
+void SaveServerIP()
+{
+    QString strpath = "IVSysMan_grpc_android_server.txt";
+#ifdef Android_IVSYSMAN
+    strpath = "/storage/emulated/0/IVSysMan_grpc_android_server.txt";
+#endif
+    QFile xFile;
+    xFile.setFileName(strpath);
+    if(!xFile.open(QIODevice::ReadWrite))
+    {
+        return;
+    }
+    xFile.resize(0);
+    xFile.write(gstrserverip.data(),static_cast<qint64>(gstrserverip.length()) );
+    xFile.close();
+}
+
+#ifdef Android_IVSYSMAN
+
+bool requestPermission() {
+   QtAndroid::PermissionResult  r = QtAndroid::checkPermission("android.permission.WRITE_EXTERNAL_STORAGE");
+    if(r == QtAndroid::PermissionResult::Denied) {
+        QtAndroid::requestPermissionsSync( QStringList() << "android.permission.WRITE_EXTERNAL_STORAGE" );
+        r = QtAndroid::checkPermission("android.permission.WRITE_EXTERNAL_STORAGE");
+        if(r == QtAndroid::PermissionResult::Denied) {
+             return false;
+        }
+   }
+   return true;
+}
+
+#endif
+
+int main(int argc, char *argv[])
+{
+    QApplication a(argc, argv);
+
+#ifdef Android_IVSYSMAN
+
+    requestPermission();
+
+    QAndroidJniEnvironment env;
+    QAndroidJniObject activity = QtAndroid::androidActivity();
+
+
+    QAndroidJniObject name = QAndroidJniObject::getStaticObjectField(
+                "android/content/Context",
+                "POWER_SERVICE",
+                "Ljava/lang/String;"
+                );
+//    CHECK_EXCEPTION();
+    QAndroidJniObject powerService = activity.callObjectMethod(
+                "getSystemService",
+                "(Ljava/lang/String;)Ljava/lang/Object;",
+                name.object<jstring>());
+//    CHECK_EXCEPTION();
+    QAndroidJniObject tag = QAndroidJniObject::fromString("QtJniWakeLock");
+    QAndroidJniObject k = powerService.callObjectMethod(
+                "newWakeLock",
+                "(ILjava/lang/String;)Landroid/os/PowerManager$WakeLock;",
+                10, //SCREEN_BRIGHT_WAKE_LOCK
+                tag.object<jstring>()
+                );
+
+    if(k.isValid())
+    {
+        k.callMethod<void>("acquire");
+
+    }
+//    CHECK_EXCEPTION();
+
+
+#endif
+
+    QString strpath = QCoreApplication::applicationDirPath();
+
+   if(argc < 2)
+       strpath = strpath + "/IVSysMan_grpc.xml";
+   else
+       strpath = argv[1];
+//   std::cout<<strpath.toStdString()<<std::endl;
+
+#ifdef Android_IVSYSMAN
+   strpath = "/storage/emulated/0/IVSysMan_grpc.xml";
+#endif
+
+   iv::xmlparam::Xmlparam xp(strpath.toStdString());
+
+   gstrmode = xp.GetParam("useoutgrpc","false");
+   gstrserverip = xp.GetParam("serverip","192.168.1.102");
+   gstrserverport = xp.GetParam("serverport","30061");
+   gstrqueryinterval = xp.GetParam("queryinterval","1000");
+
+   grpcclientthread xrpcthread;
+
+#ifdef Android_IVSYSMAN
+   ggt = &xrpcthread;
+#endif
+
+   LoadServerIP();
+
+   if(strncmp(gstrmode.data(),"false",255) == 0)
+   {
+       xrpcthread.setserverip(gstrserverip);
+       xrpcthread.setserverport(gstrserverport);
+       xrpcthread.setqueryinterval(gstrqueryinterval);
+       xrpcthread.addquerymsgunit("IVSysMan_State",100000,1);
+       xrpcthread.addctrlmsgunit("IVSysMan_Ctrl",1000,1);
+
+#ifndef Android_IVSYSMAN
+       xrpcthread.startlisten();
+#endif
+       xrpcthread.start();
+   }
+
+    MainWindow w;
+
+
+#ifdef Android_IVSYSMAN
+    w.showFullScreen();
+//    w.showMaximized();
+
+#else
+     w.show();
+#endif
+
+
+    return a.exec();
+}

+ 58 - 0
src/tool/IVSysMan_grpc/mainwindow.cpp

@@ -0,0 +1,58 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+
+
+MainWindow::MainWindow(QWidget *parent) :
+    QMainWindow(parent),
+    ui(new Ui::MainWindow)
+{
+    ui->setupUi(this);
+
+    QGroupBox * pGroup = new QGroupBox();
+    pGroup->setGeometry(0,0,1030,6000);
+    pGroup->setStyleSheet("QGroupBox{border:none}");
+
+    QScrollArea * pScroll = new QScrollArea(ui->centralWidget);
+    pScroll->setWidget(pGroup);
+
+    pScroll->setGeometry(0,0,1000,1000);
+
+
+    QLabel * pLabel1,* pLabel2;
+    SwitchButton * pswitch;
+    int i;
+    for(i=0;i<30;i++)
+    {
+        pLabel1 = new QLabel(pGroup);
+        pLabel1->setText("detection_lidar_cnn_segmentaion" + QString::number(i));
+        pLabel1->setStyleSheet("font: 50px 'Arial';");
+        pLabel1->setGeometry(0,i*150,800,100);
+
+        pswitch = new SwitchButton(pGroup);
+        pswitch->setStyleSheet("font: 50px 'Arial';");
+        pswitch->setGeometry(830,i*150,150,100);
+
+        pLabel2 = new QLabel(pGroup);
+        pLabel2->setText("text text text text text text text text text text text text text text text text text" + QString::number(i));
+        pLabel2->setStyleSheet("font: 15px 'Arial';");
+        pLabel2->setGeometry(0,i*150+100,600,30);
+    }
+
+    mpScroll = pScroll;
+
+
+}
+
+MainWindow::~MainWindow()
+{
+    delete ui;
+}
+
+void MainWindow::resizeEvent(QResizeEvent *event)
+{
+    (void)event;
+    QSize sizemain = ui->centralWidget->size();
+
+    mpScroll->setGeometry(0,0,sizemain.width(),sizemain.height());
+}

+ 33 - 0
src/tool/IVSysMan_grpc/mainwindow.h

@@ -0,0 +1,33 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+#include <QGroupBox>
+#include <QScrollArea>
+
+#include <QLabel>
+
+#include "switchbutton.h"
+
+namespace Ui {
+class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    explicit MainWindow(QWidget *parent = 0);
+    ~MainWindow();
+public:
+     void resizeEvent(QResizeEvent *event);
+
+private:
+    Ui::MainWindow *ui;
+
+    QScrollArea * mpScroll;
+};
+
+#endif // MAINWINDOW_H

+ 40 - 0
src/tool/IVSysMan_grpc/mainwindow.ui

@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralWidget"/>
+  <widget class="QMenuBar" name="menuBar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>400</width>
+     <height>28</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QToolBar" name="mainToolBar">
+   <attribute name="toolBarArea">
+    <enum>TopToolBarArea</enum>
+   </attribute>
+   <attribute name="toolBarBreak">
+    <bool>false</bool>
+   </attribute>
+  </widget>
+  <widget class="QStatusBar" name="statusBar"/>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>

+ 62 - 0
src/tool/IVSysMan_grpc/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/tool/IVSysMan_grpc/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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 391 - 0
src/ui/ADCIntelligentShow_grpc/proto1804/grpcclientthread.cpp

@@ -0,0 +1,391 @@
+#include "grpcclientthread.h"
+
+
+grpcclientthread * ggrpcclient;
+
+#ifdef Android
+#include "adcintelligentshow.h"
+extern ADCIntelligentShow * gAShow;
+#endif
+
+void ListenData(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
+{
+    ggrpcclient->UpdateData(strdata,nSize,strmemname);
+//    std::cout<<"name is "<<strmemname<<std::endl;
+
+}
+
+
+grpcclientthread::grpcclientthread()
+{
+    ggrpcclient = this;
+}
+
+void grpcclientthread::dec_yaml(const char * stryamlpath)
+{
+
+    YAML::Node config;
+    try
+    {
+        config = YAML::LoadFile(stryamlpath);
+    }
+    catch(YAML::BadFile e)
+    {
+        qDebug("load error.");
+        return;
+    }
+
+    std::vector<std::string> vecmodulename;
+
+
+    if(config["server"])
+    {
+        mstrserverip = config["server"].as<std::string>();
+    }
+    if(config["port"])
+    {
+        mstrserverport = config["port"].as<std::string>();
+    }
+    if(config["uploadinterval"])
+    {
+        mstrqueryinterval = config["uploadinterval"].as<std::string>();
+    }
+
+
+
+    std::string strmsgname;
+
+    if(config["querymessage"])
+    {
+
+        for(YAML::const_iterator it= config["querymessage"].begin(); it != config["querymessage"].end();++it)
+        {
+            std::string strtitle = it->first.as<std::string>();
+            std::cout<<strtitle<<std::endl;
+
+            if(config["querymessage"][strtitle]["msgname"]&&config["querymessage"][strtitle]["buffersize"]&&config["querymessage"][strtitle]["buffercount"])
+            {
+                iv::rpcmsgunit xmu;
+                strmsgname = config["querymessage"][strtitle]["msgname"].as<std::string>();
+                strncpy(xmu.mstrmsgname,strmsgname.data(),255);
+                xmu.mnBufferSize = config["querymessage"][strtitle]["buffersize"].as<int>();
+                xmu.mnBufferCount = config["querymessage"][strtitle]["buffercount"].as<int>();
+                mvectorquerymsgunit.push_back(xmu);
+            }
+        }
+    }
+    else
+    {
+
+
+    }
+
+
+    if(config["ctrlmessage"])
+    {
+        std::string strnodename = "ctrlmessage";
+        for(YAML::const_iterator it= config[strnodename].begin(); it != config[strnodename].end();++it)
+        {
+            std::string strtitle = it->first.as<std::string>();
+            std::cout<<strtitle<<std::endl;
+
+            if(config[strnodename][strtitle]["msgname"]&&config[strnodename][strtitle]["buffersize"]&&config[strnodename][strtitle]["buffercount"])
+            {
+                iv::rpcmsgunit xmu;
+                strmsgname = config[strnodename][strtitle]["msgname"].as<std::string>();
+                strncpy(xmu.mstrmsgname,strmsgname.data(),255);
+                xmu.mnBufferSize = config[strnodename][strtitle]["buffersize"].as<int>();
+                xmu.mnBufferCount = config[strnodename][strtitle]["buffercount"].as<int>();
+                mvectorctrlmsgunit.push_back(xmu);
+            }
+        }
+    }
+    else
+    {
+
+    }
+
+    return;
+
+}
+
+void grpcclientthread::addquerymsgunit(std::string strquerymsg, int nbuffsize, int nbuffcount)
+{
+    int i;
+    for(i=0;i<mvectorquerymsgunit.size();i++)
+    {
+        if(strncmp(mvectorquerymsgunit[i].mstrmsgname,strquerymsg.data(),255)==0)
+        {
+            std::cout<<"grpcclientthread::addquerymsgunit msg "<<strquerymsg<<" is exist."<<std::endl;
+            return;
+        }
+    }
+
+    iv::rpcmsgunit xmu;
+    strncpy(xmu.mstrmsgname,strquerymsg.data(),255);
+    xmu.mnBufferSize = nbuffsize;
+    xmu.mnBufferCount = nbuffcount;
+    mvectorquerymsgunit.push_back(xmu);
+}
+
+void grpcclientthread::addctrlmsgunit(std::string strctrlmsg, int nbuffsize, int nbuffcount)
+{
+    int i;
+    for(i=0;i<mvectorctrlmsgunit.size();i++)
+    {
+        if(strncmp(mvectorctrlmsgunit[i].mstrmsgname,strctrlmsg.data(),255)==0)
+        {
+            std::cout<<"grpcclientthread::addquerymsgunit msg "<<strctrlmsg<<" is exist."<<std::endl;
+            return;
+        }
+    }
+
+    iv::rpcmsgunit xmu;
+    strncpy(xmu.mstrmsgname,strctrlmsg.data(),255);
+    xmu.mnBufferSize = nbuffsize;
+    xmu.mnBufferCount = nbuffcount;
+    mvectorctrlmsgunit.push_back(xmu);
+}
+
+
+void grpcclientthread::startlisten()
+{
+    int i;
+    for(i=0;i<mvectorctrlmsgunit.size();i++)
+    {
+        mvectorctrlmsgunit[i].mpa = iv::modulecomm::RegisterRecv(mvectorctrlmsgunit[i].mstrmsgname,ListenData);
+    }
+
+    for(i=0;i<mvectorquerymsgunit.size();i++)
+    {
+        mvectorquerymsgunit[i].mpa = iv::modulecomm::RegisterSend(mvectorquerymsgunit[i].mstrmsgname,mvectorquerymsgunit[i].mnBufferSize,
+                                                                 mvectorquerymsgunit[i].mnBufferCount);
+    }
+}
+
+void grpcclientthread::UpdateData(const char *strdata, const unsigned int nSize, const char *strmemname)
+{
+    int nsize = mvectorctrlmsgunit.size();
+    int i;
+    for(i=0;i<nsize;i++)
+    {
+        if(strncmp(strmemname,mvectorctrlmsgunit[i].mstrmsgname,255) == 0)
+        {
+            mMutexMsg.lock();
+            char * strtem = new char[nSize];
+            memcpy(strtem,strdata,nSize);
+            mvectorctrlmsgunit[i].mpstrmsgdata.reset(strtem);
+            mvectorctrlmsgunit[i].mndatasize = nSize;
+            mvectorctrlmsgunit[i].mbRefresh = true;
+            mMutexMsg.unlock();
+            break;
+        }
+    }
+}
+
+void grpcclientthread::run()
+{
+    int nsize = mvectorquerymsgunit.size();
+    int i;
+
+    int ninterval = atoi(mstrqueryinterval.data());
+    if(ninterval<=0)ninterval = 10;
+
+    QTime xTime;
+    xTime.start();
+    int nlastsend = xTime.elapsed();
+
+    std::string target_str = mstrserverip+":";
+    target_str = target_str + mstrserverport ;//std::to_string()
+    auto cargs = grpc::ChannelArguments();
+    cargs.SetMaxReceiveMessageSize(1024 * 1024 * 1024); // 1 GB
+    cargs.SetMaxSendMessageSize(1024 * 1024 * 1024);
+
+    std::shared_ptr<Channel> channel = grpc::CreateCustomChannel(
+             target_str, grpc::InsecureChannelCredentials(),cargs);
+
+    std::unique_ptr<iv::ivgrpc::Stub> stub_ = iv::ivgrpc::NewStub(channel);
+
+
+
+
+    int nid = 0;
+
+    // Container for the data we expect from the server.
+
+    gpr_timespec timespec;
+      timespec.tv_sec = 3;//设置阻塞时间为2秒
+      timespec.tv_nsec = 0;
+      timespec.clock_type = GPR_TIMESPAN;
+
+   int ndataindex = 0;
+
+ //   ClientContext context;
+
+    int nctrlindex = 0;
+    int nctrlnid = 0;
+
+    while(!QThread::isInterruptionRequested())
+    {
+        iv::queryreq request;
+        iv::queryReply reply;
+        std::this_thread::sleep_for(std::chrono::milliseconds(1));
+        if((xTime.elapsed()-nlastsend)<ninterval)
+        {
+            continue;
+        }
+
+        request.set_nindex(ndataindex);
+        request.set_strdevicename(mstrdevname);
+        for(i=0;i<nsize;i++)request.add_strmsgname();
+        for(i=0;i<nsize;i++)
+        {
+            request.set_strmsgname(i,mvectorquerymsgunit[i].mstrmsgname);
+        }
+//        std::cout<<"size is "<<nsize<<" msg size is "<<request.strmsgname_size()<<std::endl;
+
+        ClientContext context ;
+        context.set_deadline(timespec);
+
+        Status status = stub_->query(&context, request, &reply);
+        if (status.ok()) {
+//            std::cout<<nid<<" upload successfully"<<std::endl;
+            ndataindex = reply.nlastindex();
+            for(i=0;i<reply.msg_size();i++)
+            {
+  //              std::cout<<"share message. "<<std::endl;
+                sharequerymsg(&reply.msg(i));
+//                int j;
+//                for(j=0;j<reply.msg_size();j++)
+//                {
+//                    sharequerymsg(&reply.msg(j));
+//                }
+            }
+        } else {
+#ifndef Android
+ //         std::cout << status.error_code() << ": " << status.error_message()
+ //                   << std::endl;
+ //         std::cout<<"RPC failed"<<std::endl;
+#endif
+//          qDebug("not connected to server.");
+          if(status.error_code() == 4)
+          {
+#ifndef Android
+ //             std::cout<<" RPC Exceed Time, Create New stub_"<<std::endl;
+#endif
+              channel = grpc::CreateCustomChannel(
+                       target_str, grpc::InsecureChannelCredentials(),cargs);
+
+              stub_ = iv::ivgrpc::NewStub(channel);
+          }
+          std::this_thread::sleep_for(std::chrono::milliseconds(900));
+
+        }
+        nlastsend = xTime.elapsed();
+
+
+        iv::ctrlreq ctrlrequest;
+        iv::ctrlReply ctrlreply;
+
+        mMutexMsg.lock();
+        for(i=0;i<mvectorctrlmsgunit.size();i++)
+        {
+            if(mvectorctrlmsgunit[i].mbRefresh)
+            {
+                mvectorctrlmsgunit[i].mbRefresh = false;
+                iv::ModuleMsg xctrl;
+                xctrl.set_msgname(mvectorctrlmsgunit[i].mstrmsgname);
+                xctrl.set_index(nctrlindex);
+                nctrlindex++;
+                xctrl.set_xdata(mvectorctrlmsgunit[i].mpstrmsgdata.get(),mvectorctrlmsgunit[i].mndatasize);
+                xctrl.set_nlen(mvectorctrlmsgunit[i].mndatasize);
+                iv::ModuleMsg * pmsg = ctrlrequest.add_msg();
+                pmsg->CopyFrom(xctrl);
+
+            }
+
+        }
+        mMutexMsg.unlock();
+
+        if(ctrlrequest.msg_size()>0)
+        {
+            ctrlrequest.set_nid(nctrlnid);
+            nctrlnid++;
+            ctrlrequest.set_strdevicename(mstrdevname);
+
+            ClientContext contextctrl ;
+            contextctrl.set_deadline(timespec);
+
+            Status status2 = stub_->ctrl(&contextctrl, ctrlrequest, &ctrlreply);
+            if (status2.ok()) {
+       //         std::cout<<nid<<" upload successfully"<<std::endl;
+            } else {
+              std::cout << status2.error_code() << ": " << status2.error_message()
+                        << std::endl;
+              std::cout<<"RPC failed"<<std::endl;
+              if(status2.error_code() == 4)
+              {
+                  std::cout<<" RPC Exceed Time, Create New stub_"<<std::endl;
+                  channel = grpc::CreateCustomChannel(
+                           target_str, grpc::InsecureChannelCredentials(),cargs);
+
+                  stub_ = iv::ivgrpc::NewStub(channel);
+              }
+              std::this_thread::sleep_for(std::chrono::milliseconds(900));
+
+            }
+
+        }
+
+    }
+}
+
+void grpcclientthread::sharequerymsg(const iv::ModuleMsg *pxmsg)
+{
+    int i;
+//    std::cout<<"msg is "<<pxmsg->msgname()<<std::endl;
+    int nsize = mvectorquerymsgunit.size();
+    for(i=0;i<nsize;i++)
+    {
+        if(strncmp(pxmsg->msgname().data(),mvectorquerymsgunit[i].mstrmsgname,256) == 0)
+        {
+ //           std::cout<<"msg is "<<pxmsg->msgname()<<" size is: "<<pxmsg->xdata().size()<<std::endl;
+            if(strncmp(pxmsg->msgname().data(),"tracemap",256) == 0)
+            {
+                std::cout<<"trace map size is "<<pxmsg->xdata().size()<<std::endl;
+            }
+
+#ifdef Android_IVSYSMAN
+
+#else
+#ifndef Android
+          iv::modulecomm::ModuleSendMsg(mvectorquerymsgunit[i].mpa,pxmsg->xdata().data(),pxmsg->xdata().size());
+#else
+            gAShow->AndroidSetMsg(pxmsg->msgname().data(),pxmsg->xdata().data(),pxmsg->xdata().size());
+#endif
+#endif
+            break;
+        }
+    }
+}
+
+void grpcclientthread::setdevname(std::string strdevname)
+{
+    mstrdevname = strdevname;
+}
+
+void grpcclientthread::setserverip(std::string strip)
+{
+    mstrserverip = strip;
+}
+
+void grpcclientthread::setserverport(std::string strport)
+{
+    mstrserverport = strport;
+}
+
+void grpcclientthread::setqueryinterval(std::string strinterval)
+{
+    mstrqueryinterval = strinterval;
+}
+

+ 71 - 0
src/ui/ADCIntelligentShow_grpc/proto1804/grpcclientthread.h

@@ -0,0 +1,71 @@
+#ifndef GRPCCLIENTTHREAD_H
+#define GRPCCLIENTTHREAD_H
+
+#include <QThread>
+
+#include <yaml-cpp/yaml.h>
+
+#include <QDateTime>
+
+#include <iostream>
+
+#include <vector>
+
+#include <memory>
+
+#include <QMutex>
+
+#include <thread>
+
+#include "modulecomm.h"
+
+#include "cloud.pb.h"
+
+#include <iostream>
+#include <memory>
+#include <string>
+
+#include <grpcpp/grpcpp.h>
+
+#include "ivgrpc.grpc.pb.h"
+
+#include "rpcmsgunit.h"
+
+using grpc::Channel;
+using grpc::ClientContext;
+using grpc::Status;
+
+class grpcclientthread  : public QThread
+{
+public:
+    grpcclientthread();
+
+private:
+    std::string mstrserverip =  "192.168.1.102";//"123.57.212.138";
+    std::string mstrserverport = "30051";//"9000";
+    std::string mstrqueryinterval = "10";
+    std::string mstrdevname = "PAD";
+    void * mpa;
+    QMutex mMutexMsg;
+    std::thread * guploadthread;
+
+    std::vector<iv::rpcmsgunit> mvectorquerymsgunit;
+
+    std::vector<iv::rpcmsgunit> mvectorctrlmsgunit;
+
+public:
+    void UpdateData(const char * strdata,const unsigned int nSize,const char * strmemname);
+    void startlisten();
+    void dec_yaml(const char * stryamlpath);
+    void addquerymsgunit(std::string strquerymsg,int nbuffsize,int nbuffcount);
+    void addctrlmsgunit(std::string strquerymsg,int nbuffsize,int nbuffcount);
+    void setserverip(std::string strip);
+    void setserverport(std::string strport);
+    void setqueryinterval(std::string strinterval);
+    void setdevname(std::string  strdevname);
+private:
+    void run();
+    void sharequerymsg(const iv::ModuleMsg * pxmsg);
+};
+
+#endif // GRPCCLIENTTHREAD_H