ROS Serial library for Mbed platforms for ROS Indigo Igloo. Check http://wiki.ros.org/rosserial_mbed/ for more information

Dependencies:   BufferedSerial

Dependents:   rosserial_mbed_hello_world_publisher rtos_base_control rosserial_mbed_F64MA ROS-RTOS ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TopicInfo.h Source File

TopicInfo.h

00001 #ifndef _ROS_rosserial_msgs_TopicInfo_h
00002 #define _ROS_rosserial_msgs_TopicInfo_h
00003 
00004 #include <stdint.h>
00005 #include <string.h>
00006 #include <stdlib.h>
00007 #include "ros/msg.h"
00008 
00009 namespace rosserial_msgs
00010 {
00011 
00012   class TopicInfo : public ros::Msg
00013   {
00014     public:
00015       uint16_t topic_id;
00016       const char* topic_name;
00017       const char* message_type;
00018       const char* md5sum;
00019       int32_t buffer_size;
00020       enum { ID_PUBLISHER = 0 };
00021       enum { ID_SUBSCRIBER = 1 };
00022       enum { ID_SERVICE_SERVER = 2 };
00023       enum { ID_SERVICE_CLIENT = 4 };
00024       enum { ID_PARAMETER_REQUEST = 6 };
00025       enum { ID_LOG = 7 };
00026       enum { ID_TIME = 10 };
00027       enum { ID_TX_STOP = 11 };
00028 
00029     TopicInfo():
00030       topic_id(0),
00031       topic_name(""),
00032       message_type(""),
00033       md5sum(""),
00034       buffer_size(0)
00035     {
00036     }
00037 
00038     virtual int serialize(unsigned char *outbuffer) const
00039     {
00040       int offset = 0;
00041       *(outbuffer + offset + 0) = (this->topic_id >> (8 * 0)) & 0xFF;
00042       *(outbuffer + offset + 1) = (this->topic_id >> (8 * 1)) & 0xFF;
00043       offset += sizeof(this->topic_id);
00044       uint32_t length_topic_name = strlen(this->topic_name);
00045       memcpy(outbuffer + offset, &length_topic_name, sizeof(uint32_t));
00046       offset += 4;
00047       memcpy(outbuffer + offset, this->topic_name, length_topic_name);
00048       offset += length_topic_name;
00049       uint32_t length_message_type = strlen(this->message_type);
00050       memcpy(outbuffer + offset, &length_message_type, sizeof(uint32_t));
00051       offset += 4;
00052       memcpy(outbuffer + offset, this->message_type, length_message_type);
00053       offset += length_message_type;
00054       uint32_t length_md5sum = strlen(this->md5sum);
00055       memcpy(outbuffer + offset, &length_md5sum, sizeof(uint32_t));
00056       offset += 4;
00057       memcpy(outbuffer + offset, this->md5sum, length_md5sum);
00058       offset += length_md5sum;
00059       union {
00060         int32_t real;
00061         uint32_t base;
00062       } u_buffer_size;
00063       u_buffer_size.real = this->buffer_size;
00064       *(outbuffer + offset + 0) = (u_buffer_size.base >> (8 * 0)) & 0xFF;
00065       *(outbuffer + offset + 1) = (u_buffer_size.base >> (8 * 1)) & 0xFF;
00066       *(outbuffer + offset + 2) = (u_buffer_size.base >> (8 * 2)) & 0xFF;
00067       *(outbuffer + offset + 3) = (u_buffer_size.base >> (8 * 3)) & 0xFF;
00068       offset += sizeof(this->buffer_size);
00069       return offset;
00070     }
00071 
00072     virtual int deserialize(unsigned char *inbuffer)
00073     {
00074       int offset = 0;
00075       this->topic_id =  ((uint16_t) (*(inbuffer + offset)));
00076       this->topic_id |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1);
00077       offset += sizeof(this->topic_id);
00078       uint32_t length_topic_name;
00079       memcpy(&length_topic_name, (inbuffer + offset), sizeof(uint32_t));
00080       offset += 4;
00081       for(unsigned int k= offset; k< offset+length_topic_name; ++k){
00082           inbuffer[k-1]=inbuffer[k];
00083       }
00084       inbuffer[offset+length_topic_name-1]=0;
00085       this->topic_name = (char *)(inbuffer + offset-1);
00086       offset += length_topic_name;
00087       uint32_t length_message_type;
00088       memcpy(&length_message_type, (inbuffer + offset), sizeof(uint32_t));
00089       offset += 4;
00090       for(unsigned int k= offset; k< offset+length_message_type; ++k){
00091           inbuffer[k-1]=inbuffer[k];
00092       }
00093       inbuffer[offset+length_message_type-1]=0;
00094       this->message_type = (char *)(inbuffer + offset-1);
00095       offset += length_message_type;
00096       uint32_t length_md5sum;
00097       memcpy(&length_md5sum, (inbuffer + offset), sizeof(uint32_t));
00098       offset += 4;
00099       for(unsigned int k= offset; k< offset+length_md5sum; ++k){
00100           inbuffer[k-1]=inbuffer[k];
00101       }
00102       inbuffer[offset+length_md5sum-1]=0;
00103       this->md5sum = (char *)(inbuffer + offset-1);
00104       offset += length_md5sum;
00105       union {
00106         int32_t real;
00107         uint32_t base;
00108       } u_buffer_size;
00109       u_buffer_size.base = 0;
00110       u_buffer_size.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
00111       u_buffer_size.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
00112       u_buffer_size.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
00113       u_buffer_size.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
00114       this->buffer_size = u_buffer_size.real;
00115       offset += sizeof(this->buffer_size);
00116      return offset;
00117     }
00118 
00119     const char * getType(){ return "rosserial_msgs/TopicInfo"; };
00120     const char * getMD5(){ return "0ad51f88fc44892f8c10684077646005"; };
00121 
00122   };
00123 
00124 }
00125 #endif