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:
Fri Aug 19 09:06:30 2011 +0000
Revision:
0:77afd7560544
Child:
1:ff0ec969dad1

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nucho 0:77afd7560544 1 #ifndef ros_DiagnosticStatus_h
nucho 0:77afd7560544 2 #define ros_DiagnosticStatus_h
nucho 0:77afd7560544 3
nucho 0:77afd7560544 4 #include <stdint.h>
nucho 0:77afd7560544 5 #include <string.h>
nucho 0:77afd7560544 6 #include <stdlib.h>
nucho 0:77afd7560544 7 #include "../ros/msg.h"
nucho 0:77afd7560544 8 #include "diagnostic_msgs/KeyValue.h"
nucho 0:77afd7560544 9
nucho 0:77afd7560544 10 namespace diagnostic_msgs
nucho 0:77afd7560544 11 {
nucho 0:77afd7560544 12
nucho 0:77afd7560544 13 class DiagnosticStatus : public ros::Msg
nucho 0:77afd7560544 14 {
nucho 0:77afd7560544 15 public:
nucho 0:77afd7560544 16 unsigned char level;
nucho 0:77afd7560544 17 char * name;
nucho 0:77afd7560544 18 char * message;
nucho 0:77afd7560544 19 char * hardware_id;
nucho 0:77afd7560544 20 unsigned char values_length;
nucho 0:77afd7560544 21 diagnostic_msgs::KeyValue st_values;
nucho 0:77afd7560544 22 diagnostic_msgs::KeyValue * values;
nucho 0:77afd7560544 23 enum { OK = 0 };
nucho 0:77afd7560544 24 enum { WARN = 1 };
nucho 0:77afd7560544 25 enum { ERROR = 2 };
nucho 0:77afd7560544 26
nucho 0:77afd7560544 27 virtual int serialize(unsigned char *outbuffer)
nucho 0:77afd7560544 28 {
nucho 0:77afd7560544 29 int offset = 0;
nucho 0:77afd7560544 30 union {
nucho 0:77afd7560544 31 unsigned char real;
nucho 0:77afd7560544 32 unsigned char base;
nucho 0:77afd7560544 33 } u_level;
nucho 0:77afd7560544 34 u_level.real = this->level;
nucho 0:77afd7560544 35 *(outbuffer + offset + 0) = (u_level.base >> (8 * 0)) & 0xFF;
nucho 0:77afd7560544 36 offset += sizeof(this->level);
nucho 0:77afd7560544 37 long * length_name = (long *)(outbuffer + offset);
nucho 0:77afd7560544 38 *length_name = strlen( (const char*) this->name);
nucho 0:77afd7560544 39 offset += 4;
nucho 0:77afd7560544 40 memcpy(outbuffer + offset, this->name, *length_name);
nucho 0:77afd7560544 41 offset += *length_name;
nucho 0:77afd7560544 42 long * length_message = (long *)(outbuffer + offset);
nucho 0:77afd7560544 43 *length_message = strlen( (const char*) this->message);
nucho 0:77afd7560544 44 offset += 4;
nucho 0:77afd7560544 45 memcpy(outbuffer + offset, this->message, *length_message);
nucho 0:77afd7560544 46 offset += *length_message;
nucho 0:77afd7560544 47 long * length_hardware_id = (long *)(outbuffer + offset);
nucho 0:77afd7560544 48 *length_hardware_id = strlen( (const char*) this->hardware_id);
nucho 0:77afd7560544 49 offset += 4;
nucho 0:77afd7560544 50 memcpy(outbuffer + offset, this->hardware_id, *length_hardware_id);
nucho 0:77afd7560544 51 offset += *length_hardware_id;
nucho 0:77afd7560544 52 *(outbuffer + offset++) = values_length;
nucho 0:77afd7560544 53 *(outbuffer + offset++) = 0;
nucho 0:77afd7560544 54 *(outbuffer + offset++) = 0;
nucho 0:77afd7560544 55 *(outbuffer + offset++) = 0;
nucho 0:77afd7560544 56 for( unsigned char i = 0; i < values_length; i++){
nucho 0:77afd7560544 57 offset += this->values[i].serialize(outbuffer + offset);
nucho 0:77afd7560544 58 }
nucho 0:77afd7560544 59 return offset;
nucho 0:77afd7560544 60 }
nucho 0:77afd7560544 61
nucho 0:77afd7560544 62 virtual int deserialize(unsigned char *inbuffer)
nucho 0:77afd7560544 63 {
nucho 0:77afd7560544 64 int offset = 0;
nucho 0:77afd7560544 65 union {
nucho 0:77afd7560544 66 unsigned char real;
nucho 0:77afd7560544 67 unsigned char base;
nucho 0:77afd7560544 68 } u_level;
nucho 0:77afd7560544 69 u_level.base = 0;
nucho 0:77afd7560544 70 u_level.base |= ((typeof(u_level.base)) (*(inbuffer + offset + 0))) << (8 * 0);
nucho 0:77afd7560544 71 this->level = u_level.real;
nucho 0:77afd7560544 72 offset += sizeof(this->level);
nucho 0:77afd7560544 73 uint32_t length_name = *(uint32_t *)(inbuffer + offset);
nucho 0:77afd7560544 74 offset += 4;
nucho 0:77afd7560544 75 for(unsigned int k= offset; k< offset+length_name; ++k){
nucho 0:77afd7560544 76 inbuffer[k-1]=inbuffer[k];
nucho 0:77afd7560544 77 }
nucho 0:77afd7560544 78 inbuffer[offset+length_name-1]=0;
nucho 0:77afd7560544 79 this->name = (char *)(inbuffer + offset-1);
nucho 0:77afd7560544 80 offset += length_name;
nucho 0:77afd7560544 81 uint32_t length_message = *(uint32_t *)(inbuffer + offset);
nucho 0:77afd7560544 82 offset += 4;
nucho 0:77afd7560544 83 for(unsigned int k= offset; k< offset+length_message; ++k){
nucho 0:77afd7560544 84 inbuffer[k-1]=inbuffer[k];
nucho 0:77afd7560544 85 }
nucho 0:77afd7560544 86 inbuffer[offset+length_message-1]=0;
nucho 0:77afd7560544 87 this->message = (char *)(inbuffer + offset-1);
nucho 0:77afd7560544 88 offset += length_message;
nucho 0:77afd7560544 89 uint32_t length_hardware_id = *(uint32_t *)(inbuffer + offset);
nucho 0:77afd7560544 90 offset += 4;
nucho 0:77afd7560544 91 for(unsigned int k= offset; k< offset+length_hardware_id; ++k){
nucho 0:77afd7560544 92 inbuffer[k-1]=inbuffer[k];
nucho 0:77afd7560544 93 }
nucho 0:77afd7560544 94 inbuffer[offset+length_hardware_id-1]=0;
nucho 0:77afd7560544 95 this->hardware_id = (char *)(inbuffer + offset-1);
nucho 0:77afd7560544 96 offset += length_hardware_id;
nucho 0:77afd7560544 97 unsigned char values_lengthT = *(inbuffer + offset++);
nucho 0:77afd7560544 98 if(values_lengthT > values_length)
nucho 0:77afd7560544 99 this->values = (diagnostic_msgs::KeyValue*)realloc(this->values, values_lengthT * sizeof(diagnostic_msgs::KeyValue));
nucho 0:77afd7560544 100 offset += 3;
nucho 0:77afd7560544 101 values_length = values_lengthT;
nucho 0:77afd7560544 102 for( unsigned char i = 0; i < values_length; i++){
nucho 0:77afd7560544 103 offset += this->st_values.deserialize(inbuffer + offset);
nucho 0:77afd7560544 104 memcpy( &(this->values[i]), &(this->st_values), sizeof(diagnostic_msgs::KeyValue));
nucho 0:77afd7560544 105 }
nucho 0:77afd7560544 106 return offset;
nucho 0:77afd7560544 107 }
nucho 0:77afd7560544 108
nucho 0:77afd7560544 109 virtual const char * getType(){ return "diagnostic_msgs/DiagnosticStatus"; };
nucho 0:77afd7560544 110
nucho 0:77afd7560544 111 };
nucho 0:77afd7560544 112
nucho 0:77afd7560544 113 }
nucho 0:77afd7560544 114 #endif