catchrobo2022 / Mbed 2 deprecated catchrobo2022_mbed

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Spectrum.h Source File

Spectrum.h

00001 #ifndef _ROS_jsk_recognition_msgs_Spectrum_h
00002 #define _ROS_jsk_recognition_msgs_Spectrum_h
00003 
00004 #include <stdint.h>
00005 #include <string.h>
00006 #include <stdlib.h>
00007 #include "ros/msg.h"
00008 #include "std_msgs/Header.h"
00009 
00010 namespace jsk_recognition_msgs
00011 {
00012 
00013   class Spectrum : public ros::Msg
00014   {
00015     public:
00016       typedef std_msgs::Header _header_type;
00017       _header_type header;
00018       uint32_t amplitude_length;
00019       typedef float _amplitude_type;
00020       _amplitude_type st_amplitude;
00021       _amplitude_type * amplitude;
00022       uint32_t frequency_length;
00023       typedef float _frequency_type;
00024       _frequency_type st_frequency;
00025       _frequency_type * frequency;
00026 
00027     Spectrum():
00028       header(),
00029       amplitude_length(0), amplitude(NULL),
00030       frequency_length(0), frequency(NULL)
00031     {
00032     }
00033 
00034     virtual int serialize(unsigned char *outbuffer) const
00035     {
00036       int offset = 0;
00037       offset += this->header.serialize(outbuffer + offset);
00038       *(outbuffer + offset + 0) = (this->amplitude_length >> (8 * 0)) & 0xFF;
00039       *(outbuffer + offset + 1) = (this->amplitude_length >> (8 * 1)) & 0xFF;
00040       *(outbuffer + offset + 2) = (this->amplitude_length >> (8 * 2)) & 0xFF;
00041       *(outbuffer + offset + 3) = (this->amplitude_length >> (8 * 3)) & 0xFF;
00042       offset += sizeof(this->amplitude_length);
00043       for( uint32_t i = 0; i < amplitude_length; i++){
00044       union {
00045         float real;
00046         uint32_t base;
00047       } u_amplitudei;
00048       u_amplitudei.real = this->amplitude[i];
00049       *(outbuffer + offset + 0) = (u_amplitudei.base >> (8 * 0)) & 0xFF;
00050       *(outbuffer + offset + 1) = (u_amplitudei.base >> (8 * 1)) & 0xFF;
00051       *(outbuffer + offset + 2) = (u_amplitudei.base >> (8 * 2)) & 0xFF;
00052       *(outbuffer + offset + 3) = (u_amplitudei.base >> (8 * 3)) & 0xFF;
00053       offset += sizeof(this->amplitude[i]);
00054       }
00055       *(outbuffer + offset + 0) = (this->frequency_length >> (8 * 0)) & 0xFF;
00056       *(outbuffer + offset + 1) = (this->frequency_length >> (8 * 1)) & 0xFF;
00057       *(outbuffer + offset + 2) = (this->frequency_length >> (8 * 2)) & 0xFF;
00058       *(outbuffer + offset + 3) = (this->frequency_length >> (8 * 3)) & 0xFF;
00059       offset += sizeof(this->frequency_length);
00060       for( uint32_t i = 0; i < frequency_length; i++){
00061       union {
00062         float real;
00063         uint32_t base;
00064       } u_frequencyi;
00065       u_frequencyi.real = this->frequency[i];
00066       *(outbuffer + offset + 0) = (u_frequencyi.base >> (8 * 0)) & 0xFF;
00067       *(outbuffer + offset + 1) = (u_frequencyi.base >> (8 * 1)) & 0xFF;
00068       *(outbuffer + offset + 2) = (u_frequencyi.base >> (8 * 2)) & 0xFF;
00069       *(outbuffer + offset + 3) = (u_frequencyi.base >> (8 * 3)) & 0xFF;
00070       offset += sizeof(this->frequency[i]);
00071       }
00072       return offset;
00073     }
00074 
00075     virtual int deserialize(unsigned char *inbuffer)
00076     {
00077       int offset = 0;
00078       offset += this->header.deserialize(inbuffer + offset);
00079       uint32_t amplitude_lengthT = ((uint32_t) (*(inbuffer + offset))); 
00080       amplitude_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 
00081       amplitude_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 
00082       amplitude_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 
00083       offset += sizeof(this->amplitude_length);
00084       if(amplitude_lengthT > amplitude_length)
00085         this->amplitude = (float*)realloc(this->amplitude, amplitude_lengthT * sizeof(float));
00086       amplitude_length = amplitude_lengthT;
00087       for( uint32_t i = 0; i < amplitude_length; i++){
00088       union {
00089         float real;
00090         uint32_t base;
00091       } u_st_amplitude;
00092       u_st_amplitude.base = 0;
00093       u_st_amplitude.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
00094       u_st_amplitude.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
00095       u_st_amplitude.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
00096       u_st_amplitude.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
00097       this->st_amplitude = u_st_amplitude.real;
00098       offset += sizeof(this->st_amplitude);
00099         memcpy( &(this->amplitude[i]), &(this->st_amplitude), sizeof(float));
00100       }
00101       uint32_t frequency_lengthT = ((uint32_t) (*(inbuffer + offset))); 
00102       frequency_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 
00103       frequency_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 
00104       frequency_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 
00105       offset += sizeof(this->frequency_length);
00106       if(frequency_lengthT > frequency_length)
00107         this->frequency = (float*)realloc(this->frequency, frequency_lengthT * sizeof(float));
00108       frequency_length = frequency_lengthT;
00109       for( uint32_t i = 0; i < frequency_length; i++){
00110       union {
00111         float real;
00112         uint32_t base;
00113       } u_st_frequency;
00114       u_st_frequency.base = 0;
00115       u_st_frequency.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
00116       u_st_frequency.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
00117       u_st_frequency.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
00118       u_st_frequency.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
00119       this->st_frequency = u_st_frequency.real;
00120       offset += sizeof(this->st_frequency);
00121         memcpy( &(this->frequency[i]), &(this->st_frequency), sizeof(float));
00122       }
00123      return offset;
00124     }
00125 
00126     virtual const char * getType(){ return "jsk_recognition_msgs/Spectrum"; };
00127     virtual const char * getMD5(){ return "df74a130749a91198632eab1192d1cc9"; };
00128 
00129   };
00130 
00131 }
00132 #endif