catchrobo2022 / Mbed 2 deprecated catchrobo2022_mbed

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Update.h Source File

Update.h

00001 #ifndef _ROS_SERVICE_Update_h
00002 #define _ROS_SERVICE_Update_h
00003 #include <stdint.h>
00004 #include <string.h>
00005 #include <stdlib.h>
00006 #include "ros/msg.h"
00007 #include "ros/duration.h"
00008 
00009 namespace jsk_topic_tools
00010 {
00011 
00012 static const char UPDATE[] = "jsk_topic_tools/Update";
00013 
00014   class UpdateRequest : public ros::Msg
00015   {
00016     public:
00017       typedef const char* _topic_name_type;
00018       _topic_name_type topic_name;
00019       typedef bool _periodic_type;
00020       _periodic_type periodic;
00021       typedef ros::Duration _periodic_rate_type;
00022       _periodic_rate_type periodic_rate;
00023 
00024     UpdateRequest():
00025       topic_name(""),
00026       periodic(0),
00027       periodic_rate()
00028     {
00029     }
00030 
00031     virtual int serialize(unsigned char *outbuffer) const
00032     {
00033       int offset = 0;
00034       uint32_t length_topic_name = strlen(this->topic_name);
00035       varToArr(outbuffer + offset, length_topic_name);
00036       offset += 4;
00037       memcpy(outbuffer + offset, this->topic_name, length_topic_name);
00038       offset += length_topic_name;
00039       union {
00040         bool real;
00041         uint8_t base;
00042       } u_periodic;
00043       u_periodic.real = this->periodic;
00044       *(outbuffer + offset + 0) = (u_periodic.base >> (8 * 0)) & 0xFF;
00045       offset += sizeof(this->periodic);
00046       *(outbuffer + offset + 0) = (this->periodic_rate.sec >> (8 * 0)) & 0xFF;
00047       *(outbuffer + offset + 1) = (this->periodic_rate.sec >> (8 * 1)) & 0xFF;
00048       *(outbuffer + offset + 2) = (this->periodic_rate.sec >> (8 * 2)) & 0xFF;
00049       *(outbuffer + offset + 3) = (this->periodic_rate.sec >> (8 * 3)) & 0xFF;
00050       offset += sizeof(this->periodic_rate.sec);
00051       *(outbuffer + offset + 0) = (this->periodic_rate.nsec >> (8 * 0)) & 0xFF;
00052       *(outbuffer + offset + 1) = (this->periodic_rate.nsec >> (8 * 1)) & 0xFF;
00053       *(outbuffer + offset + 2) = (this->periodic_rate.nsec >> (8 * 2)) & 0xFF;
00054       *(outbuffer + offset + 3) = (this->periodic_rate.nsec >> (8 * 3)) & 0xFF;
00055       offset += sizeof(this->periodic_rate.nsec);
00056       return offset;
00057     }
00058 
00059     virtual int deserialize(unsigned char *inbuffer)
00060     {
00061       int offset = 0;
00062       uint32_t length_topic_name;
00063       arrToVar(length_topic_name, (inbuffer + offset));
00064       offset += 4;
00065       for(unsigned int k= offset; k< offset+length_topic_name; ++k){
00066           inbuffer[k-1]=inbuffer[k];
00067       }
00068       inbuffer[offset+length_topic_name-1]=0;
00069       this->topic_name = (char *)(inbuffer + offset-1);
00070       offset += length_topic_name;
00071       union {
00072         bool real;
00073         uint8_t base;
00074       } u_periodic;
00075       u_periodic.base = 0;
00076       u_periodic.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0);
00077       this->periodic = u_periodic.real;
00078       offset += sizeof(this->periodic);
00079       this->periodic_rate.sec =  ((uint32_t) (*(inbuffer + offset)));
00080       this->periodic_rate.sec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
00081       this->periodic_rate.sec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
00082       this->periodic_rate.sec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
00083       offset += sizeof(this->periodic_rate.sec);
00084       this->periodic_rate.nsec =  ((uint32_t) (*(inbuffer + offset)));
00085       this->periodic_rate.nsec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
00086       this->periodic_rate.nsec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
00087       this->periodic_rate.nsec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
00088       offset += sizeof(this->periodic_rate.nsec);
00089      return offset;
00090     }
00091 
00092     virtual const char * getType(){ return UPDATE; };
00093     virtual const char * getMD5(){ return "0050acd5c94510531ac3023287e6b559"; };
00094 
00095   };
00096 
00097   class UpdateResponse : public ros::Msg
00098   {
00099     public:
00100       typedef double _rate_type;
00101       _rate_type rate;
00102 
00103     UpdateResponse():
00104       rate(0)
00105     {
00106     }
00107 
00108     virtual int serialize(unsigned char *outbuffer) const
00109     {
00110       int offset = 0;
00111       union {
00112         double real;
00113         uint64_t base;
00114       } u_rate;
00115       u_rate.real = this->rate;
00116       *(outbuffer + offset + 0) = (u_rate.base >> (8 * 0)) & 0xFF;
00117       *(outbuffer + offset + 1) = (u_rate.base >> (8 * 1)) & 0xFF;
00118       *(outbuffer + offset + 2) = (u_rate.base >> (8 * 2)) & 0xFF;
00119       *(outbuffer + offset + 3) = (u_rate.base >> (8 * 3)) & 0xFF;
00120       *(outbuffer + offset + 4) = (u_rate.base >> (8 * 4)) & 0xFF;
00121       *(outbuffer + offset + 5) = (u_rate.base >> (8 * 5)) & 0xFF;
00122       *(outbuffer + offset + 6) = (u_rate.base >> (8 * 6)) & 0xFF;
00123       *(outbuffer + offset + 7) = (u_rate.base >> (8 * 7)) & 0xFF;
00124       offset += sizeof(this->rate);
00125       return offset;
00126     }
00127 
00128     virtual int deserialize(unsigned char *inbuffer)
00129     {
00130       int offset = 0;
00131       union {
00132         double real;
00133         uint64_t base;
00134       } u_rate;
00135       u_rate.base = 0;
00136       u_rate.base |= ((uint64_t) (*(inbuffer + offset + 0))) << (8 * 0);
00137       u_rate.base |= ((uint64_t) (*(inbuffer + offset + 1))) << (8 * 1);
00138       u_rate.base |= ((uint64_t) (*(inbuffer + offset + 2))) << (8 * 2);
00139       u_rate.base |= ((uint64_t) (*(inbuffer + offset + 3))) << (8 * 3);
00140       u_rate.base |= ((uint64_t) (*(inbuffer + offset + 4))) << (8 * 4);
00141       u_rate.base |= ((uint64_t) (*(inbuffer + offset + 5))) << (8 * 5);
00142       u_rate.base |= ((uint64_t) (*(inbuffer + offset + 6))) << (8 * 6);
00143       u_rate.base |= ((uint64_t) (*(inbuffer + offset + 7))) << (8 * 7);
00144       this->rate = u_rate.real;
00145       offset += sizeof(this->rate);
00146      return offset;
00147     }
00148 
00149     virtual const char * getType(){ return UPDATE; };
00150     virtual const char * getMD5(){ return "4910f3d55cbb29566b6c8f8f16528adf"; };
00151 
00152   };
00153 
00154   class Update {
00155     public:
00156     typedef UpdateRequest Request;
00157     typedef UpdateResponse Response;
00158   };
00159 
00160 }
00161 #endif