ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hello,

I had a small success with my problem.

I am now able to publish messages, i.e. each instance of my GenericPublisher class is now able to publish on the correct topic with the correct type at the correct time.

But still there is no data in the message. It publishes 0 for the std_msgs::Int32 and '' for the std_msgs::String.

This is the ByteArrayMessage class:

class ByteArrayMessage 
{
public:
    ByteArrayMessage(uint8_t* buffer, uint32_t length, std::string dataType, std::string md5sum, std::string messageDefinition) 
        : __serialized_length(length),
          m_dataType(dataType),
          m_md5sum(md5sum),
          m_messageDefinition(messageDefinition),
          buffer_(buffer), length_(length)
    {}

    const std::string __getDataType() const {   return m_dataType;  }
    const std::string __getMD5Sum() const   {   return m_md5sum;    }
    const std::string __getMessageDefinition() const    {   return m_messageDefinition; }

    uint32_t serializationLength() const    {   return __serialized_length; }
    uint8_t *serialize(uint8_t *write_ptr, uint32_t seq) const;

    uint8_t byte(size_t i) {    return buffer_[i];  }
    uint32_t length() { return length_; }

    uint32_t __serialized_length;


private:
    std::string m_dataType;
    std::string m_md5sum;
    std::string m_messageDefinition;

    uint8_t *buffer_;
    uint32_t length_;
};

uint8_t* ByteArrayMessage::serialize(uint8_t *write_ptr, uint32_t seq) const
{
    ROS_INFO("call ByteArrayMessage::serialize");
    return buffer_;
}

This is the Serializer struct that I use:

namespace serialization{

template<>
struct Serializer<ByteArrayMessage>{
    template<typename Stream>
    inline static void write(Stream& stream, const ByteArrayMessage& m) {
        m.write(stream);
    }

    inline static uint32_t serializedLength(const ByteArrayMessage& m) {
        return m.length();  
    }
};

} // namespace serialization

Initialization as follows:

ByteArrayMessage msg(i_stream.getData(), i_stream.getLength(), m_genericRosTopic.MessageDataType, m_genericRosTopic.MD5Sum, m_genericRosTopic.MessageDefinition);

msg.byte() shows that buffer_ in my ByteArrayMessage it contains the desired message.

I also recognized that neither the serialize nor the write function is called during execution. Thus it seems that the Stream is still empty.

Can anyone give me a little more details on what happens when calling

m_genericRosTopic_publisher.publish(msg);

Any suggestions on how I can get the buffer_ data into the stream?