Skip to content

Commit

Permalink
Add plotjuggler group creation and data reading
Browse files Browse the repository at this point in the history
With recent version of fastDDS we can now read wml file with key, so
read this value and create group.
Plotjuggler groups are now created in FastDdsDataStreamer so that it can
latter handle them.

Issue: [eProsima#56]
Signed-off-by: Manuel Valch <manuelValch@proton.me>
  • Loading branch information
manuelValch committed Aug 29, 2024
1 parent 1330a70 commit 2fea81d
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 11 deletions.
98 changes: 88 additions & 10 deletions plugins/datastreamer_plugin/datastreamer/FastDdsDataStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ bool FastDdsDataStreamer::start(
configuration_.data_type_configuration);
}

running_ = timeSeriesCreation();
running_ = pjGroupCreation();

return running_;
}
Expand Down Expand Up @@ -139,6 +139,55 @@ bool FastDdsDataStreamer::xmlLoadState(
return configuration_.xmlLoadState(parent_element);
}


void FastDdsDataStreamer::onNewInstance(const std::string& topic_name, const std::string& instance_name)
{


// First we need to now which series belong to the instance and then register them
// this will all be name based, i.e on topic name
std::vector<types::DatumLabel> numeric_series = fastdds_handler_.numeric_data_series_names();
std::vector<types::DatumLabel> string_series = fastdds_handler_.string_data_series_names();

// get Pj group serie belong to

// NUMERIC
for (const auto& series : numeric_series)
{
std::size_t char_id = series.find_first_of("/");
std::string topic_name = series.substr(0U, char_id);
std::string series_name = series.substr(char_id);

if (plot_groups_.end() == plot_groups_.find(topic_name))
{
// Create plotjuggler group
DEBUG("Creating plotjuggler group: " << topic_name);
plot_groups_.insert({topic_name, std::make_shared<PJ::PlotGroup>(topic_name)});
}
// Create a series
DEBUG("Creating numeric series: " << series_name);
dataMap().addNumeric(series_name, plot_groups_.at(topic_name));
}

// STRING
for (const auto& series : string_series)
{
std::size_t char_id = series.find_first_of("/");
std::string topic_name = series.substr(0U, char_id);
std::string series_name = series.substr(char_id);

if (plot_groups_.end() == plot_groups_.find(topic_name))
{
// Create plotjuggler group
DEBUG("Creating plotjuggler group: " << topic_name);
plot_groups_.insert({topic_name, std::make_shared<PJ::PlotGroup>(topic_name)});
}
// Create a series
DEBUG("Creating string series: " << series_name);
dataMap().addStringSeries(series_name, plot_groups_.at(topic_name));
}
}

////////////////////////////////////////////////////
// FASTDDS LISTENER METHODS
////////////////////////////////////////////////////
Expand All @@ -156,10 +205,25 @@ void FastDdsDataStreamer::on_double_data_read(
{
DEBUG("Adding to numeric series " << data.first << " value " << data.second << " with timestamp " << timestamp);

// Get data map
auto& series = dataMap().numeric.find(data.first)->second;
// Add data to series
series.pushBack( { timestamp, data.second});
//Find to which group it belong
std::string group = data_per_topic_value[0U].first;
std::size_t char_id = group.find_first_of("/");
std::string topic_name = group.substr(0U, char_id);
std::string series_name = group.substr(char_id);

if (plot_groups_.end() == plot_groups_.find(topic_name))
{
// Create plotjuggler group
WARNING("Received not registered topic: " << topic_name);
}
else
{
// Get data map
auto& series = dataMap().numeric.find(series_name)->second;
// Add data to series
series.pushBack( { timestamp, data.second});
}

}

emit dataReceived();
Expand All @@ -178,10 +242,24 @@ void FastDdsDataStreamer::on_string_data_read(
{
DEBUG("Adding to string series " << data.first << " value " << data.second << " with timestamp " << timestamp);

// Get data map
auto& series = dataMap().strings.find(data.first)->second;
// Add data to series
series.pushBack( { timestamp, data.second});
//Find to which group it belong
std::string group = data_per_topic_value[0U].first;
std::size_t char_id = group.find_first_of("/");
std::string topic_name = group.substr(0U, char_id);
std::string series_name = group.substr(char_id);

if (plot_groups_.end() == plot_groups_.find(topic_name))
{
// Create plotjuggler group
WARNING("Received not registered topic: " << topic_name);
}
else
{
// Get data map
auto& series = dataMap().strings.find(series_name)->second;
// Add data to series
series.pushBack( { timestamp, data.second});
}
}

emit dataReceived();
Expand Down Expand Up @@ -237,7 +315,7 @@ void FastDdsDataStreamer::connect_to_domain_(
select_topics_dialog_.connect_to_domain(domain_id);
}

bool FastDdsDataStreamer::timeSeriesCreation()
bool FastDdsDataStreamer::pjGroupCreation()
{

// Get all series from topics and create them
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class FastDdsDataStreamer :
bool xmlLoadState(
const QDomElement& parent_element) override;

void onNewInstance(const std::string& topic_name, const std::string& instance_name);

////////////////////////////////////////////////////
// FASTDDS LISTENER METHODS
////////////////////////////////////////////////////
Expand Down Expand Up @@ -133,7 +135,7 @@ class FastDdsDataStreamer :
unsigned int domain_id);


bool timeSeriesCreation();
bool pjGroupCreation();

////////////////////////////////////////////////////
// INTERNAL VALUES
Expand Down

0 comments on commit 2fea81d

Please sign in to comment.