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.
Dependents: rosserial_mbed_hello_world_publisher rtos_base_control rosserial_mbed_F64MA ROS-RTOS ... more
Floats.h
00001 #ifndef _ROS_rospy_tutorials_Floats_h 00002 #define _ROS_rospy_tutorials_Floats_h 00003 00004 #include <stdint.h> 00005 #include <string.h> 00006 #include <stdlib.h> 00007 #include "ros/msg.h" 00008 00009 namespace rospy_tutorials 00010 { 00011 00012 class Floats : public ros::Msg 00013 { 00014 public: 00015 uint8_t data_length; 00016 float st_data; 00017 float * data; 00018 00019 Floats(): 00020 data_length(0), data(NULL) 00021 { 00022 } 00023 00024 virtual int serialize(unsigned char *outbuffer) const 00025 { 00026 int offset = 0; 00027 *(outbuffer + offset++) = data_length; 00028 *(outbuffer + offset++) = 0; 00029 *(outbuffer + offset++) = 0; 00030 *(outbuffer + offset++) = 0; 00031 for( uint8_t i = 0; i < data_length; i++){ 00032 union { 00033 float real; 00034 uint32_t base; 00035 } u_datai; 00036 u_datai.real = this->data[i]; 00037 *(outbuffer + offset + 0) = (u_datai.base >> (8 * 0)) & 0xFF; 00038 *(outbuffer + offset + 1) = (u_datai.base >> (8 * 1)) & 0xFF; 00039 *(outbuffer + offset + 2) = (u_datai.base >> (8 * 2)) & 0xFF; 00040 *(outbuffer + offset + 3) = (u_datai.base >> (8 * 3)) & 0xFF; 00041 offset += sizeof(this->data[i]); 00042 } 00043 return offset; 00044 } 00045 00046 virtual int deserialize(unsigned char *inbuffer) 00047 { 00048 int offset = 0; 00049 uint8_t data_lengthT = *(inbuffer + offset++); 00050 if(data_lengthT > data_length) 00051 this->data = (float*)realloc(this->data, data_lengthT * sizeof(float)); 00052 offset += 3; 00053 data_length = data_lengthT; 00054 for( uint8_t i = 0; i < data_length; i++){ 00055 union { 00056 float real; 00057 uint32_t base; 00058 } u_st_data; 00059 u_st_data.base = 0; 00060 u_st_data.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); 00061 u_st_data.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 00062 u_st_data.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 00063 u_st_data.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 00064 this->st_data = u_st_data.real; 00065 offset += sizeof(this->st_data); 00066 memcpy( &(this->data[i]), &(this->st_data), sizeof(float)); 00067 } 00068 return offset; 00069 } 00070 00071 const char * getType(){ return "rospy_tutorials/Floats"; }; 00072 const char * getMD5(){ return "420cd38b6b071cd49f2970c3e2cee511"; }; 00073 00074 }; 00075 00076 } 00077 #endif
Generated on Tue Jul 12 2022 18:39:39 by
1.7.2