hairo

Dependencies:   mbed BufferedSerial

Committer:
garyservin
Date:
Sat Dec 31 00:48:34 2016 +0000
Revision:
0:9e9b7db60fd5
Initial commit, generated based on a clean kinetic-desktop-full

Who changed what in which revision?

UserRevisionLine numberNew contents of line
garyservin 0:9e9b7db60fd5 1 #ifndef _ROS_SERVICE_Spawn_h
garyservin 0:9e9b7db60fd5 2 #define _ROS_SERVICE_Spawn_h
garyservin 0:9e9b7db60fd5 3 #include <stdint.h>
garyservin 0:9e9b7db60fd5 4 #include <string.h>
garyservin 0:9e9b7db60fd5 5 #include <stdlib.h>
garyservin 0:9e9b7db60fd5 6 #include "ros/msg.h"
garyservin 0:9e9b7db60fd5 7
garyservin 0:9e9b7db60fd5 8 namespace turtlesim
garyservin 0:9e9b7db60fd5 9 {
garyservin 0:9e9b7db60fd5 10
garyservin 0:9e9b7db60fd5 11 static const char SPAWN[] = "turtlesim/Spawn";
garyservin 0:9e9b7db60fd5 12
garyservin 0:9e9b7db60fd5 13 class SpawnRequest : public ros::Msg
garyservin 0:9e9b7db60fd5 14 {
garyservin 0:9e9b7db60fd5 15 public:
garyservin 0:9e9b7db60fd5 16 typedef float _x_type;
garyservin 0:9e9b7db60fd5 17 _x_type x;
garyservin 0:9e9b7db60fd5 18 typedef float _y_type;
garyservin 0:9e9b7db60fd5 19 _y_type y;
garyservin 0:9e9b7db60fd5 20 typedef float _theta_type;
garyservin 0:9e9b7db60fd5 21 _theta_type theta;
garyservin 0:9e9b7db60fd5 22 typedef const char* _name_type;
garyservin 0:9e9b7db60fd5 23 _name_type name;
garyservin 0:9e9b7db60fd5 24
garyservin 0:9e9b7db60fd5 25 SpawnRequest():
garyservin 0:9e9b7db60fd5 26 x(0),
garyservin 0:9e9b7db60fd5 27 y(0),
garyservin 0:9e9b7db60fd5 28 theta(0),
garyservin 0:9e9b7db60fd5 29 name("")
garyservin 0:9e9b7db60fd5 30 {
garyservin 0:9e9b7db60fd5 31 }
garyservin 0:9e9b7db60fd5 32
garyservin 0:9e9b7db60fd5 33 virtual int serialize(unsigned char *outbuffer) const
garyservin 0:9e9b7db60fd5 34 {
garyservin 0:9e9b7db60fd5 35 int offset = 0;
garyservin 0:9e9b7db60fd5 36 union {
garyservin 0:9e9b7db60fd5 37 float real;
garyservin 0:9e9b7db60fd5 38 uint32_t base;
garyservin 0:9e9b7db60fd5 39 } u_x;
garyservin 0:9e9b7db60fd5 40 u_x.real = this->x;
garyservin 0:9e9b7db60fd5 41 *(outbuffer + offset + 0) = (u_x.base >> (8 * 0)) & 0xFF;
garyservin 0:9e9b7db60fd5 42 *(outbuffer + offset + 1) = (u_x.base >> (8 * 1)) & 0xFF;
garyservin 0:9e9b7db60fd5 43 *(outbuffer + offset + 2) = (u_x.base >> (8 * 2)) & 0xFF;
garyservin 0:9e9b7db60fd5 44 *(outbuffer + offset + 3) = (u_x.base >> (8 * 3)) & 0xFF;
garyservin 0:9e9b7db60fd5 45 offset += sizeof(this->x);
garyservin 0:9e9b7db60fd5 46 union {
garyservin 0:9e9b7db60fd5 47 float real;
garyservin 0:9e9b7db60fd5 48 uint32_t base;
garyservin 0:9e9b7db60fd5 49 } u_y;
garyservin 0:9e9b7db60fd5 50 u_y.real = this->y;
garyservin 0:9e9b7db60fd5 51 *(outbuffer + offset + 0) = (u_y.base >> (8 * 0)) & 0xFF;
garyservin 0:9e9b7db60fd5 52 *(outbuffer + offset + 1) = (u_y.base >> (8 * 1)) & 0xFF;
garyservin 0:9e9b7db60fd5 53 *(outbuffer + offset + 2) = (u_y.base >> (8 * 2)) & 0xFF;
garyservin 0:9e9b7db60fd5 54 *(outbuffer + offset + 3) = (u_y.base >> (8 * 3)) & 0xFF;
garyservin 0:9e9b7db60fd5 55 offset += sizeof(this->y);
garyservin 0:9e9b7db60fd5 56 union {
garyservin 0:9e9b7db60fd5 57 float real;
garyservin 0:9e9b7db60fd5 58 uint32_t base;
garyservin 0:9e9b7db60fd5 59 } u_theta;
garyservin 0:9e9b7db60fd5 60 u_theta.real = this->theta;
garyservin 0:9e9b7db60fd5 61 *(outbuffer + offset + 0) = (u_theta.base >> (8 * 0)) & 0xFF;
garyservin 0:9e9b7db60fd5 62 *(outbuffer + offset + 1) = (u_theta.base >> (8 * 1)) & 0xFF;
garyservin 0:9e9b7db60fd5 63 *(outbuffer + offset + 2) = (u_theta.base >> (8 * 2)) & 0xFF;
garyservin 0:9e9b7db60fd5 64 *(outbuffer + offset + 3) = (u_theta.base >> (8 * 3)) & 0xFF;
garyservin 0:9e9b7db60fd5 65 offset += sizeof(this->theta);
garyservin 0:9e9b7db60fd5 66 uint32_t length_name = strlen(this->name);
garyservin 0:9e9b7db60fd5 67 varToArr(outbuffer + offset, length_name);
garyservin 0:9e9b7db60fd5 68 offset += 4;
garyservin 0:9e9b7db60fd5 69 memcpy(outbuffer + offset, this->name, length_name);
garyservin 0:9e9b7db60fd5 70 offset += length_name;
garyservin 0:9e9b7db60fd5 71 return offset;
garyservin 0:9e9b7db60fd5 72 }
garyservin 0:9e9b7db60fd5 73
garyservin 0:9e9b7db60fd5 74 virtual int deserialize(unsigned char *inbuffer)
garyservin 0:9e9b7db60fd5 75 {
garyservin 0:9e9b7db60fd5 76 int offset = 0;
garyservin 0:9e9b7db60fd5 77 union {
garyservin 0:9e9b7db60fd5 78 float real;
garyservin 0:9e9b7db60fd5 79 uint32_t base;
garyservin 0:9e9b7db60fd5 80 } u_x;
garyservin 0:9e9b7db60fd5 81 u_x.base = 0;
garyservin 0:9e9b7db60fd5 82 u_x.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
garyservin 0:9e9b7db60fd5 83 u_x.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
garyservin 0:9e9b7db60fd5 84 u_x.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
garyservin 0:9e9b7db60fd5 85 u_x.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
garyservin 0:9e9b7db60fd5 86 this->x = u_x.real;
garyservin 0:9e9b7db60fd5 87 offset += sizeof(this->x);
garyservin 0:9e9b7db60fd5 88 union {
garyservin 0:9e9b7db60fd5 89 float real;
garyservin 0:9e9b7db60fd5 90 uint32_t base;
garyservin 0:9e9b7db60fd5 91 } u_y;
garyservin 0:9e9b7db60fd5 92 u_y.base = 0;
garyservin 0:9e9b7db60fd5 93 u_y.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
garyservin 0:9e9b7db60fd5 94 u_y.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
garyservin 0:9e9b7db60fd5 95 u_y.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
garyservin 0:9e9b7db60fd5 96 u_y.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
garyservin 0:9e9b7db60fd5 97 this->y = u_y.real;
garyservin 0:9e9b7db60fd5 98 offset += sizeof(this->y);
garyservin 0:9e9b7db60fd5 99 union {
garyservin 0:9e9b7db60fd5 100 float real;
garyservin 0:9e9b7db60fd5 101 uint32_t base;
garyservin 0:9e9b7db60fd5 102 } u_theta;
garyservin 0:9e9b7db60fd5 103 u_theta.base = 0;
garyservin 0:9e9b7db60fd5 104 u_theta.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
garyservin 0:9e9b7db60fd5 105 u_theta.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
garyservin 0:9e9b7db60fd5 106 u_theta.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
garyservin 0:9e9b7db60fd5 107 u_theta.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
garyservin 0:9e9b7db60fd5 108 this->theta = u_theta.real;
garyservin 0:9e9b7db60fd5 109 offset += sizeof(this->theta);
garyservin 0:9e9b7db60fd5 110 uint32_t length_name;
garyservin 0:9e9b7db60fd5 111 arrToVar(length_name, (inbuffer + offset));
garyservin 0:9e9b7db60fd5 112 offset += 4;
garyservin 0:9e9b7db60fd5 113 for(unsigned int k= offset; k< offset+length_name; ++k){
garyservin 0:9e9b7db60fd5 114 inbuffer[k-1]=inbuffer[k];
garyservin 0:9e9b7db60fd5 115 }
garyservin 0:9e9b7db60fd5 116 inbuffer[offset+length_name-1]=0;
garyservin 0:9e9b7db60fd5 117 this->name = (char *)(inbuffer + offset-1);
garyservin 0:9e9b7db60fd5 118 offset += length_name;
garyservin 0:9e9b7db60fd5 119 return offset;
garyservin 0:9e9b7db60fd5 120 }
garyservin 0:9e9b7db60fd5 121
garyservin 0:9e9b7db60fd5 122 const char * getType(){ return SPAWN; };
garyservin 0:9e9b7db60fd5 123 const char * getMD5(){ return "57f001c49ab7b11d699f8606c1f4f7ff"; };
garyservin 0:9e9b7db60fd5 124
garyservin 0:9e9b7db60fd5 125 };
garyservin 0:9e9b7db60fd5 126
garyservin 0:9e9b7db60fd5 127 class SpawnResponse : public ros::Msg
garyservin 0:9e9b7db60fd5 128 {
garyservin 0:9e9b7db60fd5 129 public:
garyservin 0:9e9b7db60fd5 130 typedef const char* _name_type;
garyservin 0:9e9b7db60fd5 131 _name_type name;
garyservin 0:9e9b7db60fd5 132
garyservin 0:9e9b7db60fd5 133 SpawnResponse():
garyservin 0:9e9b7db60fd5 134 name("")
garyservin 0:9e9b7db60fd5 135 {
garyservin 0:9e9b7db60fd5 136 }
garyservin 0:9e9b7db60fd5 137
garyservin 0:9e9b7db60fd5 138 virtual int serialize(unsigned char *outbuffer) const
garyservin 0:9e9b7db60fd5 139 {
garyservin 0:9e9b7db60fd5 140 int offset = 0;
garyservin 0:9e9b7db60fd5 141 uint32_t length_name = strlen(this->name);
garyservin 0:9e9b7db60fd5 142 varToArr(outbuffer + offset, length_name);
garyservin 0:9e9b7db60fd5 143 offset += 4;
garyservin 0:9e9b7db60fd5 144 memcpy(outbuffer + offset, this->name, length_name);
garyservin 0:9e9b7db60fd5 145 offset += length_name;
garyservin 0:9e9b7db60fd5 146 return offset;
garyservin 0:9e9b7db60fd5 147 }
garyservin 0:9e9b7db60fd5 148
garyservin 0:9e9b7db60fd5 149 virtual int deserialize(unsigned char *inbuffer)
garyservin 0:9e9b7db60fd5 150 {
garyservin 0:9e9b7db60fd5 151 int offset = 0;
garyservin 0:9e9b7db60fd5 152 uint32_t length_name;
garyservin 0:9e9b7db60fd5 153 arrToVar(length_name, (inbuffer + offset));
garyservin 0:9e9b7db60fd5 154 offset += 4;
garyservin 0:9e9b7db60fd5 155 for(unsigned int k= offset; k< offset+length_name; ++k){
garyservin 0:9e9b7db60fd5 156 inbuffer[k-1]=inbuffer[k];
garyservin 0:9e9b7db60fd5 157 }
garyservin 0:9e9b7db60fd5 158 inbuffer[offset+length_name-1]=0;
garyservin 0:9e9b7db60fd5 159 this->name = (char *)(inbuffer + offset-1);
garyservin 0:9e9b7db60fd5 160 offset += length_name;
garyservin 0:9e9b7db60fd5 161 return offset;
garyservin 0:9e9b7db60fd5 162 }
garyservin 0:9e9b7db60fd5 163
garyservin 0:9e9b7db60fd5 164 const char * getType(){ return SPAWN; };
garyservin 0:9e9b7db60fd5 165 const char * getMD5(){ return "c1f3d28f1b044c871e6eff2e9fc3c667"; };
garyservin 0:9e9b7db60fd5 166
garyservin 0:9e9b7db60fd5 167 };
garyservin 0:9e9b7db60fd5 168
garyservin 0:9e9b7db60fd5 169 class Spawn {
garyservin 0:9e9b7db60fd5 170 public:
garyservin 0:9e9b7db60fd5 171 typedef SpawnRequest Request;
garyservin 0:9e9b7db60fd5 172 typedef SpawnResponse Response;
garyservin 0:9e9b7db60fd5 173 };
garyservin 0:9e9b7db60fd5 174
garyservin 0:9e9b7db60fd5 175 }
garyservin 0:9e9b7db60fd5 176 #endif