catchrobo2022 / Mbed 2 deprecated catchrobo2022_mbed

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers OverlayMenu.h Source File

OverlayMenu.h

00001 #ifndef _ROS_jsk_rviz_plugins_OverlayMenu_h
00002 #define _ROS_jsk_rviz_plugins_OverlayMenu_h
00003 
00004 #include <stdint.h>
00005 #include <string.h>
00006 #include <stdlib.h>
00007 #include "ros/msg.h"
00008 #include "std_msgs/ColorRGBA.h"
00009 
00010 namespace jsk_rviz_plugins
00011 {
00012 
00013   class OverlayMenu : public ros::Msg
00014   {
00015     public:
00016       typedef int32_t _action_type;
00017       _action_type action;
00018       typedef uint32_t _current_index_type;
00019       _current_index_type current_index;
00020       uint32_t menus_length;
00021       typedef char* _menus_type;
00022       _menus_type st_menus;
00023       _menus_type * menus;
00024       typedef const char* _title_type;
00025       _title_type title;
00026       typedef std_msgs::ColorRGBA _bg_color_type;
00027       _bg_color_type bg_color;
00028       typedef std_msgs::ColorRGBA _fg_color_type;
00029       _fg_color_type fg_color;
00030       enum { ACTION_SELECT = 0 };
00031       enum { ACTION_CLOSE = 1 };
00032 
00033     OverlayMenu():
00034       action(0),
00035       current_index(0),
00036       menus_length(0), menus(NULL),
00037       title(""),
00038       bg_color(),
00039       fg_color()
00040     {
00041     }
00042 
00043     virtual int serialize(unsigned char *outbuffer) const
00044     {
00045       int offset = 0;
00046       union {
00047         int32_t real;
00048         uint32_t base;
00049       } u_action;
00050       u_action.real = this->action;
00051       *(outbuffer + offset + 0) = (u_action.base >> (8 * 0)) & 0xFF;
00052       *(outbuffer + offset + 1) = (u_action.base >> (8 * 1)) & 0xFF;
00053       *(outbuffer + offset + 2) = (u_action.base >> (8 * 2)) & 0xFF;
00054       *(outbuffer + offset + 3) = (u_action.base >> (8 * 3)) & 0xFF;
00055       offset += sizeof(this->action);
00056       *(outbuffer + offset + 0) = (this->current_index >> (8 * 0)) & 0xFF;
00057       *(outbuffer + offset + 1) = (this->current_index >> (8 * 1)) & 0xFF;
00058       *(outbuffer + offset + 2) = (this->current_index >> (8 * 2)) & 0xFF;
00059       *(outbuffer + offset + 3) = (this->current_index >> (8 * 3)) & 0xFF;
00060       offset += sizeof(this->current_index);
00061       *(outbuffer + offset + 0) = (this->menus_length >> (8 * 0)) & 0xFF;
00062       *(outbuffer + offset + 1) = (this->menus_length >> (8 * 1)) & 0xFF;
00063       *(outbuffer + offset + 2) = (this->menus_length >> (8 * 2)) & 0xFF;
00064       *(outbuffer + offset + 3) = (this->menus_length >> (8 * 3)) & 0xFF;
00065       offset += sizeof(this->menus_length);
00066       for( uint32_t i = 0; i < menus_length; i++){
00067       uint32_t length_menusi = strlen(this->menus[i]);
00068       varToArr(outbuffer + offset, length_menusi);
00069       offset += 4;
00070       memcpy(outbuffer + offset, this->menus[i], length_menusi);
00071       offset += length_menusi;
00072       }
00073       uint32_t length_title = strlen(this->title);
00074       varToArr(outbuffer + offset, length_title);
00075       offset += 4;
00076       memcpy(outbuffer + offset, this->title, length_title);
00077       offset += length_title;
00078       offset += this->bg_color.serialize(outbuffer + offset);
00079       offset += this->fg_color.serialize(outbuffer + offset);
00080       return offset;
00081     }
00082 
00083     virtual int deserialize(unsigned char *inbuffer)
00084     {
00085       int offset = 0;
00086       union {
00087         int32_t real;
00088         uint32_t base;
00089       } u_action;
00090       u_action.base = 0;
00091       u_action.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
00092       u_action.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
00093       u_action.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
00094       u_action.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
00095       this->action = u_action.real;
00096       offset += sizeof(this->action);
00097       this->current_index =  ((uint32_t) (*(inbuffer + offset)));
00098       this->current_index |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
00099       this->current_index |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
00100       this->current_index |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
00101       offset += sizeof(this->current_index);
00102       uint32_t menus_lengthT = ((uint32_t) (*(inbuffer + offset))); 
00103       menus_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 
00104       menus_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 
00105       menus_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 
00106       offset += sizeof(this->menus_length);
00107       if(menus_lengthT > menus_length)
00108         this->menus = (char**)realloc(this->menus, menus_lengthT * sizeof(char*));
00109       menus_length = menus_lengthT;
00110       for( uint32_t i = 0; i < menus_length; i++){
00111       uint32_t length_st_menus;
00112       arrToVar(length_st_menus, (inbuffer + offset));
00113       offset += 4;
00114       for(unsigned int k= offset; k< offset+length_st_menus; ++k){
00115           inbuffer[k-1]=inbuffer[k];
00116       }
00117       inbuffer[offset+length_st_menus-1]=0;
00118       this->st_menus = (char *)(inbuffer + offset-1);
00119       offset += length_st_menus;
00120         memcpy( &(this->menus[i]), &(this->st_menus), sizeof(char*));
00121       }
00122       uint32_t length_title;
00123       arrToVar(length_title, (inbuffer + offset));
00124       offset += 4;
00125       for(unsigned int k= offset; k< offset+length_title; ++k){
00126           inbuffer[k-1]=inbuffer[k];
00127       }
00128       inbuffer[offset+length_title-1]=0;
00129       this->title = (char *)(inbuffer + offset-1);
00130       offset += length_title;
00131       offset += this->bg_color.deserialize(inbuffer + offset);
00132       offset += this->fg_color.deserialize(inbuffer + offset);
00133      return offset;
00134     }
00135 
00136     virtual const char * getType(){ return "jsk_rviz_plugins/OverlayMenu"; };
00137     virtual const char * getMD5(){ return "517426ba068ca022d86cf2c56c98889f"; };
00138 
00139   };
00140 
00141 }
00142 #endif