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_SERVICE_SelfTest_h
scarter1 0:020db18a476d 2 #define _ROS_SERVICE_SelfTest_h
scarter1 0:020db18a476d 3 #include <stdint.h>
scarter1 0:020db18a476d 4 #include <string.h>
scarter1 0:020db18a476d 5 #include <stdlib.h>
scarter1 0:020db18a476d 6 #include "ros/msg.h"
scarter1 0:020db18a476d 7 #include "diagnostic_msgs/DiagnosticStatus.h"
scarter1 0:020db18a476d 8
scarter1 0:020db18a476d 9 namespace diagnostic_msgs
scarter1 0:020db18a476d 10 {
scarter1 0:020db18a476d 11
scarter1 0:020db18a476d 12 static const char SELFTEST[] = "diagnostic_msgs/SelfTest";
scarter1 0:020db18a476d 13
scarter1 0:020db18a476d 14 class SelfTestRequest : public ros::Msg
scarter1 0:020db18a476d 15 {
scarter1 0:020db18a476d 16 public:
scarter1 0:020db18a476d 17
scarter1 0:020db18a476d 18 SelfTestRequest()
scarter1 0:020db18a476d 19 {
scarter1 0:020db18a476d 20 }
scarter1 0:020db18a476d 21
scarter1 0:020db18a476d 22 virtual int serialize(unsigned char *outbuffer) const
scarter1 0:020db18a476d 23 {
scarter1 0:020db18a476d 24 int offset = 0;
scarter1 0:020db18a476d 25 return offset;
scarter1 0:020db18a476d 26 }
scarter1 0:020db18a476d 27
scarter1 0:020db18a476d 28 virtual int deserialize(unsigned char *inbuffer)
scarter1 0:020db18a476d 29 {
scarter1 0:020db18a476d 30 int offset = 0;
scarter1 0:020db18a476d 31 return offset;
scarter1 0:020db18a476d 32 }
scarter1 0:020db18a476d 33
scarter1 0:020db18a476d 34 const char * getType(){ return SELFTEST; };
scarter1 0:020db18a476d 35 const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; };
scarter1 0:020db18a476d 36
scarter1 0:020db18a476d 37 };
scarter1 0:020db18a476d 38
scarter1 0:020db18a476d 39 class SelfTestResponse : public ros::Msg
scarter1 0:020db18a476d 40 {
scarter1 0:020db18a476d 41 public:
scarter1 0:020db18a476d 42 typedef const char* _id_type;
scarter1 0:020db18a476d 43 _id_type id;
scarter1 0:020db18a476d 44 typedef int8_t _passed_type;
scarter1 0:020db18a476d 45 _passed_type passed;
scarter1 0:020db18a476d 46 uint32_t status_length;
scarter1 0:020db18a476d 47 typedef diagnostic_msgs::DiagnosticStatus _status_type;
scarter1 0:020db18a476d 48 _status_type st_status;
scarter1 0:020db18a476d 49 _status_type * status;
scarter1 0:020db18a476d 50
scarter1 0:020db18a476d 51 SelfTestResponse():
scarter1 0:020db18a476d 52 id(""),
scarter1 0:020db18a476d 53 passed(0),
scarter1 0:020db18a476d 54 status_length(0), status(NULL)
scarter1 0:020db18a476d 55 {
scarter1 0:020db18a476d 56 }
scarter1 0:020db18a476d 57
scarter1 0:020db18a476d 58 virtual int serialize(unsigned char *outbuffer) const
scarter1 0:020db18a476d 59 {
scarter1 0:020db18a476d 60 int offset = 0;
scarter1 0:020db18a476d 61 uint32_t length_id = strlen(this->id);
scarter1 0:020db18a476d 62 varToArr(outbuffer + offset, length_id);
scarter1 0:020db18a476d 63 offset += 4;
scarter1 0:020db18a476d 64 memcpy(outbuffer + offset, this->id, length_id);
scarter1 0:020db18a476d 65 offset += length_id;
scarter1 0:020db18a476d 66 union {
scarter1 0:020db18a476d 67 int8_t real;
scarter1 0:020db18a476d 68 uint8_t base;
scarter1 0:020db18a476d 69 } u_passed;
scarter1 0:020db18a476d 70 u_passed.real = this->passed;
scarter1 0:020db18a476d 71 *(outbuffer + offset + 0) = (u_passed.base >> (8 * 0)) & 0xFF;
scarter1 0:020db18a476d 72 offset += sizeof(this->passed);
scarter1 0:020db18a476d 73 *(outbuffer + offset + 0) = (this->status_length >> (8 * 0)) & 0xFF;
scarter1 0:020db18a476d 74 *(outbuffer + offset + 1) = (this->status_length >> (8 * 1)) & 0xFF;
scarter1 0:020db18a476d 75 *(outbuffer + offset + 2) = (this->status_length >> (8 * 2)) & 0xFF;
scarter1 0:020db18a476d 76 *(outbuffer + offset + 3) = (this->status_length >> (8 * 3)) & 0xFF;
scarter1 0:020db18a476d 77 offset += sizeof(this->status_length);
scarter1 0:020db18a476d 78 for( uint32_t i = 0; i < status_length; i++){
scarter1 0:020db18a476d 79 offset += this->status[i].serialize(outbuffer + offset);
scarter1 0:020db18a476d 80 }
scarter1 0:020db18a476d 81 return offset;
scarter1 0:020db18a476d 82 }
scarter1 0:020db18a476d 83
scarter1 0:020db18a476d 84 virtual int deserialize(unsigned char *inbuffer)
scarter1 0:020db18a476d 85 {
scarter1 0:020db18a476d 86 int offset = 0;
scarter1 0:020db18a476d 87 uint32_t length_id;
scarter1 0:020db18a476d 88 arrToVar(length_id, (inbuffer + offset));
scarter1 0:020db18a476d 89 offset += 4;
scarter1 0:020db18a476d 90 for(unsigned int k= offset; k< offset+length_id; ++k){
scarter1 0:020db18a476d 91 inbuffer[k-1]=inbuffer[k];
scarter1 0:020db18a476d 92 }
scarter1 0:020db18a476d 93 inbuffer[offset+length_id-1]=0;
scarter1 0:020db18a476d 94 this->id = (char *)(inbuffer + offset-1);
scarter1 0:020db18a476d 95 offset += length_id;
scarter1 0:020db18a476d 96 union {
scarter1 0:020db18a476d 97 int8_t real;
scarter1 0:020db18a476d 98 uint8_t base;
scarter1 0:020db18a476d 99 } u_passed;
scarter1 0:020db18a476d 100 u_passed.base = 0;
scarter1 0:020db18a476d 101 u_passed.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0);
scarter1 0:020db18a476d 102 this->passed = u_passed.real;
scarter1 0:020db18a476d 103 offset += sizeof(this->passed);
scarter1 0:020db18a476d 104 uint32_t status_lengthT = ((uint32_t) (*(inbuffer + offset)));
scarter1 0:020db18a476d 105 status_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
scarter1 0:020db18a476d 106 status_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
scarter1 0:020db18a476d 107 status_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
scarter1 0:020db18a476d 108 offset += sizeof(this->status_length);
scarter1 0:020db18a476d 109 if(status_lengthT > status_length)
scarter1 0:020db18a476d 110 this->status = (diagnostic_msgs::DiagnosticStatus*)realloc(this->status, status_lengthT * sizeof(diagnostic_msgs::DiagnosticStatus));
scarter1 0:020db18a476d 111 status_length = status_lengthT;
scarter1 0:020db18a476d 112 for( uint32_t i = 0; i < status_length; i++){
scarter1 0:020db18a476d 113 offset += this->st_status.deserialize(inbuffer + offset);
scarter1 0:020db18a476d 114 memcpy( &(this->status[i]), &(this->st_status), sizeof(diagnostic_msgs::DiagnosticStatus));
scarter1 0:020db18a476d 115 }
scarter1 0:020db18a476d 116 return offset;
scarter1 0:020db18a476d 117 }
scarter1 0:020db18a476d 118
scarter1 0:020db18a476d 119 const char * getType(){ return SELFTEST; };
scarter1 0:020db18a476d 120 const char * getMD5(){ return "ac21b1bab7ab17546986536c22eb34e9"; };
scarter1 0:020db18a476d 121
scarter1 0:020db18a476d 122 };
scarter1 0:020db18a476d 123
scarter1 0:020db18a476d 124 class SelfTest {
scarter1 0:020db18a476d 125 public:
scarter1 0:020db18a476d 126 typedef SelfTestRequest Request;
scarter1 0:020db18a476d 127 typedef SelfTestResponse Response;
scarter1 0:020db18a476d 128 };
scarter1 0:020db18a476d 129
scarter1 0:020db18a476d 130 }
scarter1 0:020db18a476d 131 #endif