Personal fork
Fork of rosserial_mbed_lib by
rosserial_msgs/TopicInfo.h@0:77afd7560544, 2011-08-19 (annotated)
- Committer:
- nucho
- Date:
- Fri Aug 19 09:06:30 2011 +0000
- Revision:
- 0:77afd7560544
- Child:
- 1:ff0ec969dad1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 0:77afd7560544 | 1 | #ifndef ros_TopicInfo_h |
nucho | 0:77afd7560544 | 2 | #define ros_TopicInfo_h |
nucho | 0:77afd7560544 | 3 | |
nucho | 0:77afd7560544 | 4 | #include <stdint.h> |
nucho | 0:77afd7560544 | 5 | #include <string.h> |
nucho | 0:77afd7560544 | 6 | #include <stdlib.h> |
nucho | 0:77afd7560544 | 7 | #include "../ros/msg.h" |
nucho | 0:77afd7560544 | 8 | |
nucho | 0:77afd7560544 | 9 | namespace rosserial_msgs |
nucho | 0:77afd7560544 | 10 | { |
nucho | 0:77afd7560544 | 11 | |
nucho | 0:77afd7560544 | 12 | class TopicInfo : public ros::Msg |
nucho | 0:77afd7560544 | 13 | { |
nucho | 0:77afd7560544 | 14 | public: |
nucho | 0:77afd7560544 | 15 | unsigned short topic_id; |
nucho | 0:77afd7560544 | 16 | char * topic_name; |
nucho | 0:77afd7560544 | 17 | char * message_type; |
nucho | 0:77afd7560544 | 18 | enum { ID_PUBLISHER = 0 }; |
nucho | 0:77afd7560544 | 19 | enum { ID_SUBSCRIBER = 1 }; |
nucho | 0:77afd7560544 | 20 | enum { ID_SERVICE_SERVER = 2 }; |
nucho | 0:77afd7560544 | 21 | enum { ID_SERVICE_CLIENT = 3 }; |
nucho | 0:77afd7560544 | 22 | enum { ID_PARAMETER_REQUEST = 4 }; |
nucho | 0:77afd7560544 | 23 | enum { ID_LOG = 5 }; |
nucho | 0:77afd7560544 | 24 | enum { ID_TIME = 10 }; |
nucho | 0:77afd7560544 | 25 | |
nucho | 0:77afd7560544 | 26 | virtual int serialize(unsigned char *outbuffer) |
nucho | 0:77afd7560544 | 27 | { |
nucho | 0:77afd7560544 | 28 | int offset = 0; |
nucho | 0:77afd7560544 | 29 | union { |
nucho | 0:77afd7560544 | 30 | unsigned short real; |
nucho | 0:77afd7560544 | 31 | unsigned short base; |
nucho | 0:77afd7560544 | 32 | } u_topic_id; |
nucho | 0:77afd7560544 | 33 | u_topic_id.real = this->topic_id; |
nucho | 0:77afd7560544 | 34 | *(outbuffer + offset + 0) = (u_topic_id.base >> (8 * 0)) & 0xFF; |
nucho | 0:77afd7560544 | 35 | *(outbuffer + offset + 1) = (u_topic_id.base >> (8 * 1)) & 0xFF; |
nucho | 0:77afd7560544 | 36 | offset += sizeof(this->topic_id); |
nucho | 0:77afd7560544 | 37 | long * length_topic_name = (long *)(outbuffer + offset); |
nucho | 0:77afd7560544 | 38 | *length_topic_name = strlen( (const char*) this->topic_name); |
nucho | 0:77afd7560544 | 39 | offset += 4; |
nucho | 0:77afd7560544 | 40 | memcpy(outbuffer + offset, this->topic_name, *length_topic_name); |
nucho | 0:77afd7560544 | 41 | offset += *length_topic_name; |
nucho | 0:77afd7560544 | 42 | long * length_message_type = (long *)(outbuffer + offset); |
nucho | 0:77afd7560544 | 43 | *length_message_type = strlen( (const char*) this->message_type); |
nucho | 0:77afd7560544 | 44 | offset += 4; |
nucho | 0:77afd7560544 | 45 | memcpy(outbuffer + offset, this->message_type, *length_message_type); |
nucho | 0:77afd7560544 | 46 | offset += *length_message_type; |
nucho | 0:77afd7560544 | 47 | return offset; |
nucho | 0:77afd7560544 | 48 | } |
nucho | 0:77afd7560544 | 49 | |
nucho | 0:77afd7560544 | 50 | virtual int deserialize(unsigned char *inbuffer) |
nucho | 0:77afd7560544 | 51 | { |
nucho | 0:77afd7560544 | 52 | int offset = 0; |
nucho | 0:77afd7560544 | 53 | union { |
nucho | 0:77afd7560544 | 54 | unsigned short real; |
nucho | 0:77afd7560544 | 55 | unsigned short base; |
nucho | 0:77afd7560544 | 56 | } u_topic_id; |
nucho | 0:77afd7560544 | 57 | u_topic_id.base = 0; |
nucho | 0:77afd7560544 | 58 | u_topic_id.base |= ((typeof(u_topic_id.base)) (*(inbuffer + offset + 0))) << (8 * 0); |
nucho | 0:77afd7560544 | 59 | u_topic_id.base |= ((typeof(u_topic_id.base)) (*(inbuffer + offset + 1))) << (8 * 1); |
nucho | 0:77afd7560544 | 60 | this->topic_id = u_topic_id.real; |
nucho | 0:77afd7560544 | 61 | offset += sizeof(this->topic_id); |
nucho | 0:77afd7560544 | 62 | uint32_t length_topic_name = *(uint32_t *)(inbuffer + offset); |
nucho | 0:77afd7560544 | 63 | offset += 4; |
nucho | 0:77afd7560544 | 64 | for(unsigned int k= offset; k< offset+length_topic_name; ++k){ |
nucho | 0:77afd7560544 | 65 | inbuffer[k-1]=inbuffer[k]; |
nucho | 0:77afd7560544 | 66 | } |
nucho | 0:77afd7560544 | 67 | inbuffer[offset+length_topic_name-1]=0; |
nucho | 0:77afd7560544 | 68 | this->topic_name = (char *)(inbuffer + offset-1); |
nucho | 0:77afd7560544 | 69 | offset += length_topic_name; |
nucho | 0:77afd7560544 | 70 | uint32_t length_message_type = *(uint32_t *)(inbuffer + offset); |
nucho | 0:77afd7560544 | 71 | offset += 4; |
nucho | 0:77afd7560544 | 72 | for(unsigned int k= offset; k< offset+length_message_type; ++k){ |
nucho | 0:77afd7560544 | 73 | inbuffer[k-1]=inbuffer[k]; |
nucho | 0:77afd7560544 | 74 | } |
nucho | 0:77afd7560544 | 75 | inbuffer[offset+length_message_type-1]=0; |
nucho | 0:77afd7560544 | 76 | this->message_type = (char *)(inbuffer + offset-1); |
nucho | 0:77afd7560544 | 77 | offset += length_message_type; |
nucho | 0:77afd7560544 | 78 | return offset; |
nucho | 0:77afd7560544 | 79 | } |
nucho | 0:77afd7560544 | 80 | |
nucho | 0:77afd7560544 | 81 | virtual const char * getType(){ return "rosserial_msgs/TopicInfo"; }; |
nucho | 0:77afd7560544 | 82 | |
nucho | 0:77afd7560544 | 83 | }; |
nucho | 0:77afd7560544 | 84 | |
nucho | 0:77afd7560544 | 85 | } |
nucho | 0:77afd7560544 | 86 | #endif |