Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _ROS_MSG_H_
00036 #define _ROS_MSG_H_
00037
00038 #include <stdint.h>
00039
00040 namespace ros {
00041
00042
00043 class Msg
00044 {
00045 public:
00046 virtual int serialize(unsigned char *outbuffer) const = 0;
00047 virtual int deserialize(unsigned char *data) = 0;
00048 virtual const char * getType() = 0;
00049 virtual const char * getMD5() = 0;
00050
00062 static int serializeAvrFloat64(unsigned char* outbuffer, const float f)
00063 {
00064 const int32_t* val = (int32_t*) &f;
00065 int32_t exp = ((*val >> 23) & 255);
00066 if (exp != 0)
00067 {
00068 exp += 1023 - 127;
00069 }
00070
00071 int32_t sig = *val;
00072 *(outbuffer++) = 0;
00073 *(outbuffer++) = 0;
00074 *(outbuffer++) = 0;
00075 *(outbuffer++) = (sig << 5) & 0xff;
00076 *(outbuffer++) = (sig >> 3) & 0xff;
00077 *(outbuffer++) = (sig >> 11) & 0xff;
00078 *(outbuffer++) = ((exp << 4) & 0xF0) | ((sig >> 19) & 0x0F);
00079 *(outbuffer++) = (exp >> 4) & 0x7F;
00080
00081
00082 if (f < 0)
00083 {
00084 *(outbuffer - 1) |= 0x80;
00085 }
00086
00087 return 8;
00088 }
00089
00100 static int deserializeAvrFloat64(const unsigned char* inbuffer, float* f)
00101 {
00102 uint32_t* val = (uint32_t*)f;
00103 inbuffer += 3;
00104
00105
00106 *val = ((uint32_t)(*(inbuffer++)) >> 5 & 0x07);
00107 *val |= ((uint32_t)(*(inbuffer++)) & 0xff) << 3;
00108 *val |= ((uint32_t)(*(inbuffer++)) & 0xff) << 11;
00109 *val |= ((uint32_t)(*inbuffer) & 0x0f) << 19;
00110
00111
00112 uint32_t exp = ((uint32_t)(*(inbuffer++)) & 0xf0)>>4;
00113 exp |= ((uint32_t)(*inbuffer) & 0x7f) << 4;
00114 if (exp != 0)
00115 {
00116 *val |= ((exp) - 1023 + 127) << 23;
00117 }
00118
00119
00120 *val |= ((uint32_t)(*(inbuffer++)) & 0x80) << 24;
00121
00122 return 8;
00123 }
00124
00125 };
00126
00127 }
00128
00129 #endif