Floats.h
Go to the documentation of this file.
00001 #ifndef _ROS_rospy_tutorials_Floats_h
00002 #define _ROS_rospy_tutorials_Floats_h
00003 
00004 #include <stdint.h>
00005 #include <string.h>
00006 #include <stdlib.h>
00007 #include "ros/msg.h"
00008 
00009 namespace rospy_tutorials
00010 {
00011 
00012   class Floats : public ros::Msg
00013   {
00014     public:
00015       uint8_t data_length;
00016       float st_data;
00017       float * data;
00018 
00019     virtual int serialize(unsigned char *outbuffer) const
00020     {
00021       int offset = 0;
00022       *(outbuffer + offset++) = data_length;
00023       *(outbuffer + offset++) = 0;
00024       *(outbuffer + offset++) = 0;
00025       *(outbuffer + offset++) = 0;
00026       for( uint8_t i = 0; i < data_length; i++){
00027       union {
00028         float real;
00029         uint32_t base;
00030       } u_datai;
00031       u_datai.real = this->data[i];
00032       *(outbuffer + offset + 0) = (u_datai.base >> (8 * 0)) & 0xFF;
00033       *(outbuffer + offset + 1) = (u_datai.base >> (8 * 1)) & 0xFF;
00034       *(outbuffer + offset + 2) = (u_datai.base >> (8 * 2)) & 0xFF;
00035       *(outbuffer + offset + 3) = (u_datai.base >> (8 * 3)) & 0xFF;
00036       offset += sizeof(this->data[i]);
00037       }
00038       return offset;
00039     }
00040 
00041     virtual int deserialize(unsigned char *inbuffer)
00042     {
00043       int offset = 0;
00044       uint8_t data_lengthT = *(inbuffer + offset++);
00045       if(data_lengthT > data_length)
00046         this->data = (float*)realloc(this->data, data_lengthT * sizeof(float));
00047       offset += 3;
00048       data_length = data_lengthT;
00049       for( uint8_t i = 0; i < data_length; i++){
00050       union {
00051         float real;
00052         uint32_t base;
00053       } u_st_data;
00054       u_st_data.base = 0;
00055       u_st_data.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
00056       u_st_data.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
00057       u_st_data.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
00058       u_st_data.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
00059       this->st_data = u_st_data.real;
00060       offset += sizeof(this->st_data);
00061         memcpy( &(this->data[i]), &(this->st_data), sizeof(float));
00062       }
00063      return offset;
00064     }
00065 
00066     const char * getType(){ return "rospy_tutorials/Floats"; };
00067     const char * getMD5(){ return "420cd38b6b071cd49f2970c3e2cee511"; };
00068 
00069   };
00070 
00071 }
00072 #endif


ric_mc
Author(s): RoboTiCan
autogenerated on Thu Aug 27 2015 14:39:49