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:
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_String_h
nucho 0:77afd7560544 2 #define ros_String_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"mbed.h"
nucho 0:77afd7560544 9
nucho 0:77afd7560544 10
nucho 0:77afd7560544 11 namespace std_msgs
nucho 0:77afd7560544 12 {
nucho 0:77afd7560544 13
nucho 0:77afd7560544 14 class String : public ros::Msg
nucho 0:77afd7560544 15 {
nucho 0:77afd7560544 16 public:
nucho 0:77afd7560544 17 char * data;
nucho 0:77afd7560544 18
nucho 0:77afd7560544 19 virtual int serialize(unsigned char *outbuffer)
nucho 0:77afd7560544 20 {
nucho 0:77afd7560544 21 int offset = 0;
nucho 0:77afd7560544 22 long * length_data = (long *)(outbuffer + offset);
nucho 0:77afd7560544 23 *length_data = strlen( (const char*) this->data);
nucho 0:77afd7560544 24 offset += 4;
nucho 0:77afd7560544 25 memcpy(outbuffer + offset, this->data, *length_data);
nucho 0:77afd7560544 26 offset += *length_data;
nucho 0:77afd7560544 27 return offset;
nucho 0:77afd7560544 28 }
nucho 0:77afd7560544 29
nucho 0:77afd7560544 30 virtual int deserialize(unsigned char *inbuffer)
nucho 0:77afd7560544 31 {
nucho 0:77afd7560544 32 int offset = 0;
nucho 0:77afd7560544 33 uint32_t length_data = *(uint32_t *)(inbuffer + offset);
nucho 0:77afd7560544 34 offset += 4;
nucho 0:77afd7560544 35 for(unsigned int k= offset; k< offset+length_data; ++k){
nucho 0:77afd7560544 36 inbuffer[k-1]=inbuffer[k];
nucho 0:77afd7560544 37 }
nucho 0:77afd7560544 38 inbuffer[offset+length_data-1]=0;
nucho 0:77afd7560544 39 this->data = (char *)(inbuffer + offset-1);
nucho 0:77afd7560544 40 offset += length_data;
nucho 0:77afd7560544 41 return offset;
nucho 0:77afd7560544 42 }
nucho 0:77afd7560544 43
nucho 0:77afd7560544 44 virtual const char * getType(){ return "std_msgs/String"; };
nucho 0:77afd7560544 45
nucho 0:77afd7560544 46 };
nucho 0:77afd7560544 47
nucho 0:77afd7560544 48 }
nucho 0:77afd7560544 49 #endif