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_Joy_h
Jeonghoon 3:2a3664dc6634 2 #define _ROS_sensor_msgs_Joy_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 #include "std_msgs/Header.h"
Jeonghoon 3:2a3664dc6634 9
Jeonghoon 3:2a3664dc6634 10 namespace sensor_msgs
Jeonghoon 3:2a3664dc6634 11 {
Jeonghoon 3:2a3664dc6634 12
Jeonghoon 3:2a3664dc6634 13 class Joy : public ros::Msg
Jeonghoon 3:2a3664dc6634 14 {
Jeonghoon 3:2a3664dc6634 15 public:
Jeonghoon 3:2a3664dc6634 16 typedef std_msgs::Header _header_type;
Jeonghoon 3:2a3664dc6634 17 _header_type header;
Jeonghoon 3:2a3664dc6634 18 uint32_t axes_length;
Jeonghoon 3:2a3664dc6634 19 typedef float _axes_type;
Jeonghoon 3:2a3664dc6634 20 _axes_type st_axes;
Jeonghoon 3:2a3664dc6634 21 _axes_type * axes;
Jeonghoon 3:2a3664dc6634 22 uint32_t buttons_length;
Jeonghoon 3:2a3664dc6634 23 typedef int32_t _buttons_type;
Jeonghoon 3:2a3664dc6634 24 _buttons_type st_buttons;
Jeonghoon 3:2a3664dc6634 25 _buttons_type * buttons;
Jeonghoon 3:2a3664dc6634 26
Jeonghoon 3:2a3664dc6634 27 Joy():
Jeonghoon 3:2a3664dc6634 28 header(),
Jeonghoon 3:2a3664dc6634 29 axes_length(0), axes(NULL),
Jeonghoon 3:2a3664dc6634 30 buttons_length(0), buttons(NULL)
Jeonghoon 3:2a3664dc6634 31 {
Jeonghoon 3:2a3664dc6634 32 }
Jeonghoon 3:2a3664dc6634 33
Jeonghoon 3:2a3664dc6634 34 virtual int serialize(unsigned char *outbuffer) const
Jeonghoon 3:2a3664dc6634 35 {
Jeonghoon 3:2a3664dc6634 36 int offset = 0;
Jeonghoon 3:2a3664dc6634 37 offset += this->header.serialize(outbuffer + offset);
Jeonghoon 3:2a3664dc6634 38 *(outbuffer + offset + 0) = (this->axes_length >> (8 * 0)) & 0xFF;
Jeonghoon 3:2a3664dc6634 39 *(outbuffer + offset + 1) = (this->axes_length >> (8 * 1)) & 0xFF;
Jeonghoon 3:2a3664dc6634 40 *(outbuffer + offset + 2) = (this->axes_length >> (8 * 2)) & 0xFF;
Jeonghoon 3:2a3664dc6634 41 *(outbuffer + offset + 3) = (this->axes_length >> (8 * 3)) & 0xFF;
Jeonghoon 3:2a3664dc6634 42 offset += sizeof(this->axes_length);
Jeonghoon 3:2a3664dc6634 43 for( uint32_t i = 0; i < axes_length; i++){
Jeonghoon 3:2a3664dc6634 44 union {
Jeonghoon 3:2a3664dc6634 45 float real;
Jeonghoon 3:2a3664dc6634 46 uint32_t base;
Jeonghoon 3:2a3664dc6634 47 } u_axesi;
Jeonghoon 3:2a3664dc6634 48 u_axesi.real = this->axes[i];
Jeonghoon 3:2a3664dc6634 49 *(outbuffer + offset + 0) = (u_axesi.base >> (8 * 0)) & 0xFF;
Jeonghoon 3:2a3664dc6634 50 *(outbuffer + offset + 1) = (u_axesi.base >> (8 * 1)) & 0xFF;
Jeonghoon 3:2a3664dc6634 51 *(outbuffer + offset + 2) = (u_axesi.base >> (8 * 2)) & 0xFF;
Jeonghoon 3:2a3664dc6634 52 *(outbuffer + offset + 3) = (u_axesi.base >> (8 * 3)) & 0xFF;
Jeonghoon 3:2a3664dc6634 53 offset += sizeof(this->axes[i]);
Jeonghoon 3:2a3664dc6634 54 }
Jeonghoon 3:2a3664dc6634 55 *(outbuffer + offset + 0) = (this->buttons_length >> (8 * 0)) & 0xFF;
Jeonghoon 3:2a3664dc6634 56 *(outbuffer + offset + 1) = (this->buttons_length >> (8 * 1)) & 0xFF;
Jeonghoon 3:2a3664dc6634 57 *(outbuffer + offset + 2) = (this->buttons_length >> (8 * 2)) & 0xFF;
Jeonghoon 3:2a3664dc6634 58 *(outbuffer + offset + 3) = (this->buttons_length >> (8 * 3)) & 0xFF;
Jeonghoon 3:2a3664dc6634 59 offset += sizeof(this->buttons_length);
Jeonghoon 3:2a3664dc6634 60 for( uint32_t i = 0; i < buttons_length; i++){
Jeonghoon 3:2a3664dc6634 61 union {
Jeonghoon 3:2a3664dc6634 62 int32_t real;
Jeonghoon 3:2a3664dc6634 63 uint32_t base;
Jeonghoon 3:2a3664dc6634 64 } u_buttonsi;
Jeonghoon 3:2a3664dc6634 65 u_buttonsi.real = this->buttons[i];
Jeonghoon 3:2a3664dc6634 66 *(outbuffer + offset + 0) = (u_buttonsi.base >> (8 * 0)) & 0xFF;
Jeonghoon 3:2a3664dc6634 67 *(outbuffer + offset + 1) = (u_buttonsi.base >> (8 * 1)) & 0xFF;
Jeonghoon 3:2a3664dc6634 68 *(outbuffer + offset + 2) = (u_buttonsi.base >> (8 * 2)) & 0xFF;
Jeonghoon 3:2a3664dc6634 69 *(outbuffer + offset + 3) = (u_buttonsi.base >> (8 * 3)) & 0xFF;
Jeonghoon 3:2a3664dc6634 70 offset += sizeof(this->buttons[i]);
Jeonghoon 3:2a3664dc6634 71 }
Jeonghoon 3:2a3664dc6634 72 return offset;
Jeonghoon 3:2a3664dc6634 73 }
Jeonghoon 3:2a3664dc6634 74
Jeonghoon 3:2a3664dc6634 75 virtual int deserialize(unsigned char *inbuffer)
Jeonghoon 3:2a3664dc6634 76 {
Jeonghoon 3:2a3664dc6634 77 int offset = 0;
Jeonghoon 3:2a3664dc6634 78 offset += this->header.deserialize(inbuffer + offset);
Jeonghoon 3:2a3664dc6634 79 uint32_t axes_lengthT = ((uint32_t) (*(inbuffer + offset)));
Jeonghoon 3:2a3664dc6634 80 axes_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
Jeonghoon 3:2a3664dc6634 81 axes_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
Jeonghoon 3:2a3664dc6634 82 axes_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
Jeonghoon 3:2a3664dc6634 83 offset += sizeof(this->axes_length);
Jeonghoon 3:2a3664dc6634 84 if(axes_lengthT > axes_length)
Jeonghoon 3:2a3664dc6634 85 this->axes = (float*)realloc(this->axes, axes_lengthT * sizeof(float));
Jeonghoon 3:2a3664dc6634 86 axes_length = axes_lengthT;
Jeonghoon 3:2a3664dc6634 87 for( uint32_t i = 0; i < axes_length; i++){
Jeonghoon 3:2a3664dc6634 88 union {
Jeonghoon 3:2a3664dc6634 89 float real;
Jeonghoon 3:2a3664dc6634 90 uint32_t base;
Jeonghoon 3:2a3664dc6634 91 } u_st_axes;
Jeonghoon 3:2a3664dc6634 92 u_st_axes.base = 0;
Jeonghoon 3:2a3664dc6634 93 u_st_axes.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
Jeonghoon 3:2a3664dc6634 94 u_st_axes.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
Jeonghoon 3:2a3664dc6634 95 u_st_axes.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
Jeonghoon 3:2a3664dc6634 96 u_st_axes.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
Jeonghoon 3:2a3664dc6634 97 this->st_axes = u_st_axes.real;
Jeonghoon 3:2a3664dc6634 98 offset += sizeof(this->st_axes);
Jeonghoon 3:2a3664dc6634 99 memcpy( &(this->axes[i]), &(this->st_axes), sizeof(float));
Jeonghoon 3:2a3664dc6634 100 }
Jeonghoon 3:2a3664dc6634 101 uint32_t buttons_lengthT = ((uint32_t) (*(inbuffer + offset)));
Jeonghoon 3:2a3664dc6634 102 buttons_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
Jeonghoon 3:2a3664dc6634 103 buttons_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
Jeonghoon 3:2a3664dc6634 104 buttons_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
Jeonghoon 3:2a3664dc6634 105 offset += sizeof(this->buttons_length);
Jeonghoon 3:2a3664dc6634 106 if(buttons_lengthT > buttons_length)
Jeonghoon 3:2a3664dc6634 107 this->buttons = (int32_t*)realloc(this->buttons, buttons_lengthT * sizeof(int32_t));
Jeonghoon 3:2a3664dc6634 108 buttons_length = buttons_lengthT;
Jeonghoon 3:2a3664dc6634 109 for( uint32_t i = 0; i < buttons_length; i++){
Jeonghoon 3:2a3664dc6634 110 union {
Jeonghoon 3:2a3664dc6634 111 int32_t real;
Jeonghoon 3:2a3664dc6634 112 uint32_t base;
Jeonghoon 3:2a3664dc6634 113 } u_st_buttons;
Jeonghoon 3:2a3664dc6634 114 u_st_buttons.base = 0;
Jeonghoon 3:2a3664dc6634 115 u_st_buttons.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
Jeonghoon 3:2a3664dc6634 116 u_st_buttons.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
Jeonghoon 3:2a3664dc6634 117 u_st_buttons.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
Jeonghoon 3:2a3664dc6634 118 u_st_buttons.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
Jeonghoon 3:2a3664dc6634 119 this->st_buttons = u_st_buttons.real;
Jeonghoon 3:2a3664dc6634 120 offset += sizeof(this->st_buttons);
Jeonghoon 3:2a3664dc6634 121 memcpy( &(this->buttons[i]), &(this->st_buttons), sizeof(int32_t));
Jeonghoon 3:2a3664dc6634 122 }
Jeonghoon 3:2a3664dc6634 123 return offset;
Jeonghoon 3:2a3664dc6634 124 }
Jeonghoon 3:2a3664dc6634 125
Jeonghoon 3:2a3664dc6634 126 const char * getType(){ return "sensor_msgs/Joy"; };
Jeonghoon 3:2a3664dc6634 127 const char * getMD5(){ return "5a9ea5f83505693b71e785041e67a8bb"; };
Jeonghoon 3:2a3664dc6634 128
Jeonghoon 3:2a3664dc6634 129 };
Jeonghoon 3:2a3664dc6634 130
Jeonghoon 3:2a3664dc6634 131 }
Jeonghoon 3:2a3664dc6634 132 #endif