Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrected breaks when plotting array data #50

Merged
merged 3 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion plugins/datastreamer_plugin/fastdds/ReaderHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ ReaderHandler::ReaderHandler(
, type_(type)
, listener_(listener)
, stop_(false)
, mtx_data_available_()
{
// Create data so it is not required to create it each time and avoid reallocation if possible
data_ = eprosima::fastrtps::types::DynamicDataFactory::get_instance()->create_data(type_);
Expand Down Expand Up @@ -108,6 +109,8 @@ void ReaderHandler::stop()
void ReaderHandler::on_data_available(
eprosima::fastdds::dds::DataReader* reader)
{
std::lock_guard<std::mutex> lock(mtx_data_available_);
juanlofer-eprosima marked this conversation as resolved.
Show resolved Hide resolved

eprosima::fastdds::dds::SampleInfo info;
eprosima::fastrtps::types::ReturnCode_t read_ret =
eprosima::fastrtps::types::ReturnCode_t::RETCODE_OK;
Expand All @@ -116,7 +119,7 @@ void ReaderHandler::on_data_available(
while (!stop_ && read_ret == eprosima::fastrtps::types::ReturnCode_t::RETCODE_OK)
{
// Read next data
read_ret = reader->take_next_sample(data_.get(), &info);
read_ret = reader->take_next_sample(data_, &info);

// If data has been read
if (read_ret == eprosima::fastrtps::types::ReturnCode_t::RETCODE_OK &&
Expand All @@ -130,6 +133,7 @@ void ReaderHandler::on_data_available(
numeric_data_info_,
data_,
numeric_data_);

utils::get_introspection_string_data(
string_data_info_,
data_,
Expand Down
5 changes: 4 additions & 1 deletion plugins/datastreamer_plugin/fastdds/ReaderHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define _EPROSIMA_PLOTJUGGLERFASTDDSPLUGIN_PLUGINS_DATASTREAMERPLUGIN_FASTDDS_READERHANDLER_HPP_

#include <atomic>
#include <mutex>

#include <fastdds/dds/topic/Topic.hpp>
#include <fastdds/dds/subscriber/DataReader.hpp>
Expand Down Expand Up @@ -128,7 +129,7 @@ struct ReaderHandler : public eprosima::fastdds::dds::DataReaderListener
eprosima::fastrtps::types::DynamicType_ptr type_;

//! Data Type element
eprosima::fastrtps::types::DynamicData_ptr data_;
eprosima::fastrtps::types::DynamicData* data_;
juanlofer-eprosima marked this conversation as resolved.
Show resolved Hide resolved

std::atomic<bool> stop_;

Expand All @@ -138,6 +139,8 @@ struct ReaderHandler : public eprosima::fastdds::dds::DataReaderListener
utils::TypeIntrospectionNumericStruct numeric_data_;
utils::TypeIntrospectionStringStruct string_data_;

std::mutex mtx_data_available_;

};

} /* namespace fastdds */
Expand Down
33 changes: 18 additions & 15 deletions plugins/datastreamer_plugin/utils/dynamic_types_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ void get_introspection_type_names(
const std::vector<TypeKind>& current_kinds_tree /* = {} */,
const std::string& separator /* = "/" */)
{
DEBUG("Getting types for type member " << base_type_name);

// Get type kind and store it as kind tree
TypeKind kind = type->get_kind();

DEBUG("Getting types for type member " << base_type_name << " of kind " + std::to_string(kind));

switch (kind)
{
case fastrtps::types::TK_BOOLEAN:
Expand Down Expand Up @@ -92,8 +92,7 @@ void get_introspection_type_names(

case fastrtps::types::TK_ARRAY:
{
DynamicType_ptr internal_type =
array_internal_kind(type);
DynamicType_ptr internal_type = array_internal_kind(type);
unsigned int this_array_size = array_size(type);

// Allow this array depending on data type configuration
Expand Down Expand Up @@ -180,7 +179,7 @@ void get_introspection_type_names(

void get_introspection_numeric_data(
const TypeIntrospectionCollection& numeric_type_names,
const DynamicData_ptr& data,
DynamicData* data,
TypeIntrospectionNumericStruct& numeric_data_result)
{
DEBUG("Getting numeric data");
Expand All @@ -206,7 +205,7 @@ void get_introspection_numeric_data(
std::get<TypeKind>(member_type_info);

// Get Data parent that has the member we are looking for
const auto& parent_data = get_parent_data_of_member(
auto parent_data = get_parent_data_of_member(
data,
members,
kinds);
Expand All @@ -220,7 +219,7 @@ void get_introspection_numeric_data(

void get_introspection_string_data(
const TypeIntrospectionCollection& string_type_names,
const eprosima::fastrtps::types::DynamicData_ptr& data,
DynamicData* data,
TypeIntrospectionStringStruct& string_data_result)
{
DEBUG("Getting string data");
Expand All @@ -246,7 +245,7 @@ void get_introspection_string_data(
std::get<TypeKind>(member_type_info);

// Get Data parent that has the member we are looking for
const auto& parent_data = get_parent_data_of_member(
auto parent_data = get_parent_data_of_member(
data,
members,
kinds);
Expand All @@ -258,13 +257,15 @@ void get_introspection_string_data(
}
}

DynamicData_ptr get_parent_data_of_member(
const DynamicData_ptr& data,
DynamicData* get_parent_data_of_member(
DynamicData* data,
const std::vector<MemberId>& members_tree,
const std::vector<TypeKind>& kind_tree,
unsigned int array_indexes /* = 0 */)
{

DEBUG("Getting parent data of type " << std::to_string(kind_tree[array_indexes]));

if (array_indexes == members_tree.size() - 1)
{
// One-to-last value, so this one is the value to take, as it is the parent of the data
Expand All @@ -282,10 +283,12 @@ DynamicData_ptr get_parent_data_of_member(
{
// Access to the data inside the structure
DynamicData* child_data;
data->get_complex_value(&child_data, member_id);
// data->get_complex_value(&child_data, member_id);
child_data = data->loan_value(member_id);
data->return_loaned_value(child_data);
juanlofer-eprosima marked this conversation as resolved.
Show resolved Hide resolved

return get_parent_data_of_member(
DynamicData_ptr(child_data),
child_data,
members_tree,
kind_tree,
array_indexes + 1);
Expand All @@ -306,11 +309,11 @@ DynamicData_ptr get_parent_data_of_member(
}

double get_numeric_type_from_data(
const DynamicData_ptr& data,
DynamicData* data,
const MemberId& member,
const TypeKind& kind)
{
DEBUG("Getting numeric data of kind " << kind << " in member " << member);
DEBUG("Getting numeric data of kind " << std::to_string(kind) << " in member " << member);
juanlofer-eprosima marked this conversation as resolved.
Show resolved Hide resolved

switch (kind)
{
Expand Down Expand Up @@ -354,7 +357,7 @@ double get_numeric_type_from_data(
}

std::string get_string_type_from_data(
const DynamicData_ptr& data,
DynamicData* data,
const MemberId& member,
const TypeKind& kind)
{
Expand Down
16 changes: 8 additions & 8 deletions plugins/datastreamer_plugin/utils/dynamic_types_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ std::vector<std::string> get_introspection_type_names(
* If \c type is a basic type, it adds its label, that is \c base_type_name to the
* \c TypeIntrospectionCollection that it belongs, depending if it is numeric or text kind.
* Along with the label, it is added the vector of parents as member Ids and kinds.
* Those are useful to allow to acces this specific field from a \c DynamicData_ptr .
* Those are useful to allow to acces this specific field from a \c DynamicData* .
*
* If \c type is not a basic type (array or struct) this function is called for each value
* updating \c base_type_name for each recursive call.
Expand Down Expand Up @@ -110,15 +110,15 @@ void get_introspection_type_names(
*/
void get_introspection_numeric_data(
const TypeIntrospectionCollection& numeric_type_names,
const DynamicData_ptr& data,
DynamicData* data,
TypeIntrospectionNumericStruct& numeric_data_result);

/**
* @brief TODO
*/
void get_introspection_string_data(
const TypeIntrospectionCollection& string_type_names,
const DynamicData_ptr& data,
DynamicData* data,
TypeIntrospectionStringStruct& string_data_result);

/**
Expand All @@ -132,10 +132,10 @@ void get_introspection_string_data(
* @param members_tree [in]
* @param kind [in]
* @param array_indexes [in]
* @return DynamicData_ptr
* @return DynamicData*
*/
DynamicData_ptr get_parent_data_of_member(
const DynamicData_ptr& data,
DynamicData* get_parent_data_of_member(
DynamicData* data,
const std::vector<MemberId>& members,
const std::vector<TypeKind>& kinds,
unsigned int array_index = 0);
Expand All @@ -149,7 +149,7 @@ DynamicData_ptr get_parent_data_of_member(
* @return numeric data of the member casted to double
*/
double get_numeric_type_from_data(
const DynamicData_ptr& data,
DynamicData* data,
const MemberId& member,
const TypeKind& kind);

Expand All @@ -162,7 +162,7 @@ double get_numeric_type_from_data(
* @return string data of the member casted to string
*/
std::string get_string_type_from_data(
const DynamicData_ptr& data,
DynamicData* data,
const MemberId& member,
const TypeKind& kind);

Expand Down