Statistics
| Branch: | Revision:

root / quad2 / arduino / src / ros_lib / sensor_msgs / ChannelFloat32.h @ c1426757

History | View | Annotate | Download (2.71 KB)

1
#ifndef _ROS_sensor_msgs_ChannelFloat32_h
2
#define _ROS_sensor_msgs_ChannelFloat32_h
3

    
4
#include <stdint.h>
5
#include <string.h>
6
#include <stdlib.h>
7
#include "ros/msg.h"
8

    
9
namespace sensor_msgs
10
{
11

    
12
  class ChannelFloat32 : public ros::Msg
13
  {
14
    public:
15
      char * name;
16
      uint8_t values_length;
17
      float st_values;
18
      float * values;
19

    
20
    virtual int serialize(unsigned char *outbuffer) const
21
    {
22
      int offset = 0;
23
      uint32_t * length_name = (uint32_t *)(outbuffer + offset);
24
      *length_name = strlen( (const char*) this->name);
25
      offset += 4;
26
      memcpy(outbuffer + offset, this->name, *length_name);
27
      offset += *length_name;
28
      *(outbuffer + offset++) = values_length;
29
      *(outbuffer + offset++) = 0;
30
      *(outbuffer + offset++) = 0;
31
      *(outbuffer + offset++) = 0;
32
      for( uint8_t i = 0; i < values_length; i++){
33
      union {
34
        float real;
35
        uint32_t base;
36
      } u_valuesi;
37
      u_valuesi.real = this->values[i];
38
      *(outbuffer + offset + 0) = (u_valuesi.base >> (8 * 0)) & 0xFF;
39
      *(outbuffer + offset + 1) = (u_valuesi.base >> (8 * 1)) & 0xFF;
40
      *(outbuffer + offset + 2) = (u_valuesi.base >> (8 * 2)) & 0xFF;
41
      *(outbuffer + offset + 3) = (u_valuesi.base >> (8 * 3)) & 0xFF;
42
      offset += sizeof(this->values[i]);
43
      }
44
      return offset;
45
    }
46

    
47
    virtual int deserialize(unsigned char *inbuffer)
48
    {
49
      int offset = 0;
50
      uint32_t length_name = *(uint32_t *)(inbuffer + offset);
51
      offset += 4;
52
      for(unsigned int k= offset; k< offset+length_name; ++k){
53
          inbuffer[k-1]=inbuffer[k];
54
      }
55
      inbuffer[offset+length_name-1]=0;
56
      this->name = (char *)(inbuffer + offset-1);
57
      offset += length_name;
58
      uint8_t values_lengthT = *(inbuffer + offset++);
59
      if(values_lengthT > values_length)
60
        this->values = (float*)realloc(this->values, values_lengthT * sizeof(float));
61
      offset += 3;
62
      values_length = values_lengthT;
63
      for( uint8_t i = 0; i < values_length; i++){
64
      union {
65
        float real;
66
        uint32_t base;
67
      } u_st_values;
68
      u_st_values.base = 0;
69
      u_st_values.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
70
      u_st_values.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
71
      u_st_values.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
72
      u_st_values.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
73
      this->st_values = u_st_values.real;
74
      offset += sizeof(this->st_values);
75
        memcpy( &(this->values[i]), &(this->st_values), sizeof(float));
76
      }
77
     return offset;
78
    }
79

    
80
    const char * getType(){ return "sensor_msgs/ChannelFloat32"; };
81
    const char * getMD5(){ return "3d40139cdd33dfedcb71ffeeeb42ae7f"; };
82

    
83
  };
84

    
85
}
86
#endif