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_SwitchController_h
akashvibhute 0:30537dec6e0b 2 #define _ROS_SERVICE_SwitchController_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
akashvibhute 0:30537dec6e0b 8 namespace controller_manager_msgs
akashvibhute 0:30537dec6e0b 9 {
akashvibhute 0:30537dec6e0b 10
akashvibhute 0:30537dec6e0b 11 static const char SWITCHCONTROLLER[] = "controller_manager_msgs/SwitchController";
akashvibhute 0:30537dec6e0b 12
akashvibhute 0:30537dec6e0b 13 class SwitchControllerRequest : public ros::Msg
akashvibhute 0:30537dec6e0b 14 {
akashvibhute 0:30537dec6e0b 15 public:
akashvibhute 0:30537dec6e0b 16 uint8_t start_controllers_length;
akashvibhute 0:30537dec6e0b 17 char* st_start_controllers;
akashvibhute 0:30537dec6e0b 18 char* * start_controllers;
akashvibhute 0:30537dec6e0b 19 uint8_t stop_controllers_length;
akashvibhute 0:30537dec6e0b 20 char* st_stop_controllers;
akashvibhute 0:30537dec6e0b 21 char* * stop_controllers;
akashvibhute 0:30537dec6e0b 22 int32_t strictness;
akashvibhute 0:30537dec6e0b 23 enum { BEST_EFFORT = 1 };
akashvibhute 0:30537dec6e0b 24 enum { STRICT = 2 };
akashvibhute 0:30537dec6e0b 25
akashvibhute 0:30537dec6e0b 26 SwitchControllerRequest():
akashvibhute 0:30537dec6e0b 27 start_controllers_length(0), start_controllers(NULL),
akashvibhute 0:30537dec6e0b 28 stop_controllers_length(0), stop_controllers(NULL),
akashvibhute 0:30537dec6e0b 29 strictness(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 *(outbuffer + offset++) = start_controllers_length;
akashvibhute 0:30537dec6e0b 37 *(outbuffer + offset++) = 0;
akashvibhute 0:30537dec6e0b 38 *(outbuffer + offset++) = 0;
akashvibhute 0:30537dec6e0b 39 *(outbuffer + offset++) = 0;
akashvibhute 0:30537dec6e0b 40 for( uint8_t i = 0; i < start_controllers_length; i++){
akashvibhute 0:30537dec6e0b 41 uint32_t length_start_controllersi = strlen(this->start_controllers[i]);
akashvibhute 0:30537dec6e0b 42 memcpy(outbuffer + offset, &length_start_controllersi, sizeof(uint32_t));
akashvibhute 0:30537dec6e0b 43 offset += 4;
akashvibhute 0:30537dec6e0b 44 memcpy(outbuffer + offset, this->start_controllers[i], length_start_controllersi);
akashvibhute 0:30537dec6e0b 45 offset += length_start_controllersi;
akashvibhute 0:30537dec6e0b 46 }
akashvibhute 0:30537dec6e0b 47 *(outbuffer + offset++) = stop_controllers_length;
akashvibhute 0:30537dec6e0b 48 *(outbuffer + offset++) = 0;
akashvibhute 0:30537dec6e0b 49 *(outbuffer + offset++) = 0;
akashvibhute 0:30537dec6e0b 50 *(outbuffer + offset++) = 0;
akashvibhute 0:30537dec6e0b 51 for( uint8_t i = 0; i < stop_controllers_length; i++){
akashvibhute 0:30537dec6e0b 52 uint32_t length_stop_controllersi = strlen(this->stop_controllers[i]);
akashvibhute 0:30537dec6e0b 53 memcpy(outbuffer + offset, &length_stop_controllersi, sizeof(uint32_t));
akashvibhute 0:30537dec6e0b 54 offset += 4;
akashvibhute 0:30537dec6e0b 55 memcpy(outbuffer + offset, this->stop_controllers[i], length_stop_controllersi);
akashvibhute 0:30537dec6e0b 56 offset += length_stop_controllersi;
akashvibhute 0:30537dec6e0b 57 }
akashvibhute 0:30537dec6e0b 58 union {
akashvibhute 0:30537dec6e0b 59 int32_t real;
akashvibhute 0:30537dec6e0b 60 uint32_t base;
akashvibhute 0:30537dec6e0b 61 } u_strictness;
akashvibhute 0:30537dec6e0b 62 u_strictness.real = this->strictness;
akashvibhute 0:30537dec6e0b 63 *(outbuffer + offset + 0) = (u_strictness.base >> (8 * 0)) & 0xFF;
akashvibhute 0:30537dec6e0b 64 *(outbuffer + offset + 1) = (u_strictness.base >> (8 * 1)) & 0xFF;
akashvibhute 0:30537dec6e0b 65 *(outbuffer + offset + 2) = (u_strictness.base >> (8 * 2)) & 0xFF;
akashvibhute 0:30537dec6e0b 66 *(outbuffer + offset + 3) = (u_strictness.base >> (8 * 3)) & 0xFF;
akashvibhute 0:30537dec6e0b 67 offset += sizeof(this->strictness);
akashvibhute 0:30537dec6e0b 68 return offset;
akashvibhute 0:30537dec6e0b 69 }
akashvibhute 0:30537dec6e0b 70
akashvibhute 0:30537dec6e0b 71 virtual int deserialize(unsigned char *inbuffer)
akashvibhute 0:30537dec6e0b 72 {
akashvibhute 0:30537dec6e0b 73 int offset = 0;
akashvibhute 0:30537dec6e0b 74 uint8_t start_controllers_lengthT = *(inbuffer + offset++);
akashvibhute 0:30537dec6e0b 75 if(start_controllers_lengthT > start_controllers_length)
akashvibhute 0:30537dec6e0b 76 this->start_controllers = (char**)realloc(this->start_controllers, start_controllers_lengthT * sizeof(char*));
akashvibhute 0:30537dec6e0b 77 offset += 3;
akashvibhute 0:30537dec6e0b 78 start_controllers_length = start_controllers_lengthT;
akashvibhute 0:30537dec6e0b 79 for( uint8_t i = 0; i < start_controllers_length; i++){
akashvibhute 0:30537dec6e0b 80 uint32_t length_st_start_controllers;
akashvibhute 0:30537dec6e0b 81 memcpy(&length_st_start_controllers, (inbuffer + offset), sizeof(uint32_t));
akashvibhute 0:30537dec6e0b 82 offset += 4;
akashvibhute 0:30537dec6e0b 83 for(unsigned int k= offset; k< offset+length_st_start_controllers; ++k){
akashvibhute 0:30537dec6e0b 84 inbuffer[k-1]=inbuffer[k];
akashvibhute 0:30537dec6e0b 85 }
akashvibhute 0:30537dec6e0b 86 inbuffer[offset+length_st_start_controllers-1]=0;
akashvibhute 0:30537dec6e0b 87 this->st_start_controllers = (char *)(inbuffer + offset-1);
akashvibhute 0:30537dec6e0b 88 offset += length_st_start_controllers;
akashvibhute 0:30537dec6e0b 89 memcpy( &(this->start_controllers[i]), &(this->st_start_controllers), sizeof(char*));
akashvibhute 0:30537dec6e0b 90 }
akashvibhute 0:30537dec6e0b 91 uint8_t stop_controllers_lengthT = *(inbuffer + offset++);
akashvibhute 0:30537dec6e0b 92 if(stop_controllers_lengthT > stop_controllers_length)
akashvibhute 0:30537dec6e0b 93 this->stop_controllers = (char**)realloc(this->stop_controllers, stop_controllers_lengthT * sizeof(char*));
akashvibhute 0:30537dec6e0b 94 offset += 3;
akashvibhute 0:30537dec6e0b 95 stop_controllers_length = stop_controllers_lengthT;
akashvibhute 0:30537dec6e0b 96 for( uint8_t i = 0; i < stop_controllers_length; i++){
akashvibhute 0:30537dec6e0b 97 uint32_t length_st_stop_controllers;
akashvibhute 0:30537dec6e0b 98 memcpy(&length_st_stop_controllers, (inbuffer + offset), sizeof(uint32_t));
akashvibhute 0:30537dec6e0b 99 offset += 4;
akashvibhute 0:30537dec6e0b 100 for(unsigned int k= offset; k< offset+length_st_stop_controllers; ++k){
akashvibhute 0:30537dec6e0b 101 inbuffer[k-1]=inbuffer[k];
akashvibhute 0:30537dec6e0b 102 }
akashvibhute 0:30537dec6e0b 103 inbuffer[offset+length_st_stop_controllers-1]=0;
akashvibhute 0:30537dec6e0b 104 this->st_stop_controllers = (char *)(inbuffer + offset-1);
akashvibhute 0:30537dec6e0b 105 offset += length_st_stop_controllers;
akashvibhute 0:30537dec6e0b 106 memcpy( &(this->stop_controllers[i]), &(this->st_stop_controllers), sizeof(char*));
akashvibhute 0:30537dec6e0b 107 }
akashvibhute 0:30537dec6e0b 108 union {
akashvibhute 0:30537dec6e0b 109 int32_t real;
akashvibhute 0:30537dec6e0b 110 uint32_t base;
akashvibhute 0:30537dec6e0b 111 } u_strictness;
akashvibhute 0:30537dec6e0b 112 u_strictness.base = 0;
akashvibhute 0:30537dec6e0b 113 u_strictness.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
akashvibhute 0:30537dec6e0b 114 u_strictness.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
akashvibhute 0:30537dec6e0b 115 u_strictness.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
akashvibhute 0:30537dec6e0b 116 u_strictness.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
akashvibhute 0:30537dec6e0b 117 this->strictness = u_strictness.real;
akashvibhute 0:30537dec6e0b 118 offset += sizeof(this->strictness);
akashvibhute 0:30537dec6e0b 119 return offset;
akashvibhute 0:30537dec6e0b 120 }
akashvibhute 0:30537dec6e0b 121
akashvibhute 0:30537dec6e0b 122 const char * getType(){ return SWITCHCONTROLLER; };
akashvibhute 0:30537dec6e0b 123 const char * getMD5(){ return "434da54adc434a5af5743ed711fd6ba1"; };
akashvibhute 0:30537dec6e0b 124
akashvibhute 0:30537dec6e0b 125 };
akashvibhute 0:30537dec6e0b 126
akashvibhute 0:30537dec6e0b 127 class SwitchControllerResponse : public ros::Msg
akashvibhute 0:30537dec6e0b 128 {
akashvibhute 0:30537dec6e0b 129 public:
akashvibhute 0:30537dec6e0b 130 bool ok;
akashvibhute 0:30537dec6e0b 131
akashvibhute 0:30537dec6e0b 132 SwitchControllerResponse():
akashvibhute 0:30537dec6e0b 133 ok(0)
akashvibhute 0:30537dec6e0b 134 {
akashvibhute 0:30537dec6e0b 135 }
akashvibhute 0:30537dec6e0b 136
akashvibhute 0:30537dec6e0b 137 virtual int serialize(unsigned char *outbuffer) const
akashvibhute 0:30537dec6e0b 138 {
akashvibhute 0:30537dec6e0b 139 int offset = 0;
akashvibhute 0:30537dec6e0b 140 union {
akashvibhute 0:30537dec6e0b 141 bool real;
akashvibhute 0:30537dec6e0b 142 uint8_t base;
akashvibhute 0:30537dec6e0b 143 } u_ok;
akashvibhute 0:30537dec6e0b 144 u_ok.real = this->ok;
akashvibhute 0:30537dec6e0b 145 *(outbuffer + offset + 0) = (u_ok.base >> (8 * 0)) & 0xFF;
akashvibhute 0:30537dec6e0b 146 offset += sizeof(this->ok);
akashvibhute 0:30537dec6e0b 147 return offset;
akashvibhute 0:30537dec6e0b 148 }
akashvibhute 0:30537dec6e0b 149
akashvibhute 0:30537dec6e0b 150 virtual int deserialize(unsigned char *inbuffer)
akashvibhute 0:30537dec6e0b 151 {
akashvibhute 0:30537dec6e0b 152 int offset = 0;
akashvibhute 0:30537dec6e0b 153 union {
akashvibhute 0:30537dec6e0b 154 bool real;
akashvibhute 0:30537dec6e0b 155 uint8_t base;
akashvibhute 0:30537dec6e0b 156 } u_ok;
akashvibhute 0:30537dec6e0b 157 u_ok.base = 0;
akashvibhute 0:30537dec6e0b 158 u_ok.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0);
akashvibhute 0:30537dec6e0b 159 this->ok = u_ok.real;
akashvibhute 0:30537dec6e0b 160 offset += sizeof(this->ok);
akashvibhute 0:30537dec6e0b 161 return offset;
akashvibhute 0:30537dec6e0b 162 }
akashvibhute 0:30537dec6e0b 163
akashvibhute 0:30537dec6e0b 164 const char * getType(){ return SWITCHCONTROLLER; };
akashvibhute 0:30537dec6e0b 165 const char * getMD5(){ return "6f6da3883749771fac40d6deb24a8c02"; };
akashvibhute 0:30537dec6e0b 166
akashvibhute 0:30537dec6e0b 167 };
akashvibhute 0:30537dec6e0b 168
akashvibhute 0:30537dec6e0b 169 class SwitchController {
akashvibhute 0:30537dec6e0b 170 public:
akashvibhute 0:30537dec6e0b 171 typedef SwitchControllerRequest Request;
akashvibhute 0:30537dec6e0b 172 typedef SwitchControllerResponse Response;
akashvibhute 0:30537dec6e0b 173 };
akashvibhute 0:30537dec6e0b 174
akashvibhute 0:30537dec6e0b 175 }
akashvibhute 0:30537dec6e0b 176 #endif
akashvibhute 0:30537dec6e0b 177