catchrobo2022 / Mbed 2 deprecated catchrobo2022_mbed

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Person.h Source File

Person.h

00001 #ifndef _ROS_people_msgs_Person_h
00002 #define _ROS_people_msgs_Person_h
00003 
00004 #include <stdint.h>
00005 #include <string.h>
00006 #include <stdlib.h>
00007 #include "ros/msg.h"
00008 #include "geometry_msgs/Point.h"
00009 
00010 namespace people_msgs
00011 {
00012 
00013   class Person : public ros::Msg
00014   {
00015     public:
00016       typedef const char* _name_type;
00017       _name_type name;
00018       typedef geometry_msgs::Point _position_type;
00019       _position_type position;
00020       typedef geometry_msgs::Point _velocity_type;
00021       _velocity_type velocity;
00022       typedef double _reliability_type;
00023       _reliability_type reliability;
00024       uint32_t tagnames_length;
00025       typedef char* _tagnames_type;
00026       _tagnames_type st_tagnames;
00027       _tagnames_type * tagnames;
00028       uint32_t tags_length;
00029       typedef char* _tags_type;
00030       _tags_type st_tags;
00031       _tags_type * tags;
00032 
00033     Person():
00034       name(""),
00035       position(),
00036       velocity(),
00037       reliability(0),
00038       tagnames_length(0), tagnames(NULL),
00039       tags_length(0), tags(NULL)
00040     {
00041     }
00042 
00043     virtual int serialize(unsigned char *outbuffer) const
00044     {
00045       int offset = 0;
00046       uint32_t length_name = strlen(this->name);
00047       varToArr(outbuffer + offset, length_name);
00048       offset += 4;
00049       memcpy(outbuffer + offset, this->name, length_name);
00050       offset += length_name;
00051       offset += this->position.serialize(outbuffer + offset);
00052       offset += this->velocity.serialize(outbuffer + offset);
00053       union {
00054         double real;
00055         uint64_t base;
00056       } u_reliability;
00057       u_reliability.real = this->reliability;
00058       *(outbuffer + offset + 0) = (u_reliability.base >> (8 * 0)) & 0xFF;
00059       *(outbuffer + offset + 1) = (u_reliability.base >> (8 * 1)) & 0xFF;
00060       *(outbuffer + offset + 2) = (u_reliability.base >> (8 * 2)) & 0xFF;
00061       *(outbuffer + offset + 3) = (u_reliability.base >> (8 * 3)) & 0xFF;
00062       *(outbuffer + offset + 4) = (u_reliability.base >> (8 * 4)) & 0xFF;
00063       *(outbuffer + offset + 5) = (u_reliability.base >> (8 * 5)) & 0xFF;
00064       *(outbuffer + offset + 6) = (u_reliability.base >> (8 * 6)) & 0xFF;
00065       *(outbuffer + offset + 7) = (u_reliability.base >> (8 * 7)) & 0xFF;
00066       offset += sizeof(this->reliability);
00067       *(outbuffer + offset + 0) = (this->tagnames_length >> (8 * 0)) & 0xFF;
00068       *(outbuffer + offset + 1) = (this->tagnames_length >> (8 * 1)) & 0xFF;
00069       *(outbuffer + offset + 2) = (this->tagnames_length >> (8 * 2)) & 0xFF;
00070       *(outbuffer + offset + 3) = (this->tagnames_length >> (8 * 3)) & 0xFF;
00071       offset += sizeof(this->tagnames_length);
00072       for( uint32_t i = 0; i < tagnames_length; i++){
00073       uint32_t length_tagnamesi = strlen(this->tagnames[i]);
00074       varToArr(outbuffer + offset, length_tagnamesi);
00075       offset += 4;
00076       memcpy(outbuffer + offset, this->tagnames[i], length_tagnamesi);
00077       offset += length_tagnamesi;
00078       }
00079       *(outbuffer + offset + 0) = (this->tags_length >> (8 * 0)) & 0xFF;
00080       *(outbuffer + offset + 1) = (this->tags_length >> (8 * 1)) & 0xFF;
00081       *(outbuffer + offset + 2) = (this->tags_length >> (8 * 2)) & 0xFF;
00082       *(outbuffer + offset + 3) = (this->tags_length >> (8 * 3)) & 0xFF;
00083       offset += sizeof(this->tags_length);
00084       for( uint32_t i = 0; i < tags_length; i++){
00085       uint32_t length_tagsi = strlen(this->tags[i]);
00086       varToArr(outbuffer + offset, length_tagsi);
00087       offset += 4;
00088       memcpy(outbuffer + offset, this->tags[i], length_tagsi);
00089       offset += length_tagsi;
00090       }
00091       return offset;
00092     }
00093 
00094     virtual int deserialize(unsigned char *inbuffer)
00095     {
00096       int offset = 0;
00097       uint32_t length_name;
00098       arrToVar(length_name, (inbuffer + offset));
00099       offset += 4;
00100       for(unsigned int k= offset; k< offset+length_name; ++k){
00101           inbuffer[k-1]=inbuffer[k];
00102       }
00103       inbuffer[offset+length_name-1]=0;
00104       this->name = (char *)(inbuffer + offset-1);
00105       offset += length_name;
00106       offset += this->position.deserialize(inbuffer + offset);
00107       offset += this->velocity.deserialize(inbuffer + offset);
00108       union {
00109         double real;
00110         uint64_t base;
00111       } u_reliability;
00112       u_reliability.base = 0;
00113       u_reliability.base |= ((uint64_t) (*(inbuffer + offset + 0))) << (8 * 0);
00114       u_reliability.base |= ((uint64_t) (*(inbuffer + offset + 1))) << (8 * 1);
00115       u_reliability.base |= ((uint64_t) (*(inbuffer + offset + 2))) << (8 * 2);
00116       u_reliability.base |= ((uint64_t) (*(inbuffer + offset + 3))) << (8 * 3);
00117       u_reliability.base |= ((uint64_t) (*(inbuffer + offset + 4))) << (8 * 4);
00118       u_reliability.base |= ((uint64_t) (*(inbuffer + offset + 5))) << (8 * 5);
00119       u_reliability.base |= ((uint64_t) (*(inbuffer + offset + 6))) << (8 * 6);
00120       u_reliability.base |= ((uint64_t) (*(inbuffer + offset + 7))) << (8 * 7);
00121       this->reliability = u_reliability.real;
00122       offset += sizeof(this->reliability);
00123       uint32_t tagnames_lengthT = ((uint32_t) (*(inbuffer + offset))); 
00124       tagnames_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 
00125       tagnames_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 
00126       tagnames_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 
00127       offset += sizeof(this->tagnames_length);
00128       if(tagnames_lengthT > tagnames_length)
00129         this->tagnames = (char**)realloc(this->tagnames, tagnames_lengthT * sizeof(char*));
00130       tagnames_length = tagnames_lengthT;
00131       for( uint32_t i = 0; i < tagnames_length; i++){
00132       uint32_t length_st_tagnames;
00133       arrToVar(length_st_tagnames, (inbuffer + offset));
00134       offset += 4;
00135       for(unsigned int k= offset; k< offset+length_st_tagnames; ++k){
00136           inbuffer[k-1]=inbuffer[k];
00137       }
00138       inbuffer[offset+length_st_tagnames-1]=0;
00139       this->st_tagnames = (char *)(inbuffer + offset-1);
00140       offset += length_st_tagnames;
00141         memcpy( &(this->tagnames[i]), &(this->st_tagnames), sizeof(char*));
00142       }
00143       uint32_t tags_lengthT = ((uint32_t) (*(inbuffer + offset))); 
00144       tags_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 
00145       tags_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 
00146       tags_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 
00147       offset += sizeof(this->tags_length);
00148       if(tags_lengthT > tags_length)
00149         this->tags = (char**)realloc(this->tags, tags_lengthT * sizeof(char*));
00150       tags_length = tags_lengthT;
00151       for( uint32_t i = 0; i < tags_length; i++){
00152       uint32_t length_st_tags;
00153       arrToVar(length_st_tags, (inbuffer + offset));
00154       offset += 4;
00155       for(unsigned int k= offset; k< offset+length_st_tags; ++k){
00156           inbuffer[k-1]=inbuffer[k];
00157       }
00158       inbuffer[offset+length_st_tags-1]=0;
00159       this->st_tags = (char *)(inbuffer + offset-1);
00160       offset += length_st_tags;
00161         memcpy( &(this->tags[i]), &(this->st_tags), sizeof(char*));
00162       }
00163      return offset;
00164     }
00165 
00166     virtual const char * getType(){ return "people_msgs/Person"; };
00167     virtual const char * getMD5(){ return "0b7c0818b76476f3863bd13f4d59f8df"; };
00168 
00169   };
00170 
00171 }
00172 #endif