modify for Hydro version
Fork of rosserial_mbed_lib by
std_msgs/Float64.h@0:77afd7560544, 2011-08-19 (annotated)
- Committer:
- nucho
- Date:
- Fri Aug 19 09:06:30 2011 +0000
- Revision:
- 0:77afd7560544
- Child:
- 1:ff0ec969dad1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 0:77afd7560544 | 1 | #ifndef ros_Float64_h |
nucho | 0:77afd7560544 | 2 | #define ros_Float64_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 std_msgs |
nucho | 0:77afd7560544 | 10 | { |
nucho | 0:77afd7560544 | 11 | |
nucho | 0:77afd7560544 | 12 | class Float64 : public ros::Msg |
nucho | 0:77afd7560544 | 13 | { |
nucho | 0:77afd7560544 | 14 | public: |
nucho | 0:77afd7560544 | 15 | float data; |
nucho | 0:77afd7560544 | 16 | |
nucho | 0:77afd7560544 | 17 | virtual int serialize(unsigned char *outbuffer) |
nucho | 0:77afd7560544 | 18 | { |
nucho | 0:77afd7560544 | 19 | int offset = 0; |
nucho | 0:77afd7560544 | 20 | long * val_data = (long *) &(this->data); |
nucho | 0:77afd7560544 | 21 | long exp_data = (((*val_data)>>23)&255); |
nucho | 0:77afd7560544 | 22 | if(exp_data != 0) |
nucho | 0:77afd7560544 | 23 | exp_data += 1023-127; |
nucho | 0:77afd7560544 | 24 | long sig_data = *val_data; |
nucho | 0:77afd7560544 | 25 | *(outbuffer + offset++) = 0; |
nucho | 0:77afd7560544 | 26 | *(outbuffer + offset++) = 0; |
nucho | 0:77afd7560544 | 27 | *(outbuffer + offset++) = 0; |
nucho | 0:77afd7560544 | 28 | *(outbuffer + offset++) = (sig_data<<5) & 0xff; |
nucho | 0:77afd7560544 | 29 | *(outbuffer + offset++) = (sig_data>>3) & 0xff; |
nucho | 0:77afd7560544 | 30 | *(outbuffer + offset++) = (sig_data>>11) & 0xff; |
nucho | 0:77afd7560544 | 31 | *(outbuffer + offset++) = ((exp_data<<4) & 0xF0) | ((sig_data>>19)&0x0F); |
nucho | 0:77afd7560544 | 32 | *(outbuffer + offset++) = (exp_data>>4) & 0x7F; |
nucho | 0:77afd7560544 | 33 | if(this->data < 0) *(outbuffer + offset -1) |= 0x80; |
nucho | 0:77afd7560544 | 34 | return offset; |
nucho | 0:77afd7560544 | 35 | } |
nucho | 0:77afd7560544 | 36 | |
nucho | 0:77afd7560544 | 37 | virtual int deserialize(unsigned char *inbuffer) |
nucho | 0:77afd7560544 | 38 | { |
nucho | 0:77afd7560544 | 39 | int offset = 0; |
nucho | 0:77afd7560544 | 40 | unsigned long * val_data = (unsigned long*) &(this->data); |
nucho | 0:77afd7560544 | 41 | offset += 3; |
nucho | 0:77afd7560544 | 42 | *val_data = ((unsigned long)(*(inbuffer + offset++))>>5 & 0x07); |
nucho | 0:77afd7560544 | 43 | *val_data |= ((unsigned long)(*(inbuffer + offset++)) & 0xff)<<3; |
nucho | 0:77afd7560544 | 44 | *val_data |= ((unsigned long)(*(inbuffer + offset++)) & 0xff)<<11; |
nucho | 0:77afd7560544 | 45 | *val_data |= ((unsigned long)(*(inbuffer + offset)) & 0x0f)<<19; |
nucho | 0:77afd7560544 | 46 | unsigned long exp_data = ((unsigned long)(*(inbuffer + offset++))&0xf0)>>4; |
nucho | 0:77afd7560544 | 47 | exp_data |= ((unsigned long)(*(inbuffer + offset)) & 0x7f)<<4; |
nucho | 0:77afd7560544 | 48 | if(exp_data !=0) |
nucho | 0:77afd7560544 | 49 | *val_data |= ((exp_data)-1023+127)<<23; |
nucho | 0:77afd7560544 | 50 | if( ((*(inbuffer+offset++)) & 0x80) > 0) this->data = -this->data; |
nucho | 0:77afd7560544 | 51 | return offset; |
nucho | 0:77afd7560544 | 52 | } |
nucho | 0:77afd7560544 | 53 | |
nucho | 0:77afd7560544 | 54 | virtual const char * getType(){ return "std_msgs/Float64"; }; |
nucho | 0:77afd7560544 | 55 | |
nucho | 0:77afd7560544 | 56 | }; |
nucho | 0:77afd7560544 | 57 | |
nucho | 0:77afd7560544 | 58 | } |
nucho | 0:77afd7560544 | 59 | #endif |