@@ -29,7 +29,9 @@ Author: i11 - Embedded Software, RWTH Aachen University
29
29
#include " rtps/config.h"
30
30
#include " rtps/messages/MessageTypes.h"
31
31
#include " ucdr/microcdr.h"
32
-
32
+ #if defined(unix) || defined(__unix__)
33
+ #include < chrono>
34
+ #endif
33
35
#include < array>
34
36
35
37
namespace rtps {
@@ -40,11 +42,11 @@ typedef uint32_t BuiltinEndpointSet_t;
40
42
41
43
class ParticipantProxyData {
42
44
public:
43
- ParticipantProxyData () = default ;
44
- ParticipantProxyData (Guid guid);
45
+ ParticipantProxyData () { onAliveSignal (); }
46
+ ParticipantProxyData (Guid_t guid);
45
47
46
48
ProtocolVersion_t m_protocolVersion = PROTOCOLVERSION;
47
- Guid m_guid = Guid {GUIDPREFIX_UNKNOWN, ENTITYID_UNKNOWN};
49
+ Guid_t m_guid = Guid_t {GUIDPREFIX_UNKNOWN, ENTITYID_UNKNOWN};
48
50
VendorId_t m_vendorId = VENDOR_UNKNOWN;
49
51
bool m_expectsInlineQos = false ;
50
52
BuiltinEndpointSet_t m_availableBuiltInEndpoints;
@@ -57,8 +59,13 @@ class ParticipantProxyData {
57
59
std::array<Locator, Config::SPDP_MAX_NUM_LOCATORS>
58
60
m_defaultMulticastLocatorList;
59
61
Count_t m_manualLivelinessCount{1 };
60
- Duration_t m_leaseDuration = Config::SPDP_LEASE_DURATION;
61
-
62
+ Duration_t m_leaseDuration = Config::SPDP_DEFAULT_REMOTE_LEASE_DURATION;
63
+ #if defined(unix) || defined(__unix__)
64
+ std::chrono::time_point<std::chrono::high_resolution_clock>
65
+ m_lastLivelinessReceivedTimestamp;
66
+ #else
67
+ TickType_t m_lastLivelinessReceivedTickCount = 0 ;
68
+ #endif
62
69
void reset ();
63
70
64
71
bool readFromUcdrBuffer (ucdrBuffer &buffer);
@@ -70,6 +77,10 @@ class ParticipantProxyData {
70
77
inline bool hasSubscriptionWriter ();
71
78
inline bool hasSubscriptionReader ();
72
79
80
+ inline void onAliveSignal ();
81
+ inline bool isAlive ();
82
+ inline uint32_t getAliveSignalAgeInMilliseconds ();
83
+
73
84
private:
74
85
bool
75
86
readLocatorIntoList (ucdrBuffer &buffer,
@@ -131,5 +142,45 @@ bool ParticipantProxyData::hasSubscriptionReader() {
131
142
return (m_availableBuiltInEndpoints &
132
143
DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_DETECTOR) != 0 ;
133
144
}
145
+
146
+ void ParticipantProxyData::onAliveSignal () {
147
+ #if defined(unix) || defined(__unix__)
148
+ m_lastLivelinessReceivedTimestamp = std::chrono::high_resolution_clock::now ();
149
+ #else
150
+ m_lastLivelinessReceivedTickCount = xTaskGetTickCount ();
151
+ #endif
152
+ }
153
+
154
+ uint32_t ParticipantProxyData::getAliveSignalAgeInMilliseconds () {
155
+ #if defined(unix) || defined(__unix__)
156
+ auto now = std::chrono::high_resolution_clock::now ();
157
+ std::chrono::duration<double , std::milli> duration =
158
+ now - m_lastLivelinessReceivedTimestamp;
159
+ return duration.count ();
160
+ #else
161
+ return (xTaskGetTickCount () - m_lastLivelinessReceivedTickCount) *
162
+ (1000 / configTICK_RATE_HZ);
163
+ #endif
164
+ }
165
+
166
+ /*
167
+ * Returns true if last heartbeat within lease duration, else false
168
+ */
169
+ bool ParticipantProxyData::isAlive () {
170
+ uint32_t lease_in_ms =
171
+ m_leaseDuration.seconds * 1000 + m_leaseDuration.fraction * 1e-6 ;
172
+
173
+ uint32_t max_lease_in_ms =
174
+ Config::SPDP_MAX_REMOTE_LEASE_DURATION.seconds * 1000 +
175
+ Config::SPDP_MAX_REMOTE_LEASE_DURATION.fraction * 1e-6 ;
176
+
177
+ auto heatbeat_age_in_ms = getAliveSignalAgeInMilliseconds ();
178
+
179
+ if (heatbeat_age_in_ms > std::min (lease_in_ms, max_lease_in_ms)) {
180
+ return false ;
181
+ }
182
+ return true ;
183
+ }
184
+
134
185
} // namespace rtps
135
186
#endif // RTPS_PARTICIPANTPROXYDATA_H
0 commit comments