This program is porting rosserial_arduino for mbed http://www.ros.org/wiki/rosserial_arduino This program supported the revision of 169 of rosserial.

Dependencies:  

Dependents:   rosserial_mbed robot_S2

Committer:
nucho
Date:
Wed Feb 29 23:00:21 2012 +0000
Revision:
4:684f39d0c346
Parent:
3:1cf99502f396

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nucho 3:1cf99502f396 1 #ifndef _ROS_sensor_msgs_CompressedImage_h
nucho 3:1cf99502f396 2 #define _ROS_sensor_msgs_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 3:1cf99502f396 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 3:1cf99502f396 18 uint8_t data_length;
nucho 3:1cf99502f396 19 uint8_t st_data;
nucho 3:1cf99502f396 20 uint8_t * data;
nucho 0:77afd7560544 21
nucho 3:1cf99502f396 22 virtual int serialize(unsigned char *outbuffer) const
nucho 0:77afd7560544 23 {
nucho 0:77afd7560544 24 int offset = 0;
nucho 0:77afd7560544 25 offset += this->header.serialize(outbuffer + offset);
nucho 3:1cf99502f396 26 uint32_t * length_format = (uint32_t *)(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 3:1cf99502f396 35 for( uint8_t i = 0; i < data_length; i++){
nucho 3:1cf99502f396 36 *(outbuffer + offset + 0) = (this->data[i] >> (8 * 0)) & 0xFF;
nucho 0:77afd7560544 37 offset += sizeof(this->data[i]);
nucho 0:77afd7560544 38 }
nucho 0:77afd7560544 39 return offset;
nucho 0:77afd7560544 40 }
nucho 0:77afd7560544 41
nucho 0:77afd7560544 42 virtual int deserialize(unsigned char *inbuffer)
nucho 0:77afd7560544 43 {
nucho 0:77afd7560544 44 int offset = 0;
nucho 0:77afd7560544 45 offset += this->header.deserialize(inbuffer + offset);
nucho 0:77afd7560544 46 uint32_t length_format = *(uint32_t *)(inbuffer + offset);
nucho 0:77afd7560544 47 offset += 4;
nucho 0:77afd7560544 48 for(unsigned int k= offset; k< offset+length_format; ++k){
nucho 0:77afd7560544 49 inbuffer[k-1]=inbuffer[k];
nucho 3:1cf99502f396 50 }
nucho 0:77afd7560544 51 inbuffer[offset+length_format-1]=0;
nucho 0:77afd7560544 52 this->format = (char *)(inbuffer + offset-1);
nucho 0:77afd7560544 53 offset += length_format;
nucho 3:1cf99502f396 54 uint8_t data_lengthT = *(inbuffer + offset++);
nucho 0:77afd7560544 55 if(data_lengthT > data_length)
nucho 3:1cf99502f396 56 this->data = (uint8_t*)realloc(this->data, data_lengthT * sizeof(uint8_t));
nucho 0:77afd7560544 57 offset += 3;
nucho 0:77afd7560544 58 data_length = data_lengthT;
nucho 3:1cf99502f396 59 for( uint8_t i = 0; i < data_length; i++){
nucho 3:1cf99502f396 60 this->st_data |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0);
nucho 0:77afd7560544 61 offset += sizeof(this->st_data);
nucho 3:1cf99502f396 62 memcpy( &(this->data[i]), &(this->st_data), sizeof(uint8_t));
nucho 0:77afd7560544 63 }
nucho 0:77afd7560544 64 return offset;
nucho 0:77afd7560544 65 }
nucho 0:77afd7560544 66
nucho 3:1cf99502f396 67 virtual const char * getType(){ return "sensor_msgs/CompressedImage"; };
nucho 3:1cf99502f396 68 virtual const char * getMD5(){ return "8f7a12909da2c9d3332d540a0977563f"; };
nucho 0:77afd7560544 69
nucho 0:77afd7560544 70 };
nucho 0:77afd7560544 71
nucho 0:77afd7560544 72 }
nucho 0:77afd7560544 73 #endif