如何获取openDDS UDP套接字接收的数据

时间:2019-12-26 11:05:47

标签: sockets udp opendds

我的项目包含以下主要由QTCreator IDE核心库和OpenDDS实现的类:

1-绑定UDP套接字以接收使用QUDPSocket实现的数据的NetworkDefinition类。 2- BinaryToDDS类,将从QUDPSocket接收的数据映射到dds定义的主题。 2-我的发布者使用第一类和第二类作为库来接收消息,然后将它们写入合适的订户。

我的根cmake文件: // =====

cmake_minimum_required(VERSION 3.0)
project(DataToDDSLib)

#always add the needed library before
add_subdirectory(DataMappingProtocol)

FIND_PACKAGE(OpenDDS)
FIND_PACKAGE(Qt5 REQUIRED
    Widgets
    Network
)
set(src "${CMAKE_CURRENT_SOURCE_DIR}/..")


# Publisher
add_executable(publisher
    ${src}/publisher.cpp
    )

OPENDDS_TARGET_SOURCES(publisher
    ${src}/MyData.idl
    ${src}/ MyDataWriter.cpp
    ${src}/ MyDataWriter.h
    )

target_link_libraries(publisher DataMappingProtocol)
target_link_libraries(publisher Qt5::Widgets)
target_link_libraries(publisher Qt5::Network )
target_link_libraries(publisher OpenDDS::OpenDDS)

# Subscriber
add_executable(subscriber
    ${src}/subscriber.cpp
    )
OPENDDS_TARGET_SOURCES(subscriber
    ${src}/ MyData.idl
    ${src}/ MyDataListener.cpp
    ${src}/ MyDataListener.h
    )

target_link_libraries(subscriber OpenDDS::OpenDDS)

// ====

在我的Publisher.cpp中

int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
    DDS::DomainParticipantFactory_var dpf;
    DDS::DomainParticipant_var participant;

//DataToDDS class includes the last data instance received so the writer can access and publish the data.
    DataToDDS* mapper = new DataToDDS();// the include of the socket binding from qt library in cmake


    try {

        std::cout << "Starting publisher test1" << std::endl;
        {
            // Initialize DomainParticipantFactory
            dpf = TheParticipantFactoryWithArgs(argc, argv);

            std::cout << "Starting publisher with " << argc << " args" << std::endl;

            // Create DomainParticipant
            participant = dpf->create_participant(GROUND_DOMAIN_ID,
                                                  PARTICIPANT_QOS_DEFAULT,
                                                  0,
                                                  OpenDDS::DCPS::DEFAULT_STATUS_MASK);

......

// ====

我的网络配置文件(由于我正在处理qtcreator中定义的库中的套接字,所以未添加udp tarsport类型):

[common]
DCPSGlobalTransportConfig=$file
DCPSDefaultDiscovery=DEFAULT_RTPS

[transport/the_rtps_transport]
transport_type=rtps_udp

// ======

  • 现在,当我运行发布者时,我没有收到任何数据,我不确定是否必须在网络配置文件中初始化udp传输类型。

我可以将udp用作传输类型,但是找不到如何从opendds库获取套接字数据,然后将数据映射到正确的主题以将其写入订阅者的任何示例。

0 个答案:

没有答案