rosserial library for mbed Inspired by nucho's rosserial library This library is still under development
Dependents: mbed_roshydro_test
Library still under development!
bond/Status.h@0:30537dec6e0b, 2015-02-15 (annotated)
- Committer:
- akashvibhute
- Date:
- Sun Feb 15 10:53:43 2015 +0000
- Revision:
- 0:30537dec6e0b
First commit; Library still need to be debugged, compilation issues with new mbed and modserial updates.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
akashvibhute | 0:30537dec6e0b | 1 | #ifndef _ROS_bond_Status_h |
akashvibhute | 0:30537dec6e0b | 2 | #define _ROS_bond_Status_h |
akashvibhute | 0:30537dec6e0b | 3 | |
akashvibhute | 0:30537dec6e0b | 4 | #include <stdint.h> |
akashvibhute | 0:30537dec6e0b | 5 | #include <string.h> |
akashvibhute | 0:30537dec6e0b | 6 | #include <stdlib.h> |
akashvibhute | 0:30537dec6e0b | 7 | #include "ros/msg.h" |
akashvibhute | 0:30537dec6e0b | 8 | #include "std_msgs/Header.h" |
akashvibhute | 0:30537dec6e0b | 9 | |
akashvibhute | 0:30537dec6e0b | 10 | namespace bond |
akashvibhute | 0:30537dec6e0b | 11 | { |
akashvibhute | 0:30537dec6e0b | 12 | |
akashvibhute | 0:30537dec6e0b | 13 | class Status : public ros::Msg |
akashvibhute | 0:30537dec6e0b | 14 | { |
akashvibhute | 0:30537dec6e0b | 15 | public: |
akashvibhute | 0:30537dec6e0b | 16 | std_msgs::Header header; |
akashvibhute | 0:30537dec6e0b | 17 | const char* id; |
akashvibhute | 0:30537dec6e0b | 18 | const char* instance_id; |
akashvibhute | 0:30537dec6e0b | 19 | bool active; |
akashvibhute | 0:30537dec6e0b | 20 | float heartbeat_timeout; |
akashvibhute | 0:30537dec6e0b | 21 | float heartbeat_period; |
akashvibhute | 0:30537dec6e0b | 22 | |
akashvibhute | 0:30537dec6e0b | 23 | Status(): |
akashvibhute | 0:30537dec6e0b | 24 | header(), |
akashvibhute | 0:30537dec6e0b | 25 | id(""), |
akashvibhute | 0:30537dec6e0b | 26 | instance_id(""), |
akashvibhute | 0:30537dec6e0b | 27 | active(0), |
akashvibhute | 0:30537dec6e0b | 28 | heartbeat_timeout(0), |
akashvibhute | 0:30537dec6e0b | 29 | heartbeat_period(0) |
akashvibhute | 0:30537dec6e0b | 30 | { |
akashvibhute | 0:30537dec6e0b | 31 | } |
akashvibhute | 0:30537dec6e0b | 32 | |
akashvibhute | 0:30537dec6e0b | 33 | virtual int serialize(unsigned char *outbuffer) const |
akashvibhute | 0:30537dec6e0b | 34 | { |
akashvibhute | 0:30537dec6e0b | 35 | int offset = 0; |
akashvibhute | 0:30537dec6e0b | 36 | offset += this->header.serialize(outbuffer + offset); |
akashvibhute | 0:30537dec6e0b | 37 | uint32_t length_id = strlen(this->id); |
akashvibhute | 0:30537dec6e0b | 38 | memcpy(outbuffer + offset, &length_id, sizeof(uint32_t)); |
akashvibhute | 0:30537dec6e0b | 39 | offset += 4; |
akashvibhute | 0:30537dec6e0b | 40 | memcpy(outbuffer + offset, this->id, length_id); |
akashvibhute | 0:30537dec6e0b | 41 | offset += length_id; |
akashvibhute | 0:30537dec6e0b | 42 | uint32_t length_instance_id = strlen(this->instance_id); |
akashvibhute | 0:30537dec6e0b | 43 | memcpy(outbuffer + offset, &length_instance_id, sizeof(uint32_t)); |
akashvibhute | 0:30537dec6e0b | 44 | offset += 4; |
akashvibhute | 0:30537dec6e0b | 45 | memcpy(outbuffer + offset, this->instance_id, length_instance_id); |
akashvibhute | 0:30537dec6e0b | 46 | offset += length_instance_id; |
akashvibhute | 0:30537dec6e0b | 47 | union { |
akashvibhute | 0:30537dec6e0b | 48 | bool real; |
akashvibhute | 0:30537dec6e0b | 49 | uint8_t base; |
akashvibhute | 0:30537dec6e0b | 50 | } u_active; |
akashvibhute | 0:30537dec6e0b | 51 | u_active.real = this->active; |
akashvibhute | 0:30537dec6e0b | 52 | *(outbuffer + offset + 0) = (u_active.base >> (8 * 0)) & 0xFF; |
akashvibhute | 0:30537dec6e0b | 53 | offset += sizeof(this->active); |
akashvibhute | 0:30537dec6e0b | 54 | union { |
akashvibhute | 0:30537dec6e0b | 55 | float real; |
akashvibhute | 0:30537dec6e0b | 56 | uint32_t base; |
akashvibhute | 0:30537dec6e0b | 57 | } u_heartbeat_timeout; |
akashvibhute | 0:30537dec6e0b | 58 | u_heartbeat_timeout.real = this->heartbeat_timeout; |
akashvibhute | 0:30537dec6e0b | 59 | *(outbuffer + offset + 0) = (u_heartbeat_timeout.base >> (8 * 0)) & 0xFF; |
akashvibhute | 0:30537dec6e0b | 60 | *(outbuffer + offset + 1) = (u_heartbeat_timeout.base >> (8 * 1)) & 0xFF; |
akashvibhute | 0:30537dec6e0b | 61 | *(outbuffer + offset + 2) = (u_heartbeat_timeout.base >> (8 * 2)) & 0xFF; |
akashvibhute | 0:30537dec6e0b | 62 | *(outbuffer + offset + 3) = (u_heartbeat_timeout.base >> (8 * 3)) & 0xFF; |
akashvibhute | 0:30537dec6e0b | 63 | offset += sizeof(this->heartbeat_timeout); |
akashvibhute | 0:30537dec6e0b | 64 | union { |
akashvibhute | 0:30537dec6e0b | 65 | float real; |
akashvibhute | 0:30537dec6e0b | 66 | uint32_t base; |
akashvibhute | 0:30537dec6e0b | 67 | } u_heartbeat_period; |
akashvibhute | 0:30537dec6e0b | 68 | u_heartbeat_period.real = this->heartbeat_period; |
akashvibhute | 0:30537dec6e0b | 69 | *(outbuffer + offset + 0) = (u_heartbeat_period.base >> (8 * 0)) & 0xFF; |
akashvibhute | 0:30537dec6e0b | 70 | *(outbuffer + offset + 1) = (u_heartbeat_period.base >> (8 * 1)) & 0xFF; |
akashvibhute | 0:30537dec6e0b | 71 | *(outbuffer + offset + 2) = (u_heartbeat_period.base >> (8 * 2)) & 0xFF; |
akashvibhute | 0:30537dec6e0b | 72 | *(outbuffer + offset + 3) = (u_heartbeat_period.base >> (8 * 3)) & 0xFF; |
akashvibhute | 0:30537dec6e0b | 73 | offset += sizeof(this->heartbeat_period); |
akashvibhute | 0:30537dec6e0b | 74 | return offset; |
akashvibhute | 0:30537dec6e0b | 75 | } |
akashvibhute | 0:30537dec6e0b | 76 | |
akashvibhute | 0:30537dec6e0b | 77 | virtual int deserialize(unsigned char *inbuffer) |
akashvibhute | 0:30537dec6e0b | 78 | { |
akashvibhute | 0:30537dec6e0b | 79 | int offset = 0; |
akashvibhute | 0:30537dec6e0b | 80 | offset += this->header.deserialize(inbuffer + offset); |
akashvibhute | 0:30537dec6e0b | 81 | uint32_t length_id; |
akashvibhute | 0:30537dec6e0b | 82 | memcpy(&length_id, (inbuffer + offset), sizeof(uint32_t)); |
akashvibhute | 0:30537dec6e0b | 83 | offset += 4; |
akashvibhute | 0:30537dec6e0b | 84 | for(unsigned int k= offset; k< offset+length_id; ++k){ |
akashvibhute | 0:30537dec6e0b | 85 | inbuffer[k-1]=inbuffer[k]; |
akashvibhute | 0:30537dec6e0b | 86 | } |
akashvibhute | 0:30537dec6e0b | 87 | inbuffer[offset+length_id-1]=0; |
akashvibhute | 0:30537dec6e0b | 88 | this->id = (char *)(inbuffer + offset-1); |
akashvibhute | 0:30537dec6e0b | 89 | offset += length_id; |
akashvibhute | 0:30537dec6e0b | 90 | uint32_t length_instance_id; |
akashvibhute | 0:30537dec6e0b | 91 | memcpy(&length_instance_id, (inbuffer + offset), sizeof(uint32_t)); |
akashvibhute | 0:30537dec6e0b | 92 | offset += 4; |
akashvibhute | 0:30537dec6e0b | 93 | for(unsigned int k= offset; k< offset+length_instance_id; ++k){ |
akashvibhute | 0:30537dec6e0b | 94 | inbuffer[k-1]=inbuffer[k]; |
akashvibhute | 0:30537dec6e0b | 95 | } |
akashvibhute | 0:30537dec6e0b | 96 | inbuffer[offset+length_instance_id-1]=0; |
akashvibhute | 0:30537dec6e0b | 97 | this->instance_id = (char *)(inbuffer + offset-1); |
akashvibhute | 0:30537dec6e0b | 98 | offset += length_instance_id; |
akashvibhute | 0:30537dec6e0b | 99 | union { |
akashvibhute | 0:30537dec6e0b | 100 | bool real; |
akashvibhute | 0:30537dec6e0b | 101 | uint8_t base; |
akashvibhute | 0:30537dec6e0b | 102 | } u_active; |
akashvibhute | 0:30537dec6e0b | 103 | u_active.base = 0; |
akashvibhute | 0:30537dec6e0b | 104 | u_active.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); |
akashvibhute | 0:30537dec6e0b | 105 | this->active = u_active.real; |
akashvibhute | 0:30537dec6e0b | 106 | offset += sizeof(this->active); |
akashvibhute | 0:30537dec6e0b | 107 | union { |
akashvibhute | 0:30537dec6e0b | 108 | float real; |
akashvibhute | 0:30537dec6e0b | 109 | uint32_t base; |
akashvibhute | 0:30537dec6e0b | 110 | } u_heartbeat_timeout; |
akashvibhute | 0:30537dec6e0b | 111 | u_heartbeat_timeout.base = 0; |
akashvibhute | 0:30537dec6e0b | 112 | u_heartbeat_timeout.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); |
akashvibhute | 0:30537dec6e0b | 113 | u_heartbeat_timeout.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); |
akashvibhute | 0:30537dec6e0b | 114 | u_heartbeat_timeout.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); |
akashvibhute | 0:30537dec6e0b | 115 | u_heartbeat_timeout.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); |
akashvibhute | 0:30537dec6e0b | 116 | this->heartbeat_timeout = u_heartbeat_timeout.real; |
akashvibhute | 0:30537dec6e0b | 117 | offset += sizeof(this->heartbeat_timeout); |
akashvibhute | 0:30537dec6e0b | 118 | union { |
akashvibhute | 0:30537dec6e0b | 119 | float real; |
akashvibhute | 0:30537dec6e0b | 120 | uint32_t base; |
akashvibhute | 0:30537dec6e0b | 121 | } u_heartbeat_period; |
akashvibhute | 0:30537dec6e0b | 122 | u_heartbeat_period.base = 0; |
akashvibhute | 0:30537dec6e0b | 123 | u_heartbeat_period.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); |
akashvibhute | 0:30537dec6e0b | 124 | u_heartbeat_period.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); |
akashvibhute | 0:30537dec6e0b | 125 | u_heartbeat_period.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); |
akashvibhute | 0:30537dec6e0b | 126 | u_heartbeat_period.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); |
akashvibhute | 0:30537dec6e0b | 127 | this->heartbeat_period = u_heartbeat_period.real; |
akashvibhute | 0:30537dec6e0b | 128 | offset += sizeof(this->heartbeat_period); |
akashvibhute | 0:30537dec6e0b | 129 | return offset; |
akashvibhute | 0:30537dec6e0b | 130 | } |
akashvibhute | 0:30537dec6e0b | 131 | |
akashvibhute | 0:30537dec6e0b | 132 | const char * getType(){ return "bond/Status"; }; |
akashvibhute | 0:30537dec6e0b | 133 | const char * getMD5(){ return "eacc84bf5d65b6777d4c50f463dfb9c8"; }; |
akashvibhute | 0:30537dec6e0b | 134 | |
akashvibhute | 0:30537dec6e0b | 135 | }; |
akashvibhute | 0:30537dec6e0b | 136 | |
akashvibhute | 0:30537dec6e0b | 137 | } |
akashvibhute | 0:30537dec6e0b | 138 | #endif |