catchrobo2022 / Mbed 2 deprecated catchrobo2022_mbed

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Object.h Source File

Object.h

00001 #ifndef _ROS_jsk_recognition_msgs_Object_h
00002 #define _ROS_jsk_recognition_msgs_Object_h
00003 
00004 #include <stdint.h>
00005 #include <string.h>
00006 #include <stdlib.h>
00007 #include "ros/msg.h"
00008 #include "geometry_msgs/Vector3.h"
00009 
00010 namespace jsk_recognition_msgs
00011 {
00012 
00013   class Object : public ros::Msg
00014   {
00015     public:
00016       typedef int32_t _id_type;
00017       _id_type id;
00018       typedef const char* _name_type;
00019       _name_type name;
00020       typedef int32_t _class_id_type;
00021       _class_id_type class_id;
00022       typedef const char* _class_name_type;
00023       _class_name_type class_name;
00024       uint32_t image_resources_length;
00025       typedef char* _image_resources_type;
00026       _image_resources_type st_image_resources;
00027       _image_resources_type * image_resources;
00028       typedef const char* _mesh_resource_type;
00029       _mesh_resource_type mesh_resource;
00030       typedef float _weight_type;
00031       _weight_type weight;
00032       typedef geometry_msgs::Vector3 _dimensions_type;
00033       _dimensions_type dimensions;
00034 
00035     Object():
00036       id(0),
00037       name(""),
00038       class_id(0),
00039       class_name(""),
00040       image_resources_length(0), image_resources(NULL),
00041       mesh_resource(""),
00042       weight(0),
00043       dimensions()
00044     {
00045     }
00046 
00047     virtual int serialize(unsigned char *outbuffer) const
00048     {
00049       int offset = 0;
00050       union {
00051         int32_t real;
00052         uint32_t base;
00053       } u_id;
00054       u_id.real = this->id;
00055       *(outbuffer + offset + 0) = (u_id.base >> (8 * 0)) & 0xFF;
00056       *(outbuffer + offset + 1) = (u_id.base >> (8 * 1)) & 0xFF;
00057       *(outbuffer + offset + 2) = (u_id.base >> (8 * 2)) & 0xFF;
00058       *(outbuffer + offset + 3) = (u_id.base >> (8 * 3)) & 0xFF;
00059       offset += sizeof(this->id);
00060       uint32_t length_name = strlen(this->name);
00061       varToArr(outbuffer + offset, length_name);
00062       offset += 4;
00063       memcpy(outbuffer + offset, this->name, length_name);
00064       offset += length_name;
00065       union {
00066         int32_t real;
00067         uint32_t base;
00068       } u_class_id;
00069       u_class_id.real = this->class_id;
00070       *(outbuffer + offset + 0) = (u_class_id.base >> (8 * 0)) & 0xFF;
00071       *(outbuffer + offset + 1) = (u_class_id.base >> (8 * 1)) & 0xFF;
00072       *(outbuffer + offset + 2) = (u_class_id.base >> (8 * 2)) & 0xFF;
00073       *(outbuffer + offset + 3) = (u_class_id.base >> (8 * 3)) & 0xFF;
00074       offset += sizeof(this->class_id);
00075       uint32_t length_class_name = strlen(this->class_name);
00076       varToArr(outbuffer + offset, length_class_name);
00077       offset += 4;
00078       memcpy(outbuffer + offset, this->class_name, length_class_name);
00079       offset += length_class_name;
00080       *(outbuffer + offset + 0) = (this->image_resources_length >> (8 * 0)) & 0xFF;
00081       *(outbuffer + offset + 1) = (this->image_resources_length >> (8 * 1)) & 0xFF;
00082       *(outbuffer + offset + 2) = (this->image_resources_length >> (8 * 2)) & 0xFF;
00083       *(outbuffer + offset + 3) = (this->image_resources_length >> (8 * 3)) & 0xFF;
00084       offset += sizeof(this->image_resources_length);
00085       for( uint32_t i = 0; i < image_resources_length; i++){
00086       uint32_t length_image_resourcesi = strlen(this->image_resources[i]);
00087       varToArr(outbuffer + offset, length_image_resourcesi);
00088       offset += 4;
00089       memcpy(outbuffer + offset, this->image_resources[i], length_image_resourcesi);
00090       offset += length_image_resourcesi;
00091       }
00092       uint32_t length_mesh_resource = strlen(this->mesh_resource);
00093       varToArr(outbuffer + offset, length_mesh_resource);
00094       offset += 4;
00095       memcpy(outbuffer + offset, this->mesh_resource, length_mesh_resource);
00096       offset += length_mesh_resource;
00097       union {
00098         float real;
00099         uint32_t base;
00100       } u_weight;
00101       u_weight.real = this->weight;
00102       *(outbuffer + offset + 0) = (u_weight.base >> (8 * 0)) & 0xFF;
00103       *(outbuffer + offset + 1) = (u_weight.base >> (8 * 1)) & 0xFF;
00104       *(outbuffer + offset + 2) = (u_weight.base >> (8 * 2)) & 0xFF;
00105       *(outbuffer + offset + 3) = (u_weight.base >> (8 * 3)) & 0xFF;
00106       offset += sizeof(this->weight);
00107       offset += this->dimensions.serialize(outbuffer + offset);
00108       return offset;
00109     }
00110 
00111     virtual int deserialize(unsigned char *inbuffer)
00112     {
00113       int offset = 0;
00114       union {
00115         int32_t real;
00116         uint32_t base;
00117       } u_id;
00118       u_id.base = 0;
00119       u_id.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
00120       u_id.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
00121       u_id.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
00122       u_id.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
00123       this->id = u_id.real;
00124       offset += sizeof(this->id);
00125       uint32_t length_name;
00126       arrToVar(length_name, (inbuffer + offset));
00127       offset += 4;
00128       for(unsigned int k= offset; k< offset+length_name; ++k){
00129           inbuffer[k-1]=inbuffer[k];
00130       }
00131       inbuffer[offset+length_name-1]=0;
00132       this->name = (char *)(inbuffer + offset-1);
00133       offset += length_name;
00134       union {
00135         int32_t real;
00136         uint32_t base;
00137       } u_class_id;
00138       u_class_id.base = 0;
00139       u_class_id.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
00140       u_class_id.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
00141       u_class_id.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
00142       u_class_id.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
00143       this->class_id = u_class_id.real;
00144       offset += sizeof(this->class_id);
00145       uint32_t length_class_name;
00146       arrToVar(length_class_name, (inbuffer + offset));
00147       offset += 4;
00148       for(unsigned int k= offset; k< offset+length_class_name; ++k){
00149           inbuffer[k-1]=inbuffer[k];
00150       }
00151       inbuffer[offset+length_class_name-1]=0;
00152       this->class_name = (char *)(inbuffer + offset-1);
00153       offset += length_class_name;
00154       uint32_t image_resources_lengthT = ((uint32_t) (*(inbuffer + offset))); 
00155       image_resources_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 
00156       image_resources_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 
00157       image_resources_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 
00158       offset += sizeof(this->image_resources_length);
00159       if(image_resources_lengthT > image_resources_length)
00160         this->image_resources = (char**)realloc(this->image_resources, image_resources_lengthT * sizeof(char*));
00161       image_resources_length = image_resources_lengthT;
00162       for( uint32_t i = 0; i < image_resources_length; i++){
00163       uint32_t length_st_image_resources;
00164       arrToVar(length_st_image_resources, (inbuffer + offset));
00165       offset += 4;
00166       for(unsigned int k= offset; k< offset+length_st_image_resources; ++k){
00167           inbuffer[k-1]=inbuffer[k];
00168       }
00169       inbuffer[offset+length_st_image_resources-1]=0;
00170       this->st_image_resources = (char *)(inbuffer + offset-1);
00171       offset += length_st_image_resources;
00172         memcpy( &(this->image_resources[i]), &(this->st_image_resources), sizeof(char*));
00173       }
00174       uint32_t length_mesh_resource;
00175       arrToVar(length_mesh_resource, (inbuffer + offset));
00176       offset += 4;
00177       for(unsigned int k= offset; k< offset+length_mesh_resource; ++k){
00178           inbuffer[k-1]=inbuffer[k];
00179       }
00180       inbuffer[offset+length_mesh_resource-1]=0;
00181       this->mesh_resource = (char *)(inbuffer + offset-1);
00182       offset += length_mesh_resource;
00183       union {
00184         float real;
00185         uint32_t base;
00186       } u_weight;
00187       u_weight.base = 0;
00188       u_weight.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
00189       u_weight.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
00190       u_weight.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
00191       u_weight.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
00192       this->weight = u_weight.real;
00193       offset += sizeof(this->weight);
00194       offset += this->dimensions.deserialize(inbuffer + offset);
00195      return offset;
00196     }
00197 
00198     virtual const char * getType(){ return "jsk_recognition_msgs/Object"; };
00199     virtual const char * getMD5(){ return "57c53e712043df0244b0482d0447adee"; };
00200 
00201   };
00202 
00203 }
00204 #endif