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