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_SelfTest_h
nucho 3:1cf99502f396 2 #define _ROS_SERVICE_SelfTest_h
nucho 0:77afd7560544 3 #include <stdint.h>
nucho 0:77afd7560544 4 #include <string.h>
nucho 0:77afd7560544 5 #include <stdlib.h>
nucho 3:1cf99502f396 6 #include "ros/msg.h"
nucho 0:77afd7560544 7 #include "diagnostic_msgs/DiagnosticStatus.h"
nucho 3:1cf99502f396 8 #include "diagnostic_msgs/byte.h"
nucho 0:77afd7560544 9
nucho 0:77afd7560544 10 namespace diagnostic_msgs
nucho 0:77afd7560544 11 {
nucho 0:77afd7560544 12
nucho 0:77afd7560544 13 static const char SELFTEST[] = "diagnostic_msgs/SelfTest";
nucho 0:77afd7560544 14
nucho 0:77afd7560544 15 class SelfTestRequest : public ros::Msg
nucho 0:77afd7560544 16 {
nucho 0:77afd7560544 17 public:
nucho 0:77afd7560544 18
nucho 3:1cf99502f396 19 virtual int serialize(unsigned char *outbuffer) const
nucho 0:77afd7560544 20 {
nucho 0:77afd7560544 21 int offset = 0;
nucho 0:77afd7560544 22 return offset;
nucho 0:77afd7560544 23 }
nucho 0:77afd7560544 24
nucho 0:77afd7560544 25 virtual int deserialize(unsigned char *inbuffer)
nucho 0:77afd7560544 26 {
nucho 0:77afd7560544 27 int offset = 0;
nucho 0:77afd7560544 28 return offset;
nucho 0:77afd7560544 29 }
nucho 0:77afd7560544 30
nucho 4:684f39d0c346 31 const char * getType(){ return SELFTEST; };
nucho 4:684f39d0c346 32 const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; };
nucho 0:77afd7560544 33
nucho 0:77afd7560544 34 };
nucho 0:77afd7560544 35
nucho 0:77afd7560544 36 class SelfTestResponse : public ros::Msg
nucho 0:77afd7560544 37 {
nucho 0:77afd7560544 38 public:
nucho 0:77afd7560544 39 char * id;
nucho 3:1cf99502f396 40 diagnostic_msgs::byte passed;
nucho 3:1cf99502f396 41 uint8_t status_length;
nucho 0:77afd7560544 42 diagnostic_msgs::DiagnosticStatus st_status;
nucho 0:77afd7560544 43 diagnostic_msgs::DiagnosticStatus * status;
nucho 0:77afd7560544 44
nucho 3:1cf99502f396 45 virtual int serialize(unsigned char *outbuffer) const
nucho 0:77afd7560544 46 {
nucho 0:77afd7560544 47 int offset = 0;
nucho 3:1cf99502f396 48 uint32_t * length_id = (uint32_t *)(outbuffer + offset);
nucho 0:77afd7560544 49 *length_id = strlen( (const char*) this->id);
nucho 0:77afd7560544 50 offset += 4;
nucho 0:77afd7560544 51 memcpy(outbuffer + offset, this->id, *length_id);
nucho 0:77afd7560544 52 offset += *length_id;
nucho 3:1cf99502f396 53 offset += this->passed.serialize(outbuffer + offset);
nucho 0:77afd7560544 54 *(outbuffer + offset++) = status_length;
nucho 0:77afd7560544 55 *(outbuffer + offset++) = 0;
nucho 0:77afd7560544 56 *(outbuffer + offset++) = 0;
nucho 0:77afd7560544 57 *(outbuffer + offset++) = 0;
nucho 3:1cf99502f396 58 for( uint8_t i = 0; i < status_length; i++){
nucho 0:77afd7560544 59 offset += this->status[i].serialize(outbuffer + offset);
nucho 0:77afd7560544 60 }
nucho 0:77afd7560544 61 return offset;
nucho 0:77afd7560544 62 }
nucho 0:77afd7560544 63
nucho 0:77afd7560544 64 virtual int deserialize(unsigned char *inbuffer)
nucho 0:77afd7560544 65 {
nucho 0:77afd7560544 66 int offset = 0;
nucho 0:77afd7560544 67 uint32_t length_id = *(uint32_t *)(inbuffer + offset);
nucho 0:77afd7560544 68 offset += 4;
nucho 0:77afd7560544 69 for(unsigned int k= offset; k< offset+length_id; ++k){
nucho 0:77afd7560544 70 inbuffer[k-1]=inbuffer[k];
nucho 3:1cf99502f396 71 }
nucho 0:77afd7560544 72 inbuffer[offset+length_id-1]=0;
nucho 0:77afd7560544 73 this->id = (char *)(inbuffer + offset-1);
nucho 0:77afd7560544 74 offset += length_id;
nucho 3:1cf99502f396 75 offset += this->passed.deserialize(inbuffer + offset);
nucho 3:1cf99502f396 76 uint8_t status_lengthT = *(inbuffer + offset++);
nucho 0:77afd7560544 77 if(status_lengthT > status_length)
nucho 0:77afd7560544 78 this->status = (diagnostic_msgs::DiagnosticStatus*)realloc(this->status, status_lengthT * sizeof(diagnostic_msgs::DiagnosticStatus));
nucho 0:77afd7560544 79 offset += 3;
nucho 0:77afd7560544 80 status_length = status_lengthT;
nucho 3:1cf99502f396 81 for( uint8_t i = 0; i < status_length; i++){
nucho 0:77afd7560544 82 offset += this->st_status.deserialize(inbuffer + offset);
nucho 0:77afd7560544 83 memcpy( &(this->status[i]), &(this->st_status), sizeof(diagnostic_msgs::DiagnosticStatus));
nucho 0:77afd7560544 84 }
nucho 0:77afd7560544 85 return offset;
nucho 0:77afd7560544 86 }
nucho 0:77afd7560544 87
nucho 4:684f39d0c346 88 const char * getType(){ return SELFTEST; };
nucho 4:684f39d0c346 89 const char * getMD5(){ return "74c9372c870a76da4fc2b3973978b898"; };
nucho 0:77afd7560544 90
nucho 0:77afd7560544 91 };
nucho 0:77afd7560544 92
nucho 3:1cf99502f396 93 class SelfTest {
nucho 3:1cf99502f396 94 public:
nucho 3:1cf99502f396 95 typedef SelfTestRequest Request;
nucho 3:1cf99502f396 96 typedef SelfTestResponse Response;
nucho 3:1cf99502f396 97 };
nucho 3:1cf99502f396 98
nucho 0:77afd7560544 99 }
nucho 0:77afd7560544 100 #endif