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:
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_MultiArrayLayout_h
nucho 0:77afd7560544 2 #define ros_MultiArrayLayout_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 "std_msgs/MultiArrayDimension.h"
nucho 0:77afd7560544 9
nucho 1:ff0ec969dad1 10 namespace std_msgs {
nucho 0:77afd7560544 11
nucho 1:ff0ec969dad1 12 class MultiArrayLayout : public ros::Msg {
nucho 1:ff0ec969dad1 13 public:
nucho 1:ff0ec969dad1 14 unsigned char dim_length;
nucho 1:ff0ec969dad1 15 std_msgs::MultiArrayDimension st_dim;
nucho 1:ff0ec969dad1 16 std_msgs::MultiArrayDimension * dim;
nucho 1:ff0ec969dad1 17 unsigned long data_offset;
nucho 0:77afd7560544 18
nucho 1:ff0ec969dad1 19 virtual int serialize(unsigned char *outbuffer) {
nucho 1:ff0ec969dad1 20 int offset = 0;
nucho 1:ff0ec969dad1 21 *(outbuffer + offset++) = dim_length;
nucho 1:ff0ec969dad1 22 *(outbuffer + offset++) = 0;
nucho 1:ff0ec969dad1 23 *(outbuffer + offset++) = 0;
nucho 1:ff0ec969dad1 24 *(outbuffer + offset++) = 0;
nucho 1:ff0ec969dad1 25 for ( unsigned char i = 0; i < dim_length; i++) {
nucho 1:ff0ec969dad1 26 offset += this->dim[i].serialize(outbuffer + offset);
nucho 1:ff0ec969dad1 27 }
nucho 1:ff0ec969dad1 28 union {
nucho 1:ff0ec969dad1 29 uint32_t real;
nucho 1:ff0ec969dad1 30 uint32_t base;
nucho 1:ff0ec969dad1 31 } u_data_offset;
nucho 1:ff0ec969dad1 32 u_data_offset.real = this->data_offset;
nucho 1:ff0ec969dad1 33 *(outbuffer + offset + 0) = (u_data_offset.base >> (8 * 0)) & 0xFF;
nucho 1:ff0ec969dad1 34 *(outbuffer + offset + 1) = (u_data_offset.base >> (8 * 1)) & 0xFF;
nucho 1:ff0ec969dad1 35 *(outbuffer + offset + 2) = (u_data_offset.base >> (8 * 2)) & 0xFF;
nucho 1:ff0ec969dad1 36 *(outbuffer + offset + 3) = (u_data_offset.base >> (8 * 3)) & 0xFF;
nucho 1:ff0ec969dad1 37 offset += sizeof(this->data_offset);
nucho 1:ff0ec969dad1 38 return offset;
nucho 0:77afd7560544 39 }
nucho 0:77afd7560544 40
nucho 1:ff0ec969dad1 41 virtual int deserialize(unsigned char *inbuffer) {
nucho 1:ff0ec969dad1 42 int offset = 0;
nucho 1:ff0ec969dad1 43 unsigned char dim_lengthT = *(inbuffer + offset++);
nucho 1:ff0ec969dad1 44 if (dim_lengthT > dim_length)
nucho 1:ff0ec969dad1 45 this->dim = (std_msgs::MultiArrayDimension*)realloc(this->dim, dim_lengthT * sizeof(std_msgs::MultiArrayDimension));
nucho 1:ff0ec969dad1 46 offset += 3;
nucho 1:ff0ec969dad1 47 dim_length = dim_lengthT;
nucho 1:ff0ec969dad1 48 for ( unsigned char i = 0; i < dim_length; i++) {
nucho 1:ff0ec969dad1 49 offset += this->st_dim.deserialize(inbuffer + offset);
nucho 1:ff0ec969dad1 50 memcpy( &(this->dim[i]), &(this->st_dim), sizeof(std_msgs::MultiArrayDimension));
nucho 1:ff0ec969dad1 51 }
nucho 1:ff0ec969dad1 52 union {
nucho 1:ff0ec969dad1 53 uint32_t real;
nucho 1:ff0ec969dad1 54 uint32_t base;
nucho 1:ff0ec969dad1 55 } u_data_offset;
nucho 1:ff0ec969dad1 56 u_data_offset.base = 0;
nucho 1:ff0ec969dad1 57 u_data_offset.base |= ((typeof(u_data_offset.base)) (*(inbuffer + offset + 0))) << (8 * 0);
nucho 1:ff0ec969dad1 58 u_data_offset.base |= ((typeof(u_data_offset.base)) (*(inbuffer + offset + 1))) << (8 * 1);
nucho 1:ff0ec969dad1 59 u_data_offset.base |= ((typeof(u_data_offset.base)) (*(inbuffer + offset + 2))) << (8 * 2);
nucho 1:ff0ec969dad1 60 u_data_offset.base |= ((typeof(u_data_offset.base)) (*(inbuffer + offset + 3))) << (8 * 3);
nucho 1:ff0ec969dad1 61 this->data_offset = u_data_offset.real;
nucho 1:ff0ec969dad1 62 offset += sizeof(this->data_offset);
nucho 1:ff0ec969dad1 63 return offset;
nucho 0:77afd7560544 64 }
nucho 0:77afd7560544 65
nucho 1:ff0ec969dad1 66 virtual const char * getType() {
nucho 1:ff0ec969dad1 67 return "std_msgs/MultiArrayLayout";
nucho 1:ff0ec969dad1 68 };
nucho 0:77afd7560544 69
nucho 1:ff0ec969dad1 70 };
nucho 0:77afd7560544 71
nucho 0:77afd7560544 72 }
nucho 0:77afd7560544 73 #endif