This program is porting rosserial_arduino for mbed http://www.ros.org/wiki/rosserial_arduino This program supported the revision of 169 of rosserial. This program contains an example.

Dependencies:   rosserial_mbed_lib mbed Servo

Committer:
nucho
Date:
Fri Aug 19 09:06:16 2011 +0000
Revision:
0:06fc856e99ca
Child:
1:098e75fd5ad2

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nucho 0:06fc856e99ca 1 #ifndef ros_GridCells_h
nucho 0:06fc856e99ca 2 #define ros_GridCells_h
nucho 0:06fc856e99ca 3
nucho 0:06fc856e99ca 4 #include <stdint.h>
nucho 0:06fc856e99ca 5 #include <string.h>
nucho 0:06fc856e99ca 6 #include <stdlib.h>
nucho 0:06fc856e99ca 7 #include "../ros/msg.h"
nucho 0:06fc856e99ca 8 #include "std_msgs/Header.h"
nucho 0:06fc856e99ca 9 #include "geometry_msgs/Point.h"
nucho 0:06fc856e99ca 10
nucho 0:06fc856e99ca 11 namespace nav_msgs
nucho 0:06fc856e99ca 12 {
nucho 0:06fc856e99ca 13
nucho 0:06fc856e99ca 14 class GridCells : public ros::Msg
nucho 0:06fc856e99ca 15 {
nucho 0:06fc856e99ca 16 public:
nucho 0:06fc856e99ca 17 std_msgs::Header header;
nucho 0:06fc856e99ca 18 float cell_width;
nucho 0:06fc856e99ca 19 float cell_height;
nucho 0:06fc856e99ca 20 unsigned char cells_length;
nucho 0:06fc856e99ca 21 geometry_msgs::Point st_cells;
nucho 0:06fc856e99ca 22 geometry_msgs::Point * cells;
nucho 0:06fc856e99ca 23
nucho 0:06fc856e99ca 24 virtual int serialize(unsigned char *outbuffer)
nucho 0:06fc856e99ca 25 {
nucho 0:06fc856e99ca 26 int offset = 0;
nucho 0:06fc856e99ca 27 offset += this->header.serialize(outbuffer + offset);
nucho 0:06fc856e99ca 28 union {
nucho 0:06fc856e99ca 29 float real;
nucho 0:06fc856e99ca 30 unsigned long base;
nucho 0:06fc856e99ca 31 } u_cell_width;
nucho 0:06fc856e99ca 32 u_cell_width.real = this->cell_width;
nucho 0:06fc856e99ca 33 *(outbuffer + offset + 0) = (u_cell_width.base >> (8 * 0)) & 0xFF;
nucho 0:06fc856e99ca 34 *(outbuffer + offset + 1) = (u_cell_width.base >> (8 * 1)) & 0xFF;
nucho 0:06fc856e99ca 35 *(outbuffer + offset + 2) = (u_cell_width.base >> (8 * 2)) & 0xFF;
nucho 0:06fc856e99ca 36 *(outbuffer + offset + 3) = (u_cell_width.base >> (8 * 3)) & 0xFF;
nucho 0:06fc856e99ca 37 offset += sizeof(this->cell_width);
nucho 0:06fc856e99ca 38 union {
nucho 0:06fc856e99ca 39 float real;
nucho 0:06fc856e99ca 40 unsigned long base;
nucho 0:06fc856e99ca 41 } u_cell_height;
nucho 0:06fc856e99ca 42 u_cell_height.real = this->cell_height;
nucho 0:06fc856e99ca 43 *(outbuffer + offset + 0) = (u_cell_height.base >> (8 * 0)) & 0xFF;
nucho 0:06fc856e99ca 44 *(outbuffer + offset + 1) = (u_cell_height.base >> (8 * 1)) & 0xFF;
nucho 0:06fc856e99ca 45 *(outbuffer + offset + 2) = (u_cell_height.base >> (8 * 2)) & 0xFF;
nucho 0:06fc856e99ca 46 *(outbuffer + offset + 3) = (u_cell_height.base >> (8 * 3)) & 0xFF;
nucho 0:06fc856e99ca 47 offset += sizeof(this->cell_height);
nucho 0:06fc856e99ca 48 *(outbuffer + offset++) = cells_length;
nucho 0:06fc856e99ca 49 *(outbuffer + offset++) = 0;
nucho 0:06fc856e99ca 50 *(outbuffer + offset++) = 0;
nucho 0:06fc856e99ca 51 *(outbuffer + offset++) = 0;
nucho 0:06fc856e99ca 52 for( unsigned char i = 0; i < cells_length; i++){
nucho 0:06fc856e99ca 53 offset += this->cells[i].serialize(outbuffer + offset);
nucho 0:06fc856e99ca 54 }
nucho 0:06fc856e99ca 55 return offset;
nucho 0:06fc856e99ca 56 }
nucho 0:06fc856e99ca 57
nucho 0:06fc856e99ca 58 virtual int deserialize(unsigned char *inbuffer)
nucho 0:06fc856e99ca 59 {
nucho 0:06fc856e99ca 60 int offset = 0;
nucho 0:06fc856e99ca 61 offset += this->header.deserialize(inbuffer + offset);
nucho 0:06fc856e99ca 62 union {
nucho 0:06fc856e99ca 63 float real;
nucho 0:06fc856e99ca 64 unsigned long base;
nucho 0:06fc856e99ca 65 } u_cell_width;
nucho 0:06fc856e99ca 66 u_cell_width.base = 0;
nucho 0:06fc856e99ca 67 u_cell_width.base |= ((typeof(u_cell_width.base)) (*(inbuffer + offset + 0))) << (8 * 0);
nucho 0:06fc856e99ca 68 u_cell_width.base |= ((typeof(u_cell_width.base)) (*(inbuffer + offset + 1))) << (8 * 1);
nucho 0:06fc856e99ca 69 u_cell_width.base |= ((typeof(u_cell_width.base)) (*(inbuffer + offset + 2))) << (8 * 2);
nucho 0:06fc856e99ca 70 u_cell_width.base |= ((typeof(u_cell_width.base)) (*(inbuffer + offset + 3))) << (8 * 3);
nucho 0:06fc856e99ca 71 this->cell_width = u_cell_width.real;
nucho 0:06fc856e99ca 72 offset += sizeof(this->cell_width);
nucho 0:06fc856e99ca 73 union {
nucho 0:06fc856e99ca 74 float real;
nucho 0:06fc856e99ca 75 unsigned long base;
nucho 0:06fc856e99ca 76 } u_cell_height;
nucho 0:06fc856e99ca 77 u_cell_height.base = 0;
nucho 0:06fc856e99ca 78 u_cell_height.base |= ((typeof(u_cell_height.base)) (*(inbuffer + offset + 0))) << (8 * 0);
nucho 0:06fc856e99ca 79 u_cell_height.base |= ((typeof(u_cell_height.base)) (*(inbuffer + offset + 1))) << (8 * 1);
nucho 0:06fc856e99ca 80 u_cell_height.base |= ((typeof(u_cell_height.base)) (*(inbuffer + offset + 2))) << (8 * 2);
nucho 0:06fc856e99ca 81 u_cell_height.base |= ((typeof(u_cell_height.base)) (*(inbuffer + offset + 3))) << (8 * 3);
nucho 0:06fc856e99ca 82 this->cell_height = u_cell_height.real;
nucho 0:06fc856e99ca 83 offset += sizeof(this->cell_height);
nucho 0:06fc856e99ca 84 unsigned char cells_lengthT = *(inbuffer + offset++);
nucho 0:06fc856e99ca 85 if(cells_lengthT > cells_length)
nucho 0:06fc856e99ca 86 this->cells = (geometry_msgs::Point*)realloc(this->cells, cells_lengthT * sizeof(geometry_msgs::Point));
nucho 0:06fc856e99ca 87 offset += 3;
nucho 0:06fc856e99ca 88 cells_length = cells_lengthT;
nucho 0:06fc856e99ca 89 for( unsigned char i = 0; i < cells_length; i++){
nucho 0:06fc856e99ca 90 offset += this->st_cells.deserialize(inbuffer + offset);
nucho 0:06fc856e99ca 91 memcpy( &(this->cells[i]), &(this->st_cells), sizeof(geometry_msgs::Point));
nucho 0:06fc856e99ca 92 }
nucho 0:06fc856e99ca 93 return offset;
nucho 0:06fc856e99ca 94 }
nucho 0:06fc856e99ca 95
nucho 0:06fc856e99ca 96 virtual const char * getType(){ return "nav_msgs/GridCells"; };
nucho 0:06fc856e99ca 97
nucho 0:06fc856e99ca 98 };
nucho 0:06fc856e99ca 99
nucho 0:06fc856e99ca 100 }
nucho 0:06fc856e99ca 101 #endif