rosserial for Hydro
Fork of rosserial_mbed_lib by
sensor_msgs/PointField.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_PointField_h |
nucho | 0:77afd7560544 | 2 | #define ros_PointField_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 | |
nucho | 0:77afd7560544 | 9 | namespace sensor_msgs |
nucho | 0:77afd7560544 | 10 | { |
nucho | 0:77afd7560544 | 11 | |
nucho | 0:77afd7560544 | 12 | class PointField : public ros::Msg |
nucho | 0:77afd7560544 | 13 | { |
nucho | 0:77afd7560544 | 14 | public: |
nucho | 0:77afd7560544 | 15 | char * name; |
nucho | 0:77afd7560544 | 16 | unsigned long offset; |
nucho | 0:77afd7560544 | 17 | unsigned char datatype; |
nucho | 0:77afd7560544 | 18 | unsigned long count; |
nucho | 0:77afd7560544 | 19 | enum { INT8 = 1 }; |
nucho | 0:77afd7560544 | 20 | enum { UINT8 = 2 }; |
nucho | 0:77afd7560544 | 21 | enum { INT16 = 3 }; |
nucho | 0:77afd7560544 | 22 | enum { UINT16 = 4 }; |
nucho | 0:77afd7560544 | 23 | enum { INT32 = 5 }; |
nucho | 0:77afd7560544 | 24 | enum { UINT32 = 6 }; |
nucho | 0:77afd7560544 | 25 | enum { FLOAT32 = 7 }; |
nucho | 0:77afd7560544 | 26 | enum { FLOAT64 = 8 }; |
nucho | 0:77afd7560544 | 27 | |
nucho | 0:77afd7560544 | 28 | virtual int serialize(unsigned char *outbuffer) |
nucho | 0:77afd7560544 | 29 | { |
nucho | 0:77afd7560544 | 30 | int offset = 0; |
nucho | 0:77afd7560544 | 31 | long * length_name = (long *)(outbuffer + offset); |
nucho | 0:77afd7560544 | 32 | *length_name = strlen( (const char*) this->name); |
nucho | 0:77afd7560544 | 33 | offset += 4; |
nucho | 0:77afd7560544 | 34 | memcpy(outbuffer + offset, this->name, *length_name); |
nucho | 0:77afd7560544 | 35 | offset += *length_name; |
nucho | 0:77afd7560544 | 36 | union { |
nucho | 0:77afd7560544 | 37 | unsigned long real; |
nucho | 0:77afd7560544 | 38 | unsigned long base; |
nucho | 0:77afd7560544 | 39 | } u_offset; |
nucho | 0:77afd7560544 | 40 | u_offset.real = this->offset; |
nucho | 0:77afd7560544 | 41 | *(outbuffer + offset + 0) = (u_offset.base >> (8 * 0)) & 0xFF; |
nucho | 0:77afd7560544 | 42 | *(outbuffer + offset + 1) = (u_offset.base >> (8 * 1)) & 0xFF; |
nucho | 0:77afd7560544 | 43 | *(outbuffer + offset + 2) = (u_offset.base >> (8 * 2)) & 0xFF; |
nucho | 0:77afd7560544 | 44 | *(outbuffer + offset + 3) = (u_offset.base >> (8 * 3)) & 0xFF; |
nucho | 0:77afd7560544 | 45 | offset += sizeof(this->offset); |
nucho | 0:77afd7560544 | 46 | union { |
nucho | 0:77afd7560544 | 47 | unsigned char real; |
nucho | 0:77afd7560544 | 48 | unsigned char base; |
nucho | 0:77afd7560544 | 49 | } u_datatype; |
nucho | 0:77afd7560544 | 50 | u_datatype.real = this->datatype; |
nucho | 0:77afd7560544 | 51 | *(outbuffer + offset + 0) = (u_datatype.base >> (8 * 0)) & 0xFF; |
nucho | 0:77afd7560544 | 52 | offset += sizeof(this->datatype); |
nucho | 0:77afd7560544 | 53 | union { |
nucho | 0:77afd7560544 | 54 | unsigned long real; |
nucho | 0:77afd7560544 | 55 | unsigned long base; |
nucho | 0:77afd7560544 | 56 | } u_count; |
nucho | 0:77afd7560544 | 57 | u_count.real = this->count; |
nucho | 0:77afd7560544 | 58 | *(outbuffer + offset + 0) = (u_count.base >> (8 * 0)) & 0xFF; |
nucho | 0:77afd7560544 | 59 | *(outbuffer + offset + 1) = (u_count.base >> (8 * 1)) & 0xFF; |
nucho | 0:77afd7560544 | 60 | *(outbuffer + offset + 2) = (u_count.base >> (8 * 2)) & 0xFF; |
nucho | 0:77afd7560544 | 61 | *(outbuffer + offset + 3) = (u_count.base >> (8 * 3)) & 0xFF; |
nucho | 0:77afd7560544 | 62 | offset += sizeof(this->count); |
nucho | 0:77afd7560544 | 63 | return offset; |
nucho | 0:77afd7560544 | 64 | } |
nucho | 0:77afd7560544 | 65 | |
nucho | 0:77afd7560544 | 66 | virtual int deserialize(unsigned char *inbuffer) |
nucho | 0:77afd7560544 | 67 | { |
nucho | 0:77afd7560544 | 68 | int offset = 0; |
nucho | 0:77afd7560544 | 69 | uint32_t length_name = *(uint32_t *)(inbuffer + offset); |
nucho | 0:77afd7560544 | 70 | offset += 4; |
nucho | 0:77afd7560544 | 71 | for(unsigned int k= offset; k< offset+length_name; ++k){ |
nucho | 0:77afd7560544 | 72 | inbuffer[k-1]=inbuffer[k]; |
nucho | 0:77afd7560544 | 73 | } |
nucho | 0:77afd7560544 | 74 | inbuffer[offset+length_name-1]=0; |
nucho | 0:77afd7560544 | 75 | this->name = (char *)(inbuffer + offset-1); |
nucho | 0:77afd7560544 | 76 | offset += length_name; |
nucho | 0:77afd7560544 | 77 | union { |
nucho | 0:77afd7560544 | 78 | unsigned long real; |
nucho | 0:77afd7560544 | 79 | unsigned long base; |
nucho | 0:77afd7560544 | 80 | } u_offset; |
nucho | 0:77afd7560544 | 81 | u_offset.base = 0; |
nucho | 0:77afd7560544 | 82 | u_offset.base |= ((typeof(u_offset.base)) (*(inbuffer + offset + 0))) << (8 * 0); |
nucho | 0:77afd7560544 | 83 | u_offset.base |= ((typeof(u_offset.base)) (*(inbuffer + offset + 1))) << (8 * 1); |
nucho | 0:77afd7560544 | 84 | u_offset.base |= ((typeof(u_offset.base)) (*(inbuffer + offset + 2))) << (8 * 2); |
nucho | 0:77afd7560544 | 85 | u_offset.base |= ((typeof(u_offset.base)) (*(inbuffer + offset + 3))) << (8 * 3); |
nucho | 0:77afd7560544 | 86 | this->offset = u_offset.real; |
nucho | 0:77afd7560544 | 87 | offset += sizeof(this->offset); |
nucho | 0:77afd7560544 | 88 | union { |
nucho | 0:77afd7560544 | 89 | unsigned char real; |
nucho | 0:77afd7560544 | 90 | unsigned char base; |
nucho | 0:77afd7560544 | 91 | } u_datatype; |
nucho | 0:77afd7560544 | 92 | u_datatype.base = 0; |
nucho | 0:77afd7560544 | 93 | u_datatype.base |= ((typeof(u_datatype.base)) (*(inbuffer + offset + 0))) << (8 * 0); |
nucho | 0:77afd7560544 | 94 | this->datatype = u_datatype.real; |
nucho | 0:77afd7560544 | 95 | offset += sizeof(this->datatype); |
nucho | 0:77afd7560544 | 96 | union { |
nucho | 0:77afd7560544 | 97 | unsigned long real; |
nucho | 0:77afd7560544 | 98 | unsigned long base; |
nucho | 0:77afd7560544 | 99 | } u_count; |
nucho | 0:77afd7560544 | 100 | u_count.base = 0; |
nucho | 0:77afd7560544 | 101 | u_count.base |= ((typeof(u_count.base)) (*(inbuffer + offset + 0))) << (8 * 0); |
nucho | 0:77afd7560544 | 102 | u_count.base |= ((typeof(u_count.base)) (*(inbuffer + offset + 1))) << (8 * 1); |
nucho | 0:77afd7560544 | 103 | u_count.base |= ((typeof(u_count.base)) (*(inbuffer + offset + 2))) << (8 * 2); |
nucho | 0:77afd7560544 | 104 | u_count.base |= ((typeof(u_count.base)) (*(inbuffer + offset + 3))) << (8 * 3); |
nucho | 0:77afd7560544 | 105 | this->count = u_count.real; |
nucho | 0:77afd7560544 | 106 | offset += sizeof(this->count); |
nucho | 0:77afd7560544 | 107 | return offset; |
nucho | 0:77afd7560544 | 108 | } |
nucho | 0:77afd7560544 | 109 | |
nucho | 0:77afd7560544 | 110 | virtual const char * getType(){ return "sensor_msgs/PointField"; }; |
nucho | 0:77afd7560544 | 111 | |
nucho | 0:77afd7560544 | 112 | }; |
nucho | 0:77afd7560544 | 113 | |
nucho | 0:77afd7560544 | 114 | } |
nucho | 0:77afd7560544 | 115 | #endif |