rosserial for Hydro
Fork of rosserial_mbed_lib by
sensor_msgs/PointCloud2.h@0:77afd7560544, 2011-08-19 (annotated)
- Committer:
- nucho
- Date:
- Fri Aug 19 09:06:30 2011 +0000
- Revision:
- 0:77afd7560544
- Child:
- 3:1cf99502f396
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 0:77afd7560544 | 1 | #ifndef ros_PointCloud2_h |
nucho | 0:77afd7560544 | 2 | #define ros_PointCloud2_h |
nucho | 0:77afd7560544 | 3 | |
nucho | 0:77afd7560544 | 4 | #include <stdint.h> |
nucho | 0:77afd7560544 | 5 | #include <string.h> |
nucho | 0:77afd7560544 | 6 | #include <stdlib.h> |
nucho | 0:77afd7560544 | 7 | #include "../ros/msg.h" |
nucho | 0:77afd7560544 | 8 | #include "std_msgs/Header.h" |
nucho | 0:77afd7560544 | 9 | #include "sensor_msgs/PointField.h" |
nucho | 0:77afd7560544 | 10 | |
nucho | 0:77afd7560544 | 11 | namespace sensor_msgs |
nucho | 0:77afd7560544 | 12 | { |
nucho | 0:77afd7560544 | 13 | |
nucho | 0:77afd7560544 | 14 | class PointCloud2 : public ros::Msg |
nucho | 0:77afd7560544 | 15 | { |
nucho | 0:77afd7560544 | 16 | public: |
nucho | 0:77afd7560544 | 17 | std_msgs::Header header; |
nucho | 0:77afd7560544 | 18 | unsigned long height; |
nucho | 0:77afd7560544 | 19 | unsigned long width; |
nucho | 0:77afd7560544 | 20 | unsigned char fields_length; |
nucho | 0:77afd7560544 | 21 | sensor_msgs::PointField st_fields; |
nucho | 0:77afd7560544 | 22 | sensor_msgs::PointField * fields; |
nucho | 0:77afd7560544 | 23 | bool is_bigendian; |
nucho | 0:77afd7560544 | 24 | unsigned long point_step; |
nucho | 0:77afd7560544 | 25 | unsigned long row_step; |
nucho | 0:77afd7560544 | 26 | unsigned char data_length; |
nucho | 0:77afd7560544 | 27 | unsigned char st_data; |
nucho | 0:77afd7560544 | 28 | unsigned char * data; |
nucho | 0:77afd7560544 | 29 | bool is_dense; |
nucho | 0:77afd7560544 | 30 | |
nucho | 0:77afd7560544 | 31 | virtual int serialize(unsigned char *outbuffer) |
nucho | 0:77afd7560544 | 32 | { |
nucho | 0:77afd7560544 | 33 | int offset = 0; |
nucho | 0:77afd7560544 | 34 | offset += this->header.serialize(outbuffer + offset); |
nucho | 0:77afd7560544 | 35 | union { |
nucho | 0:77afd7560544 | 36 | unsigned long real; |
nucho | 0:77afd7560544 | 37 | unsigned long base; |
nucho | 0:77afd7560544 | 38 | } u_height; |
nucho | 0:77afd7560544 | 39 | u_height.real = this->height; |
nucho | 0:77afd7560544 | 40 | *(outbuffer + offset + 0) = (u_height.base >> (8 * 0)) & 0xFF; |
nucho | 0:77afd7560544 | 41 | *(outbuffer + offset + 1) = (u_height.base >> (8 * 1)) & 0xFF; |
nucho | 0:77afd7560544 | 42 | *(outbuffer + offset + 2) = (u_height.base >> (8 * 2)) & 0xFF; |
nucho | 0:77afd7560544 | 43 | *(outbuffer + offset + 3) = (u_height.base >> (8 * 3)) & 0xFF; |
nucho | 0:77afd7560544 | 44 | offset += sizeof(this->height); |
nucho | 0:77afd7560544 | 45 | union { |
nucho | 0:77afd7560544 | 46 | unsigned long real; |
nucho | 0:77afd7560544 | 47 | unsigned long base; |
nucho | 0:77afd7560544 | 48 | } u_width; |
nucho | 0:77afd7560544 | 49 | u_width.real = this->width; |
nucho | 0:77afd7560544 | 50 | *(outbuffer + offset + 0) = (u_width.base >> (8 * 0)) & 0xFF; |
nucho | 0:77afd7560544 | 51 | *(outbuffer + offset + 1) = (u_width.base >> (8 * 1)) & 0xFF; |
nucho | 0:77afd7560544 | 52 | *(outbuffer + offset + 2) = (u_width.base >> (8 * 2)) & 0xFF; |
nucho | 0:77afd7560544 | 53 | *(outbuffer + offset + 3) = (u_width.base >> (8 * 3)) & 0xFF; |
nucho | 0:77afd7560544 | 54 | offset += sizeof(this->width); |
nucho | 0:77afd7560544 | 55 | *(outbuffer + offset++) = fields_length; |
nucho | 0:77afd7560544 | 56 | *(outbuffer + offset++) = 0; |
nucho | 0:77afd7560544 | 57 | *(outbuffer + offset++) = 0; |
nucho | 0:77afd7560544 | 58 | *(outbuffer + offset++) = 0; |
nucho | 0:77afd7560544 | 59 | for( unsigned char i = 0; i < fields_length; i++){ |
nucho | 0:77afd7560544 | 60 | offset += this->fields[i].serialize(outbuffer + offset); |
nucho | 0:77afd7560544 | 61 | } |
nucho | 0:77afd7560544 | 62 | union { |
nucho | 0:77afd7560544 | 63 | bool real; |
nucho | 0:77afd7560544 | 64 | unsigned char base; |
nucho | 0:77afd7560544 | 65 | } u_is_bigendian; |
nucho | 0:77afd7560544 | 66 | u_is_bigendian.real = this->is_bigendian; |
nucho | 0:77afd7560544 | 67 | *(outbuffer + offset + 0) = (u_is_bigendian.base >> (8 * 0)) & 0xFF; |
nucho | 0:77afd7560544 | 68 | offset += sizeof(this->is_bigendian); |
nucho | 0:77afd7560544 | 69 | union { |
nucho | 0:77afd7560544 | 70 | unsigned long real; |
nucho | 0:77afd7560544 | 71 | unsigned long base; |
nucho | 0:77afd7560544 | 72 | } u_point_step; |
nucho | 0:77afd7560544 | 73 | u_point_step.real = this->point_step; |
nucho | 0:77afd7560544 | 74 | *(outbuffer + offset + 0) = (u_point_step.base >> (8 * 0)) & 0xFF; |
nucho | 0:77afd7560544 | 75 | *(outbuffer + offset + 1) = (u_point_step.base >> (8 * 1)) & 0xFF; |
nucho | 0:77afd7560544 | 76 | *(outbuffer + offset + 2) = (u_point_step.base >> (8 * 2)) & 0xFF; |
nucho | 0:77afd7560544 | 77 | *(outbuffer + offset + 3) = (u_point_step.base >> (8 * 3)) & 0xFF; |
nucho | 0:77afd7560544 | 78 | offset += sizeof(this->point_step); |
nucho | 0:77afd7560544 | 79 | union { |
nucho | 0:77afd7560544 | 80 | unsigned long real; |
nucho | 0:77afd7560544 | 81 | unsigned long base; |
nucho | 0:77afd7560544 | 82 | } u_row_step; |
nucho | 0:77afd7560544 | 83 | u_row_step.real = this->row_step; |
nucho | 0:77afd7560544 | 84 | *(outbuffer + offset + 0) = (u_row_step.base >> (8 * 0)) & 0xFF; |
nucho | 0:77afd7560544 | 85 | *(outbuffer + offset + 1) = (u_row_step.base >> (8 * 1)) & 0xFF; |
nucho | 0:77afd7560544 | 86 | *(outbuffer + offset + 2) = (u_row_step.base >> (8 * 2)) & 0xFF; |
nucho | 0:77afd7560544 | 87 | *(outbuffer + offset + 3) = (u_row_step.base >> (8 * 3)) & 0xFF; |
nucho | 0:77afd7560544 | 88 | offset += sizeof(this->row_step); |
nucho | 0:77afd7560544 | 89 | *(outbuffer + offset++) = data_length; |
nucho | 0:77afd7560544 | 90 | *(outbuffer + offset++) = 0; |
nucho | 0:77afd7560544 | 91 | *(outbuffer + offset++) = 0; |
nucho | 0:77afd7560544 | 92 | *(outbuffer + offset++) = 0; |
nucho | 0:77afd7560544 | 93 | for( unsigned char i = 0; i < data_length; i++){ |
nucho | 0:77afd7560544 | 94 | union { |
nucho | 0:77afd7560544 | 95 | unsigned char real; |
nucho | 0:77afd7560544 | 96 | unsigned char base; |
nucho | 0:77afd7560544 | 97 | } u_datai; |
nucho | 0:77afd7560544 | 98 | u_datai.real = this->data[i]; |
nucho | 0:77afd7560544 | 99 | *(outbuffer + offset + 0) = (u_datai.base >> (8 * 0)) & 0xFF; |
nucho | 0:77afd7560544 | 100 | offset += sizeof(this->data[i]); |
nucho | 0:77afd7560544 | 101 | } |
nucho | 0:77afd7560544 | 102 | union { |
nucho | 0:77afd7560544 | 103 | bool real; |
nucho | 0:77afd7560544 | 104 | unsigned char base; |
nucho | 0:77afd7560544 | 105 | } u_is_dense; |
nucho | 0:77afd7560544 | 106 | u_is_dense.real = this->is_dense; |
nucho | 0:77afd7560544 | 107 | *(outbuffer + offset + 0) = (u_is_dense.base >> (8 * 0)) & 0xFF; |
nucho | 0:77afd7560544 | 108 | offset += sizeof(this->is_dense); |
nucho | 0:77afd7560544 | 109 | return offset; |
nucho | 0:77afd7560544 | 110 | } |
nucho | 0:77afd7560544 | 111 | |
nucho | 0:77afd7560544 | 112 | virtual int deserialize(unsigned char *inbuffer) |
nucho | 0:77afd7560544 | 113 | { |
nucho | 0:77afd7560544 | 114 | int offset = 0; |
nucho | 0:77afd7560544 | 115 | offset += this->header.deserialize(inbuffer + offset); |
nucho | 0:77afd7560544 | 116 | union { |
nucho | 0:77afd7560544 | 117 | unsigned long real; |
nucho | 0:77afd7560544 | 118 | unsigned long base; |
nucho | 0:77afd7560544 | 119 | } u_height; |
nucho | 0:77afd7560544 | 120 | u_height.base = 0; |
nucho | 0:77afd7560544 | 121 | u_height.base |= ((typeof(u_height.base)) (*(inbuffer + offset + 0))) << (8 * 0); |
nucho | 0:77afd7560544 | 122 | u_height.base |= ((typeof(u_height.base)) (*(inbuffer + offset + 1))) << (8 * 1); |
nucho | 0:77afd7560544 | 123 | u_height.base |= ((typeof(u_height.base)) (*(inbuffer + offset + 2))) << (8 * 2); |
nucho | 0:77afd7560544 | 124 | u_height.base |= ((typeof(u_height.base)) (*(inbuffer + offset + 3))) << (8 * 3); |
nucho | 0:77afd7560544 | 125 | this->height = u_height.real; |
nucho | 0:77afd7560544 | 126 | offset += sizeof(this->height); |
nucho | 0:77afd7560544 | 127 | union { |
nucho | 0:77afd7560544 | 128 | unsigned long real; |
nucho | 0:77afd7560544 | 129 | unsigned long base; |
nucho | 0:77afd7560544 | 130 | } u_width; |
nucho | 0:77afd7560544 | 131 | u_width.base = 0; |
nucho | 0:77afd7560544 | 132 | u_width.base |= ((typeof(u_width.base)) (*(inbuffer + offset + 0))) << (8 * 0); |
nucho | 0:77afd7560544 | 133 | u_width.base |= ((typeof(u_width.base)) (*(inbuffer + offset + 1))) << (8 * 1); |
nucho | 0:77afd7560544 | 134 | u_width.base |= ((typeof(u_width.base)) (*(inbuffer + offset + 2))) << (8 * 2); |
nucho | 0:77afd7560544 | 135 | u_width.base |= ((typeof(u_width.base)) (*(inbuffer + offset + 3))) << (8 * 3); |
nucho | 0:77afd7560544 | 136 | this->width = u_width.real; |
nucho | 0:77afd7560544 | 137 | offset += sizeof(this->width); |
nucho | 0:77afd7560544 | 138 | unsigned char fields_lengthT = *(inbuffer + offset++); |
nucho | 0:77afd7560544 | 139 | if(fields_lengthT > fields_length) |
nucho | 0:77afd7560544 | 140 | this->fields = (sensor_msgs::PointField*)realloc(this->fields, fields_lengthT * sizeof(sensor_msgs::PointField)); |
nucho | 0:77afd7560544 | 141 | offset += 3; |
nucho | 0:77afd7560544 | 142 | fields_length = fields_lengthT; |
nucho | 0:77afd7560544 | 143 | for( unsigned char i = 0; i < fields_length; i++){ |
nucho | 0:77afd7560544 | 144 | offset += this->st_fields.deserialize(inbuffer + offset); |
nucho | 0:77afd7560544 | 145 | memcpy( &(this->fields[i]), &(this->st_fields), sizeof(sensor_msgs::PointField)); |
nucho | 0:77afd7560544 | 146 | } |
nucho | 0:77afd7560544 | 147 | union { |
nucho | 0:77afd7560544 | 148 | bool real; |
nucho | 0:77afd7560544 | 149 | unsigned char base; |
nucho | 0:77afd7560544 | 150 | } u_is_bigendian; |
nucho | 0:77afd7560544 | 151 | u_is_bigendian.base = 0; |
nucho | 0:77afd7560544 | 152 | u_is_bigendian.base |= ((typeof(u_is_bigendian.base)) (*(inbuffer + offset + 0))) << (8 * 0); |
nucho | 0:77afd7560544 | 153 | this->is_bigendian = u_is_bigendian.real; |
nucho | 0:77afd7560544 | 154 | offset += sizeof(this->is_bigendian); |
nucho | 0:77afd7560544 | 155 | union { |
nucho | 0:77afd7560544 | 156 | unsigned long real; |
nucho | 0:77afd7560544 | 157 | unsigned long base; |
nucho | 0:77afd7560544 | 158 | } u_point_step; |
nucho | 0:77afd7560544 | 159 | u_point_step.base = 0; |
nucho | 0:77afd7560544 | 160 | u_point_step.base |= ((typeof(u_point_step.base)) (*(inbuffer + offset + 0))) << (8 * 0); |
nucho | 0:77afd7560544 | 161 | u_point_step.base |= ((typeof(u_point_step.base)) (*(inbuffer + offset + 1))) << (8 * 1); |
nucho | 0:77afd7560544 | 162 | u_point_step.base |= ((typeof(u_point_step.base)) (*(inbuffer + offset + 2))) << (8 * 2); |
nucho | 0:77afd7560544 | 163 | u_point_step.base |= ((typeof(u_point_step.base)) (*(inbuffer + offset + 3))) << (8 * 3); |
nucho | 0:77afd7560544 | 164 | this->point_step = u_point_step.real; |
nucho | 0:77afd7560544 | 165 | offset += sizeof(this->point_step); |
nucho | 0:77afd7560544 | 166 | union { |
nucho | 0:77afd7560544 | 167 | unsigned long real; |
nucho | 0:77afd7560544 | 168 | unsigned long base; |
nucho | 0:77afd7560544 | 169 | } u_row_step; |
nucho | 0:77afd7560544 | 170 | u_row_step.base = 0; |
nucho | 0:77afd7560544 | 171 | u_row_step.base |= ((typeof(u_row_step.base)) (*(inbuffer + offset + 0))) << (8 * 0); |
nucho | 0:77afd7560544 | 172 | u_row_step.base |= ((typeof(u_row_step.base)) (*(inbuffer + offset + 1))) << (8 * 1); |
nucho | 0:77afd7560544 | 173 | u_row_step.base |= ((typeof(u_row_step.base)) (*(inbuffer + offset + 2))) << (8 * 2); |
nucho | 0:77afd7560544 | 174 | u_row_step.base |= ((typeof(u_row_step.base)) (*(inbuffer + offset + 3))) << (8 * 3); |
nucho | 0:77afd7560544 | 175 | this->row_step = u_row_step.real; |
nucho | 0:77afd7560544 | 176 | offset += sizeof(this->row_step); |
nucho | 0:77afd7560544 | 177 | unsigned char data_lengthT = *(inbuffer + offset++); |
nucho | 0:77afd7560544 | 178 | if(data_lengthT > data_length) |
nucho | 0:77afd7560544 | 179 | this->data = (unsigned char*)realloc(this->data, data_lengthT * sizeof(unsigned char)); |
nucho | 0:77afd7560544 | 180 | offset += 3; |
nucho | 0:77afd7560544 | 181 | data_length = data_lengthT; |
nucho | 0:77afd7560544 | 182 | for( unsigned char i = 0; i < data_length; i++){ |
nucho | 0:77afd7560544 | 183 | union { |
nucho | 0:77afd7560544 | 184 | unsigned char real; |
nucho | 0:77afd7560544 | 185 | unsigned char base; |
nucho | 0:77afd7560544 | 186 | } u_st_data; |
nucho | 0:77afd7560544 | 187 | u_st_data.base = 0; |
nucho | 0:77afd7560544 | 188 | u_st_data.base |= ((typeof(u_st_data.base)) (*(inbuffer + offset + 0))) << (8 * 0); |
nucho | 0:77afd7560544 | 189 | this->st_data = u_st_data.real; |
nucho | 0:77afd7560544 | 190 | offset += sizeof(this->st_data); |
nucho | 0:77afd7560544 | 191 | memcpy( &(this->data[i]), &(this->st_data), sizeof(unsigned char)); |
nucho | 0:77afd7560544 | 192 | } |
nucho | 0:77afd7560544 | 193 | union { |
nucho | 0:77afd7560544 | 194 | bool real; |
nucho | 0:77afd7560544 | 195 | unsigned char base; |
nucho | 0:77afd7560544 | 196 | } u_is_dense; |
nucho | 0:77afd7560544 | 197 | u_is_dense.base = 0; |
nucho | 0:77afd7560544 | 198 | u_is_dense.base |= ((typeof(u_is_dense.base)) (*(inbuffer + offset + 0))) << (8 * 0); |
nucho | 0:77afd7560544 | 199 | this->is_dense = u_is_dense.real; |
nucho | 0:77afd7560544 | 200 | offset += sizeof(this->is_dense); |
nucho | 0:77afd7560544 | 201 | return offset; |
nucho | 0:77afd7560544 | 202 | } |
nucho | 0:77afd7560544 | 203 | |
nucho | 0:77afd7560544 | 204 | virtual const char * getType(){ return "sensor_msgs/PointCloud2"; }; |
nucho | 0:77afd7560544 | 205 | |
nucho | 0:77afd7560544 | 206 | }; |
nucho | 0:77afd7560544 | 207 | |
nucho | 0:77afd7560544 | 208 | } |
nucho | 0:77afd7560544 | 209 | #endif |