ros melodic library with custom message

Dependents:   Robot_team1_QEI_Douglas Robot_team1

Committer:
florine_van
Date:
Tue Dec 03 09:39:29 2019 +0000
Revision:
3:b964e3f71102
Parent:
0:020db18a476d
Clean code and remove unused lines

Who changed what in which revision?

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