Working towards recieving twists
Fork of ros_lib_kinetic by
Embed:
(wiki syntax)
Show/hide line numbers
Spawn.h
00001 #ifndef _ROS_SERVICE_Spawn_h 00002 #define _ROS_SERVICE_Spawn_h 00003 #include <stdint.h> 00004 #include <string.h> 00005 #include <stdlib.h> 00006 #include "ros/msg.h" 00007 00008 namespace turtlesim 00009 { 00010 00011 static const char SPAWN[] = "turtlesim/Spawn"; 00012 00013 class SpawnRequest : public ros::Msg 00014 { 00015 public: 00016 typedef float _x_type; 00017 _x_type x; 00018 typedef float _y_type; 00019 _y_type y; 00020 typedef float _theta_type; 00021 _theta_type theta; 00022 typedef const char* _name_type; 00023 _name_type name; 00024 00025 SpawnRequest(): 00026 x(0), 00027 y(0), 00028 theta(0), 00029 name("") 00030 { 00031 } 00032 00033 virtual int serialize(unsigned char *outbuffer) const 00034 { 00035 int offset = 0; 00036 union { 00037 float real; 00038 uint32_t base; 00039 } u_x; 00040 u_x.real = this->x; 00041 *(outbuffer + offset + 0) = (u_x.base >> (8 * 0)) & 0xFF; 00042 *(outbuffer + offset + 1) = (u_x.base >> (8 * 1)) & 0xFF; 00043 *(outbuffer + offset + 2) = (u_x.base >> (8 * 2)) & 0xFF; 00044 *(outbuffer + offset + 3) = (u_x.base >> (8 * 3)) & 0xFF; 00045 offset += sizeof(this->x); 00046 union { 00047 float real; 00048 uint32_t base; 00049 } u_y; 00050 u_y.real = this->y; 00051 *(outbuffer + offset + 0) = (u_y.base >> (8 * 0)) & 0xFF; 00052 *(outbuffer + offset + 1) = (u_y.base >> (8 * 1)) & 0xFF; 00053 *(outbuffer + offset + 2) = (u_y.base >> (8 * 2)) & 0xFF; 00054 *(outbuffer + offset + 3) = (u_y.base >> (8 * 3)) & 0xFF; 00055 offset += sizeof(this->y); 00056 union { 00057 float real; 00058 uint32_t base; 00059 } u_theta; 00060 u_theta.real = this->theta; 00061 *(outbuffer + offset + 0) = (u_theta.base >> (8 * 0)) & 0xFF; 00062 *(outbuffer + offset + 1) = (u_theta.base >> (8 * 1)) & 0xFF; 00063 *(outbuffer + offset + 2) = (u_theta.base >> (8 * 2)) & 0xFF; 00064 *(outbuffer + offset + 3) = (u_theta.base >> (8 * 3)) & 0xFF; 00065 offset += sizeof(this->theta); 00066 uint32_t length_name = strlen(this->name); 00067 varToArr(outbuffer + offset, length_name); 00068 offset += 4; 00069 memcpy(outbuffer + offset, this->name, length_name); 00070 offset += length_name; 00071 return offset; 00072 } 00073 00074 virtual int deserialize(unsigned char *inbuffer) 00075 { 00076 int offset = 0; 00077 union { 00078 float real; 00079 uint32_t base; 00080 } u_x; 00081 u_x.base = 0; 00082 u_x.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); 00083 u_x.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 00084 u_x.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 00085 u_x.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 00086 this->x = u_x.real; 00087 offset += sizeof(this->x); 00088 union { 00089 float real; 00090 uint32_t base; 00091 } u_y; 00092 u_y.base = 0; 00093 u_y.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); 00094 u_y.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 00095 u_y.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 00096 u_y.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 00097 this->y = u_y.real; 00098 offset += sizeof(this->y); 00099 union { 00100 float real; 00101 uint32_t base; 00102 } u_theta; 00103 u_theta.base = 0; 00104 u_theta.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); 00105 u_theta.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 00106 u_theta.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 00107 u_theta.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 00108 this->theta = u_theta.real; 00109 offset += sizeof(this->theta); 00110 uint32_t length_name; 00111 arrToVar(length_name, (inbuffer + offset)); 00112 offset += 4; 00113 for(unsigned int k= offset; k< offset+length_name; ++k){ 00114 inbuffer[k-1]=inbuffer[k]; 00115 } 00116 inbuffer[offset+length_name-1]=0; 00117 this->name = (char *)(inbuffer + offset-1); 00118 offset += length_name; 00119 return offset; 00120 } 00121 00122 const char * getType(){ return SPAWN; }; 00123 const char * getMD5(){ return "57f001c49ab7b11d699f8606c1f4f7ff"; }; 00124 00125 }; 00126 00127 class SpawnResponse : public ros::Msg 00128 { 00129 public: 00130 typedef const char* _name_type; 00131 _name_type name; 00132 00133 SpawnResponse(): 00134 name("") 00135 { 00136 } 00137 00138 virtual int serialize(unsigned char *outbuffer) const 00139 { 00140 int offset = 0; 00141 uint32_t length_name = strlen(this->name); 00142 varToArr(outbuffer + offset, length_name); 00143 offset += 4; 00144 memcpy(outbuffer + offset, this->name, length_name); 00145 offset += length_name; 00146 return offset; 00147 } 00148 00149 virtual int deserialize(unsigned char *inbuffer) 00150 { 00151 int offset = 0; 00152 uint32_t length_name; 00153 arrToVar(length_name, (inbuffer + offset)); 00154 offset += 4; 00155 for(unsigned int k= offset; k< offset+length_name; ++k){ 00156 inbuffer[k-1]=inbuffer[k]; 00157 } 00158 inbuffer[offset+length_name-1]=0; 00159 this->name = (char *)(inbuffer + offset-1); 00160 offset += length_name; 00161 return offset; 00162 } 00163 00164 const char * getType(){ return SPAWN; }; 00165 const char * getMD5(){ return "c1f3d28f1b044c871e6eff2e9fc3c667"; }; 00166 00167 }; 00168 00169 class Spawn { 00170 public: 00171 typedef SpawnRequest Request; 00172 typedef SpawnResponse Response; 00173 }; 00174 00175 } 00176 #endif
Generated on Tue Jul 12 2022 21:32:17 by 1.7.2