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:
Wed Feb 29 23:00:21 2012 +0000
Revision:
4:684f39d0c346
Parent:
3:1cf99502f396

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nucho 3:1cf99502f396 1 #ifndef _ROS_SERVICE_MuxList_h
nucho 3:1cf99502f396 2 #define _ROS_SERVICE_MuxList_h
nucho 3:1cf99502f396 3 #include <stdint.h>
nucho 3:1cf99502f396 4 #include <string.h>
nucho 3:1cf99502f396 5 #include <stdlib.h>
nucho 3:1cf99502f396 6 #include "ros/msg.h"
nucho 3:1cf99502f396 7
nucho 3:1cf99502f396 8 namespace topic_tools
nucho 3:1cf99502f396 9 {
nucho 3:1cf99502f396 10
nucho 3:1cf99502f396 11 static const char MUXLIST[] = "topic_tools/MuxList";
nucho 3:1cf99502f396 12
nucho 3:1cf99502f396 13 class MuxListRequest : public ros::Msg
nucho 3:1cf99502f396 14 {
nucho 3:1cf99502f396 15 public:
nucho 3:1cf99502f396 16
nucho 3:1cf99502f396 17 virtual int serialize(unsigned char *outbuffer) const
nucho 3:1cf99502f396 18 {
nucho 3:1cf99502f396 19 int offset = 0;
nucho 3:1cf99502f396 20 return offset;
nucho 3:1cf99502f396 21 }
nucho 3:1cf99502f396 22
nucho 3:1cf99502f396 23 virtual int deserialize(unsigned char *inbuffer)
nucho 3:1cf99502f396 24 {
nucho 3:1cf99502f396 25 int offset = 0;
nucho 3:1cf99502f396 26 return offset;
nucho 3:1cf99502f396 27 }
nucho 3:1cf99502f396 28
nucho 3:1cf99502f396 29 virtual const char * getType(){ return MUXLIST; };
nucho 3:1cf99502f396 30 virtual const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; };
nucho 3:1cf99502f396 31
nucho 3:1cf99502f396 32 };
nucho 3:1cf99502f396 33
nucho 3:1cf99502f396 34 class MuxListResponse : public ros::Msg
nucho 3:1cf99502f396 35 {
nucho 3:1cf99502f396 36 public:
nucho 3:1cf99502f396 37 uint8_t topics_length;
nucho 3:1cf99502f396 38 char* st_topics;
nucho 3:1cf99502f396 39 char* * topics;
nucho 3:1cf99502f396 40
nucho 3:1cf99502f396 41 virtual int serialize(unsigned char *outbuffer) const
nucho 3:1cf99502f396 42 {
nucho 3:1cf99502f396 43 int offset = 0;
nucho 3:1cf99502f396 44 *(outbuffer + offset++) = topics_length;
nucho 3:1cf99502f396 45 *(outbuffer + offset++) = 0;
nucho 3:1cf99502f396 46 *(outbuffer + offset++) = 0;
nucho 3:1cf99502f396 47 *(outbuffer + offset++) = 0;
nucho 3:1cf99502f396 48 for( uint8_t i = 0; i < topics_length; i++){
nucho 3:1cf99502f396 49 uint32_t * length_topicsi = (uint32_t *)(outbuffer + offset);
nucho 3:1cf99502f396 50 *length_topicsi = strlen( (const char*) this->topics[i]);
nucho 3:1cf99502f396 51 offset += 4;
nucho 3:1cf99502f396 52 memcpy(outbuffer + offset, this->topics[i], *length_topicsi);
nucho 3:1cf99502f396 53 offset += *length_topicsi;
nucho 3:1cf99502f396 54 }
nucho 3:1cf99502f396 55 return offset;
nucho 3:1cf99502f396 56 }
nucho 3:1cf99502f396 57
nucho 3:1cf99502f396 58 virtual int deserialize(unsigned char *inbuffer)
nucho 3:1cf99502f396 59 {
nucho 3:1cf99502f396 60 int offset = 0;
nucho 3:1cf99502f396 61 uint8_t topics_lengthT = *(inbuffer + offset++);
nucho 3:1cf99502f396 62 if(topics_lengthT > topics_length)
nucho 3:1cf99502f396 63 this->topics = (char**)realloc(this->topics, topics_lengthT * sizeof(char*));
nucho 3:1cf99502f396 64 offset += 3;
nucho 3:1cf99502f396 65 topics_length = topics_lengthT;
nucho 3:1cf99502f396 66 for( uint8_t i = 0; i < topics_length; i++){
nucho 3:1cf99502f396 67 uint32_t length_st_topics = *(uint32_t *)(inbuffer + offset);
nucho 3:1cf99502f396 68 offset += 4;
nucho 3:1cf99502f396 69 for(unsigned int k= offset; k< offset+length_st_topics; ++k){
nucho 3:1cf99502f396 70 inbuffer[k-1]=inbuffer[k];
nucho 3:1cf99502f396 71 }
nucho 3:1cf99502f396 72 inbuffer[offset+length_st_topics-1]=0;
nucho 3:1cf99502f396 73 this->st_topics = (char *)(inbuffer + offset-1);
nucho 3:1cf99502f396 74 offset += length_st_topics;
nucho 3:1cf99502f396 75 memcpy( &(this->topics[i]), &(this->st_topics), sizeof(char*));
nucho 3:1cf99502f396 76 }
nucho 3:1cf99502f396 77 return offset;
nucho 3:1cf99502f396 78 }
nucho 3:1cf99502f396 79
nucho 3:1cf99502f396 80 virtual const char * getType(){ return MUXLIST; };
nucho 3:1cf99502f396 81 virtual const char * getMD5(){ return "b0eef9a05d4e829092fc2f2c3c2aad3d"; };
nucho 3:1cf99502f396 82
nucho 3:1cf99502f396 83 };
nucho 3:1cf99502f396 84
nucho 3:1cf99502f396 85 class MuxList {
nucho 3:1cf99502f396 86 public:
nucho 3:1cf99502f396 87 typedef MuxListRequest Request;
nucho 3:1cf99502f396 88 typedef MuxListResponse Response;
nucho 3:1cf99502f396 89 };
nucho 3:1cf99502f396 90
nucho 3:1cf99502f396 91 }
nucho 3:1cf99502f396 92 #endif