Working towards recieving twists

Dependencies:   BufferedSerial

Fork of ros_lib_kinetic by Gary Servin

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LinkStates.h Source File

LinkStates.h

00001 #ifndef _ROS_gazebo_msgs_LinkStates_h
00002 #define _ROS_gazebo_msgs_LinkStates_h
00003 
00004 #include <stdint.h>
00005 #include <string.h>
00006 #include <stdlib.h>
00007 #include "ros/msg.h"
00008 #include "geometry_msgs/Pose.h"
00009 #include "geometry_msgs/Twist.h"
00010 
00011 namespace gazebo_msgs
00012 {
00013 
00014   class LinkStates : public ros::Msg
00015   {
00016     public:
00017       uint32_t name_length;
00018       typedef char* _name_type;
00019       _name_type st_name;
00020       _name_type * name;
00021       uint32_t pose_length;
00022       typedef geometry_msgs::Pose _pose_type;
00023       _pose_type st_pose;
00024       _pose_type * pose;
00025       uint32_t twist_length;
00026       typedef geometry_msgs::Twist _twist_type;
00027       _twist_type st_twist;
00028       _twist_type * twist;
00029 
00030     LinkStates():
00031       name_length(0), name(NULL),
00032       pose_length(0), pose(NULL),
00033       twist_length(0), twist(NULL)
00034     {
00035     }
00036 
00037     virtual int serialize(unsigned char *outbuffer) const
00038     {
00039       int offset = 0;
00040       *(outbuffer + offset + 0) = (this->name_length >> (8 * 0)) & 0xFF;
00041       *(outbuffer + offset + 1) = (this->name_length >> (8 * 1)) & 0xFF;
00042       *(outbuffer + offset + 2) = (this->name_length >> (8 * 2)) & 0xFF;
00043       *(outbuffer + offset + 3) = (this->name_length >> (8 * 3)) & 0xFF;
00044       offset += sizeof(this->name_length);
00045       for( uint32_t i = 0; i < name_length; i++){
00046       uint32_t length_namei = strlen(this->name[i]);
00047       varToArr(outbuffer + offset, length_namei);
00048       offset += 4;
00049       memcpy(outbuffer + offset, this->name[i], length_namei);
00050       offset += length_namei;
00051       }
00052       *(outbuffer + offset + 0) = (this->pose_length >> (8 * 0)) & 0xFF;
00053       *(outbuffer + offset + 1) = (this->pose_length >> (8 * 1)) & 0xFF;
00054       *(outbuffer + offset + 2) = (this->pose_length >> (8 * 2)) & 0xFF;
00055       *(outbuffer + offset + 3) = (this->pose_length >> (8 * 3)) & 0xFF;
00056       offset += sizeof(this->pose_length);
00057       for( uint32_t i = 0; i < pose_length; i++){
00058       offset += this->pose[i].serialize(outbuffer + offset);
00059       }
00060       *(outbuffer + offset + 0) = (this->twist_length >> (8 * 0)) & 0xFF;
00061       *(outbuffer + offset + 1) = (this->twist_length >> (8 * 1)) & 0xFF;
00062       *(outbuffer + offset + 2) = (this->twist_length >> (8 * 2)) & 0xFF;
00063       *(outbuffer + offset + 3) = (this->twist_length >> (8 * 3)) & 0xFF;
00064       offset += sizeof(this->twist_length);
00065       for( uint32_t i = 0; i < twist_length; i++){
00066       offset += this->twist[i].serialize(outbuffer + offset);
00067       }
00068       return offset;
00069     }
00070 
00071     virtual int deserialize(unsigned char *inbuffer)
00072     {
00073       int offset = 0;
00074       uint32_t name_lengthT = ((uint32_t) (*(inbuffer + offset))); 
00075       name_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 
00076       name_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 
00077       name_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 
00078       offset += sizeof(this->name_length);
00079       if(name_lengthT > name_length)
00080         this->name = (char**)realloc(this->name, name_lengthT * sizeof(char*));
00081       name_length = name_lengthT;
00082       for( uint32_t i = 0; i < name_length; i++){
00083       uint32_t length_st_name;
00084       arrToVar(length_st_name, (inbuffer + offset));
00085       offset += 4;
00086       for(unsigned int k= offset; k< offset+length_st_name; ++k){
00087           inbuffer[k-1]=inbuffer[k];
00088       }
00089       inbuffer[offset+length_st_name-1]=0;
00090       this->st_name = (char *)(inbuffer + offset-1);
00091       offset += length_st_name;
00092         memcpy( &(this->name[i]), &(this->st_name), sizeof(char*));
00093       }
00094       uint32_t pose_lengthT = ((uint32_t) (*(inbuffer + offset))); 
00095       pose_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 
00096       pose_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 
00097       pose_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 
00098       offset += sizeof(this->pose_length);
00099       if(pose_lengthT > pose_length)
00100         this->pose = (geometry_msgs::Pose*)realloc(this->pose, pose_lengthT * sizeof(geometry_msgs::Pose));
00101       pose_length = pose_lengthT;
00102       for( uint32_t i = 0; i < pose_length; i++){
00103       offset += this->st_pose.deserialize(inbuffer + offset);
00104         memcpy( &(this->pose[i]), &(this->st_pose), sizeof(geometry_msgs::Pose));
00105       }
00106       uint32_t twist_lengthT = ((uint32_t) (*(inbuffer + offset))); 
00107       twist_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 
00108       twist_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 
00109       twist_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 
00110       offset += sizeof(this->twist_length);
00111       if(twist_lengthT > twist_length)
00112         this->twist = (geometry_msgs::Twist*)realloc(this->twist, twist_lengthT * sizeof(geometry_msgs::Twist));
00113       twist_length = twist_lengthT;
00114       for( uint32_t i = 0; i < twist_length; i++){
00115       offset += this->st_twist.deserialize(inbuffer + offset);
00116         memcpy( &(this->twist[i]), &(this->st_twist), sizeof(geometry_msgs::Twist));
00117       }
00118      return offset;
00119     }
00120 
00121     const char * getType(){ return "gazebo_msgs/LinkStates"; };
00122     const char * getMD5(){ return "48c080191eb15c41858319b4d8a609c2"; };
00123 
00124   };
00125 
00126 }
00127 #endif