catchrobo2022 / Mbed 2 deprecated catchrobo2022_mbed

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SoundRequest.h Source File

SoundRequest.h

00001 #ifndef _ROS_sound_play_SoundRequest_h
00002 #define _ROS_sound_play_SoundRequest_h
00003 
00004 #include <stdint.h>
00005 #include <string.h>
00006 #include <stdlib.h>
00007 #include "ros/msg.h"
00008 
00009 namespace sound_play
00010 {
00011 
00012   class SoundRequest : public ros::Msg
00013   {
00014     public:
00015       typedef int8_t _sound_type;
00016       _sound_type sound;
00017       typedef int8_t _command_type;
00018       _command_type command;
00019       typedef float _volume_type;
00020       _volume_type volume;
00021       typedef const char* _arg_type;
00022       _arg_type arg;
00023       typedef const char* _arg2_type;
00024       _arg2_type arg2;
00025       enum { BACKINGUP =  1 };
00026       enum { NEEDS_UNPLUGGING =  2 };
00027       enum { NEEDS_PLUGGING =  3 };
00028       enum { NEEDS_UNPLUGGING_BADLY =  4 };
00029       enum { NEEDS_PLUGGING_BADLY =  5 };
00030       enum { ALL =  -1  };
00031       enum { PLAY_FILE =  -2 };
00032       enum { SAY =  -3 };
00033       enum { PLAY_STOP =  0  };
00034       enum { PLAY_ONCE =  1  };
00035       enum { PLAY_START =  2  };
00036 
00037     SoundRequest():
00038       sound(0),
00039       command(0),
00040       volume(0),
00041       arg(""),
00042       arg2("")
00043     {
00044     }
00045 
00046     virtual int serialize(unsigned char *outbuffer) const
00047     {
00048       int offset = 0;
00049       union {
00050         int8_t real;
00051         uint8_t base;
00052       } u_sound;
00053       u_sound.real = this->sound;
00054       *(outbuffer + offset + 0) = (u_sound.base >> (8 * 0)) & 0xFF;
00055       offset += sizeof(this->sound);
00056       union {
00057         int8_t real;
00058         uint8_t base;
00059       } u_command;
00060       u_command.real = this->command;
00061       *(outbuffer + offset + 0) = (u_command.base >> (8 * 0)) & 0xFF;
00062       offset += sizeof(this->command);
00063       union {
00064         float real;
00065         uint32_t base;
00066       } u_volume;
00067       u_volume.real = this->volume;
00068       *(outbuffer + offset + 0) = (u_volume.base >> (8 * 0)) & 0xFF;
00069       *(outbuffer + offset + 1) = (u_volume.base >> (8 * 1)) & 0xFF;
00070       *(outbuffer + offset + 2) = (u_volume.base >> (8 * 2)) & 0xFF;
00071       *(outbuffer + offset + 3) = (u_volume.base >> (8 * 3)) & 0xFF;
00072       offset += sizeof(this->volume);
00073       uint32_t length_arg = strlen(this->arg);
00074       varToArr(outbuffer + offset, length_arg);
00075       offset += 4;
00076       memcpy(outbuffer + offset, this->arg, length_arg);
00077       offset += length_arg;
00078       uint32_t length_arg2 = strlen(this->arg2);
00079       varToArr(outbuffer + offset, length_arg2);
00080       offset += 4;
00081       memcpy(outbuffer + offset, this->arg2, length_arg2);
00082       offset += length_arg2;
00083       return offset;
00084     }
00085 
00086     virtual int deserialize(unsigned char *inbuffer)
00087     {
00088       int offset = 0;
00089       union {
00090         int8_t real;
00091         uint8_t base;
00092       } u_sound;
00093       u_sound.base = 0;
00094       u_sound.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0);
00095       this->sound = u_sound.real;
00096       offset += sizeof(this->sound);
00097       union {
00098         int8_t real;
00099         uint8_t base;
00100       } u_command;
00101       u_command.base = 0;
00102       u_command.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0);
00103       this->command = u_command.real;
00104       offset += sizeof(this->command);
00105       union {
00106         float real;
00107         uint32_t base;
00108       } u_volume;
00109       u_volume.base = 0;
00110       u_volume.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
00111       u_volume.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
00112       u_volume.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
00113       u_volume.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
00114       this->volume = u_volume.real;
00115       offset += sizeof(this->volume);
00116       uint32_t length_arg;
00117       arrToVar(length_arg, (inbuffer + offset));
00118       offset += 4;
00119       for(unsigned int k= offset; k< offset+length_arg; ++k){
00120           inbuffer[k-1]=inbuffer[k];
00121       }
00122       inbuffer[offset+length_arg-1]=0;
00123       this->arg = (char *)(inbuffer + offset-1);
00124       offset += length_arg;
00125       uint32_t length_arg2;
00126       arrToVar(length_arg2, (inbuffer + offset));
00127       offset += 4;
00128       for(unsigned int k= offset; k< offset+length_arg2; ++k){
00129           inbuffer[k-1]=inbuffer[k];
00130       }
00131       inbuffer[offset+length_arg2-1]=0;
00132       this->arg2 = (char *)(inbuffer + offset-1);
00133       offset += length_arg2;
00134      return offset;
00135     }
00136 
00137     virtual const char * getType(){ return "sound_play/SoundRequest"; };
00138     virtual const char * getMD5(){ return "d098ce4a040686259137ece23a625167"; };
00139 
00140   };
00141 
00142 }
00143 #endif