rosserial library for mbed Inspired by nucho's rosserial library This library is still under development

Dependencies:   MODSERIAL mbed

Dependents:   mbed_roshydro_test

Library still under development!

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?

UserRevisionLine numberNew contents of line
akashvibhute 0:30537dec6e0b 1 #ifndef _ROS_SERVICE_GetPolledImage_h
akashvibhute 0:30537dec6e0b 2 #define _ROS_SERVICE_GetPolledImage_h
akashvibhute 0:30537dec6e0b 3 #include <stdint.h>
akashvibhute 0:30537dec6e0b 4 #include <string.h>
akashvibhute 0:30537dec6e0b 5 #include <stdlib.h>
akashvibhute 0:30537dec6e0b 6 #include "ros/msg.h"
akashvibhute 0:30537dec6e0b 7 #include "sensor_msgs/RegionOfInterest.h"
akashvibhute 0:30537dec6e0b 8 #include "ros/duration.h"
akashvibhute 0:30537dec6e0b 9 #include "ros/time.h"
akashvibhute 0:30537dec6e0b 10
akashvibhute 0:30537dec6e0b 11 namespace polled_camera
akashvibhute 0:30537dec6e0b 12 {
akashvibhute 0:30537dec6e0b 13
akashvibhute 0:30537dec6e0b 14 static const char GETPOLLEDIMAGE[] = "polled_camera/GetPolledImage";
akashvibhute 0:30537dec6e0b 15
akashvibhute 0:30537dec6e0b 16 class GetPolledImageRequest : public ros::Msg
akashvibhute 0:30537dec6e0b 17 {
akashvibhute 0:30537dec6e0b 18 public:
akashvibhute 0:30537dec6e0b 19 const char* response_namespace;
akashvibhute 0:30537dec6e0b 20 ros::Duration timeout;
akashvibhute 0:30537dec6e0b 21 uint32_t binning_x;
akashvibhute 0:30537dec6e0b 22 uint32_t binning_y;
akashvibhute 0:30537dec6e0b 23 sensor_msgs::RegionOfInterest roi;
akashvibhute 0:30537dec6e0b 24
akashvibhute 0:30537dec6e0b 25 GetPolledImageRequest():
akashvibhute 0:30537dec6e0b 26 response_namespace(""),
akashvibhute 0:30537dec6e0b 27 timeout(),
akashvibhute 0:30537dec6e0b 28 binning_x(0),
akashvibhute 0:30537dec6e0b 29 binning_y(0),
akashvibhute 0:30537dec6e0b 30 roi()
akashvibhute 0:30537dec6e0b 31 {
akashvibhute 0:30537dec6e0b 32 }
akashvibhute 0:30537dec6e0b 33
akashvibhute 0:30537dec6e0b 34 virtual int serialize(unsigned char *outbuffer) const
akashvibhute 0:30537dec6e0b 35 {
akashvibhute 0:30537dec6e0b 36 int offset = 0;
akashvibhute 0:30537dec6e0b 37 uint32_t length_response_namespace = strlen(this->response_namespace);
akashvibhute 0:30537dec6e0b 38 memcpy(outbuffer + offset, &length_response_namespace, sizeof(uint32_t));
akashvibhute 0:30537dec6e0b 39 offset += 4;
akashvibhute 0:30537dec6e0b 40 memcpy(outbuffer + offset, this->response_namespace, length_response_namespace);
akashvibhute 0:30537dec6e0b 41 offset += length_response_namespace;
akashvibhute 0:30537dec6e0b 42 *(outbuffer + offset + 0) = (this->timeout.sec >> (8 * 0)) & 0xFF;
akashvibhute 0:30537dec6e0b 43 *(outbuffer + offset + 1) = (this->timeout.sec >> (8 * 1)) & 0xFF;
akashvibhute 0:30537dec6e0b 44 *(outbuffer + offset + 2) = (this->timeout.sec >> (8 * 2)) & 0xFF;
akashvibhute 0:30537dec6e0b 45 *(outbuffer + offset + 3) = (this->timeout.sec >> (8 * 3)) & 0xFF;
akashvibhute 0:30537dec6e0b 46 offset += sizeof(this->timeout.sec);
akashvibhute 0:30537dec6e0b 47 *(outbuffer + offset + 0) = (this->timeout.nsec >> (8 * 0)) & 0xFF;
akashvibhute 0:30537dec6e0b 48 *(outbuffer + offset + 1) = (this->timeout.nsec >> (8 * 1)) & 0xFF;
akashvibhute 0:30537dec6e0b 49 *(outbuffer + offset + 2) = (this->timeout.nsec >> (8 * 2)) & 0xFF;
akashvibhute 0:30537dec6e0b 50 *(outbuffer + offset + 3) = (this->timeout.nsec >> (8 * 3)) & 0xFF;
akashvibhute 0:30537dec6e0b 51 offset += sizeof(this->timeout.nsec);
akashvibhute 0:30537dec6e0b 52 *(outbuffer + offset + 0) = (this->binning_x >> (8 * 0)) & 0xFF;
akashvibhute 0:30537dec6e0b 53 *(outbuffer + offset + 1) = (this->binning_x >> (8 * 1)) & 0xFF;
akashvibhute 0:30537dec6e0b 54 *(outbuffer + offset + 2) = (this->binning_x >> (8 * 2)) & 0xFF;
akashvibhute 0:30537dec6e0b 55 *(outbuffer + offset + 3) = (this->binning_x >> (8 * 3)) & 0xFF;
akashvibhute 0:30537dec6e0b 56 offset += sizeof(this->binning_x);
akashvibhute 0:30537dec6e0b 57 *(outbuffer + offset + 0) = (this->binning_y >> (8 * 0)) & 0xFF;
akashvibhute 0:30537dec6e0b 58 *(outbuffer + offset + 1) = (this->binning_y >> (8 * 1)) & 0xFF;
akashvibhute 0:30537dec6e0b 59 *(outbuffer + offset + 2) = (this->binning_y >> (8 * 2)) & 0xFF;
akashvibhute 0:30537dec6e0b 60 *(outbuffer + offset + 3) = (this->binning_y >> (8 * 3)) & 0xFF;
akashvibhute 0:30537dec6e0b 61 offset += sizeof(this->binning_y);
akashvibhute 0:30537dec6e0b 62 offset += this->roi.serialize(outbuffer + offset);
akashvibhute 0:30537dec6e0b 63 return offset;
akashvibhute 0:30537dec6e0b 64 }
akashvibhute 0:30537dec6e0b 65
akashvibhute 0:30537dec6e0b 66 virtual int deserialize(unsigned char *inbuffer)
akashvibhute 0:30537dec6e0b 67 {
akashvibhute 0:30537dec6e0b 68 int offset = 0;
akashvibhute 0:30537dec6e0b 69 uint32_t length_response_namespace;
akashvibhute 0:30537dec6e0b 70 memcpy(&length_response_namespace, (inbuffer + offset), sizeof(uint32_t));
akashvibhute 0:30537dec6e0b 71 offset += 4;
akashvibhute 0:30537dec6e0b 72 for(unsigned int k= offset; k< offset+length_response_namespace; ++k){
akashvibhute 0:30537dec6e0b 73 inbuffer[k-1]=inbuffer[k];
akashvibhute 0:30537dec6e0b 74 }
akashvibhute 0:30537dec6e0b 75 inbuffer[offset+length_response_namespace-1]=0;
akashvibhute 0:30537dec6e0b 76 this->response_namespace = (char *)(inbuffer + offset-1);
akashvibhute 0:30537dec6e0b 77 offset += length_response_namespace;
akashvibhute 0:30537dec6e0b 78 this->timeout.sec = ((uint32_t) (*(inbuffer + offset)));
akashvibhute 0:30537dec6e0b 79 this->timeout.sec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
akashvibhute 0:30537dec6e0b 80 this->timeout.sec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
akashvibhute 0:30537dec6e0b 81 this->timeout.sec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
akashvibhute 0:30537dec6e0b 82 offset += sizeof(this->timeout.sec);
akashvibhute 0:30537dec6e0b 83 this->timeout.nsec = ((uint32_t) (*(inbuffer + offset)));
akashvibhute 0:30537dec6e0b 84 this->timeout.nsec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
akashvibhute 0:30537dec6e0b 85 this->timeout.nsec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
akashvibhute 0:30537dec6e0b 86 this->timeout.nsec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
akashvibhute 0:30537dec6e0b 87 offset += sizeof(this->timeout.nsec);
akashvibhute 0:30537dec6e0b 88 this->binning_x = ((uint32_t) (*(inbuffer + offset)));
akashvibhute 0:30537dec6e0b 89 this->binning_x |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
akashvibhute 0:30537dec6e0b 90 this->binning_x |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
akashvibhute 0:30537dec6e0b 91 this->binning_x |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
akashvibhute 0:30537dec6e0b 92 offset += sizeof(this->binning_x);
akashvibhute 0:30537dec6e0b 93 this->binning_y = ((uint32_t) (*(inbuffer + offset)));
akashvibhute 0:30537dec6e0b 94 this->binning_y |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
akashvibhute 0:30537dec6e0b 95 this->binning_y |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
akashvibhute 0:30537dec6e0b 96 this->binning_y |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
akashvibhute 0:30537dec6e0b 97 offset += sizeof(this->binning_y);
akashvibhute 0:30537dec6e0b 98 offset += this->roi.deserialize(inbuffer + offset);
akashvibhute 0:30537dec6e0b 99 return offset;
akashvibhute 0:30537dec6e0b 100 }
akashvibhute 0:30537dec6e0b 101
akashvibhute 0:30537dec6e0b 102 const char * getType(){ return GETPOLLEDIMAGE; };
akashvibhute 0:30537dec6e0b 103 const char * getMD5(){ return "c77ed43e530fd48e9e7a2a93845e154c"; };
akashvibhute 0:30537dec6e0b 104
akashvibhute 0:30537dec6e0b 105 };
akashvibhute 0:30537dec6e0b 106
akashvibhute 0:30537dec6e0b 107 class GetPolledImageResponse : public ros::Msg
akashvibhute 0:30537dec6e0b 108 {
akashvibhute 0:30537dec6e0b 109 public:
akashvibhute 0:30537dec6e0b 110 bool success;
akashvibhute 0:30537dec6e0b 111 const char* status_message;
akashvibhute 0:30537dec6e0b 112 ros::Time stamp;
akashvibhute 0:30537dec6e0b 113
akashvibhute 0:30537dec6e0b 114 GetPolledImageResponse():
akashvibhute 0:30537dec6e0b 115 success(0),
akashvibhute 0:30537dec6e0b 116 status_message(""),
akashvibhute 0:30537dec6e0b 117 stamp()
akashvibhute 0:30537dec6e0b 118 {
akashvibhute 0:30537dec6e0b 119 }
akashvibhute 0:30537dec6e0b 120
akashvibhute 0:30537dec6e0b 121 virtual int serialize(unsigned char *outbuffer) const
akashvibhute 0:30537dec6e0b 122 {
akashvibhute 0:30537dec6e0b 123 int offset = 0;
akashvibhute 0:30537dec6e0b 124 union {
akashvibhute 0:30537dec6e0b 125 bool real;
akashvibhute 0:30537dec6e0b 126 uint8_t base;
akashvibhute 0:30537dec6e0b 127 } u_success;
akashvibhute 0:30537dec6e0b 128 u_success.real = this->success;
akashvibhute 0:30537dec6e0b 129 *(outbuffer + offset + 0) = (u_success.base >> (8 * 0)) & 0xFF;
akashvibhute 0:30537dec6e0b 130 offset += sizeof(this->success);
akashvibhute 0:30537dec6e0b 131 uint32_t length_status_message = strlen(this->status_message);
akashvibhute 0:30537dec6e0b 132 memcpy(outbuffer + offset, &length_status_message, sizeof(uint32_t));
akashvibhute 0:30537dec6e0b 133 offset += 4;
akashvibhute 0:30537dec6e0b 134 memcpy(outbuffer + offset, this->status_message, length_status_message);
akashvibhute 0:30537dec6e0b 135 offset += length_status_message;
akashvibhute 0:30537dec6e0b 136 *(outbuffer + offset + 0) = (this->stamp.sec >> (8 * 0)) & 0xFF;
akashvibhute 0:30537dec6e0b 137 *(outbuffer + offset + 1) = (this->stamp.sec >> (8 * 1)) & 0xFF;
akashvibhute 0:30537dec6e0b 138 *(outbuffer + offset + 2) = (this->stamp.sec >> (8 * 2)) & 0xFF;
akashvibhute 0:30537dec6e0b 139 *(outbuffer + offset + 3) = (this->stamp.sec >> (8 * 3)) & 0xFF;
akashvibhute 0:30537dec6e0b 140 offset += sizeof(this->stamp.sec);
akashvibhute 0:30537dec6e0b 141 *(outbuffer + offset + 0) = (this->stamp.nsec >> (8 * 0)) & 0xFF;
akashvibhute 0:30537dec6e0b 142 *(outbuffer + offset + 1) = (this->stamp.nsec >> (8 * 1)) & 0xFF;
akashvibhute 0:30537dec6e0b 143 *(outbuffer + offset + 2) = (this->stamp.nsec >> (8 * 2)) & 0xFF;
akashvibhute 0:30537dec6e0b 144 *(outbuffer + offset + 3) = (this->stamp.nsec >> (8 * 3)) & 0xFF;
akashvibhute 0:30537dec6e0b 145 offset += sizeof(this->stamp.nsec);
akashvibhute 0:30537dec6e0b 146 return offset;
akashvibhute 0:30537dec6e0b 147 }
akashvibhute 0:30537dec6e0b 148
akashvibhute 0:30537dec6e0b 149 virtual int deserialize(unsigned char *inbuffer)
akashvibhute 0:30537dec6e0b 150 {
akashvibhute 0:30537dec6e0b 151 int offset = 0;
akashvibhute 0:30537dec6e0b 152 union {
akashvibhute 0:30537dec6e0b 153 bool real;
akashvibhute 0:30537dec6e0b 154 uint8_t base;
akashvibhute 0:30537dec6e0b 155 } u_success;
akashvibhute 0:30537dec6e0b 156 u_success.base = 0;
akashvibhute 0:30537dec6e0b 157 u_success.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0);
akashvibhute 0:30537dec6e0b 158 this->success = u_success.real;
akashvibhute 0:30537dec6e0b 159 offset += sizeof(this->success);
akashvibhute 0:30537dec6e0b 160 uint32_t length_status_message;
akashvibhute 0:30537dec6e0b 161 memcpy(&length_status_message, (inbuffer + offset), sizeof(uint32_t));
akashvibhute 0:30537dec6e0b 162 offset += 4;
akashvibhute 0:30537dec6e0b 163 for(unsigned int k= offset; k< offset+length_status_message; ++k){
akashvibhute 0:30537dec6e0b 164 inbuffer[k-1]=inbuffer[k];
akashvibhute 0:30537dec6e0b 165 }
akashvibhute 0:30537dec6e0b 166 inbuffer[offset+length_status_message-1]=0;
akashvibhute 0:30537dec6e0b 167 this->status_message = (char *)(inbuffer + offset-1);
akashvibhute 0:30537dec6e0b 168 offset += length_status_message;
akashvibhute 0:30537dec6e0b 169 this->stamp.sec = ((uint32_t) (*(inbuffer + offset)));
akashvibhute 0:30537dec6e0b 170 this->stamp.sec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
akashvibhute 0:30537dec6e0b 171 this->stamp.sec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
akashvibhute 0:30537dec6e0b 172 this->stamp.sec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
akashvibhute 0:30537dec6e0b 173 offset += sizeof(this->stamp.sec);
akashvibhute 0:30537dec6e0b 174 this->stamp.nsec = ((uint32_t) (*(inbuffer + offset)));
akashvibhute 0:30537dec6e0b 175 this->stamp.nsec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
akashvibhute 0:30537dec6e0b 176 this->stamp.nsec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
akashvibhute 0:30537dec6e0b 177 this->stamp.nsec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
akashvibhute 0:30537dec6e0b 178 offset += sizeof(this->stamp.nsec);
akashvibhute 0:30537dec6e0b 179 return offset;
akashvibhute 0:30537dec6e0b 180 }
akashvibhute 0:30537dec6e0b 181
akashvibhute 0:30537dec6e0b 182 const char * getType(){ return GETPOLLEDIMAGE; };
akashvibhute 0:30537dec6e0b 183 const char * getMD5(){ return "dbf1f851bc511800e6129ccd5a3542ab"; };
akashvibhute 0:30537dec6e0b 184
akashvibhute 0:30537dec6e0b 185 };
akashvibhute 0:30537dec6e0b 186
akashvibhute 0:30537dec6e0b 187 class GetPolledImage {
akashvibhute 0:30537dec6e0b 188 public:
akashvibhute 0:30537dec6e0b 189 typedef GetPolledImageRequest Request;
akashvibhute 0:30537dec6e0b 190 typedef GetPolledImageResponse Response;
akashvibhute 0:30537dec6e0b 191 };
akashvibhute 0:30537dec6e0b 192
akashvibhute 0:30537dec6e0b 193 }
akashvibhute 0:30537dec6e0b 194 #endif
akashvibhute 0:30537dec6e0b 195