complete motor

Dependencies:   BufferedSerial motor_sn7544

Committer:
Jeonghoon
Date:
Thu Jun 27 04:58:29 2019 +0000
Revision:
7:13dd93a0efe8
combine motor with ROS

Who changed what in which revision?

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