kitt_platform
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Macros
BatteryState.h
Go to the documentation of this file.
1 #ifndef _ROS_sensor_msgs_BatteryState_h
2 #define _ROS_sensor_msgs_BatteryState_h
3 
4 #include <stdint.h>
5 #include <string.h>
6 #include <stdlib.h>
7 #include "ros/msg.h"
8 #include "std_msgs/Header.h"
9 
10 namespace sensor_msgs
11 {
12 
13  class BatteryState : public ros::Msg
14  {
15  public:
17  float voltage;
18  float current;
19  float charge;
20  float capacity;
22  float percentage;
26  bool present;
29  float * cell_voltage;
30  const char* location;
31  const char* serial_number;
53 
55  header(),
56  voltage(0),
57  current(0),
58  charge(0),
59  capacity(0),
60  design_capacity(0),
61  percentage(0),
65  present(0),
67  location(""),
68  serial_number("")
69  {
70  }
71 
72  virtual int serialize(unsigned char *outbuffer) const
73  {
74  int offset = 0;
75  offset += this->header.serialize(outbuffer + offset);
76  union {
77  float real;
78  uint32_t base;
79  } u_voltage;
80  u_voltage.real = this->voltage;
81  *(outbuffer + offset + 0) = (u_voltage.base >> (8 * 0)) & 0xFF;
82  *(outbuffer + offset + 1) = (u_voltage.base >> (8 * 1)) & 0xFF;
83  *(outbuffer + offset + 2) = (u_voltage.base >> (8 * 2)) & 0xFF;
84  *(outbuffer + offset + 3) = (u_voltage.base >> (8 * 3)) & 0xFF;
85  offset += sizeof(this->voltage);
86  union {
87  float real;
88  uint32_t base;
89  } u_current;
90  u_current.real = this->current;
91  *(outbuffer + offset + 0) = (u_current.base >> (8 * 0)) & 0xFF;
92  *(outbuffer + offset + 1) = (u_current.base >> (8 * 1)) & 0xFF;
93  *(outbuffer + offset + 2) = (u_current.base >> (8 * 2)) & 0xFF;
94  *(outbuffer + offset + 3) = (u_current.base >> (8 * 3)) & 0xFF;
95  offset += sizeof(this->current);
96  union {
97  float real;
98  uint32_t base;
99  } u_charge;
100  u_charge.real = this->charge;
101  *(outbuffer + offset + 0) = (u_charge.base >> (8 * 0)) & 0xFF;
102  *(outbuffer + offset + 1) = (u_charge.base >> (8 * 1)) & 0xFF;
103  *(outbuffer + offset + 2) = (u_charge.base >> (8 * 2)) & 0xFF;
104  *(outbuffer + offset + 3) = (u_charge.base >> (8 * 3)) & 0xFF;
105  offset += sizeof(this->charge);
106  union {
107  float real;
108  uint32_t base;
109  } u_capacity;
110  u_capacity.real = this->capacity;
111  *(outbuffer + offset + 0) = (u_capacity.base >> (8 * 0)) & 0xFF;
112  *(outbuffer + offset + 1) = (u_capacity.base >> (8 * 1)) & 0xFF;
113  *(outbuffer + offset + 2) = (u_capacity.base >> (8 * 2)) & 0xFF;
114  *(outbuffer + offset + 3) = (u_capacity.base >> (8 * 3)) & 0xFF;
115  offset += sizeof(this->capacity);
116  union {
117  float real;
118  uint32_t base;
119  } u_design_capacity;
120  u_design_capacity.real = this->design_capacity;
121  *(outbuffer + offset + 0) = (u_design_capacity.base >> (8 * 0)) & 0xFF;
122  *(outbuffer + offset + 1) = (u_design_capacity.base >> (8 * 1)) & 0xFF;
123  *(outbuffer + offset + 2) = (u_design_capacity.base >> (8 * 2)) & 0xFF;
124  *(outbuffer + offset + 3) = (u_design_capacity.base >> (8 * 3)) & 0xFF;
125  offset += sizeof(this->design_capacity);
126  union {
127  float real;
128  uint32_t base;
129  } u_percentage;
130  u_percentage.real = this->percentage;
131  *(outbuffer + offset + 0) = (u_percentage.base >> (8 * 0)) & 0xFF;
132  *(outbuffer + offset + 1) = (u_percentage.base >> (8 * 1)) & 0xFF;
133  *(outbuffer + offset + 2) = (u_percentage.base >> (8 * 2)) & 0xFF;
134  *(outbuffer + offset + 3) = (u_percentage.base >> (8 * 3)) & 0xFF;
135  offset += sizeof(this->percentage);
136  *(outbuffer + offset + 0) = (this->power_supply_status >> (8 * 0)) & 0xFF;
137  offset += sizeof(this->power_supply_status);
138  *(outbuffer + offset + 0) = (this->power_supply_health >> (8 * 0)) & 0xFF;
139  offset += sizeof(this->power_supply_health);
140  *(outbuffer + offset + 0) = (this->power_supply_technology >> (8 * 0)) & 0xFF;
141  offset += sizeof(this->power_supply_technology);
142  union {
143  bool real;
144  uint8_t base;
145  } u_present;
146  u_present.real = this->present;
147  *(outbuffer + offset + 0) = (u_present.base >> (8 * 0)) & 0xFF;
148  offset += sizeof(this->present);
149  *(outbuffer + offset++) = cell_voltage_length;
150  *(outbuffer + offset++) = 0;
151  *(outbuffer + offset++) = 0;
152  *(outbuffer + offset++) = 0;
153  for( uint8_t i = 0; i < cell_voltage_length; i++){
154  union {
155  float real;
156  uint32_t base;
157  } u_cell_voltagei;
158  u_cell_voltagei.real = this->cell_voltage[i];
159  *(outbuffer + offset + 0) = (u_cell_voltagei.base >> (8 * 0)) & 0xFF;
160  *(outbuffer + offset + 1) = (u_cell_voltagei.base >> (8 * 1)) & 0xFF;
161  *(outbuffer + offset + 2) = (u_cell_voltagei.base >> (8 * 2)) & 0xFF;
162  *(outbuffer + offset + 3) = (u_cell_voltagei.base >> (8 * 3)) & 0xFF;
163  offset += sizeof(this->cell_voltage[i]);
164  }
165  uint32_t length_location = strlen(this->location);
166  memcpy(outbuffer + offset, &length_location, sizeof(uint32_t));
167  offset += 4;
168  memcpy(outbuffer + offset, this->location, length_location);
169  offset += length_location;
170  uint32_t length_serial_number = strlen(this->serial_number);
171  memcpy(outbuffer + offset, &length_serial_number, sizeof(uint32_t));
172  offset += 4;
173  memcpy(outbuffer + offset, this->serial_number, length_serial_number);
174  offset += length_serial_number;
175  return offset;
176  }
177 
178  virtual int deserialize(unsigned char *inbuffer)
179  {
180  int offset = 0;
181  offset += this->header.deserialize(inbuffer + offset);
182  union {
183  float real;
184  uint32_t base;
185  } u_voltage;
186  u_voltage.base = 0;
187  u_voltage.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
188  u_voltage.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
189  u_voltage.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
190  u_voltage.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
191  this->voltage = u_voltage.real;
192  offset += sizeof(this->voltage);
193  union {
194  float real;
195  uint32_t base;
196  } u_current;
197  u_current.base = 0;
198  u_current.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
199  u_current.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
200  u_current.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
201  u_current.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
202  this->current = u_current.real;
203  offset += sizeof(this->current);
204  union {
205  float real;
206  uint32_t base;
207  } u_charge;
208  u_charge.base = 0;
209  u_charge.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
210  u_charge.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
211  u_charge.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
212  u_charge.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
213  this->charge = u_charge.real;
214  offset += sizeof(this->charge);
215  union {
216  float real;
217  uint32_t base;
218  } u_capacity;
219  u_capacity.base = 0;
220  u_capacity.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
221  u_capacity.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
222  u_capacity.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
223  u_capacity.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
224  this->capacity = u_capacity.real;
225  offset += sizeof(this->capacity);
226  union {
227  float real;
228  uint32_t base;
229  } u_design_capacity;
230  u_design_capacity.base = 0;
231  u_design_capacity.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
232  u_design_capacity.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
233  u_design_capacity.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
234  u_design_capacity.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
235  this->design_capacity = u_design_capacity.real;
236  offset += sizeof(this->design_capacity);
237  union {
238  float real;
239  uint32_t base;
240  } u_percentage;
241  u_percentage.base = 0;
242  u_percentage.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
243  u_percentage.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
244  u_percentage.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
245  u_percentage.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
246  this->percentage = u_percentage.real;
247  offset += sizeof(this->percentage);
248  this->power_supply_status = ((uint8_t) (*(inbuffer + offset)));
249  offset += sizeof(this->power_supply_status);
250  this->power_supply_health = ((uint8_t) (*(inbuffer + offset)));
251  offset += sizeof(this->power_supply_health);
252  this->power_supply_technology = ((uint8_t) (*(inbuffer + offset)));
253  offset += sizeof(this->power_supply_technology);
254  union {
255  bool real;
256  uint8_t base;
257  } u_present;
258  u_present.base = 0;
259  u_present.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0);
260  this->present = u_present.real;
261  offset += sizeof(this->present);
262  uint8_t cell_voltage_lengthT = *(inbuffer + offset++);
263  if(cell_voltage_lengthT > cell_voltage_length)
264  this->cell_voltage = (float*)realloc(this->cell_voltage, cell_voltage_lengthT * sizeof(float));
265  offset += 3;
266  cell_voltage_length = cell_voltage_lengthT;
267  for( uint8_t i = 0; i < cell_voltage_length; i++){
268  union {
269  float real;
270  uint32_t base;
271  } u_st_cell_voltage;
272  u_st_cell_voltage.base = 0;
273  u_st_cell_voltage.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
274  u_st_cell_voltage.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
275  u_st_cell_voltage.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
276  u_st_cell_voltage.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
277  this->st_cell_voltage = u_st_cell_voltage.real;
278  offset += sizeof(this->st_cell_voltage);
279  memcpy( &(this->cell_voltage[i]), &(this->st_cell_voltage), sizeof(float));
280  }
281  uint32_t length_location;
282  memcpy(&length_location, (inbuffer + offset), sizeof(uint32_t));
283  offset += 4;
284  for(unsigned int k= offset; k< offset+length_location; ++k){
285  inbuffer[k-1]=inbuffer[k];
286  }
287  inbuffer[offset+length_location-1]=0;
288  this->location = (char *)(inbuffer + offset-1);
289  offset += length_location;
290  uint32_t length_serial_number;
291  memcpy(&length_serial_number, (inbuffer + offset), sizeof(uint32_t));
292  offset += 4;
293  for(unsigned int k= offset; k< offset+length_serial_number; ++k){
294  inbuffer[k-1]=inbuffer[k];
295  }
296  inbuffer[offset+length_serial_number-1]=0;
297  this->serial_number = (char *)(inbuffer + offset-1);
298  offset += length_serial_number;
299  return offset;
300  }
301 
302  const char * getType(){ return "sensor_msgs/BatteryState"; };
303  const char * getMD5(){ return "476f837fa6771f6e16e3bf4ef96f8770"; };
304 
305  };
306 
307 }
308 #endif
virtual int deserialize(unsigned char *inbuffer)
Definition: Header.h:53
float charge
Definition: BatteryState.h:19
uint8_t cell_voltage_length
Definition: BatteryState.h:27
float capacity
Definition: BatteryState.h:20
float percentage
Definition: BatteryState.h:22
bool present
Definition: BatteryState.h:26
uint8_t power_supply_health
Definition: BatteryState.h:24
float current
Definition: BatteryState.h:18
float design_capacity
Definition: BatteryState.h:21
virtual int serialize(unsigned char *outbuffer) const
Definition: Header.h:27
float * cell_voltage
Definition: BatteryState.h:29
const char * serial_number
Definition: BatteryState.h:31
Definition: Header.h:13
BatteryState()
Definition: BatteryState.h:54
std_msgs::Header header
Definition: BatteryState.h:16
float st_cell_voltage
Definition: BatteryState.h:28
Definition: BatteryState.h:13
uint8_t power_supply_technology
Definition: BatteryState.h:25
uint8_t power_supply_status
Definition: BatteryState.h:23
const char * getType()
Definition: BatteryState.h:302
const char * location
Definition: BatteryState.h:30
Definition: msg.h:43
virtual int serialize(unsigned char *outbuffer) const
Definition: BatteryState.h:72
const char * getMD5()
Definition: BatteryState.h:303
virtual int deserialize(unsigned char *inbuffer)
Definition: BatteryState.h:178
float voltage
Definition: BatteryState.h:17