RTPS: adjust timestamp_sample in urtps_agent

This commit is contained in:
Ildar Sadykov
2021-02-12 15:12:08 +03:00
committed by Nuno Marques
parent e48a869160
commit 51dd141c86
2 changed files with 44 additions and 1 deletions
+4 -1
View File
@@ -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']@
+40
View File
@@ -63,6 +63,7 @@ except AttributeError:
#include <fastcdr/Cdr.h>
#include <condition_variable>
#include <queue>
#include <type_traits>
#include "microRTPS_timesync.h"
@@ -116,11 +117,28 @@ private:
@[end for]@
@[end if]@
// SFINAE
template<typename T> struct hasTimestampSample{
private:
static void detect(...);
template<typename U> static decltype(std::declval<U>().timestamp_sample()) detect(const U&);
public:
static constexpr bool value = std::is_same<uint64_t, decltype(detect(std::declval<T>()))>::value;
};
template<typename T>
inline typename std::enable_if<!hasTimestampSample<T>::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 <class T>
inline uint64_t getMsgTimestamp(const T* msg) { return msg->timestamp_(); }
template<typename T>
inline typename std::enable_if<hasTimestampSample<T>::value, uint64_t>::type
getMsgTimestampSample_impl(const T* msg) { return msg->timestamp_sample_(); }
template <class T>
inline uint8_t getMsgSysID(const T* msg) { return msg->sys_id_(); }
@@ -130,6 +148,10 @@ private:
template <class T>
inline uint64_t getMsgTimestamp(const T* msg) { return msg->timestamp(); }
template<typename T>
inline typename std::enable_if<hasTimestampSample<T>::value, uint64_t>::type
getMsgTimestampSample_impl(const T* msg) { return msg->timestamp_sample(); }
template <class T>
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 <class T>
inline uint64_t getMsgTimestampSample(const T* msg) { return getMsgTimestampSample_impl(msg); }
template<typename T>
inline typename std::enable_if<!hasTimestampSample<T>::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 <class T>
inline void setMsgTimestamp(T* msg, const uint64_t& timestamp) { msg->timestamp_() = timestamp; }
template <class T>
inline typename std::enable_if<hasTimestampSample<T>::value, void>::type
setMsgTimestampSample_impl(T* msg, const uint64_t& timestamp_sample) { msg->timestamp_sample_() = timestamp_sample; }
template <class T>
inline void setMsgSysID(T* msg, const uint8_t& sys_id) { msg->sys_id_() = sys_id; }
@@ -151,6 +184,10 @@ private:
template <class T>
inline void setMsgTimestamp(T* msg, const uint64_t& timestamp) { msg->timestamp() = timestamp; }
template <class T>
inline typename std::enable_if<hasTimestampSample<T>::value, void>::type
setMsgTimestampSample_impl(T* msg, const uint64_t& timestamp_sample) { msg->timestamp_sample() = timestamp_sample; }
template <class T>
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 <class T>
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