diff --git a/msg/templates/urtps/RtpsTopics.cpp.em b/msg/templates/urtps/RtpsTopics.cpp.em index a65c38c63e..e9e1b27105 100644 --- a/msg/templates/urtps/RtpsTopics.cpp.em +++ b/msg/templates/urtps/RtpsTopics.cpp.em @@ -139,10 +139,13 @@ bool RtpsTopics::getMsg(const uint8_t topic_ID, eprosima::fastcdr::Cdr &scdr) @[ if topic == 'Timesync' or topic == 'timesync']@ if (getMsgSysID(&msg) == 0) { @[ end if]@ - // apply timestamp offset + // apply timestamps offset uint64_t timestamp = getMsgTimestamp(&msg); + uint64_t timestamp_sample = getMsgTimestampSample(&msg); _timesync->addOffset(timestamp); setMsgTimestamp(&msg, timestamp); + _timesync->addOffset(timestamp_sample); + setMsgTimestampSample(&msg, timestamp_sample); msg.serialize(scdr); ret = true; @[ if topic == 'Timesync' or topic == 'timesync']@ diff --git a/msg/templates/urtps/RtpsTopics.h.em b/msg/templates/urtps/RtpsTopics.h.em index 6d8d2975f4..4f3f9d4e15 100644 --- a/msg/templates/urtps/RtpsTopics.h.em +++ b/msg/templates/urtps/RtpsTopics.h.em @@ -63,6 +63,7 @@ except AttributeError: #include #include #include +#include #include "microRTPS_timesync.h" @@ -116,11 +117,28 @@ private: @[end for]@ @[end if]@ + // SFINAE + template struct hasTimestampSample{ + private: + static void detect(...); + template static decltype(std::declval().timestamp_sample()) detect(const U&); + public: + static constexpr bool value = std::is_same()))>::value; + }; + + template + inline typename std::enable_if::value, uint64_t>::type + getMsgTimestampSample_impl(const T*) { return 0; } + /** Msg metada Getters **/ @[if version.parse(fastrtps_version) <= version.parse('1.7.2') or not ros2_distro]@ template inline uint64_t getMsgTimestamp(const T* msg) { return msg->timestamp_(); } + template + inline typename std::enable_if::value, uint64_t>::type + getMsgTimestampSample_impl(const T* msg) { return msg->timestamp_sample_(); } + template inline uint8_t getMsgSysID(const T* msg) { return msg->sys_id_(); } @@ -130,6 +148,10 @@ private: template inline uint64_t getMsgTimestamp(const T* msg) { return msg->timestamp(); } + template + inline typename std::enable_if::value, uint64_t>::type + getMsgTimestampSample_impl(const T* msg) { return msg->timestamp_sample(); } + template inline uint8_t getMsgSysID(const T* msg) { return msg->sys_id(); } @@ -137,11 +159,22 @@ private: inline uint8_t getMsgSeq(const T* msg) { return msg->seq(); } @[end if]@ + template + inline uint64_t getMsgTimestampSample(const T* msg) { return getMsgTimestampSample_impl(msg); } + + template + inline typename std::enable_if::value, void>::type + setMsgTimestampSample_impl(T*, const uint64_t&) {} + /** Msg metadata Setters **/ @[if version.parse(fastrtps_version) <= version.parse('1.7.2') or not ros2_distro]@ template inline void setMsgTimestamp(T* msg, const uint64_t& timestamp) { msg->timestamp_() = timestamp; } + template + inline typename std::enable_if::value, void>::type + setMsgTimestampSample_impl(T* msg, const uint64_t& timestamp_sample) { msg->timestamp_sample_() = timestamp_sample; } + template inline void setMsgSysID(T* msg, const uint8_t& sys_id) { msg->sys_id_() = sys_id; } @@ -151,6 +184,10 @@ private: template inline void setMsgTimestamp(T* msg, const uint64_t& timestamp) { msg->timestamp() = timestamp; } + template + inline typename std::enable_if::value, void>::type + setMsgTimestampSample_impl(T* msg, const uint64_t& timestamp_sample) { msg->timestamp_sample() = timestamp_sample; } + template inline void setMsgSysID(T* msg, const uint8_t& sys_id) { msg->sys_id() = sys_id; } @@ -158,6 +195,9 @@ private: inline void setMsgSeq(T* msg, const uint8_t& seq) { msg->seq() = seq; } @[end if]@ + template + inline void setMsgTimestampSample(T* msg, const uint64_t& timestamp_sample) { setMsgTimestampSample_impl(msg, timestamp_sample); } + /** * @@brief Timesync object ptr. * This object is used to compuyte and apply the time offsets to the