microRTPS: use FastRTPS version instead of FastRTPSGen version to generate conditional code

This commit is contained in:
TSC21
2020-03-11 15:13:07 +00:00
committed by Nuno Marques
parent c7d86b73d4
commit 7612879ffd
10 changed files with 76 additions and 90 deletions
+3 -3
View File
@@ -69,7 +69,7 @@ except AttributeError:
#include <fastrtps/Domain.h>
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
@[if fastrtps_version <= 1.7]@
#include <fastrtps/utils/eClock.h>
@[end if]@
@@ -85,7 +85,7 @@ bool @(topic)_Publisher::init()
// Create RTPSParticipant
ParticipantAttributes PParam;
PParam.rtps.builtin.domainId = 0;
@[if 1.5 <= fastrtpsgen_version <= 1.7 or ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal" or ros2_distro == "dashing"]@
@[if fastrtps_version <= 1.8]@
PParam.rtps.builtin.leaseDuration = c_TimeInfinite;
@[else]@
PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
@@ -149,7 +149,7 @@ void @(topic)_Publisher::PubListener::onPublicationMatched(Publisher* pub, Match
}
}
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
@[if fastrtps_version <= 1.7]@
@[ if ros2_distro]@
void @(topic)_Publisher::publish(@(package)::msg::dds_::@(topic)_* st)
@[ else]@
+3 -3
View File
@@ -68,7 +68,7 @@ except AttributeError:
#include <fastrtps/fastrtps_fwd.h>
#include <fastrtps/publisher/PublisherListener.h>
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
@[if fastrtps_version <= 1.7]@
#include "@(topic)_PubSubTypes.h"
@[else]@
#include "@(topic)PubSubTypes.h"
@@ -84,7 +84,7 @@ public:
virtual ~@(topic)_Publisher();
bool init();
void run();
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
@[if fastrtps_version <= 1.7]@
@[ if ros2_distro]@
void publish(@(package)::msg::dds_::@(topic)_* st);
@[ else]@
@@ -109,7 +109,7 @@ private:
void onPublicationMatched(Publisher* pub, MatchingInfo& info);
int n_matched;
} m_listener;
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
@[if fastrtps_version <= 1.7]@
@[ if ros2_distro]@
@(package)::msg::dds_::@(topic)_PubSubType @(topic)DataType;
@[ else]@
+4 -4
View File
@@ -20,7 +20,7 @@ from px_generate_uorb_topic_files import MsgScope # this is in Tools/
send_topics = [(alias[idx] if alias[idx] else s.short_name) for idx, s in enumerate(spec) if scope[idx] == MsgScope.SEND]
recv_topics = [(alias[idx] if alias[idx] else s.short_name) for idx, s in enumerate(spec) if scope[idx] == MsgScope.RECEIVE]
package = package[0]
fastrtpsgen_version = fastrtpsgen_version[0]
fastrtps_version = fastrtps_version[0]
try:
ros2_distro = ros2_distro[0].decode("utf-8")
except AttributeError:
@@ -74,7 +74,7 @@ except AttributeError:
@[for topic in recv_topics]@
@[ if 1.5 <= fastrtpsgen_version <= 1.7]@
@[ if fastrtps_version <= 1.7]@
@[ if ros2_distro]@
using @(topic)_msg_t = @(package)::msg::dds_::@(topic)_;
@[ else]@
@@ -89,7 +89,7 @@ using @(topic)_msg_t = @(topic);
@[ end if]@
@[end for]@
@[for topic in send_topics]@
@[ if 1.5 <= fastrtpsgen_version <= 1.7]@
@[ if fastrtps_version <= 1.7]@
@[ if ros2_distro]@
using @(topic)_msg_t = @(package)::msg::dds_::@(topic)_;
@[ else]@
@@ -131,7 +131,7 @@ private:
@[end for]@
@[end if]@
@[if 1.5 <= fastrtpsgen_version <= 1.7 or not ros2_distro]@
@[if fastrtps_version <= 1.7 or not ros2_distro]@
template <class T>
uint8_t getMsgSysID(T* msg) { return msg->sys_id_(); }
+2 -2
View File
@@ -84,7 +84,7 @@ bool @(topic)_Subscriber::init(uint8_t topic_ID, std::condition_variable* t_send
// Create RTPSParticipant
ParticipantAttributes PParam;
PParam.rtps.builtin.domainId = 0; // MUST BE THE SAME AS IN THE PUBLISHER
@[if 1.5 <= fastrtpsgen_version <= 1.7 or ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal" or ros2_distro == "dashing"]@
@[if fastrtps_version <= 1.8]@
PParam.rtps.builtin.leaseDuration = c_TimeInfinite;
@[else]@
PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
@@ -199,7 +199,7 @@ bool @(topic)_Subscriber::hasMsg()
return false;
}
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
@[if fastrtps_version <= 1.7]@
@[ if ros2_distro]@
@(package)::msg::dds_::@(topic)_ @(topic)_Subscriber::getMsg()
@[ else]@
+4 -4
View File
@@ -68,7 +68,7 @@ except AttributeError:
#include <fastrtps/fastrtps_fwd.h>
#include <fastrtps/subscriber/SubscriberListener.h>
#include <fastrtps/subscriber/SampleInfo.h>
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
@[if fastrtps_version <= 1.7]@
#include "@(topic)_PubSubTypes.h"
@[else]@
#include "@(topic)PubSubTypes.h"
@@ -89,7 +89,7 @@ public:
bool init(uint8_t topic_ID, std::condition_variable* t_send_queue_cv, std::mutex* t_send_queue_mutex, std::queue<uint8_t>* t_send_queue);
void run();
bool hasMsg();
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
@[if fastrtps_version <= 1.7]@
@[ if ros2_distro]@
@(package)::msg::dds_::@(topic)_ getMsg();
@[ else]@
@@ -118,7 +118,7 @@ private:
SampleInfo_t m_info;
int n_matched;
int n_msg;
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
@[if fastrtps_version <= 1.7]@
@[ if ros2_distro]@
@(package)::msg::dds_::@(topic)_ msg;
@[ else]@
@@ -140,7 +140,7 @@ private:
std::mutex has_msg_mutex;
} m_listener;
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
@[if fastrtps_version <= 1.7]@
@[ if ros2_distro]@
@(package)::msg::dds_::@(topic)_PubSubType @(topic)DataType;
@[ else]@
@@ -17,7 +17,7 @@ from px_generate_uorb_topic_helper import * # this is in Tools/
from px_generate_uorb_topic_files import MsgScope # this is in Tools/
package = package[0]
fastrtpsgen_version = fastrtpsgen_version[0]
fastrtps_version = fastrtps_version[0]
try:
ros2_distro = ros2_distro[0].decode("utf-8")
except AttributeError:
+2 -2
View File
@@ -17,7 +17,7 @@ from px_generate_uorb_topic_helper import * # this is in Tools/
from px_generate_uorb_topic_files import MsgScope # this is in Tools/
package = package[0]
fastrtpsgen_version = fastrtpsgen_version[0]
fastrtps_version = fastrtps_version[0]
try:
ros2_distro = ros2_distro[0].decode("utf-8")
except AttributeError:
@@ -86,7 +86,7 @@ static constexpr int64_t TRIGGER_RESET_THRESHOLD_NS = 100ll * 1000ll * 1000ll;
static constexpr int REQUEST_RESET_COUNTER_THRESHOLD = 5;
@# Sets the timesync DDS type according to the FastRTPS and ROS2 version
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
@[if fastrtps_version <= 1.7]@
@[ if ros2_distro]@
using timesync_msg_t = @(package)::msg::dds_::Timesync_;
@[ else]@
+6 -6
View File
@@ -57,7 +57,7 @@ def get_include_directives(spec):
if genmsg.msgs.is_valid_constant_type(genmsg.msgs.bare_msg_type(field.type)):
continue
builtin_type = str(field.base_type).replace('px4/', '')
if 1.5 <= fastrtpsgen_version <= 1.7:
if fastrtps_version <= 1.7:
include_directive = '#include "%s_.idl"' % builtin_type
else:
include_directive = '#include "%s.idl"' % builtin_type
@@ -77,12 +77,12 @@ def get_idl_type_name(field_type):
def add_msg_field(field):
if (not field.is_header):
if field.is_array:
if 1.5 <= fastrtpsgen_version <= 1.7:
if fastrtps_version <= 1.7:
print(' {0}__{1}_array_{2} {3}_;'.format(topic, str(get_idl_type_name(field.base_type)).replace(" ", "_"), str(field.array_len), field.name))
else:
print(' {0}__{1}_array_{2} {3};'.format(topic, str(get_idl_type_name(field.base_type)).replace(" ", "_"), str(field.array_len), field.name))
else:
if 1.5 <= fastrtpsgen_version <= 1.7:
if fastrtps_version <= 1.7:
base_type = get_idl_type_name(field.base_type) + "_" if get_idl_type_name(field.base_type) in builtin_types else get_idl_type_name(field.base_type)
else:
base_type = get_idl_type_name(field.base_type) if get_idl_type_name(field.base_type) in builtin_types else get_idl_type_name(field.base_type)
@@ -96,7 +96,7 @@ def add_msg_fields():
def add_array_typedefs():
for field in spec.parsed_fields():
if not field.is_header and field.is_array:
if 1.5 <= fastrtpsgen_version <= 1.7:
if fastrtps_version <= 1.7:
base_type = get_idl_type_name(field.base_type) + "_" if get_idl_type_name(field.base_type) in builtin_types else get_idl_type_name(field.base_type)
else:
base_type = get_idl_type_name(field.base_type) if get_idl_type_name(field.base_type) in builtin_types else get_idl_type_name(field.base_type)
@@ -127,14 +127,14 @@ def add_msg_constants():
@add_msg_constants()
@# Array types
@add_array_typedefs()
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
@[if fastrtps_version <= 1.7]@
struct @(topic)_
@[else]@
struct @(topic)
@[end if]@
{
@add_msg_fields()
@[if 1.5 <= fastrtpsgen_version <= 1.7]@
@[if fastrtps_version <= 1.7]@
}; // struct @(topic)_
#pragma keylist @(topic)_