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.
Dependencies: mbed
TimedSwitch.h
00001 #ifndef _ROS_wiimote_TimedSwitch_h 00002 #define _ROS_wiimote_TimedSwitch_h 00003 00004 #include <stdint.h> 00005 #include <string.h> 00006 #include <stdlib.h> 00007 #include "ros/msg.h" 00008 00009 namespace wiimote 00010 { 00011 00012 class TimedSwitch : public ros::Msg 00013 { 00014 public: 00015 typedef int8_t _switch_mode_type; 00016 _switch_mode_type switch_mode; 00017 typedef int32_t _num_cycles_type; 00018 _num_cycles_type num_cycles; 00019 uint32_t pulse_pattern_length; 00020 typedef float _pulse_pattern_type; 00021 _pulse_pattern_type st_pulse_pattern; 00022 _pulse_pattern_type * pulse_pattern; 00023 enum { ON = 1 }; 00024 enum { OFF = 0 }; 00025 enum { NO_CHANGE = -2 }; 00026 enum { REPEAT = -1 }; 00027 enum { FOREVER = -1 }; 00028 00029 TimedSwitch(): 00030 switch_mode(0), 00031 num_cycles(0), 00032 pulse_pattern_length(0), pulse_pattern(NULL) 00033 { 00034 } 00035 00036 virtual int serialize(unsigned char *outbuffer) const 00037 { 00038 int offset = 0; 00039 union { 00040 int8_t real; 00041 uint8_t base; 00042 } u_switch_mode; 00043 u_switch_mode.real = this->switch_mode; 00044 *(outbuffer + offset + 0) = (u_switch_mode.base >> (8 * 0)) & 0xFF; 00045 offset += sizeof(this->switch_mode); 00046 union { 00047 int32_t real; 00048 uint32_t base; 00049 } u_num_cycles; 00050 u_num_cycles.real = this->num_cycles; 00051 *(outbuffer + offset + 0) = (u_num_cycles.base >> (8 * 0)) & 0xFF; 00052 *(outbuffer + offset + 1) = (u_num_cycles.base >> (8 * 1)) & 0xFF; 00053 *(outbuffer + offset + 2) = (u_num_cycles.base >> (8 * 2)) & 0xFF; 00054 *(outbuffer + offset + 3) = (u_num_cycles.base >> (8 * 3)) & 0xFF; 00055 offset += sizeof(this->num_cycles); 00056 *(outbuffer + offset + 0) = (this->pulse_pattern_length >> (8 * 0)) & 0xFF; 00057 *(outbuffer + offset + 1) = (this->pulse_pattern_length >> (8 * 1)) & 0xFF; 00058 *(outbuffer + offset + 2) = (this->pulse_pattern_length >> (8 * 2)) & 0xFF; 00059 *(outbuffer + offset + 3) = (this->pulse_pattern_length >> (8 * 3)) & 0xFF; 00060 offset += sizeof(this->pulse_pattern_length); 00061 for( uint32_t i = 0; i < pulse_pattern_length; i++){ 00062 union { 00063 float real; 00064 uint32_t base; 00065 } u_pulse_patterni; 00066 u_pulse_patterni.real = this->pulse_pattern[i]; 00067 *(outbuffer + offset + 0) = (u_pulse_patterni.base >> (8 * 0)) & 0xFF; 00068 *(outbuffer + offset + 1) = (u_pulse_patterni.base >> (8 * 1)) & 0xFF; 00069 *(outbuffer + offset + 2) = (u_pulse_patterni.base >> (8 * 2)) & 0xFF; 00070 *(outbuffer + offset + 3) = (u_pulse_patterni.base >> (8 * 3)) & 0xFF; 00071 offset += sizeof(this->pulse_pattern[i]); 00072 } 00073 return offset; 00074 } 00075 00076 virtual int deserialize(unsigned char *inbuffer) 00077 { 00078 int offset = 0; 00079 union { 00080 int8_t real; 00081 uint8_t base; 00082 } u_switch_mode; 00083 u_switch_mode.base = 0; 00084 u_switch_mode.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); 00085 this->switch_mode = u_switch_mode.real; 00086 offset += sizeof(this->switch_mode); 00087 union { 00088 int32_t real; 00089 uint32_t base; 00090 } u_num_cycles; 00091 u_num_cycles.base = 0; 00092 u_num_cycles.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); 00093 u_num_cycles.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 00094 u_num_cycles.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 00095 u_num_cycles.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 00096 this->num_cycles = u_num_cycles.real; 00097 offset += sizeof(this->num_cycles); 00098 uint32_t pulse_pattern_lengthT = ((uint32_t) (*(inbuffer + offset))); 00099 pulse_pattern_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 00100 pulse_pattern_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 00101 pulse_pattern_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 00102 offset += sizeof(this->pulse_pattern_length); 00103 if(pulse_pattern_lengthT > pulse_pattern_length) 00104 this->pulse_pattern = (float*)realloc(this->pulse_pattern, pulse_pattern_lengthT * sizeof(float)); 00105 pulse_pattern_length = pulse_pattern_lengthT; 00106 for( uint32_t i = 0; i < pulse_pattern_length; i++){ 00107 union { 00108 float real; 00109 uint32_t base; 00110 } u_st_pulse_pattern; 00111 u_st_pulse_pattern.base = 0; 00112 u_st_pulse_pattern.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); 00113 u_st_pulse_pattern.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); 00114 u_st_pulse_pattern.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); 00115 u_st_pulse_pattern.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); 00116 this->st_pulse_pattern = u_st_pulse_pattern.real; 00117 offset += sizeof(this->st_pulse_pattern); 00118 memcpy( &(this->pulse_pattern[i]), &(this->st_pulse_pattern), sizeof(float)); 00119 } 00120 return offset; 00121 } 00122 00123 virtual const char * getType(){ return "wiimote/TimedSwitch"; }; 00124 virtual const char * getMD5(){ return "e4c8d9327409cef6066fa6c368032c1e"; }; 00125 00126 }; 00127 00128 } 00129 #endif
Generated on Mon Sep 26 2022 13:47:04 by
