ros melodic library with custom message
Dependents: Robot_team1_QEI_Douglas Robot_team1
ros_lib/rosserial_msgs/RequestParam.h@0:020db18a476d, 2019-10-30 (annotated)
- Committer:
- scarter1
- Date:
- Wed Oct 30 14:59:49 2019 +0000
- Revision:
- 0:020db18a476d
melodic library;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
scarter1 | 0:020db18a476d | 1 | #ifndef _ROS_SERVICE_RequestParam_h |
scarter1 | 0:020db18a476d | 2 | #define _ROS_SERVICE_RequestParam_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 rosserial_msgs |
scarter1 | 0:020db18a476d | 9 | { |
scarter1 | 0:020db18a476d | 10 | |
scarter1 | 0:020db18a476d | 11 | static const char REQUESTPARAM[] = "rosserial_msgs/RequestParam"; |
scarter1 | 0:020db18a476d | 12 | |
scarter1 | 0:020db18a476d | 13 | class RequestParamRequest : public ros::Msg |
scarter1 | 0:020db18a476d | 14 | { |
scarter1 | 0:020db18a476d | 15 | public: |
scarter1 | 0:020db18a476d | 16 | typedef const char* _name_type; |
scarter1 | 0:020db18a476d | 17 | _name_type name; |
scarter1 | 0:020db18a476d | 18 | |
scarter1 | 0:020db18a476d | 19 | RequestParamRequest(): |
scarter1 | 0:020db18a476d | 20 | name("") |
scarter1 | 0:020db18a476d | 21 | { |
scarter1 | 0:020db18a476d | 22 | } |
scarter1 | 0:020db18a476d | 23 | |
scarter1 | 0:020db18a476d | 24 | virtual int serialize(unsigned char *outbuffer) const |
scarter1 | 0:020db18a476d | 25 | { |
scarter1 | 0:020db18a476d | 26 | int offset = 0; |
scarter1 | 0:020db18a476d | 27 | uint32_t length_name = strlen(this->name); |
scarter1 | 0:020db18a476d | 28 | varToArr(outbuffer + offset, length_name); |
scarter1 | 0:020db18a476d | 29 | offset += 4; |
scarter1 | 0:020db18a476d | 30 | memcpy(outbuffer + offset, this->name, length_name); |
scarter1 | 0:020db18a476d | 31 | offset += length_name; |
scarter1 | 0:020db18a476d | 32 | return offset; |
scarter1 | 0:020db18a476d | 33 | } |
scarter1 | 0:020db18a476d | 34 | |
scarter1 | 0:020db18a476d | 35 | virtual int deserialize(unsigned char *inbuffer) |
scarter1 | 0:020db18a476d | 36 | { |
scarter1 | 0:020db18a476d | 37 | int offset = 0; |
scarter1 | 0:020db18a476d | 38 | uint32_t length_name; |
scarter1 | 0:020db18a476d | 39 | arrToVar(length_name, (inbuffer + offset)); |
scarter1 | 0:020db18a476d | 40 | offset += 4; |
scarter1 | 0:020db18a476d | 41 | for(unsigned int k= offset; k< offset+length_name; ++k){ |
scarter1 | 0:020db18a476d | 42 | inbuffer[k-1]=inbuffer[k]; |
scarter1 | 0:020db18a476d | 43 | } |
scarter1 | 0:020db18a476d | 44 | inbuffer[offset+length_name-1]=0; |
scarter1 | 0:020db18a476d | 45 | this->name = (char *)(inbuffer + offset-1); |
scarter1 | 0:020db18a476d | 46 | offset += length_name; |
scarter1 | 0:020db18a476d | 47 | return offset; |
scarter1 | 0:020db18a476d | 48 | } |
scarter1 | 0:020db18a476d | 49 | |
scarter1 | 0:020db18a476d | 50 | const char * getType(){ return REQUESTPARAM; }; |
scarter1 | 0:020db18a476d | 51 | const char * getMD5(){ return "c1f3d28f1b044c871e6eff2e9fc3c667"; }; |
scarter1 | 0:020db18a476d | 52 | |
scarter1 | 0:020db18a476d | 53 | }; |
scarter1 | 0:020db18a476d | 54 | |
scarter1 | 0:020db18a476d | 55 | class RequestParamResponse : public ros::Msg |
scarter1 | 0:020db18a476d | 56 | { |
scarter1 | 0:020db18a476d | 57 | public: |
scarter1 | 0:020db18a476d | 58 | uint32_t ints_length; |
scarter1 | 0:020db18a476d | 59 | typedef int32_t _ints_type; |
scarter1 | 0:020db18a476d | 60 | _ints_type st_ints; |
scarter1 | 0:020db18a476d | 61 | _ints_type * ints; |
scarter1 | 0:020db18a476d | 62 | uint32_t floats_length; |
scarter1 | 0:020db18a476d | 63 | typedef float _floats_type; |
scarter1 | 0:020db18a476d | 64 | _floats_type st_floats; |
scarter1 | 0:020db18a476d | 65 | _floats_type * floats; |
scarter1 | 0:020db18a476d | 66 | uint32_t strings_length; |
scarter1 | 0:020db18a476d | 67 | typedef char* _strings_type; |
scarter1 | 0:020db18a476d | 68 | _strings_type st_strings; |
scarter1 | 0:020db18a476d | 69 | _strings_type * strings; |
scarter1 | 0:020db18a476d | 70 | |
scarter1 | 0:020db18a476d | 71 | RequestParamResponse(): |
scarter1 | 0:020db18a476d | 72 | ints_length(0), ints(NULL), |
scarter1 | 0:020db18a476d | 73 | floats_length(0), floats(NULL), |
scarter1 | 0:020db18a476d | 74 | strings_length(0), strings(NULL) |
scarter1 | 0:020db18a476d | 75 | { |
scarter1 | 0:020db18a476d | 76 | } |
scarter1 | 0:020db18a476d | 77 | |
scarter1 | 0:020db18a476d | 78 | virtual int serialize(unsigned char *outbuffer) const |
scarter1 | 0:020db18a476d | 79 | { |
scarter1 | 0:020db18a476d | 80 | int offset = 0; |
scarter1 | 0:020db18a476d | 81 | *(outbuffer + offset + 0) = (this->ints_length >> (8 * 0)) & 0xFF; |
scarter1 | 0:020db18a476d | 82 | *(outbuffer + offset + 1) = (this->ints_length >> (8 * 1)) & 0xFF; |
scarter1 | 0:020db18a476d | 83 | *(outbuffer + offset + 2) = (this->ints_length >> (8 * 2)) & 0xFF; |
scarter1 | 0:020db18a476d | 84 | *(outbuffer + offset + 3) = (this->ints_length >> (8 * 3)) & 0xFF; |
scarter1 | 0:020db18a476d | 85 | offset += sizeof(this->ints_length); |
scarter1 | 0:020db18a476d | 86 | for( uint32_t i = 0; i < ints_length; i++){ |
scarter1 | 0:020db18a476d | 87 | union { |
scarter1 | 0:020db18a476d | 88 | int32_t real; |
scarter1 | 0:020db18a476d | 89 | uint32_t base; |
scarter1 | 0:020db18a476d | 90 | } u_intsi; |
scarter1 | 0:020db18a476d | 91 | u_intsi.real = this->ints[i]; |
scarter1 | 0:020db18a476d | 92 | *(outbuffer + offset + 0) = (u_intsi.base >> (8 * 0)) & 0xFF; |
scarter1 | 0:020db18a476d | 93 | *(outbuffer + offset + 1) = (u_intsi.base >> (8 * 1)) & 0xFF; |
scarter1 | 0:020db18a476d | 94 | *(outbuffer + offset + 2) = (u_intsi.base >> (8 * 2)) & 0xFF; |
scarter1 | 0:020db18a476d | 95 | *(outbuffer + offset + 3) = (u_intsi.base >> (8 * 3)) & 0xFF; |
scarter1 | 0:020db18a476d | 96 | offset += sizeof(this->ints[i]); |
scarter1 | 0:020db18a476d | 97 | } |
scarter1 | 0:020db18a476d | 98 | *(outbuffer + offset + 0) = (this->floats_length >> (8 * 0)) & 0xFF; |
scarter1 | 0:020db18a476d | 99 | *(outbuffer + offset + 1) = (this->floats_length >> (8 * 1)) & 0xFF; |
scarter1 | 0:020db18a476d | 100 | *(outbuffer + offset + 2) = (this->floats_length >> (8 * 2)) & 0xFF; |
scarter1 | 0:020db18a476d | 101 | *(outbuffer + offset + 3) = (this->floats_length >> (8 * 3)) & 0xFF; |
scarter1 | 0:020db18a476d | 102 | offset += sizeof(this->floats_length); |
scarter1 | 0:020db18a476d | 103 | for( uint32_t i = 0; i < floats_length; i++){ |
scarter1 | 0:020db18a476d | 104 | union { |
scarter1 | 0:020db18a476d | 105 | float real; |
scarter1 | 0:020db18a476d | 106 | uint32_t base; |
scarter1 | 0:020db18a476d | 107 | } u_floatsi; |
scarter1 | 0:020db18a476d | 108 | u_floatsi.real = this->floats[i]; |
scarter1 | 0:020db18a476d | 109 | *(outbuffer + offset + 0) = (u_floatsi.base >> (8 * 0)) & 0xFF; |
scarter1 | 0:020db18a476d | 110 | *(outbuffer + offset + 1) = (u_floatsi.base >> (8 * 1)) & 0xFF; |
scarter1 | 0:020db18a476d | 111 | *(outbuffer + offset + 2) = (u_floatsi.base >> (8 * 2)) & 0xFF; |
scarter1 | 0:020db18a476d | 112 | *(outbuffer + offset + 3) = (u_floatsi.base >> (8 * 3)) & 0xFF; |
scarter1 | 0:020db18a476d | 113 | offset += sizeof(this->floats[i]); |
scarter1 | 0:020db18a476d | 114 | } |
scarter1 | 0:020db18a476d | 115 | *(outbuffer + offset + 0) = (this->strings_length >> (8 * 0)) & 0xFF; |
scarter1 | 0:020db18a476d | 116 | *(outbuffer + offset + 1) = (this->strings_length >> (8 * 1)) & 0xFF; |
scarter1 | 0:020db18a476d | 117 | *(outbuffer + offset + 2) = (this->strings_length >> (8 * 2)) & 0xFF; |
scarter1 | 0:020db18a476d | 118 | *(outbuffer + offset + 3) = (this->strings_length >> (8 * 3)) & 0xFF; |
scarter1 | 0:020db18a476d | 119 | offset += sizeof(this->strings_length); |
scarter1 | 0:020db18a476d | 120 | for( uint32_t i = 0; i < strings_length; i++){ |
scarter1 | 0:020db18a476d | 121 | uint32_t length_stringsi = strlen(this->strings[i]); |
scarter1 | 0:020db18a476d | 122 | varToArr(outbuffer + offset, length_stringsi); |
scarter1 | 0:020db18a476d | 123 | offset += 4; |
scarter1 | 0:020db18a476d | 124 | memcpy(outbuffer + offset, this->strings[i], length_stringsi); |
scarter1 | 0:020db18a476d | 125 | offset += length_stringsi; |
scarter1 | 0:020db18a476d | 126 | } |
scarter1 | 0:020db18a476d | 127 | return offset; |
scarter1 | 0:020db18a476d | 128 | } |
scarter1 | 0:020db18a476d | 129 | |
scarter1 | 0:020db18a476d | 130 | virtual int deserialize(unsigned char *inbuffer) |
scarter1 | 0:020db18a476d | 131 | { |
scarter1 | 0:020db18a476d | 132 | int offset = 0; |
scarter1 | 0:020db18a476d | 133 | uint32_t ints_lengthT = ((uint32_t) (*(inbuffer + offset))); |
scarter1 | 0:020db18a476d | 134 | ints_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); |
scarter1 | 0:020db18a476d | 135 | ints_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); |
scarter1 | 0:020db18a476d | 136 | ints_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); |
scarter1 | 0:020db18a476d | 137 | offset += sizeof(this->ints_length); |
scarter1 | 0:020db18a476d | 138 | if(ints_lengthT > ints_length) |
scarter1 | 0:020db18a476d | 139 | this->ints = (int32_t*)realloc(this->ints, ints_lengthT * sizeof(int32_t)); |
scarter1 | 0:020db18a476d | 140 | ints_length = ints_lengthT; |
scarter1 | 0:020db18a476d | 141 | for( uint32_t i = 0; i < ints_length; i++){ |
scarter1 | 0:020db18a476d | 142 | union { |
scarter1 | 0:020db18a476d | 143 | int32_t real; |
scarter1 | 0:020db18a476d | 144 | uint32_t base; |
scarter1 | 0:020db18a476d | 145 | } u_st_ints; |
scarter1 | 0:020db18a476d | 146 | u_st_ints.base = 0; |
scarter1 | 0:020db18a476d | 147 | u_st_ints.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); |
scarter1 | 0:020db18a476d | 148 | u_st_ints.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); |
scarter1 | 0:020db18a476d | 149 | u_st_ints.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); |
scarter1 | 0:020db18a476d | 150 | u_st_ints.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); |
scarter1 | 0:020db18a476d | 151 | this->st_ints = u_st_ints.real; |
scarter1 | 0:020db18a476d | 152 | offset += sizeof(this->st_ints); |
scarter1 | 0:020db18a476d | 153 | memcpy( &(this->ints[i]), &(this->st_ints), sizeof(int32_t)); |
scarter1 | 0:020db18a476d | 154 | } |
scarter1 | 0:020db18a476d | 155 | uint32_t floats_lengthT = ((uint32_t) (*(inbuffer + offset))); |
scarter1 | 0:020db18a476d | 156 | floats_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); |
scarter1 | 0:020db18a476d | 157 | floats_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); |
scarter1 | 0:020db18a476d | 158 | floats_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); |
scarter1 | 0:020db18a476d | 159 | offset += sizeof(this->floats_length); |
scarter1 | 0:020db18a476d | 160 | if(floats_lengthT > floats_length) |
scarter1 | 0:020db18a476d | 161 | this->floats = (float*)realloc(this->floats, floats_lengthT * sizeof(float)); |
scarter1 | 0:020db18a476d | 162 | floats_length = floats_lengthT; |
scarter1 | 0:020db18a476d | 163 | for( uint32_t i = 0; i < floats_length; i++){ |
scarter1 | 0:020db18a476d | 164 | union { |
scarter1 | 0:020db18a476d | 165 | float real; |
scarter1 | 0:020db18a476d | 166 | uint32_t base; |
scarter1 | 0:020db18a476d | 167 | } u_st_floats; |
scarter1 | 0:020db18a476d | 168 | u_st_floats.base = 0; |
scarter1 | 0:020db18a476d | 169 | u_st_floats.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); |
scarter1 | 0:020db18a476d | 170 | u_st_floats.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); |
scarter1 | 0:020db18a476d | 171 | u_st_floats.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); |
scarter1 | 0:020db18a476d | 172 | u_st_floats.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); |
scarter1 | 0:020db18a476d | 173 | this->st_floats = u_st_floats.real; |
scarter1 | 0:020db18a476d | 174 | offset += sizeof(this->st_floats); |
scarter1 | 0:020db18a476d | 175 | memcpy( &(this->floats[i]), &(this->st_floats), sizeof(float)); |
scarter1 | 0:020db18a476d | 176 | } |
scarter1 | 0:020db18a476d | 177 | uint32_t strings_lengthT = ((uint32_t) (*(inbuffer + offset))); |
scarter1 | 0:020db18a476d | 178 | strings_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); |
scarter1 | 0:020db18a476d | 179 | strings_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); |
scarter1 | 0:020db18a476d | 180 | strings_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); |
scarter1 | 0:020db18a476d | 181 | offset += sizeof(this->strings_length); |
scarter1 | 0:020db18a476d | 182 | if(strings_lengthT > strings_length) |
scarter1 | 0:020db18a476d | 183 | this->strings = (char**)realloc(this->strings, strings_lengthT * sizeof(char*)); |
scarter1 | 0:020db18a476d | 184 | strings_length = strings_lengthT; |
scarter1 | 0:020db18a476d | 185 | for( uint32_t i = 0; i < strings_length; i++){ |
scarter1 | 0:020db18a476d | 186 | uint32_t length_st_strings; |
scarter1 | 0:020db18a476d | 187 | arrToVar(length_st_strings, (inbuffer + offset)); |
scarter1 | 0:020db18a476d | 188 | offset += 4; |
scarter1 | 0:020db18a476d | 189 | for(unsigned int k= offset; k< offset+length_st_strings; ++k){ |
scarter1 | 0:020db18a476d | 190 | inbuffer[k-1]=inbuffer[k]; |
scarter1 | 0:020db18a476d | 191 | } |
scarter1 | 0:020db18a476d | 192 | inbuffer[offset+length_st_strings-1]=0; |
scarter1 | 0:020db18a476d | 193 | this->st_strings = (char *)(inbuffer + offset-1); |
scarter1 | 0:020db18a476d | 194 | offset += length_st_strings; |
scarter1 | 0:020db18a476d | 195 | memcpy( &(this->strings[i]), &(this->st_strings), sizeof(char*)); |
scarter1 | 0:020db18a476d | 196 | } |
scarter1 | 0:020db18a476d | 197 | return offset; |
scarter1 | 0:020db18a476d | 198 | } |
scarter1 | 0:020db18a476d | 199 | |
scarter1 | 0:020db18a476d | 200 | const char * getType(){ return REQUESTPARAM; }; |
scarter1 | 0:020db18a476d | 201 | const char * getMD5(){ return "9f0e98bda65981986ddf53afa7a40e49"; }; |
scarter1 | 0:020db18a476d | 202 | |
scarter1 | 0:020db18a476d | 203 | }; |
scarter1 | 0:020db18a476d | 204 | |
scarter1 | 0:020db18a476d | 205 | class RequestParam { |
scarter1 | 0:020db18a476d | 206 | public: |
scarter1 | 0:020db18a476d | 207 | typedef RequestParamRequest Request; |
scarter1 | 0:020db18a476d | 208 | typedef RequestParamResponse Response; |
scarter1 | 0:020db18a476d | 209 | }; |
scarter1 | 0:020db18a476d | 210 | |
scarter1 | 0:020db18a476d | 211 | } |
scarter1 | 0:020db18a476d | 212 | #endif |