ROS Serial library for Mbed platforms for ROS Kinetic Kame. Check http://wiki.ros.org/rosserial_mbed/ for more information.

Dependencies:   BufferedSerial

Dependents:   mbed-os-example-blinky

Committer:
fllay
Date:
Thu Aug 01 17:08:55 2019 +0000
Revision:
2:f2240ad62eaf
Parent:
0:9e9b7db60fd5
fix time.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
garyservin 0:9e9b7db60fd5 1 #ifndef _ROS_bond_Status_h
garyservin 0:9e9b7db60fd5 2 #define _ROS_bond_Status_h
garyservin 0:9e9b7db60fd5 3
garyservin 0:9e9b7db60fd5 4 #include <stdint.h>
garyservin 0:9e9b7db60fd5 5 #include <string.h>
garyservin 0:9e9b7db60fd5 6 #include <stdlib.h>
garyservin 0:9e9b7db60fd5 7 #include "ros/msg.h"
garyservin 0:9e9b7db60fd5 8 #include "std_msgs/Header.h"
garyservin 0:9e9b7db60fd5 9
garyservin 0:9e9b7db60fd5 10 namespace bond
garyservin 0:9e9b7db60fd5 11 {
garyservin 0:9e9b7db60fd5 12
garyservin 0:9e9b7db60fd5 13 class Status : public ros::Msg
garyservin 0:9e9b7db60fd5 14 {
garyservin 0:9e9b7db60fd5 15 public:
garyservin 0:9e9b7db60fd5 16 typedef std_msgs::Header _header_type;
garyservin 0:9e9b7db60fd5 17 _header_type header;
garyservin 0:9e9b7db60fd5 18 typedef const char* _id_type;
garyservin 0:9e9b7db60fd5 19 _id_type id;
garyservin 0:9e9b7db60fd5 20 typedef const char* _instance_id_type;
garyservin 0:9e9b7db60fd5 21 _instance_id_type instance_id;
garyservin 0:9e9b7db60fd5 22 typedef bool _active_type;
garyservin 0:9e9b7db60fd5 23 _active_type active;
garyservin 0:9e9b7db60fd5 24 typedef float _heartbeat_timeout_type;
garyservin 0:9e9b7db60fd5 25 _heartbeat_timeout_type heartbeat_timeout;
garyservin 0:9e9b7db60fd5 26 typedef float _heartbeat_period_type;
garyservin 0:9e9b7db60fd5 27 _heartbeat_period_type heartbeat_period;
garyservin 0:9e9b7db60fd5 28
garyservin 0:9e9b7db60fd5 29 Status():
garyservin 0:9e9b7db60fd5 30 header(),
garyservin 0:9e9b7db60fd5 31 id(""),
garyservin 0:9e9b7db60fd5 32 instance_id(""),
garyservin 0:9e9b7db60fd5 33 active(0),
garyservin 0:9e9b7db60fd5 34 heartbeat_timeout(0),
garyservin 0:9e9b7db60fd5 35 heartbeat_period(0)
garyservin 0:9e9b7db60fd5 36 {
garyservin 0:9e9b7db60fd5 37 }
garyservin 0:9e9b7db60fd5 38
garyservin 0:9e9b7db60fd5 39 virtual int serialize(unsigned char *outbuffer) const
garyservin 0:9e9b7db60fd5 40 {
garyservin 0:9e9b7db60fd5 41 int offset = 0;
garyservin 0:9e9b7db60fd5 42 offset += this->header.serialize(outbuffer + offset);
garyservin 0:9e9b7db60fd5 43 uint32_t length_id = strlen(this->id);
garyservin 0:9e9b7db60fd5 44 varToArr(outbuffer + offset, length_id);
garyservin 0:9e9b7db60fd5 45 offset += 4;
garyservin 0:9e9b7db60fd5 46 memcpy(outbuffer + offset, this->id, length_id);
garyservin 0:9e9b7db60fd5 47 offset += length_id;
garyservin 0:9e9b7db60fd5 48 uint32_t length_instance_id = strlen(this->instance_id);
garyservin 0:9e9b7db60fd5 49 varToArr(outbuffer + offset, length_instance_id);
garyservin 0:9e9b7db60fd5 50 offset += 4;
garyservin 0:9e9b7db60fd5 51 memcpy(outbuffer + offset, this->instance_id, length_instance_id);
garyservin 0:9e9b7db60fd5 52 offset += length_instance_id;
garyservin 0:9e9b7db60fd5 53 union {
garyservin 0:9e9b7db60fd5 54 bool real;
garyservin 0:9e9b7db60fd5 55 uint8_t base;
garyservin 0:9e9b7db60fd5 56 } u_active;
garyservin 0:9e9b7db60fd5 57 u_active.real = this->active;
garyservin 0:9e9b7db60fd5 58 *(outbuffer + offset + 0) = (u_active.base >> (8 * 0)) & 0xFF;
garyservin 0:9e9b7db60fd5 59 offset += sizeof(this->active);
garyservin 0:9e9b7db60fd5 60 union {
garyservin 0:9e9b7db60fd5 61 float real;
garyservin 0:9e9b7db60fd5 62 uint32_t base;
garyservin 0:9e9b7db60fd5 63 } u_heartbeat_timeout;
garyservin 0:9e9b7db60fd5 64 u_heartbeat_timeout.real = this->heartbeat_timeout;
garyservin 0:9e9b7db60fd5 65 *(outbuffer + offset + 0) = (u_heartbeat_timeout.base >> (8 * 0)) & 0xFF;
garyservin 0:9e9b7db60fd5 66 *(outbuffer + offset + 1) = (u_heartbeat_timeout.base >> (8 * 1)) & 0xFF;
garyservin 0:9e9b7db60fd5 67 *(outbuffer + offset + 2) = (u_heartbeat_timeout.base >> (8 * 2)) & 0xFF;
garyservin 0:9e9b7db60fd5 68 *(outbuffer + offset + 3) = (u_heartbeat_timeout.base >> (8 * 3)) & 0xFF;
garyservin 0:9e9b7db60fd5 69 offset += sizeof(this->heartbeat_timeout);
garyservin 0:9e9b7db60fd5 70 union {
garyservin 0:9e9b7db60fd5 71 float real;
garyservin 0:9e9b7db60fd5 72 uint32_t base;
garyservin 0:9e9b7db60fd5 73 } u_heartbeat_period;
garyservin 0:9e9b7db60fd5 74 u_heartbeat_period.real = this->heartbeat_period;
garyservin 0:9e9b7db60fd5 75 *(outbuffer + offset + 0) = (u_heartbeat_period.base >> (8 * 0)) & 0xFF;
garyservin 0:9e9b7db60fd5 76 *(outbuffer + offset + 1) = (u_heartbeat_period.base >> (8 * 1)) & 0xFF;
garyservin 0:9e9b7db60fd5 77 *(outbuffer + offset + 2) = (u_heartbeat_period.base >> (8 * 2)) & 0xFF;
garyservin 0:9e9b7db60fd5 78 *(outbuffer + offset + 3) = (u_heartbeat_period.base >> (8 * 3)) & 0xFF;
garyservin 0:9e9b7db60fd5 79 offset += sizeof(this->heartbeat_period);
garyservin 0:9e9b7db60fd5 80 return offset;
garyservin 0:9e9b7db60fd5 81 }
garyservin 0:9e9b7db60fd5 82
garyservin 0:9e9b7db60fd5 83 virtual int deserialize(unsigned char *inbuffer)
garyservin 0:9e9b7db60fd5 84 {
garyservin 0:9e9b7db60fd5 85 int offset = 0;
garyservin 0:9e9b7db60fd5 86 offset += this->header.deserialize(inbuffer + offset);
garyservin 0:9e9b7db60fd5 87 uint32_t length_id;
garyservin 0:9e9b7db60fd5 88 arrToVar(length_id, (inbuffer + offset));
garyservin 0:9e9b7db60fd5 89 offset += 4;
garyservin 0:9e9b7db60fd5 90 for(unsigned int k= offset; k< offset+length_id; ++k){
garyservin 0:9e9b7db60fd5 91 inbuffer[k-1]=inbuffer[k];
garyservin 0:9e9b7db60fd5 92 }
garyservin 0:9e9b7db60fd5 93 inbuffer[offset+length_id-1]=0;
garyservin 0:9e9b7db60fd5 94 this->id = (char *)(inbuffer + offset-1);
garyservin 0:9e9b7db60fd5 95 offset += length_id;
garyservin 0:9e9b7db60fd5 96 uint32_t length_instance_id;
garyservin 0:9e9b7db60fd5 97 arrToVar(length_instance_id, (inbuffer + offset));
garyservin 0:9e9b7db60fd5 98 offset += 4;
garyservin 0:9e9b7db60fd5 99 for(unsigned int k= offset; k< offset+length_instance_id; ++k){
garyservin 0:9e9b7db60fd5 100 inbuffer[k-1]=inbuffer[k];
garyservin 0:9e9b7db60fd5 101 }
garyservin 0:9e9b7db60fd5 102 inbuffer[offset+length_instance_id-1]=0;
garyservin 0:9e9b7db60fd5 103 this->instance_id = (char *)(inbuffer + offset-1);
garyservin 0:9e9b7db60fd5 104 offset += length_instance_id;
garyservin 0:9e9b7db60fd5 105 union {
garyservin 0:9e9b7db60fd5 106 bool real;
garyservin 0:9e9b7db60fd5 107 uint8_t base;
garyservin 0:9e9b7db60fd5 108 } u_active;
garyservin 0:9e9b7db60fd5 109 u_active.base = 0;
garyservin 0:9e9b7db60fd5 110 u_active.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0);
garyservin 0:9e9b7db60fd5 111 this->active = u_active.real;
garyservin 0:9e9b7db60fd5 112 offset += sizeof(this->active);
garyservin 0:9e9b7db60fd5 113 union {
garyservin 0:9e9b7db60fd5 114 float real;
garyservin 0:9e9b7db60fd5 115 uint32_t base;
garyservin 0:9e9b7db60fd5 116 } u_heartbeat_timeout;
garyservin 0:9e9b7db60fd5 117 u_heartbeat_timeout.base = 0;
garyservin 0:9e9b7db60fd5 118 u_heartbeat_timeout.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
garyservin 0:9e9b7db60fd5 119 u_heartbeat_timeout.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
garyservin 0:9e9b7db60fd5 120 u_heartbeat_timeout.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
garyservin 0:9e9b7db60fd5 121 u_heartbeat_timeout.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
garyservin 0:9e9b7db60fd5 122 this->heartbeat_timeout = u_heartbeat_timeout.real;
garyservin 0:9e9b7db60fd5 123 offset += sizeof(this->heartbeat_timeout);
garyservin 0:9e9b7db60fd5 124 union {
garyservin 0:9e9b7db60fd5 125 float real;
garyservin 0:9e9b7db60fd5 126 uint32_t base;
garyservin 0:9e9b7db60fd5 127 } u_heartbeat_period;
garyservin 0:9e9b7db60fd5 128 u_heartbeat_period.base = 0;
garyservin 0:9e9b7db60fd5 129 u_heartbeat_period.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
garyservin 0:9e9b7db60fd5 130 u_heartbeat_period.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
garyservin 0:9e9b7db60fd5 131 u_heartbeat_period.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
garyservin 0:9e9b7db60fd5 132 u_heartbeat_period.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
garyservin 0:9e9b7db60fd5 133 this->heartbeat_period = u_heartbeat_period.real;
garyservin 0:9e9b7db60fd5 134 offset += sizeof(this->heartbeat_period);
garyservin 0:9e9b7db60fd5 135 return offset;
garyservin 0:9e9b7db60fd5 136 }
garyservin 0:9e9b7db60fd5 137
garyservin 0:9e9b7db60fd5 138 const char * getType(){ return "bond/Status"; };
garyservin 0:9e9b7db60fd5 139 const char * getMD5(){ return "eacc84bf5d65b6777d4c50f463dfb9c8"; };
garyservin 0:9e9b7db60fd5 140
garyservin 0:9e9b7db60fd5 141 };
garyservin 0:9e9b7db60fd5 142
garyservin 0:9e9b7db60fd5 143 }
garyservin 0:9e9b7db60fd5 144 #endif