yuchuli пре 3 година
родитељ
комит
357a4ae99f
5 измењених фајлова са 263 додато и 36 уклоњено
  1. 2 0
      deploylib.sh
  2. 17 3
      include/common.pri
  3. 13 32
      include/modulecomm.h
  4. 208 0
      include/modulecommext.h
  5. 23 1
      src/common/modulecomm/modulecomm.pro

+ 2 - 0
deploylib.sh

@@ -31,6 +31,8 @@ fi
 QtPlatformdir=$Qtgccdir/plugins/platforms
 QtLibDir=$Qtgccdir/lib
 
+export LD_LIBRARY_PATH=./thirdpartylib/FastRTPS/lib/libarm64:$LD_LIBRARY_PATH
+
 if [ "$#" -lt 1 ]; then
 	echo "没有输入"
 	echo "$1"

+ 17 - 3
include/common.pri

@@ -1,7 +1,7 @@
 
 unix:system("./ivversion.sh ")
 
-DEFINES += RUNSYSTEMTEST
+unix:DEFINES += RUNSYSTEMTEST
 
 if(contains(DEFINES,RUNSYSTEMTEST)){
 unix:system("./linuxsystemtest.sh ")
@@ -26,8 +26,22 @@ QMAKE_LFLAGS += -no-pie
 
 INCLUDEPATH += $$PWD/../src/include/msgtype
 
-if(contains(DEFINES,USE_PLUS_MODULECOMM)){
-LIBS += -L$$PWD -lfastcdr -lfastrtps
+if(contains(DEFINES,SYSTEM_AGX)){
+DEFINES += USE_FASTRTPS
+LIBS += -L$$PWD/../thirdpartylib/FastRTPS/lib/libarm64
+system("cd ./../thirdpartylib/FastRTPS/lib ; unzip -x -n libarm64.zip ; cd ../../../include ; echo $PWD")
+}
+
+if(contains(DEFINES,SYSTEM_UBUNTU1804)){
+DEFINES += USE_FASTRTPS
+LIBS += -L$$PWD/../thirdpartylib/FastRTPS/lib/libamd64
+system("cd ./../thirdpartylib/FastRTPS/lib ; unzip -x -n libamd64.zip ; cd ../../../include ; echo $PWD")
+}
+
+
+
+if(contains(DEFINES,USE_FASTRTPS)){
+LIBS +=  -lfastcdr -lfastrtps
 }
 
 

+ 13 - 32
include/modulecomm.h

@@ -1,11 +1,15 @@
-#ifndef MODULECOMM_H
+#ifndef MODULECOMM_H
 #define MODULECOMM_H
 
+
 #include <QtCore/qglobal.h>
 #include <QDateTime>
 
 #include <functional>
 
+
+
+
 #if defined(MODULECOMM_LIBRARY)
 #  define MODULECOMMSHARED_EXPORT Q_DECL_EXPORT
 #else
@@ -13,30 +17,9 @@
 #endif
 
 
-#ifndef USE_PLUS_MODULECOMM
 
-//#include <iostream>
-//#include <thread>
 
-//using namespace std::placeholders;
-typedef std::function<void(const char * ,const unsigned int , const unsigned int , QDateTime * ,const char *)> ModuleFun;
-typedef void (* SMCallBack)(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
 
-namespace iv {
-namespace modulecomm {
-void * MODULECOMMSHARED_EXPORT RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount);
-void * MODULECOMMSHARED_EXPORT RegisterRecv(const char * strcommname,SMCallBack pCall);
-void * MODULECOMMSHARED_EXPORT RegisterRecvPlus(const char * strcommname,ModuleFun xFun);
-void MODULECOMMSHARED_EXPORT ModuleSendMsg(void * pHandle,const char * strdata,const unsigned int nDataLen);
-void MODULECOMMSHARED_EXPORT Unregister(void * pHandle);
-void MODULECOMMSHARED_EXPORT PauseComm(void * pHandle);
-void MODULECOMMSHARED_EXPORT ContintuComm(void * pHandle);
-
-}
-
-}
-
-#else
 
 //#include <iostream>
 //#include <thread>
@@ -58,16 +41,19 @@ enum ModuleComm_TYPE
     ModuleComm_SHAREMEM = 0,
     ModuleComm_INTERIOR = 1,
     ModuleComm_FASTRTPS = 2,
-    ModuleComm_FASTRTPS_TCP = 3
+    ModuleComm_FASTRTPS_TCP = 3,
+    ModuleComm_UNDEFINE = 4
 };
 
+void * MODULECOMMSHARED_EXPORT RegisterSend(const char * strcommname);
+
 
 void * MODULECOMMSHARED_EXPORT RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount
-                                            ,ModuleComm_TYPE xmctype = ModuleComm_SHAREMEM,const unsigned short nport = 5100);
+                                            ,ModuleComm_TYPE xmctype = ModuleComm_UNDEFINE,const unsigned short nport = 5100);
 void * MODULECOMMSHARED_EXPORT RegisterRecv(const char * strcommname,SMCallBack pCall,
-                                            ModuleComm_TYPE xmctype = ModuleComm_SHAREMEM,const char * strip = 0,const unsigned short = 5100);
+                                            ModuleComm_TYPE xmctype = ModuleComm_UNDEFINE,const char * strip = 0,const unsigned short = 5100);
 void * MODULECOMMSHARED_EXPORT RegisterRecvPlus(const char * strcommname,ModuleFun xFun,
-                                                ModuleComm_TYPE xmctype = ModuleComm_SHAREMEM,const char * strip = 0,const unsigned short = 5100);
+                                                ModuleComm_TYPE xmctype = ModuleComm_UNDEFINE,const char * strip = 0,const unsigned short = 5100);
 
 void MODULECOMMSHARED_EXPORT ModuleSendMsg(void * pHandle,const char * strdata,const unsigned int nDataLen);
 void MODULECOMMSHARED_EXPORT Unregister(void * pHandle);
@@ -78,9 +64,4 @@ void MODULECOMMSHARED_EXPORT ContintuComm(void * pHandle);
 
 }
 
-
-#endif
-
-
-
-#endif 
+#endif // MODULECOMM_H

+ 208 - 0
include/modulecommext.h

@@ -0,0 +1,208 @@
+#ifndef MODULECOMMEXT_H
+#define MODULECOMMEXT_H
+
+#include <QtCore/qglobal.h>
+#include <QDateTime>
+
+#include <functional>
+
+
+#include "modulecomm.h"
+
+#if defined(MODULECOMMEXT_LIBRARY)
+#  define MODULECOMMEXTSHARED_EXPORT Q_DECL_EXPORT
+#else
+#  define MODULECOMMEXTSHARED_EXPORT Q_DECL_IMPORT
+#endif
+
+
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/port.h>
+#include <google/protobuf/stubs/once.h>
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/wire_format_lite_inl.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/generated_message_reflection.h>
+#include <google/protobuf/reflection_ops.h>
+#include <google/protobuf/wire_format.h>
+
+
+
+#ifndef IV_MODULEEXT_FUN
+
+typedef std::function<void(google::protobuf::Message & xmsg)> ModuleExtFun;
+typedef void (* SMExtCallBack)(google::protobuf::Message & xmsg);
+#define IV_MODULEEXT_FUN
+#endif
+
+namespace iv {
+namespace modulecommext {
+
+
+template<class T>
+class modulecommmsg
+{
+private:
+    T mMessage;
+    void * mphandle = NULL;
+    ModuleExtFun mFun;
+    SMExtCallBack mpCall;
+    bool mbCallPlus = false;
+    int mnType = 0; //0:Not Init  1:Send   2:Recv
+    void UpdateMsg(const char *strdata,
+                                         const unsigned int nSize, const unsigned int index, const QDateTime *dt,
+                                         const char *strmemname);
+public:
+    modulecommmsg();
+    ~modulecommmsg();
+
+    void RegisterSend(const char * strcommname);
+
+    void RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount
+                                                ,iv::modulecomm::ModuleComm_TYPE xmctype = iv::modulecomm::ModuleComm_UNDEFINE,const unsigned short nport = 5100);
+    void RegisterRecv(const char * strcommname,SMExtCallBack pCall,
+                                                iv::modulecomm::ModuleComm_TYPE xmctype =iv::modulecomm:: ModuleComm_UNDEFINE,const char * strip = 0,const unsigned short = 5100);
+    void RegisterRecvPlus(const char * strcommname,ModuleExtFun xFun,
+                                                    iv::modulecomm::ModuleComm_TYPE xmctype = iv::modulecomm::ModuleComm_UNDEFINE,const char * strip = 0,const unsigned short = 5100);
+
+    void ModuleSendMsg(google::protobuf::Message & xmsg);
+    void Unregister();
+    void PauseComm();
+    void ContintuComm();
+};
+
+template<class T>
+modulecommmsg<T>::modulecommmsg()
+{
+
+}
+
+template<class T>
+modulecommmsg<T>::~modulecommmsg()
+{
+    if(mphandle != NULL)
+    {
+        Unregister();
+    }
+}
+
+template<class T>
+void modulecommmsg<T>::UpdateMsg(const char *strdata,
+                                 const unsigned int nSize, const unsigned int index, const QDateTime *dt,
+                                 const char *strmemname)
+{
+    (void)&index;
+    (void)dt;
+    (void)strmemname;
+    T xmsg;
+    google::protobuf::Message * pmsg = (google::protobuf::Message *)&xmsg;
+    bool bParse = pmsg->ParseFromArray(strdata,nSize);
+    if(bParse == false)
+    {
+        qDebug("modulecommext<T>::UpdateMsg Parse Fail.");
+        return;
+    }
+    if(mbCallPlus)
+        mFun(*pmsg);
+    else
+        (*mpCall)(*pmsg);
+
+}
+
+
+
+template<class T>
+void modulecommmsg<T>::RegisterSend(const char * strcommname)
+{
+    mphandle = iv::modulecomm::RegisterSend(strcommname);
+    mnType = 1;
+}
+
+template<class T>
+void modulecommmsg<T>::RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount
+                                            ,iv::modulecomm::ModuleComm_TYPE xmctype ,const unsigned short nport)
+{
+    mphandle = iv::modulecomm::RegisterSend(strcommname,nBufSize,nMsgBufCount,xmctype,nport);
+    mnType = 1;
+}
+
+template<class T>
+void modulecommmsg<T>::RegisterRecv(const char * strcommname,SMExtCallBack pCall,
+                                            iv::modulecomm::ModuleComm_TYPE xmctype,const char * strip,const unsigned short nport)
+{
+    mpCall = pCall;
+    mbCallPlus = false;
+    ModuleFun funext = std::bind(&modulecommmsg::UpdateMsg,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
+    mphandle = iv::modulecomm::RegisterRecvPlus(strcommname,funext,xmctype,strip,nport);
+    mnType = 2;
+}
+
+template<class T>
+void modulecommmsg<T>::RegisterRecvPlus(const char * strcommname,ModuleExtFun xFun,
+                                                iv::modulecomm::ModuleComm_TYPE xmctype ,const char * strip ,const unsigned short nport)
+{
+    mFun = xFun;
+    mbCallPlus = true;
+    ModuleFun funext = std::bind(&modulecommmsg::UpdateMsg,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
+    mphandle = iv::modulecomm::RegisterRecvPlus(strcommname,funext,xmctype,strip,nport);
+    mnType = 2;
+}
+
+template<class T>
+void modulecommmsg<T>::ModuleSendMsg(google::protobuf::Message & xmsg)
+{
+    if((mnType != 1)||(mphandle == NULL))
+    {
+        qDebug("This Handle is not send. type : %d ",mnType);
+        return;
+    }
+    int ndatasize = xmsg.ByteSize();
+    std::shared_ptr<char> str_ptr= std::shared_ptr<char>(new char[ndatasize]);
+    bool bSer = xmsg.SerializeToArray(str_ptr.get(),ndatasize);
+    if(bSer == false)
+    {
+        qDebug("modulecommext<T>::ModuleSendMsg serialize fail.");
+        return;
+    }
+    iv::modulecomm::ModuleSendMsg(mphandle,str_ptr.get(),ndatasize);
+
+}
+
+template<class T>
+void modulecommmsg<T>::Unregister()
+{
+    if((mnType == 0)||(mphandle == NULL))
+    {
+        return;
+    }
+    iv::modulecomm::Unregister(mphandle);
+    mphandle = NULL;
+}
+
+template<class T>
+void modulecommmsg<T>::PauseComm()
+{
+    if((mnType == 0)||(mphandle == NULL))
+    {
+        qDebug("modulecommext<T>::PauseComm handle not init.");
+        return;
+    }
+    iv::modulecomm::PauseComm(mphandle);
+}
+
+template<class T>
+void modulecommmsg<T>::ContintuComm()
+{
+    if((mnType == 0)||(mphandle == NULL))
+    {
+        qDebug("modulecommext<T>::PauseComm handle not init.");
+        return;
+    }
+    iv::modulecomm::ContintuComm(mphandle);
+}
+
+
+
+}
+}
+#endif // MODULECOMMEXT_H

+ 23 - 1
src/common/modulecomm/modulecomm.pro

@@ -6,7 +6,15 @@ QT += xml
 TEMPLATE = lib
 DEFINES += MODULECOMM_LIBRARY
 
-unix:DEFINES += USE_FASTRTPS
+unix:DEFINES += RUNSYSTEMTEST
+
+if(contains(DEFINES,RUNSYSTEMTEST)){
+unix:system("./../../../include/linuxsystemtest.sh ")
+}
+
+unix:include(./../../../include/systemdef.pri)
+win32: DEFINES += SYSTEM_WIN
+
 DEFINES += USEDBUS
 
 CONFIG += c++11
@@ -50,6 +58,20 @@ unix {
     error( "Couldn't find the modulecomm_inter.pri file!" )
 }
 
+if(contains(DEFINES,SYSTEM_AGX)){
+DEFINES += USE_FASTRTPS
+LIBS += -L$$PWD/../../../thirdpartylib/FastRTPS/lib/libarm64
+system("cd ./../../../thirdpartylib/FastRTPS/lib ; unzip -x -n libarm64.zip ; cd ../../../include ; echo $PWD")
+}
+
+if(contains(DEFINES,SYSTEM_UBUNTU1804)){
+DEFINES += USE_FASTRTPS
+LIBS += -L$$PWD/../../../thirdpartylib/FastRTPS/lib/libamd64
+system("cd ./../../../thirdpartylib/FastRTPS/lib ; unzip -x -n libamd64.zip ; cd ../../../include ; echo $PWD")
+}
+
+
+
 if(contains(DEFINES,USE_FASTRTPS)){
 !include(./fastrtps/modulecomm_fastrtps.pri ) {
     error( "Couldn't find the modulecomm_fastrtps.pri file!" )