SetPWM.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016  
00017 
00018 #ifndef _ROS_SERVICE_SetPWM_h
00019 #define _ROS_SERVICE_SetPWM_h
00020 #include <stdint.h>
00021 #include <string.h>
00022 #include <stdlib.h>
00023 #include "ros/msg.h"
00024 
00025 namespace cob_hand_bridge
00026 {
00027 
00028 static const char SETPWM[] = "cob_hand_bridge/SetPWM";
00029 
00030   class SetPWMRequest : public ros::Msg
00031   {
00032     public:
00033       uint8_t pins_length;
00034       uint8_t st_pins;
00035       uint8_t * pins;
00036       uint8_t levels_length;
00037       float st_levels;
00038       float * levels;
00039 
00040     SetPWMRequest():
00041       pins_length(0), pins(NULL),
00042       levels_length(0), levels(NULL)
00043     {
00044     }
00045 
00046     virtual int serialize(unsigned char *outbuffer) const
00047     {
00048       int offset = 0;
00049       *(outbuffer + offset++) = pins_length;
00050       *(outbuffer + offset++) = 0;
00051       *(outbuffer + offset++) = 0;
00052       *(outbuffer + offset++) = 0;
00053       for( uint8_t i = 0; i < pins_length; i++){
00054       *(outbuffer + offset + 0) = (this->pins[i] >> (8 * 0)) & 0xFF;
00055       offset += sizeof(this->pins[i]);
00056       }
00057       *(outbuffer + offset++) = levels_length;
00058       *(outbuffer + offset++) = 0;
00059       *(outbuffer + offset++) = 0;
00060       *(outbuffer + offset++) = 0;
00061       for( uint8_t i = 0; i < levels_length; i++){
00062       union {
00063         float real;
00064         uint32_t base;
00065       } u_levelsi;
00066       u_levelsi.real = this->levels[i];
00067       *(outbuffer + offset + 0) = (u_levelsi.base >> (8 * 0)) & 0xFF;
00068       *(outbuffer + offset + 1) = (u_levelsi.base >> (8 * 1)) & 0xFF;
00069       *(outbuffer + offset + 2) = (u_levelsi.base >> (8 * 2)) & 0xFF;
00070       *(outbuffer + offset + 3) = (u_levelsi.base >> (8 * 3)) & 0xFF;
00071       offset += sizeof(this->levels[i]);
00072       }
00073       return offset;
00074     }
00075 
00076     virtual int deserialize(unsigned char *inbuffer)
00077     {
00078       int offset = 0;
00079       uint8_t pins_lengthT = *(inbuffer + offset++);
00080       if(pins_lengthT > pins_length)
00081         this->pins = (uint8_t*)realloc(this->pins, pins_lengthT * sizeof(uint8_t));
00082       offset += 3;
00083       pins_length = pins_lengthT;
00084       for( uint8_t i = 0; i < pins_length; i++){
00085       this->st_pins =  ((uint8_t) (*(inbuffer + offset)));
00086       offset += sizeof(this->st_pins);
00087         memcpy( &(this->pins[i]), &(this->st_pins), sizeof(uint8_t));
00088       }
00089       uint8_t levels_lengthT = *(inbuffer + offset++);
00090       if(levels_lengthT > levels_length)
00091         this->levels = (float*)realloc(this->levels, levels_lengthT * sizeof(float));
00092       offset += 3;
00093       levels_length = levels_lengthT;
00094       for( uint8_t i = 0; i < levels_length; i++){
00095       union {
00096         float real;
00097         uint32_t base;
00098       } u_st_levels;
00099       u_st_levels.base = 0;
00100       u_st_levels.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
00101       u_st_levels.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
00102       u_st_levels.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
00103       u_st_levels.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
00104       this->st_levels = u_st_levels.real;
00105       offset += sizeof(this->st_levels);
00106         memcpy( &(this->levels[i]), &(this->st_levels), sizeof(float));
00107       }
00108      return offset;
00109     }
00110 
00111     const char * getType(){ return SETPWM; };
00112     const char * getMD5(){ return "d3b671b5e2eb290c5f274725029ed0c2"; };
00113 
00114   };
00115 
00116   class SetPWMResponse : public ros::Msg
00117   {
00118     public:
00119       bool success;
00120 
00121     SetPWMResponse():
00122       success(0)
00123     {
00124     }
00125 
00126     virtual int serialize(unsigned char *outbuffer) const
00127     {
00128       int offset = 0;
00129       union {
00130         bool real;
00131         uint8_t base;
00132       } u_success;
00133       u_success.real = this->success;
00134       *(outbuffer + offset + 0) = (u_success.base >> (8 * 0)) & 0xFF;
00135       offset += sizeof(this->success);
00136       return offset;
00137     }
00138 
00139     virtual int deserialize(unsigned char *inbuffer)
00140     {
00141       int offset = 0;
00142       union {
00143         bool real;
00144         uint8_t base;
00145       } u_success;
00146       u_success.base = 0;
00147       u_success.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0);
00148       this->success = u_success.real;
00149       offset += sizeof(this->success);
00150      return offset;
00151     }
00152 
00153     const char * getType(){ return SETPWM; };
00154     const char * getMD5(){ return "358e233cde0c8a8bcfea4ce193f8fc15"; };
00155 
00156   };
00157 
00158   class SetPWM {
00159     public:
00160     typedef SetPWMRequest Request;
00161     typedef SetPWMResponse Response;
00162   };
00163 
00164 }
00165 #endif


cob_hand_bridge
Author(s): Mathias L├╝dtke
autogenerated on Thu Jun 6 2019 20:43:57