Skip to content

Commit 04c0209

Browse files
authored
Final implementation with all commands (#12)
* Implement version command and add colors Signed-off-by: jparisu <[email protected]> * Add yaml writer methods Signed-off-by: jparisu <[email protected]> * Add commands for all entities Signed-off-by: jparisu <[email protected]> * Implement topic rate calculatio Signed-off-by: jparisu <[email protected]> * fix rebase Signed-off-by: jparisu <[email protected]> * Add rate and fix small things Signed-off-by: jparisu <[email protected]> * uncrustify Signed-off-by: jparisu <[email protected]> --------- Signed-off-by: jparisu <[email protected]>
1 parent f4a9794 commit 04c0209

File tree

16 files changed

+503
-134
lines changed

16 files changed

+503
-134
lines changed

fastddsspy_participants/include/fastddsspy_participants/model/DataStreamer.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <ddspipe_core/types/topic/dds/DdsTopic.hpp>
2424
#include <ddspipe_core/types/dds/Payload.hpp>
2525

26-
#include <ddspipe_participants/participant/dynamic_types/ISchemaHandler.hpp>
26+
#include <fastddsspy_participants/model/TopicRateCalculator.hpp>
2727

2828
namespace eprosima {
2929
namespace spy {
@@ -32,7 +32,7 @@ namespace participants {
3232
/**
3333
* TODO
3434
*/
35-
class DataStreamer : public ddspipe::participants::ISchemaHandler
35+
class DataStreamer : public TopicRateCalculator
3636
{
3737
public:
3838

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License\.
14+
15+
#pragma once
16+
17+
#include <tuple>
18+
19+
#include <cpp_utils/types/Atomicable.hpp>
20+
21+
#include <ddspipe_core/types/topic/dds/DdsTopic.hpp>
22+
#include <ddspipe_core/types/dds/Payload.hpp>
23+
24+
#include <ddspipe_participants/participant/dynamic_types/ISchemaHandler.hpp>
25+
26+
namespace eprosima {
27+
namespace spy {
28+
namespace participants {
29+
30+
/**
31+
* TODO
32+
*/
33+
class TopicRateCalculator : public ddspipe::participants::ISchemaHandler
34+
{
35+
public:
36+
37+
void add_data(
38+
const ddspipe::core::types::DdsTopic& topic,
39+
ddspipe::core::types::RtpsPayloadData& data) override;
40+
41+
using RateType = float;
42+
43+
RateType get_topic_rate(
44+
const ddspipe::core::types::DdsTopic& topic) const noexcept;
45+
46+
protected:
47+
48+
struct DataRateInfo
49+
{
50+
ddspipe::core::types::DataTime first_data_time;
51+
unsigned int data_received;
52+
ddspipe::core::types::DataTime last_data_time;
53+
};
54+
55+
bool get_data_rate_from_topic_nts_(
56+
const ddspipe::core::types::DdsTopic& topic,
57+
DataRateInfo& data) const noexcept;
58+
59+
DataRateInfo& get_or_create_data_rate_from_topic_nts_(
60+
const ddspipe::core::types::DdsTopic& topic);
61+
62+
using RateByTopicMapType = utils::SharedAtomicable<std::map<ddspipe::core::types::DdsTopic, DataRateInfo>>;
63+
64+
mutable RateByTopicMapType data_by_topic_;
65+
};
66+
67+
} /* namespace participants */
68+
} /* namespace spy */
69+
} /* namespace eprosima */

fastddsspy_participants/include/fastddsspy_participants/visualization/ModelParser.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ struct ModelParser
5050
const SpyModel& model,
5151
const ddspipe::core::types::Guid& guid);
5252

53+
static ddspipe::core::types::DdsTopic get_topic(
54+
const SpyModel& model,
55+
std::string topic_name);
56+
5357
static std::vector<SimpleTopicData> topics(
5458
const SpyModel& model);
5559
static std::vector<ComplexTopicData> topics_verbose(

fastddsspy_participants/include/fastddsspy_participants/visualization/parser_data.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ struct ComplexEndpointData
6969

7070
struct QoS
7171
{
72-
std::string durability;
73-
std::string reliability;
72+
ddspipe::core::types::DurabilityKind durability;
73+
ddspipe::core::types::ReliabilityKind reliability;
7474
};
7575

7676
ddspipe::core::types::Guid guid;

fastddsspy_participants/src/cpp/model/DataStreamer.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ void DataStreamer::add_data(
8585
const ddspipe::core::types::DdsTopic& topic,
8686
ddspipe::core::types::RtpsPayloadData& data)
8787
{
88+
TopicRateCalculator::add_data(topic, data);
89+
8890
std::shared_lock<std::shared_timed_mutex> _(mutex_);
8991

9092
if (activated_)

fastddsspy_participants/src/cpp/model/NetworkDatabase.cpp

-38
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License\.
14+
15+
#include <fastddsspy_participants/model/TopicRateCalculator.hpp>
16+
17+
namespace eprosima {
18+
namespace spy {
19+
namespace participants {
20+
21+
void TopicRateCalculator::add_data(
22+
const ddspipe::core::types::DdsTopic& topic,
23+
ddspipe::core::types::RtpsPayloadData& data)
24+
{
25+
std::unique_lock<RateByTopicMapType> _(data_by_topic_);
26+
auto& rate_data = get_or_create_data_rate_from_topic_nts_(topic);
27+
28+
// If is first data, set initial time
29+
if (rate_data.data_received == 0)
30+
{
31+
rate_data.first_data_time = data.source_timestamp;
32+
}
33+
34+
// Set reception time
35+
rate_data.last_data_time = data.source_timestamp;
36+
37+
// Increase in 1 the number of data received
38+
rate_data.data_received++;
39+
}
40+
41+
TopicRateCalculator::RateType TopicRateCalculator::get_topic_rate(
42+
const ddspipe::core::types::DdsTopic& topic) const noexcept
43+
{
44+
std::shared_lock<RateByTopicMapType> _(data_by_topic_);
45+
46+
DataRateInfo data;
47+
bool exist = get_data_rate_from_topic_nts_(topic, data);
48+
if (!exist)
49+
{
50+
return 0;
51+
}
52+
53+
// If there is only one data (or in a special case) first and last could be the same and produce a 0 division
54+
float seconds_elapsed = data.last_data_time.seconds() - data.first_data_time.seconds();
55+
if (seconds_elapsed == 0)
56+
{
57+
// TODO decide what to do in this case
58+
return data.data_received;
59+
}
60+
61+
return static_cast<float>(data.data_received) / seconds_elapsed;
62+
}
63+
64+
TopicRateCalculator::DataRateInfo& TopicRateCalculator::get_or_create_data_rate_from_topic_nts_(
65+
const ddspipe::core::types::DdsTopic& topic)
66+
{
67+
// Create data or return the one already stored
68+
return data_by_topic_[topic];
69+
}
70+
71+
bool TopicRateCalculator::get_data_rate_from_topic_nts_(
72+
const ddspipe::core::types::DdsTopic& topic,
73+
TopicRateCalculator::DataRateInfo& data) const noexcept
74+
{
75+
auto it = data_by_topic_.find(topic);
76+
if (data_by_topic_.find(topic) == data_by_topic_.end())
77+
{
78+
return false;
79+
}
80+
data = it->second;
81+
return true;
82+
}
83+
84+
} /* namespace participants */
85+
} /* namespace spy */
86+
} /* namespace eprosima */

fastddsspy_participants/src/cpp/visualization/ModelParser.cpp

+23-40
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,8 @@ void fill_complex_endpoint(
166166
result.guid = endpoint.guid;
167167
result.topic.topic_name = endpoint.topic.m_topic_name;
168168
result.topic.topic_type = endpoint.topic.type_name;
169-
if (endpoint.topic.topic_qos.durability_qos) // TODO move to YamlWriter
170-
{
171-
result.qos.durability = "transient-local";
172-
}
173-
else
174-
{
175-
result.qos.durability = "volatile";
176-
}
177-
if (endpoint.topic.topic_qos.reliability_qos)
178-
{
179-
result.qos.reliability = "best-effort";
180-
}
181-
else
182-
{
183-
result.qos.reliability = "reliable";
184-
}
169+
result.qos.durability = endpoint.topic.topic_qos.durability_qos;
170+
result.qos.reliability = endpoint.topic.topic_qos.reliability_qos;
185171
}
186172

187173
void set_endpoint_simple_information(
@@ -303,7 +289,7 @@ std::set<eprosima::ddspipe::core::types::DdsTopic> get_topics(
303289
return result;
304290
}
305291

306-
ddspipe::core::types::DdsTopic get_topic(
292+
ddspipe::core::types::DdsTopic ModelParser::get_topic(
307293
const SpyModel& model,
308294
std::string topic_name)
309295
{
@@ -349,7 +335,7 @@ std::vector<SimpleTopicData> ModelParser::topics(
349335
datawriters,
350336
datareaders,
351337
{
352-
10, // TODO not implementated yet
338+
model.get_topic_rate(topic),
353339
"Hz"
354340
}
355341
});
@@ -377,42 +363,39 @@ ComplexTopicData ModelParser::topics(
377363
const std::string& topic_name)
378364
{
379365
ComplexTopicData result;
380-
std::vector<ComplexTopicData::Endpoint> datareaders;
381-
std::vector<ComplexTopicData::Endpoint> datawriters;
382366

383-
std::string type_name = "Not discovered yet";
367+
// Lets check if topic exists
368+
auto topic = get_topic(model, topic_name);
369+
370+
// If topic not found, return an empty Daa
371+
if (topic.m_topic_name != topic_name)
372+
{
373+
result.name = "";
374+
return result;
375+
}
376+
377+
// Topic found, fill its information
378+
result.name = topic.m_topic_name;
379+
result.type = topic.type_name;
380+
result.discovered = model.is_topic_type_discovered(topic);
381+
result.rate.rate = model.get_topic_rate(topic);
382+
result.rate.unit = "Hz";
384383

385384
for (const auto& it : model.endpoint_database_)
386385
{
387-
if (it.second.topic.m_topic_name == topic_name)
386+
if (topic.m_topic_name == it.second.topic.m_topic_name)
388387
{
389-
type_name = it.second.topic.type_name;
390388
if (it.second.is_reader())
391389
{
392-
datareaders.push_back({it.first});
390+
result.datareaders.push_back({it.first});
393391
}
394392
if (it.second.is_writer())
395393
{
396-
datawriters.push_back({it.first});
394+
result.datawriters.push_back({it.first});
397395
}
398396
}
399397
}
400398

401-
if (type_name == "Not discovered yet")
402-
{
403-
result.name = "";
404-
}
405-
else
406-
{
407-
result.name = topic_name;
408-
}
409-
result.type = type_name;
410-
result.datawriters = datawriters;
411-
result.datareaders = datareaders;
412-
result.rate.rate = 10;
413-
result.rate.unit = "Hz"; // TODO not implementated yet
414-
result.discovered = model.is_topic_type_discovered(get_topic(model, topic_name));
415-
416399
return result;
417400
}
418401

fastddsspy_tool/src/cpp/main.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int main(
9999
{
100100
file_path = eprosima::spy::DEFAULT_CONFIGURATION_FILE_NAME;
101101

102-
logUser(
102+
logInfo(
103103
FASTDDSSPY_TOOL,
104104
"Not configuration file given, try to use default file " << file_path << ".");
105105
}
@@ -108,7 +108,7 @@ int main(
108108
// NOTE: this check is redundant with option parse arg check
109109
if (!is_file_accessible(file_path.c_str(), eprosima::utils::FileAccessMode::read))
110110
{
111-
logUser(
111+
logInfo(
112112
FASTDDSSPY_TOOL,
113113
"File '" << file_path << "' does not exist or it is not accessible. Using default configuration.");
114114
file_path = "";
@@ -140,7 +140,7 @@ int main(
140140
[&spy, file_path]
141141
(std::string file_name)
142142
{
143-
logUser(
143+
logInfo(
144144
FASTDDSSPY_TOOL,
145145
"FileWatcher notified changes in file " << file_name << ". Reloading configuration");
146146

@@ -179,7 +179,7 @@ int main(
179179
[&spy, file_path]
180180
()
181181
{
182-
logUser(
182+
logInfo(
183183
FASTDDSSPY_TOOL,
184184
"Periodic Timer raised. Reloading configuration from file " << file_path << ".");
185185

0 commit comments

Comments
 (0)