catchrobo2022 / Mbed 2 deprecated catchrobo2022_mbed

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers VoiceMessage.h Source File

VoiceMessage.h

00001 #ifndef _ROS_jsk_gui_msgs_VoiceMessage_h
00002 #define _ROS_jsk_gui_msgs_VoiceMessage_h
00003 
00004 #include <stdint.h>
00005 #include <string.h>
00006 #include <stdlib.h>
00007 #include "ros/msg.h"
00008 
00009 namespace jsk_gui_msgs
00010 {
00011 
00012   class VoiceMessage : public ros::Msg
00013   {
00014     public:
00015       uint32_t texts_length;
00016       typedef char* _texts_type;
00017       _texts_type st_texts;
00018       _texts_type * texts;
00019 
00020     VoiceMessage():
00021       texts_length(0), texts(NULL)
00022     {
00023     }
00024 
00025     virtual int serialize(unsigned char *outbuffer) const
00026     {
00027       int offset = 0;
00028       *(outbuffer + offset + 0) = (this->texts_length >> (8 * 0)) & 0xFF;
00029       *(outbuffer + offset + 1) = (this->texts_length >> (8 * 1)) & 0xFF;
00030       *(outbuffer + offset + 2) = (this->texts_length >> (8 * 2)) & 0xFF;
00031       *(outbuffer + offset + 3) = (this->texts_length >> (8 * 3)) & 0xFF;
00032       offset += sizeof(this->texts_length);
00033       for( uint32_t i = 0; i < texts_length; i++){
00034       uint32_t length_textsi = strlen(this->texts[i]);
00035       varToArr(outbuffer + offset, length_textsi);
00036       offset += 4;
00037       memcpy(outbuffer + offset, this->texts[i], length_textsi);
00038       offset += length_textsi;
00039       }
00040       return offset;
00041     }
00042 
00043     virtual int deserialize(unsigned char *inbuffer)
00044     {
00045       int offset = 0;
00046       uint32_t texts_lengthT = ((uint32_t) (*(inbuffer + offset))); 
00047       texts_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 
00048       texts_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 
00049       texts_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 
00050       offset += sizeof(this->texts_length);
00051       if(texts_lengthT > texts_length)
00052         this->texts = (char**)realloc(this->texts, texts_lengthT * sizeof(char*));
00053       texts_length = texts_lengthT;
00054       for( uint32_t i = 0; i < texts_length; i++){
00055       uint32_t length_st_texts;
00056       arrToVar(length_st_texts, (inbuffer + offset));
00057       offset += 4;
00058       for(unsigned int k= offset; k< offset+length_st_texts; ++k){
00059           inbuffer[k-1]=inbuffer[k];
00060       }
00061       inbuffer[offset+length_st_texts-1]=0;
00062       this->st_texts = (char *)(inbuffer + offset-1);
00063       offset += length_st_texts;
00064         memcpy( &(this->texts[i]), &(this->st_texts), sizeof(char*));
00065       }
00066      return offset;
00067     }
00068 
00069     virtual const char * getType(){ return "jsk_gui_msgs/VoiceMessage"; };
00070     virtual const char * getMD5(){ return "8d7dcfb3b46640ccf02177a3f0cf9530"; };
00071 
00072   };
00073 
00074 }
00075 #endif