Statistics
| Branch: | Revision:

root / quad2 / arduino / src / ros_lib / rosserial_arduino / Test.h @ c1426757

History | View | Annotate | Download (2.23 KB)

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

    
8
namespace rosserial_arduino
9
{
10

    
11
static const char TEST[] = "rosserial_arduino/Test";
12

    
13
  class TestRequest : public ros::Msg
14
  {
15
    public:
16
      char * input;
17

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

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

    
43
    const char * getType(){ return TEST; };
44
    const char * getMD5(){ return "39e92f1778057359c64c7b8a7d7b19de"; };
45

    
46
  };
47

    
48
  class TestResponse : public ros::Msg
49
  {
50
    public:
51
      char * output;
52

    
53
    virtual int serialize(unsigned char *outbuffer) const
54
    {
55
      int offset = 0;
56
      uint32_t * length_output = (uint32_t *)(outbuffer + offset);
57
      *length_output = strlen( (const char*) this->output);
58
      offset += 4;
59
      memcpy(outbuffer + offset, this->output, *length_output);
60
      offset += *length_output;
61
      return offset;
62
    }
63

    
64
    virtual int deserialize(unsigned char *inbuffer)
65
    {
66
      int offset = 0;
67
      uint32_t length_output = *(uint32_t *)(inbuffer + offset);
68
      offset += 4;
69
      for(unsigned int k= offset; k< offset+length_output; ++k){
70
          inbuffer[k-1]=inbuffer[k];
71
      }
72
      inbuffer[offset+length_output-1]=0;
73
      this->output = (char *)(inbuffer + offset-1);
74
      offset += length_output;
75
     return offset;
76
    }
77

    
78
    const char * getType(){ return TEST; };
79
    const char * getMD5(){ return "0825d95fdfa2c8f4bbb4e9c74bccd3fd"; };
80

    
81
  };
82

    
83
  class Test {
84
    public:
85
    typedef TestRequest Request;
86
    typedef TestResponse Response;
87
  };
88

    
89
}
90
#endif