ROS Serial library for Mbed platforms for ROS Indigo Igloo. Check http://wiki.ros.org/rosserial_mbed/ for more information
Dependents: rosserial_mbed_hello_world_publisher rtos_base_control rosserial_mbed_F64MA ROS-RTOS ... more
Image.h
00001 #ifndef _ROS_sensor_msgs_Image_h 00002 #define _ROS_sensor_msgs_Image_h 00003 00004 #include <stdint.h> 00005 #include <string.h> 00006 #include <stdlib.h> 00007 #include "ros/msg.h" 00008 #include "std_msgs/Header.h" 00009 00010 namespace sensor_msgs 00011 { 00012 00013 class Image : public ros::Msg 00014 { 00015 public: 00016 std_msgs::Header header; 00017 uint32_t height; 00018 uint32_t width; 00019 const char* encoding; 00020 uint8_t is_bigendian; 00021 uint32_t step; 00022 uint8_t data_length; 00023 uint8_t st_data; 00024 uint8_t * data; 00025 00026 Image(): 00027 header(), 00028 height(0), 00029 width(0), 00030 encoding(""), 00031 is_bigendian(0), 00032 step(0), 00033 data_length(0), data(NULL) 00034 { 00035 } 00036 00037 virtual int serialize(unsigned char *outbuffer) const 00038 { 00039 int offset = 0; 00040 offset += this->header.serialize(outbuffer + offset); 00041 *(outbuffer + offset + 0) = (this->height >> (8 * 0)) & 0xFF; 00042 *(outbuffer + offset + 1) = (this->height >> (8 * 1)) & 0xFF; 00043 *(outbuffer + offset + 2) = (this->height >> (8 * 2)) & 0xFF; 00044 *(outbuffer + offset + 3) = (this->height >> (8 * 3)) & 0xFF; 00045 offset += sizeof(this->height); 00046 *(outbuffer + offset + 0) = (this->width >> (8 * 0)) & 0xFF; 00047 *(outbuffer + offset + 1) = (this->width >> (8 * 1)) & 0xFF; 00048 *(outbuffer + offset + 2) = (this->width >> (8 * 2)) & 0xFF; 00049 *(outbuffer + offset + 3) = (this->width >> (8 * 3)) & 0xFF; 00050 offset += sizeof(this->width); 00051 uint32_t length_encoding = strlen(this->encoding); 00052 memcpy(outbuffer + offset, &length_encoding, sizeof(uint32_t)); 00053 offset += 4; 00054 memcpy(outbuffer + offset, this->encoding, length_encoding); 00055 offset += length_encoding; 00056 *(outbuffer + offset + 0) = (this->is_bigendian >> (8 * 0)) & 0xFF; 00057 offset += sizeof(this->is_bigendian); 00058 *(outbuffer + offset + 0) = (this->step >> (8 * 0)) & 0xFF; 00059 *(outbuffer + offset + 1) = (this->step >> (8 * 1)) & 0xFF; 00060 *(outbuffer + offset + 2) = (this->step >> (8 * 2)) & 0xFF; 00061 *(outbuffer + offset + 3) = (this->step >> (8 * 3)) & 0xFF; 00062 offset += sizeof(this->step); 00063 *(outbuffer + offset++) = data_length; 00064 *(outbuffer + offset++) = 0; 00065 *(outbuffer + offset++) = 0; 00066 *(outbuffer + offset++) = 0; 00067 for( uint8_t i = 0; i < data_length; i++){ 00068 *(outbuffer + offset + 0) = (this->data[i] >> (8 * 0)) & 0xFF; 00069 offset += sizeof(this->data[i]); 00070 } 00071 return offset; 00072 } 00073 00074 virtual int deserialize(unsigned char *inbuffer) 00075 { 00076 int offset = 0; 00077 offset += this->header.deserialize(inbuffer + offset); 00078 this->height = ((uint32_t) (*(inbuffer + offset))); 00079 this->height |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 00080 this->height |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 00081 this->height |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 00082 offset += sizeof(this->height); 00083 this->width = ((uint32_t) (*(inbuffer + offset))); 00084 this->width |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 00085 this->width |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 00086 this->width |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 00087 offset += sizeof(this->width); 00088 uint32_t length_encoding; 00089 memcpy(&length_encoding, (inbuffer + offset), sizeof(uint32_t)); 00090 offset += 4; 00091 for(unsigned int k= offset; k< offset+length_encoding; ++k){ 00092 inbuffer[k-1]=inbuffer[k]; 00093 } 00094 inbuffer[offset+length_encoding-1]=0; 00095 this->encoding = (char *)(inbuffer + offset-1); 00096 offset += length_encoding; 00097 this->is_bigendian = ((uint8_t) (*(inbuffer + offset))); 00098 offset += sizeof(this->is_bigendian); 00099 this->step = ((uint32_t) (*(inbuffer + offset))); 00100 this->step |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 00101 this->step |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 00102 this->step |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 00103 offset += sizeof(this->step); 00104 uint8_t data_lengthT = *(inbuffer + offset++); 00105 if(data_lengthT > data_length) 00106 this->data = (uint8_t*)realloc(this->data, data_lengthT * sizeof(uint8_t)); 00107 offset += 3; 00108 data_length = data_lengthT; 00109 for( uint8_t i = 0; i < data_length; i++){ 00110 this->st_data = ((uint8_t) (*(inbuffer + offset))); 00111 offset += sizeof(this->st_data); 00112 memcpy( &(this->data[i]), &(this->st_data), sizeof(uint8_t)); 00113 } 00114 return offset; 00115 } 00116 00117 const char * getType(){ return "sensor_msgs/Image"; }; 00118 const char * getMD5(){ return "060021388200f6f0f447d0fcd9c64743"; }; 00119 00120 }; 00121 00122 } 00123 #endif
Generated on Tue Jul 12 2022 18:39:39 by 1.7.2