ros melodic library with custom message
Dependents: Robot_team1_QEI_Douglas Robot_team1
ros_lib/bond/Status.h@3:b964e3f71102, 2019-12-03 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
scarter1 | 0:020db18a476d | 1 | #ifndef _ROS_bond_Status_h |
scarter1 | 0:020db18a476d | 2 | #define _ROS_bond_Status_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 bond |
scarter1 | 0:020db18a476d | 11 | { |
scarter1 | 0:020db18a476d | 12 | |
scarter1 | 0:020db18a476d | 13 | class Status : 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 const char* _id_type; |
scarter1 | 0:020db18a476d | 19 | _id_type id; |
scarter1 | 0:020db18a476d | 20 | typedef const char* _instance_id_type; |
scarter1 | 0:020db18a476d | 21 | _instance_id_type instance_id; |
scarter1 | 0:020db18a476d | 22 | typedef bool _active_type; |
scarter1 | 0:020db18a476d | 23 | _active_type active; |
scarter1 | 0:020db18a476d | 24 | typedef float _heartbeat_timeout_type; |
scarter1 | 0:020db18a476d | 25 | _heartbeat_timeout_type heartbeat_timeout; |
scarter1 | 0:020db18a476d | 26 | typedef float _heartbeat_period_type; |
scarter1 | 0:020db18a476d | 27 | _heartbeat_period_type heartbeat_period; |
scarter1 | 0:020db18a476d | 28 | |
scarter1 | 0:020db18a476d | 29 | Status(): |
scarter1 | 0:020db18a476d | 30 | header(), |
scarter1 | 0:020db18a476d | 31 | id(""), |
scarter1 | 0:020db18a476d | 32 | instance_id(""), |
scarter1 | 0:020db18a476d | 33 | active(0), |
scarter1 | 0:020db18a476d | 34 | heartbeat_timeout(0), |
scarter1 | 0:020db18a476d | 35 | heartbeat_period(0) |
scarter1 | 0:020db18a476d | 36 | { |
scarter1 | 0:020db18a476d | 37 | } |
scarter1 | 0:020db18a476d | 38 | |
scarter1 | 0:020db18a476d | 39 | virtual int serialize(unsigned char *outbuffer) const |
scarter1 | 0:020db18a476d | 40 | { |
scarter1 | 0:020db18a476d | 41 | int offset = 0; |
scarter1 | 0:020db18a476d | 42 | offset += this->header.serialize(outbuffer + offset); |
scarter1 | 0:020db18a476d | 43 | uint32_t length_id = strlen(this->id); |
scarter1 | 0:020db18a476d | 44 | varToArr(outbuffer + offset, length_id); |
scarter1 | 0:020db18a476d | 45 | offset += 4; |
scarter1 | 0:020db18a476d | 46 | memcpy(outbuffer + offset, this->id, length_id); |
scarter1 | 0:020db18a476d | 47 | offset += length_id; |
scarter1 | 0:020db18a476d | 48 | uint32_t length_instance_id = strlen(this->instance_id); |
scarter1 | 0:020db18a476d | 49 | varToArr(outbuffer + offset, length_instance_id); |
scarter1 | 0:020db18a476d | 50 | offset += 4; |
scarter1 | 0:020db18a476d | 51 | memcpy(outbuffer + offset, this->instance_id, length_instance_id); |
scarter1 | 0:020db18a476d | 52 | offset += length_instance_id; |
scarter1 | 0:020db18a476d | 53 | union { |
scarter1 | 0:020db18a476d | 54 | bool real; |
scarter1 | 0:020db18a476d | 55 | uint8_t base; |
scarter1 | 0:020db18a476d | 56 | } u_active; |
scarter1 | 0:020db18a476d | 57 | u_active.real = this->active; |
scarter1 | 0:020db18a476d | 58 | *(outbuffer + offset + 0) = (u_active.base >> (8 * 0)) & 0xFF; |
scarter1 | 0:020db18a476d | 59 | offset += sizeof(this->active); |
scarter1 | 0:020db18a476d | 60 | union { |
scarter1 | 0:020db18a476d | 61 | float real; |
scarter1 | 0:020db18a476d | 62 | uint32_t base; |
scarter1 | 0:020db18a476d | 63 | } u_heartbeat_timeout; |
scarter1 | 0:020db18a476d | 64 | u_heartbeat_timeout.real = this->heartbeat_timeout; |
scarter1 | 0:020db18a476d | 65 | *(outbuffer + offset + 0) = (u_heartbeat_timeout.base >> (8 * 0)) & 0xFF; |
scarter1 | 0:020db18a476d | 66 | *(outbuffer + offset + 1) = (u_heartbeat_timeout.base >> (8 * 1)) & 0xFF; |
scarter1 | 0:020db18a476d | 67 | *(outbuffer + offset + 2) = (u_heartbeat_timeout.base >> (8 * 2)) & 0xFF; |
scarter1 | 0:020db18a476d | 68 | *(outbuffer + offset + 3) = (u_heartbeat_timeout.base >> (8 * 3)) & 0xFF; |
scarter1 | 0:020db18a476d | 69 | offset += sizeof(this->heartbeat_timeout); |
scarter1 | 0:020db18a476d | 70 | union { |
scarter1 | 0:020db18a476d | 71 | float real; |
scarter1 | 0:020db18a476d | 72 | uint32_t base; |
scarter1 | 0:020db18a476d | 73 | } u_heartbeat_period; |
scarter1 | 0:020db18a476d | 74 | u_heartbeat_period.real = this->heartbeat_period; |
scarter1 | 0:020db18a476d | 75 | *(outbuffer + offset + 0) = (u_heartbeat_period.base >> (8 * 0)) & 0xFF; |
scarter1 | 0:020db18a476d | 76 | *(outbuffer + offset + 1) = (u_heartbeat_period.base >> (8 * 1)) & 0xFF; |
scarter1 | 0:020db18a476d | 77 | *(outbuffer + offset + 2) = (u_heartbeat_period.base >> (8 * 2)) & 0xFF; |
scarter1 | 0:020db18a476d | 78 | *(outbuffer + offset + 3) = (u_heartbeat_period.base >> (8 * 3)) & 0xFF; |
scarter1 | 0:020db18a476d | 79 | offset += sizeof(this->heartbeat_period); |
scarter1 | 0:020db18a476d | 80 | return offset; |
scarter1 | 0:020db18a476d | 81 | } |
scarter1 | 0:020db18a476d | 82 | |
scarter1 | 0:020db18a476d | 83 | virtual int deserialize(unsigned char *inbuffer) |
scarter1 | 0:020db18a476d | 84 | { |
scarter1 | 0:020db18a476d | 85 | int offset = 0; |
scarter1 | 0:020db18a476d | 86 | offset += this->header.deserialize(inbuffer + offset); |
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 | uint32_t length_instance_id; |
scarter1 | 0:020db18a476d | 97 | arrToVar(length_instance_id, (inbuffer + offset)); |
scarter1 | 0:020db18a476d | 98 | offset += 4; |
scarter1 | 0:020db18a476d | 99 | for(unsigned int k= offset; k< offset+length_instance_id; ++k){ |
scarter1 | 0:020db18a476d | 100 | inbuffer[k-1]=inbuffer[k]; |
scarter1 | 0:020db18a476d | 101 | } |
scarter1 | 0:020db18a476d | 102 | inbuffer[offset+length_instance_id-1]=0; |
scarter1 | 0:020db18a476d | 103 | this->instance_id = (char *)(inbuffer + offset-1); |
scarter1 | 0:020db18a476d | 104 | offset += length_instance_id; |
scarter1 | 0:020db18a476d | 105 | union { |
scarter1 | 0:020db18a476d | 106 | bool real; |
scarter1 | 0:020db18a476d | 107 | uint8_t base; |
scarter1 | 0:020db18a476d | 108 | } u_active; |
scarter1 | 0:020db18a476d | 109 | u_active.base = 0; |
scarter1 | 0:020db18a476d | 110 | u_active.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); |
scarter1 | 0:020db18a476d | 111 | this->active = u_active.real; |
scarter1 | 0:020db18a476d | 112 | offset += sizeof(this->active); |
scarter1 | 0:020db18a476d | 113 | union { |
scarter1 | 0:020db18a476d | 114 | float real; |
scarter1 | 0:020db18a476d | 115 | uint32_t base; |
scarter1 | 0:020db18a476d | 116 | } u_heartbeat_timeout; |
scarter1 | 0:020db18a476d | 117 | u_heartbeat_timeout.base = 0; |
scarter1 | 0:020db18a476d | 118 | u_heartbeat_timeout.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); |
scarter1 | 0:020db18a476d | 119 | u_heartbeat_timeout.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); |
scarter1 | 0:020db18a476d | 120 | u_heartbeat_timeout.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); |
scarter1 | 0:020db18a476d | 121 | u_heartbeat_timeout.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); |
scarter1 | 0:020db18a476d | 122 | this->heartbeat_timeout = u_heartbeat_timeout.real; |
scarter1 | 0:020db18a476d | 123 | offset += sizeof(this->heartbeat_timeout); |
scarter1 | 0:020db18a476d | 124 | union { |
scarter1 | 0:020db18a476d | 125 | float real; |
scarter1 | 0:020db18a476d | 126 | uint32_t base; |
scarter1 | 0:020db18a476d | 127 | } u_heartbeat_period; |
scarter1 | 0:020db18a476d | 128 | u_heartbeat_period.base = 0; |
scarter1 | 0:020db18a476d | 129 | u_heartbeat_period.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); |
scarter1 | 0:020db18a476d | 130 | u_heartbeat_period.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); |
scarter1 | 0:020db18a476d | 131 | u_heartbeat_period.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); |
scarter1 | 0:020db18a476d | 132 | u_heartbeat_period.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); |
scarter1 | 0:020db18a476d | 133 | this->heartbeat_period = u_heartbeat_period.real; |
scarter1 | 0:020db18a476d | 134 | offset += sizeof(this->heartbeat_period); |
scarter1 | 0:020db18a476d | 135 | return offset; |
scarter1 | 0:020db18a476d | 136 | } |
scarter1 | 0:020db18a476d | 137 | |
scarter1 | 0:020db18a476d | 138 | const char * getType(){ return "bond/Status"; }; |
scarter1 | 0:020db18a476d | 139 | const char * getMD5(){ return "eacc84bf5d65b6777d4c50f463dfb9c8"; }; |
scarter1 | 0:020db18a476d | 140 | |
scarter1 | 0:020db18a476d | 141 | }; |
scarter1 | 0:020db18a476d | 142 | |
scarter1 | 0:020db18a476d | 143 | } |
scarter1 | 0:020db18a476d | 144 | #endif |