capstone_finish

Dependencies:   BufferedSerial motor_sn7544

Committer:
Jeonghoon
Date:
Tue Nov 26 15:30:27 2019 +0000
Revision:
10:ca4e4062701a
Parent:
3:2a3664dc6634
capstone finish

Who changed what in which revision?

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