GenericPublisher using ShapeShifter and SerializedMessage
Hi there,
I want to write a generic publisher that is able to publish ros-topics where each instance of this class publishes topics of different message types (e.g. pub_1 publishes std_msg::Int32, pub_2 publishes sensor_msgs::PointCloud2,...).
I work with serialized messages, i.e.:
ros::serialization::IStream i_stream((u_int8_t*) testArray.data(), m_genericRosTopic.SerializedMessageSize);
contains my serialized message which I want to publish. I also know the message type and the topic_name, that I want to publish on.
How can I do this in a generic way? I saw that the ros::Publisher class has a publish() function that is able to publish a ros::SerializedMessage.
Thus, I made a SerializedMessage from the IStream:
boost::shared_array<uint8_t> buf(i_stream.getData());
ros::SerializedMessage msg(buf, i_stream.getLength());
My generic publisher class has a ros::Publisher as a member. For advertising, I found:
m_genericRosTopic_publisher = m_shapeShifter.advertise(n, m_genericRosTopic.TopicName, 10);
After that I would like to publish the topic somehow:
m_genericRosTopic_publisher.publish(msg);
Publishing like this doesn't work. I guess there is still something missing. But it seems that everything I need is already there (somewhere in roscpp), but I am not able to put the puzzle together.
Can someone help me out here, by clarifying the correct usage of topic_tools::ShapeShifter, ros::SerializedMessage and ros::Publisher?
Thanks for your help!