Statistics
| Branch: | Revision:

root / quad2 / arduino / src / ros_lib / std_msgs / Float32MultiArray.h @ c1426757

History | View | Annotate | Download (2.3 KB)

1
#ifndef _ROS_std_msgs_Float32MultiArray_h
2
#define _ROS_std_msgs_Float32MultiArray_h
3

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

    
10
namespace std_msgs
11
{
12

    
13
  class Float32MultiArray : public ros::Msg
14
  {
15
    public:
16
      std_msgs::MultiArrayLayout layout;
17
      uint8_t data_length;
18
      float st_data;
19
      float * data;
20

    
21
    virtual int serialize(unsigned char *outbuffer) const
22
    {
23
      int offset = 0;
24
      offset += this->layout.serialize(outbuffer + offset);
25
      *(outbuffer + offset++) = data_length;
26
      *(outbuffer + offset++) = 0;
27
      *(outbuffer + offset++) = 0;
28
      *(outbuffer + offset++) = 0;
29
      for( uint8_t i = 0; i < data_length; i++){
30
      union {
31
        float real;
32
        uint32_t base;
33
      } u_datai;
34
      u_datai.real = this->data[i];
35
      *(outbuffer + offset + 0) = (u_datai.base >> (8 * 0)) & 0xFF;
36
      *(outbuffer + offset + 1) = (u_datai.base >> (8 * 1)) & 0xFF;
37
      *(outbuffer + offset + 2) = (u_datai.base >> (8 * 2)) & 0xFF;
38
      *(outbuffer + offset + 3) = (u_datai.base >> (8 * 3)) & 0xFF;
39
      offset += sizeof(this->data[i]);
40
      }
41
      return offset;
42
    }
43

    
44
    virtual int deserialize(unsigned char *inbuffer)
45
    {
46
      int offset = 0;
47
      offset += this->layout.deserialize(inbuffer + offset);
48
      uint8_t data_lengthT = *(inbuffer + offset++);
49
      if(data_lengthT > data_length)
50
        this->data = (float*)realloc(this->data, data_lengthT * sizeof(float));
51
      offset += 3;
52
      data_length = data_lengthT;
53
      for( uint8_t i = 0; i < data_length; i++){
54
      union {
55
        float real;
56
        uint32_t base;
57
      } u_st_data;
58
      u_st_data.base = 0;
59
      u_st_data.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
60
      u_st_data.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
61
      u_st_data.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
62
      u_st_data.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
63
      this->st_data = u_st_data.real;
64
      offset += sizeof(this->st_data);
65
        memcpy( &(this->data[i]), &(this->st_data), sizeof(float));
66
      }
67
     return offset;
68
    }
69

    
70
    const char * getType(){ return "std_msgs/Float32MultiArray"; };
71
    const char * getMD5(){ return "6a40e0ffa6a17a503ac3f8616991b1f6"; };
72

    
73
  };
74

    
75
}
76
#endif