Irfan Tito Kurniawan / ros_lib
Committer:
irfantitok
Date:
Wed Sep 02 13:51:31 2020 +0000
Revision:
0:8f3710bfd298
Resolved round not found

Who changed what in which revision?

UserRevisionLine numberNew contents of line
irfantitok 0:8f3710bfd298 1 #ifndef _ROS_sensor_msgs_ChannelFloat32_h
irfantitok 0:8f3710bfd298 2 #define _ROS_sensor_msgs_ChannelFloat32_h
irfantitok 0:8f3710bfd298 3
irfantitok 0:8f3710bfd298 4 #include <stdint.h>
irfantitok 0:8f3710bfd298 5 #include <string.h>
irfantitok 0:8f3710bfd298 6 #include <stdlib.h>
irfantitok 0:8f3710bfd298 7 #include "ros/msg.h"
irfantitok 0:8f3710bfd298 8
irfantitok 0:8f3710bfd298 9 namespace sensor_msgs
irfantitok 0:8f3710bfd298 10 {
irfantitok 0:8f3710bfd298 11
irfantitok 0:8f3710bfd298 12 class ChannelFloat32 : public ros::Msg
irfantitok 0:8f3710bfd298 13 {
irfantitok 0:8f3710bfd298 14 public:
irfantitok 0:8f3710bfd298 15 typedef const char* _name_type;
irfantitok 0:8f3710bfd298 16 _name_type name;
irfantitok 0:8f3710bfd298 17 uint32_t values_length;
irfantitok 0:8f3710bfd298 18 typedef float _values_type;
irfantitok 0:8f3710bfd298 19 _values_type st_values;
irfantitok 0:8f3710bfd298 20 _values_type * values;
irfantitok 0:8f3710bfd298 21
irfantitok 0:8f3710bfd298 22 ChannelFloat32():
irfantitok 0:8f3710bfd298 23 name(""),
irfantitok 0:8f3710bfd298 24 values_length(0), values(NULL)
irfantitok 0:8f3710bfd298 25 {
irfantitok 0:8f3710bfd298 26 }
irfantitok 0:8f3710bfd298 27
irfantitok 0:8f3710bfd298 28 virtual int serialize(unsigned char *outbuffer) const
irfantitok 0:8f3710bfd298 29 {
irfantitok 0:8f3710bfd298 30 int offset = 0;
irfantitok 0:8f3710bfd298 31 uint32_t length_name = strlen(this->name);
irfantitok 0:8f3710bfd298 32 varToArr(outbuffer + offset, length_name);
irfantitok 0:8f3710bfd298 33 offset += 4;
irfantitok 0:8f3710bfd298 34 memcpy(outbuffer + offset, this->name, length_name);
irfantitok 0:8f3710bfd298 35 offset += length_name;
irfantitok 0:8f3710bfd298 36 *(outbuffer + offset + 0) = (this->values_length >> (8 * 0)) & 0xFF;
irfantitok 0:8f3710bfd298 37 *(outbuffer + offset + 1) = (this->values_length >> (8 * 1)) & 0xFF;
irfantitok 0:8f3710bfd298 38 *(outbuffer + offset + 2) = (this->values_length >> (8 * 2)) & 0xFF;
irfantitok 0:8f3710bfd298 39 *(outbuffer + offset + 3) = (this->values_length >> (8 * 3)) & 0xFF;
irfantitok 0:8f3710bfd298 40 offset += sizeof(this->values_length);
irfantitok 0:8f3710bfd298 41 for( uint32_t i = 0; i < values_length; i++){
irfantitok 0:8f3710bfd298 42 union {
irfantitok 0:8f3710bfd298 43 float real;
irfantitok 0:8f3710bfd298 44 uint32_t base;
irfantitok 0:8f3710bfd298 45 } u_valuesi;
irfantitok 0:8f3710bfd298 46 u_valuesi.real = this->values[i];
irfantitok 0:8f3710bfd298 47 *(outbuffer + offset + 0) = (u_valuesi.base >> (8 * 0)) & 0xFF;
irfantitok 0:8f3710bfd298 48 *(outbuffer + offset + 1) = (u_valuesi.base >> (8 * 1)) & 0xFF;
irfantitok 0:8f3710bfd298 49 *(outbuffer + offset + 2) = (u_valuesi.base >> (8 * 2)) & 0xFF;
irfantitok 0:8f3710bfd298 50 *(outbuffer + offset + 3) = (u_valuesi.base >> (8 * 3)) & 0xFF;
irfantitok 0:8f3710bfd298 51 offset += sizeof(this->values[i]);
irfantitok 0:8f3710bfd298 52 }
irfantitok 0:8f3710bfd298 53 return offset;
irfantitok 0:8f3710bfd298 54 }
irfantitok 0:8f3710bfd298 55
irfantitok 0:8f3710bfd298 56 virtual int deserialize(unsigned char *inbuffer)
irfantitok 0:8f3710bfd298 57 {
irfantitok 0:8f3710bfd298 58 int offset = 0;
irfantitok 0:8f3710bfd298 59 uint32_t length_name;
irfantitok 0:8f3710bfd298 60 arrToVar(length_name, (inbuffer + offset));
irfantitok 0:8f3710bfd298 61 offset += 4;
irfantitok 0:8f3710bfd298 62 for(unsigned int k= offset; k< offset+length_name; ++k){
irfantitok 0:8f3710bfd298 63 inbuffer[k-1]=inbuffer[k];
irfantitok 0:8f3710bfd298 64 }
irfantitok 0:8f3710bfd298 65 inbuffer[offset+length_name-1]=0;
irfantitok 0:8f3710bfd298 66 this->name = (char *)(inbuffer + offset-1);
irfantitok 0:8f3710bfd298 67 offset += length_name;
irfantitok 0:8f3710bfd298 68 uint32_t values_lengthT = ((uint32_t) (*(inbuffer + offset)));
irfantitok 0:8f3710bfd298 69 values_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
irfantitok 0:8f3710bfd298 70 values_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
irfantitok 0:8f3710bfd298 71 values_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
irfantitok 0:8f3710bfd298 72 offset += sizeof(this->values_length);
irfantitok 0:8f3710bfd298 73 if(values_lengthT > values_length)
irfantitok 0:8f3710bfd298 74 this->values = (float*)realloc(this->values, values_lengthT * sizeof(float));
irfantitok 0:8f3710bfd298 75 values_length = values_lengthT;
irfantitok 0:8f3710bfd298 76 for( uint32_t i = 0; i < values_length; i++){
irfantitok 0:8f3710bfd298 77 union {
irfantitok 0:8f3710bfd298 78 float real;
irfantitok 0:8f3710bfd298 79 uint32_t base;
irfantitok 0:8f3710bfd298 80 } u_st_values;
irfantitok 0:8f3710bfd298 81 u_st_values.base = 0;
irfantitok 0:8f3710bfd298 82 u_st_values.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
irfantitok 0:8f3710bfd298 83 u_st_values.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
irfantitok 0:8f3710bfd298 84 u_st_values.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
irfantitok 0:8f3710bfd298 85 u_st_values.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
irfantitok 0:8f3710bfd298 86 this->st_values = u_st_values.real;
irfantitok 0:8f3710bfd298 87 offset += sizeof(this->st_values);
irfantitok 0:8f3710bfd298 88 memcpy( &(this->values[i]), &(this->st_values), sizeof(float));
irfantitok 0:8f3710bfd298 89 }
irfantitok 0:8f3710bfd298 90 return offset;
irfantitok 0:8f3710bfd298 91 }
irfantitok 0:8f3710bfd298 92
irfantitok 0:8f3710bfd298 93 const char * getType(){ return "sensor_msgs/ChannelFloat32"; };
irfantitok 0:8f3710bfd298 94 const char * getMD5(){ return "3d40139cdd33dfedcb71ffeeeb42ae7f"; };
irfantitok 0:8f3710bfd298 95
irfantitok 0:8f3710bfd298 96 };
irfantitok 0:8f3710bfd298 97
irfantitok 0:8f3710bfd298 98 }
irfantitok 0:8f3710bfd298 99 #endif