This program is porting rosserial_arduino for mbed http://www.ros.org/wiki/rosserial_arduino This program supported the revision of 169 of rosserial. This program contains an example.
Dependencies: rosserial_mbed_lib mbed Servo
roscpp/Logger.h@3:dff241b66f84, 2011-11-12 (annotated)
- Committer:
- nucho
- Date:
- Sat Nov 12 23:53:04 2011 +0000
- Revision:
- 3:dff241b66f84
This program supported the revision of 167 of rosserial.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 3:dff241b66f84 | 1 | #ifndef _ROS_roscpp_Logger_h |
nucho | 3:dff241b66f84 | 2 | #define _ROS_roscpp_Logger_h |
nucho | 3:dff241b66f84 | 3 | |
nucho | 3:dff241b66f84 | 4 | #include <stdint.h> |
nucho | 3:dff241b66f84 | 5 | #include <string.h> |
nucho | 3:dff241b66f84 | 6 | #include <stdlib.h> |
nucho | 3:dff241b66f84 | 7 | #include "ros/msg.h" |
nucho | 3:dff241b66f84 | 8 | |
nucho | 3:dff241b66f84 | 9 | namespace roscpp |
nucho | 3:dff241b66f84 | 10 | { |
nucho | 3:dff241b66f84 | 11 | |
nucho | 3:dff241b66f84 | 12 | class Logger : public ros::Msg |
nucho | 3:dff241b66f84 | 13 | { |
nucho | 3:dff241b66f84 | 14 | public: |
nucho | 3:dff241b66f84 | 15 | char * name; |
nucho | 3:dff241b66f84 | 16 | char * level; |
nucho | 3:dff241b66f84 | 17 | |
nucho | 3:dff241b66f84 | 18 | virtual int serialize(unsigned char *outbuffer) const |
nucho | 3:dff241b66f84 | 19 | { |
nucho | 3:dff241b66f84 | 20 | int offset = 0; |
nucho | 3:dff241b66f84 | 21 | uint32_t * length_name = (uint32_t *)(outbuffer + offset); |
nucho | 3:dff241b66f84 | 22 | *length_name = strlen( (const char*) this->name); |
nucho | 3:dff241b66f84 | 23 | offset += 4; |
nucho | 3:dff241b66f84 | 24 | memcpy(outbuffer + offset, this->name, *length_name); |
nucho | 3:dff241b66f84 | 25 | offset += *length_name; |
nucho | 3:dff241b66f84 | 26 | uint32_t * length_level = (uint32_t *)(outbuffer + offset); |
nucho | 3:dff241b66f84 | 27 | *length_level = strlen( (const char*) this->level); |
nucho | 3:dff241b66f84 | 28 | offset += 4; |
nucho | 3:dff241b66f84 | 29 | memcpy(outbuffer + offset, this->level, *length_level); |
nucho | 3:dff241b66f84 | 30 | offset += *length_level; |
nucho | 3:dff241b66f84 | 31 | return offset; |
nucho | 3:dff241b66f84 | 32 | } |
nucho | 3:dff241b66f84 | 33 | |
nucho | 3:dff241b66f84 | 34 | virtual int deserialize(unsigned char *inbuffer) |
nucho | 3:dff241b66f84 | 35 | { |
nucho | 3:dff241b66f84 | 36 | int offset = 0; |
nucho | 3:dff241b66f84 | 37 | uint32_t length_name = *(uint32_t *)(inbuffer + offset); |
nucho | 3:dff241b66f84 | 38 | offset += 4; |
nucho | 3:dff241b66f84 | 39 | for(unsigned int k= offset; k< offset+length_name; ++k){ |
nucho | 3:dff241b66f84 | 40 | inbuffer[k-1]=inbuffer[k]; |
nucho | 3:dff241b66f84 | 41 | } |
nucho | 3:dff241b66f84 | 42 | inbuffer[offset+length_name-1]=0; |
nucho | 3:dff241b66f84 | 43 | this->name = (char *)(inbuffer + offset-1); |
nucho | 3:dff241b66f84 | 44 | offset += length_name; |
nucho | 3:dff241b66f84 | 45 | uint32_t length_level = *(uint32_t *)(inbuffer + offset); |
nucho | 3:dff241b66f84 | 46 | offset += 4; |
nucho | 3:dff241b66f84 | 47 | for(unsigned int k= offset; k< offset+length_level; ++k){ |
nucho | 3:dff241b66f84 | 48 | inbuffer[k-1]=inbuffer[k]; |
nucho | 3:dff241b66f84 | 49 | } |
nucho | 3:dff241b66f84 | 50 | inbuffer[offset+length_level-1]=0; |
nucho | 3:dff241b66f84 | 51 | this->level = (char *)(inbuffer + offset-1); |
nucho | 3:dff241b66f84 | 52 | offset += length_level; |
nucho | 3:dff241b66f84 | 53 | return offset; |
nucho | 3:dff241b66f84 | 54 | } |
nucho | 3:dff241b66f84 | 55 | |
nucho | 3:dff241b66f84 | 56 | virtual const char * getType(){ return "roscpp/Logger"; }; |
nucho | 3:dff241b66f84 | 57 | virtual const char * getMD5(){ return "a6069a2ff40db7bd32143dd66e1f408e"; }; |
nucho | 3:dff241b66f84 | 58 | |
nucho | 3:dff241b66f84 | 59 | }; |
nucho | 3:dff241b66f84 | 60 | |
nucho | 3:dff241b66f84 | 61 | } |
nucho | 3:dff241b66f84 | 62 | #endif |