capstone_finish

Dependencies:   BufferedSerial motor_sn7544

Committer:
Jeonghoon
Date:
Tue Nov 26 15:30:27 2019 +0000
Revision:
10:ca4e4062701a
Parent:
3:2a3664dc6634
capstone finish

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jeonghoon 3:2a3664dc6634 1 #ifndef _ROS_sensor_msgs_LaserEcho_h
Jeonghoon 3:2a3664dc6634 2 #define _ROS_sensor_msgs_LaserEcho_h
Jeonghoon 3:2a3664dc6634 3
Jeonghoon 3:2a3664dc6634 4 #include <stdint.h>
Jeonghoon 3:2a3664dc6634 5 #include <string.h>
Jeonghoon 3:2a3664dc6634 6 #include <stdlib.h>
Jeonghoon 3:2a3664dc6634 7 #include "ros/msg.h"
Jeonghoon 3:2a3664dc6634 8
Jeonghoon 3:2a3664dc6634 9 namespace sensor_msgs
Jeonghoon 3:2a3664dc6634 10 {
Jeonghoon 3:2a3664dc6634 11
Jeonghoon 3:2a3664dc6634 12 class LaserEcho : public ros::Msg
Jeonghoon 3:2a3664dc6634 13 {
Jeonghoon 3:2a3664dc6634 14 public:
Jeonghoon 3:2a3664dc6634 15 uint32_t echoes_length;
Jeonghoon 3:2a3664dc6634 16 typedef float _echoes_type;
Jeonghoon 3:2a3664dc6634 17 _echoes_type st_echoes;
Jeonghoon 3:2a3664dc6634 18 _echoes_type * echoes;
Jeonghoon 3:2a3664dc6634 19
Jeonghoon 3:2a3664dc6634 20 LaserEcho():
Jeonghoon 3:2a3664dc6634 21 echoes_length(0), echoes(NULL)
Jeonghoon 3:2a3664dc6634 22 {
Jeonghoon 3:2a3664dc6634 23 }
Jeonghoon 3:2a3664dc6634 24
Jeonghoon 3:2a3664dc6634 25 virtual int serialize(unsigned char *outbuffer) const
Jeonghoon 3:2a3664dc6634 26 {
Jeonghoon 3:2a3664dc6634 27 int offset = 0;
Jeonghoon 3:2a3664dc6634 28 *(outbuffer + offset + 0) = (this->echoes_length >> (8 * 0)) & 0xFF;
Jeonghoon 3:2a3664dc6634 29 *(outbuffer + offset + 1) = (this->echoes_length >> (8 * 1)) & 0xFF;
Jeonghoon 3:2a3664dc6634 30 *(outbuffer + offset + 2) = (this->echoes_length >> (8 * 2)) & 0xFF;
Jeonghoon 3:2a3664dc6634 31 *(outbuffer + offset + 3) = (this->echoes_length >> (8 * 3)) & 0xFF;
Jeonghoon 3:2a3664dc6634 32 offset += sizeof(this->echoes_length);
Jeonghoon 3:2a3664dc6634 33 for( uint32_t i = 0; i < echoes_length; i++){
Jeonghoon 3:2a3664dc6634 34 union {
Jeonghoon 3:2a3664dc6634 35 float real;
Jeonghoon 3:2a3664dc6634 36 uint32_t base;
Jeonghoon 3:2a3664dc6634 37 } u_echoesi;
Jeonghoon 3:2a3664dc6634 38 u_echoesi.real = this->echoes[i];
Jeonghoon 3:2a3664dc6634 39 *(outbuffer + offset + 0) = (u_echoesi.base >> (8 * 0)) & 0xFF;
Jeonghoon 3:2a3664dc6634 40 *(outbuffer + offset + 1) = (u_echoesi.base >> (8 * 1)) & 0xFF;
Jeonghoon 3:2a3664dc6634 41 *(outbuffer + offset + 2) = (u_echoesi.base >> (8 * 2)) & 0xFF;
Jeonghoon 3:2a3664dc6634 42 *(outbuffer + offset + 3) = (u_echoesi.base >> (8 * 3)) & 0xFF;
Jeonghoon 3:2a3664dc6634 43 offset += sizeof(this->echoes[i]);
Jeonghoon 3:2a3664dc6634 44 }
Jeonghoon 3:2a3664dc6634 45 return offset;
Jeonghoon 3:2a3664dc6634 46 }
Jeonghoon 3:2a3664dc6634 47
Jeonghoon 3:2a3664dc6634 48 virtual int deserialize(unsigned char *inbuffer)
Jeonghoon 3:2a3664dc6634 49 {
Jeonghoon 3:2a3664dc6634 50 int offset = 0;
Jeonghoon 3:2a3664dc6634 51 uint32_t echoes_lengthT = ((uint32_t) (*(inbuffer + offset)));
Jeonghoon 3:2a3664dc6634 52 echoes_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
Jeonghoon 3:2a3664dc6634 53 echoes_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
Jeonghoon 3:2a3664dc6634 54 echoes_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
Jeonghoon 3:2a3664dc6634 55 offset += sizeof(this->echoes_length);
Jeonghoon 3:2a3664dc6634 56 if(echoes_lengthT > echoes_length)
Jeonghoon 3:2a3664dc6634 57 this->echoes = (float*)realloc(this->echoes, echoes_lengthT * sizeof(float));
Jeonghoon 3:2a3664dc6634 58 echoes_length = echoes_lengthT;
Jeonghoon 3:2a3664dc6634 59 for( uint32_t i = 0; i < echoes_length; i++){
Jeonghoon 3:2a3664dc6634 60 union {
Jeonghoon 3:2a3664dc6634 61 float real;
Jeonghoon 3:2a3664dc6634 62 uint32_t base;
Jeonghoon 3:2a3664dc6634 63 } u_st_echoes;
Jeonghoon 3:2a3664dc6634 64 u_st_echoes.base = 0;
Jeonghoon 3:2a3664dc6634 65 u_st_echoes.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
Jeonghoon 3:2a3664dc6634 66 u_st_echoes.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
Jeonghoon 3:2a3664dc6634 67 u_st_echoes.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
Jeonghoon 3:2a3664dc6634 68 u_st_echoes.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
Jeonghoon 3:2a3664dc6634 69 this->st_echoes = u_st_echoes.real;
Jeonghoon 3:2a3664dc6634 70 offset += sizeof(this->st_echoes);
Jeonghoon 3:2a3664dc6634 71 memcpy( &(this->echoes[i]), &(this->st_echoes), sizeof(float));
Jeonghoon 3:2a3664dc6634 72 }
Jeonghoon 3:2a3664dc6634 73 return offset;
Jeonghoon 3:2a3664dc6634 74 }
Jeonghoon 3:2a3664dc6634 75
Jeonghoon 3:2a3664dc6634 76 const char * getType(){ return "sensor_msgs/LaserEcho"; };
Jeonghoon 3:2a3664dc6634 77 const char * getMD5(){ return "8bc5ae449b200fba4d552b4225586696"; };
Jeonghoon 3:2a3664dc6634 78
Jeonghoon 3:2a3664dc6634 79 };
Jeonghoon 3:2a3664dc6634 80
Jeonghoon 3:2a3664dc6634 81 }
Jeonghoon 3:2a3664dc6634 82 #endif