modify for Hydro version

Dependencies:   MODSERIAL

Fork of rosserial_mbed_lib by nucho

Committer:
nucho
Date:
Sun Oct 16 07:19:36 2011 +0000
Revision:
1:ff0ec969dad1
Parent:
0:77afd7560544
Child:
3:1cf99502f396
This program supported the revision of 143 of rosserial.
And the bug fix of receive of array data.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nucho 0:77afd7560544 1 #ifndef ros_MultiArrayDimension_h
nucho 0:77afd7560544 2 #define ros_MultiArrayDimension_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
nucho 0:77afd7560544 9 namespace std_msgs
nucho 0:77afd7560544 10 {
nucho 0:77afd7560544 11
nucho 0:77afd7560544 12 class MultiArrayDimension : public ros::Msg
nucho 0:77afd7560544 13 {
nucho 0:77afd7560544 14 public:
nucho 0:77afd7560544 15 char * label;
nucho 1:ff0ec969dad1 16 uint32_t size;
nucho 1:ff0ec969dad1 17 uint32_t stride;
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_label = (long *)(outbuffer + offset);
nucho 0:77afd7560544 23 *length_label = strlen( (const char*) this->label);
nucho 0:77afd7560544 24 offset += 4;
nucho 0:77afd7560544 25 memcpy(outbuffer + offset, this->label, *length_label);
nucho 0:77afd7560544 26 offset += *length_label;
nucho 0:77afd7560544 27 union {
nucho 1:ff0ec969dad1 28 uint32_t real;
nucho 1:ff0ec969dad1 29 uint32_t base;
nucho 0:77afd7560544 30 } u_size;
nucho 0:77afd7560544 31 u_size.real = this->size;
nucho 0:77afd7560544 32 *(outbuffer + offset + 0) = (u_size.base >> (8 * 0)) & 0xFF;
nucho 0:77afd7560544 33 *(outbuffer + offset + 1) = (u_size.base >> (8 * 1)) & 0xFF;
nucho 0:77afd7560544 34 *(outbuffer + offset + 2) = (u_size.base >> (8 * 2)) & 0xFF;
nucho 0:77afd7560544 35 *(outbuffer + offset + 3) = (u_size.base >> (8 * 3)) & 0xFF;
nucho 0:77afd7560544 36 offset += sizeof(this->size);
nucho 0:77afd7560544 37 union {
nucho 1:ff0ec969dad1 38 uint32_t real;
nucho 1:ff0ec969dad1 39 uint32_t base;
nucho 0:77afd7560544 40 } u_stride;
nucho 0:77afd7560544 41 u_stride.real = this->stride;
nucho 0:77afd7560544 42 *(outbuffer + offset + 0) = (u_stride.base >> (8 * 0)) & 0xFF;
nucho 0:77afd7560544 43 *(outbuffer + offset + 1) = (u_stride.base >> (8 * 1)) & 0xFF;
nucho 0:77afd7560544 44 *(outbuffer + offset + 2) = (u_stride.base >> (8 * 2)) & 0xFF;
nucho 0:77afd7560544 45 *(outbuffer + offset + 3) = (u_stride.base >> (8 * 3)) & 0xFF;
nucho 0:77afd7560544 46 offset += sizeof(this->stride);
nucho 0:77afd7560544 47 return offset;
nucho 0:77afd7560544 48 }
nucho 0:77afd7560544 49
nucho 0:77afd7560544 50 virtual int deserialize(unsigned char *inbuffer)
nucho 0:77afd7560544 51 {
nucho 0:77afd7560544 52 int offset = 0;
nucho 0:77afd7560544 53 uint32_t length_label = *(uint32_t *)(inbuffer + offset);
nucho 0:77afd7560544 54 offset += 4;
nucho 0:77afd7560544 55 for(unsigned int k= offset; k< offset+length_label; ++k){
nucho 0:77afd7560544 56 inbuffer[k-1]=inbuffer[k];
nucho 0:77afd7560544 57 }
nucho 0:77afd7560544 58 inbuffer[offset+length_label-1]=0;
nucho 0:77afd7560544 59 this->label = (char *)(inbuffer + offset-1);
nucho 0:77afd7560544 60 offset += length_label;
nucho 0:77afd7560544 61 union {
nucho 1:ff0ec969dad1 62 uint32_t real;
nucho 1:ff0ec969dad1 63 uint32_t base;
nucho 0:77afd7560544 64 } u_size;
nucho 0:77afd7560544 65 u_size.base = 0;
nucho 0:77afd7560544 66 u_size.base |= ((typeof(u_size.base)) (*(inbuffer + offset + 0))) << (8 * 0);
nucho 0:77afd7560544 67 u_size.base |= ((typeof(u_size.base)) (*(inbuffer + offset + 1))) << (8 * 1);
nucho 0:77afd7560544 68 u_size.base |= ((typeof(u_size.base)) (*(inbuffer + offset + 2))) << (8 * 2);
nucho 0:77afd7560544 69 u_size.base |= ((typeof(u_size.base)) (*(inbuffer + offset + 3))) << (8 * 3);
nucho 0:77afd7560544 70 this->size = u_size.real;
nucho 0:77afd7560544 71 offset += sizeof(this->size);
nucho 0:77afd7560544 72 union {
nucho 1:ff0ec969dad1 73 uint32_t real;
nucho 1:ff0ec969dad1 74 uint32_t base;
nucho 0:77afd7560544 75 } u_stride;
nucho 0:77afd7560544 76 u_stride.base = 0;
nucho 0:77afd7560544 77 u_stride.base |= ((typeof(u_stride.base)) (*(inbuffer + offset + 0))) << (8 * 0);
nucho 0:77afd7560544 78 u_stride.base |= ((typeof(u_stride.base)) (*(inbuffer + offset + 1))) << (8 * 1);
nucho 0:77afd7560544 79 u_stride.base |= ((typeof(u_stride.base)) (*(inbuffer + offset + 2))) << (8 * 2);
nucho 0:77afd7560544 80 u_stride.base |= ((typeof(u_stride.base)) (*(inbuffer + offset + 3))) << (8 * 3);
nucho 0:77afd7560544 81 this->stride = u_stride.real;
nucho 0:77afd7560544 82 offset += sizeof(this->stride);
nucho 0:77afd7560544 83 return offset;
nucho 0:77afd7560544 84 }
nucho 0:77afd7560544 85
nucho 0:77afd7560544 86 virtual const char * getType(){ return "std_msgs/MultiArrayDimension"; };
nucho 0:77afd7560544 87
nucho 0:77afd7560544 88 };
nucho 0:77afd7560544 89
nucho 0:77afd7560544 90 }
nucho 0:77afd7560544 91 #endif