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

Dependencies:   BufferedSerial

Committer:
krogedal
Date:
Thu May 27 19:25:46 2021 +0000
Revision:
2:fa426560b283
Parent:
0:04ac6be8229a
no change

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Gary Servin 0:04ac6be8229a 1 #ifndef _ROS_SERVICE_MuxList_h
Gary Servin 0:04ac6be8229a 2 #define _ROS_SERVICE_MuxList_h
Gary Servin 0:04ac6be8229a 3 #include <stdint.h>
Gary Servin 0:04ac6be8229a 4 #include <string.h>
Gary Servin 0:04ac6be8229a 5 #include <stdlib.h>
Gary Servin 0:04ac6be8229a 6 #include "ros/msg.h"
Gary Servin 0:04ac6be8229a 7
Gary Servin 0:04ac6be8229a 8 namespace topic_tools
Gary Servin 0:04ac6be8229a 9 {
Gary Servin 0:04ac6be8229a 10
Gary Servin 0:04ac6be8229a 11 static const char MUXLIST[] = "topic_tools/MuxList";
Gary Servin 0:04ac6be8229a 12
Gary Servin 0:04ac6be8229a 13 class MuxListRequest : public ros::Msg
Gary Servin 0:04ac6be8229a 14 {
Gary Servin 0:04ac6be8229a 15 public:
Gary Servin 0:04ac6be8229a 16
Gary Servin 0:04ac6be8229a 17 MuxListRequest()
Gary Servin 0:04ac6be8229a 18 {
Gary Servin 0:04ac6be8229a 19 }
Gary Servin 0:04ac6be8229a 20
Gary Servin 0:04ac6be8229a 21 virtual int serialize(unsigned char *outbuffer) const
Gary Servin 0:04ac6be8229a 22 {
Gary Servin 0:04ac6be8229a 23 int offset = 0;
Gary Servin 0:04ac6be8229a 24 return offset;
Gary Servin 0:04ac6be8229a 25 }
Gary Servin 0:04ac6be8229a 26
Gary Servin 0:04ac6be8229a 27 virtual int deserialize(unsigned char *inbuffer)
Gary Servin 0:04ac6be8229a 28 {
Gary Servin 0:04ac6be8229a 29 int offset = 0;
Gary Servin 0:04ac6be8229a 30 return offset;
Gary Servin 0:04ac6be8229a 31 }
Gary Servin 0:04ac6be8229a 32
Gary Servin 0:04ac6be8229a 33 const char * getType(){ return MUXLIST; };
Gary Servin 0:04ac6be8229a 34 const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; };
Gary Servin 0:04ac6be8229a 35
Gary Servin 0:04ac6be8229a 36 };
Gary Servin 0:04ac6be8229a 37
Gary Servin 0:04ac6be8229a 38 class MuxListResponse : public ros::Msg
Gary Servin 0:04ac6be8229a 39 {
Gary Servin 0:04ac6be8229a 40 public:
Gary Servin 0:04ac6be8229a 41 uint32_t topics_length;
Gary Servin 0:04ac6be8229a 42 typedef char* _topics_type;
Gary Servin 0:04ac6be8229a 43 _topics_type st_topics;
Gary Servin 0:04ac6be8229a 44 _topics_type * topics;
Gary Servin 0:04ac6be8229a 45
Gary Servin 0:04ac6be8229a 46 MuxListResponse():
Gary Servin 0:04ac6be8229a 47 topics_length(0), topics(NULL)
Gary Servin 0:04ac6be8229a 48 {
Gary Servin 0:04ac6be8229a 49 }
Gary Servin 0:04ac6be8229a 50
Gary Servin 0:04ac6be8229a 51 virtual int serialize(unsigned char *outbuffer) const
Gary Servin 0:04ac6be8229a 52 {
Gary Servin 0:04ac6be8229a 53 int offset = 0;
Gary Servin 0:04ac6be8229a 54 *(outbuffer + offset + 0) = (this->topics_length >> (8 * 0)) & 0xFF;
Gary Servin 0:04ac6be8229a 55 *(outbuffer + offset + 1) = (this->topics_length >> (8 * 1)) & 0xFF;
Gary Servin 0:04ac6be8229a 56 *(outbuffer + offset + 2) = (this->topics_length >> (8 * 2)) & 0xFF;
Gary Servin 0:04ac6be8229a 57 *(outbuffer + offset + 3) = (this->topics_length >> (8 * 3)) & 0xFF;
Gary Servin 0:04ac6be8229a 58 offset += sizeof(this->topics_length);
Gary Servin 0:04ac6be8229a 59 for( uint32_t i = 0; i < topics_length; i++){
Gary Servin 0:04ac6be8229a 60 uint32_t length_topicsi = strlen(this->topics[i]);
Gary Servin 0:04ac6be8229a 61 varToArr(outbuffer + offset, length_topicsi);
Gary Servin 0:04ac6be8229a 62 offset += 4;
Gary Servin 0:04ac6be8229a 63 memcpy(outbuffer + offset, this->topics[i], length_topicsi);
Gary Servin 0:04ac6be8229a 64 offset += length_topicsi;
Gary Servin 0:04ac6be8229a 65 }
Gary Servin 0:04ac6be8229a 66 return offset;
Gary Servin 0:04ac6be8229a 67 }
Gary Servin 0:04ac6be8229a 68
Gary Servin 0:04ac6be8229a 69 virtual int deserialize(unsigned char *inbuffer)
Gary Servin 0:04ac6be8229a 70 {
Gary Servin 0:04ac6be8229a 71 int offset = 0;
Gary Servin 0:04ac6be8229a 72 uint32_t topics_lengthT = ((uint32_t) (*(inbuffer + offset)));
Gary Servin 0:04ac6be8229a 73 topics_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
Gary Servin 0:04ac6be8229a 74 topics_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
Gary Servin 0:04ac6be8229a 75 topics_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
Gary Servin 0:04ac6be8229a 76 offset += sizeof(this->topics_length);
Gary Servin 0:04ac6be8229a 77 if(topics_lengthT > topics_length)
Gary Servin 0:04ac6be8229a 78 this->topics = (char**)realloc(this->topics, topics_lengthT * sizeof(char*));
Gary Servin 0:04ac6be8229a 79 topics_length = topics_lengthT;
Gary Servin 0:04ac6be8229a 80 for( uint32_t i = 0; i < topics_length; i++){
Gary Servin 0:04ac6be8229a 81 uint32_t length_st_topics;
Gary Servin 0:04ac6be8229a 82 arrToVar(length_st_topics, (inbuffer + offset));
Gary Servin 0:04ac6be8229a 83 offset += 4;
Gary Servin 0:04ac6be8229a 84 for(unsigned int k= offset; k< offset+length_st_topics; ++k){
Gary Servin 0:04ac6be8229a 85 inbuffer[k-1]=inbuffer[k];
Gary Servin 0:04ac6be8229a 86 }
Gary Servin 0:04ac6be8229a 87 inbuffer[offset+length_st_topics-1]=0;
Gary Servin 0:04ac6be8229a 88 this->st_topics = (char *)(inbuffer + offset-1);
Gary Servin 0:04ac6be8229a 89 offset += length_st_topics;
Gary Servin 0:04ac6be8229a 90 memcpy( &(this->topics[i]), &(this->st_topics), sizeof(char*));
Gary Servin 0:04ac6be8229a 91 }
Gary Servin 0:04ac6be8229a 92 return offset;
Gary Servin 0:04ac6be8229a 93 }
Gary Servin 0:04ac6be8229a 94
Gary Servin 0:04ac6be8229a 95 const char * getType(){ return MUXLIST; };
Gary Servin 0:04ac6be8229a 96 const char * getMD5(){ return "b0eef9a05d4e829092fc2f2c3c2aad3d"; };
Gary Servin 0:04ac6be8229a 97
Gary Servin 0:04ac6be8229a 98 };
Gary Servin 0:04ac6be8229a 99
Gary Servin 0:04ac6be8229a 100 class MuxList {
Gary Servin 0:04ac6be8229a 101 public:
Gary Servin 0:04ac6be8229a 102 typedef MuxListRequest Request;
Gary Servin 0:04ac6be8229a 103 typedef MuxListResponse Response;
Gary Servin 0:04ac6be8229a 104 };
Gary Servin 0:04ac6be8229a 105
Gary Servin 0:04ac6be8229a 106 }
Gary Servin 0:04ac6be8229a 107 #endif