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_ChannelFloat32_h
nucho 3:1cf99502f396 2 #define _ROS_sensor_msgs_ChannelFloat32_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
nucho 0:77afd7560544 9 namespace sensor_msgs
nucho 0:77afd7560544 10 {
nucho 0:77afd7560544 11
nucho 0:77afd7560544 12 class ChannelFloat32 : public ros::Msg
nucho 0:77afd7560544 13 {
nucho 0:77afd7560544 14 public:
nucho 0:77afd7560544 15 char * name;
nucho 3:1cf99502f396 16 uint8_t values_length;
nucho 0:77afd7560544 17 float st_values;
nucho 0:77afd7560544 18 float * values;
nucho 0:77afd7560544 19
nucho 3:1cf99502f396 20 virtual int serialize(unsigned char *outbuffer) const
nucho 0:77afd7560544 21 {
nucho 0:77afd7560544 22 int offset = 0;
nucho 3:1cf99502f396 23 uint32_t * length_name = (uint32_t *)(outbuffer + offset);
nucho 0:77afd7560544 24 *length_name = strlen( (const char*) this->name);
nucho 0:77afd7560544 25 offset += 4;
nucho 0:77afd7560544 26 memcpy(outbuffer + offset, this->name, *length_name);
nucho 0:77afd7560544 27 offset += *length_name;
nucho 0:77afd7560544 28 *(outbuffer + offset++) = values_length;
nucho 0:77afd7560544 29 *(outbuffer + offset++) = 0;
nucho 0:77afd7560544 30 *(outbuffer + offset++) = 0;
nucho 0:77afd7560544 31 *(outbuffer + offset++) = 0;
nucho 3:1cf99502f396 32 for( uint8_t i = 0; i < values_length; i++){
nucho 0:77afd7560544 33 union {
nucho 0:77afd7560544 34 float real;
nucho 3:1cf99502f396 35 uint32_t base;
nucho 0:77afd7560544 36 } u_valuesi;
nucho 0:77afd7560544 37 u_valuesi.real = this->values[i];
nucho 0:77afd7560544 38 *(outbuffer + offset + 0) = (u_valuesi.base >> (8 * 0)) & 0xFF;
nucho 0:77afd7560544 39 *(outbuffer + offset + 1) = (u_valuesi.base >> (8 * 1)) & 0xFF;
nucho 0:77afd7560544 40 *(outbuffer + offset + 2) = (u_valuesi.base >> (8 * 2)) & 0xFF;
nucho 0:77afd7560544 41 *(outbuffer + offset + 3) = (u_valuesi.base >> (8 * 3)) & 0xFF;
nucho 0:77afd7560544 42 offset += sizeof(this->values[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 uint32_t length_name = *(uint32_t *)(inbuffer + offset);
nucho 0:77afd7560544 51 offset += 4;
nucho 0:77afd7560544 52 for(unsigned int k= offset; k< offset+length_name; ++k){
nucho 0:77afd7560544 53 inbuffer[k-1]=inbuffer[k];
nucho 3:1cf99502f396 54 }
nucho 0:77afd7560544 55 inbuffer[offset+length_name-1]=0;
nucho 0:77afd7560544 56 this->name = (char *)(inbuffer + offset-1);
nucho 0:77afd7560544 57 offset += length_name;
nucho 3:1cf99502f396 58 uint8_t values_lengthT = *(inbuffer + offset++);
nucho 0:77afd7560544 59 if(values_lengthT > values_length)
nucho 0:77afd7560544 60 this->values = (float*)realloc(this->values, values_lengthT * sizeof(float));
nucho 0:77afd7560544 61 offset += 3;
nucho 0:77afd7560544 62 values_length = values_lengthT;
nucho 3:1cf99502f396 63 for( uint8_t i = 0; i < values_length; i++){
nucho 0:77afd7560544 64 union {
nucho 0:77afd7560544 65 float real;
nucho 3:1cf99502f396 66 uint32_t base;
nucho 0:77afd7560544 67 } u_st_values;
nucho 0:77afd7560544 68 u_st_values.base = 0;
nucho 3:1cf99502f396 69 u_st_values.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
nucho 3:1cf99502f396 70 u_st_values.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
nucho 3:1cf99502f396 71 u_st_values.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
nucho 3:1cf99502f396 72 u_st_values.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
nucho 0:77afd7560544 73 this->st_values = u_st_values.real;
nucho 0:77afd7560544 74 offset += sizeof(this->st_values);
nucho 0:77afd7560544 75 memcpy( &(this->values[i]), &(this->st_values), sizeof(float));
nucho 0:77afd7560544 76 }
nucho 0:77afd7560544 77 return offset;
nucho 0:77afd7560544 78 }
nucho 0:77afd7560544 79
nucho 3:1cf99502f396 80 virtual const char * getType(){ return "sensor_msgs/ChannelFloat32"; };
nucho 3:1cf99502f396 81 virtual const char * getMD5(){ return "3d40139cdd33dfedcb71ffeeeb42ae7f"; };
nucho 0:77afd7560544 82
nucho 0:77afd7560544 83 };
nucho 0:77afd7560544 84
nucho 0:77afd7560544 85 }
nucho 0:77afd7560544 86 #endif