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_rosgraph_msgs_Log_h
scarter1 0:020db18a476d 2 #define _ROS_rosgraph_msgs_Log_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 "std_msgs/Header.h"
scarter1 0:020db18a476d 9
scarter1 0:020db18a476d 10 namespace rosgraph_msgs
scarter1 0:020db18a476d 11 {
scarter1 0:020db18a476d 12
scarter1 0:020db18a476d 13 class Log : public ros::Msg
scarter1 0:020db18a476d 14 {
scarter1 0:020db18a476d 15 public:
scarter1 0:020db18a476d 16 typedef std_msgs::Header _header_type;
scarter1 0:020db18a476d 17 _header_type header;
scarter1 0:020db18a476d 18 typedef int8_t _level_type;
scarter1 0:020db18a476d 19 _level_type level;
scarter1 0:020db18a476d 20 typedef const char* _name_type;
scarter1 0:020db18a476d 21 _name_type name;
scarter1 0:020db18a476d 22 typedef const char* _msg_type;
scarter1 0:020db18a476d 23 _msg_type msg;
scarter1 0:020db18a476d 24 typedef const char* _file_type;
scarter1 0:020db18a476d 25 _file_type file;
scarter1 0:020db18a476d 26 typedef const char* _function_type;
scarter1 0:020db18a476d 27 _function_type function;
scarter1 0:020db18a476d 28 typedef uint32_t _line_type;
scarter1 0:020db18a476d 29 _line_type line;
scarter1 0:020db18a476d 30 uint32_t topics_length;
scarter1 0:020db18a476d 31 typedef char* _topics_type;
scarter1 0:020db18a476d 32 _topics_type st_topics;
scarter1 0:020db18a476d 33 _topics_type * topics;
scarter1 0:020db18a476d 34 enum { DEBUG = 1 };
scarter1 0:020db18a476d 35 enum { INFO = 2 };
scarter1 0:020db18a476d 36 enum { WARN = 4 };
scarter1 0:020db18a476d 37 enum { ERROR = 8 };
scarter1 0:020db18a476d 38 enum { FATAL = 16 };
scarter1 0:020db18a476d 39
scarter1 0:020db18a476d 40 Log():
scarter1 0:020db18a476d 41 header(),
scarter1 0:020db18a476d 42 level(0),
scarter1 0:020db18a476d 43 name(""),
scarter1 0:020db18a476d 44 msg(""),
scarter1 0:020db18a476d 45 file(""),
scarter1 0:020db18a476d 46 function(""),
scarter1 0:020db18a476d 47 line(0),
scarter1 0:020db18a476d 48 topics_length(0), topics(NULL)
scarter1 0:020db18a476d 49 {
scarter1 0:020db18a476d 50 }
scarter1 0:020db18a476d 51
scarter1 0:020db18a476d 52 virtual int serialize(unsigned char *outbuffer) const
scarter1 0:020db18a476d 53 {
scarter1 0:020db18a476d 54 int offset = 0;
scarter1 0:020db18a476d 55 offset += this->header.serialize(outbuffer + offset);
scarter1 0:020db18a476d 56 union {
scarter1 0:020db18a476d 57 int8_t real;
scarter1 0:020db18a476d 58 uint8_t base;
scarter1 0:020db18a476d 59 } u_level;
scarter1 0:020db18a476d 60 u_level.real = this->level;
scarter1 0:020db18a476d 61 *(outbuffer + offset + 0) = (u_level.base >> (8 * 0)) & 0xFF;
scarter1 0:020db18a476d 62 offset += sizeof(this->level);
scarter1 0:020db18a476d 63 uint32_t length_name = strlen(this->name);
scarter1 0:020db18a476d 64 varToArr(outbuffer + offset, length_name);
scarter1 0:020db18a476d 65 offset += 4;
scarter1 0:020db18a476d 66 memcpy(outbuffer + offset, this->name, length_name);
scarter1 0:020db18a476d 67 offset += length_name;
scarter1 0:020db18a476d 68 uint32_t length_msg = strlen(this->msg);
scarter1 0:020db18a476d 69 varToArr(outbuffer + offset, length_msg);
scarter1 0:020db18a476d 70 offset += 4;
scarter1 0:020db18a476d 71 memcpy(outbuffer + offset, this->msg, length_msg);
scarter1 0:020db18a476d 72 offset += length_msg;
scarter1 0:020db18a476d 73 uint32_t length_file = strlen(this->file);
scarter1 0:020db18a476d 74 varToArr(outbuffer + offset, length_file);
scarter1 0:020db18a476d 75 offset += 4;
scarter1 0:020db18a476d 76 memcpy(outbuffer + offset, this->file, length_file);
scarter1 0:020db18a476d 77 offset += length_file;
scarter1 0:020db18a476d 78 uint32_t length_function = strlen(this->function);
scarter1 0:020db18a476d 79 varToArr(outbuffer + offset, length_function);
scarter1 0:020db18a476d 80 offset += 4;
scarter1 0:020db18a476d 81 memcpy(outbuffer + offset, this->function, length_function);
scarter1 0:020db18a476d 82 offset += length_function;
scarter1 0:020db18a476d 83 *(outbuffer + offset + 0) = (this->line >> (8 * 0)) & 0xFF;
scarter1 0:020db18a476d 84 *(outbuffer + offset + 1) = (this->line >> (8 * 1)) & 0xFF;
scarter1 0:020db18a476d 85 *(outbuffer + offset + 2) = (this->line >> (8 * 2)) & 0xFF;
scarter1 0:020db18a476d 86 *(outbuffer + offset + 3) = (this->line >> (8 * 3)) & 0xFF;
scarter1 0:020db18a476d 87 offset += sizeof(this->line);
scarter1 0:020db18a476d 88 *(outbuffer + offset + 0) = (this->topics_length >> (8 * 0)) & 0xFF;
scarter1 0:020db18a476d 89 *(outbuffer + offset + 1) = (this->topics_length >> (8 * 1)) & 0xFF;
scarter1 0:020db18a476d 90 *(outbuffer + offset + 2) = (this->topics_length >> (8 * 2)) & 0xFF;
scarter1 0:020db18a476d 91 *(outbuffer + offset + 3) = (this->topics_length >> (8 * 3)) & 0xFF;
scarter1 0:020db18a476d 92 offset += sizeof(this->topics_length);
scarter1 0:020db18a476d 93 for( uint32_t i = 0; i < topics_length; i++){
scarter1 0:020db18a476d 94 uint32_t length_topicsi = strlen(this->topics[i]);
scarter1 0:020db18a476d 95 varToArr(outbuffer + offset, length_topicsi);
scarter1 0:020db18a476d 96 offset += 4;
scarter1 0:020db18a476d 97 memcpy(outbuffer + offset, this->topics[i], length_topicsi);
scarter1 0:020db18a476d 98 offset += length_topicsi;
scarter1 0:020db18a476d 99 }
scarter1 0:020db18a476d 100 return offset;
scarter1 0:020db18a476d 101 }
scarter1 0:020db18a476d 102
scarter1 0:020db18a476d 103 virtual int deserialize(unsigned char *inbuffer)
scarter1 0:020db18a476d 104 {
scarter1 0:020db18a476d 105 int offset = 0;
scarter1 0:020db18a476d 106 offset += this->header.deserialize(inbuffer + offset);
scarter1 0:020db18a476d 107 union {
scarter1 0:020db18a476d 108 int8_t real;
scarter1 0:020db18a476d 109 uint8_t base;
scarter1 0:020db18a476d 110 } u_level;
scarter1 0:020db18a476d 111 u_level.base = 0;
scarter1 0:020db18a476d 112 u_level.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0);
scarter1 0:020db18a476d 113 this->level = u_level.real;
scarter1 0:020db18a476d 114 offset += sizeof(this->level);
scarter1 0:020db18a476d 115 uint32_t length_name;
scarter1 0:020db18a476d 116 arrToVar(length_name, (inbuffer + offset));
scarter1 0:020db18a476d 117 offset += 4;
scarter1 0:020db18a476d 118 for(unsigned int k= offset; k< offset+length_name; ++k){
scarter1 0:020db18a476d 119 inbuffer[k-1]=inbuffer[k];
scarter1 0:020db18a476d 120 }
scarter1 0:020db18a476d 121 inbuffer[offset+length_name-1]=0;
scarter1 0:020db18a476d 122 this->name = (char *)(inbuffer + offset-1);
scarter1 0:020db18a476d 123 offset += length_name;
scarter1 0:020db18a476d 124 uint32_t length_msg;
scarter1 0:020db18a476d 125 arrToVar(length_msg, (inbuffer + offset));
scarter1 0:020db18a476d 126 offset += 4;
scarter1 0:020db18a476d 127 for(unsigned int k= offset; k< offset+length_msg; ++k){
scarter1 0:020db18a476d 128 inbuffer[k-1]=inbuffer[k];
scarter1 0:020db18a476d 129 }
scarter1 0:020db18a476d 130 inbuffer[offset+length_msg-1]=0;
scarter1 0:020db18a476d 131 this->msg = (char *)(inbuffer + offset-1);
scarter1 0:020db18a476d 132 offset += length_msg;
scarter1 0:020db18a476d 133 uint32_t length_file;
scarter1 0:020db18a476d 134 arrToVar(length_file, (inbuffer + offset));
scarter1 0:020db18a476d 135 offset += 4;
scarter1 0:020db18a476d 136 for(unsigned int k= offset; k< offset+length_file; ++k){
scarter1 0:020db18a476d 137 inbuffer[k-1]=inbuffer[k];
scarter1 0:020db18a476d 138 }
scarter1 0:020db18a476d 139 inbuffer[offset+length_file-1]=0;
scarter1 0:020db18a476d 140 this->file = (char *)(inbuffer + offset-1);
scarter1 0:020db18a476d 141 offset += length_file;
scarter1 0:020db18a476d 142 uint32_t length_function;
scarter1 0:020db18a476d 143 arrToVar(length_function, (inbuffer + offset));
scarter1 0:020db18a476d 144 offset += 4;
scarter1 0:020db18a476d 145 for(unsigned int k= offset; k< offset+length_function; ++k){
scarter1 0:020db18a476d 146 inbuffer[k-1]=inbuffer[k];
scarter1 0:020db18a476d 147 }
scarter1 0:020db18a476d 148 inbuffer[offset+length_function-1]=0;
scarter1 0:020db18a476d 149 this->function = (char *)(inbuffer + offset-1);
scarter1 0:020db18a476d 150 offset += length_function;
scarter1 0:020db18a476d 151 this->line = ((uint32_t) (*(inbuffer + offset)));
scarter1 0:020db18a476d 152 this->line |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
scarter1 0:020db18a476d 153 this->line |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
scarter1 0:020db18a476d 154 this->line |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
scarter1 0:020db18a476d 155 offset += sizeof(this->line);
scarter1 0:020db18a476d 156 uint32_t topics_lengthT = ((uint32_t) (*(inbuffer + offset)));
scarter1 0:020db18a476d 157 topics_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
scarter1 0:020db18a476d 158 topics_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
scarter1 0:020db18a476d 159 topics_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
scarter1 0:020db18a476d 160 offset += sizeof(this->topics_length);
scarter1 0:020db18a476d 161 if(topics_lengthT > topics_length)
scarter1 0:020db18a476d 162 this->topics = (char**)realloc(this->topics, topics_lengthT * sizeof(char*));
scarter1 0:020db18a476d 163 topics_length = topics_lengthT;
scarter1 0:020db18a476d 164 for( uint32_t i = 0; i < topics_length; i++){
scarter1 0:020db18a476d 165 uint32_t length_st_topics;
scarter1 0:020db18a476d 166 arrToVar(length_st_topics, (inbuffer + offset));
scarter1 0:020db18a476d 167 offset += 4;
scarter1 0:020db18a476d 168 for(unsigned int k= offset; k< offset+length_st_topics; ++k){
scarter1 0:020db18a476d 169 inbuffer[k-1]=inbuffer[k];
scarter1 0:020db18a476d 170 }
scarter1 0:020db18a476d 171 inbuffer[offset+length_st_topics-1]=0;
scarter1 0:020db18a476d 172 this->st_topics = (char *)(inbuffer + offset-1);
scarter1 0:020db18a476d 173 offset += length_st_topics;
scarter1 0:020db18a476d 174 memcpy( &(this->topics[i]), &(this->st_topics), sizeof(char*));
scarter1 0:020db18a476d 175 }
scarter1 0:020db18a476d 176 return offset;
scarter1 0:020db18a476d 177 }
scarter1 0:020db18a476d 178
scarter1 0:020db18a476d 179 const char * getType(){ return "rosgraph_msgs/Log"; };
scarter1 0:020db18a476d 180 const char * getMD5(){ return "acffd30cd6b6de30f120938c17c593fb"; };
scarter1 0:020db18a476d 181
scarter1 0:020db18a476d 182 };
scarter1 0:020db18a476d 183
scarter1 0:020db18a476d 184 }
scarter1 0:020db18a476d 185 #endif