rosserial for Hydro

Dependencies:   MODSERIAL

Fork of rosserial_mbed_lib by nucho

Committer:
nucho
Date:
Fri Aug 19 09:06:30 2011 +0000
Revision:
0:77afd7560544
Child:
3:1cf99502f396

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nucho 0:77afd7560544 1 #ifndef ros_CompressedImage_h
nucho 0:77afd7560544 2 #define ros_CompressedImage_h
nucho 0:77afd7560544 3
nucho 0:77afd7560544 4 #include <stdint.h>
nucho 0:77afd7560544 5 #include <string.h>
nucho 0:77afd7560544 6 #include <stdlib.h>
nucho 0:77afd7560544 7 #include "../ros/msg.h"
nucho 0:77afd7560544 8 #include "std_msgs/Header.h"
nucho 0:77afd7560544 9
nucho 0:77afd7560544 10 namespace sensor_msgs
nucho 0:77afd7560544 11 {
nucho 0:77afd7560544 12
nucho 0:77afd7560544 13 class CompressedImage : public ros::Msg
nucho 0:77afd7560544 14 {
nucho 0:77afd7560544 15 public:
nucho 0:77afd7560544 16 std_msgs::Header header;
nucho 0:77afd7560544 17 char * format;
nucho 0:77afd7560544 18 unsigned char data_length;
nucho 0:77afd7560544 19 unsigned char st_data;
nucho 0:77afd7560544 20 unsigned char * data;
nucho 0:77afd7560544 21
nucho 0:77afd7560544 22 virtual int serialize(unsigned char *outbuffer)
nucho 0:77afd7560544 23 {
nucho 0:77afd7560544 24 int offset = 0;
nucho 0:77afd7560544 25 offset += this->header.serialize(outbuffer + offset);
nucho 0:77afd7560544 26 long * length_format = (long *)(outbuffer + offset);
nucho 0:77afd7560544 27 *length_format = strlen( (const char*) this->format);
nucho 0:77afd7560544 28 offset += 4;
nucho 0:77afd7560544 29 memcpy(outbuffer + offset, this->format, *length_format);
nucho 0:77afd7560544 30 offset += *length_format;
nucho 0:77afd7560544 31 *(outbuffer + offset++) = data_length;
nucho 0:77afd7560544 32 *(outbuffer + offset++) = 0;
nucho 0:77afd7560544 33 *(outbuffer + offset++) = 0;
nucho 0:77afd7560544 34 *(outbuffer + offset++) = 0;
nucho 0:77afd7560544 35 for( unsigned char i = 0; i < data_length; i++){
nucho 0:77afd7560544 36 union {
nucho 0:77afd7560544 37 unsigned char real;
nucho 0:77afd7560544 38 unsigned char base;
nucho 0:77afd7560544 39 } u_datai;
nucho 0:77afd7560544 40 u_datai.real = this->data[i];
nucho 0:77afd7560544 41 *(outbuffer + offset + 0) = (u_datai.base >> (8 * 0)) & 0xFF;
nucho 0:77afd7560544 42 offset += sizeof(this->data[i]);
nucho 0:77afd7560544 43 }
nucho 0:77afd7560544 44 return offset;
nucho 0:77afd7560544 45 }
nucho 0:77afd7560544 46
nucho 0:77afd7560544 47 virtual int deserialize(unsigned char *inbuffer)
nucho 0:77afd7560544 48 {
nucho 0:77afd7560544 49 int offset = 0;
nucho 0:77afd7560544 50 offset += this->header.deserialize(inbuffer + offset);
nucho 0:77afd7560544 51 uint32_t length_format = *(uint32_t *)(inbuffer + offset);
nucho 0:77afd7560544 52 offset += 4;
nucho 0:77afd7560544 53 for(unsigned int k= offset; k< offset+length_format; ++k){
nucho 0:77afd7560544 54 inbuffer[k-1]=inbuffer[k];
nucho 0:77afd7560544 55 }
nucho 0:77afd7560544 56 inbuffer[offset+length_format-1]=0;
nucho 0:77afd7560544 57 this->format = (char *)(inbuffer + offset-1);
nucho 0:77afd7560544 58 offset += length_format;
nucho 0:77afd7560544 59 unsigned char data_lengthT = *(inbuffer + offset++);
nucho 0:77afd7560544 60 if(data_lengthT > data_length)
nucho 0:77afd7560544 61 this->data = (unsigned char*)realloc(this->data, data_lengthT * sizeof(unsigned char));
nucho 0:77afd7560544 62 offset += 3;
nucho 0:77afd7560544 63 data_length = data_lengthT;
nucho 0:77afd7560544 64 for( unsigned char i = 0; i < data_length; i++){
nucho 0:77afd7560544 65 union {
nucho 0:77afd7560544 66 unsigned char real;
nucho 0:77afd7560544 67 unsigned char base;
nucho 0:77afd7560544 68 } u_st_data;
nucho 0:77afd7560544 69 u_st_data.base = 0;
nucho 0:77afd7560544 70 u_st_data.base |= ((typeof(u_st_data.base)) (*(inbuffer + offset + 0))) << (8 * 0);
nucho 0:77afd7560544 71 this->st_data = u_st_data.real;
nucho 0:77afd7560544 72 offset += sizeof(this->st_data);
nucho 0:77afd7560544 73 memcpy( &(this->data[i]), &(this->st_data), sizeof(unsigned char));
nucho 0:77afd7560544 74 }
nucho 0:77afd7560544 75 return offset;
nucho 0:77afd7560544 76 }
nucho 0:77afd7560544 77
nucho 0:77afd7560544 78 virtual const char * getType(){ return "sensor_msgs/CompressedImage"; };
nucho 0:77afd7560544 79
nucho 0:77afd7560544 80 };
nucho 0:77afd7560544 81
nucho 0:77afd7560544 82 }
nucho 0:77afd7560544 83 #endif