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 #include <stddef.h>
00040
00041 namespace ros {
00042
00043
00044 class Msg
00045 {
00046 public:
00047 virtual int serialize(unsigned char *outbuffer) const = 0;
00048 virtual int deserialize(unsigned char *data) = 0;
00049 virtual const char * getType() = 0;
00050 virtual const char * getMD5() = 0;
00051
00063 static int serializeAvrFloat64(unsigned char* outbuffer, const float f)
00064 {
00065 const int32_t* val = (int32_t*) &f;
00066 int32_t exp = ((*val >> 23) & 255);
00067 if (exp != 0)
00068 {
00069 exp += 1023 - 127;
00070 }
00071
00072 int32_t sig = *val;
00073 *(outbuffer++) = 0;
00074 *(outbuffer++) = 0;
00075 *(outbuffer++) = 0;
00076 *(outbuffer++) = (sig << 5) & 0xff;
00077 *(outbuffer++) = (sig >> 3) & 0xff;
00078 *(outbuffer++) = (sig >> 11) & 0xff;
00079 *(outbuffer++) = ((exp << 4) & 0xF0) | ((sig >> 19) & 0x0F);
00080 *(outbuffer++) = (exp >> 4) & 0x7F;
00081
00082
00083 if (f < 0)
00084 {
00085 *(outbuffer - 1) |= 0x80;
00086 }
00087
00088 return 8;
00089 }
00090
00101 static int deserializeAvrFloat64(const unsigned char* inbuffer, float* f)
00102 {
00103 uint32_t* val = (uint32_t*)f;
00104 inbuffer += 3;
00105
00106
00107 *val = ((uint32_t)(*(inbuffer++)) >> 5 & 0x07);
00108 *val |= ((uint32_t)(*(inbuffer++)) & 0xff) << 3;
00109 *val |= ((uint32_t)(*(inbuffer++)) & 0xff) << 11;
00110 *val |= ((uint32_t)(*inbuffer) & 0x0f) << 19;
00111
00112
00113 uint32_t exp = ((uint32_t)(*(inbuffer++)) & 0xf0)>>4;
00114 exp |= ((uint32_t)(*inbuffer) & 0x7f) << 4;
00115 if (exp != 0)
00116 {
00117 *val |= ((exp) - 1023 + 127) << 23;
00118 }
00119
00120
00121 *val |= ((uint32_t)(*(inbuffer++)) & 0x80) << 24;
00122
00123 return 8;
00124 }
00125
00126
00127 template<typename A, typename V>
00128 static void varToArr(A arr, const V var)
00129 {
00130 for(size_t i = 0; i < sizeof(V); i++)
00131 arr[i] = (var >> (8 * i));
00132 }
00133
00134
00135 template<typename V, typename A>
00136 static void arrToVar(V& var, const A arr)
00137 {
00138 var = 0;
00139 for(size_t i = 0; i < sizeof(V); i++)
00140 var |= (arr[i] << (8 * i));
00141 }
00142
00143 };
00144
00145 }
00146
00147 #endif