This program is porting rosserial_arduino for mbed http://www.ros.org/wiki/rosserial_arduino This program supported the revision of 169 of rosserial.
Dependents: rosserial_mbed robot_S2
std_msgs/Int16MultiArray.h@4:684f39d0c346, 2012-02-29 (annotated)
- Committer:
- nucho
- Date:
- Wed Feb 29 23:00:21 2012 +0000
- Revision:
- 4:684f39d0c346
- Parent:
- 3:1cf99502f396
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 3:1cf99502f396 | 1 | #ifndef _ROS_std_msgs_Int16MultiArray_h |
nucho | 3:1cf99502f396 | 2 | #define _ROS_std_msgs_Int16MultiArray_h |
nucho | 3:1cf99502f396 | 3 | |
nucho | 3:1cf99502f396 | 4 | #include <stdint.h> |
nucho | 3:1cf99502f396 | 5 | #include <string.h> |
nucho | 3:1cf99502f396 | 6 | #include <stdlib.h> |
nucho | 3:1cf99502f396 | 7 | #include "ros/msg.h" |
nucho | 3:1cf99502f396 | 8 | #include "std_msgs/MultiArrayLayout.h" |
nucho | 3:1cf99502f396 | 9 | |
nucho | 3:1cf99502f396 | 10 | namespace std_msgs |
nucho | 3:1cf99502f396 | 11 | { |
nucho | 3:1cf99502f396 | 12 | |
nucho | 3:1cf99502f396 | 13 | class Int16MultiArray : public ros::Msg |
nucho | 3:1cf99502f396 | 14 | { |
nucho | 3:1cf99502f396 | 15 | public: |
nucho | 3:1cf99502f396 | 16 | std_msgs::MultiArrayLayout layout; |
nucho | 3:1cf99502f396 | 17 | uint8_t data_length; |
nucho | 3:1cf99502f396 | 18 | int16_t st_data; |
nucho | 3:1cf99502f396 | 19 | int16_t * data; |
nucho | 3:1cf99502f396 | 20 | |
nucho | 3:1cf99502f396 | 21 | virtual int serialize(unsigned char *outbuffer) const |
nucho | 3:1cf99502f396 | 22 | { |
nucho | 3:1cf99502f396 | 23 | int offset = 0; |
nucho | 3:1cf99502f396 | 24 | offset += this->layout.serialize(outbuffer + offset); |
nucho | 3:1cf99502f396 | 25 | *(outbuffer + offset++) = data_length; |
nucho | 3:1cf99502f396 | 26 | *(outbuffer + offset++) = 0; |
nucho | 3:1cf99502f396 | 27 | *(outbuffer + offset++) = 0; |
nucho | 3:1cf99502f396 | 28 | *(outbuffer + offset++) = 0; |
nucho | 3:1cf99502f396 | 29 | for( uint8_t i = 0; i < data_length; i++){ |
nucho | 3:1cf99502f396 | 30 | union { |
nucho | 3:1cf99502f396 | 31 | int16_t real; |
nucho | 3:1cf99502f396 | 32 | uint16_t base; |
nucho | 3:1cf99502f396 | 33 | } u_datai; |
nucho | 3:1cf99502f396 | 34 | u_datai.real = this->data[i]; |
nucho | 3:1cf99502f396 | 35 | *(outbuffer + offset + 0) = (u_datai.base >> (8 * 0)) & 0xFF; |
nucho | 3:1cf99502f396 | 36 | *(outbuffer + offset + 1) = (u_datai.base >> (8 * 1)) & 0xFF; |
nucho | 3:1cf99502f396 | 37 | offset += sizeof(this->data[i]); |
nucho | 3:1cf99502f396 | 38 | } |
nucho | 3:1cf99502f396 | 39 | return offset; |
nucho | 3:1cf99502f396 | 40 | } |
nucho | 3:1cf99502f396 | 41 | |
nucho | 3:1cf99502f396 | 42 | virtual int deserialize(unsigned char *inbuffer) |
nucho | 3:1cf99502f396 | 43 | { |
nucho | 3:1cf99502f396 | 44 | int offset = 0; |
nucho | 3:1cf99502f396 | 45 | offset += this->layout.deserialize(inbuffer + offset); |
nucho | 3:1cf99502f396 | 46 | uint8_t data_lengthT = *(inbuffer + offset++); |
nucho | 3:1cf99502f396 | 47 | if(data_lengthT > data_length) |
nucho | 3:1cf99502f396 | 48 | this->data = (int16_t*)realloc(this->data, data_lengthT * sizeof(int16_t)); |
nucho | 3:1cf99502f396 | 49 | offset += 3; |
nucho | 3:1cf99502f396 | 50 | data_length = data_lengthT; |
nucho | 3:1cf99502f396 | 51 | for( uint8_t i = 0; i < data_length; i++){ |
nucho | 3:1cf99502f396 | 52 | union { |
nucho | 3:1cf99502f396 | 53 | int16_t real; |
nucho | 3:1cf99502f396 | 54 | uint16_t base; |
nucho | 3:1cf99502f396 | 55 | } u_st_data; |
nucho | 3:1cf99502f396 | 56 | u_st_data.base = 0; |
nucho | 3:1cf99502f396 | 57 | u_st_data.base |= ((uint16_t) (*(inbuffer + offset + 0))) << (8 * 0); |
nucho | 3:1cf99502f396 | 58 | u_st_data.base |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); |
nucho | 3:1cf99502f396 | 59 | this->st_data = u_st_data.real; |
nucho | 3:1cf99502f396 | 60 | offset += sizeof(this->st_data); |
nucho | 3:1cf99502f396 | 61 | memcpy( &(this->data[i]), &(this->st_data), sizeof(int16_t)); |
nucho | 3:1cf99502f396 | 62 | } |
nucho | 3:1cf99502f396 | 63 | return offset; |
nucho | 3:1cf99502f396 | 64 | } |
nucho | 3:1cf99502f396 | 65 | |
nucho | 3:1cf99502f396 | 66 | virtual const char * getType(){ return "std_msgs/Int16MultiArray"; }; |
nucho | 3:1cf99502f396 | 67 | virtual const char * getMD5(){ return "d9338d7f523fcb692fae9d0a0e9f067c"; }; |
nucho | 3:1cf99502f396 | 68 | |
nucho | 3:1cf99502f396 | 69 | }; |
nucho | 3:1cf99502f396 | 70 | |
nucho | 3:1cf99502f396 | 71 | } |
nucho | 0:77afd7560544 | 72 | #endif |