Personal fork
Fork of rosserial_mbed_lib by
rosserial_msgs/TopicInfo.h@1:ff0ec969dad1, 2011-10-16 (annotated)
- Committer:
- nucho
- Date:
- Sun Oct 16 07:19:36 2011 +0000
- Revision:
- 1:ff0ec969dad1
- Parent:
- 0:77afd7560544
- Child:
- 3:1cf99502f396
This program supported the revision of 143 of rosserial.
And the bug fix of receive of array data.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 1:ff0ec969dad1 | 1 | #ifndef ros_rosserial_msgs_TopicInfo_h |
nucho | 1:ff0ec969dad1 | 2 | #define ros_rosserial_msgs_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 | namespace rosserial_msgs |
nucho | 0:77afd7560544 | 9 | { |
nucho | 0:77afd7560544 | 10 | class TopicInfo : public ros::Msg |
nucho | 0:77afd7560544 | 11 | { |
nucho | 0:77afd7560544 | 12 | public: |
nucho | 0:77afd7560544 | 13 | unsigned short topic_id; |
nucho | 0:77afd7560544 | 14 | char * topic_name; |
nucho | 0:77afd7560544 | 15 | char * message_type; |
nucho | 1:ff0ec969dad1 | 16 | char * md5_checksum; |
nucho | 0:77afd7560544 | 17 | enum { ID_PUBLISHER = 0 }; |
nucho | 0:77afd7560544 | 18 | enum { ID_SUBSCRIBER = 1 }; |
nucho | 0:77afd7560544 | 19 | enum { ID_SERVICE_SERVER = 2 }; |
nucho | 0:77afd7560544 | 20 | enum { ID_SERVICE_CLIENT = 3 }; |
nucho | 0:77afd7560544 | 21 | enum { ID_PARAMETER_REQUEST = 4 }; |
nucho | 0:77afd7560544 | 22 | enum { ID_LOG = 5 }; |
nucho | 0:77afd7560544 | 23 | enum { ID_TIME = 10 }; |
nucho | 0:77afd7560544 | 24 | |
nucho | 0:77afd7560544 | 25 | virtual int serialize(unsigned char *outbuffer) |
nucho | 0:77afd7560544 | 26 | { |
nucho | 0:77afd7560544 | 27 | int offset = 0; |
nucho | 0:77afd7560544 | 28 | union { |
nucho | 1:ff0ec969dad1 | 29 | uint16_t real; |
nucho | 1:ff0ec969dad1 | 30 | uint16_t base; |
nucho | 0:77afd7560544 | 31 | } u_topic_id; |
nucho | 0:77afd7560544 | 32 | u_topic_id.real = this->topic_id; |
nucho | 0:77afd7560544 | 33 | *(outbuffer + offset + 0) = (u_topic_id.base >> (8 * 0)) & 0xFF; |
nucho | 0:77afd7560544 | 34 | *(outbuffer + offset + 1) = (u_topic_id.base >> (8 * 1)) & 0xFF; |
nucho | 0:77afd7560544 | 35 | offset += sizeof(this->topic_id); |
nucho | 1:ff0ec969dad1 | 36 | |
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 | 1:ff0ec969dad1 | 42 | |
nucho | 0:77afd7560544 | 43 | long * length_message_type = (long *)(outbuffer + offset); |
nucho | 0:77afd7560544 | 44 | *length_message_type = strlen( (const char*) this->message_type); |
nucho | 0:77afd7560544 | 45 | offset += 4; |
nucho | 0:77afd7560544 | 46 | memcpy(outbuffer + offset, this->message_type, *length_message_type); |
nucho | 0:77afd7560544 | 47 | offset += *length_message_type; |
nucho | 1:ff0ec969dad1 | 48 | |
nucho | 1:ff0ec969dad1 | 49 | long * length_md5_checksum = (long *)(outbuffer + offset); |
nucho | 1:ff0ec969dad1 | 50 | *length_md5_checksum = strlen( (const char*) this->md5_checksum); |
nucho | 1:ff0ec969dad1 | 51 | offset += 4; |
nucho | 1:ff0ec969dad1 | 52 | memcpy(outbuffer + offset, this->md5_checksum, *length_md5_checksum); |
nucho | 1:ff0ec969dad1 | 53 | offset += *length_md5_checksum; |
nucho | 1:ff0ec969dad1 | 54 | |
nucho | 0:77afd7560544 | 55 | return offset; |
nucho | 0:77afd7560544 | 56 | } |
nucho | 0:77afd7560544 | 57 | |
nucho | 0:77afd7560544 | 58 | virtual int deserialize(unsigned char *inbuffer) |
nucho | 0:77afd7560544 | 59 | { |
nucho | 0:77afd7560544 | 60 | int offset = 0; |
nucho | 0:77afd7560544 | 61 | union { |
nucho | 0:77afd7560544 | 62 | unsigned short real; |
nucho | 0:77afd7560544 | 63 | unsigned short base; |
nucho | 0:77afd7560544 | 64 | } u_topic_id; |
nucho | 0:77afd7560544 | 65 | u_topic_id.base = 0; |
nucho | 0:77afd7560544 | 66 | u_topic_id.base |= ((typeof(u_topic_id.base)) (*(inbuffer + offset + 0))) << (8 * 0); |
nucho | 0:77afd7560544 | 67 | u_topic_id.base |= ((typeof(u_topic_id.base)) (*(inbuffer + offset + 1))) << (8 * 1); |
nucho | 0:77afd7560544 | 68 | this->topic_id = u_topic_id.real; |
nucho | 0:77afd7560544 | 69 | offset += sizeof(this->topic_id); |
nucho | 0:77afd7560544 | 70 | uint32_t length_topic_name = *(uint32_t *)(inbuffer + offset); |
nucho | 0:77afd7560544 | 71 | offset += 4; |
nucho | 0:77afd7560544 | 72 | for(unsigned int k= offset; k< offset+length_topic_name; ++k){ |
nucho | 0:77afd7560544 | 73 | inbuffer[k-1]=inbuffer[k]; |
nucho | 0:77afd7560544 | 74 | } |
nucho | 0:77afd7560544 | 75 | inbuffer[offset+length_topic_name-1]=0; |
nucho | 0:77afd7560544 | 76 | this->topic_name = (char *)(inbuffer + offset-1); |
nucho | 0:77afd7560544 | 77 | offset += length_topic_name; |
nucho | 0:77afd7560544 | 78 | uint32_t length_message_type = *(uint32_t *)(inbuffer + offset); |
nucho | 0:77afd7560544 | 79 | offset += 4; |
nucho | 0:77afd7560544 | 80 | for(unsigned int k= offset; k< offset+length_message_type; ++k){ |
nucho | 0:77afd7560544 | 81 | inbuffer[k-1]=inbuffer[k]; |
nucho | 0:77afd7560544 | 82 | } |
nucho | 0:77afd7560544 | 83 | inbuffer[offset+length_message_type-1]=0; |
nucho | 0:77afd7560544 | 84 | this->message_type = (char *)(inbuffer + offset-1); |
nucho | 0:77afd7560544 | 85 | offset += length_message_type; |
nucho | 1:ff0ec969dad1 | 86 | |
nucho | 1:ff0ec969dad1 | 87 | uint32_t length_md5_checksum = *(uint32_t *)(inbuffer + offset); |
nucho | 1:ff0ec969dad1 | 88 | offset += 4; |
nucho | 1:ff0ec969dad1 | 89 | for(unsigned int k= offset; k< offset+length_md5_checksum; ++k){ |
nucho | 1:ff0ec969dad1 | 90 | inbuffer[k-1]=inbuffer[k]; |
nucho | 1:ff0ec969dad1 | 91 | } |
nucho | 1:ff0ec969dad1 | 92 | inbuffer[offset+length_md5_checksum-1]=0; |
nucho | 1:ff0ec969dad1 | 93 | this->md5_checksum = (char *)(inbuffer + offset-1); |
nucho | 1:ff0ec969dad1 | 94 | offset += length_md5_checksum; |
nucho | 1:ff0ec969dad1 | 95 | |
nucho | 0:77afd7560544 | 96 | return offset; |
nucho | 0:77afd7560544 | 97 | } |
nucho | 0:77afd7560544 | 98 | |
nucho | 0:77afd7560544 | 99 | virtual const char * getType(){ return "rosserial_msgs/TopicInfo"; }; |
nucho | 0:77afd7560544 | 100 | |
nucho | 0:77afd7560544 | 101 | }; |
nucho | 0:77afd7560544 | 102 | |
nucho | 0:77afd7560544 | 103 | } |
nucho | 0:77afd7560544 | 104 | #endif |