![](/media/cache/profiles/94aef38441efa3380a3bed3faf1f9d5d.50x50_q85.jpg)
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
dianostic_msgs/SelfTest.h@0:06fc856e99ca, 2011-08-19 (annotated)
- Committer:
- nucho
- Date:
- Fri Aug 19 09:06:16 2011 +0000
- Revision:
- 0:06fc856e99ca
- Child:
- 3:dff241b66f84
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 0:06fc856e99ca | 1 | #ifndef ros_SERVICE_SelfTest_h |
nucho | 0:06fc856e99ca | 2 | #define ros_SERVICE_SelfTest_h |
nucho | 0:06fc856e99ca | 3 | #include <stdint.h> |
nucho | 0:06fc856e99ca | 4 | #include <string.h> |
nucho | 0:06fc856e99ca | 5 | #include <stdlib.h> |
nucho | 0:06fc856e99ca | 6 | #include "../ros/msg.h" |
nucho | 0:06fc856e99ca | 7 | #include "diagnostic_msgs/DiagnosticStatus.h" |
nucho | 0:06fc856e99ca | 8 | |
nucho | 0:06fc856e99ca | 9 | namespace diagnostic_msgs |
nucho | 0:06fc856e99ca | 10 | { |
nucho | 0:06fc856e99ca | 11 | |
nucho | 0:06fc856e99ca | 12 | static const char SELFTEST[] = "diagnostic_msgs/SelfTest"; |
nucho | 0:06fc856e99ca | 13 | |
nucho | 0:06fc856e99ca | 14 | class SelfTestRequest : public ros::Msg |
nucho | 0:06fc856e99ca | 15 | { |
nucho | 0:06fc856e99ca | 16 | public: |
nucho | 0:06fc856e99ca | 17 | |
nucho | 0:06fc856e99ca | 18 | virtual int serialize(unsigned char *outbuffer) |
nucho | 0:06fc856e99ca | 19 | { |
nucho | 0:06fc856e99ca | 20 | int offset = 0; |
nucho | 0:06fc856e99ca | 21 | return offset; |
nucho | 0:06fc856e99ca | 22 | } |
nucho | 0:06fc856e99ca | 23 | |
nucho | 0:06fc856e99ca | 24 | virtual int deserialize(unsigned char *inbuffer) |
nucho | 0:06fc856e99ca | 25 | { |
nucho | 0:06fc856e99ca | 26 | int offset = 0; |
nucho | 0:06fc856e99ca | 27 | return offset; |
nucho | 0:06fc856e99ca | 28 | } |
nucho | 0:06fc856e99ca | 29 | |
nucho | 0:06fc856e99ca | 30 | const char * getType(){ return SELFTEST; }; |
nucho | 0:06fc856e99ca | 31 | |
nucho | 0:06fc856e99ca | 32 | }; |
nucho | 0:06fc856e99ca | 33 | |
nucho | 0:06fc856e99ca | 34 | class SelfTestResponse : public ros::Msg |
nucho | 0:06fc856e99ca | 35 | { |
nucho | 0:06fc856e99ca | 36 | public: |
nucho | 0:06fc856e99ca | 37 | char * id; |
nucho | 0:06fc856e99ca | 38 | unsigned char passed; |
nucho | 0:06fc856e99ca | 39 | unsigned char status_length; |
nucho | 0:06fc856e99ca | 40 | diagnostic_msgs::DiagnosticStatus st_status; |
nucho | 0:06fc856e99ca | 41 | diagnostic_msgs::DiagnosticStatus * status; |
nucho | 0:06fc856e99ca | 42 | |
nucho | 0:06fc856e99ca | 43 | virtual int serialize(unsigned char *outbuffer) |
nucho | 0:06fc856e99ca | 44 | { |
nucho | 0:06fc856e99ca | 45 | int offset = 0; |
nucho | 0:06fc856e99ca | 46 | long * length_id = (long *)(outbuffer + offset); |
nucho | 0:06fc856e99ca | 47 | *length_id = strlen( (const char*) this->id); |
nucho | 0:06fc856e99ca | 48 | offset += 4; |
nucho | 0:06fc856e99ca | 49 | memcpy(outbuffer + offset, this->id, *length_id); |
nucho | 0:06fc856e99ca | 50 | offset += *length_id; |
nucho | 0:06fc856e99ca | 51 | union { |
nucho | 0:06fc856e99ca | 52 | unsigned char real; |
nucho | 0:06fc856e99ca | 53 | unsigned char base; |
nucho | 0:06fc856e99ca | 54 | } u_passed; |
nucho | 0:06fc856e99ca | 55 | u_passed.real = this->passed; |
nucho | 0:06fc856e99ca | 56 | *(outbuffer + offset + 0) = (u_passed.base >> (8 * 0)) & 0xFF; |
nucho | 0:06fc856e99ca | 57 | offset += sizeof(this->passed); |
nucho | 0:06fc856e99ca | 58 | *(outbuffer + offset++) = status_length; |
nucho | 0:06fc856e99ca | 59 | *(outbuffer + offset++) = 0; |
nucho | 0:06fc856e99ca | 60 | *(outbuffer + offset++) = 0; |
nucho | 0:06fc856e99ca | 61 | *(outbuffer + offset++) = 0; |
nucho | 0:06fc856e99ca | 62 | for( unsigned char i = 0; i < status_length; i++){ |
nucho | 0:06fc856e99ca | 63 | offset += this->status[i].serialize(outbuffer + offset); |
nucho | 0:06fc856e99ca | 64 | } |
nucho | 0:06fc856e99ca | 65 | return offset; |
nucho | 0:06fc856e99ca | 66 | } |
nucho | 0:06fc856e99ca | 67 | |
nucho | 0:06fc856e99ca | 68 | virtual int deserialize(unsigned char *inbuffer) |
nucho | 0:06fc856e99ca | 69 | { |
nucho | 0:06fc856e99ca | 70 | int offset = 0; |
nucho | 0:06fc856e99ca | 71 | uint32_t length_id = *(uint32_t *)(inbuffer + offset); |
nucho | 0:06fc856e99ca | 72 | offset += 4; |
nucho | 0:06fc856e99ca | 73 | for(unsigned int k= offset; k< offset+length_id; ++k){ |
nucho | 0:06fc856e99ca | 74 | inbuffer[k-1]=inbuffer[k]; |
nucho | 0:06fc856e99ca | 75 | } |
nucho | 0:06fc856e99ca | 76 | inbuffer[offset+length_id-1]=0; |
nucho | 0:06fc856e99ca | 77 | this->id = (char *)(inbuffer + offset-1); |
nucho | 0:06fc856e99ca | 78 | offset += length_id; |
nucho | 0:06fc856e99ca | 79 | union { |
nucho | 0:06fc856e99ca | 80 | unsigned char real; |
nucho | 0:06fc856e99ca | 81 | unsigned char base; |
nucho | 0:06fc856e99ca | 82 | } u_passed; |
nucho | 0:06fc856e99ca | 83 | u_passed.base = 0; |
nucho | 0:06fc856e99ca | 84 | u_passed.base |= ((typeof(u_passed.base)) (*(inbuffer + offset + 0))) << (8 * 0); |
nucho | 0:06fc856e99ca | 85 | this->passed = u_passed.real; |
nucho | 0:06fc856e99ca | 86 | offset += sizeof(this->passed); |
nucho | 0:06fc856e99ca | 87 | unsigned char status_lengthT = *(inbuffer + offset++); |
nucho | 0:06fc856e99ca | 88 | if(status_lengthT > status_length) |
nucho | 0:06fc856e99ca | 89 | this->status = (diagnostic_msgs::DiagnosticStatus*)realloc(this->status, status_lengthT * sizeof(diagnostic_msgs::DiagnosticStatus)); |
nucho | 0:06fc856e99ca | 90 | offset += 3; |
nucho | 0:06fc856e99ca | 91 | status_length = status_lengthT; |
nucho | 0:06fc856e99ca | 92 | for( unsigned char i = 0; i < status_length; i++){ |
nucho | 0:06fc856e99ca | 93 | offset += this->st_status.deserialize(inbuffer + offset); |
nucho | 0:06fc856e99ca | 94 | memcpy( &(this->status[i]), &(this->st_status), sizeof(diagnostic_msgs::DiagnosticStatus)); |
nucho | 0:06fc856e99ca | 95 | } |
nucho | 0:06fc856e99ca | 96 | return offset; |
nucho | 0:06fc856e99ca | 97 | } |
nucho | 0:06fc856e99ca | 98 | |
nucho | 0:06fc856e99ca | 99 | virtual const char * getType(){ return SELFTEST; }; |
nucho | 0:06fc856e99ca | 100 | |
nucho | 0:06fc856e99ca | 101 | }; |
nucho | 0:06fc856e99ca | 102 | |
nucho | 0:06fc856e99ca | 103 | } |
nucho | 0:06fc856e99ca | 104 | #endif |