From 722f28728117c0928f38feab55ad3bd23ab6e598 Mon Sep 17 00:00:00 2001 From: TSC21 Date: Fri, 10 Jan 2020 09:55:05 +0000 Subject: [PATCH] msg: urtps: change the topic Data Type name to match expected on ROS2 --- msg/templates/urtps/Publisher.cpp.em | 11 +++++++++-- msg/templates/urtps/Publisher.h.em | 8 ++++---- msg/templates/urtps/Subscriber.cpp.em | 12 ++++++++++-- msg/templates/urtps/Subscriber.h.em | 8 ++++---- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/msg/templates/urtps/Publisher.cpp.em b/msg/templates/urtps/Publisher.cpp.em index 71f375e516..2b171e53f6 100644 --- a/msg/templates/urtps/Publisher.cpp.em +++ b/msg/templates/urtps/Publisher.cpp.em @@ -95,13 +95,20 @@ bool @(topic)_Publisher::init() if(mp_participant == nullptr) return false; +@[if ros2_distro and (ros2_distro == "dashing" or ros2_distro == "eloquent")]@ + // Type name should match the expected type name on ROS2 + // Note: the change is being done here since the 'fastrtpsgen' example + // generator does not allow to change the type naming on the template + @(topic)DataType.setName("@(package)::msg::dds_::@(topic)_"); +@[end if]@ + // Register the type - Domain::registerType(mp_participant, static_cast(&myType)); + Domain::registerType(mp_participant, static_cast(&@(topic)DataType)); // Create Publisher PublisherAttributes Wparam; Wparam.topic.topicKind = NO_KEY; - Wparam.topic.topicDataType = myType.getName(); //This type MUST be registered + Wparam.topic.topicDataType = @(topic)DataType.getName(); @[if ros2_distro]@ @[ if ros2_distro == "ardent"]@ Wparam.qos.m_partition.push_back("rt"); diff --git a/msg/templates/urtps/Publisher.h.em b/msg/templates/urtps/Publisher.h.em index 4b1b356efa..b5aa12a37c 100644 --- a/msg/templates/urtps/Publisher.h.em +++ b/msg/templates/urtps/Publisher.h.em @@ -111,15 +111,15 @@ private: } m_listener; @[if 1.5 <= fastrtpsgen_version <= 1.7]@ @[ if ros2_distro]@ - @(package)::msg::dds_::@(topic)_PubSubType myType; + @(package)::msg::dds_::@(topic)_PubSubType @(topic)DataType; @[ else]@ - @(topic)_PubSubType myType; + @(topic)_PubSubType @(topic)DataType; @[ end if]@ @[else]@ @[ if ros2_distro]@ - @(package)::msg::@(topic)PubSubType myType; + @(package)::msg::@(topic)PubSubType @(topic)DataType; @[ else]@ - @(topic)PubSubType myType; + @(topic)PubSubType @(topic)DataType; @[ end if]@ @[end if]@ }; diff --git a/msg/templates/urtps/Subscriber.cpp.em b/msg/templates/urtps/Subscriber.cpp.em index fd957052ef..54b6080f1e 100644 --- a/msg/templates/urtps/Subscriber.cpp.em +++ b/msg/templates/urtps/Subscriber.cpp.em @@ -94,13 +94,21 @@ bool @(topic)_Subscriber::init(uint8_t topic_ID, std::condition_variable* t_send if(mp_participant == nullptr) return false; +@[if ros2_distro and (ros2_distro == "dashing" or ros2_distro == "eloquent")]@ + // Type name should match the expected type name on ROS2 + // Note: the change is being done here since the 'fastrtpsgen' example + // generator does not allow to change the type naming on the template of + // "*PubSubTypes.cpp" file + @(topic)DataType.setName("@(package)::msg::dds_::@(topic)_"); +@[end if]@ + //Register the type - Domain::registerType(mp_participant, static_cast(&myType)); + Domain::registerType(mp_participant, static_cast(&@(topic)DataType)); // 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.topicDataType = @(topic)DataType.getName(); @[if ros2_distro]@ @[ if ros2_distro == "ardent"]@ Rparam.qos.m_partition.push_back("rt"); diff --git a/msg/templates/urtps/Subscriber.h.em b/msg/templates/urtps/Subscriber.h.em index c7c992b9a8..dba740e100 100644 --- a/msg/templates/urtps/Subscriber.h.em +++ b/msg/templates/urtps/Subscriber.h.em @@ -142,15 +142,15 @@ private: } m_listener; @[if 1.5 <= fastrtpsgen_version <= 1.7]@ @[ if ros2_distro]@ - @(package)::msg::dds_::@(topic)_PubSubType myType; + @(package)::msg::dds_::@(topic)_PubSubType @(topic)DataType; @[ else]@ - @(topic)_PubSubType myType; + @(topic)_PubSubType @(topic)DataType; @[ end if]@ @[else]@ @[ if ros2_distro]@ - @(package)::msg::@(topic)PubSubType myType; + @(package)::msg::@(topic)PubSubType @(topic)DataType; @[ else]@ - @(topic)PubSubType myType; + @(topic)PubSubType @(topic)DataType; @[ end if]@ @[end if]@ };