Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of rosserial_mbed_lib by
sensor_msgs/ChannelFloat32.h@0:77afd7560544, 2011-08-19 (annotated)
- Committer:
- nucho
- Date:
- Fri Aug 19 09:06:30 2011 +0000
- Revision:
- 0:77afd7560544
- Child:
- 3:1cf99502f396
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| nucho | 0:77afd7560544 | 1 | #ifndef ros_ChannelFloat32_h |
| nucho | 0:77afd7560544 | 2 | #define ros_ChannelFloat32_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 | |
| nucho | 0:77afd7560544 | 9 | namespace sensor_msgs |
| nucho | 0:77afd7560544 | 10 | { |
| nucho | 0:77afd7560544 | 11 | |
| nucho | 0:77afd7560544 | 12 | class ChannelFloat32 : public ros::Msg |
| nucho | 0:77afd7560544 | 13 | { |
| nucho | 0:77afd7560544 | 14 | public: |
| nucho | 0:77afd7560544 | 15 | char * name; |
| nucho | 0:77afd7560544 | 16 | unsigned char values_length; |
| nucho | 0:77afd7560544 | 17 | float st_values; |
| nucho | 0:77afd7560544 | 18 | float * values; |
| nucho | 0:77afd7560544 | 19 | |
| nucho | 0:77afd7560544 | 20 | virtual int serialize(unsigned char *outbuffer) |
| nucho | 0:77afd7560544 | 21 | { |
| nucho | 0:77afd7560544 | 22 | int offset = 0; |
| nucho | 0:77afd7560544 | 23 | long * length_name = (long *)(outbuffer + offset); |
| nucho | 0:77afd7560544 | 24 | *length_name = strlen( (const char*) this->name); |
| nucho | 0:77afd7560544 | 25 | offset += 4; |
| nucho | 0:77afd7560544 | 26 | memcpy(outbuffer + offset, this->name, *length_name); |
| nucho | 0:77afd7560544 | 27 | offset += *length_name; |
| nucho | 0:77afd7560544 | 28 | *(outbuffer + offset++) = values_length; |
| nucho | 0:77afd7560544 | 29 | *(outbuffer + offset++) = 0; |
| nucho | 0:77afd7560544 | 30 | *(outbuffer + offset++) = 0; |
| nucho | 0:77afd7560544 | 31 | *(outbuffer + offset++) = 0; |
| nucho | 0:77afd7560544 | 32 | for( unsigned char i = 0; i < values_length; i++){ |
| nucho | 0:77afd7560544 | 33 | union { |
| nucho | 0:77afd7560544 | 34 | float real; |
| nucho | 0:77afd7560544 | 35 | unsigned long base; |
| nucho | 0:77afd7560544 | 36 | } u_valuesi; |
| nucho | 0:77afd7560544 | 37 | u_valuesi.real = this->values[i]; |
| nucho | 0:77afd7560544 | 38 | *(outbuffer + offset + 0) = (u_valuesi.base >> (8 * 0)) & 0xFF; |
| nucho | 0:77afd7560544 | 39 | *(outbuffer + offset + 1) = (u_valuesi.base >> (8 * 1)) & 0xFF; |
| nucho | 0:77afd7560544 | 40 | *(outbuffer + offset + 2) = (u_valuesi.base >> (8 * 2)) & 0xFF; |
| nucho | 0:77afd7560544 | 41 | *(outbuffer + offset + 3) = (u_valuesi.base >> (8 * 3)) & 0xFF; |
| nucho | 0:77afd7560544 | 42 | offset += sizeof(this->values[i]); |
| nucho | 0:77afd7560544 | 43 | } |
| nucho | 0:77afd7560544 | 44 | return offset; |
| nucho | 0:77afd7560544 | 45 | } |
| nucho | 0:77afd7560544 | 46 | |
| nucho | 0:77afd7560544 | 47 | virtual int deserialize(unsigned char *inbuffer) |
| nucho | 0:77afd7560544 | 48 | { |
| nucho | 0:77afd7560544 | 49 | int offset = 0; |
| nucho | 0:77afd7560544 | 50 | uint32_t length_name = *(uint32_t *)(inbuffer + offset); |
| nucho | 0:77afd7560544 | 51 | offset += 4; |
| nucho | 0:77afd7560544 | 52 | for(unsigned int k= offset; k< offset+length_name; ++k){ |
| nucho | 0:77afd7560544 | 53 | inbuffer[k-1]=inbuffer[k]; |
| nucho | 0:77afd7560544 | 54 | } |
| nucho | 0:77afd7560544 | 55 | inbuffer[offset+length_name-1]=0; |
| nucho | 0:77afd7560544 | 56 | this->name = (char *)(inbuffer + offset-1); |
| nucho | 0:77afd7560544 | 57 | offset += length_name; |
| nucho | 0:77afd7560544 | 58 | unsigned char values_lengthT = *(inbuffer + offset++); |
| nucho | 0:77afd7560544 | 59 | if(values_lengthT > values_length) |
| nucho | 0:77afd7560544 | 60 | this->values = (float*)realloc(this->values, values_lengthT * sizeof(float)); |
| nucho | 0:77afd7560544 | 61 | offset += 3; |
| nucho | 0:77afd7560544 | 62 | values_length = values_lengthT; |
| nucho | 0:77afd7560544 | 63 | for( unsigned char i = 0; i < values_length; i++){ |
| nucho | 0:77afd7560544 | 64 | union { |
| nucho | 0:77afd7560544 | 65 | float real; |
| nucho | 0:77afd7560544 | 66 | unsigned long base; |
| nucho | 0:77afd7560544 | 67 | } u_st_values; |
| nucho | 0:77afd7560544 | 68 | u_st_values.base = 0; |
| nucho | 0:77afd7560544 | 69 | u_st_values.base |= ((typeof(u_st_values.base)) (*(inbuffer + offset + 0))) << (8 * 0); |
| nucho | 0:77afd7560544 | 70 | u_st_values.base |= ((typeof(u_st_values.base)) (*(inbuffer + offset + 1))) << (8 * 1); |
| nucho | 0:77afd7560544 | 71 | u_st_values.base |= ((typeof(u_st_values.base)) (*(inbuffer + offset + 2))) << (8 * 2); |
| nucho | 0:77afd7560544 | 72 | u_st_values.base |= ((typeof(u_st_values.base)) (*(inbuffer + offset + 3))) << (8 * 3); |
| nucho | 0:77afd7560544 | 73 | this->st_values = u_st_values.real; |
| nucho | 0:77afd7560544 | 74 | offset += sizeof(this->st_values); |
| nucho | 0:77afd7560544 | 75 | memcpy( &(this->values[i]), &(this->st_values), sizeof(float)); |
| nucho | 0:77afd7560544 | 76 | } |
| nucho | 0:77afd7560544 | 77 | return offset; |
| nucho | 0:77afd7560544 | 78 | } |
| nucho | 0:77afd7560544 | 79 | |
| nucho | 0:77afd7560544 | 80 | virtual const char * getType(){ return "sensor_msgs/ChannelFloat32"; }; |
| nucho | 0:77afd7560544 | 81 | |
| nucho | 0:77afd7560544 | 82 | }; |
| nucho | 0:77afd7560544 | 83 | |
| nucho | 0:77afd7560544 | 84 | } |
| nucho | 0:77afd7560544 | 85 | #endif |
