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_InitPins_h 00019 #define _ROS_SERVICE_InitPins_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 INITPINS[] = "cob_hand_bridge/InitPins"; 00029 00030 class InitPinsRequest : public ros::Msg 00031 { 00032 public: 00033 uint8_t input_pins_length; 00034 uint8_t st_input_pins; 00035 uint8_t * input_pins; 00036 uint8_t output_pins_length; 00037 uint8_t st_output_pins; 00038 uint8_t * output_pins; 00039 00040 InitPinsRequest(): 00041 input_pins_length(0), input_pins(NULL), 00042 output_pins_length(0), output_pins(NULL) 00043 { 00044 } 00045 00046 virtual int serialize(unsigned char *outbuffer) const 00047 { 00048 int offset = 0; 00049 *(outbuffer + offset++) = input_pins_length; 00050 *(outbuffer + offset++) = 0; 00051 *(outbuffer + offset++) = 0; 00052 *(outbuffer + offset++) = 0; 00053 for( uint8_t i = 0; i < input_pins_length; i++){ 00054 *(outbuffer + offset + 0) = (this->input_pins[i] >> (8 * 0)) & 0xFF; 00055 offset += sizeof(this->input_pins[i]); 00056 } 00057 *(outbuffer + offset++) = output_pins_length; 00058 *(outbuffer + offset++) = 0; 00059 *(outbuffer + offset++) = 0; 00060 *(outbuffer + offset++) = 0; 00061 for( uint8_t i = 0; i < output_pins_length; i++){ 00062 *(outbuffer + offset + 0) = (this->output_pins[i] >> (8 * 0)) & 0xFF; 00063 offset += sizeof(this->output_pins[i]); 00064 } 00065 return offset; 00066 } 00067 00068 virtual int deserialize(unsigned char *inbuffer) 00069 { 00070 int offset = 0; 00071 uint8_t input_pins_lengthT = *(inbuffer + offset++); 00072 if(input_pins_lengthT > input_pins_length) 00073 this->input_pins = (uint8_t*)realloc(this->input_pins, input_pins_lengthT * sizeof(uint8_t)); 00074 offset += 3; 00075 input_pins_length = input_pins_lengthT; 00076 for( uint8_t i = 0; i < input_pins_length; i++){ 00077 this->st_input_pins = ((uint8_t) (*(inbuffer + offset))); 00078 offset += sizeof(this->st_input_pins); 00079 memcpy( &(this->input_pins[i]), &(this->st_input_pins), sizeof(uint8_t)); 00080 } 00081 uint8_t output_pins_lengthT = *(inbuffer + offset++); 00082 if(output_pins_lengthT > output_pins_length) 00083 this->output_pins = (uint8_t*)realloc(this->output_pins, output_pins_lengthT * sizeof(uint8_t)); 00084 offset += 3; 00085 output_pins_length = output_pins_lengthT; 00086 for( uint8_t i = 0; i < output_pins_length; i++){ 00087 this->st_output_pins = ((uint8_t) (*(inbuffer + offset))); 00088 offset += sizeof(this->st_output_pins); 00089 memcpy( &(this->output_pins[i]), &(this->st_output_pins), sizeof(uint8_t)); 00090 } 00091 return offset; 00092 } 00093 00094 const char * getType(){ return INITPINS; }; 00095 const char * getMD5(){ return "842fe571cf71231e47b423e75069e2bd"; }; 00096 00097 }; 00098 00099 class InitPinsResponse : public ros::Msg 00100 { 00101 public: 00102 bool success; 00103 00104 InitPinsResponse(): 00105 success(0) 00106 { 00107 } 00108 00109 virtual int serialize(unsigned char *outbuffer) const 00110 { 00111 int offset = 0; 00112 union { 00113 bool real; 00114 uint8_t base; 00115 } u_success; 00116 u_success.real = this->success; 00117 *(outbuffer + offset + 0) = (u_success.base >> (8 * 0)) & 0xFF; 00118 offset += sizeof(this->success); 00119 return offset; 00120 } 00121 00122 virtual int deserialize(unsigned char *inbuffer) 00123 { 00124 int offset = 0; 00125 union { 00126 bool real; 00127 uint8_t base; 00128 } u_success; 00129 u_success.base = 0; 00130 u_success.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); 00131 this->success = u_success.real; 00132 offset += sizeof(this->success); 00133 return offset; 00134 } 00135 00136 const char * getType(){ return INITPINS; }; 00137 const char * getMD5(){ return "358e233cde0c8a8bcfea4ce193f8fc15"; }; 00138 00139 }; 00140 00141 class InitPins { 00142 public: 00143 typedef InitPinsRequest Request; 00144 typedef InitPinsResponse Response; 00145 }; 00146 00147 } 00148 #endif