make changes on buffer serial
dynamic_reconfigure/Group.h@2:3f1139cf73be, 2021-05-19 (annotated)
- Committer:
- howanglam3
- Date:
- Wed May 19 09:50:43 2021 +0000
- Revision:
- 2:3f1139cf73be
- Parent:
- 0:04ac6be8229a
updated buffer serial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Gary Servin |
0:04ac6be8229a | 1 | #ifndef _ROS_dynamic_reconfigure_Group_h |
Gary Servin |
0:04ac6be8229a | 2 | #define _ROS_dynamic_reconfigure_Group_h |
Gary Servin |
0:04ac6be8229a | 3 | |
Gary Servin |
0:04ac6be8229a | 4 | #include <stdint.h> |
Gary Servin |
0:04ac6be8229a | 5 | #include <string.h> |
Gary Servin |
0:04ac6be8229a | 6 | #include <stdlib.h> |
Gary Servin |
0:04ac6be8229a | 7 | #include "ros/msg.h" |
Gary Servin |
0:04ac6be8229a | 8 | #include "dynamic_reconfigure/ParamDescription.h" |
Gary Servin |
0:04ac6be8229a | 9 | |
Gary Servin |
0:04ac6be8229a | 10 | namespace dynamic_reconfigure |
Gary Servin |
0:04ac6be8229a | 11 | { |
Gary Servin |
0:04ac6be8229a | 12 | |
Gary Servin |
0:04ac6be8229a | 13 | class Group : public ros::Msg |
Gary Servin |
0:04ac6be8229a | 14 | { |
Gary Servin |
0:04ac6be8229a | 15 | public: |
Gary Servin |
0:04ac6be8229a | 16 | typedef const char* _name_type; |
Gary Servin |
0:04ac6be8229a | 17 | _name_type name; |
Gary Servin |
0:04ac6be8229a | 18 | typedef const char* _type_type; |
Gary Servin |
0:04ac6be8229a | 19 | _type_type type; |
Gary Servin |
0:04ac6be8229a | 20 | uint32_t parameters_length; |
Gary Servin |
0:04ac6be8229a | 21 | typedef dynamic_reconfigure::ParamDescription _parameters_type; |
Gary Servin |
0:04ac6be8229a | 22 | _parameters_type st_parameters; |
Gary Servin |
0:04ac6be8229a | 23 | _parameters_type * parameters; |
Gary Servin |
0:04ac6be8229a | 24 | typedef int32_t _parent_type; |
Gary Servin |
0:04ac6be8229a | 25 | _parent_type parent; |
Gary Servin |
0:04ac6be8229a | 26 | typedef int32_t _id_type; |
Gary Servin |
0:04ac6be8229a | 27 | _id_type id; |
Gary Servin |
0:04ac6be8229a | 28 | |
Gary Servin |
0:04ac6be8229a | 29 | Group(): |
Gary Servin |
0:04ac6be8229a | 30 | name(""), |
Gary Servin |
0:04ac6be8229a | 31 | type(""), |
Gary Servin |
0:04ac6be8229a | 32 | parameters_length(0), parameters(NULL), |
Gary Servin |
0:04ac6be8229a | 33 | parent(0), |
Gary Servin |
0:04ac6be8229a | 34 | id(0) |
Gary Servin |
0:04ac6be8229a | 35 | { |
Gary Servin |
0:04ac6be8229a | 36 | } |
Gary Servin |
0:04ac6be8229a | 37 | |
Gary Servin |
0:04ac6be8229a | 38 | virtual int serialize(unsigned char *outbuffer) const |
Gary Servin |
0:04ac6be8229a | 39 | { |
Gary Servin |
0:04ac6be8229a | 40 | int offset = 0; |
Gary Servin |
0:04ac6be8229a | 41 | uint32_t length_name = strlen(this->name); |
Gary Servin |
0:04ac6be8229a | 42 | varToArr(outbuffer + offset, length_name); |
Gary Servin |
0:04ac6be8229a | 43 | offset += 4; |
Gary Servin |
0:04ac6be8229a | 44 | memcpy(outbuffer + offset, this->name, length_name); |
Gary Servin |
0:04ac6be8229a | 45 | offset += length_name; |
Gary Servin |
0:04ac6be8229a | 46 | uint32_t length_type = strlen(this->type); |
Gary Servin |
0:04ac6be8229a | 47 | varToArr(outbuffer + offset, length_type); |
Gary Servin |
0:04ac6be8229a | 48 | offset += 4; |
Gary Servin |
0:04ac6be8229a | 49 | memcpy(outbuffer + offset, this->type, length_type); |
Gary Servin |
0:04ac6be8229a | 50 | offset += length_type; |
Gary Servin |
0:04ac6be8229a | 51 | *(outbuffer + offset + 0) = (this->parameters_length >> (8 * 0)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 52 | *(outbuffer + offset + 1) = (this->parameters_length >> (8 * 1)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 53 | *(outbuffer + offset + 2) = (this->parameters_length >> (8 * 2)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 54 | *(outbuffer + offset + 3) = (this->parameters_length >> (8 * 3)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 55 | offset += sizeof(this->parameters_length); |
Gary Servin |
0:04ac6be8229a | 56 | for( uint32_t i = 0; i < parameters_length; i++){ |
Gary Servin |
0:04ac6be8229a | 57 | offset += this->parameters[i].serialize(outbuffer + offset); |
Gary Servin |
0:04ac6be8229a | 58 | } |
Gary Servin |
0:04ac6be8229a | 59 | union { |
Gary Servin |
0:04ac6be8229a | 60 | int32_t real; |
Gary Servin |
0:04ac6be8229a | 61 | uint32_t base; |
Gary Servin |
0:04ac6be8229a | 62 | } u_parent; |
Gary Servin |
0:04ac6be8229a | 63 | u_parent.real = this->parent; |
Gary Servin |
0:04ac6be8229a | 64 | *(outbuffer + offset + 0) = (u_parent.base >> (8 * 0)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 65 | *(outbuffer + offset + 1) = (u_parent.base >> (8 * 1)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 66 | *(outbuffer + offset + 2) = (u_parent.base >> (8 * 2)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 67 | *(outbuffer + offset + 3) = (u_parent.base >> (8 * 3)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 68 | offset += sizeof(this->parent); |
Gary Servin |
0:04ac6be8229a | 69 | union { |
Gary Servin |
0:04ac6be8229a | 70 | int32_t real; |
Gary Servin |
0:04ac6be8229a | 71 | uint32_t base; |
Gary Servin |
0:04ac6be8229a | 72 | } u_id; |
Gary Servin |
0:04ac6be8229a | 73 | u_id.real = this->id; |
Gary Servin |
0:04ac6be8229a | 74 | *(outbuffer + offset + 0) = (u_id.base >> (8 * 0)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 75 | *(outbuffer + offset + 1) = (u_id.base >> (8 * 1)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 76 | *(outbuffer + offset + 2) = (u_id.base >> (8 * 2)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 77 | *(outbuffer + offset + 3) = (u_id.base >> (8 * 3)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 78 | offset += sizeof(this->id); |
Gary Servin |
0:04ac6be8229a | 79 | return offset; |
Gary Servin |
0:04ac6be8229a | 80 | } |
Gary Servin |
0:04ac6be8229a | 81 | |
Gary Servin |
0:04ac6be8229a | 82 | virtual int deserialize(unsigned char *inbuffer) |
Gary Servin |
0:04ac6be8229a | 83 | { |
Gary Servin |
0:04ac6be8229a | 84 | int offset = 0; |
Gary Servin |
0:04ac6be8229a | 85 | uint32_t length_name; |
Gary Servin |
0:04ac6be8229a | 86 | arrToVar(length_name, (inbuffer + offset)); |
Gary Servin |
0:04ac6be8229a | 87 | offset += 4; |
Gary Servin |
0:04ac6be8229a | 88 | for(unsigned int k= offset; k< offset+length_name; ++k){ |
Gary Servin |
0:04ac6be8229a | 89 | inbuffer[k-1]=inbuffer[k]; |
Gary Servin |
0:04ac6be8229a | 90 | } |
Gary Servin |
0:04ac6be8229a | 91 | inbuffer[offset+length_name-1]=0; |
Gary Servin |
0:04ac6be8229a | 92 | this->name = (char *)(inbuffer + offset-1); |
Gary Servin |
0:04ac6be8229a | 93 | offset += length_name; |
Gary Servin |
0:04ac6be8229a | 94 | uint32_t length_type; |
Gary Servin |
0:04ac6be8229a | 95 | arrToVar(length_type, (inbuffer + offset)); |
Gary Servin |
0:04ac6be8229a | 96 | offset += 4; |
Gary Servin |
0:04ac6be8229a | 97 | for(unsigned int k= offset; k< offset+length_type; ++k){ |
Gary Servin |
0:04ac6be8229a | 98 | inbuffer[k-1]=inbuffer[k]; |
Gary Servin |
0:04ac6be8229a | 99 | } |
Gary Servin |
0:04ac6be8229a | 100 | inbuffer[offset+length_type-1]=0; |
Gary Servin |
0:04ac6be8229a | 101 | this->type = (char *)(inbuffer + offset-1); |
Gary Servin |
0:04ac6be8229a | 102 | offset += length_type; |
Gary Servin |
0:04ac6be8229a | 103 | uint32_t parameters_lengthT = ((uint32_t) (*(inbuffer + offset))); |
Gary Servin |
0:04ac6be8229a | 104 | parameters_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); |
Gary Servin |
0:04ac6be8229a | 105 | parameters_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); |
Gary Servin |
0:04ac6be8229a | 106 | parameters_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); |
Gary Servin |
0:04ac6be8229a | 107 | offset += sizeof(this->parameters_length); |
Gary Servin |
0:04ac6be8229a | 108 | if(parameters_lengthT > parameters_length) |
Gary Servin |
0:04ac6be8229a | 109 | this->parameters = (dynamic_reconfigure::ParamDescription*)realloc(this->parameters, parameters_lengthT * sizeof(dynamic_reconfigure::ParamDescription)); |
Gary Servin |
0:04ac6be8229a | 110 | parameters_length = parameters_lengthT; |
Gary Servin |
0:04ac6be8229a | 111 | for( uint32_t i = 0; i < parameters_length; i++){ |
Gary Servin |
0:04ac6be8229a | 112 | offset += this->st_parameters.deserialize(inbuffer + offset); |
Gary Servin |
0:04ac6be8229a | 113 | memcpy( &(this->parameters[i]), &(this->st_parameters), sizeof(dynamic_reconfigure::ParamDescription)); |
Gary Servin |
0:04ac6be8229a | 114 | } |
Gary Servin |
0:04ac6be8229a | 115 | union { |
Gary Servin |
0:04ac6be8229a | 116 | int32_t real; |
Gary Servin |
0:04ac6be8229a | 117 | uint32_t base; |
Gary Servin |
0:04ac6be8229a | 118 | } u_parent; |
Gary Servin |
0:04ac6be8229a | 119 | u_parent.base = 0; |
Gary Servin |
0:04ac6be8229a | 120 | u_parent.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); |
Gary Servin |
0:04ac6be8229a | 121 | u_parent.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); |
Gary Servin |
0:04ac6be8229a | 122 | u_parent.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); |
Gary Servin |
0:04ac6be8229a | 123 | u_parent.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); |
Gary Servin |
0:04ac6be8229a | 124 | this->parent = u_parent.real; |
Gary Servin |
0:04ac6be8229a | 125 | offset += sizeof(this->parent); |
Gary Servin |
0:04ac6be8229a | 126 | union { |
Gary Servin |
0:04ac6be8229a | 127 | int32_t real; |
Gary Servin |
0:04ac6be8229a | 128 | uint32_t base; |
Gary Servin |
0:04ac6be8229a | 129 | } u_id; |
Gary Servin |
0:04ac6be8229a | 130 | u_id.base = 0; |
Gary Servin |
0:04ac6be8229a | 131 | u_id.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); |
Gary Servin |
0:04ac6be8229a | 132 | u_id.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); |
Gary Servin |
0:04ac6be8229a | 133 | u_id.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); |
Gary Servin |
0:04ac6be8229a | 134 | u_id.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); |
Gary Servin |
0:04ac6be8229a | 135 | this->id = u_id.real; |
Gary Servin |
0:04ac6be8229a | 136 | offset += sizeof(this->id); |
Gary Servin |
0:04ac6be8229a | 137 | return offset; |
Gary Servin |
0:04ac6be8229a | 138 | } |
Gary Servin |
0:04ac6be8229a | 139 | |
Gary Servin |
0:04ac6be8229a | 140 | const char * getType(){ return "dynamic_reconfigure/Group"; }; |
Gary Servin |
0:04ac6be8229a | 141 | const char * getMD5(){ return "9e8cd9e9423c94823db3614dd8b1cf7a"; }; |
Gary Servin |
0:04ac6be8229a | 142 | |
Gary Servin |
0:04ac6be8229a | 143 | }; |
Gary Servin |
0:04ac6be8229a | 144 | |
Gary Servin |
0:04ac6be8229a | 145 | } |
Gary Servin |
0:04ac6be8229a | 146 | #endif |