forked from Archive/PX4-Autopilot
microRTPS: use package.version to compare FastRTPS lib versions
This commit is contained in:
parent
1f4b2d1d53
commit
1ea5280299
|
@ -11,6 +11,7 @@
|
||||||
@# - ids (List) list of all RTPS msg ids
|
@# - ids (List) list of all RTPS msg ids
|
||||||
@###############################################
|
@###############################################
|
||||||
@{
|
@{
|
||||||
|
from packaging import version
|
||||||
import genmsg.msgs
|
import genmsg.msgs
|
||||||
|
|
||||||
from px_generate_uorb_topic_helper import * # this is in Tools/
|
from px_generate_uorb_topic_helper import * # this is in Tools/
|
||||||
|
@ -69,13 +70,12 @@ except AttributeError:
|
||||||
|
|
||||||
#include <fastrtps/Domain.h>
|
#include <fastrtps/Domain.h>
|
||||||
|
|
||||||
@[if fastrtps_version <= 1.7]@
|
@[if version.parse(fastrtps_version) <= version.parse('1.7')]@
|
||||||
#include <fastrtps/utils/eClock.h>
|
#include <fastrtps/utils/eClock.h>
|
||||||
@[end if]@
|
@[end if]@
|
||||||
|
|
||||||
#include "@(topic)_Publisher.h"
|
#include "@(topic)_Publisher.h"
|
||||||
|
|
||||||
|
|
||||||
@(topic)_Publisher::@(topic)_Publisher()
|
@(topic)_Publisher::@(topic)_Publisher()
|
||||||
: mp_participant(nullptr),
|
: mp_participant(nullptr),
|
||||||
mp_publisher(nullptr)
|
mp_publisher(nullptr)
|
||||||
|
@ -91,7 +91,7 @@ bool @(topic)_Publisher::init()
|
||||||
// Create RTPSParticipant
|
// Create RTPSParticipant
|
||||||
ParticipantAttributes PParam;
|
ParticipantAttributes PParam;
|
||||||
PParam.rtps.builtin.domainId = 0;
|
PParam.rtps.builtin.domainId = 0;
|
||||||
@[if fastrtps_version <= 1.8]@
|
@[if version.parse(fastrtps_version) <= version.parse('1.8')]@
|
||||||
PParam.rtps.builtin.leaseDuration = c_TimeInfinite;
|
PParam.rtps.builtin.leaseDuration = c_TimeInfinite;
|
||||||
@[else]@
|
@[else]@
|
||||||
PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
|
PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
@# - ids (List) list of all RTPS msg ids
|
@# - ids (List) list of all RTPS msg ids
|
||||||
@###############################################
|
@###############################################
|
||||||
@{
|
@{
|
||||||
|
from packaging import version
|
||||||
import genmsg.msgs
|
import genmsg.msgs
|
||||||
|
|
||||||
from px_generate_uorb_topic_helper import * # this is in Tools/
|
from px_generate_uorb_topic_helper import * # this is in Tools/
|
||||||
|
@ -68,7 +69,7 @@ except AttributeError:
|
||||||
#include <fastrtps/fastrtps_fwd.h>
|
#include <fastrtps/fastrtps_fwd.h>
|
||||||
#include <fastrtps/publisher/PublisherListener.h>
|
#include <fastrtps/publisher/PublisherListener.h>
|
||||||
|
|
||||||
@[if fastrtps_version <= 1.7]@
|
@[if version.parse(fastrtps_version) <= version.parse('1.7')]@
|
||||||
#include "@(topic)_PubSubTypes.h"
|
#include "@(topic)_PubSubTypes.h"
|
||||||
@[else]@
|
@[else]@
|
||||||
#include "@(topic)PubSubTypes.h"
|
#include "@(topic)PubSubTypes.h"
|
||||||
|
@ -77,7 +78,7 @@ except AttributeError:
|
||||||
using namespace eprosima::fastrtps;
|
using namespace eprosima::fastrtps;
|
||||||
using namespace eprosima::fastrtps::rtps;
|
using namespace eprosima::fastrtps::rtps;
|
||||||
|
|
||||||
@[if fastrtps_version <= 1.7]@
|
@[if version.parse(fastrtps_version) <= version.parse('1.7')]@
|
||||||
@[ if ros2_distro]@
|
@[ if ros2_distro]@
|
||||||
using @(topic)_msg_t = @(package)::msg::dds_::@(topic)_;
|
using @(topic)_msg_t = @(package)::msg::dds_::@(topic)_;
|
||||||
using @(topic)_msg_datatype = @(package)::msg::dds_::@(topic)_PubSubType;
|
using @(topic)_msg_datatype = @(package)::msg::dds_::@(topic)_PubSubType;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
@###############################################
|
@###############################################
|
||||||
@{
|
@{
|
||||||
import os
|
import os
|
||||||
|
from packaging import version
|
||||||
|
|
||||||
import genmsg.msgs
|
import genmsg.msgs
|
||||||
|
|
||||||
|
@ -74,7 +75,7 @@ except AttributeError:
|
||||||
|
|
||||||
|
|
||||||
@[for topic in (recv_topics + send_topics)]@
|
@[for topic in (recv_topics + send_topics)]@
|
||||||
@[ if fastrtps_version <= 1.7]@
|
@[ if version.parse(fastrtps_version) <= version.parse('1.7')]@
|
||||||
@[ if ros2_distro]@
|
@[ if ros2_distro]@
|
||||||
using @(topic)_msg_t = @(package)::msg::dds_::@(topic)_;
|
using @(topic)_msg_t = @(package)::msg::dds_::@(topic)_;
|
||||||
@[ else]@
|
@[ else]@
|
||||||
|
@ -116,7 +117,7 @@ private:
|
||||||
@[end if]@
|
@[end if]@
|
||||||
|
|
||||||
/** Msg metada Getters **/
|
/** Msg metada Getters **/
|
||||||
@[if fastrtps_version <= 1.7 or not ros2_distro]@
|
@[if version.parse(fastrtps_version) <= version.parse('1.7') or not ros2_distro]@
|
||||||
template <class T>
|
template <class T>
|
||||||
inline uint64_t getMsgTimestamp(const T* msg) { return msg->timestamp_(); }
|
inline uint64_t getMsgTimestamp(const T* msg) { return msg->timestamp_(); }
|
||||||
|
|
||||||
|
@ -137,7 +138,7 @@ private:
|
||||||
@[end if]@
|
@[end if]@
|
||||||
|
|
||||||
/** Msg metadata Setters **/
|
/** Msg metadata Setters **/
|
||||||
@[if fastrtps_version <= 1.7 or not ros2_distro]@
|
@[if version.parse(fastrtps_version) <= version.parse('1.7') or not ros2_distro]@
|
||||||
template <class T>
|
template <class T>
|
||||||
inline uint64_t setMsgTimestamp(T* msg, const uint64_t& timestamp) { msg->timestamp_() = timestamp; }
|
inline uint64_t setMsgTimestamp(T* msg, const uint64_t& timestamp) { msg->timestamp_() = timestamp; }
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
@# - ids (List) list of all RTPS msg ids
|
@# - ids (List) list of all RTPS msg ids
|
||||||
@###############################################
|
@###############################################
|
||||||
@{
|
@{
|
||||||
|
from packaging import version
|
||||||
import genmsg.msgs
|
import genmsg.msgs
|
||||||
|
|
||||||
from px_generate_uorb_topic_helper import * # this is in Tools/
|
from px_generate_uorb_topic_helper import * # this is in Tools/
|
||||||
|
@ -90,7 +91,7 @@ bool @(topic)_Subscriber::init(uint8_t topic_ID, std::condition_variable* t_send
|
||||||
// Create RTPSParticipant
|
// Create RTPSParticipant
|
||||||
ParticipantAttributes PParam;
|
ParticipantAttributes PParam;
|
||||||
PParam.rtps.builtin.domainId = 0; // MUST BE THE SAME AS IN THE PUBLISHER
|
PParam.rtps.builtin.domainId = 0; // MUST BE THE SAME AS IN THE PUBLISHER
|
||||||
@[if fastrtps_version <= 1.8]@
|
@[if version.parse(fastrtps_version) <= version.parse('1.8')]@
|
||||||
PParam.rtps.builtin.leaseDuration = c_TimeInfinite;
|
PParam.rtps.builtin.leaseDuration = c_TimeInfinite;
|
||||||
@[else]@
|
@[else]@
|
||||||
PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
|
PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
@# - ids (List) list of all RTPS msg ids
|
@# - ids (List) list of all RTPS msg ids
|
||||||
@###############################################
|
@###############################################
|
||||||
@{
|
@{
|
||||||
|
from packaging import version
|
||||||
import genmsg.msgs
|
import genmsg.msgs
|
||||||
|
|
||||||
from px_generate_uorb_topic_helper import * # this is in Tools/
|
from px_generate_uorb_topic_helper import * # this is in Tools/
|
||||||
|
@ -68,7 +69,7 @@ except AttributeError:
|
||||||
#include <fastrtps/fastrtps_fwd.h>
|
#include <fastrtps/fastrtps_fwd.h>
|
||||||
#include <fastrtps/subscriber/SubscriberListener.h>
|
#include <fastrtps/subscriber/SubscriberListener.h>
|
||||||
#include <fastrtps/subscriber/SampleInfo.h>
|
#include <fastrtps/subscriber/SampleInfo.h>
|
||||||
@[if fastrtps_version <= 1.7]@
|
@[if version.parse(fastrtps_version) <= version.parse('1.7')]@
|
||||||
#include "@(topic)_PubSubTypes.h"
|
#include "@(topic)_PubSubTypes.h"
|
||||||
@[else]@
|
@[else]@
|
||||||
#include "@(topic)PubSubTypes.h"
|
#include "@(topic)PubSubTypes.h"
|
||||||
|
@ -81,7 +82,7 @@ except AttributeError:
|
||||||
using namespace eprosima::fastrtps;
|
using namespace eprosima::fastrtps;
|
||||||
using namespace eprosima::fastrtps::rtps;
|
using namespace eprosima::fastrtps::rtps;
|
||||||
|
|
||||||
@[if fastrtps_version <= 1.7]@
|
@[if version.parse(fastrtps_version) <= version.parse('1.7')]@
|
||||||
@[ if ros2_distro]@
|
@[ if ros2_distro]@
|
||||||
using @(topic)_msg_t = @(package)::msg::dds_::@(topic)_;
|
using @(topic)_msg_t = @(package)::msg::dds_::@(topic)_;
|
||||||
using @(topic)_msg_datatype = @(package)::msg::dds_::@(topic)_PubSubType;
|
using @(topic)_msg_datatype = @(package)::msg::dds_::@(topic)_PubSubType;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
@# - ids (List) list of all RTPS msg ids
|
@# - ids (List) list of all RTPS msg ids
|
||||||
@###############################################
|
@###############################################
|
||||||
@{
|
@{
|
||||||
|
from packaging import version
|
||||||
import genmsg.msgs
|
import genmsg.msgs
|
||||||
|
|
||||||
from px_generate_uorb_topic_helper import * # this is in Tools/
|
from px_generate_uorb_topic_helper import * # this is in Tools/
|
||||||
|
@ -86,7 +87,7 @@ static constexpr int64_t TRIGGER_RESET_THRESHOLD_NS = 100ll * 1000ll * 1000ll;
|
||||||
static constexpr int REQUEST_RESET_COUNTER_THRESHOLD = 5;
|
static constexpr int REQUEST_RESET_COUNTER_THRESHOLD = 5;
|
||||||
|
|
||||||
@# Sets the timesync DDS type according to the FastRTPS and ROS2 version
|
@# Sets the timesync DDS type according to the FastRTPS and ROS2 version
|
||||||
@[if fastrtps_version <= 1.7]@
|
@[if version.parse(fastrtps_version) <= version.parse('1.7')]@
|
||||||
@[ if ros2_distro]@
|
@[ if ros2_distro]@
|
||||||
using timesync_msg_t = @(package)::msg::dds_::Timesync_;
|
using timesync_msg_t = @(package)::msg::dds_::Timesync_;
|
||||||
@[ else]@
|
@[ else]@
|
||||||
|
@ -213,7 +214,7 @@ private:
|
||||||
inline void updateOffset(const uint64_t& offset) { _offset_ns.store(offset, std::memory_order_relaxed); }
|
inline void updateOffset(const uint64_t& offset) { _offset_ns.store(offset, std::memory_order_relaxed); }
|
||||||
|
|
||||||
/** Timesync msg Getters **/
|
/** Timesync msg Getters **/
|
||||||
@[if fastrtps_version <= 1.7 or not ros2_distro]@
|
@[if version.parse(fastrtps_version) <= version.parse('1.7') or not ros2_distro]@
|
||||||
inline uint64_t getMsgTimestamp(const timesync_msg_t* msg) { return msg->timestamp_(); }
|
inline uint64_t getMsgTimestamp(const timesync_msg_t* msg) { return msg->timestamp_(); }
|
||||||
inline uint8_t getMsgSysID(const timesync_msg_t* msg) { return msg->sys_id_(); }
|
inline uint8_t getMsgSysID(const timesync_msg_t* msg) { return msg->sys_id_(); }
|
||||||
inline uint8_t getMsgSeq(const timesync_msg_t* msg) { return msg->seq_(); }
|
inline uint8_t getMsgSeq(const timesync_msg_t* msg) { return msg->seq_(); }
|
||||||
|
@ -228,7 +229,7 @@ private:
|
||||||
@[end if]@
|
@[end if]@
|
||||||
|
|
||||||
/** Timesync msg Setters **/
|
/** Timesync msg Setters **/
|
||||||
@[if fastrtps_version <= 1.7 or not ros2_distro]@
|
@[if version.parse(fastrtps_version) <= version.parse('1.7') or not ros2_distro]@
|
||||||
inline uint64_t setMsgTimestamp(timesync_msg_t* msg, const uint64_t& timestamp) { msg->timestamp_() = timestamp; }
|
inline uint64_t setMsgTimestamp(timesync_msg_t* msg, const uint64_t& timestamp) { msg->timestamp_() = timestamp; }
|
||||||
inline uint8_t setMsgSysID(timesync_msg_t* msg, const uint8_t& sys_id) { msg->sys_id_() = sys_id; }
|
inline uint8_t setMsgSysID(timesync_msg_t* msg, const uint8_t& sys_id) { msg->sys_id_() = sys_id; }
|
||||||
inline uint8_t setMsgSeq(timesync_msg_t* msg, const uint8_t& seq) { msg->seq_() = seq; }
|
inline uint8_t setMsgSeq(timesync_msg_t* msg, const uint8_t& seq) { msg->seq_() = seq; }
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
@#
|
@#
|
||||||
@################################################################################
|
@################################################################################
|
||||||
@{
|
@{
|
||||||
|
from packaging import version
|
||||||
import genmsg.msgs
|
import genmsg.msgs
|
||||||
|
|
||||||
from px_generate_uorb_topic_helper import * # this is in Tools/
|
from px_generate_uorb_topic_helper import * # this is in Tools/
|
||||||
|
@ -57,7 +58,7 @@ def get_include_directives(spec):
|
||||||
if genmsg.msgs.is_valid_constant_type(genmsg.msgs.bare_msg_type(field.type)):
|
if genmsg.msgs.is_valid_constant_type(genmsg.msgs.bare_msg_type(field.type)):
|
||||||
continue
|
continue
|
||||||
builtin_type = str(field.base_type).replace('px4/', '')
|
builtin_type = str(field.base_type).replace('px4/', '')
|
||||||
if fastrtps_version <= 1.7:
|
if version.parse(fastrtps_version) <= version.parse('1.7'):
|
||||||
include_directive = '#include "%s_.idl"' % builtin_type
|
include_directive = '#include "%s_.idl"' % builtin_type
|
||||||
else:
|
else:
|
||||||
include_directive = '#include "%s.idl"' % builtin_type
|
include_directive = '#include "%s.idl"' % builtin_type
|
||||||
|
@ -77,12 +78,12 @@ def get_idl_type_name(field_type):
|
||||||
def add_msg_field(field):
|
def add_msg_field(field):
|
||||||
if (not field.is_header):
|
if (not field.is_header):
|
||||||
if field.is_array:
|
if field.is_array:
|
||||||
if fastrtps_version <= 1.7:
|
if version.parse(fastrtps_version) <= version.parse('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))
|
print(' {0}__{1}_array_{2} {3}_;'.format(topic, str(get_idl_type_name(field.base_type)).replace(" ", "_"), str(field.array_len), field.name))
|
||||||
else:
|
else:
|
||||||
print(' {0}__{1}_array_{2} {3};'.format(topic, str(get_idl_type_name(field.base_type)).replace(" ", "_"), str(field.array_len), field.name))
|
print(' {0}__{1}_array_{2} {3};'.format(topic, str(get_idl_type_name(field.base_type)).replace(" ", "_"), str(field.array_len), field.name))
|
||||||
else:
|
else:
|
||||||
if fastrtps_version <= 1.7:
|
if version.parse(fastrtps_version) <= version.parse('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)
|
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:
|
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)
|
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 +97,7 @@ def add_msg_fields():
|
||||||
def add_array_typedefs():
|
def add_array_typedefs():
|
||||||
for field in spec.parsed_fields():
|
for field in spec.parsed_fields():
|
||||||
if not field.is_header and field.is_array:
|
if not field.is_header and field.is_array:
|
||||||
if fastrtps_version <= 1.7:
|
if version.parse(fastrtps_version) <= version.parse('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)
|
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:
|
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)
|
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)
|
||||||
|
@ -123,18 +124,20 @@ def add_msg_constants():
|
||||||
@[for line in get_include_directives(spec)]@
|
@[for line in get_include_directives(spec)]@
|
||||||
@(line)@
|
@(line)@
|
||||||
@[end for]@
|
@[end for]@
|
||||||
|
|
||||||
|
|
||||||
@# Constants
|
@# Constants
|
||||||
@add_msg_constants()
|
@add_msg_constants()
|
||||||
@# Array types
|
@# Array types
|
||||||
@add_array_typedefs()
|
@add_array_typedefs()
|
||||||
@[if fastrtps_version <= 1.7]@
|
@[if version.parse(fastrtps_version) <= version.parse('1.7')]@
|
||||||
struct @(topic)_
|
struct @(topic)_
|
||||||
@[else]@
|
@[else]@
|
||||||
struct @(topic)
|
struct @(topic)
|
||||||
@[end if]@
|
@[end if]@
|
||||||
{
|
{
|
||||||
@add_msg_fields()
|
@add_msg_fields()
|
||||||
@[if fastrtps_version <= 1.7]@
|
@[if version.parse(fastrtps_version) <= version.parse('1.7')]@
|
||||||
}; // struct @(topic)_
|
}; // struct @(topic)_
|
||||||
|
|
||||||
#pragma keylist @(topic)_
|
#pragma keylist @(topic)_
|
||||||
|
|
|
@ -227,13 +227,9 @@ if fastrtpsgen_include is not None and fastrtpsgen_include != '':
|
||||||
os.path.abspath(
|
os.path.abspath(
|
||||||
args.fastrtpsgen_include) + " "
|
args.fastrtpsgen_include) + " "
|
||||||
|
|
||||||
# get FastRTPS version (major.minor, since patch is not relevant at this stage)
|
# get FastRTPS version
|
||||||
fastrtps_version = ""
|
fastrtps_version = subprocess.check_output(
|
||||||
try:
|
"ldconfig -v | grep libfastrtps", shell=True).decode("utf-8").strip().split('so.')[-1]
|
||||||
fastrtps_version = float(subprocess.check_output(
|
|
||||||
"ldconfig -v | grep libfastrtps | tail -c 6", shell=True).decode("utf-8").strip()[-5:-2])
|
|
||||||
except ValueError:
|
|
||||||
print("No valid version found to FasRTPS. Make sure it is installed.")
|
|
||||||
|
|
||||||
# get ROS 2 version, if exists
|
# get ROS 2 version, if exists
|
||||||
ros2_distro = ""
|
ros2_distro = ""
|
||||||
|
|
|
@ -43,6 +43,7 @@ import shutil
|
||||||
import filecmp
|
import filecmp
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
from packaging import version
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import em
|
import em
|
||||||
|
@ -187,7 +188,7 @@ def generate_idl_file(filename_msg, msg_dir, alias, outputdir, templatedir, pack
|
||||||
os.makedirs(outputdir)
|
os.makedirs(outputdir)
|
||||||
|
|
||||||
template_file = os.path.join(templatedir, IDL_TEMPLATE_FILE)
|
template_file = os.path.join(templatedir, IDL_TEMPLATE_FILE)
|
||||||
if 1.5 <= fastrtps_version <= 1.7:
|
if version.parse(fastrtps_version) <= version.parse('1.7'):
|
||||||
output_file = os.path.join(outputdir, IDL_TEMPLATE_FILE.replace(
|
output_file = os.path.join(outputdir, IDL_TEMPLATE_FILE.replace(
|
||||||
"msg.idl.em", str(spec_short_name + "_.idl")))
|
"msg.idl.em", str(spec_short_name + "_.idl")))
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue