rosserial library for mbed Inspired by nucho's rosserial library This library is still under development
Dependents: mbed_roshydro_test
Library still under development!
diagnostic_msgs/DiagnosticStatus.h
- Committer:
- akashvibhute
- Date:
- 2015-02-15
- Revision:
- 0:30537dec6e0b
File content as of revision 0:30537dec6e0b:
#ifndef _ROS_diagnostic_msgs_DiagnosticStatus_h #define _ROS_diagnostic_msgs_DiagnosticStatus_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" #include "diagnostic_msgs/KeyValue.h" namespace diagnostic_msgs { class DiagnosticStatus : public ros::Msg { public: int8_t level; const char* name; const char* message; const char* hardware_id; uint8_t values_length; diagnostic_msgs::KeyValue st_values; diagnostic_msgs::KeyValue * values; enum { OK = 0 }; enum { WARN = 1 }; enum { ERROR = 2 }; DiagnosticStatus(): level(0), name(""), message(""), hardware_id(""), values_length(0), values(NULL) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; union { int8_t real; uint8_t base; } u_level; u_level.real = this->level; *(outbuffer + offset + 0) = (u_level.base >> (8 * 0)) & 0xFF; offset += sizeof(this->level); uint32_t length_name = strlen(this->name); memcpy(outbuffer + offset, &length_name, sizeof(uint32_t)); offset += 4; memcpy(outbuffer + offset, this->name, length_name); offset += length_name; uint32_t length_message = strlen(this->message); memcpy(outbuffer + offset, &length_message, sizeof(uint32_t)); offset += 4; memcpy(outbuffer + offset, this->message, length_message); offset += length_message; uint32_t length_hardware_id = strlen(this->hardware_id); memcpy(outbuffer + offset, &length_hardware_id, sizeof(uint32_t)); offset += 4; memcpy(outbuffer + offset, this->hardware_id, length_hardware_id); offset += length_hardware_id; *(outbuffer + offset++) = values_length; *(outbuffer + offset++) = 0; *(outbuffer + offset++) = 0; *(outbuffer + offset++) = 0; for( uint8_t i = 0; i < values_length; i++){ offset += this->values[i].serialize(outbuffer + offset); } return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; union { int8_t real; uint8_t base; } u_level; u_level.base = 0; u_level.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); this->level = u_level.real; offset += sizeof(this->level); uint32_t length_name; memcpy(&length_name, (inbuffer + offset), sizeof(uint32_t)); offset += 4; for(unsigned int k= offset; k< offset+length_name; ++k){ inbuffer[k-1]=inbuffer[k]; } inbuffer[offset+length_name-1]=0; this->name = (char *)(inbuffer + offset-1); offset += length_name; uint32_t length_message; memcpy(&length_message, (inbuffer + offset), sizeof(uint32_t)); offset += 4; for(unsigned int k= offset; k< offset+length_message; ++k){ inbuffer[k-1]=inbuffer[k]; } inbuffer[offset+length_message-1]=0; this->message = (char *)(inbuffer + offset-1); offset += length_message; uint32_t length_hardware_id; memcpy(&length_hardware_id, (inbuffer + offset), sizeof(uint32_t)); offset += 4; for(unsigned int k= offset; k< offset+length_hardware_id; ++k){ inbuffer[k-1]=inbuffer[k]; } inbuffer[offset+length_hardware_id-1]=0; this->hardware_id = (char *)(inbuffer + offset-1); offset += length_hardware_id; uint8_t values_lengthT = *(inbuffer + offset++); if(values_lengthT > values_length) this->values = (diagnostic_msgs::KeyValue*)realloc(this->values, values_lengthT * sizeof(diagnostic_msgs::KeyValue)); offset += 3; values_length = values_lengthT; for( uint8_t i = 0; i < values_length; i++){ offset += this->st_values.deserialize(inbuffer + offset); memcpy( &(this->values[i]), &(this->st_values), sizeof(diagnostic_msgs::KeyValue)); } return offset; } const char * getType(){ return "diagnostic_msgs/DiagnosticStatus"; }; const char * getMD5(){ return "67d15a62edb26e9d52b0f0efa3ef9da7"; }; }; } #endif