Răsfoiți Sursa

change src1/common/modulecomm.

yuchuli 3 ani în urmă
părinte
comite
aec95eea50
37 a modificat fișierele cu 3792 adăugiri și 9 ștergeri
  1. 2 0
      include/common.pri
  2. 33 7
      include/modulecomm.h
  3. 323 0
      src1/common/modulecomm/fastrtps/Topics.cxx
  4. 253 0
      src1/common/modulecomm/fastrtps/Topics.h
  5. 13 0
      src1/common/modulecomm/fastrtps/Topics.idl
  6. 138 0
      src1/common/modulecomm/fastrtps/TopicsPubSubTypes.cxx
  7. 61 0
      src1/common/modulecomm/fastrtps/TopicsPubSubTypes.h
  8. 215 0
      src1/common/modulecomm/fastrtps/TopicsPublisher.cxx
  9. 56 0
      src1/common/modulecomm/fastrtps/TopicsPublisher.h
  10. 228 0
      src1/common/modulecomm/fastrtps/TopicsSubscriber.cxx
  11. 72 0
      src1/common/modulecomm/fastrtps/TopicsSubscriber.h
  12. 19 0
      src1/common/modulecomm/fastrtps/modulecomm_fastrtps.pri
  13. 61 0
      src1/common/modulecomm/fastrtps/modulecomm_fastrtps_shm.cpp
  14. 29 0
      src1/common/modulecomm/fastrtps/modulecomm_fastrtps_shm.h
  15. 61 0
      src1/common/modulecomm/fastrtps/modulecomm_fastrtps_tcp.cpp
  16. 26 0
      src1/common/modulecomm/fastrtps/modulecomm_fastrtps_tcp.h
  17. 140 0
      src1/common/modulecomm/fastrtps/modulecomm_impl_shm.cpp
  18. 41 0
      src1/common/modulecomm/fastrtps/modulecomm_impl_shm.h
  19. 140 0
      src1/common/modulecomm/fastrtps/modulecomm_impl_tcp.cpp
  20. 41 0
      src1/common/modulecomm/fastrtps/modulecomm_impl_tcp.h
  21. 480 0
      src1/common/modulecomm/inter/intercomm.cpp
  22. 109 0
      src1/common/modulecomm/inter/intercomm.h
  23. 60 0
      src1/common/modulecomm/inter/modulecomm_inter.cpp
  24. 30 0
      src1/common/modulecomm/inter/modulecomm_inter.h
  25. 7 0
      src1/common/modulecomm/inter/modulecomm_inter.pri
  26. 17 2
      src1/common/modulecomm/modulecomm.pro
  27. 11 0
      src1/common/modulecomm/modulecomm_base.cpp
  28. 33 0
      src1/common/modulecomm/modulecomm_base.h
  29. 54 0
      src1/common/modulecomm/shm/b/modulecomm_shm.cpp
  30. 42 0
      src1/common/modulecomm/shm/b/modulecomm_shm.h
  31. 61 0
      src1/common/modulecomm/shm/modulecomm_shm.cpp
  32. 28 0
      src1/common/modulecomm/shm/modulecomm_shm.h
  33. 9 0
      src1/common/modulecomm/shm/modulecomm_shm.pri
  34. 378 0
      src1/common/modulecomm/shm/procsm.cpp
  35. 112 0
      src1/common/modulecomm/shm/procsm.h
  36. 310 0
      src1/common/modulecomm/shm/procsm_if.cpp
  37. 99 0
      src1/common/modulecomm/shm/procsm_if.h

+ 2 - 0
include/common.pri

@@ -3,6 +3,8 @@ INCLUDEPATH += $$PWD/../include/
 LIBS += -L$$PWD/../bin/ -lxmlparam -lmodulecomm  -livlog -livfault -livexit -livbacktrace
 
 
+#LIBS += -L$$PWD/../bin/ -lmodulecomm_shm -lmodulecomm_fastrtps -lmodulecomm_fastrtps_tcp -lmodulecomm_inter
+
 unix:LIBS += -lboost_system  -lbacktrace -ldl
 
 QMAKE_CXXFLAGS +=  -g

+ 33 - 7
include/modulecomm.h

@@ -1,11 +1,18 @@
-#ifndef MODULECOMM_H
+#ifndef MODULECOMM_H
 #define MODULECOMM_H
 
+
 #include <QtCore/qglobal.h>
 #include <QDateTime>
 
 #include <functional>
 
+
+#include "modulecomm_shm.h"
+#include "modulecomm_fastrtps.h"
+#include "modulecomm_inter.h"
+#include "modulecomm_fastrtps_tcp.h"
+
 #if defined(MODULECOMM_LIBRARY)
 #  define MODULECOMMSHARED_EXPORT Q_DECL_EXPORT
 #else
@@ -14,18 +21,39 @@
 
 
 
+
+
+
 //#include <iostream>
 //#include <thread>
 
 //using namespace std::placeholders;
+
+#ifndef IV_MODULE_FUN
+
 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);
+#define IV_MODULE_FUN
+#endif
 
 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);
+
+enum ModuleComm_TYPE
+{
+    ModuleComm_SHAREMEM = 0,
+    ModuleComm_INTERIOR = 1,
+    ModuleComm_FASTRTPS = 2,
+    ModuleComm_FASTRTPS_TCP = 3
+};
+
+
+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);
+void * MODULECOMMSHARED_EXPORT RegisterRecv(const char * strcommname,SMCallBack pCall,
+                                            ModuleComm_TYPE xmctype = ModuleComm_SHAREMEM,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);
 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);
@@ -35,6 +63,4 @@ void MODULECOMMSHARED_EXPORT ContintuComm(void * pHandle);
 
 }
 
-
-
-#endif 
+#endif // MODULECOMM_H

+ 323 - 0
src1/common/modulecomm/fastrtps/Topics.cxx

@@ -0,0 +1,323 @@
+// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/*!
+ * @file Topics.cpp
+ * This source file contains the definition of the described types in the IDL file.
+ *
+ * This file was generated by the tool gen.
+ */
+
+#ifdef _WIN32
+// Remove linker warning LNK4221 on Visual Studio
+namespace { char dummy; }
+#endif
+
+#include "Topics.h"
+#include <fastcdr/Cdr.h>
+
+#include <fastcdr/exceptions/BadParamException.h>
+using namespace eprosima::fastcdr::exception;
+
+#include <utility>
+
+
+TopicSample::Message::Message()
+{
+    // m_msgname com.eprosima.idl.parser.typecode.StringTypeCode@76329302
+    m_msgname ="";
+    // m_counter com.eprosima.idl.parser.typecode.PrimitiveTypeCode@5e25a92e
+    m_counter = 0;
+    // m_sendtime com.eprosima.idl.parser.typecode.PrimitiveTypeCode@4df828d7
+    m_sendtime = 0;
+    // m_xdata com.eprosima.idl.parser.typecode.AliasTypeCode@b59d31
+
+    m_xdata.push_back(1);
+    m_xdata.push_back(2);
+
+
+}
+
+TopicSample::Message::~Message()
+{
+
+
+
+
+}
+
+TopicSample::Message::Message(const Message &x)
+{
+    m_msgname = x.m_msgname;
+    m_counter = x.m_counter;
+    m_sendtime = x.m_sendtime;
+    m_xdata = x.m_xdata;
+}
+
+TopicSample::Message::Message(Message &&x)
+{
+    m_msgname = std::move(x.m_msgname);
+    m_counter = x.m_counter;
+    m_sendtime = x.m_sendtime;
+    m_xdata = std::move(x.m_xdata);
+}
+
+TopicSample::Message& TopicSample::Message::operator=(const Message &x)
+{
+
+    m_msgname = x.m_msgname;
+    m_counter = x.m_counter;
+    m_sendtime = x.m_sendtime;
+    m_xdata = x.m_xdata;
+
+    return *this;
+}
+
+TopicSample::Message& TopicSample::Message::operator=(Message &&x)
+{
+
+    m_msgname = std::move(x.m_msgname);
+    m_counter = x.m_counter;
+    m_sendtime = x.m_sendtime;
+    m_xdata = std::move(x.m_xdata);
+
+    return *this;
+}
+
+size_t TopicSample::Message::getMaxCdrSerializedSize(size_t current_alignment)
+{
+    size_t initial_alignment = current_alignment;
+
+
+    current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 255 + 1;
+
+    current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
+
+
+    current_alignment += 8 + eprosima::fastcdr::Cdr::alignment(current_alignment, 8);
+
+
+    current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
+
+    current_alignment += (100 * 1) + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);
+
+
+
+    return 10000000;
+//    return current_alignment - initial_alignment;
+}
+
+size_t TopicSample::Message::getCdrSerializedSize(const TopicSample::Message& data, size_t current_alignment)
+{
+    (void)data;
+    size_t initial_alignment = current_alignment;
+
+
+    current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.msgname().size() + 1;
+
+    current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
+
+
+    current_alignment += 8 + eprosima::fastcdr::Cdr::alignment(current_alignment, 8);
+
+
+    current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
+
+    if (data.xdata().size() > 0)
+    {
+        current_alignment += (data.xdata().size() * 1) + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);
+    }
+
+
+
+
+    return current_alignment - initial_alignment;
+}
+
+void TopicSample::Message::serialize(eprosima::fastcdr::Cdr &scdr) const
+{
+
+    scdr << m_msgname;
+    scdr << m_counter;
+    scdr << m_sendtime;
+    scdr << m_xdata;
+
+//    std::cout<<"serialize."<<std::endl;
+}
+
+void TopicSample::Message::deserialize(eprosima::fastcdr::Cdr &dcdr)
+{
+
+    dcdr >> m_msgname;
+    dcdr >> m_counter;
+    dcdr >> m_sendtime;
+    dcdr >> m_xdata;
+}
+
+/*!
+ * @brief This function copies the value in member msgname
+ * @param _msgname New value to be copied in member msgname
+ */
+void TopicSample::Message::msgname(const std::string &_msgname)
+{
+m_msgname = _msgname;
+}
+
+/*!
+ * @brief This function moves the value in member msgname
+ * @param _msgname New value to be moved in member msgname
+ */
+void TopicSample::Message::msgname(std::string &&_msgname)
+{
+m_msgname = std::move(_msgname);
+}
+
+/*!
+ * @brief This function returns a constant reference to member msgname
+ * @return Constant reference to member msgname
+ */
+const std::string& TopicSample::Message::msgname() const
+{
+    return m_msgname;
+}
+
+/*!
+ * @brief This function returns a reference to member msgname
+ * @return Reference to member msgname
+ */
+std::string& TopicSample::Message::msgname()
+{
+    return m_msgname;
+}
+/*!
+ * @brief This function sets a value in member counter
+ * @param _counter New value for member counter
+ */
+void TopicSample::Message::counter(int32_t _counter)
+{
+m_counter = _counter;
+}
+
+/*!
+ * @brief This function returns the value of member counter
+ * @return Value of member counter
+ */
+int32_t TopicSample::Message::counter() const
+{
+    return m_counter;
+}
+
+/*!
+ * @brief This function returns a reference to member counter
+ * @return Reference to member counter
+ */
+int32_t& TopicSample::Message::counter()
+{
+    return m_counter;
+}
+
+/*!
+ * @brief This function sets a value in member sendtime
+ * @param _sendtime New value for member sendtime
+ */
+void TopicSample::Message::sendtime(int64_t _sendtime)
+{
+m_sendtime = _sendtime;
+}
+
+/*!
+ * @brief This function returns the value of member sendtime
+ * @return Value of member sendtime
+ */
+int64_t TopicSample::Message::sendtime() const
+{
+    return m_sendtime;
+}
+
+/*!
+ * @brief This function returns a reference to member sendtime
+ * @return Reference to member sendtime
+ */
+int64_t& TopicSample::Message::sendtime()
+{
+    return m_sendtime;
+}
+
+/*!
+ * @brief This function copies the value in member xdata
+ * @param _xdata New value to be copied in member xdata
+ */
+void TopicSample::Message::xdata(const TopicSample::SomeBytes &_xdata)
+{
+ //   return;
+  m_xdata = _xdata;
+//int i;
+//for(i=0;i<300;i++)
+//    m_xdata.push_back(_xdata.at(i));
+}
+
+/*!
+ * @brief This function moves the value in member xdata
+ * @param _xdata New value to be moved in member xdata
+ */
+void TopicSample::Message::xdata(TopicSample::SomeBytes &&_xdata)
+{
+m_xdata = std::move(_xdata);
+}
+
+/*!
+ * @brief This function returns a constant reference to member xdata
+ * @return Constant reference to member xdata
+ */
+const TopicSample::SomeBytes& TopicSample::Message::xdata() const
+{
+    return m_xdata;
+}
+
+/*!
+ * @brief This function returns a reference to member xdata
+ * @return Reference to member xdata
+ */
+TopicSample::SomeBytes& TopicSample::Message::xdata()
+{
+    return m_xdata;
+}
+
+size_t TopicSample::Message::getKeyMaxCdrSerializedSize(size_t current_alignment)
+{
+    size_t current_align = current_alignment;
+
+
+
+
+
+
+
+    return current_align;
+}
+
+bool TopicSample::Message::isKeyDefined()
+{
+   return false;
+}
+
+void TopicSample::Message::serializeKey(eprosima::fastcdr::Cdr &scdr) const
+{
+    (void) scdr;
+     
+     
+     
+     
+}
+

+ 253 - 0
src1/common/modulecomm/fastrtps/Topics.h

@@ -0,0 +1,253 @@
+// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/*!
+ * @file Topics.h
+ * This header file contains the declaration of the described types in the IDL file.
+ *
+ * This file was generated by the tool gen.
+ */
+
+#ifndef _TOPICSAMPLE_TOPICS_H_
+#define _TOPICSAMPLE_TOPICS_H_
+
+// TODO Poner en el contexto.
+
+#include <stdint.h>
+#include <array>
+#include <string>
+#include <vector>
+#include <map>
+#include <bitset>
+
+#if defined(_WIN32)
+#if defined(EPROSIMA_USER_DLL_EXPORT)
+#define eProsima_user_DllExport __declspec( dllexport )
+#else
+#define eProsima_user_DllExport
+#endif
+#else
+#define eProsima_user_DllExport
+#endif
+
+#if defined(_WIN32)
+#if defined(EPROSIMA_USER_DLL_EXPORT)
+#if defined(Topics_SOURCE)
+#define Topics_DllAPI __declspec( dllexport )
+#else
+#define Topics_DllAPI __declspec( dllimport )
+#endif // Topics_SOURCE
+#else
+#define Topics_DllAPI
+#endif
+#else
+#define Topics_DllAPI
+#endif // _WIN32
+
+namespace eprosima
+{
+    namespace fastcdr
+    {
+        class Cdr;
+    }
+}
+
+
+namespace TopicSample
+{
+    typedef std::vector<uint8_t> SomeBytes;
+    /*!
+     * @brief This class represents the structure Message defined by the user in the IDL file.
+     * @ingroup TOPICS
+     */
+    class Message
+    {
+    public:
+
+        /*!
+         * @brief Default constructor.
+         */
+        eProsima_user_DllExport Message();
+
+        /*!
+         * @brief Default destructor.
+         */
+        eProsima_user_DllExport ~Message();
+
+        /*!
+         * @brief Copy constructor.
+         * @param x Reference to the object TopicSample::Message that will be copied.
+         */
+        eProsima_user_DllExport Message(const Message &x);
+
+        /*!
+         * @brief Move constructor.
+         * @param x Reference to the object TopicSample::Message that will be copied.
+         */
+        eProsima_user_DllExport Message(Message &&x);
+
+        /*!
+         * @brief Copy assignment.
+         * @param x Reference to the object TopicSample::Message that will be copied.
+         */
+        eProsima_user_DllExport Message& operator=(const Message &x);
+
+        /*!
+         * @brief Move assignment.
+         * @param x Reference to the object TopicSample::Message that will be copied.
+         */
+        eProsima_user_DllExport Message& operator=(Message &&x);
+
+        /*!
+         * @brief This function copies the value in member msgname
+         * @param _msgname New value to be copied in member msgname
+         */
+        eProsima_user_DllExport void msgname(const std::string &_msgname);
+
+        /*!
+         * @brief This function moves the value in member msgname
+         * @param _msgname New value to be moved in member msgname
+         */
+        eProsima_user_DllExport void msgname(std::string &&_msgname);
+
+        /*!
+         * @brief This function returns a constant reference to member msgname
+         * @return Constant reference to member msgname
+         */
+        eProsima_user_DllExport const std::string& msgname() const;
+
+        /*!
+         * @brief This function returns a reference to member msgname
+         * @return Reference to member msgname
+         */
+        eProsima_user_DllExport std::string& msgname();
+        /*!
+         * @brief This function sets a value in member counter
+         * @param _counter New value for member counter
+         */
+        eProsima_user_DllExport void counter(int32_t _counter);
+
+        /*!
+         * @brief This function returns the value of member counter
+         * @return Value of member counter
+         */
+        eProsima_user_DllExport int32_t counter() const;
+
+        /*!
+         * @brief This function returns a reference to member counter
+         * @return Reference to member counter
+         */
+        eProsima_user_DllExport int32_t& counter();
+
+        /*!
+         * @brief This function sets a value in member sendtime
+         * @param _sendtime New value for member sendtime
+         */
+        eProsima_user_DllExport void sendtime(int64_t _sendtime);
+
+        /*!
+         * @brief This function returns the value of member sendtime
+         * @return Value of member sendtime
+         */
+        eProsima_user_DllExport int64_t sendtime() const;
+
+        /*!
+         * @brief This function returns a reference to member sendtime
+         * @return Reference to member sendtime
+         */
+        eProsima_user_DllExport int64_t& sendtime();
+
+        /*!
+         * @brief This function copies the value in member xdata
+         * @param _xdata New value to be copied in member xdata
+         */
+        eProsima_user_DllExport void xdata(const TopicSample::SomeBytes &_xdata);
+
+        /*!
+         * @brief This function moves the value in member xdata
+         * @param _xdata New value to be moved in member xdata
+         */
+        eProsima_user_DllExport void xdata(TopicSample::SomeBytes &&_xdata);
+
+        /*!
+         * @brief This function returns a constant reference to member xdata
+         * @return Constant reference to member xdata
+         */
+        eProsima_user_DllExport const TopicSample::SomeBytes& xdata() const;
+
+        /*!
+         * @brief This function returns a reference to member xdata
+         * @return Reference to member xdata
+         */
+        eProsima_user_DllExport TopicSample::SomeBytes& xdata();
+
+        /*!
+         * @brief This function returns the maximum serialized size of an object
+         * depending on the buffer alignment.
+         * @param current_alignment Buffer alignment.
+         * @return Maximum serialized size.
+         */
+        eProsima_user_DllExport static size_t getMaxCdrSerializedSize(size_t current_alignment = 0);
+
+        /*!
+         * @brief This function returns the serialized size of a data depending on the buffer alignment.
+         * @param data Data which is calculated its serialized size.
+         * @param current_alignment Buffer alignment.
+         * @return Serialized size.
+         */
+        eProsima_user_DllExport static size_t getCdrSerializedSize(const TopicSample::Message& data, size_t current_alignment = 0);
+
+
+        /*!
+         * @brief This function serializes an object using CDR serialization.
+         * @param cdr CDR serialization object.
+         */
+        eProsima_user_DllExport void serialize(eprosima::fastcdr::Cdr &cdr) const;
+
+        /*!
+         * @brief This function deserializes an object using CDR serialization.
+         * @param cdr CDR serialization object.
+         */
+        eProsima_user_DllExport void deserialize(eprosima::fastcdr::Cdr &cdr);
+
+
+
+        /*!
+         * @brief This function returns the maximum serialized size of the Key of an object
+         * depending on the buffer alignment.
+         * @param current_alignment Buffer alignment.
+         * @return Maximum serialized size.
+         */
+        eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize(size_t current_alignment = 0);
+
+        /*!
+         * @brief This function tells you if the Key has been defined for this type
+         */
+        eProsima_user_DllExport static bool isKeyDefined();
+
+        /*!
+         * @brief This function serializes the key members of an object using CDR serialization.
+         * @param cdr CDR serialization object.
+         */
+        eProsima_user_DllExport void serializeKey(eprosima::fastcdr::Cdr &cdr) const;
+
+    private:
+        std::string m_msgname;
+        int32_t m_counter;
+        int64_t m_sendtime;
+        TopicSample::SomeBytes m_xdata;
+    };
+}
+
+#endif // _TOPICSAMPLE_TOPICS_H_

+ 13 - 0
src1/common/modulecomm/fastrtps/Topics.idl

@@ -0,0 +1,13 @@
+module TopicSample {
+
+#pragma DCPS_DATA_TYPE "TopicSample::Message"
+
+typedef sequence<octet> SomeBytes;
+struct Message {
+  string msgname;
+  long counter;
+  long long sendtime;
+  SomeBytes   xdata;
+};
+
+};

+ 138 - 0
src1/common/modulecomm/fastrtps/TopicsPubSubTypes.cxx

@@ -0,0 +1,138 @@
+// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/*!
+ * @file TopicsPubSubTypes.cpp
+ * This header file contains the implementation of the serialization functions.
+ *
+ * This file was generated by the tool fastcdrgen.
+ */
+
+
+#include <fastcdr/FastBuffer.h>
+#include <fastcdr/Cdr.h>
+
+#include "TopicsPubSubTypes.h"
+
+using namespace eprosima::fastrtps;
+using namespace eprosima::fastrtps::rtps;
+
+namespace TopicSample
+{
+
+    MessagePubSubType::MessagePubSubType()
+    {
+        setName("TopicSample::Message");
+        m_typeSize = static_cast<uint32_t>(Message::getMaxCdrSerializedSize()) + 4 /*encapsulation*/;
+        m_isGetKeyDefined = Message::isKeyDefined();
+        size_t keyLength = Message::getKeyMaxCdrSerializedSize()>16 ? Message::getKeyMaxCdrSerializedSize() : 16;
+        m_keyBuffer = reinterpret_cast<unsigned char*>(malloc(keyLength));
+        memset(m_keyBuffer, 0, keyLength);
+    }
+
+    MessagePubSubType::~MessagePubSubType()
+    {
+        if(m_keyBuffer!=nullptr)
+            free(m_keyBuffer);
+    }
+
+    bool MessagePubSubType::serialize(void *data, SerializedPayload_t *payload)
+    {
+        Message *p_type = static_cast<Message*>(data);
+        eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload->data), payload->max_size); // Object that manages the raw buffer.
+        eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
+                eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data.
+        payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
+        // Serialize encapsulation
+        ser.serialize_encapsulation();
+
+        try
+        {
+            p_type->serialize(ser); // Serialize the object:
+        }
+        catch(eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/)
+        {
+            return false;
+        }
+
+        payload->length = static_cast<uint32_t>(ser.getSerializedDataLength()); //Get the serialized length
+        return true;
+    }
+
+    bool MessagePubSubType::deserialize(SerializedPayload_t* payload, void* data)
+    {
+        Message* p_type = static_cast<Message*>(data); //Convert DATA to pointer of your type
+        eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload->data), payload->length); // Object that manages the raw buffer.
+        eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
+                eprosima::fastcdr::Cdr::DDS_CDR); // Object that deserializes the data.
+        // Deserialize encapsulation.
+        deser.read_encapsulation();
+        payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
+
+        try
+        {
+            p_type->deserialize(deser); //Deserialize the object:
+        }
+        catch(eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/)
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+    std::function<uint32_t()> MessagePubSubType::getSerializedSizeProvider(void* data)
+    {
+        return [data]() -> uint32_t
+        {
+            return static_cast<uint32_t>(type::getCdrSerializedSize(*static_cast<Message*>(data))) + 4 /*encapsulation*/;
+        };
+    }
+
+    void* MessagePubSubType::createData()
+    {
+        return reinterpret_cast<void*>(new Message());
+    }
+
+    void MessagePubSubType::deleteData(void* data)
+    {
+        delete(reinterpret_cast<Message*>(data));
+    }
+
+    bool MessagePubSubType::getKey(void *data, InstanceHandle_t* handle, bool force_md5)
+    {
+        if(!m_isGetKeyDefined)
+            return false;
+        Message* p_type = static_cast<Message*>(data);
+        eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(m_keyBuffer),Message::getKeyMaxCdrSerializedSize());     // Object that manages the raw buffer.
+        eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS);     // Object that serializes the data.
+        p_type->serializeKey(ser);
+        if(force_md5 || Message::getKeyMaxCdrSerializedSize()>16)    {
+            m_md5.init();
+            m_md5.update(m_keyBuffer, static_cast<unsigned int>(ser.getSerializedDataLength()));
+            m_md5.finalize();
+            for(uint8_t i = 0;i<16;++i)        {
+                handle->value[i] = m_md5.digest[i];
+            }
+        }
+        else    {
+            for(uint8_t i = 0;i<16;++i)        {
+                handle->value[i] = m_keyBuffer[i];
+            }
+        }
+        return true;
+    }
+
+
+} //End of namespace TopicSample

+ 61 - 0
src1/common/modulecomm/fastrtps/TopicsPubSubTypes.h

@@ -0,0 +1,61 @@
+// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/*!
+ * @file TopicsPubSubTypes.h
+ * This header file contains the declaration of the serialization functions.
+ *
+ * This file was generated by the tool fastcdrgen.
+ */
+
+
+#ifndef _TOPICSAMPLE_TOPICS_PUBSUBTYPES_H_
+#define _TOPICSAMPLE_TOPICS_PUBSUBTYPES_H_
+
+#include <fastrtps/config.h>
+#include <fastrtps/TopicDataType.h>
+
+#include "Topics.h"
+
+#if !defined(GEN_API_VER) || (GEN_API_VER != 1)
+#error Generated Topics is not compatible with current installed Fast-RTPS. Please, regenerate it with fastrtpsgen.
+#endif
+
+namespace TopicSample
+{
+    typedef std::vector<uint8_t> SomeBytes;
+    /*!
+     * @brief This class represents the TopicDataType of the type Message defined by the user in the IDL file.
+     * @ingroup TOPICS
+     */
+    class MessagePubSubType : public eprosima::fastrtps::TopicDataType {
+    public:
+        typedef Message type;
+
+        eProsima_user_DllExport MessagePubSubType();
+
+        eProsima_user_DllExport virtual ~MessagePubSubType();
+        eProsima_user_DllExport virtual bool serialize(void *data, eprosima::fastrtps::rtps::SerializedPayload_t *payload) override;
+        eProsima_user_DllExport virtual bool deserialize(eprosima::fastrtps::rtps::SerializedPayload_t *payload, void *data) override;
+        eProsima_user_DllExport virtual std::function<uint32_t()> getSerializedSizeProvider(void* data) override;
+        eProsima_user_DllExport virtual bool getKey(void *data, eprosima::fastrtps::rtps::InstanceHandle_t *ihandle,
+            bool force_md5 = false) override;
+        eProsima_user_DllExport virtual void* createData() override;
+        eProsima_user_DllExport virtual void deleteData(void * data) override;
+        MD5 m_md5;
+        unsigned char* m_keyBuffer;
+    };
+}
+
+#endif // _TOPICSAMPLE_TOPICS_PUBSUBTYPES_H_

+ 215 - 0
src1/common/modulecomm/fastrtps/TopicsPublisher.cxx

@@ -0,0 +1,215 @@
+// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/*!
+ * @file TopicsPublisher.cpp
+ * This file contains the implementation of the publisher functions.
+ *
+ * This file was generated by the tool fastcdrgen.
+ */
+
+
+#include <fastrtps/participant/Participant.h>
+#include <fastrtps/attributes/ParticipantAttributes.h>
+#include <fastrtps/publisher/Publisher.h>
+#include <fastrtps/attributes/PublisherAttributes.h>
+
+#include <fastrtps/Domain.h>
+
+#include <fastrtps/participant/Participant.h>
+#include <fastrtps/attributes/ParticipantAttributes.h>
+#include <fastrtps/attributes/PublisherAttributes.h>
+#include <fastrtps/publisher/Publisher.h>
+#include <fastrtps/Domain.h>
+#include <fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h>
+#include <fastdds/rtps/transport/UDPv4TransportDescriptor.h>
+#include <fastdds/rtps/transport/TCPv4TransportDescriptor.h>
+
+#include <thread>
+#include <chrono>
+
+#include "TopicsPublisher.h"
+
+using namespace eprosima::fastrtps;
+using namespace eprosima::fastrtps::rtps;
+
+using namespace eprosima::fastdds::rtps;
+
+TopicsPublisher::TopicsPublisher() : mp_participant(nullptr), mp_publisher(nullptr) {}
+
+TopicsPublisher::~TopicsPublisher() {	Domain::removeParticipant(mp_participant);}
+
+bool TopicsPublisher::init(const char * strtopic,const unsigned short nListenPort,const int ntype )
+{
+    strncpy(mstrtopic,strtopic,255);
+    // Create RTPSParticipant
+
+    ParticipantAttributes PParam;
+    PParam.rtps.sendSocketBufferSize = 100000000;
+    PParam.rtps.setName("Participant_publisher");  //You can put here the name you want
+
+    PParam.rtps.builtin.discovery_config.discoveryProtocol = DiscoveryProtocol_t::SIMPLE;
+    PParam.rtps.builtin.discovery_config.use_SIMPLE_EndpointDiscoveryProtocol = true;
+    PParam.rtps.builtin.discovery_config.m_simpleEDP.use_PublicationReaderANDSubscriptionWriter = true;
+    PParam.rtps.builtin.discovery_config.m_simpleEDP.use_PublicationWriterANDSubscriptionReader = true;
+    PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
+
+    // SharedMem transport configuration
+    PParam.rtps.useBuiltinTransports = false;
+
+    if(ntype == 0)
+    {
+    auto shm_transport = std::make_shared<SharedMemTransportDescriptor>();
+    shm_transport->segment_size(100*1024*1024);
+    PParam.rtps.userTransports.push_back(shm_transport);
+
+    // UDP
+    auto udp_transport = std::make_shared<UDPv4TransportDescriptor>();
+    //udp_transport->interfaceWhiteList.push_back("127.0.0.1");
+    PParam.rtps.userTransports.push_back(udp_transport);
+
+
+    }
+    else
+    {
+        //Create a descriptor for the new transport.
+        auto tcp_transport = std::make_shared<TCPv4TransportDescriptor>();
+        tcp_transport->add_listener_port(nListenPort);
+        tcp_transport->set_WAN_address("0.0.0.0");
+
+        tcp_transport->wait_for_tcp_negotiation = false;
+        tcp_transport->sendBufferSize = 0;
+        tcp_transport->receiveBufferSize = 0;
+
+        PParam.rtps.userTransports.push_back(tcp_transport);
+    }
+    mp_participant = Domain::createParticipant(PParam);
+    if(mp_participant == nullptr)
+    {
+        return false;
+    }
+
+    //Register the type
+
+    Domain::registerType(mp_participant, static_cast<TopicDataType*>(&myType));
+
+    // Create Publisher
+
+    PublisherAttributes Wparam;
+    Wparam.topic.topicKind = NO_KEY;
+    Wparam.topic.topicDataType = myType.getName();  //This type MUST be registered
+    Wparam.topic.topicName = strtopic;//"TopicsPubSubTopic";
+
+    Wparam.topic.historyQos.depth = 30;
+    Wparam.topic.resourceLimitsQos.max_samples = 50;
+    Wparam.topic.resourceLimitsQos.allocated_samples = 20;
+    Wparam.times.heartbeatPeriod.seconds = 2;
+    Wparam.times.heartbeatPeriod.nanosec = 200 * 1000 * 1000;
+    Wparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
+    Wparam.qos.m_publishMode.kind = ASYNCHRONOUS_PUBLISH_MODE;
+
+    mp_publisher = Domain::createPublisher(mp_participant,Wparam,static_cast<PublisherListener*>(&m_listener));
+
+    if(mp_publisher == nullptr)
+    {
+        return false;
+    }
+
+    std::cout << "Publisher created, waiting for Subscribers." << std::endl;
+    return true;
+}
+
+void TopicsPublisher::PubListener::onPublicationMatched(Publisher* pub,MatchingInfo& info)
+{
+    (void)pub;
+
+    if (info.status == MATCHED_MATCHING)
+    {
+        n_matched++;
+        std::cout << "Publisher matched" << std::endl;
+    }
+    else
+    {
+        n_matched--;
+        std::cout << "Publisher unmatched" << std::endl;
+    }
+}
+
+void TopicsPublisher::run()
+{
+    while(m_listener.n_matched == 0)
+    {
+        std::this_thread::sleep_for(std::chrono::milliseconds(250)); // Sleep 250 ms
+    }
+
+    // Publication code
+
+    TopicSample::Message st;
+
+    /* Initialize your structure here */
+
+    int msgsent = 0;
+    char ch = 'y';
+    do
+    {
+        if(ch == 'y')
+        {
+            mp_publisher->write(&st);  ++msgsent;
+            std::cout << "Sending sample, count=" << msgsent << ", send another sample?(y-yes,n-stop): ";
+        }
+        else if(ch == 'n')
+        {
+            std::cout << "Stopping execution " << std::endl;
+            break;
+        }
+        else
+        {
+            std::cout << "Command " << ch << " not recognized, please enter \"y/n\":";
+        }
+    } while(std::cin >> ch);
+}
+
+#include <QDateTime>
+
+void TopicsPublisher::senddata(const char *str, int nsize)
+{
+
+
+    static int ncount = 1;
+    std::cout<<"send data."<<std::endl;
+//    while(m_listener.n_matched == 0)
+    TopicSample::SomeBytes x;
+    x.resize(nsize);
+    memcpy(x.data(),str,nsize);
+
+    TopicSample::Message st;
+
+    st.msgname(mstrtopic);
+//    st.msgname("topictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopic");
+    st.counter(ncount);ncount++;
+    st.sendtime(QDateTime::currentMSecsSinceEpoch());
+    TopicSample::SomeBytes & px = x;
+    st.xdata(x);
+
+    int ndatasize = TopicSample::Message::getCdrSerializedSize(st);
+
+    std::cout<<"size is "<<ndatasize<<std::endl;
+
+
+    mp_publisher->write(&st);
+
+
+
+}
+

+ 56 - 0
src1/common/modulecomm/fastrtps/TopicsPublisher.h

@@ -0,0 +1,56 @@
+// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/*!
+ * @file TopicsPublisher.h
+ * This header file contains the declaration of the publisher functions.
+ *
+ * This file was generated by the tool fastcdrgen.
+ */
+
+
+#ifndef _TOPICSAMPLE_TOPICS_PUBLISHER_H_
+#define _TOPICSAMPLE_TOPICS_PUBLISHER_H_
+
+#include <fastrtps/fastrtps_fwd.h>
+#include <fastrtps/publisher/PublisherListener.h>
+
+#include "TopicsPubSubTypes.h"
+
+class TopicsPublisher
+{
+public:
+	TopicsPublisher();
+	virtual ~TopicsPublisher();
+    bool init(const char * strtopic,const unsigned short nListenPort = 5100,const int ntype = 0);
+	void run();
+    void senddata(const char *str, int nsize);
+private:
+	eprosima::fastrtps::Participant *mp_participant;
+	eprosima::fastrtps::Publisher *mp_publisher;
+
+    char mstrtopic[256];
+
+	class PubListener : public eprosima::fastrtps::PublisherListener
+	{
+	public:
+		PubListener() : n_matched(0){};
+		~PubListener(){};
+		void onPublicationMatched(eprosima::fastrtps::Publisher* pub,eprosima::fastrtps::rtps::MatchingInfo& info);
+		int n_matched;
+	} m_listener;
+	TopicSample::MessagePubSubType myType;
+};
+
+#endif // _TOPICSAMPLE_TOPICS_PUBLISHER_H_

+ 228 - 0
src1/common/modulecomm/fastrtps/TopicsSubscriber.cxx

@@ -0,0 +1,228 @@
+// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/*!
+ * @file TopicsSubscriber.cpp
+ * This file contains the implementation of the subscriber functions.
+ *
+ * This file was generated by the tool fastcdrgen.
+ */
+
+#include <fastrtps/participant/Participant.h>
+#include <fastrtps/attributes/ParticipantAttributes.h>
+#include <fastrtps/subscriber/Subscriber.h>
+#include <fastrtps/attributes/SubscriberAttributes.h>
+
+#include <fastrtps/Domain.h>
+
+#include <fastcdr/FastBuffer.h>
+#include <fastcdr/FastCdr.h>
+#include <fastcdr/Cdr.h>
+
+#include <fastrtps/participant/Participant.h>
+#include <fastrtps/attributes/ParticipantAttributes.h>
+#include <fastrtps/attributes/PublisherAttributes.h>
+#include <fastrtps/publisher/Publisher.h>
+#include <fastrtps/Domain.h>
+#include <fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h>
+#include <fastdds/rtps/transport/UDPv4TransportDescriptor.h>
+#include <fastdds/rtps/transport/TCPv4TransportDescriptor.h>
+
+#include "TopicsSubscriber.h"
+
+using namespace eprosima::fastrtps;
+using namespace eprosima::fastrtps::rtps;
+
+using namespace eprosima::fastdds::rtps;
+
+
+
+
+#include <QDateTime>
+
+TopicsSubscriber::TopicsSubscriber() : mp_participant(nullptr), mp_subscriber(nullptr) {}
+
+TopicsSubscriber::~TopicsSubscriber() {	Domain::removeParticipant(mp_participant);}
+
+bool TopicsSubscriber::init(const char * strtopic,const char * strpubip,const unsigned short nPort,int ntype)
+{
+
+    strncpy(mstrtopic,strtopic,255);
+    // Create RTPSParticipant
+
+    ParticipantAttributes PParam;
+    PParam.rtps.setName("Participant_subscriber"); //You can put the name you want
+
+    PParam.rtps.builtin.discovery_config.discoveryProtocol = DiscoveryProtocol_t::SIMPLE;
+    PParam.rtps.builtin.discovery_config.use_SIMPLE_EndpointDiscoveryProtocol = true;
+    PParam.rtps.builtin.discovery_config.m_simpleEDP.use_PublicationReaderANDSubscriptionWriter = true;
+    PParam.rtps.builtin.discovery_config.m_simpleEDP.use_PublicationWriterANDSubscriptionReader = true;
+    PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
+
+    // SharedMem transport configuration
+    PParam.rtps.useBuiltinTransports = false;
+
+    if(ntype == 0)
+    {
+    auto sm_transport = std::make_shared<SharedMemTransportDescriptor>();
+    sm_transport->segment_size(100*1024*1024);
+    PParam.rtps.userTransports.push_back(sm_transport);
+
+    // UDP
+    auto udp_transport = std::make_shared<UDPv4TransportDescriptor>();
+    //udp_transport->interfaceWhiteList.push_back("127.0.0.1");
+    PParam.rtps.userTransports.push_back(udp_transport);
+    }
+    else
+    {
+        auto tcp2_transport = std::make_shared<TCPv4TransportDescriptor>();
+
+        //Set initial peers.
+        Locator_t initial_peer_locator;
+        initial_peer_locator.kind = LOCATOR_KIND_TCPv4;
+        IPLocator::setIPv4(initial_peer_locator, strpubip);
+        initial_peer_locator.port = nPort;
+        PParam.rtps.builtin.initialPeersList.push_back(initial_peer_locator);
+
+    //    PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
+    //    PParam.rtps.builtin.discovery_config.leaseDuration_announcementperiod = Duration_t(5, 0);
+    //    PParam.rtps.setName("Participant_sub");
+
+        tcp2_transport->wait_for_tcp_negotiation = false;
+        //Link the Transport Layer to the Participant.
+        PParam.rtps.userTransports.push_back(tcp2_transport);
+    }
+
+
+    mp_participant = Domain::createParticipant(PParam);
+    if(mp_participant == nullptr)
+    {
+        return false;
+    }
+
+    //Register the type
+
+    Domain::registerType(mp_participant, static_cast<TopicDataType*>(&myType));
+
+    // Create Subscriber
+
+    SubscriberAttributes Rparam;
+    Rparam.topic.topicKind = NO_KEY;
+    Rparam.topic.topicDataType = myType.getName(); //Must be registered before the creation of the subscriber
+    Rparam.topic.topicName = strtopic;//"TopicsPubSubTopic";
+
+    Rparam.topic.historyQos.depth = 30;
+    Rparam.topic.resourceLimitsQos.max_samples = 50;
+    Rparam.topic.resourceLimitsQos.allocated_samples = 20;
+
+    Rparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
+
+
+    mp_subscriber = Domain::createSubscriber(mp_participant,Rparam, static_cast<SubscriberListener*>(&m_listener));
+    if(mp_subscriber == nullptr)
+    {
+        return false;
+    }
+    return true;
+}
+
+void TopicsSubscriber::SubListener::onSubscriptionMatched(Subscriber* sub,MatchingInfo& info)
+{
+    (void)sub;
+
+    if (info.status == MATCHED_MATCHING)
+    {
+        n_matched++;
+        std::cout << "Subscriber matched" << std::endl;
+    }
+    else
+    {
+        n_matched--;
+        std::cout << "Subscriber unmatched" << std::endl;
+    }
+}
+
+
+void TopicsSubscriber::SubListener::setReceivedTopicFunction(ModuleFun xFun)
+{
+    mFun = xFun;
+    mbSetFun = true;
+}
+void TopicsSubscriber::SubListener::onNewDataMessage(Subscriber* sub)
+{
+    // Take data
+    TopicSample::Message st;
+    static int ncount = 0;
+
+    static int nmaxlatancy = 0;
+
+    std::cout<<"new msg"<<std::endl;
+
+
+//    char * strbuf = new char[1000000];
+//    eprosima::fastcdr::FastBuffer pbuf(strbuf,1000000);
+//    eprosima::fastcdr::Cdr * pxcdr;//
+//    pxcdr = new eprosima::fastcdr::Cdr(pbuf);
+
+//    if(sub->takeNextData(pxcdr, &m_info))
+//    {
+//        if(m_info.sampleKind == ALIVE)
+//        {
+//            // Print your structure data here.
+//            ++n_msg;
+//            std::cout << "Sample received, count=" << n_msg<<std::endl;
+//            st.deserialize(*pxcdr);
+
+//            std::cout<<" size is "<<TopicSample::Message::getCdrSerializedSize(st)<<std::endl;
+//        }
+//    }
+
+//    return;
+
+//    sub->get_first_untaken_info(&m_info);
+    std::cout<<"count is "<<sub->getUnreadCount()<<std::endl;
+
+    if(sub->takeNextData(&st, &m_info))
+    {
+        if(m_info.sampleKind == ALIVE)
+        {
+            // Print your structure data here.
+            ++n_msg;
+            ncount++;
+            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;
+            QDateTime dt = QDateTime::fromMSecsSinceEpoch(st.sendtime());
+            if(mbSetFun) mFun((char *)(st.xdata().data()),st.xdata().size(),st.counter(),&dt,st.msgname().data());
+
+
+        }
+    }
+}
+
+void TopicsSubscriber::setReceivedTopicFunction(ModuleFun xFun)
+{
+    m_listener.setReceivedTopicFunction(xFun);
+}
+
+void TopicsSubscriber::run()
+{
+    std::cout << "Waiting for Data, press Enter to stop the Subscriber. "<<std::endl;
+    std::cin.ignore();
+    std::cout << "Shutting down the Subscriber." << std::endl;
+}
+

+ 72 - 0
src1/common/modulecomm/fastrtps/TopicsSubscriber.h

@@ -0,0 +1,72 @@
+// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/*!
+ * @file TopicsSubscriber.h
+ * This header file contains the declaration of the subscriber functions.
+ *
+ * This file was generated by the tool fastcdrgen.
+ */
+
+
+#ifndef _TOPICSAMPLE_TOPICS_SUBSCRIBER_H_
+#define _TOPICSAMPLE_TOPICS_SUBSCRIBER_H_
+
+#include <fastrtps/fastrtps_fwd.h>
+#include <fastrtps/subscriber/SubscriberListener.h>
+#include <fastrtps/subscriber/SampleInfo.h>
+#include "TopicsPubSubTypes.h"
+
+
+#include <QDateTime>
+
+typedef std::function<void(const char * ,const unsigned int , const unsigned int , QDateTime * ,const char *)> ModuleFun;
+
+class TopicsSubscriber
+{
+public:
+	TopicsSubscriber();
+	virtual ~TopicsSubscriber();
+    bool init(const char * strtopic,const char * strpubip = 0,const unsigned short nPort = 5100,int ntype = 0);
+	void run();
+
+    void setReceivedTopicFunction(ModuleFun xFun);
+private:
+	eprosima::fastrtps::Participant *mp_participant;
+	eprosima::fastrtps::Subscriber *mp_subscriber;
+
+
+    char mstrtopic[256];
+
+	class SubListener : public eprosima::fastrtps::SubscriberListener
+	{
+	public:
+		SubListener() : n_matched(0),n_msg(0){};
+		~SubListener(){};
+		void onSubscriptionMatched(eprosima::fastrtps::Subscriber* sub,eprosima::fastrtps::rtps::MatchingInfo& info);
+		void onNewDataMessage(eprosima::fastrtps::Subscriber* sub);
+		eprosima::fastrtps::SampleInfo_t m_info;
+		int n_matched;
+		int n_msg;
+
+        void setReceivedTopicFunction(ModuleFun xFun);
+
+    private:
+        bool mbSetFun = false;
+        ModuleFun mFun;
+	} m_listener;
+	TopicSample::MessagePubSubType myType;
+};
+
+#endif // _TOPICSAMPLE_TOPICS_SUBSCRIBER_H_

+ 19 - 0
src1/common/modulecomm/fastrtps/modulecomm_fastrtps.pri

@@ -0,0 +1,19 @@
+HEADERS += \
+    $$PWD/Topics.h \
+    $$PWD/TopicsPubSubTypes.h \
+    $$PWD/TopicsPublisher.h \
+    $$PWD/TopicsSubscriber.h \
+    $$PWD/modulecomm_fastrtps_shm.h \
+    $$PWD/modulecomm_fastrtps_tcp.h \
+    $$PWD/modulecomm_impl_shm.h \
+    $$PWD/modulecomm_impl_tcp.h
+
+SOURCES += \
+    $$PWD/Topics.cxx \
+    $$PWD/TopicsPubSubTypes.cxx \
+    $$PWD/TopicsPublisher.cxx \
+    $$PWD/TopicsSubscriber.cxx \
+    $$PWD/modulecomm_fastrtps_shm.cpp \
+    $$PWD/modulecomm_fastrtps_tcp.cpp \
+    $$PWD/modulecomm_impl_shm.cpp \
+    $$PWD/modulecomm_impl_tcp.cpp

+ 61 - 0
src1/common/modulecomm/fastrtps/modulecomm_fastrtps_shm.cpp

@@ -0,0 +1,61 @@
+#include "modulecomm_fastrtps_shm.h"
+
+#include "modulecomm_impl_shm.h"
+
+namespace  iv {
+
+
+modulecomm_fastrtps_shm::modulecomm_fastrtps_shm()
+{
+
+}
+
+void modulecomm_fastrtps_shm::RegisterSend(const char *strcommname, const unsigned int nBufSize, const unsigned int nMsgBufCount)
+{
+    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);
+ //   procsm_if * pif = new procsm_if(strcommname,0,0,procsm::ModeRead);
+    pif->listenmsg(pCall);
+    mpif = pif;
+}
+
+void modulecomm_fastrtps_shm::RegisterRecvPlus(const char *strcommname, ModuleFun xFun)
+{
+    modulecomm_impl_shm * pif = new modulecomm_impl_shm(strcommname,modulecomm_impl_shm::type_recv);
+ //   procsm_if * pif = new procsm_if(strcommname,0,0,procsm::ModeRead);
+    pif->listenmsg(xFun);
+    mpif = pif;
+}
+
+void modulecomm_fastrtps_shm::ModuleSendMsg(const char *strdata, const unsigned int nDataLen)
+{
+    modulecomm_impl_shm * pif= (modulecomm_impl_shm *)mpif;
+ //   procsm_if * pif = (procsm_if *)pHandle;
+    pif->writemsg(strdata,nDataLen);
+}
+
+void modulecomm_fastrtps_shm::PauseComm()
+{
+
+}
+
+void modulecomm_fastrtps_shm::ContintuComm()
+{
+
+}
+
+void modulecomm_fastrtps_shm::Unregister()
+{
+    modulecomm_impl_shm * pif= (modulecomm_impl_shm *)mpif;
+//    procsm_if * pif = (procsm_if *)pHandle;
+    delete pif;
+}
+
+}

+ 29 - 0
src1/common/modulecomm/fastrtps/modulecomm_fastrtps_shm.h

@@ -0,0 +1,29 @@
+#ifndef MODULECOMM_FASTRTPS_SHM_H
+#define MODULECOMM_FASTRTPS_SHM_H
+
+#include "modulecomm_impl_shm.h"
+
+namespace iv {
+
+
+
+class modulecomm_fastrtps_shm
+{
+public:
+    modulecomm_fastrtps_shm();
+
+    void RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount);
+    void RegisterRecv(const char * strcommname,SMCallBack pCall);
+    void RegisterRecvPlus(const char * strcommname,ModuleFun xFun);
+    virtual void ModuleSendMsg(const char * strdata,const unsigned int nDataLen);
+    virtual void Unregister();
+    virtual void PauseComm();
+    virtual void ContintuComm();
+
+private:
+    void * mpif;
+};
+
+}
+
+#endif // MODULECOMM_FASTRTPS_SHM_H

+ 61 - 0
src1/common/modulecomm/fastrtps/modulecomm_fastrtps_tcp.cpp

@@ -0,0 +1,61 @@
+#include "modulecomm_fastrtps_tcp.h"
+
+#include "modulecomm_impl_tcp.h"
+
+namespace  iv {
+
+
+modulecomm_fastrtps_tcp::modulecomm_fastrtps_tcp()
+{
+
+}
+
+void modulecomm_fastrtps_tcp::RegisterSend(const char *strcommname, const unsigned int nBufSize, const unsigned int nMsgBufCount, unsigned int nListenPort)
+{
+    modulecomm_impl_tcp * pif = new modulecomm_impl_tcp(strcommname,modulecomm_impl_tcp::type_send,nListenPort);
+
+//    procsm_if * pif = new procsm_if(strcommname,nBufSize,nMsgBufCount,procsm::ModeWrite);
+    mpif = pif;
+}
+
+void modulecomm_fastrtps_tcp::RegisterRecv(const char *strcommname, SMCallBack pCall, const char *strpubip, unsigned int nListenPort)
+{
+    modulecomm_impl_tcp * pif = new modulecomm_impl_tcp(strcommname,modulecomm_impl_tcp::type_recv,nListenPort,strpubip);
+ //   procsm_if * pif = new procsm_if(strcommname,0,0,procsm::ModeRead);
+    pif->listenmsg(pCall);
+    mpif = pif;
+}
+
+void modulecomm_fastrtps_tcp::RegisterRecvPlus(const char *strcommname, ModuleFun xFun, const char *strpubip, unsigned int nListenPort)
+{
+    modulecomm_impl_tcp * pif = new modulecomm_impl_tcp(strcommname,modulecomm_impl_tcp::type_recv,nListenPort,strpubip);
+ //   procsm_if * pif = new procsm_if(strcommname,0,0,procsm::ModeRead);
+    pif->listenmsg(xFun);
+    mpif = pif;
+}
+
+void modulecomm_fastrtps_tcp::ContintuComm()
+{
+
+}
+
+void modulecomm_fastrtps_tcp::PauseComm()
+{
+
+}
+
+void modulecomm_fastrtps_tcp::ModuleSendMsg(const char *strdata, const unsigned int nDataLen)
+{
+    modulecomm_impl_tcp * pif= (modulecomm_impl_tcp *)mpif;
+ //   procsm_if * pif = (procsm_if *)pHandle;
+    pif->writemsg(strdata,nDataLen);
+}
+
+void modulecomm_fastrtps_tcp::Unregister()
+{
+    modulecomm_impl_tcp * pif= (modulecomm_impl_tcp *)mpif;
+//    procsm_if * pif = (procsm_if *)pHandle;
+    delete pif;
+
+}
+}

+ 26 - 0
src1/common/modulecomm/fastrtps/modulecomm_fastrtps_tcp.h

@@ -0,0 +1,26 @@
+#ifndef MODULECOMM_FASTRTPS_TCP_H
+#define MODULECOMM_FASTRTPS_TCP_H
+
+#include "modulecomm_impl_tcp.h"
+namespace  iv {
+
+
+class modulecomm_fastrtps_tcp
+{
+public:
+    modulecomm_fastrtps_tcp();
+    void RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount,unsigned int nListenPort);
+    void RegisterRecv(const char * strcommname,SMCallBack pCall,const char * strpubip,unsigned int nListenPort);
+    void RegisterRecvPlus(const char * strcommname,ModuleFun xFun,const char * strpubip,unsigned int nListenPort);
+    virtual void ModuleSendMsg(const char * strdata,const unsigned int nDataLen);
+    virtual void Unregister();
+    virtual void PauseComm();
+    virtual void ContintuComm();
+
+private:
+    void * mpif;
+};
+
+}
+
+#endif // MODULECOMM_FASTRTPS_TCP_H

+ 140 - 0
src1/common/modulecomm/fastrtps/modulecomm_impl_shm.cpp

@@ -0,0 +1,140 @@
+#include "modulecomm_impl_shm.h"
+
+#include <thread>
+#include <iostream>
+#include <QDateTime>
+
+#include <QMutex>
+#include <QFile>
+
+namespace iv {
+namespace modulecomm {
+static QMutex gmodulecomm_dds_Mutex;
+static int createcount = 0;
+}
+
+}
+
+
+void modulecomm_impl_shm::callbackTopic(const char * strdata,const unsigned int nSize,const unsigned int index, QDateTime * dt,const char * strmemname) {
+
+  if(mbFunPlus)
+  {
+      mFun(strdata,nSize,index,dt,strmemname);
+  }
+  else
+  {
+     (*mpCall)(strdata,nSize,index,dt,strmemname);
+  }
+}
+
+
+int modulecomm_impl_shm::GetTempConfPath(char *strpath)
+{
+    char strtmppath[256];
+    QDateTime dt = QDateTime::currentDateTime();
+    snprintf(strtmppath,256,"/tmp/adc_modulecomm_conf_%04d%02d%02d%02d%02d.ini",dt.date().year(),
+             dt.date().month(),dt.date().day(),dt.time().hour(),dt.time().minute());
+    QFile xFile;
+    xFile.setFileName(strtmppath);
+    char strtem[256];
+    char strdata[10000];
+    snprintf(strdata,10000,"");
+    if(!xFile.exists())
+    {
+        if(xFile.open(QIODevice::ReadWrite))
+        {
+            snprintf(strtem,256,"[common]\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"DCPSDefaultDiscovery=TheRTPSConfig\n");strncat(strdata,strtem,10000);
+#ifdef dds_use_shm
+            snprintf(strtem,256,"DCPSGlobalTransportConfig=myconfig\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"[config/myconfig]\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"transports=share\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"[transport/share]\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"transport_type=shmem\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"pool_size=100000000\n");strncat(strdata,strtem,10000);
+#endif
+            snprintf(strtem,256,"[rtps_discovery/TheRTPSConfig]\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"ResendPeriod=5\n");strncat(strdata,strtem,10000);
+            xFile.write(strdata,strnlen(strdata,10000));
+            xFile.close();
+        }
+    }
+    strncpy(strpath,strtmppath,255);
+    return 0;
+}
+
+modulecomm_impl_shm::modulecomm_impl_shm(const char * strcommname,int ntype )
+{
+
+    strncpy(mstrtopic,strcommname,255);
+
+    iv::modulecomm::gmodulecomm_dds_Mutex.lock();
+    if(ntype == type_recv)
+    {
+        mpSub = new TopicsSubscriber();
+        mpSub->init(strcommname);
+//        std::this_thread::sleep_for(std::chrono::milliseconds(10));
+
+        mnType = type_recv;
+    }
+    else
+    {
+        mpPub = new TopicsPublisher();
+        mpPub->init(strcommname);
+ //       std::this_thread::sleep_for(std::chrono::milliseconds(10));
+        mnType = type_send;
+    }
+    iv::modulecomm::createcount++;
+    std::cout<<"count is "<<iv::modulecomm::createcount<<std::endl;
+    iv::modulecomm::gmodulecomm_dds_Mutex.unlock();
+
+}
+
+int modulecomm_impl_shm::listenmsg(ModuleFun xFun)
+{
+    if(mnType == type_send)
+    {
+        std::cout<<"send not listen."<<std::endl;;
+        return -1;
+    }
+    mbFunPlus = true;
+    mFun = xFun;
+    ModuleFun topicFunction = std::bind(&modulecomm_impl_shm::callbackTopic,this,std::placeholders::_1,
+                                                                                std::placeholders::_2,
+                                                                                std::placeholders::_3,
+                                                                                std::placeholders::_4,
+                                                                                std::placeholders::_5);
+    mpSub->setReceivedTopicFunction(topicFunction);
+    return 0;
+}
+
+int modulecomm_impl_shm::listenmsg(SMCallBack pCall)
+{
+    if(mnType == type_send)
+    {
+        std::cout<<"send not listen."<<std::endl;
+        return -1;
+    }
+    mbFunPlus = false;
+    mpCall = pCall;
+    ModuleFun topicFunction = std::bind(&modulecomm_impl_shm::callbackTopic,this,std::placeholders::_1,
+                                                                                std::placeholders::_2,
+                                                                                std::placeholders::_3,
+                                                                                std::placeholders::_4,
+                                                                                std::placeholders::_5);
+    mpSub->setReceivedTopicFunction(topicFunction);
+    return 0;
+}
+
+void modulecomm_impl_shm::writemsg(const char *str, int nlen)
+{
+    if(mnType == type_recv)
+    {
+        std::cout<<"recv not send."<<std::endl;
+        return ;
+    }
+
+    mpPub->senddata(str,nlen);
+
+}

+ 41 - 0
src1/common/modulecomm/fastrtps/modulecomm_impl_shm.h

@@ -0,0 +1,41 @@
+#ifndef MODULECOMM_IMPL_SHM_H
+#define MODULECOMM_IMPL_SHM_H
+
+#include <QDateTime>
+
+#include "TopicsPublisher.h"
+#include "TopicsSubscriber.h"
+
+
+typedef void (* SMCallBack)(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
+
+
+class modulecomm_impl_shm
+{
+public:
+    const static int type_send = 1;
+    const static int type_recv = 2;
+public:
+    modulecomm_impl_shm(const char * strcommname,int ntype = 2);
+    int listenmsg(SMCallBack pCall);
+    int listenmsg(ModuleFun xFun);
+    void writemsg(const char * str,int nlen);
+
+private:
+    char mstrtopic[256];
+    int mnType = type_recv;
+    TopicsPublisher * mpPub;
+    TopicsSubscriber * mpSub;
+    SMCallBack  mpCall;
+    ModuleFun mFun;
+    void callbackTopic(const char * strdata,const unsigned int nSize,const unsigned int index,QDateTime * dt,const char * strmemname);
+
+    int GetTempConfPath(char * strpath);
+
+
+
+    bool mbFunPlus = false;
+
+};
+
+#endif // MODULECOMM_IMPL_H

+ 140 - 0
src1/common/modulecomm/fastrtps/modulecomm_impl_tcp.cpp

@@ -0,0 +1,140 @@
+#include "modulecomm_impl_tcp.h"
+
+#include <thread>
+#include <iostream>
+#include <QDateTime>
+
+#include <QMutex>
+#include <QFile>
+
+namespace iv {
+namespace modulecomm {
+static QMutex gmodulecomm_dds_Mutex;
+static int createcount = 0;
+}
+
+}
+
+
+void modulecomm_impl_tcp::callbackTopic(const char * strdata,const unsigned int nSize,const unsigned int index, QDateTime * dt,const char * strmemname) {
+
+  if(mbFunPlus)
+  {
+      mFun(strdata,nSize,index,dt,strmemname);
+  }
+  else
+  {
+     (*mpCall)(strdata,nSize,index,dt,strmemname);
+  }
+}
+
+
+int modulecomm_impl_tcp::GetTempConfPath(char *strpath)
+{
+    char strtmppath[256];
+    QDateTime dt = QDateTime::currentDateTime();
+    snprintf(strtmppath,256,"/tmp/adc_modulecomm_conf_%04d%02d%02d%02d%02d.ini",dt.date().year(),
+             dt.date().month(),dt.date().day(),dt.time().hour(),dt.time().minute());
+    QFile xFile;
+    xFile.setFileName(strtmppath);
+    char strtem[256];
+    char strdata[10000];
+    snprintf(strdata,10000,"");
+    if(!xFile.exists())
+    {
+        if(xFile.open(QIODevice::ReadWrite))
+        {
+            snprintf(strtem,256,"[common]\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"DCPSDefaultDiscovery=TheRTPSConfig\n");strncat(strdata,strtem,10000);
+#ifdef dds_use_shm
+            snprintf(strtem,256,"DCPSGlobalTransportConfig=myconfig\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"[config/myconfig]\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"transports=share\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"[transport/share]\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"transport_type=shmem\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"pool_size=100000000\n");strncat(strdata,strtem,10000);
+#endif
+            snprintf(strtem,256,"[rtps_discovery/TheRTPSConfig]\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"ResendPeriod=5\n");strncat(strdata,strtem,10000);
+            xFile.write(strdata,strnlen(strdata,10000));
+            xFile.close();
+        }
+    }
+    strncpy(strpath,strtmppath,255);
+    return 0;
+}
+
+modulecomm_impl_tcp::modulecomm_impl_tcp(const char * strcommname,int ntype,const unsigned short nport ,const char * strip )
+{
+
+    strncpy(mstrtopic,strcommname,255);
+
+    iv::modulecomm::gmodulecomm_dds_Mutex.lock();
+    if(ntype == type_recv)
+    {
+        mpSub = new TopicsSubscriber();
+        mpSub->init(strcommname,strip,nport,1);
+//        std::this_thread::sleep_for(std::chrono::milliseconds(10));
+
+        mnType = type_recv;
+    }
+    else
+    {
+        mpPub = new TopicsPublisher();
+        mpPub->init(strcommname,nport,1);
+ //       std::this_thread::sleep_for(std::chrono::milliseconds(10));
+        mnType = type_send;
+    }
+    iv::modulecomm::createcount++;
+    std::cout<<"count is "<<iv::modulecomm::createcount<<std::endl;
+    iv::modulecomm::gmodulecomm_dds_Mutex.unlock();
+
+}
+
+int modulecomm_impl_tcp::listenmsg(ModuleFun xFun)
+{
+    if(mnType == type_send)
+    {
+        std::cout<<"send not listen."<<std::endl;;
+        return -1;
+    }
+    mbFunPlus = true;
+    mFun = xFun;
+    ModuleFun topicFunction = std::bind(&modulecomm_impl_tcp::callbackTopic,this,std::placeholders::_1,
+                                                                                std::placeholders::_2,
+                                                                                std::placeholders::_3,
+                                                                                std::placeholders::_4,
+                                                                                std::placeholders::_5);
+    mpSub->setReceivedTopicFunction(topicFunction);
+    return 0;
+}
+
+int modulecomm_impl_tcp::listenmsg(SMCallBack pCall)
+{
+    if(mnType == type_send)
+    {
+        std::cout<<"send not listen."<<std::endl;
+        return -1;
+    }
+    mbFunPlus = false;
+    mpCall = pCall;
+    ModuleFun topicFunction = std::bind(&modulecomm_impl_tcp::callbackTopic,this,std::placeholders::_1,
+                                                                                std::placeholders::_2,
+                                                                                std::placeholders::_3,
+                                                                                std::placeholders::_4,
+                                                                                std::placeholders::_5);
+    mpSub->setReceivedTopicFunction(topicFunction);
+    return 0;
+}
+
+void modulecomm_impl_tcp::writemsg(const char *str, int nlen)
+{
+    if(mnType == type_recv)
+    {
+        std::cout<<"recv not send."<<std::endl;
+        return ;
+    }
+
+    mpPub->senddata(str,nlen);
+
+}

+ 41 - 0
src1/common/modulecomm/fastrtps/modulecomm_impl_tcp.h

@@ -0,0 +1,41 @@
+#ifndef MODULECOMM_IMPL_TCP_H
+#define MODULECOMM_IMPL_TCP_H
+
+#include <QDateTime>
+
+#include "TopicsPublisher.h"
+#include "TopicsSubscriber.h"
+
+
+typedef void (* SMCallBack)(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
+
+
+class modulecomm_impl_tcp
+{
+public:
+    const static int type_send = 1;
+    const static int type_recv = 2;
+public:
+    modulecomm_impl_tcp(const char * strcommname,int ntype = 2,const unsigned short nport =1,const char * strip = 0);
+    int listenmsg(SMCallBack pCall);
+    int listenmsg(ModuleFun xFun);
+    void writemsg(const char * str,int nlen);
+
+private:
+    char mstrtopic[256];
+    int mnType = type_recv;
+    TopicsPublisher * mpPub;
+    TopicsSubscriber * mpSub;
+    SMCallBack  mpCall;
+    ModuleFun mFun;
+    void callbackTopic(const char * strdata,const unsigned int nSize,const unsigned int index,QDateTime * dt,const char * strmemname);
+
+    int GetTempConfPath(char * strpath);
+
+
+
+    bool mbFunPlus = false;
+
+};
+
+#endif // MODULECOMM_IMPL_H

+ 480 - 0
src1/common/modulecomm/inter/intercomm.cpp

@@ -0,0 +1,480 @@
+#include "intercomm.h"
+
+#include <QMutex>
+#include <QWaitCondition>
+#include <iostream>
+
+namespace  iv {
+
+struct InterListenUnit
+{
+    QMutex mWaitMutex;
+    SMCallBack  mpCall;
+    ModuleFun mFun;
+    QWaitCondition * mpwc;
+    bool mbFunPlus = false;
+};
+
+struct interunit
+{
+    char strintername[256];
+    char * strdatabuf;
+    int nbufsize = 0;
+    int nPacCount;
+    QMutex mMutexUnit;
+    std::vector<InterListenUnit *> mvectorlisten;
+    QWaitCondition mwc;
+    bool mbHaveWriter = false;
+
+};
+
+std::vector<interunit *> gvectorinter;
+QMutex gMutexInter;
+
+
+static interunit * FindInterUnitByName(const char * strname)
+{
+    interunit * p = 0;
+    int i;
+    int nsize;
+    nsize = gvectorinter.size();
+    for(i=0;i<nsize;i++)
+    {
+        if(strncmp(strname,gvectorinter.at(i)->strintername,256) == 0)
+        {
+            return (gvectorinter.at(i));
+        }
+    }
+    return p;
+}
+
+
+intercomm::intercomm(const char * strsmname,const unsigned int nBufSize,const unsigned int nMaxPacCount,const int nMode)
+{
+    strncpy(mstrsmname,strsmname,256);
+
+    mnMode = nMode;
+    if(nMode == ModeWrite)
+    {
+        gMutexInter.lock();
+        interunit * p = FindInterUnitByName(strsmname);
+        if(p == 0)
+        {
+            interunit * pnewinter = new interunit;
+            strncpy(pnewinter->strintername,strsmname,256);
+            pnewinter->strdatabuf = new char[sizeof(procinter_info)+nMaxPacCount*sizeof(procinter_head) + nBufSize];
+            pnewinter->nPacCount = nMaxPacCount;
+            pnewinter->nbufsize = nBufSize;
+            gvectorinter.push_back(pnewinter);
+            mpa = pnewinter;
+
+
+        }
+        else
+        {
+            p->mMutexUnit.lock();
+            delete p->strdatabuf;
+            p->strdatabuf = new char[sizeof(procinter_info)+nMaxPacCount*sizeof(procinter_head) + nBufSize];
+            p->nPacCount = nMaxPacCount;
+            p->nbufsize = nBufSize;
+            p->mMutexUnit.unlock();
+            mpa = p;
+        }
+
+        interunit * pinter = (interunit * )mpa;
+        char * pdata = (char *)pinter->strdatabuf;
+        mpinfo = (procinter_info *)pdata;
+        mphead = (procinter_head *)(pdata+sizeof(procinter_info));
+        mpinfo->mCap = nMaxPacCount;
+        mpinfo->mnBufSize = nBufSize;
+        mpinfo->mFirst = 0;
+        mpinfo->mNext = 0;
+        mpinfo->mLock = 0;
+        pinter->mbHaveWriter = true;
+
+        gMutexInter.unlock();
+
+    }
+    else
+    {
+        gMutexInter.lock();
+        interunit * p = FindInterUnitByName(strsmname);
+        if(p == 0)
+        {
+            interunit * pnewinter = new interunit;
+            strncpy(pnewinter->strintername,strsmname,256);
+            gvectorinter.push_back(pnewinter);
+            mpa = pnewinter;
+        }
+        else
+        {
+            mpa = p;
+        }
+
+        interunit * pinter = (interunit * )mpa;
+        char * pdata = (char *)pinter->strdatabuf;
+        mpinfo = (procinter_info *)pdata;
+        mphead = (procinter_head *)(pdata+sizeof(procinter_info));
+
+        gMutexInter.unlock();
+    }
+}
+
+intercomm::~intercomm()
+{
+    if(mnMode == ModeRead)
+    {
+        stoplisten();
+        interunit * p = (interunit *)mpa;
+        p->mMutexUnit.lock();
+        InterListenUnit * plisten = (InterListenUnit *)mplistenunit;
+        int i;
+        for(i=0;i<p->mvectorlisten.size();i++)
+        {
+            if(plisten == p->mvectorlisten.at(i))
+            {
+                p->mvectorlisten.erase(p->mvectorlisten.begin() + i);
+                delete plisten;
+                break;
+            }
+        }
+        p->mMutexUnit.unlock();
+    }
+}
+
+int intercomm::listenmsg(ModuleFun xFun)
+{
+    if(mnMode == ModeWrite)
+    {
+        std::cout<<"intercomm::listenmsg this is Write. Can't Listen."<<std::endl;
+        return - 1;
+    }
+
+    interunit * p = (interunit *)mpa;
+    p->mMutexUnit.lock();
+    InterListenUnit * pnewlisten = new InterListenUnit;
+    pnewlisten->mbFunPlus = true;
+    pnewlisten->mFun = xFun;
+    pnewlisten->mpwc = &p->mwc;
+    p->mvectorlisten.push_back(pnewlisten);
+    p->mMutexUnit.unlock();
+
+    mplistenunit = (void *)pnewlisten;
+
+    mplistenthread = new std::thread(&intercomm::listernrun,this);
+    return 0;
+}
+
+int intercomm::listenmsg(SMCallBack pCall)
+{
+    if(mnMode == ModeWrite)
+    {
+        std::cout<<"intercomm::listenmsg this is Write. Can't Listen."<<std::endl;
+        return - 1;
+    }
+
+    interunit * p = (interunit *)mpa;
+    p->mMutexUnit.lock();
+    InterListenUnit * pnewlisten = new InterListenUnit;
+    pnewlisten->mbFunPlus = false;
+    pnewlisten->mpCall = pCall;
+    pnewlisten->mpwc = &p->mwc;
+    p->mvectorlisten.push_back(pnewlisten);
+    p->mMutexUnit.unlock();
+    mplistenunit = (void *)pnewlisten;
+    mplistenthread = new std::thread(&intercomm::listernrun,this);
+    return 0;
+}
+
+void intercomm::stoplisten()
+{
+    mblistenrun = false;
+    if(mplistenthread != 0)
+    {
+        mplistenthread->join();
+        mplistenthread = 0;
+    }
+}
+
+void intercomm::pausecomm()
+{
+    mbPause = true;
+}
+
+void intercomm::continuecomm()
+{
+    mbPause = false;
+}
+
+void intercomm::listernrun()
+{
+    InterListenUnit * pILU = (InterListenUnit * )mplistenunit;
+    QTime xTime;
+    xTime.start();
+    unsigned int nBufLen = 1;
+    unsigned int nRead;
+    char * str = new char[nBufLen];
+    unsigned int index =0;
+    QDateTime *pdt = new QDateTime();
+    interunit * pinter = (interunit *)mpa;
+    while(mblistenrun)
+    {
+        if(mbPause)
+        {
+            std::this_thread::sleep_for(std::chrono::milliseconds(100));
+            continue;
+        }
+        if(pinter->mbHaveWriter == false)
+        {
+            std::this_thread::sleep_for(std::chrono::milliseconds(100));
+            continue;
+        }
+        pILU->mWaitMutex.lock();
+        pILU->mpwc->wait(&pILU->mWaitMutex,100);
+        pILU->mWaitMutex.unlock();
+        int nRtn = readmsg(index,str,nBufLen,&nRead,pdt);
+        while ((nRtn != 0)&&(mblistenrun))
+        {
+            if(nRtn == -1)
+            {
+                nBufLen = nRead;
+                delete str;
+                if(nBufLen < 1)nBufLen = 1;
+                str = new char[nBufLen];
+            }
+            else
+            {
+                if(nRtn == -2)
+                {
+                   index = getcurrentnext();
+                }
+                else
+                {
+                   if(nRtn >0)
+                   {
+                       if(pILU->mbFunPlus)
+                       {
+                           pILU->mFun(str,nRtn,index,pdt,mstrsmname);
+                       }
+                       else
+                       {
+                          (*pILU->mpCall)(str,nRtn,index,pdt,mstrsmname);
+                       }
+                       index++;
+                   }
+                   else
+                   {
+                       std::this_thread::sleep_for(std::chrono::milliseconds(100));
+                   }
+                }
+            }
+            nRtn = readmsg(index,str,nBufLen,&nRead,pdt);
+        }
+
+    }
+
+    delete str;
+    delete pdt;
+}
+
+int intercomm::writemsg(const char *str, const unsigned int nSize)
+{
+    if(mbPause)return -2;
+    if(mnMode == ModeRead)
+    {
+        std::cout<<"Register read. can't write."<<std::endl;
+        return -1;
+    }
+    interunit * pinter = (interunit *)mpa;
+
+    pinter->mMutexUnit.lock();
+    char * pdata = (char *)pinter->strdatabuf;
+    mpinfo = (procinter_info *)pdata;
+    mphead = (procinter_head *)(pdata+sizeof(procinter_info));
+    if(nSize > pinter->nbufsize)
+    {
+        qDebug("procsm::writemsg message size is very big");
+        return -1;
+    }
+
+WRITEMSG:
+
+    char * pH,*pD;
+    QDateTime dt;
+    pH = (char *)pinter->strdatabuf;pH = pH + sizeof(procinter_info);
+    pD = (char *)pinter->strdatabuf;pD = pD + sizeof(procinter_info) + pinter->nPacCount * sizeof(procinter_head);
+    procinter_head * phh = (procinter_head *)pH;
+    unsigned int nPac = mpinfo->mNext - mpinfo->mFirst;
+    if(nPac>=pinter->nPacCount)
+    {
+        unsigned int nRemove = pinter->nPacCount/3;
+        if(nRemove == 0)nRemove = 1;
+        MoveMem(nRemove);
+        goto WRITEMSG;
+    }
+    if(nPac == 0)
+    {
+        memcpy(pD,str,nSize);
+        dt = QDateTime::currentDateTime();
+        phh->SetDate(dt);
+        phh->mindex = mpinfo->mNext;
+        phh->mnPos = 0;
+        phh->mnLen = nSize;
+        mpinfo->mNext = mpinfo->mNext+1;
+    }
+    else
+    {
+        if(((phh+nPac-1)->mnPos+(phh+nPac-1)->mnLen + nSize)>=pinter->nbufsize)
+        {
+            unsigned int nRemove = pinter->nPacCount/2;
+            if(nRemove == 0)nRemove = 1;
+            MoveMem(nRemove);
+            goto WRITEMSG;
+        }
+        else
+        {
+            unsigned int nPos = (phh+nPac-1)->mnPos + (phh+nPac-1)->mnLen;
+            memcpy(pD+nPos,str,nSize);
+            dt = QDateTime::currentDateTime();
+            (phh+nPac)->SetDate(dt);
+            (phh+nPac)->mindex = mpinfo->mNext;
+            (phh+nPac)->mnPos = nPos;
+            (phh+nPac)->mnLen = nSize;
+            mpinfo->mNext = mpinfo->mNext+1;
+        }
+    }
+
+    const unsigned int nTM = 0x6fffffff;
+    if((mpinfo->mNext >nTM)&&(mpinfo->mFirst>nTM))
+    {
+       nPac = mpinfo->mNext - mpinfo->mFirst;
+       unsigned int i;
+       for(i=0;i<nPac;i++)
+       {
+           (phh+i)->mindex = (phh+i)->mindex-nTM;
+       }
+       mpinfo->mFirst = mpinfo->mFirst-nTM;
+       mpinfo->mNext = mpinfo->mNext - nTM;
+    }
+
+    pinter->mMutexUnit.unlock();
+    pinter->mwc.wakeAll();
+    return 0;
+}
+
+int intercomm::MoveMem(const unsigned int nSize)
+{
+    unsigned int nRemove = nSize;
+    if(nRemove == 0)return -1;
+    interunit * pinter = (interunit *)mpa;
+    char * pH,*pD;
+    pH = (char *)pinter->strdatabuf;pH = pH + sizeof(procinter_info);
+    pD = (char *)pinter->strdatabuf;pD = pD + sizeof(procinter_info) + pinter->nPacCount * sizeof(procinter_head);
+    procinter_head * phh = (procinter_head *)pH;
+    unsigned int nPac = mpinfo->mNext - mpinfo->mFirst;
+
+    if(nRemove >nPac)
+    {
+        nRemove = nPac;
+    }
+
+    if(nRemove == nPac)
+    {
+        mpinfo->mFirst = mpinfo->mFirst + (unsigned int)nRemove;
+        return 0;
+    }
+
+    unsigned int i;
+    int nDataMove = 0;
+    for(i=0;i<nRemove;i++)
+    {
+        procinter_head * phd = phh+i;
+        nDataMove = nDataMove + phd->mnLen;
+    }
+    unsigned int nDataTotal;
+    for(i=0;i<(nPac - nRemove);i++)
+    {
+        memcpy(phh+i,phh+i+nRemove,sizeof(procinter_head));
+        (phh+i)->mnPos = (phh+i)->mnPos - nDataMove;
+    }
+    nDataTotal = (phh + nPac-nRemove-1)->mnPos + (phh+nPac-nRemove-1)->mnLen;
+    char * strtem = new char[pinter->nbufsize];
+    memcpy(strtem,pD+nDataMove,nDataTotal);
+    memcpy(pD,strtem,nDataTotal);
+    delete strtem;
+
+    mpinfo->mFirst = mpinfo->mFirst + (unsigned int)nRemove;
+    return 0;
+}
+
+int intercomm::readmsg(unsigned int index, char *str, unsigned int nMaxSize, unsigned int *nRead, QDateTime *pdt)
+{
+    int nRtn = 0;
+
+    interunit * pinter = (interunit *)mpa;
+
+    if(pinter->nbufsize == 0)return 0;
+    char * pdata = (char *)pinter->strdatabuf;
+    mpinfo = (procinter_info *)pdata;
+    mphead = (procinter_head *)(pdata+sizeof(procinter_info));
+
+    if((index< mpinfo->mFirst)||(index > mpinfo->mNext))
+    {
+        nRtn = -2;
+    }
+    if(nRtn != (-2))
+    {
+        if(index == mpinfo->mNext)
+        {
+            nRtn = 0;
+        }
+        else
+        {
+            char * pH,*pD;
+ //           pH = (char *)mpASM->data();pH = pH + 2*sizeof(unsigned int);
+
+ //           pD = (char *)mpASM->data();pD = pD + 2*sizeof(unsigned int) + mnMaxPacCount * sizeof(procsm_head);
+            pD = (char *)pinter->strdatabuf;pD = pD+ sizeof(procinter_info) + mpinfo->mCap*sizeof(procinter_head);
+            pH = (char *)pinter->strdatabuf;pH = pH+sizeof(procinter_info);
+            procinter_head * phh = (procinter_head *)pH;
+            unsigned int nPac = mpinfo->mNext - mpinfo->mFirst;
+            if(nPac == 0)
+            {
+                nRtn = 0;
+            }
+            else
+            {
+                unsigned int nPos = index - mpinfo->mFirst;
+                *nRead = (phh+nPos)->mnLen;
+                if((phh+nPos)->mnLen > nMaxSize)
+                {
+                    nRtn = -1;
+
+                }
+                else
+                {
+        //            qDebug("read pos = %d",(phh+nPos)->mnPos);
+                   memcpy(str,pD + (phh+nPos)->mnPos,(phh+nPos)->mnLen);
+          //         qDebug("read pos = %d",(phh+nPos)->mnPos);
+                   nRtn = (phh+nPos)->mnLen;
+                   (phh+nPos)->GetDate(pdt);
+           //        memcpy(pdt,&((phh+nPos)->mdt),sizeof(QDateTime));
+                }
+            }
+        }
+    }
+    return nRtn;
+}
+
+unsigned int intercomm::getcurrentnext()
+{
+    unsigned int nNext;
+    interunit * pinter = (interunit *)mpa;
+    char * pdata = (char *)pinter->strdatabuf;
+    mpinfo = (procinter_info *)pdata;
+    mphead = (procinter_head *)(pdata+sizeof(procinter_info));
+    nNext = mpinfo->mNext;
+    return nNext;
+}
+
+}

+ 109 - 0
src1/common/modulecomm/inter/intercomm.h

@@ -0,0 +1,109 @@
+#ifndef INTERCOMM_H
+#define INTERCOMM_H
+
+#include <QDateTime>
+#include "vector"
+#include <functional>
+#include <thread>
+
+typedef void (* SMCallBack)(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
+using namespace std::placeholders;
+typedef std::function<void(const char * ,const unsigned int , const unsigned int , QDateTime * ,const char *)> ModuleFun;
+
+
+class procinter_info
+{
+public:
+  unsigned int mFirst;
+  unsigned int mNext;
+  unsigned int mCap;
+  unsigned int mLock;
+  unsigned int mnBufSize;
+};
+
+class procinter_head
+{
+public:
+    unsigned short mYear;
+    unsigned char mMonth;
+    unsigned char mDay;
+    unsigned char mHour;
+    unsigned char mMinute;
+    unsigned char mSec;
+    unsigned short mMSec;
+    unsigned int mindex;
+    unsigned int mnPos;
+    unsigned int mnLen;
+public:
+    void SetDate(QDateTime dt)
+    {
+        mYear = dt.date().year();
+        mMonth = dt.date().month();
+        mDay = dt.date().day();
+        mHour = dt.time().hour();
+        mMinute = dt.time().minute();
+        mSec = dt.time().second();
+        mMSec = dt.time().msec();
+    }
+    void GetDate(QDateTime * pdt)
+    {
+        QDate dt;
+        dt.setDate(mYear,mMonth,mDay);
+        QTime time;
+        time.setHMS(mHour,mMinute,mSec,mMSec);
+        pdt->setDate(dt);
+        pdt->setTime(time);
+
+    }
+};
+
+
+namespace  iv {
+
+class intercomm
+{
+public:
+    intercomm(const char * strsmname,const unsigned int nBufSize,const unsigned int nMaxPacCount,const int nMode);
+    ~intercomm();
+
+    int listenmsg(SMCallBack pCall);
+    int listenmsg(ModuleFun xFun);
+    void stoplisten();
+
+    void pausecomm();
+    void continuecomm();
+
+    const static int ModeRead = 1;
+    const static int ModeWrite = 0;
+
+    int writemsg(const char * str,const unsigned int nSize);
+
+private:
+
+
+    char mstrsmname[256];
+    int mnMode;
+    void * mpa;
+    void * mplistenunit;
+
+private:
+    void listernrun();
+    bool mblistenrun = true;
+    bool mbPause = false;
+    std::thread * mplistenthread = 0;
+
+    procinter_info * mpinfo;
+    procinter_head * mphead;
+
+
+private:
+
+    int readmsg(unsigned int index,char * str,unsigned int nMaxSize,unsigned int * nRead,QDateTime * pdt);
+    int MoveMem(const unsigned int nSize);
+    unsigned int getcurrentnext();
+};
+}
+
+
+
+#endif // INTERCOMM_H

+ 60 - 0
src1/common/modulecomm/inter/modulecomm_inter.cpp

@@ -0,0 +1,60 @@
+#include "modulecomm_inter.h"
+
+#include <iostream>
+
+#include "intercomm.h"
+
+namespace iv {
+
+
+
+modulecomm_inter::modulecomm_inter()
+{
+
+}
+
+void modulecomm_inter::RegisterSend(const char *strcommname, const unsigned int nBufSize, const unsigned int nMsgBufCount)
+{
+    iv::intercomm * pinter = new iv::intercomm(strcommname,nBufSize,nMsgBufCount,iv::intercomm::ModeWrite);
+    mpinter = (void *)pinter;
+}
+
+void modulecomm_inter::RegisterRecv(const char *strcommname, SMCallBack pCall)
+{
+    iv::intercomm * pif = new iv::intercomm(strcommname,0,0,iv::intercomm::ModeRead);
+    pif->listenmsg(pCall);
+    mpinter = (void *)pif;
+}
+
+void modulecomm_inter::RegisterRecvPlus(const char *strcommname, ModuleFun xFun)
+{
+    iv::intercomm * pif = new iv::intercomm(strcommname,0,0,iv::intercomm::ModeRead);
+    pif->listenmsg(xFun);
+    mpinter = (void *)pif;
+}
+
+void modulecomm_inter::ModuleSendMsg(const char *strdata, const unsigned int nDataLen)
+{
+    iv::intercomm * pif = (iv::intercomm *)mpinter;
+    pif->writemsg(strdata,nDataLen);
+}
+
+void modulecomm_inter::ContintuComm()
+{
+    iv::intercomm * pif = (iv::intercomm *)mpinter;
+    pif->continuecomm();
+}
+
+void modulecomm_inter::PauseComm()
+{
+    iv::intercomm * pif = (iv::intercomm *)mpinter;
+    pif->pausecomm();
+}
+
+void modulecomm_inter::Unregister()
+{
+    iv::intercomm * pif = (iv::intercomm *)mpinter;
+    delete pif;
+}
+
+}

+ 30 - 0
src1/common/modulecomm/inter/modulecomm_inter.h

@@ -0,0 +1,30 @@
+#ifndef MODULECOMM_INTER_H
+#define MODULECOMM_INTER_H
+
+#include "modulecomm_base.h"
+
+namespace iv {
+
+
+class modulecomm_inter : public modulecomm_base
+{
+public:
+    modulecomm_inter();
+
+    void RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount);
+    void RegisterRecv(const char * strcommname,SMCallBack pCall);
+    void RegisterRecvPlus(const char * strcommname,ModuleFun xFun);
+    virtual void ModuleSendMsg(const char * strdata,const unsigned int nDataLen);
+    virtual void Unregister();
+    virtual void PauseComm();
+    virtual void ContintuComm();
+
+private:
+    void * mpinter;
+};
+
+}
+
+
+
+#endif // MODULECOMM_INTER_H

+ 7 - 0
src1/common/modulecomm/inter/modulecomm_inter.pri

@@ -0,0 +1,7 @@
+HEADERS += \
+    $$PWD/intercomm.h \
+    $$PWD/modulecomm_inter.h
+
+SOURCES += \
+    $$PWD/intercomm.cpp \
+    $$PWD/modulecomm_inter.cpp

+ 17 - 2
src1/common/modulecomm/modulecomm.pro

@@ -17,10 +17,12 @@ DEFINES += QT_DEPRECATED_WARNINGS
 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
 
 SOURCES += \
-    modulecomm.cpp
+    modulecomm.cpp \
+    modulecomm_base.cpp
 
 HEADERS += \
-    modulecomm.h
+    modulecomm.h \
+    modulecomm_base.h
 
 CONFIG += plugin
 
@@ -31,6 +33,19 @@ unix {
 !isEmpty(target.path): INSTALLS += target
 
 
+
+!include(./shm/modulecomm_shm.pri ) {
+    error( "Couldn't find the modulecomm_shm.pri file!" )
+}
+
+!include(./inter/modulecomm_inter.pri ) {
+    error( "Couldn't find the modulecomm_inter.pri file!" )
+}
+
+!include(./fastrtps/modulecomm_fastrtps.pri ) {
+    error( "Couldn't find the modulecomm_fastrtps.pri file!" )
+}
+
 INCLUDEPATH += $$PWD/../modulecomm_shm
 INCLUDEPATH += $$PWD/../modulecomm_fastrtps
 INCLUDEPATH += $$PWD/../modulecomm_inter

+ 11 - 0
src1/common/modulecomm/modulecomm_base.cpp

@@ -0,0 +1,11 @@
+#include "modulecomm_base.h"
+
+
+namespace  iv {
+
+modulecomm_base::modulecomm_base()
+{
+
+}
+
+}

+ 33 - 0
src1/common/modulecomm/modulecomm_base.h

@@ -0,0 +1,33 @@
+#ifndef MODULECOMM_BASE_H
+#define MODULECOMM_BASE_H
+
+
+#include <QDateTime>
+
+#include <functional>
+
+#ifndef IV_MODULE_FUN
+
+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);
+#define IV_MODULE_FUN
+#endif
+
+namespace  iv {
+
+
+class modulecomm_base
+{
+public:
+    modulecomm_base();
+
+public:
+    virtual void ModuleSendMsg(const char * strdata,const unsigned int nDataLen) = 0;
+    virtual void Unregister() = 0;
+    virtual void PauseComm() = 0;
+    virtual void ContintuComm() = 0;
+};
+
+}
+
+#endif // MODULECOMM_BASE_H

+ 54 - 0
src1/common/modulecomm/shm/b/modulecomm_shm.cpp

@@ -0,0 +1,54 @@
+#include "modulecomm_shm.h"
+#include "procsm_if.h"
+#include "procsm.h"
+#include <iostream>
+
+namespace iv {
+namespace modulecomm_shm {
+
+void *  RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount)
+{
+
+    procsm_if * pif = new procsm_if(strcommname,nBufSize,nMsgBufCount,procsm::ModeWrite);
+    return (void *)pif;
+}
+
+void  *  RegisterRecv(const char * strcommname,SMCallBack pCall)
+{
+    procsm_if * pif = new procsm_if(strcommname,0,0,procsm::ModeRead);
+    pif->listenmsg(pCall);
+    return (void *)pif;
+}
+
+void * MODULECOMMSHARED_SHM_EXPORT RegisterRecvPlus(const char * strcommname,ModuleFun xFun)
+{
+    procsm_if * pif = new procsm_if(strcommname,0,0,procsm::ModeRead);
+    pif->listenmsg(xFun);
+    return (void *)pif;
+}
+void  ModuleSendMsg(void * pHandle,const char * strdata,const unsigned int nDataLen)
+{
+    procsm_if * pif = (procsm_if *)pHandle;
+    pif->writemsg(strdata,nDataLen);
+}
+
+void  Unregister(void * pHandle)
+{
+    procsm_if * pif = (procsm_if *)pHandle;
+    delete pif;
+}
+
+void PauseComm(void *pHandle)
+{
+    procsm_if * pif = (procsm_if *)pHandle;
+    pif->pausecomm();
+}
+
+void ContintuComm(void *pHandle)
+{
+    procsm_if * pif = (procsm_if *)pHandle;
+    pif->continuecomm();
+}
+
+}
+}

+ 42 - 0
src1/common/modulecomm/shm/b/modulecomm_shm.h

@@ -0,0 +1,42 @@
+#ifndef MODULECOMM_SHM_H
+#define MODULECOMM_SHM_H
+
+#include <QtCore/qglobal.h>
+#include <QDateTime>
+
+#include <functional>
+
+#if defined(MODULECOMM_SHM_LIBRARY)
+#  define MODULECOMMSHARED_SHM_EXPORT Q_DECL_EXPORT
+#else
+#  define MODULECOMMSHARED_SHM_EXPORT Q_DECL_IMPORT
+#endif
+
+
+
+//#include <iostream>
+//#include <thread>
+
+#ifndef IV_MODULE_FUN
+
+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);
+#define IV_MODULE_FUN
+#endif
+namespace iv {
+namespace modulecomm_shm {
+void * MODULECOMMSHARED_SHM_EXPORT RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount);
+void * MODULECOMMSHARED_SHM_EXPORT RegisterRecv(const char * strcommname,SMCallBack pCall);
+void * MODULECOMMSHARED_SHM_EXPORT RegisterRecvPlus(const char * strcommname,ModuleFun xFun);
+void MODULECOMMSHARED_SHM_EXPORT ModuleSendMsg(void * pHandle,const char * strdata,const unsigned int nDataLen);
+void MODULECOMMSHARED_SHM_EXPORT Unregister(void * pHandle);
+void MODULECOMMSHARED_SHM_EXPORT PauseComm(void * pHandle);
+void MODULECOMMSHARED_SHM_EXPORT ContintuComm(void * pHandle);
+
+}
+
+}
+
+
+
+#endif 

+ 61 - 0
src1/common/modulecomm/shm/modulecomm_shm.cpp

@@ -0,0 +1,61 @@
+#include "modulecomm_shm.h"
+
+#include "procsm_if.h"
+#include "procsm.h"
+#include <iostream>
+
+namespace iv {
+
+
+modulecomm_shm::modulecomm_shm()
+{
+
+
+}
+
+void modulecomm_shm::RegisterSend(const char *strcommname, const unsigned int nBufSize, const unsigned int nMsgBufCount)
+{
+    procsm_if * pif = new procsm_if(strcommname,nBufSize,nMsgBufCount,procsm::ModeWrite);
+    mpif = pif;
+}
+
+void modulecomm_shm::RegisterRecv(const char *strcommname, SMCallBack pCall)
+{
+    procsm_if * pif = new procsm_if(strcommname,0,0,procsm::ModeRead);
+    pif->listenmsg(pCall);
+    mpif = pif;
+}
+
+void modulecomm_shm::RegisterRecvPlus(const char *strcommname, ModuleFun xFun)
+{
+    procsm_if * pif = new procsm_if(strcommname,0,0,procsm::ModeRead);
+    pif->listenmsg(xFun);
+    mpif = (void *)pif;
+}
+
+void modulecomm_shm::ModuleSendMsg(const char *strdata, const unsigned int nDataLen)
+{
+    procsm_if * pif = (procsm_if *)mpif;
+    pif->writemsg(strdata,nDataLen);
+}
+
+void modulecomm_shm::PauseComm()
+{
+    procsm_if * pif = (procsm_if *)mpif;
+    pif->pausecomm();
+}
+
+void modulecomm_shm::ContintuComm()
+{
+    procsm_if * pif = (procsm_if *)mpif;
+    pif->continuecomm();
+}
+
+void modulecomm_shm::Unregister()
+{
+    procsm_if * pif = (procsm_if *)mpif;
+    delete pif;
+    mpif =0;
+}
+
+}

+ 28 - 0
src1/common/modulecomm/shm/modulecomm_shm.h

@@ -0,0 +1,28 @@
+#ifndef MODULECOMM_SHM_H
+#define MODULECOMM_SHM_H
+
+#include "modulecomm_base.h"
+
+namespace iv {
+
+
+class modulecomm_shm : public modulecomm_base
+{
+public:
+    modulecomm_shm();
+
+    void RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount);
+    void RegisterRecv(const char * strcommname,SMCallBack pCall);
+    void RegisterRecvPlus(const char * strcommname,ModuleFun xFun);
+    virtual void ModuleSendMsg(const char * strdata,const unsigned int nDataLen);
+    virtual void Unregister();
+    virtual void PauseComm();
+    virtual void ContintuComm();
+
+private :
+    void * mpif = 0;
+};
+
+}
+
+#endif // MODULECOMM_SHM_H

+ 9 - 0
src1/common/modulecomm/shm/modulecomm_shm.pri

@@ -0,0 +1,9 @@
+HEADERS += \
+    $$PWD/modulecomm_shm.h \
+    $$PWD/procsm.h \
+    $$PWD/procsm_if.h
+
+SOURCES += \
+    $$PWD/modulecomm_shm.cpp \
+    $$PWD/procsm.cpp \
+    $$PWD/procsm_if.cpp

+ 378 - 0
src1/common/modulecomm/shm/procsm.cpp

@@ -0,0 +1,378 @@
+#include <iostream>
+#include <thread>
+#include <QTime>
+#include <QThread>
+
+#include "procsm.h"
+
+
+class AttachThread : public QThread
+{
+  public:
+    AttachThread(QSharedMemory * pa,bool & bAttach)
+    {
+       mbAttach = bAttach;
+       mpa = pa;
+       mbrun = true;
+    }
+    QSharedMemory * mpa;
+    bool mbAttach = false;
+    bool mbrun = true;
+    void run()
+    {
+        mbAttach = mpa->attach();
+        mbrun = false;
+    }
+};
+
+procsm::procsm(const char * strsmname,const unsigned int nBufSize,const unsigned int nMaxPacCount,const int nMode)
+{
+//    mnBufSize = nBufSize;
+
+//    qDebug("create dbus");
+
+    mpASM = new QSharedMemory(strsmname);
+
+    if(nMode == ModeWrite)
+    {
+
+        mmodulemsg_type.mnBufSize = nBufSize;
+        mmodulemsg_type.mnMsgBufCount = nMaxPacCount;
+        strncpy(mmodulemsg_type.mstrmsgname,strsmname,255);
+#ifdef USEDBUS
+        mmsg = QDBusMessage::createSignal("/catarc/adc",  "adc.adciv.modulecomm", strsmname);
+        mmsg<<1;
+#endif
+
+        bool bAttach = false;
+        AttachThread AT(mpASM,bAttach);
+        AT.start();
+        QTime xTime;
+        xTime.start();
+        while(xTime.elapsed()<100)
+        {
+            if(AT.mbrun == false)
+            {
+                bAttach = AT.mbAttach;
+                break;
+            }
+        }
+ //       qDebug("time is %d",xTime.elapsed());
+        if(xTime.elapsed()>= 1000)
+        {
+            qDebug("in 1000ms Attach fail.terminate it .");
+            AT.terminate();
+            bAttach = false;
+        }
+
+ //       if(!mpASM->attach())
+        if(!bAttach)
+        {
+
+            mpASM->create(sizeof(procsm_info)+nMaxPacCount*sizeof(procsm_head) + nBufSize);
+            char * p = (char *)mpASM->data();
+            mpinfo = (procsm_info *)p;
+            mphead = (procsm_head *)(p+sizeof(procsm_info));
+            mpinfo->mCap = nMaxPacCount;
+            mpinfo->mnBufSize = nBufSize;
+            mpinfo->mFirst = 0;
+            mpinfo->mNext = 0;
+            mpinfo->mLock = 0;
+        }
+
+
+
+
+        if(mpASM->isAttached())
+        {
+
+            mbAttach = true;
+            char * p = (char *)mpASM->data();
+            mpinfo = (procsm_info *)p;
+            mphead = (procsm_head *)(p+sizeof(procsm_info));
+            mnMaxPacCount = mpinfo->mCap;
+            mnBufSize = mpinfo->mnBufSize;
+    //        qDebug("attach successful");
+            mstrtem = new char[mnBufSize];
+
+#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
+        }
+        else
+        {
+          mbAttach = false;
+            qDebug("Share Memory Error.");
+        }
+
+
+    }
+}
+
+#ifdef USEDBUS
+    void procsm::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
+
+bool procsm::AttachMem()
+{
+    mpASM->attach();
+    if(mpASM->isAttached())
+    {
+        mbAttach = true;
+        char * p = (char *)mpASM->data();
+        mpinfo = (procsm_info *)p;
+        mphead = (procsm_head *)(p+sizeof(procsm_info));
+        mnMaxPacCount = mpinfo->mCap;
+        mnBufSize = mpinfo->mnBufSize;
+        return true;
+    }
+    else
+    {
+        return false;
+    }
+}
+
+int procsm::MoveMem(const unsigned int nSize)
+{
+//    qDebug("move mem");
+     unsigned int nRemove = nSize;
+     if(nRemove == 0)return -1;
+
+//     unsigned int * pIndexFirst = (unsigned int *)mpASM->data();
+//     unsigned int * pIndexNext = pIndexFirst+1;
+//     qDebug("first = %d next = %d",*pIndexFirst,*pIndexNext);
+//    unsigned int * pIndexNext = pIndexFirst;
+    char * pH,*pD;
+    pH = (char *)mpASM->data();pH = pH + sizeof(procsm_info);
+    pD = (char *)mpASM->data();pD = pD + sizeof(procsm_info) + mnMaxPacCount * sizeof(procsm_head);
+    procsm_head * phh = (procsm_head *)pH;
+    unsigned int nPac = mpinfo->mNext - mpinfo->mFirst;
+
+    if(nRemove >nPac)
+    {
+  //      qDebug("procsm::MoveMem nRemove > nPac nRemove = %d",nRemove);
+        nRemove = nPac;
+    }
+
+    if(nRemove == nPac)
+    {
+        mpinfo->mFirst = mpinfo->mFirst + (unsigned int)nRemove;
+        return 0;
+    }
+
+    unsigned int i;
+    int nDataMove = 0;
+    for(i=0;i<nRemove;i++)
+    {
+        procsm_head * phd = phh+i;
+        nDataMove = nDataMove + phd->mnLen;
+    }
+    unsigned int nDataTotal;
+    for(i=0;i<(nPac - nRemove);i++)
+    {
+        memcpy(phh+i,phh+i+nRemove,sizeof(procsm_head));
+        (phh+i)->mnPos = (phh+i)->mnPos - nDataMove;
+    }
+    nDataTotal = (phh + nPac-nRemove-1)->mnPos + (phh+nPac-nRemove-1)->mnLen;
+    memcpy(mstrtem,pD+nDataMove,nDataTotal);
+    memcpy(pD,mstrtem,nDataTotal);
+
+//    for(i=0;i<nDataTotal;i++)
+//    {
+//        *(pD+i) = *(pD+i+nDataMove);
+//    }
+    mpinfo->mFirst = mpinfo->mFirst + (unsigned int)nRemove;
+    return 0;
+}
+
+int procsm::writemsg(const char *str, const unsigned int nSize)
+{
+    if(nSize > mnBufSize)
+    {
+        qDebug("procsm::writemsg message size is very big");
+        return -1;
+    }
+    if(mbAttach == false)
+    {
+        std::cout<<"ShareMemory Attach fail."<<std::endl;
+        return -1;
+    }
+    mpASM->lock();
+
+
+
+//    unsigned int * pIndexFirst = (unsigned int *)mpASM->data();
+//    unsigned int * pIndexNext = pIndexFirst+1;
+    if(mpinfo->mLock == 1)
+    {
+        std::cout<<"ShareMemory have lock.Init."<<std::endl;
+        mpinfo->mLock = 0;
+        mpinfo->mFirst = 0;
+        mpinfo->mNext = 0;
+    }
+    mpinfo->mLock =1;
+WRITEMSG:
+    char * pH,*pD;
+    QDateTime dt;
+    pH = (char *)mpASM->data();pH = pH + sizeof(procsm_info);
+    pD = (char *)mpASM->data();pD = pD + sizeof(procsm_info) + mnMaxPacCount * sizeof(procsm_head);
+    procsm_head * phh = (procsm_head *)pH;
+    unsigned int nPac = mpinfo->mNext - mpinfo->mFirst;
+    if(nPac>=mnMaxPacCount)
+    {
+        unsigned int nRemove = mnMaxPacCount/3;
+        if(nRemove == 0)nRemove = 1;
+        MoveMem(nRemove);
+        goto WRITEMSG;
+    }
+    if(nPac == 0)
+    {
+        memcpy(pD,str,nSize);
+        dt = QDateTime::currentDateTime();
+    //    phh->mdt = dt;
+        phh->SetDate(dt);
+   //     memcpy(&phh->mdt,&dt,sizeof(QDateTime));
+   //     phh->mdt = QDateTime::currentDateTime();
+        phh->mindex = mpinfo->mNext;
+        phh->mnPos = 0;
+        phh->mnLen = nSize;
+        mpinfo->mNext = mpinfo->mNext+1;
+    }
+    else
+    {
+        if(((phh+nPac-1)->mnPos+(phh+nPac-1)->mnLen + nSize)>=mnBufSize)
+        {
+            unsigned int nRemove = mnMaxPacCount/2;
+            if(nRemove == 0)nRemove = 1;
+            MoveMem(nRemove);
+            goto WRITEMSG;
+        }
+        else
+        {
+            unsigned int nPos = (phh+nPac-1)->mnPos + (phh+nPac-1)->mnLen;
+     //       qDebug("write pos = %d",nPos);
+            memcpy(pD+nPos,str,nSize);
+            dt = QDateTime::currentDateTime();
+            (phh+nPac)->SetDate(dt);
+ //           memcpy(&(phh+nPac)->mdt,&dt,sizeof(QDateTime));
+ //           (phh+nPac)->mdt = QDateTime::currentDateTime();
+            (phh+nPac)->mindex = mpinfo->mNext;
+            (phh+nPac)->mnPos = nPos;
+            (phh+nPac)->mnLen = nSize;
+            mpinfo->mNext = mpinfo->mNext+1;
+        }
+    }
+
+    const unsigned int nTM = 0x6fffffff;
+    if((mpinfo->mNext >nTM)&&(mpinfo->mFirst>nTM))
+    {
+       nPac = mpinfo->mNext - mpinfo->mFirst;
+       unsigned int i;
+       for(i=0;i<nPac;i++)
+       {
+           (phh+i)->mindex = (phh+i)->mindex-nTM;
+       }
+       mpinfo->mFirst = mpinfo->mFirst-nTM;
+       mpinfo->mNext = mpinfo->mNext - nTM;
+    }
+
+    mpinfo->mLock = 0;
+    mpASM->unlock();
+#ifdef USEDBUS
+    QDBusConnection::sessionBus().send(mmsg);
+#endif
+    return 0;
+}
+
+unsigned int procsm::getcurrentnext()
+{
+
+
+    unsigned int nNext;
+    mpASM->lock();
+    nNext = mpinfo->mNext;
+    mpASM->unlock();
+    return nNext;
+}
+
+
+//if return 0 No Data.
+//if return -1 nMaxSize is small
+//if retrun -2 index is not in range,call getcurrentnext get position
+//if return > 0 readdata
+int procsm::readmsg(unsigned int index, char *str, unsigned int nMaxSize,unsigned int * nRead,QDateTime * pdt)
+{
+    if(mbAttach == false)
+    {
+        std::cout<<"ShareMemory Attach fail."<<std::endl;
+        return -1;
+    }
+    int nRtn = 0;
+    mpASM->lock();
+
+    if((index< mpinfo->mFirst)||(index > mpinfo->mNext))
+    {
+        nRtn = -2;
+    }
+    if(nRtn != (-2))
+    {
+        if(index == mpinfo->mNext)
+        {
+            nRtn = 0;
+        }
+        else
+        {
+            char * pH,*pD;
+ //           pH = (char *)mpASM->data();pH = pH + 2*sizeof(unsigned int);
+
+ //           pD = (char *)mpASM->data();pD = pD + 2*sizeof(unsigned int) + mnMaxPacCount * sizeof(procsm_head);
+            pD = (char *)mpASM->data();pD = pD+ sizeof(procsm_info) + mpinfo->mCap*sizeof(procsm_head);
+            pH = (char *)mpASM->data();pH = pH+sizeof(procsm_info);
+            procsm_head * phh = (procsm_head *)pH;
+            unsigned int nPac = mpinfo->mNext - mpinfo->mFirst;
+            if(nPac == 0)
+            {
+                nRtn = 0;
+            }
+            else
+            {
+                unsigned int nPos = index - mpinfo->mFirst;
+                *nRead = (phh+nPos)->mnLen;
+                if((phh+nPos)->mnLen > nMaxSize)
+                {
+                    nRtn = -1;
+
+                }
+                else
+                {
+        //            qDebug("read pos = %d",(phh+nPos)->mnPos);
+                   memcpy(str,pD + (phh+nPos)->mnPos,(phh+nPos)->mnLen);
+          //         qDebug("read pos = %d",(phh+nPos)->mnPos);
+                   nRtn = (phh+nPos)->mnLen;
+                   (phh+nPos)->GetDate(pdt);
+           //        memcpy(pdt,&((phh+nPos)->mdt),sizeof(QDateTime));
+                }
+            }
+        }
+    }
+    mpASM->unlock();
+    return nRtn;
+}
+

+ 112 - 0
src1/common/modulecomm/shm/procsm.h

@@ -0,0 +1,112 @@
+#ifndef PROCSM_H
+#define PROCSM_H
+
+#include <QThread>
+#include <QSharedMemory>
+#include <QDateTime>
+#include <QList>
+#include <QVariant>
+
+#ifdef USEDBUS
+#include <QtDBus/QDBusMessage>
+#include <QtDBus/QDBusConnection>
+
+#endif
+
+#include "ivmodulemsg_type.h"
+
+class procsm_info
+{
+public:
+  unsigned int mFirst;
+  unsigned int mNext;
+  unsigned int mCap;
+  unsigned int mLock;
+  unsigned int mnBufSize;
+};
+
+class procsm_head
+{
+public:
+    unsigned short mYear;
+    unsigned char mMonth;
+    unsigned char mDay;
+    unsigned char mHour;
+    unsigned char mMinute;
+    unsigned char mSec;
+    unsigned short mMSec;
+    unsigned int mindex;
+    unsigned int mnPos;
+    unsigned int mnLen;
+public:
+    void SetDate(QDateTime dt)
+    {
+        mYear = dt.date().year();
+        mMonth = dt.date().month();
+        mDay = dt.date().day();
+        mHour = dt.time().hour();
+        mMinute = dt.time().minute();
+        mSec = dt.time().second();
+        mMSec = dt.time().msec();
+    }
+    void GetDate(QDateTime * pdt)
+    {
+        QDate dt;
+        dt.setDate(mYear,mMonth,mDay);
+        QTime time;
+        time.setHMS(mHour,mMinute,mSec,mMSec);
+        pdt->setDate(dt);
+        pdt->setTime(time);
+
+    }
+};
+
+class procsm : public QObject
+{
+#ifdef USEDBUS
+    Q_OBJECT
+
+#endif
+public:
+    procsm(const char * strsmname,const unsigned int nBufSize,const unsigned int nMaxPacCount,const int nMode);
+    int writemsg(const char * str,const unsigned int nSize);
+    unsigned int getcurrentnext();
+    int readmsg(unsigned int index,char * str,unsigned int nMaxSize,unsigned int * nRead,QDateTime * pdt);
+
+    bool AttachMem();
+
+private:
+    int MoveMem(const unsigned int nSize);
+    QSharedMemory * mpASM;
+    unsigned int mnBufSize;
+    unsigned int mnMaxPacCount;
+    procsm_info * mpinfo;
+    procsm_head * mphead;
+
+    bool mbAttach;
+
+    char * mstrtem;
+
+public:
+    const static int ModeRead = 1;
+    const static int ModeWrite = 0;
+
+    iv::modulemsg_type mmodulemsg_type;
+
+#ifdef USEDBUS
+private slots:
+    void onQuery();
+
+#endif
+private:
+#ifdef USEDBUS
+    QDBusMessage mmsg;
+    QDBusMessage mmsgres;  //Response Message Query;
+
+#endif
+
+
+
+};
+
+#endif // PROCSM_H

+ 310 - 0
src1/common/modulecomm/shm/procsm_if.cpp

@@ -0,0 +1,310 @@
+#include "procsm_if.h"
+#include <QTimer>
+
+#include <iostream>
+
+
+
+procsm_if_readthread::procsm_if_readthread(procsm *pPSM,SMCallBack pCall,const char * strsmname)
+{
+    mpPSM = pPSM;
+    mpCall = pCall;
+    strncpy(mstrsmname,strsmname,255);
+
+#ifdef USEDBUS
+    bool bconnect = QDBusConnection::sessionBus().connect(QString(),"/catarc/adc",  "adc.adciv.modulecomm", strsmname,this,SLOT(onNewMsg(int)));
+    if(bconnect == false)
+    {
+        std::cout<<"procsm_if_readthread::procsm_if_readthread bconect is false"<<std::endl;
+    }
+#endif
+}
+
+procsm_if_readthread::procsm_if_readthread(procsm *pPSM,ModuleFun xFun,const char * strsmname)
+{
+    mpPSM = pPSM;
+    mFun = xFun;
+    strncpy(mstrsmname,strsmname,255);
+    mbFunPlus = true;
+
+#ifdef USEDBUS
+    bool bconnect = QDBusConnection::sessionBus().connect(QString(),"/catarc/adc",  "adc.adciv.modulecomm", strsmname,this,SLOT(onNewMsg(int)));
+    if(bconnect == false)
+    {
+        std::cout<<"procsm_if_readthread::procsm_if_readthread bconect is false"<<std::endl;
+        mbDBUSOK = false;
+        QTimer * timer = new QTimer();
+        timer->setTimerType(Qt::PreciseTimer);
+        delete timer;
+    }
+#endif
+}
+
+
+#ifdef USELCM
+    void procsm_if_readthread::handlerMethod(const lcm::ReceiveBuffer *rbuf, const std::string &channel)
+    {
+        qDebug("lcm receiv data. ");
+        mxindex++;
+        QDateTime dt = QDateTime::currentDateTime();
+        if(mbFunPlus)
+        {
+            mFun((char *)rbuf->data,rbuf->data_size,mxindex,&dt,mstrsmname);
+        }
+        else
+        {
+           (*mpCall)((char *)rbuf->data,rbuf->data_size,mxindex,&dt,mstrsmname);
+        }
+    }
+#endif
+
+
+void procsm_if_readthread::puaseread()
+{
+    mbRun = false;
+}
+
+void procsm_if_readthread::continueread()
+{
+    mbRun = true;
+}
+
+void procsm_if_readthread::run()
+{
+#ifdef USELCM
+    mlcm.subscribe(mstrsmname,&procsm_if_readthread::handlerMethod,this);
+    while(!QThread::isInterruptionRequested())
+    {
+        mlcm.handle();
+    }
+    return;
+#endif
+    QTime xTime;
+    xTime.start();
+    unsigned int nBufLen = 1;
+    unsigned int nRead;
+    char * str = new char[nBufLen];
+    unsigned int index =0;
+
+
+    QDateTime *pdt = new QDateTime();
+
+    bool bAttach = false;
+    while(!QThread::isInterruptionRequested())
+    {
+        if(mbRun == false)
+        {
+            msleep(10);
+            continue;
+        }
+        if(bAttach == false)
+        {
+            bAttach = mpPSM->AttachMem();
+            if(bAttach == false)
+            {
+                msleep(1);
+                continue;
+            }
+            else
+            {
+                index = mpPSM->getcurrentnext();
+            }
+        }
+
+        int nRtn = mpPSM->readmsg(index,str,nBufLen,&nRead,pdt);
+        if(nRtn == 0)
+        {
+#ifdef USEDBUS
+            if(mbDBUSOK == true)
+            {
+                mWaitMutex.lock();
+                mwc.wait(&mWaitMutex,10);
+                mWaitMutex.unlock();
+            }
+            else
+            {
+                msleep(1);
+            }
+#else
+            msleep(1);
+#endif
+        }
+        else
+        {
+            if(nRtn == -1)
+            {
+                nBufLen = nRead;
+                delete str;
+                if(nBufLen < 1)nBufLen = 1;
+                str = new char[nBufLen];
+            }
+            else
+            {
+                if(nRtn == -2)
+                {
+                   index = mpPSM->getcurrentnext();
+                }
+                else
+                {
+                   if(nRtn >0)
+                   {
+                       if(mbFunPlus)
+                       {
+                           mFun(str,nRtn,index,pdt,mstrsmname);
+                       }
+                       else
+                       {
+                          (*mpCall)(str,nRtn,index,pdt,mstrsmname);
+                       }
+                       index++;
+                   }
+                   else
+                   {
+                       usleep(100);
+                   }
+                }
+            }
+        }
+
+    }
+    delete str;
+    delete pdt;
+//    qDebug("Thread finish.");
+}
+
+#ifdef USEDBUS
+
+void procsm_if_readthread::onNewMsg(int x)
+{
+    if(x == 100)std::cout<<x<<std::endl;
+    mwc.wakeAll();
+//    qDebug("wake");
+}
+
+#endif
+
+procsm_if::procsm_if(const char * strsmname,const unsigned int nBufSize,const unsigned int nMaxPacCount,const int nMode)
+{
+    strncpy(mstrsmname,strsmname,255);
+#ifdef USELCM
+    if(nMode == procsm::ModeWrite)
+    {
+
+    }
+    else
+    {
+
+    }
+    return;
+#endif
+    mpPSM = new procsm(strsmname,nBufSize,nMaxPacCount,nMode);
+    mnType = nMode;
+
+    mTimer.setTimerType(Qt::PreciseTimer);
+
+}
+
+procsm_if::~procsm_if()
+{
+    if(mnType == procsm::ModeRead)
+    {
+
+        mpReadThread->requestInterruption();
+        while(!mpReadThread->isFinished())
+        {
+
+        }
+        delete mpReadThread;
+    }
+    delete mpPSM;
+}
+
+
+
+int procsm_if::writemsg(const char *str, const unsigned int nSize)
+{
+    if(mbRun == false)return -2;
+#ifdef USELCM
+    int nres = mlcm.publish(mstrsmname,str,nSize);
+    qDebug("publish message. res = %d",nres);
+    return 0;
+#endif
+    if(mnType == procsm::ModeRead)return -1; //this is listen.
+    return mpPSM->writemsg(str,nSize);
+}
+
+#ifdef USELCM
+    void procsm_if::handlerMethod(const lcm::ReceiveBuffer *rbuf, const std::string &channel)
+    {
+        qDebug("receiv data. ");
+    }
+#endif
+int procsm_if::listenmsg(SMCallBack pCall)
+{
+//#ifdef USELCM
+////     mlcm.subscribe(mstrsmname,&handlerMethod2);
+//    mlcm.subscribe(mstrsmname,&procsm_if::handlerMethod,this);
+//    while(true)
+//    {
+//        mlcm.handle();
+//    }
+//    return 0;
+//#endif
+    if(mnType == procsm::ModeWrite)return -1; //listening.
+    mpReadThread = new procsm_if_readthread(mpPSM,pCall,mstrsmname);
+//    mpReadThread->setPriority(QThread::TimeCriticalPriority);
+//    mpReadThread->start();
+    mpReadThread->start(QThread::HighestPriority);
+//    mnType = 1;
+    return 0;
+}
+
+int procsm_if::listenmsg(ModuleFun xFun)
+{
+//#ifdef USELCM
+//    mlcm.subscribe(mstrsmname,&procsm_if::handlerMethod,this);
+//    while(true)
+//    {
+//        mlcm.handle();
+//    }
+//    return 0;
+//#endif
+    if(mnType == procsm::ModeWrite)return -1; //listening.
+    mpReadThread = new procsm_if_readthread(mpPSM,xFun,mstrsmname);
+//    mpReadThread->setPriority(QThread::TimeCriticalPriority);
+//    mpReadThread->start();
+    mpReadThread->start(QThread::HighestPriority);
+//    mnType = 1;
+    return 0;
+}
+
+void procsm_if::stoplisten()
+{
+    if(mnType != 1)return;
+    mpReadThread->requestInterruption();
+    while(!mpReadThread->isFinished());
+    mnType = 0;
+//    mpReadThread->deleteLater();
+    qDebug("stop listen ok");
+}
+
+void procsm_if::pausecomm()
+{
+    mbRun = false;
+    if(mnType == procsm::ModeRead)
+    {
+        mpReadThread->puaseread();
+    }
+}
+
+void procsm_if::continuecomm()
+{
+    mbRun = true;
+    if(mnType == procsm::ModeRead)
+    {
+        mpReadThread->continueread();
+    }
+}
+
+
+

+ 99 - 0
src1/common/modulecomm/shm/procsm_if.h

@@ -0,0 +1,99 @@
+#ifndef PROCSM_IF_H
+#define PROCSM_IF_H
+
+#include <QThread>
+#include <QTimer>
+#include <QWaitCondition>
+#include <QMutex>
+#include <functional>
+
+#ifdef USEDBUS
+#include <QtDBus/QDBusMessage>
+#include <QtDBus/QDBusConnection>
+
+#endif
+
+#include "procsm.h"
+
+typedef void (* SMCallBack)(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
+using namespace std::placeholders;
+typedef std::function<void(const char * ,const unsigned int , const unsigned int , QDateTime * ,const char *)> ModuleFun;
+
+class procsm_if_readthread:public QThread
+{
+    Q_OBJECT
+public:
+#ifdef USELCM
+
+#endif
+    procsm_if_readthread(procsm * pPSM,SMCallBack pCall,const char * strsmname);
+    procsm_if_readthread(procsm * pPSM,ModuleFun xFun,const char * strsmname);
+
+    void puaseread();
+    void continueread();
+private slots:
+#ifdef USEDBUS
+    void onNewMsg(int x);
+#endif
+private:
+
+#ifdef USELCM
+    lcm::LCM mlcm;
+    void handlerMethod(const lcm::ReceiveBuffer *rbuf,const std::string &channel);
+    int mxindex = 0;
+#endif
+    void run();
+    procsm * mpPSM;
+    SMCallBack  mpCall;
+    ModuleFun mFun;
+    char mstrsmname[256];
+
+    QWaitCondition mwc;
+
+    QMutex mWaitMutex;
+    bool mbFunPlus = false;
+    bool mbRun = true;
+    bool mbDBUSOK = true;
+};
+
+class procsm_if
+{
+
+
+public:
+    procsm_if(const char * strsmname,const unsigned int nBufSize,const unsigned int nMaxPacCount,const int nMode);
+    ~procsm_if();
+
+    int writemsg(const char * str,const unsigned int nSize);
+    int listenmsg(SMCallBack pCall);
+    int listenmsg(ModuleFun xFun);
+    void stoplisten();
+
+    void pausecomm();
+    void continuecomm();
+
+
+private:
+    procsm * mpPSM;
+    int mnType;
+    procsm_if_readthread * mpReadThread;
+    QTimer mTimer;
+    char mstrsmname[256];
+
+    bool mbRun = true;
+
+
+
+#ifdef USELCM
+    lcm::LCM mlcm;
+    void handlerMethod(const lcm::ReceiveBuffer *rbuf,const std::string &channel);
+#endif
+
+
+
+
+
+
+};
+
+#endif // PROCSM_IF_H