Statistics
| Branch: | Revision:

root / quad2 / arduino / src / ros_lib / topic_tools / MuxList.h @ c1426757

History | View | Annotate | Download (2.34 KB)

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

    
8
namespace topic_tools
9
{
10

    
11
static const char MUXLIST[] = "topic_tools/MuxList";
12

    
13
  class MuxListRequest : public ros::Msg
14
  {
15
    public:
16

    
17
    virtual int serialize(unsigned char *outbuffer) const
18
    {
19
      int offset = 0;
20
      return offset;
21
    }
22

    
23
    virtual int deserialize(unsigned char *inbuffer)
24
    {
25
      int offset = 0;
26
     return offset;
27
    }
28

    
29
    const char * getType(){ return MUXLIST; };
30
    const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; };
31

    
32
  };
33

    
34
  class MuxListResponse : public ros::Msg
35
  {
36
    public:
37
      uint8_t topics_length;
38
      char* st_topics;
39
      char* * topics;
40

    
41
    virtual int serialize(unsigned char *outbuffer) const
42
    {
43
      int offset = 0;
44
      *(outbuffer + offset++) = topics_length;
45
      *(outbuffer + offset++) = 0;
46
      *(outbuffer + offset++) = 0;
47
      *(outbuffer + offset++) = 0;
48
      for( uint8_t i = 0; i < topics_length; i++){
49
      uint32_t * length_topicsi = (uint32_t *)(outbuffer + offset);
50
      *length_topicsi = strlen( (const char*) this->topics[i]);
51
      offset += 4;
52
      memcpy(outbuffer + offset, this->topics[i], *length_topicsi);
53
      offset += *length_topicsi;
54
      }
55
      return offset;
56
    }
57

    
58
    virtual int deserialize(unsigned char *inbuffer)
59
    {
60
      int offset = 0;
61
      uint8_t topics_lengthT = *(inbuffer + offset++);
62
      if(topics_lengthT > topics_length)
63
        this->topics = (char**)realloc(this->topics, topics_lengthT * sizeof(char*));
64
      offset += 3;
65
      topics_length = topics_lengthT;
66
      for( uint8_t i = 0; i < topics_length; i++){
67
      uint32_t length_st_topics = *(uint32_t *)(inbuffer + offset);
68
      offset += 4;
69
      for(unsigned int k= offset; k< offset+length_st_topics; ++k){
70
          inbuffer[k-1]=inbuffer[k];
71
      }
72
      inbuffer[offset+length_st_topics-1]=0;
73
      this->st_topics = (char *)(inbuffer + offset-1);
74
      offset += length_st_topics;
75
        memcpy( &(this->topics[i]), &(this->st_topics), sizeof(char*));
76
      }
77
     return offset;
78
    }
79

    
80
    const char * getType(){ return MUXLIST; };
81
    const char * getMD5(){ return "b0eef9a05d4e829092fc2f2c3c2aad3d"; };
82

    
83
  };
84

    
85
  class MuxList {
86
    public:
87
    typedef MuxListRequest Request;
88
    typedef MuxListResponse Response;
89
  };
90

    
91
}
92
#endif