SetPWM.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #ifndef _ROS_SERVICE_SetPWM_h
19 #define _ROS_SERVICE_SetPWM_h
20 #include <stdint.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include "ros/msg.h"
24 
25 namespace cob_hand_bridge
26 {
27 
28 static const char SETPWM[] = "cob_hand_bridge/SetPWM";
29 
30  class SetPWMRequest : public ros::Msg
31  {
32  public:
33  uint8_t pins_length;
34  uint8_t st_pins;
35  uint8_t * pins;
36  uint8_t levels_length;
37  float st_levels;
38  float * levels;
39 
41  pins_length(0), pins(NULL),
42  levels_length(0), levels(NULL)
43  {
44  }
45 
46  virtual int serialize(unsigned char *outbuffer) const
47  {
48  int offset = 0;
49  *(outbuffer + offset++) = pins_length;
50  *(outbuffer + offset++) = 0;
51  *(outbuffer + offset++) = 0;
52  *(outbuffer + offset++) = 0;
53  for( uint8_t i = 0; i < pins_length; i++){
54  *(outbuffer + offset + 0) = (this->pins[i] >> (8 * 0)) & 0xFF;
55  offset += sizeof(this->pins[i]);
56  }
57  *(outbuffer + offset++) = levels_length;
58  *(outbuffer + offset++) = 0;
59  *(outbuffer + offset++) = 0;
60  *(outbuffer + offset++) = 0;
61  for( uint8_t i = 0; i < levels_length; i++){
62  union {
63  float real;
64  uint32_t base;
65  } u_levelsi;
66  u_levelsi.real = this->levels[i];
67  *(outbuffer + offset + 0) = (u_levelsi.base >> (8 * 0)) & 0xFF;
68  *(outbuffer + offset + 1) = (u_levelsi.base >> (8 * 1)) & 0xFF;
69  *(outbuffer + offset + 2) = (u_levelsi.base >> (8 * 2)) & 0xFF;
70  *(outbuffer + offset + 3) = (u_levelsi.base >> (8 * 3)) & 0xFF;
71  offset += sizeof(this->levels[i]);
72  }
73  return offset;
74  }
75 
76  virtual int deserialize(unsigned char *inbuffer)
77  {
78  int offset = 0;
79  uint8_t pins_lengthT = *(inbuffer + offset++);
80  if(pins_lengthT > pins_length)
81  this->pins = (uint8_t*)realloc(this->pins, pins_lengthT * sizeof(uint8_t));
82  offset += 3;
83  pins_length = pins_lengthT;
84  for( uint8_t i = 0; i < pins_length; i++){
85  this->st_pins = ((uint8_t) (*(inbuffer + offset)));
86  offset += sizeof(this->st_pins);
87  memcpy( &(this->pins[i]), &(this->st_pins), sizeof(uint8_t));
88  }
89  uint8_t levels_lengthT = *(inbuffer + offset++);
90  if(levels_lengthT > levels_length)
91  this->levels = (float*)realloc(this->levels, levels_lengthT * sizeof(float));
92  offset += 3;
93  levels_length = levels_lengthT;
94  for( uint8_t i = 0; i < levels_length; i++){
95  union {
96  float real;
97  uint32_t base;
98  } u_st_levels;
99  u_st_levels.base = 0;
100  u_st_levels.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
101  u_st_levels.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
102  u_st_levels.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
103  u_st_levels.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
104  this->st_levels = u_st_levels.real;
105  offset += sizeof(this->st_levels);
106  memcpy( &(this->levels[i]), &(this->st_levels), sizeof(float));
107  }
108  return offset;
109  }
110 
111  const char * getType(){ return SETPWM; };
112  const char * getMD5(){ return "d3b671b5e2eb290c5f274725029ed0c2"; };
113 
114  };
115 
116  class SetPWMResponse : public ros::Msg
117  {
118  public:
119  bool success;
120 
122  success(0)
123  {
124  }
125 
126  virtual int serialize(unsigned char *outbuffer) const
127  {
128  int offset = 0;
129  union {
130  bool real;
131  uint8_t base;
132  } u_success;
133  u_success.real = this->success;
134  *(outbuffer + offset + 0) = (u_success.base >> (8 * 0)) & 0xFF;
135  offset += sizeof(this->success);
136  return offset;
137  }
138 
139  virtual int deserialize(unsigned char *inbuffer)
140  {
141  int offset = 0;
142  union {
143  bool real;
144  uint8_t base;
145  } u_success;
146  u_success.base = 0;
147  u_success.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0);
148  this->success = u_success.real;
149  offset += sizeof(this->success);
150  return offset;
151  }
152 
153  const char * getType(){ return SETPWM; };
154  const char * getMD5(){ return "358e233cde0c8a8bcfea4ce193f8fc15"; };
155 
156  };
157 
158  class SetPWM {
159  public:
162  };
163 
164 }
165 #endif
virtual int deserialize(unsigned char *inbuffer)
Definition: SetPWM.h:139
SetPWMResponse Response
Definition: SetPWM.h:161
virtual int deserialize(unsigned char *inbuffer)
Definition: SetPWM.h:76
static const char SETPWM[]
Definition: SetPWM.h:28
SetPWMRequest Request
Definition: SetPWM.h:160
virtual int serialize(unsigned char *outbuffer) const
Definition: SetPWM.h:126
const char * getType()
Definition: SetPWM.h:111
virtual int serialize(unsigned char *outbuffer) const
Definition: SetPWM.h:46
Definition: msg.h:26


cob_hand_bridge
Author(s): Mathias Lüdtke
autogenerated on Tue Oct 20 2020 03:35:57