Gary Servin / ros_lib_indigo

Dependencies:   BufferedSerial

Dependents:   rosserial_mbed_hello_world_publisher rtos_base_control rosserial_mbed_F64MA ROS-RTOS ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SelfTest.h Source File

SelfTest.h

00001 #ifndef _ROS_SERVICE_SelfTest_h
00002 #define _ROS_SERVICE_SelfTest_h
00003 #include <stdint.h>
00004 #include <string.h>
00005 #include <stdlib.h>
00006 #include "ros/msg.h"
00007 #include "diagnostic_msgs/DiagnosticStatus.h"
00008 
00009 namespace diagnostic_msgs
00010 {
00011 
00012 static const char SELFTEST[] = "diagnostic_msgs/SelfTest";
00013 
00014   class SelfTestRequest : public ros::Msg
00015   {
00016     public:
00017 
00018     SelfTestRequest()
00019     {
00020     }
00021 
00022     virtual int serialize(unsigned char *outbuffer) const
00023     {
00024       int offset = 0;
00025       return offset;
00026     }
00027 
00028     virtual int deserialize(unsigned char *inbuffer)
00029     {
00030       int offset = 0;
00031      return offset;
00032     }
00033 
00034     const char * getType(){ return SELFTEST; };
00035     const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; };
00036 
00037   };
00038 
00039   class SelfTestResponse : public ros::Msg
00040   {
00041     public:
00042       const char* id;
00043       int8_t passed;
00044       uint8_t status_length;
00045       diagnostic_msgs::DiagnosticStatus st_status;
00046       diagnostic_msgs::DiagnosticStatus * status;
00047 
00048     SelfTestResponse():
00049       id(""),
00050       passed(0),
00051       status_length(0), status(NULL)
00052     {
00053     }
00054 
00055     virtual int serialize(unsigned char *outbuffer) const
00056     {
00057       int offset = 0;
00058       uint32_t length_id = strlen(this->id);
00059       memcpy(outbuffer + offset, &length_id, sizeof(uint32_t));
00060       offset += 4;
00061       memcpy(outbuffer + offset, this->id, length_id);
00062       offset += length_id;
00063       union {
00064         int8_t real;
00065         uint8_t base;
00066       } u_passed;
00067       u_passed.real = this->passed;
00068       *(outbuffer + offset + 0) = (u_passed.base >> (8 * 0)) & 0xFF;
00069       offset += sizeof(this->passed);
00070       *(outbuffer + offset++) = status_length;
00071       *(outbuffer + offset++) = 0;
00072       *(outbuffer + offset++) = 0;
00073       *(outbuffer + offset++) = 0;
00074       for( uint8_t i = 0; i < status_length; i++){
00075       offset += this->status[i].serialize(outbuffer + offset);
00076       }
00077       return offset;
00078     }
00079 
00080     virtual int deserialize(unsigned char *inbuffer)
00081     {
00082       int offset = 0;
00083       uint32_t length_id;
00084       memcpy(&length_id, (inbuffer + offset), sizeof(uint32_t));
00085       offset += 4;
00086       for(unsigned int k= offset; k< offset+length_id; ++k){
00087           inbuffer[k-1]=inbuffer[k];
00088       }
00089       inbuffer[offset+length_id-1]=0;
00090       this->id = (char *)(inbuffer + offset-1);
00091       offset += length_id;
00092       union {
00093         int8_t real;
00094         uint8_t base;
00095       } u_passed;
00096       u_passed.base = 0;
00097       u_passed.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0);
00098       this->passed = u_passed.real;
00099       offset += sizeof(this->passed);
00100       uint8_t status_lengthT = *(inbuffer + offset++);
00101       if(status_lengthT > status_length)
00102         this->status = (diagnostic_msgs::DiagnosticStatus*)realloc(this->status, status_lengthT * sizeof(diagnostic_msgs::DiagnosticStatus));
00103       offset += 3;
00104       status_length = status_lengthT;
00105       for( uint8_t i = 0; i < status_length; i++){
00106       offset += this->st_status.deserialize(inbuffer + offset);
00107         memcpy( &(this->status[i]), &(this->st_status), sizeof(diagnostic_msgs::DiagnosticStatus));
00108       }
00109      return offset;
00110     }
00111 
00112     const char * getType(){ return SELFTEST; };
00113     const char * getMD5(){ return "ac21b1bab7ab17546986536c22eb34e9"; };
00114 
00115   };
00116 
00117   class SelfTest {
00118     public:
00119     typedef SelfTestRequest Request;
00120     typedef SelfTestResponse Response;
00121   };
00122 
00123 }
00124 #endif