Skip to content

Commit

Permalink
fix: refine read_message conditions && perform the actual read
Browse files Browse the repository at this point in the history
  • Loading branch information
bpapaspyros committed Sep 29, 2024
1 parent c3905e3 commit a4d63eb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,17 @@ inline void MessagePair<MsgT, DataT>::read_message(const MsgT& message) {
throw exceptions::NullPointerException("The message pair data is not set, nothing to read");
}

if constexpr (TranslatedDataT<MsgT> && !CustomDataT<DataT>) {
read_translated_message(message);
} else if constexpr (std::same_as<MsgT, EncodedState>) {
if constexpr (std::same_as<MsgT, EncodedState>) {
read_encoded_message(message);
} else if constexpr (CustomDataT<MsgT> && CustomDataT<DataT>) {
} else if constexpr (std::same_as<MsgT, DataT> || (CustomDataT<MsgT> && CustomDataT<DataT>) ) {
read_raw_message(message);
} else if constexpr (TranslatedDataT<MsgT> || CoreDataT<MsgT>) {
read_translated_message(message);
} else {
static_assert(false, "The message types for the message pair are not supported.");
}
}

template<typename MsgT, typename DataT>
inline void MessagePair<MsgT, DataT>::read_translated_message(const MsgT& message) {
translators::read_message(*this->data_, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ template<typename MsgT>
std::function<void(const std::shared_ptr<MsgT>)> SubscriptionHandler<MsgT>::get_raw_callback() {
return [this](const std::shared_ptr<MsgT> message) {
try {
// this->get_message_pair()->template read<MsgT, MsgT>(*message);
// this->user_callback_();
this->get_message_pair()->template read<MsgT, MsgT>(*message);
this->user_callback_();
} catch (...) {
// this->handle_callback_exceptions();
this->handle_callback_exceptions();
}
};
}
Expand Down
17 changes: 17 additions & 0 deletions source/modulo_core/test/cpp/communication/test_communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include "test_modulo_core/communication_nodes.hpp"

#include <sensor_msgs/msg/image.hpp>
#include <sensor_msgs/msg/imu.hpp>

using namespace modulo_core::communication;

class CommunicationTest : public ::testing::Test {
Expand Down Expand Up @@ -60,3 +63,17 @@ TEST_F(CommunicationTest, BasicTypes) {
this->communicate<std_msgs::msg::Int32, int>(1, 2);
this->communicate<std_msgs::msg::String, std::string>("this", "that");
}

TEST_F(CommunicationTest, CustomTypes) {
sensor_msgs::msg::Image initial_image;
initial_image.height = 480;
sensor_msgs::msg::Image new_image;
new_image.height = 320;
this->communicate<sensor_msgs::msg::Image, sensor_msgs::msg::Image>(initial_image, new_image);

// sensor_msgs::msg::Imu initial_imu;
// initial_imu.linear_acceleration.x = 1.0;
// sensor_msgs::msg::Imu new_imu;
// new_imu.linear_acceleration.x = 0.5;
// this->communicate<sensor_msgs::msg::Imu, sensor_msgs::msg::Imu>(initial_imu, new_imu);
}

0 comments on commit a4d63eb

Please sign in to comment.