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