rosserial for Hydro

Dependencies:   MODSERIAL

Fork of rosserial_mbed_lib by nucho

Committer:
nucho
Date:
Fri Aug 19 09:06:30 2011 +0000
Revision:
0:77afd7560544
Child:
3:1cf99502f396

        

Who changed what in which revision?

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