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:
1:ff0ec969dad1

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nucho 0:77afd7560544 1 #ifndef ros_Header_h
nucho 0:77afd7560544 2 #define ros_Header_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 "ros/time.h"
nucho 0:77afd7560544 9
nucho 0:77afd7560544 10 namespace std_msgs
nucho 0:77afd7560544 11 {
nucho 0:77afd7560544 12
nucho 0:77afd7560544 13 class Header : public ros::Msg
nucho 0:77afd7560544 14 {
nucho 0:77afd7560544 15 public:
nucho 0:77afd7560544 16 unsigned long seq;
nucho 0:77afd7560544 17 ros::Time stamp;
nucho 0:77afd7560544 18 char * frame_id;
nucho 0:77afd7560544 19
nucho 0:77afd7560544 20 virtual int serialize(unsigned char *outbuffer)
nucho 0:77afd7560544 21 {
nucho 0:77afd7560544 22 int offset = 0;
nucho 0:77afd7560544 23 union {
nucho 0:77afd7560544 24 unsigned long real;
nucho 0:77afd7560544 25 unsigned long base;
nucho 0:77afd7560544 26 } u_seq;
nucho 0:77afd7560544 27 u_seq.real = this->seq;
nucho 0:77afd7560544 28 *(outbuffer + offset + 0) = (u_seq.base >> (8 * 0)) & 0xFF;
nucho 0:77afd7560544 29 *(outbuffer + offset + 1) = (u_seq.base >> (8 * 1)) & 0xFF;
nucho 0:77afd7560544 30 *(outbuffer + offset + 2) = (u_seq.base >> (8 * 2)) & 0xFF;
nucho 0:77afd7560544 31 *(outbuffer + offset + 3) = (u_seq.base >> (8 * 3)) & 0xFF;
nucho 0:77afd7560544 32 offset += sizeof(this->seq);
nucho 0:77afd7560544 33 union {
nucho 0:77afd7560544 34 unsigned long real;
nucho 0:77afd7560544 35 unsigned long base;
nucho 0:77afd7560544 36 } u_sec;
nucho 0:77afd7560544 37 u_sec.real = this->stamp.sec;
nucho 0:77afd7560544 38 *(outbuffer + offset + 0) = (u_sec.base >> (8 * 0)) & 0xFF;
nucho 0:77afd7560544 39 *(outbuffer + offset + 1) = (u_sec.base >> (8 * 1)) & 0xFF;
nucho 0:77afd7560544 40 *(outbuffer + offset + 2) = (u_sec.base >> (8 * 2)) & 0xFF;
nucho 0:77afd7560544 41 *(outbuffer + offset + 3) = (u_sec.base >> (8 * 3)) & 0xFF;
nucho 0:77afd7560544 42 offset += sizeof(this->stamp.sec);
nucho 0:77afd7560544 43 union {
nucho 0:77afd7560544 44 unsigned long real;
nucho 0:77afd7560544 45 unsigned long base;
nucho 0:77afd7560544 46 } u_nsec;
nucho 0:77afd7560544 47 u_nsec.real = this->stamp.nsec;
nucho 0:77afd7560544 48 *(outbuffer + offset + 0) = (u_nsec.base >> (8 * 0)) & 0xFF;
nucho 0:77afd7560544 49 *(outbuffer + offset + 1) = (u_nsec.base >> (8 * 1)) & 0xFF;
nucho 0:77afd7560544 50 *(outbuffer + offset + 2) = (u_nsec.base >> (8 * 2)) & 0xFF;
nucho 0:77afd7560544 51 *(outbuffer + offset + 3) = (u_nsec.base >> (8 * 3)) & 0xFF;
nucho 0:77afd7560544 52 offset += sizeof(this->stamp.nsec);
nucho 0:77afd7560544 53 long * length_frame_id = (long *)(outbuffer + offset);
nucho 0:77afd7560544 54 *length_frame_id = strlen( (const char*) this->frame_id);
nucho 0:77afd7560544 55 offset += 4;
nucho 0:77afd7560544 56 memcpy(outbuffer + offset, this->frame_id, *length_frame_id);
nucho 0:77afd7560544 57 offset += *length_frame_id;
nucho 0:77afd7560544 58 return offset;
nucho 0:77afd7560544 59 }
nucho 0:77afd7560544 60
nucho 0:77afd7560544 61 virtual int deserialize(unsigned char *inbuffer)
nucho 0:77afd7560544 62 {
nucho 0:77afd7560544 63 int offset = 0;
nucho 0:77afd7560544 64 union {
nucho 0:77afd7560544 65 unsigned long real;
nucho 0:77afd7560544 66 unsigned long base;
nucho 0:77afd7560544 67 } u_seq;
nucho 0:77afd7560544 68 u_seq.base = 0;
nucho 0:77afd7560544 69 u_seq.base |= ((typeof(u_seq.base)) (*(inbuffer + offset + 0))) << (8 * 0);
nucho 0:77afd7560544 70 u_seq.base |= ((typeof(u_seq.base)) (*(inbuffer + offset + 1))) << (8 * 1);
nucho 0:77afd7560544 71 u_seq.base |= ((typeof(u_seq.base)) (*(inbuffer + offset + 2))) << (8 * 2);
nucho 0:77afd7560544 72 u_seq.base |= ((typeof(u_seq.base)) (*(inbuffer + offset + 3))) << (8 * 3);
nucho 0:77afd7560544 73 this->seq = u_seq.real;
nucho 0:77afd7560544 74 offset += sizeof(this->seq);
nucho 0:77afd7560544 75 union {
nucho 0:77afd7560544 76 unsigned long real;
nucho 0:77afd7560544 77 unsigned long base;
nucho 0:77afd7560544 78 } u_sec;
nucho 0:77afd7560544 79 u_sec.base = 0;
nucho 0:77afd7560544 80 u_sec.base |= ((typeof(u_sec.base)) (*(inbuffer + offset + 0))) << (8 * 0);
nucho 0:77afd7560544 81 u_sec.base |= ((typeof(u_sec.base)) (*(inbuffer + offset + 1))) << (8 * 1);
nucho 0:77afd7560544 82 u_sec.base |= ((typeof(u_sec.base)) (*(inbuffer + offset + 2))) << (8 * 2);
nucho 0:77afd7560544 83 u_sec.base |= ((typeof(u_sec.base)) (*(inbuffer + offset + 3))) << (8 * 3);
nucho 0:77afd7560544 84 this->stamp.sec = u_sec.real;
nucho 0:77afd7560544 85 offset += sizeof(this->stamp.sec);
nucho 0:77afd7560544 86 union {
nucho 0:77afd7560544 87 unsigned long real;
nucho 0:77afd7560544 88 unsigned long base;
nucho 0:77afd7560544 89 } u_nsec;
nucho 0:77afd7560544 90 u_nsec.base = 0;
nucho 0:77afd7560544 91 u_nsec.base |= ((typeof(u_nsec.base)) (*(inbuffer + offset + 0))) << (8 * 0);
nucho 0:77afd7560544 92 u_nsec.base |= ((typeof(u_nsec.base)) (*(inbuffer + offset + 1))) << (8 * 1);
nucho 0:77afd7560544 93 u_nsec.base |= ((typeof(u_nsec.base)) (*(inbuffer + offset + 2))) << (8 * 2);
nucho 0:77afd7560544 94 u_nsec.base |= ((typeof(u_nsec.base)) (*(inbuffer + offset + 3))) << (8 * 3);
nucho 0:77afd7560544 95 this->stamp.nsec = u_nsec.real;
nucho 0:77afd7560544 96 offset += sizeof(this->stamp.nsec);
nucho 0:77afd7560544 97 uint32_t length_frame_id = *(uint32_t *)(inbuffer + offset);
nucho 0:77afd7560544 98 offset += 4;
nucho 0:77afd7560544 99 for(unsigned int k= offset; k< offset+length_frame_id; ++k){
nucho 0:77afd7560544 100 inbuffer[k-1]=inbuffer[k];
nucho 0:77afd7560544 101 }
nucho 0:77afd7560544 102 inbuffer[offset+length_frame_id-1]=0;
nucho 0:77afd7560544 103 this->frame_id = (char *)(inbuffer + offset-1);
nucho 0:77afd7560544 104 offset += length_frame_id;
nucho 0:77afd7560544 105 return offset;
nucho 0:77afd7560544 106 }
nucho 0:77afd7560544 107
nucho 0:77afd7560544 108 virtual const char * getType(){ return "std_msgs/Header"; };
nucho 0:77afd7560544 109
nucho 0:77afd7560544 110 };
nucho 0:77afd7560544 111
nucho 0:77afd7560544 112 }
nucho 0:77afd7560544 113 #endif