Statistics
| Branch: | Revision:

root / quad2 / arduino / src / ros_lib / rosserial_msgs / RequestParam.h @ c1426757

History | View | Annotate | Download (6.03 KB)

1
#ifndef _ROS_SERVICE_RequestParam_h
2
#define _ROS_SERVICE_RequestParam_h
3
#include <stdint.h>
4
#include <string.h>
5
#include <stdlib.h>
6
#include "ros/msg.h"
7

    
8
namespace rosserial_msgs
9
{
10

    
11
static const char REQUESTPARAM[] = "rosserial_msgs/RequestParam";
12

    
13
  class RequestParamRequest : public ros::Msg
14
  {
15
    public:
16
      char * name;
17

    
18
    virtual int serialize(unsigned char *outbuffer) const
19
    {
20
      int offset = 0;
21
      uint32_t * length_name = (uint32_t *)(outbuffer + offset);
22
      *length_name = strlen( (const char*) this->name);
23
      offset += 4;
24
      memcpy(outbuffer + offset, this->name, *length_name);
25
      offset += *length_name;
26
      return offset;
27
    }
28

    
29
    virtual int deserialize(unsigned char *inbuffer)
30
    {
31
      int offset = 0;
32
      uint32_t length_name = *(uint32_t *)(inbuffer + offset);
33
      offset += 4;
34
      for(unsigned int k= offset; k< offset+length_name; ++k){
35
          inbuffer[k-1]=inbuffer[k];
36
      }
37
      inbuffer[offset+length_name-1]=0;
38
      this->name = (char *)(inbuffer + offset-1);
39
      offset += length_name;
40
     return offset;
41
    }
42

    
43
    const char * getType(){ return REQUESTPARAM; };
44
    const char * getMD5(){ return "c1f3d28f1b044c871e6eff2e9fc3c667"; };
45

    
46
  };
47

    
48
  class RequestParamResponse : public ros::Msg
49
  {
50
    public:
51
      uint8_t ints_length;
52
      int32_t st_ints;
53
      int32_t * ints;
54
      uint8_t floats_length;
55
      float st_floats;
56
      float * floats;
57
      uint8_t strings_length;
58
      char* st_strings;
59
      char* * strings;
60

    
61
    virtual int serialize(unsigned char *outbuffer) const
62
    {
63
      int offset = 0;
64
      *(outbuffer + offset++) = ints_length;
65
      *(outbuffer + offset++) = 0;
66
      *(outbuffer + offset++) = 0;
67
      *(outbuffer + offset++) = 0;
68
      for( uint8_t i = 0; i < ints_length; i++){
69
      union {
70
        int32_t real;
71
        uint32_t base;
72
      } u_intsi;
73
      u_intsi.real = this->ints[i];
74
      *(outbuffer + offset + 0) = (u_intsi.base >> (8 * 0)) & 0xFF;
75
      *(outbuffer + offset + 1) = (u_intsi.base >> (8 * 1)) & 0xFF;
76
      *(outbuffer + offset + 2) = (u_intsi.base >> (8 * 2)) & 0xFF;
77
      *(outbuffer + offset + 3) = (u_intsi.base >> (8 * 3)) & 0xFF;
78
      offset += sizeof(this->ints[i]);
79
      }
80
      *(outbuffer + offset++) = floats_length;
81
      *(outbuffer + offset++) = 0;
82
      *(outbuffer + offset++) = 0;
83
      *(outbuffer + offset++) = 0;
84
      for( uint8_t i = 0; i < floats_length; i++){
85
      union {
86
        float real;
87
        uint32_t base;
88
      } u_floatsi;
89
      u_floatsi.real = this->floats[i];
90
      *(outbuffer + offset + 0) = (u_floatsi.base >> (8 * 0)) & 0xFF;
91
      *(outbuffer + offset + 1) = (u_floatsi.base >> (8 * 1)) & 0xFF;
92
      *(outbuffer + offset + 2) = (u_floatsi.base >> (8 * 2)) & 0xFF;
93
      *(outbuffer + offset + 3) = (u_floatsi.base >> (8 * 3)) & 0xFF;
94
      offset += sizeof(this->floats[i]);
95
      }
96
      *(outbuffer + offset++) = strings_length;
97
      *(outbuffer + offset++) = 0;
98
      *(outbuffer + offset++) = 0;
99
      *(outbuffer + offset++) = 0;
100
      for( uint8_t i = 0; i < strings_length; i++){
101
      uint32_t * length_stringsi = (uint32_t *)(outbuffer + offset);
102
      *length_stringsi = strlen( (const char*) this->strings[i]);
103
      offset += 4;
104
      memcpy(outbuffer + offset, this->strings[i], *length_stringsi);
105
      offset += *length_stringsi;
106
      }
107
      return offset;
108
    }
109

    
110
    virtual int deserialize(unsigned char *inbuffer)
111
    {
112
      int offset = 0;
113
      uint8_t ints_lengthT = *(inbuffer + offset++);
114
      if(ints_lengthT > ints_length)
115
        this->ints = (int32_t*)realloc(this->ints, ints_lengthT * sizeof(int32_t));
116
      offset += 3;
117
      ints_length = ints_lengthT;
118
      for( uint8_t i = 0; i < ints_length; i++){
119
      union {
120
        int32_t real;
121
        uint32_t base;
122
      } u_st_ints;
123
      u_st_ints.base = 0;
124
      u_st_ints.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
125
      u_st_ints.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
126
      u_st_ints.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
127
      u_st_ints.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
128
      this->st_ints = u_st_ints.real;
129
      offset += sizeof(this->st_ints);
130
        memcpy( &(this->ints[i]), &(this->st_ints), sizeof(int32_t));
131
      }
132
      uint8_t floats_lengthT = *(inbuffer + offset++);
133
      if(floats_lengthT > floats_length)
134
        this->floats = (float*)realloc(this->floats, floats_lengthT * sizeof(float));
135
      offset += 3;
136
      floats_length = floats_lengthT;
137
      for( uint8_t i = 0; i < floats_length; i++){
138
      union {
139
        float real;
140
        uint32_t base;
141
      } u_st_floats;
142
      u_st_floats.base = 0;
143
      u_st_floats.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
144
      u_st_floats.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
145
      u_st_floats.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
146
      u_st_floats.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
147
      this->st_floats = u_st_floats.real;
148
      offset += sizeof(this->st_floats);
149
        memcpy( &(this->floats[i]), &(this->st_floats), sizeof(float));
150
      }
151
      uint8_t strings_lengthT = *(inbuffer + offset++);
152
      if(strings_lengthT > strings_length)
153
        this->strings = (char**)realloc(this->strings, strings_lengthT * sizeof(char*));
154
      offset += 3;
155
      strings_length = strings_lengthT;
156
      for( uint8_t i = 0; i < strings_length; i++){
157
      uint32_t length_st_strings = *(uint32_t *)(inbuffer + offset);
158
      offset += 4;
159
      for(unsigned int k= offset; k< offset+length_st_strings; ++k){
160
          inbuffer[k-1]=inbuffer[k];
161
      }
162
      inbuffer[offset+length_st_strings-1]=0;
163
      this->st_strings = (char *)(inbuffer + offset-1);
164
      offset += length_st_strings;
165
        memcpy( &(this->strings[i]), &(this->st_strings), sizeof(char*));
166
      }
167
     return offset;
168
    }
169

    
170
    const char * getType(){ return REQUESTPARAM; };
171
    const char * getMD5(){ return "9f0e98bda65981986ddf53afa7a40e49"; };
172

    
173
  };
174

    
175
  class RequestParam {
176
    public:
177
    typedef RequestParamRequest Request;
178
    typedef RequestParamResponse Response;
179
  };
180

    
181
}
182
#endif