ROS Serial library for Mbed platforms for ROS Indigo Igloo. Check http://wiki.ros.org/rosserial_mbed/ for more information
Dependents: rosserial_mbed_hello_world_publisher rtos_base_control rosserial_mbed_F64MA ROS-RTOS ... more
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 float x; 00017 float y; 00018 float theta; 00019 const char* name; 00020 00021 SpawnRequest(): 00022 x(0), 00023 y(0), 00024 theta(0), 00025 name("") 00026 { 00027 } 00028 00029 virtual int serialize(unsigned char *outbuffer) const 00030 { 00031 int offset = 0; 00032 union { 00033 float real; 00034 uint32_t base; 00035 } u_x; 00036 u_x.real = this->x; 00037 *(outbuffer + offset + 0) = (u_x.base >> (8 * 0)) & 0xFF; 00038 *(outbuffer + offset + 1) = (u_x.base >> (8 * 1)) & 0xFF; 00039 *(outbuffer + offset + 2) = (u_x.base >> (8 * 2)) & 0xFF; 00040 *(outbuffer + offset + 3) = (u_x.base >> (8 * 3)) & 0xFF; 00041 offset += sizeof(this->x); 00042 union { 00043 float real; 00044 uint32_t base; 00045 } u_y; 00046 u_y.real = this->y; 00047 *(outbuffer + offset + 0) = (u_y.base >> (8 * 0)) & 0xFF; 00048 *(outbuffer + offset + 1) = (u_y.base >> (8 * 1)) & 0xFF; 00049 *(outbuffer + offset + 2) = (u_y.base >> (8 * 2)) & 0xFF; 00050 *(outbuffer + offset + 3) = (u_y.base >> (8 * 3)) & 0xFF; 00051 offset += sizeof(this->y); 00052 union { 00053 float real; 00054 uint32_t base; 00055 } u_theta; 00056 u_theta.real = this->theta; 00057 *(outbuffer + offset + 0) = (u_theta.base >> (8 * 0)) & 0xFF; 00058 *(outbuffer + offset + 1) = (u_theta.base >> (8 * 1)) & 0xFF; 00059 *(outbuffer + offset + 2) = (u_theta.base >> (8 * 2)) & 0xFF; 00060 *(outbuffer + offset + 3) = (u_theta.base >> (8 * 3)) & 0xFF; 00061 offset += sizeof(this->theta); 00062 uint32_t length_name = strlen(this->name); 00063 memcpy(outbuffer + offset, &length_name, sizeof(uint32_t)); 00064 offset += 4; 00065 memcpy(outbuffer + offset, this->name, length_name); 00066 offset += length_name; 00067 return offset; 00068 } 00069 00070 virtual int deserialize(unsigned char *inbuffer) 00071 { 00072 int offset = 0; 00073 union { 00074 float real; 00075 uint32_t base; 00076 } u_x; 00077 u_x.base = 0; 00078 u_x.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); 00079 u_x.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 00080 u_x.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 00081 u_x.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 00082 this->x = u_x.real; 00083 offset += sizeof(this->x); 00084 union { 00085 float real; 00086 uint32_t base; 00087 } u_y; 00088 u_y.base = 0; 00089 u_y.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); 00090 u_y.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 00091 u_y.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 00092 u_y.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 00093 this->y = u_y.real; 00094 offset += sizeof(this->y); 00095 union { 00096 float real; 00097 uint32_t base; 00098 } u_theta; 00099 u_theta.base = 0; 00100 u_theta.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); 00101 u_theta.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 00102 u_theta.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 00103 u_theta.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 00104 this->theta = u_theta.real; 00105 offset += sizeof(this->theta); 00106 uint32_t length_name; 00107 memcpy(&length_name, (inbuffer + offset), sizeof(uint32_t)); 00108 offset += 4; 00109 for(unsigned int k= offset; k< offset+length_name; ++k){ 00110 inbuffer[k-1]=inbuffer[k]; 00111 } 00112 inbuffer[offset+length_name-1]=0; 00113 this->name = (char *)(inbuffer + offset-1); 00114 offset += length_name; 00115 return offset; 00116 } 00117 00118 const char * getType(){ return SPAWN; }; 00119 const char * getMD5(){ return "57f001c49ab7b11d699f8606c1f4f7ff"; }; 00120 00121 }; 00122 00123 class SpawnResponse : public ros::Msg 00124 { 00125 public: 00126 const char* name; 00127 00128 SpawnResponse(): 00129 name("") 00130 { 00131 } 00132 00133 virtual int serialize(unsigned char *outbuffer) const 00134 { 00135 int offset = 0; 00136 uint32_t length_name = strlen(this->name); 00137 memcpy(outbuffer + offset, &length_name, sizeof(uint32_t)); 00138 offset += 4; 00139 memcpy(outbuffer + offset, this->name, length_name); 00140 offset += length_name; 00141 return offset; 00142 } 00143 00144 virtual int deserialize(unsigned char *inbuffer) 00145 { 00146 int offset = 0; 00147 uint32_t length_name; 00148 memcpy(&length_name, (inbuffer + offset), sizeof(uint32_t)); 00149 offset += 4; 00150 for(unsigned int k= offset; k< offset+length_name; ++k){ 00151 inbuffer[k-1]=inbuffer[k]; 00152 } 00153 inbuffer[offset+length_name-1]=0; 00154 this->name = (char *)(inbuffer + offset-1); 00155 offset += length_name; 00156 return offset; 00157 } 00158 00159 const char * getType(){ return SPAWN; }; 00160 const char * getMD5(){ return "c1f3d28f1b044c871e6eff2e9fc3c667"; }; 00161 00162 }; 00163 00164 class Spawn { 00165 public: 00166 typedef SpawnRequest Request; 00167 typedef SpawnResponse Response; 00168 }; 00169 00170 } 00171 #endif
Generated on Tue Jul 12 2022 18:39:41 by 1.7.2