modify for Hydro version
Fork of rosserial_mbed_lib by
std_msgs/UInt8MultiArray.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 | 0:77afd7560544 | 1 | #ifndef ros_UInt8MultiArray_h |
nucho | 0:77afd7560544 | 2 | #define ros_UInt8MultiArray_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 | #include "std_msgs/MultiArrayLayout.h" |
nucho | 0:77afd7560544 | 9 | |
nucho | 0:77afd7560544 | 10 | namespace std_msgs |
nucho | 0:77afd7560544 | 11 | { |
nucho | 0:77afd7560544 | 12 | |
nucho | 0:77afd7560544 | 13 | class UInt8MultiArray : public ros::Msg |
nucho | 0:77afd7560544 | 14 | { |
nucho | 0:77afd7560544 | 15 | public: |
nucho | 0:77afd7560544 | 16 | std_msgs::MultiArrayLayout layout; |
nucho | 0:77afd7560544 | 17 | unsigned char data_length; |
nucho | 1:ff0ec969dad1 | 18 | uint8_t st_data; |
nucho | 1:ff0ec969dad1 | 19 | uint8_t * data; |
nucho | 0:77afd7560544 | 20 | |
nucho | 0:77afd7560544 | 21 | virtual int serialize(unsigned char *outbuffer) |
nucho | 0:77afd7560544 | 22 | { |
nucho | 0:77afd7560544 | 23 | int offset = 0; |
nucho | 0:77afd7560544 | 24 | offset += this->layout.serialize(outbuffer + offset); |
nucho | 0:77afd7560544 | 25 | *(outbuffer + offset++) = data_length; |
nucho | 0:77afd7560544 | 26 | *(outbuffer + offset++) = 0; |
nucho | 0:77afd7560544 | 27 | *(outbuffer + offset++) = 0; |
nucho | 0:77afd7560544 | 28 | *(outbuffer + offset++) = 0; |
nucho | 0:77afd7560544 | 29 | for( unsigned char i = 0; i < data_length; i++){ |
nucho | 0:77afd7560544 | 30 | union { |
nucho | 1:ff0ec969dad1 | 31 | uint8_t real; |
nucho | 1:ff0ec969dad1 | 32 | uint8_t base; |
nucho | 0:77afd7560544 | 33 | } u_datai; |
nucho | 0:77afd7560544 | 34 | u_datai.real = this->data[i]; |
nucho | 0:77afd7560544 | 35 | *(outbuffer + offset + 0) = (u_datai.base >> (8 * 0)) & 0xFF; |
nucho | 0:77afd7560544 | 36 | offset += sizeof(this->data[i]); |
nucho | 0:77afd7560544 | 37 | } |
nucho | 0:77afd7560544 | 38 | return offset; |
nucho | 0:77afd7560544 | 39 | } |
nucho | 0:77afd7560544 | 40 | |
nucho | 0:77afd7560544 | 41 | virtual int deserialize(unsigned char *inbuffer) |
nucho | 0:77afd7560544 | 42 | { |
nucho | 0:77afd7560544 | 43 | int offset = 0; |
nucho | 0:77afd7560544 | 44 | offset += this->layout.deserialize(inbuffer + offset); |
nucho | 0:77afd7560544 | 45 | unsigned char data_lengthT = *(inbuffer + offset++); |
nucho | 0:77afd7560544 | 46 | if(data_lengthT > data_length) |
nucho | 1:ff0ec969dad1 | 47 | this->data = (uint8_t*)realloc(this->data, data_lengthT * sizeof(uint8_t)); |
nucho | 0:77afd7560544 | 48 | offset += 3; |
nucho | 0:77afd7560544 | 49 | data_length = data_lengthT; |
nucho | 0:77afd7560544 | 50 | for( unsigned char i = 0; i < data_length; i++){ |
nucho | 0:77afd7560544 | 51 | union { |
nucho | 1:ff0ec969dad1 | 52 | uint8_t real; |
nucho | 1:ff0ec969dad1 | 53 | uint8_t base; |
nucho | 0:77afd7560544 | 54 | } u_st_data; |
nucho | 0:77afd7560544 | 55 | u_st_data.base = 0; |
nucho | 0:77afd7560544 | 56 | u_st_data.base |= ((typeof(u_st_data.base)) (*(inbuffer + offset + 0))) << (8 * 0); |
nucho | 0:77afd7560544 | 57 | this->st_data = u_st_data.real; |
nucho | 0:77afd7560544 | 58 | offset += sizeof(this->st_data); |
nucho | 1:ff0ec969dad1 | 59 | memcpy( &(this->data[i]), &(this->st_data), sizeof(uint8_t)); |
nucho | 0:77afd7560544 | 60 | } |
nucho | 0:77afd7560544 | 61 | return offset; |
nucho | 0:77afd7560544 | 62 | } |
nucho | 0:77afd7560544 | 63 | |
nucho | 0:77afd7560544 | 64 | virtual const char * getType(){ return "std_msgs/UInt8MultiArray"; }; |
nucho | 0:77afd7560544 | 65 | |
nucho | 0:77afd7560544 | 66 | }; |
nucho | 0:77afd7560544 | 67 | |
nucho | 0:77afd7560544 | 68 | } |
nucho | 0:77afd7560544 | 69 | #endif |