Skip to content

Commit

Permalink
Add missing supported types to plotjuggler (#61)
Browse files Browse the repository at this point in the history
* Refs #21571: Refactor to use json_serializer

Signed-off-by: Carlosespicur <carlosespicur@proton.me>

* Refs #21571: Fix boolean types

Signed-off-by: Carlosespicur <carlosespicur@proton.me>

* Refs #21571: Add review changes

Signed-off-by: Carlosespicur <carlosespicur@proton.me>

* Refs #21571: Fix data streaming for multiple topics with the same data type

Signed-off-by: Carlosespicur <carlosespicur@proton.me>

* Refs #21571: Uncrustify

Signed-off-by: Carlosespicur <carlosespicur@proton.me>

* Refs #21571: Fix fastcdr compilation error in Windows

Signed-off-by: Carlosespicur <carlosespicur@proton.me>

---------

Signed-off-by: Carlosespicur <carlosespicur@proton.me>
  • Loading branch information
Carlosespicur authored Sep 17, 2024
1 parent eca0e1d commit cd3c259
Show file tree
Hide file tree
Showing 9 changed files with 25,706 additions and 884 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ message(STATUS "Version: ${PROJECT_VERSION}")
###############################################################################
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake/modules)

###############################################################################
# Load external projects.
###############################################################################
include_directories(thirdparty/nlohmann-json)

###############################################################################
# System configuration
Expand Down
1 change: 1 addition & 0 deletions plugins/datastreamer_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ target_link_libraries(
${QT_LINK_LIBRARIES}
${plotjuggler_LIBRARIES}
fastdds
fastcdr
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ void FastDdsDataStreamer::on_data_available()
// Locking DataStream
std::lock_guard<std::mutex> lock(mutex());

// Clear data created from previous sample
dataMap().clear();

// Create series from new received sample
create_series_();
}
Expand All @@ -178,6 +175,7 @@ void FastDdsDataStreamer::on_double_data_read(
}
// Get data map
auto& series = dataMap().numeric.find(data.first)->second;

// Add data to series
series.pushBack( { timestamp, data.second});
DEBUG("...Data added to series");
Expand Down
34 changes: 27 additions & 7 deletions plugins/datastreamer_plugin/fastdds/Participant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,36 @@ void Participant::create_subscription(
else
{
// Type information is available and registered in participant. Create dyn_type for ReaderHandler
DynamicTypeBuilder::_ref_type dyn_type_builder;
ReturnCode_t ret = DomainParticipantFactory::get_instance()->get_dynamic_type_builder_from_xml_by_name(
type_name, dyn_type_builder);
// Two different cases:
// 1. Type info has been discovered and registered by another participant. In this case, the type Id has been saved in dyn_types_info_
// 2. Type info has been loaded manually (through XML file) and registered in participant. Info not saved in dyn_types_info_

if (RETCODE_OK != ret)
if (dyn_types_info_->find(topic_name) != dyn_types_info_->end())
{
EPROSIMA_LOG_ERROR(PARTICIPANT, "Error getting DynamicTypeBuilder from XML");
return;
DataTypeId type_id = dyn_types_info_->operator [](topic_name).second;
xtypes::TypeObject type_object;
if (RETCODE_OK != DomainParticipantFactory::get_instance()->type_object_registry().get_type_object(
type_id, type_object))
{
EPROSIMA_LOG_ERROR(PARTICIPANT, "Error getting type object for type " << type_name);
return;
}
dyn_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_type_object(
type_object)->build();
}
else
{
DynamicTypeBuilder::_ref_type dyn_type_builder;
ReturnCode_t ret = DomainParticipantFactory::get_instance()->get_dynamic_type_builder_from_xml_by_name(
type_name, dyn_type_builder);

if (RETCODE_OK != ret)
{
EPROSIMA_LOG_ERROR(PARTICIPANT, "Error getting DynamicTypeBuilder from XML");
return;
}
dyn_type = dyn_type_builder->build();
}
dyn_type = dyn_type_builder->build();
}

// Create topic
Expand Down
79 changes: 25 additions & 54 deletions plugins/datastreamer_plugin/fastdds/ReaderHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicDataFactory.hpp>
#include <fastdds/dds/xtypes/utils.hpp>

#include "ReaderHandler.hpp"
#include "utils/utils.hpp"
Expand Down Expand Up @@ -51,14 +52,7 @@ ReaderHandler::ReaderHandler(
{
// Create data so it is not required to create it each time and avoid reallocation if possible
data_ = DynamicDataFactory::get_instance()->create_data(type_);
// Determine whether the data tree will be recreated for every received sample
static_type_ = utils::is_type_static(type);

if (static_type_)
{
// Create the static structures to store the data introspection information AND the data itself
create_data_structures_();
}
// Set this object as this reader's listener
reader_->set_listener(this);
}
Expand Down Expand Up @@ -94,11 +88,9 @@ void ReaderHandler::on_data_available(
ReturnCode_t read_ret = RETCODE_OK;

// Non-fixed size types require data to be recreated (e.g. to avoid having sequence members from previous samples)
if (!static_type_)
{
DynamicDataFactory::get_instance()->delete_data(data_);
data_ = DynamicDataFactory::get_instance()->create_data(type_);
}
DynamicDataFactory::get_instance()->delete_data(data_);
data_ = DynamicDataFactory::get_instance()->create_data(type_);

// Read Data from reader while there is data available and not should stop
while (!stop_ && read_ret == RETCODE_OK)
{
Expand All @@ -109,49 +101,32 @@ void ReaderHandler::on_data_available(
if (read_ret == RETCODE_OK &&
info.instance_state == InstanceStateKind::ALIVE_INSTANCE_STATE)
{
if (!static_type_)
{
// Reset stored data info
numeric_data_info_.clear();
string_data_info_.clear();

// Reset stored data
numeric_data_.clear();
string_data_.clear();

// Recreate the structures to store the data introspection information AND the data itself
create_data_structures_(data_);

// Update previous data view according to new received data structure
listener_->on_data_available();
}
// Get timestamp
double timestamp = utils::get_timestamp_seconds_numeric_value(info.reception_timestamp);

// Get data in already created structures
utils::get_introspection_numeric_data(
numeric_data_info_,
data_,
numeric_data_);
// Reset stored data info
numeric_data_info_.clear();
string_data_info_.clear();

// Format the data received to show it in the GUI
create_data_structures_(data_);

utils::get_introspection_string_data(
string_data_info_,
data_,
string_data_);
// Update previous data view according to new received data structure
listener_->on_data_available();

// Get value maps from data and send callback if there are data
if (!numeric_data_.empty())
if (!numeric_data_info_.empty())
{
listener_->on_double_data_read(
numeric_data_,
numeric_data_info_,
timestamp);
}

// Same for strings
if (!string_data_.empty())
if (!string_data_info_.empty())
{
listener_->on_string_data_read(
string_data_,
string_data_info_,
timestamp);
}
}
Expand Down Expand Up @@ -179,24 +154,20 @@ const std::string& ReaderHandler::type_name() const
void ReaderHandler::create_data_structures_(
DynamicData::_ref_type data /* = nullptr */)
{
// Serialize data to JSON format
nlohmann::json serialized_data;
if (RETCODE_OK != utils::serialize_data(data, serialized_data))
{
EPROSIMA_LOG_ERROR(READER_HANDLER, "Error serializing data");
return;
}
// Create the structures to store the data introspection information AND the data itself
utils::get_introspection_type_names(
utils::get_formatted_data(
topic_name(),
type_,
data_type_configuration_,
numeric_data_info_,
string_data_info_,
data);

// Create the data structures
for (const auto& info : numeric_data_info_)
{
numeric_data_.push_back({ std::get<0>(info), 0});
}
for (const auto& info : string_data_info_)
{
string_data_.push_back({ std::get<0>(info), "-"});
}
serialized_data);

DEBUG("Completed type introspection created in topic: " << topic_name() << " with types: ");
for (const auto& info : numeric_data_info_)
Expand Down
12 changes: 4 additions & 8 deletions plugins/datastreamer_plugin/fastdds/ReaderHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include <atomic>

#include <nlohmann/json.hpp>

#include <fastdds/dds/core/status/StatusMask.hpp>
#include <fastdds/dds/subscriber/DataReader.hpp>
#include <fastdds/dds/subscriber/DataReaderListener.hpp>
Expand Down Expand Up @@ -140,16 +142,10 @@ struct ReaderHandler : public eprosima::fastdds::dds::DataReaderListener
//! Data Type element
eprosima::fastdds::dds::DynamicData::_ref_type data_;

//! Whether it is composed of variable sized types (e.g. sequences)
bool static_type_;

std::atomic<bool> stop_;

utils::TypeIntrospectionCollection numeric_data_info_;
utils::TypeIntrospectionCollection string_data_info_;

utils::TypeIntrospectionNumericStruct numeric_data_;
utils::TypeIntrospectionStringStruct string_data_;
utils::TypeIntrospectionNumericStruct numeric_data_info_;
utils::TypeIntrospectionStringStruct string_data_info_;

DataTypeConfiguration data_type_configuration_;
};
Expand Down
Loading

0 comments on commit cd3c259

Please sign in to comment.