Browse Source

change modulecomm for get process pid.

yuchuli 3 years ago
parent
commit
c8d4958051

+ 2 - 2
src/common/modulecomm/fastrtps/TopicsPublisher.cxx

@@ -187,7 +187,7 @@ void TopicsPublisher::senddata(const char *str, int nsize)
 
 
     static int ncount = 1;
-    std::cout<<"send data."<<std::endl;
+ //   std::cout<<"send data."<<std::endl;
 //    while(m_listener.n_matched == 0)
     TopicSample::SomeBytes x;
     x.resize(nsize);
@@ -204,7 +204,7 @@ void TopicsPublisher::senddata(const char *str, int nsize)
 
     int ndatasize = TopicSample::Message::getCdrSerializedSize(st);
 
-    std::cout<<"size is "<<ndatasize<<std::endl;
+//    std::cout<<"size is "<<ndatasize<<std::endl;
 
 
     mp_publisher->write(&st);

+ 5 - 5
src/common/modulecomm/fastrtps/TopicsSubscriber.cxx

@@ -169,7 +169,7 @@ void TopicsSubscriber::SubListener::onNewDataMessage(Subscriber* sub)
 
     static int nmaxlatancy = 0;
 
-    std::cout<<"new msg"<<std::endl;
+//    std::cout<<"new msg"<<std::endl;
 
 
 //    char * strbuf = new char[1000000];
@@ -193,7 +193,7 @@ void TopicsSubscriber::SubListener::onNewDataMessage(Subscriber* sub)
 //    return;
 
 //    sub->get_first_untaken_info(&m_info);
-    std::cout<<"count is "<<sub->getUnreadCount()<<std::endl;
+//    std::cout<<"count is "<<sub->getUnreadCount()<<std::endl;
 
     if(sub->takeNextData(&st, &m_info))
     {
@@ -202,12 +202,12 @@ void TopicsSubscriber::SubListener::onNewDataMessage(Subscriber* sub)
             // Print your structure data here.
             ++n_msg;
             ncount++;
-            std::cout << "Sample received, count=" << st.counter() <<" total: "<<ncount<<std::endl;
+//            std::cout << "Sample received, count=" << st.counter() <<" total: "<<ncount<<std::endl;
             qint64 timex = QDateTime::currentMSecsSinceEpoch();
             int nlatancy = (timex - st.sendtime());
             if(nlatancy>nmaxlatancy)nmaxlatancy = nlatancy;
-            std::cout<<"  latency is "<<nlatancy<<" max: "<<nmaxlatancy<<std::endl;
-            std::cout<<" size is "<<st.xdata().size()<<std::endl;
+//            std::cout<<"  latency is "<<nlatancy<<" max: "<<nmaxlatancy<<std::endl;
+//            std::cout<<" size is "<<st.xdata().size()<<std::endl;
             QDateTime dt = QDateTime::fromMSecsSinceEpoch(st.sendtime());
             if(mbSetFun) mFun((char *)(st.xdata().data()),st.xdata().size(),st.counter(),&dt,st.msgname().data());
 

+ 6 - 0
src/common/modulecomm/fastrtps/modulecomm_fastrtps_shm.cpp

@@ -3,6 +3,8 @@
 
 #include "modulecomm_impl_shm.h"
 
+
+
 namespace  iv {
 
 
@@ -15,10 +17,14 @@ void modulecomm_fastrtps_shm::RegisterSend(const char *strcommname, const unsign
 {
     modulecomm_impl_shm * pif = new modulecomm_impl_shm(strcommname,modulecomm_impl_shm::type_send);
 
+
+
 //    procsm_if * pif = new procsm_if(strcommname,nBufSize,nMsgBufCount,procsm::ModeWrite);
     mpif = pif;
 }
 
+
+
 void modulecomm_fastrtps_shm::RegisterRecv(const char *strcommname, SMCallBack pCall)
 {
     modulecomm_impl_shm * pif = new modulecomm_impl_shm(strcommname,modulecomm_impl_shm::type_recv);

+ 14 - 1
src/common/modulecomm/fastrtps/modulecomm_fastrtps_shm.h

@@ -3,12 +3,20 @@
 
 #include "modulecomm_impl_shm.h"
 
+
+#include "modulecomm_base.h"
+
+
+
+
+
 namespace iv {
 
 
 
-class modulecomm_fastrtps_shm
+class modulecomm_fastrtps_shm : public modulecomm_base
 {
+
 public:
     modulecomm_fastrtps_shm();
 
@@ -22,6 +30,11 @@ public:
 
 private:
     void * mpif;
+
+
+
+
+
 };
 
 }

+ 3 - 1
src/common/modulecomm/fastrtps/modulecomm_fastrtps_tcp.h

@@ -1,11 +1,13 @@
 #ifndef MODULECOMM_FASTRTPS_TCP_H
 #define MODULECOMM_FASTRTPS_TCP_H
 
+#include "modulecomm_base.h"
+
 #include "modulecomm_impl_tcp.h"
 namespace  iv {
 
 
-class modulecomm_fastrtps_tcp
+class modulecomm_fastrtps_tcp: public modulecomm_base
 {
 public:
     modulecomm_fastrtps_tcp();

+ 37 - 0
src/common/modulecomm/fastrtps/modulecomm_impl_shm.cpp

@@ -8,6 +8,10 @@
 #include <QMutex>
 #include <QFile>
 
+#ifdef Q_OS_LINUX
+#include <unistd.h>
+#endif
+
 namespace iv {
 namespace modulecomm {
 static QMutex gmodulecomm_dds_Mutex;
@@ -90,6 +94,25 @@ modulecomm_impl_shm::modulecomm_impl_shm(const char * strcommname,int ntype )
     std::cout<<"count is "<<iv::modulecomm::createcount<<std::endl;
     iv::modulecomm::gmodulecomm_dds_Mutex.unlock();
 
+    strncpy(mmodulemsg_type.mstrmsgidname,strcommname,255);
+    mmodulemsg_type.mnBufSize = 0;
+    mmodulemsg_type.mnMsgBufCount = 0;
+    strncpy(mmodulemsg_type.mstrmsgname,strcommname,255);
+#ifdef Q_OS_LINUX
+    mmodulemsg_type.mnPID = getpid();
+#endif
+
+#ifdef USEDBUS
+            mmsgres = QDBusMessage::createSignal("/catarc/adc",  "adciv.interface", "modulemsgres");
+            mmsgres<<1;
+
+            bool bconnect = QDBusConnection::sessionBus().connect(QString(),"/catarc/adc",  "adciv.interface", "modulemsgquery",this,SLOT(onQuery()));
+            if(bconnect == false)
+            {
+                std::cout<<"procsm_if_readthread::procsm_if_readthread bconect is false"<<std::endl;
+            }
+#endif
+
 }
 
 int modulecomm_impl_shm::listenmsg(ModuleFun xFun)
@@ -128,6 +151,20 @@ int modulecomm_impl_shm::listenmsg(SMCallBack pCall)
     return 0;
 }
 
+#ifdef USEDBUS
+    void modulecomm_impl_shm::onQuery()
+    {
+        QByteArray ba;
+        ba.append((char *)&mmodulemsg_type,sizeof(iv::modulemsg_type));
+
+        QList<QVariant> x;
+        x<<ba;
+        mmsgres.setArguments(x);
+        QDBusConnection::sessionBus().send(mmsgres);
+    }
+
+#endif
+
 void modulecomm_impl_shm::writemsg(const char *str, int nlen)
 {
     if(mnType == type_recv)

+ 23 - 1
src/common/modulecomm/fastrtps/modulecomm_impl_shm.h

@@ -3,15 +3,24 @@
 
 #include <QDateTime>
 
+#include "ivmodulemsg_type.h"
+
 #include "TopicsPublisher.h"
 #include "TopicsSubscriber.h"
+#include <QObject>
+
+#ifdef USEDBUS
+#include <QtDBus/QDBusMessage>
+#include <QtDBus/QDBusConnection>
 
+#endif
 
 typedef void (* SMCallBack)(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
 
 
-class modulecomm_impl_shm
+class modulecomm_impl_shm : public QObject
 {
+    Q_OBJECT
 public:
     const static int type_send = 1;
     const static int type_recv = 2;
@@ -36,6 +45,19 @@ private:
 
     bool mbFunPlus = false;
 
+    iv::modulemsg_type mmodulemsg_type;
+
+#ifdef USEDBUS
+private slots:
+    void onQuery();
+
+#endif
+private:
+#ifdef USEDBUS
+    QDBusMessage mmsgres;  //Response Message Query;
+
+#endif
+
 };
 
 #endif // MODULECOMM_IMPL_H

+ 2 - 2
src/common/modulecomm/inter/intercomm.cpp

@@ -18,7 +18,7 @@ struct InterListenUnit
 struct interunit
 {
     char strintername[256];
-    char * strdatabuf;
+    char * strdatabuf = NULL;
     int nbufsize = 0;
     int nPacCount;
     QMutex mMutexUnit;
@@ -73,7 +73,7 @@ intercomm::intercomm(const char * strsmname,const unsigned int nBufSize,const un
         else
         {
             p->mMutexUnit.lock();
-            delete p->strdatabuf;
+            if(p->strdatabuf != NULL) delete p->strdatabuf;
             p->strdatabuf = new char[sizeof(procinter_info)+nMaxPacCount*sizeof(procinter_head) + nBufSize];
             p->nPacCount = nMaxPacCount;
             p->nbufsize = nBufSize;

+ 1 - 0
src/common/modulecomm/ivmodulemsg_type.h

@@ -8,6 +8,7 @@ struct modulemsg_type
     char mstrmsgname[256];
     int mnBufSize;
     int mnMsgBufCount;
+    int mnPID;
 };
 
 }

+ 7 - 0
src/common/modulecomm/shm/procsm.cpp

@@ -5,6 +5,9 @@
 #include <algorithm>
 #include "procsm.h"
 
+#ifdef Q_OS_LINUX
+#include <unistd.h>
+#endif
 
 class AttachThread : public QThread
 {
@@ -72,6 +75,10 @@ procsm::procsm(const char * strsmname,const unsigned int nBufSize,const unsigned
         mmodulemsg_type.mnBufSize = nBufSize;
         mmodulemsg_type.mnMsgBufCount = nMaxPacCount;
         strncpy(mmodulemsg_type.mstrmsgname,strasmname,255);
+#ifdef Q_OS_LINUX
+        mmodulemsg_type.mnPID = getpid();
+#endif
+
 #ifdef USEDBUS
         mmsg = QDBusMessage::createSignal("/catarc/adc",  "adc.adciv.modulecomm", strsmname);
         mmsg<<1;

+ 0 - 73
src/test/testmodulecommconsole/.gitignore

@@ -1,73 +0,0 @@
-# This file is used to ignore files which are generated
-# ----------------------------------------------------------------------------
-
-*~
-*.autosave
-*.a
-*.core
-*.moc
-*.o
-*.obj
-*.orig
-*.rej
-*.so
-*.so.*
-*_pch.h.cpp
-*_resource.rc
-*.qm
-.#*
-*.*#
-core
-!core/
-tags
-.DS_Store
-.directory
-*.debug
-Makefile*
-*.prl
-*.app
-moc_*.cpp
-ui_*.h
-qrc_*.cpp
-Thumbs.db
-*.res
-*.rc
-/.qmake.cache
-/.qmake.stash
-
-# qtcreator generated files
-*.pro.user*
-
-# xemacs temporary files
-*.flc
-
-# Vim temporary files
-.*.swp
-
-# Visual Studio generated files
-*.ib_pdb_index
-*.idb
-*.ilk
-*.pdb
-*.sln
-*.suo
-*.vcproj
-*vcproj.*.*.user
-*.ncb
-*.sdf
-*.opensdf
-*.vcxproj
-*vcxproj.*
-
-# MinGW generated files
-*.Debug
-*.Release
-
-# Python byte code
-*.pyc
-
-# Binaries
-# --------
-*.dll
-*.exe
-

+ 0 - 8
src/test/testmodulecommconsole/main.cpp

@@ -1,8 +0,0 @@
-#include <QCoreApplication>
-
-int main(int argc, char *argv[])
-{
-    QCoreApplication a(argc, argv);
-
-    return a.exec();
-}

+ 0 - 6
src/test/testmodulecommconsole/test1.cpp

@@ -1,6 +0,0 @@
-#include "test1.h"
-
-test1::test1()
-{
-
-}

+ 0 - 11
src/test/testmodulecommconsole/test1.h

@@ -1,11 +0,0 @@
-#ifndef TEST1_H
-#define TEST1_H
-
-
-class test1
-{
-public:
-    test1();
-};
-
-#endif // TEST1_H

+ 0 - 17
src/test/testmodulecommconsole/testmodulecommconsole.pro

@@ -1,17 +0,0 @@
-QT -= gui
-
-CONFIG += c++11 console
-CONFIG -= app_bundle
-
-# The following define makes your compiler emit warnings if you use
-# any feature of Qt which as been marked 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

+ 1 - 0
src/test/testmodulecommextsend/testfastrtpssend.cpp

@@ -15,6 +15,7 @@ void testfastrtpssend::run()
         xmsg.set_b(2);
         xmsg.set_time(QDateTime::currentMSecsSinceEpoch());
         mpa->ModuleSendMsg(xmsg);
+        qDebug("send msg");
         msleep(1000);
     }
 }

+ 1 - 0
src/test/testmodulecommextsend/testfastrtpstcpsend.cpp

@@ -15,6 +15,7 @@ void testfastrtpstcpsend::run()
         xmsg.set_b(2);
         xmsg.set_time(QDateTime::currentMSecsSinceEpoch());
         mpa->ModuleSendMsg(xmsg);
+
         msleep(1000);
     }
 }

+ 12 - 1
src/tool/view_message/dialogviewmessage.cpp

@@ -6,6 +6,8 @@
 #include "google/protobuf/io/zero_copy_stream_impl.h"
 #include "google/protobuf/text_format.h"
 
+
+
 DialogViewMessage::DialogViewMessage(std::string strmsgname,QWidget *parent) :
     QDialog(parent),
     ui(new Ui::DialogViewMessage)
@@ -15,6 +17,7 @@ DialogViewMessage::DialogViewMessage(std::string strmsgname,QWidget *parent) :
     InitMsgType();
     mstrmsgname = strmsgname;
 
+
 //    mpa = new iv::modulecommext::modulecommmsg<iv::testmodulecommext>();
 
 //    ModuleExtFun funext = std::bind(&DialogViewMessage::UpdateMsg,this,std::placeholders::_1);
@@ -33,6 +36,7 @@ DialogViewMessage::DialogViewMessage(std::string strmsgname,QWidget *parent) :
 
     connect(this,SIGNAL(msgupdate()),this,SLOT(UpdatePE()));
     connect(this,SIGNAL(updatecb()),this,SLOT(UpdateCombo()));
+    connect(this,SIGNAL(countupdate()),this,SLOT(UpdateLE()));
 
     setWindowTitle(strmsgname.data());
 }
@@ -69,6 +73,8 @@ void DialogViewMessage::UpdateMsg(google::protobuf::Message &xmsg)
 
 void DialogViewMessage::UpdateRawMsg(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
 {
+    mnCount++;
+    emit countupdate();
     char * strxdata = new char[nSize];
     memcpy(strxdata,strdata,nSize);
     if(mvectorprob.size() == 0)
@@ -98,7 +104,7 @@ void DialogViewMessage::UpdateRawMsg(const char *strdata, const unsigned int nSi
         std::shared_ptr<google::protobuf::Message> msg_ptr = GetProtoMessage(strxdata,nSize,mvectorprob[indexprob]);
         if(msg_ptr != NULL)
         {
-            qDebug("parse ok.");
+//            qDebug("parse ok.");
             using google::protobuf::TextFormat;
             using google::protobuf::io::FileOutputStream;
             using google::protobuf::io::ZeroCopyOutputStream;
@@ -164,3 +170,8 @@ void DialogViewMessage::on_comboBox_currentIndexChanged(int index)
 {
     if(index>=0)mcbindex = index;
 }
+
+void DialogViewMessage::UpdateLE()
+{
+    ui->lineEdit_count->setText(QString::number(mnCount));
+}

+ 8 - 0
src/tool/view_message/dialogviewmessage.h

@@ -14,6 +14,8 @@ namespace Ui {
 class DialogViewMessage;
 }
 
+
+
 class DialogViewMessage : public QDialog
 {
     Q_OBJECT
@@ -36,10 +38,14 @@ private slots:
 
     void on_comboBox_currentIndexChanged(int index);
 
+    void UpdateLE();
+
 signals:
     void ViewMsgClose(void * handle);
     void msgupdate();
     void updatecb();
+    void countupdate();
+
 
 private:
     Ui::DialogViewMessage *ui;
@@ -65,6 +71,8 @@ private:
     std::vector<std::string> mvectorcbname;
     int mcbindex = 0;
 
+    int mnCount = 0;
+
     void UpdateMsg(::google::protobuf::Message & xmsg);
     void UpdateRawMsg(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname);
 

+ 10 - 0
src/tool/view_message/dialogviewmessage.ui

@@ -59,6 +59,16 @@
     <string>消息类型:</string>
    </property>
   </widget>
+  <widget class="QLineEdit" name="lineEdit_count">
+   <property name="geometry">
+    <rect>
+     <x>190</x>
+     <y>6</y>
+     <width>111</width>
+     <height>31</height>
+    </rect>
+   </property>
+  </widget>
  </widget>
  <resources/>
  <connections/>

+ 1 - 0
src/tool/view_message/main.cpp

@@ -2,6 +2,7 @@
 
 #include <QApplication>
 
+
 int main(int argc, char *argv[])
 {
     QApplication a(argc, argv);

+ 17 - 0
src/tool/view_message/mainwindow.cpp

@@ -38,6 +38,8 @@ void MainWindow::on_pushButton_refresh_clicked()
 {
     mSendQueryTime = QDateTime::currentMSecsSinceEpoch();
     mvectormsgname_temp.clear();
+    mvectormsgtype_temp.clear();
+    mvectormsgpid_temp.clear();
 
    QDBusConnection::sessionBus().send(mmsg);
 
@@ -84,7 +86,9 @@ void MainWindow::onQuery(QByteArray ba)
     memcpy((char *)&xmodulemsg,ba.data(),sizeof(iv::modulemsg_type));
 
     std::string strmsgname = xmodulemsg.mstrmsgidname;
+    mvectormsgtype_temp.push_back(xmodulemsg);
     mvectormsgname_temp.push_back(strmsgname);
+    mvectormsgpid_temp.push_back(xmodulemsg.mnPID);
     qDebug("id name: %s share name: %s bufsize:%d bufcount:%d",
            xmodulemsg.mstrmsgidname,xmodulemsg.mstrmsgname,
            xmodulemsg.mnBufSize,xmodulemsg.mnMsgBufCount);
@@ -96,6 +100,8 @@ void MainWindow::onTimer()
     ui->comboBox_message->clear();
     ui->pushButton_refresh->setEnabled(true);
     mvectormsg = mvectormsgname_temp;
+    mvectormsgpid = mvectormsgpid_temp;
+    mvectormsgtype = mvectormsgtype_temp;
 
 
     unsigned int i;
@@ -112,3 +118,14 @@ void MainWindow::onViewWindowClose(void *phandle)
     DialogViewMessage * pdlg = (DialogViewMessage * )phandle;
     delete pdlg;
 }
+
+void MainWindow::on_comboBox_message_currentIndexChanged(int index)
+{
+    if(index>=mvectormsgtype.size())return;
+    if(index<0)return;
+    iv::modulemsg_type xmoduletype = mvectormsgtype[index];
+    ui->lineEdit_realmem->setText(xmoduletype.mstrmsgname);
+    ui->lineEdit_bufcount->setText(QString::number(xmoduletype.mnMsgBufCount));
+    ui->lineEdit_bufsize->setText(QString::number(xmoduletype.mnBufSize));
+    ui->lineEdit_PID->setText(QString::number(xmoduletype.mnPID));
+}

+ 8 - 0
src/tool/view_message/mainwindow.h

@@ -40,13 +40,21 @@ private slots:
 
     void onViewWindowClose(void * phandle);
 
+    void on_comboBox_message_currentIndexChanged(int index);
+
 private:
     Ui::MainWindow *ui;
 
     qint64 mSendQueryTime;
 
     std::vector<std::string> mvectormsgname_temp;
+    std::vector<int> mvectormsgpid_temp;
     std::vector<std::string> mvectormsg;
+    std::vector<int> mvectormsgpid;
+
+    std::vector<iv::modulemsg_type> mvectormsgtype_temp;
+    std::vector<iv::modulemsg_type> mvectormsgtype;
+
 
     QDBusMessage mmsg;
 

+ 98 - 6
src/tool/view_message/mainwindow.ui

@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>351</width>
-    <height>335</height>
+    <width>357</width>
+    <height>504</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -41,7 +41,7 @@
     <property name="geometry">
      <rect>
       <x>20</x>
-      <y>190</y>
+      <y>406</y>
       <width>151</width>
       <height>41</height>
      </rect>
@@ -54,7 +54,7 @@
     <property name="geometry">
      <rect>
       <x>200</x>
-      <y>190</y>
+      <y>406</y>
       <width>131</width>
       <height>41</height>
      </rect>
@@ -63,14 +63,106 @@
      <string>手动增加</string>
     </property>
    </widget>
+   <widget class="QLabel" name="label">
+    <property name="geometry">
+     <rect>
+      <x>30</x>
+      <y>170</y>
+      <width>71</width>
+      <height>41</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Real Mem</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_realmem">
+    <property name="geometry">
+     <rect>
+      <x>130</x>
+      <y>170</y>
+      <width>201</width>
+      <height>41</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_bufsize">
+    <property name="geometry">
+     <rect>
+      <x>130</x>
+      <y>220</y>
+      <width>201</width>
+      <height>41</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_2">
+    <property name="geometry">
+     <rect>
+      <x>30</x>
+      <y>220</y>
+      <width>71</width>
+      <height>41</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>BufSize</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_bufcount">
+    <property name="geometry">
+     <rect>
+      <x>130</x>
+      <y>270</y>
+      <width>201</width>
+      <height>41</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_3">
+    <property name="geometry">
+     <rect>
+      <x>30</x>
+      <y>270</y>
+      <width>71</width>
+      <height>41</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>BufCount</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_PID">
+    <property name="geometry">
+     <rect>
+      <x>130</x>
+      <y>320</y>
+      <width>201</width>
+      <height>41</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_4">
+    <property name="geometry">
+     <rect>
+      <x>30</x>
+      <y>320</y>
+      <width>71</width>
+      <height>41</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>PID</string>
+    </property>
+   </widget>
   </widget>
   <widget class="QMenuBar" name="menubar">
    <property name="geometry">
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>351</width>
-     <height>28</height>
+     <width>357</width>
+     <height>22</height>
     </rect>
    </property>
   </widget>