rosserial for Hydro

Dependencies:   MODSERIAL

Fork of rosserial_mbed_lib by nucho

Committer:
nucho
Date:
Fri Aug 19 09:06:30 2011 +0000
Revision:
0:77afd7560544
Child:
1:ff0ec969dad1

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nucho 0:77afd7560544 1 #ifndef ros_Float64MultiArray_h
nucho 0:77afd7560544 2 #define ros_Float64MultiArray_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/MultiArrayLayout.h"
nucho 0:77afd7560544 9
nucho 0:77afd7560544 10 namespace std_msgs
nucho 0:77afd7560544 11 {
nucho 0:77afd7560544 12
nucho 0:77afd7560544 13 class Float64MultiArray : public ros::Msg
nucho 0:77afd7560544 14 {
nucho 0:77afd7560544 15 public:
nucho 0:77afd7560544 16 std_msgs::MultiArrayLayout layout;
nucho 0:77afd7560544 17 unsigned char data_length;
nucho 0:77afd7560544 18 float st_data;
nucho 0:77afd7560544 19 float * data;
nucho 0:77afd7560544 20
nucho 0:77afd7560544 21 virtual int serialize(unsigned char *outbuffer)
nucho 0:77afd7560544 22 {
nucho 0:77afd7560544 23 int offset = 0;
nucho 0:77afd7560544 24 offset += this->layout.serialize(outbuffer + offset);
nucho 0:77afd7560544 25 *(outbuffer + offset++) = data_length;
nucho 0:77afd7560544 26 *(outbuffer + offset++) = 0;
nucho 0:77afd7560544 27 *(outbuffer + offset++) = 0;
nucho 0:77afd7560544 28 *(outbuffer + offset++) = 0;
nucho 0:77afd7560544 29 for( unsigned char i = 0; i < data_length; i++){
nucho 0:77afd7560544 30 long * val_datai = (long *) &(this->data[i]);
nucho 0:77afd7560544 31 long exp_datai = (((*val_datai)>>23)&255);
nucho 0:77afd7560544 32 if(exp_datai != 0)
nucho 0:77afd7560544 33 exp_datai += 1023-127;
nucho 0:77afd7560544 34 long sig_datai = *val_datai;
nucho 0:77afd7560544 35 *(outbuffer + offset++) = 0;
nucho 0:77afd7560544 36 *(outbuffer + offset++) = 0;
nucho 0:77afd7560544 37 *(outbuffer + offset++) = 0;
nucho 0:77afd7560544 38 *(outbuffer + offset++) = (sig_datai<<5) & 0xff;
nucho 0:77afd7560544 39 *(outbuffer + offset++) = (sig_datai>>3) & 0xff;
nucho 0:77afd7560544 40 *(outbuffer + offset++) = (sig_datai>>11) & 0xff;
nucho 0:77afd7560544 41 *(outbuffer + offset++) = ((exp_datai<<4) & 0xF0) | ((sig_datai>>19)&0x0F);
nucho 0:77afd7560544 42 *(outbuffer + offset++) = (exp_datai>>4) & 0x7F;
nucho 0:77afd7560544 43 if(this->data[i] < 0) *(outbuffer + offset -1) |= 0x80;
nucho 0:77afd7560544 44 }
nucho 0:77afd7560544 45 return offset;
nucho 0:77afd7560544 46 }
nucho 0:77afd7560544 47
nucho 0:77afd7560544 48 virtual int deserialize(unsigned char *inbuffer)
nucho 0:77afd7560544 49 {
nucho 0:77afd7560544 50 int offset = 0;
nucho 0:77afd7560544 51 offset += this->layout.deserialize(inbuffer + offset);
nucho 0:77afd7560544 52 unsigned char data_lengthT = *(inbuffer + offset++);
nucho 0:77afd7560544 53 if(data_lengthT > data_length)
nucho 0:77afd7560544 54 this->data = (float*)realloc(this->data, data_lengthT * sizeof(float));
nucho 0:77afd7560544 55 offset += 3;
nucho 0:77afd7560544 56 data_length = data_lengthT;
nucho 0:77afd7560544 57 for( unsigned char i = 0; i < data_length; i++){
nucho 0:77afd7560544 58 unsigned long * val_st_data = (unsigned long*) &(this->st_data);
nucho 0:77afd7560544 59 offset += 3;
nucho 0:77afd7560544 60 *val_st_data = ((unsigned long)(*(inbuffer + offset++))>>5 & 0x07);
nucho 0:77afd7560544 61 *val_st_data |= ((unsigned long)(*(inbuffer + offset++)) & 0xff)<<3;
nucho 0:77afd7560544 62 *val_st_data |= ((unsigned long)(*(inbuffer + offset++)) & 0xff)<<11;
nucho 0:77afd7560544 63 *val_st_data |= ((unsigned long)(*(inbuffer + offset)) & 0x0f)<<19;
nucho 0:77afd7560544 64 unsigned long exp_st_data = ((unsigned long)(*(inbuffer + offset++))&0xf0)>>4;
nucho 0:77afd7560544 65 exp_st_data |= ((unsigned long)(*(inbuffer + offset)) & 0x7f)<<4;
nucho 0:77afd7560544 66 if(exp_st_data !=0)
nucho 0:77afd7560544 67 *val_st_data |= ((exp_st_data)-1023+127)<<23;
nucho 0:77afd7560544 68 if( ((*(inbuffer+offset++)) & 0x80) > 0) this->st_data = -this->st_data;
nucho 0:77afd7560544 69 memcpy( &(this->data[i]), &(this->st_data), sizeof(float));
nucho 0:77afd7560544 70 }
nucho 0:77afd7560544 71 return offset;
nucho 0:77afd7560544 72 }
nucho 0:77afd7560544 73
nucho 0:77afd7560544 74 virtual const char * getType(){ return "std_msgs/Float64MultiArray"; };
nucho 0:77afd7560544 75
nucho 0:77afd7560544 76 };
nucho 0:77afd7560544 77
nucho 0:77afd7560544 78 }
nucho 0:77afd7560544 79 #endif