make changes on buffer serial

Dependencies:   BufferedSerial

Dependents:  

Committer:
Gary Servin
Date:
Fri Nov 08 14:38:09 2019 -0300
Revision:
0:04ac6be8229a
Initial commit, generated based on a clean melodic-desktop-full

Who changed what in which revision?

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