capstone_finish
Dependencies: BufferedSerial motor_sn7544
sensor_msgs/CompressedImage.h@10:ca4e4062701a, 2019-11-26 (annotated)
- Committer:
- Jeonghoon
- Date:
- Tue Nov 26 15:30:27 2019 +0000
- Revision:
- 10:ca4e4062701a
- Parent:
- 3:2a3664dc6634
capstone finish
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jeonghoon | 3:2a3664dc6634 | 1 | #ifndef _ROS_sensor_msgs_CompressedImage_h |
Jeonghoon | 3:2a3664dc6634 | 2 | #define _ROS_sensor_msgs_CompressedImage_h |
Jeonghoon | 3:2a3664dc6634 | 3 | |
Jeonghoon | 3:2a3664dc6634 | 4 | #include <stdint.h> |
Jeonghoon | 3:2a3664dc6634 | 5 | #include <string.h> |
Jeonghoon | 3:2a3664dc6634 | 6 | #include <stdlib.h> |
Jeonghoon | 3:2a3664dc6634 | 7 | #include "ros/msg.h" |
Jeonghoon | 3:2a3664dc6634 | 8 | #include "std_msgs/Header.h" |
Jeonghoon | 3:2a3664dc6634 | 9 | |
Jeonghoon | 3:2a3664dc6634 | 10 | namespace sensor_msgs |
Jeonghoon | 3:2a3664dc6634 | 11 | { |
Jeonghoon | 3:2a3664dc6634 | 12 | |
Jeonghoon | 3:2a3664dc6634 | 13 | class CompressedImage : public ros::Msg |
Jeonghoon | 3:2a3664dc6634 | 14 | { |
Jeonghoon | 3:2a3664dc6634 | 15 | public: |
Jeonghoon | 3:2a3664dc6634 | 16 | typedef std_msgs::Header _header_type; |
Jeonghoon | 3:2a3664dc6634 | 17 | _header_type header; |
Jeonghoon | 3:2a3664dc6634 | 18 | typedef const char* _format_type; |
Jeonghoon | 3:2a3664dc6634 | 19 | _format_type format; |
Jeonghoon | 3:2a3664dc6634 | 20 | uint32_t data_length; |
Jeonghoon | 3:2a3664dc6634 | 21 | typedef uint8_t _data_type; |
Jeonghoon | 3:2a3664dc6634 | 22 | _data_type st_data; |
Jeonghoon | 3:2a3664dc6634 | 23 | _data_type * data; |
Jeonghoon | 3:2a3664dc6634 | 24 | |
Jeonghoon | 3:2a3664dc6634 | 25 | CompressedImage(): |
Jeonghoon | 3:2a3664dc6634 | 26 | header(), |
Jeonghoon | 3:2a3664dc6634 | 27 | format(""), |
Jeonghoon | 3:2a3664dc6634 | 28 | data_length(0), data(NULL) |
Jeonghoon | 3:2a3664dc6634 | 29 | { |
Jeonghoon | 3:2a3664dc6634 | 30 | } |
Jeonghoon | 3:2a3664dc6634 | 31 | |
Jeonghoon | 3:2a3664dc6634 | 32 | virtual int serialize(unsigned char *outbuffer) const |
Jeonghoon | 3:2a3664dc6634 | 33 | { |
Jeonghoon | 3:2a3664dc6634 | 34 | int offset = 0; |
Jeonghoon | 3:2a3664dc6634 | 35 | offset += this->header.serialize(outbuffer + offset); |
Jeonghoon | 3:2a3664dc6634 | 36 | uint32_t length_format = strlen(this->format); |
Jeonghoon | 3:2a3664dc6634 | 37 | varToArr(outbuffer + offset, length_format); |
Jeonghoon | 3:2a3664dc6634 | 38 | offset += 4; |
Jeonghoon | 3:2a3664dc6634 | 39 | memcpy(outbuffer + offset, this->format, length_format); |
Jeonghoon | 3:2a3664dc6634 | 40 | offset += length_format; |
Jeonghoon | 3:2a3664dc6634 | 41 | *(outbuffer + offset + 0) = (this->data_length >> (8 * 0)) & 0xFF; |
Jeonghoon | 3:2a3664dc6634 | 42 | *(outbuffer + offset + 1) = (this->data_length >> (8 * 1)) & 0xFF; |
Jeonghoon | 3:2a3664dc6634 | 43 | *(outbuffer + offset + 2) = (this->data_length >> (8 * 2)) & 0xFF; |
Jeonghoon | 3:2a3664dc6634 | 44 | *(outbuffer + offset + 3) = (this->data_length >> (8 * 3)) & 0xFF; |
Jeonghoon | 3:2a3664dc6634 | 45 | offset += sizeof(this->data_length); |
Jeonghoon | 3:2a3664dc6634 | 46 | for( uint32_t i = 0; i < data_length; i++){ |
Jeonghoon | 3:2a3664dc6634 | 47 | *(outbuffer + offset + 0) = (this->data[i] >> (8 * 0)) & 0xFF; |
Jeonghoon | 3:2a3664dc6634 | 48 | offset += sizeof(this->data[i]); |
Jeonghoon | 3:2a3664dc6634 | 49 | } |
Jeonghoon | 3:2a3664dc6634 | 50 | return offset; |
Jeonghoon | 3:2a3664dc6634 | 51 | } |
Jeonghoon | 3:2a3664dc6634 | 52 | |
Jeonghoon | 3:2a3664dc6634 | 53 | virtual int deserialize(unsigned char *inbuffer) |
Jeonghoon | 3:2a3664dc6634 | 54 | { |
Jeonghoon | 3:2a3664dc6634 | 55 | int offset = 0; |
Jeonghoon | 3:2a3664dc6634 | 56 | offset += this->header.deserialize(inbuffer + offset); |
Jeonghoon | 3:2a3664dc6634 | 57 | uint32_t length_format; |
Jeonghoon | 3:2a3664dc6634 | 58 | arrToVar(length_format, (inbuffer + offset)); |
Jeonghoon | 3:2a3664dc6634 | 59 | offset += 4; |
Jeonghoon | 3:2a3664dc6634 | 60 | for(unsigned int k= offset; k< offset+length_format; ++k){ |
Jeonghoon | 3:2a3664dc6634 | 61 | inbuffer[k-1]=inbuffer[k]; |
Jeonghoon | 3:2a3664dc6634 | 62 | } |
Jeonghoon | 3:2a3664dc6634 | 63 | inbuffer[offset+length_format-1]=0; |
Jeonghoon | 3:2a3664dc6634 | 64 | this->format = (char *)(inbuffer + offset-1); |
Jeonghoon | 3:2a3664dc6634 | 65 | offset += length_format; |
Jeonghoon | 3:2a3664dc6634 | 66 | uint32_t data_lengthT = ((uint32_t) (*(inbuffer + offset))); |
Jeonghoon | 3:2a3664dc6634 | 67 | data_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); |
Jeonghoon | 3:2a3664dc6634 | 68 | data_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); |
Jeonghoon | 3:2a3664dc6634 | 69 | data_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); |
Jeonghoon | 3:2a3664dc6634 | 70 | offset += sizeof(this->data_length); |
Jeonghoon | 3:2a3664dc6634 | 71 | if(data_lengthT > data_length) |
Jeonghoon | 3:2a3664dc6634 | 72 | this->data = (uint8_t*)realloc(this->data, data_lengthT * sizeof(uint8_t)); |
Jeonghoon | 3:2a3664dc6634 | 73 | data_length = data_lengthT; |
Jeonghoon | 3:2a3664dc6634 | 74 | for( uint32_t i = 0; i < data_length; i++){ |
Jeonghoon | 3:2a3664dc6634 | 75 | this->st_data = ((uint8_t) (*(inbuffer + offset))); |
Jeonghoon | 3:2a3664dc6634 | 76 | offset += sizeof(this->st_data); |
Jeonghoon | 3:2a3664dc6634 | 77 | memcpy( &(this->data[i]), &(this->st_data), sizeof(uint8_t)); |
Jeonghoon | 3:2a3664dc6634 | 78 | } |
Jeonghoon | 3:2a3664dc6634 | 79 | return offset; |
Jeonghoon | 3:2a3664dc6634 | 80 | } |
Jeonghoon | 3:2a3664dc6634 | 81 | |
Jeonghoon | 3:2a3664dc6634 | 82 | const char * getType(){ return "sensor_msgs/CompressedImage"; }; |
Jeonghoon | 3:2a3664dc6634 | 83 | const char * getMD5(){ return "8f7a12909da2c9d3332d540a0977563f"; }; |
Jeonghoon | 3:2a3664dc6634 | 84 | |
Jeonghoon | 3:2a3664dc6634 | 85 | }; |
Jeonghoon | 3:2a3664dc6634 | 86 | |
Jeonghoon | 3:2a3664dc6634 | 87 | } |
Jeonghoon | 3:2a3664dc6634 | 88 | #endif |