$search
00001 """autogenerated by genmsg_py from TimedSwitch.msg. Do not edit.""" 00002 import roslib.message 00003 import struct 00004 00005 00006 class TimedSwitch(roslib.message.Message): 00007 _md5sum = "e4c8d9327409cef6066fa6c368032c1e" 00008 _type = "wiimote/TimedSwitch" 00009 _has_header = False #flag to mark the presence of a Header object 00010 _full_text = """# TimedSwitch allows sender to: 00011 # o turn a switch on, 00012 # o turn a switch off, and 00013 # o repeat an on/off pattern forever or for a 00014 # given number of times. 00015 # Fields (refer to definitions of constants in the definition body): 00016 # o switch_mode: 00017 # ON: turn on (num_cycles and pulse_pattern fields are ignored) 00018 # OFF: turn off (num_cycles and pulse_pattern fields are ignored) 00019 # NO_CHANGE: leave LED in its current state 00020 # REPEAT: repeat an on/off pattern for as long 00021 # as is indicated in the num_cycles field. The 00022 # pattern is defined in the pulse_pattern field. 00023 # 00024 # o num_cycles: 00025 # n>=0: run the pattern that is defined in pulse_pattern 00026 # n times. 00027 # n==FOREVER: run the pattern that is defined in pulse_pattern 00028 # until a new TimedSwitch message is sent. 00029 # 00030 # o pulse_pattern: 00031 # A series of time durations in fractions of a second. The 00032 # first number is the duration for having the switch on. 00033 # The second number is the duration for which the switch 00034 # is off. The third is an 'on' period again, etc. 00035 # A pattern is terminated with the end of the array. 00036 # 00037 # Example: [1,1] specifies an on-off sequence of 1 second. 00038 00039 int8 ON = 1 00040 int8 OFF = 0 00041 int8 NO_CHANGE = -2 00042 int8 REPEAT = -1 00043 int8 FOREVER = -1 00044 00045 int8 switch_mode 00046 int32 num_cycles 00047 float32[] pulse_pattern 00048 00049 """ 00050 # Pseudo-constants 00051 ON = 1 00052 OFF = 0 00053 NO_CHANGE = -2 00054 REPEAT = -1 00055 FOREVER = -1 00056 00057 __slots__ = ['switch_mode','num_cycles','pulse_pattern'] 00058 _slot_types = ['int8','int32','float32[]'] 00059 00060 def __init__(self, *args, **kwds): 00061 """ 00062 Constructor. Any message fields that are implicitly/explicitly 00063 set to None will be assigned a default value. The recommend 00064 use is keyword arguments as this is more robust to future message 00065 changes. You cannot mix in-order arguments and keyword arguments. 00066 00067 The available fields are: 00068 switch_mode,num_cycles,pulse_pattern 00069 00070 @param args: complete set of field values, in .msg order 00071 @param kwds: use keyword arguments corresponding to message field names 00072 to set specific fields. 00073 """ 00074 if args or kwds: 00075 super(TimedSwitch, self).__init__(*args, **kwds) 00076 #message fields cannot be None, assign default values for those that are 00077 if self.switch_mode is None: 00078 self.switch_mode = 0 00079 if self.num_cycles is None: 00080 self.num_cycles = 0 00081 if self.pulse_pattern is None: 00082 self.pulse_pattern = [] 00083 else: 00084 self.switch_mode = 0 00085 self.num_cycles = 0 00086 self.pulse_pattern = [] 00087 00088 def _get_types(self): 00089 """ 00090 internal API method 00091 """ 00092 return self._slot_types 00093 00094 def serialize(self, buff): 00095 """ 00096 serialize message into buffer 00097 @param buff: buffer 00098 @type buff: StringIO 00099 """ 00100 try: 00101 _x = self 00102 buff.write(_struct_bi.pack(_x.switch_mode, _x.num_cycles)) 00103 length = len(self.pulse_pattern) 00104 buff.write(_struct_I.pack(length)) 00105 pattern = '<%sf'%length 00106 buff.write(struct.pack(pattern, *self.pulse_pattern)) 00107 except struct.error as se: self._check_types(se) 00108 except TypeError as te: self._check_types(te) 00109 00110 def deserialize(self, str): 00111 """ 00112 unpack serialized message in str into this message instance 00113 @param str: byte array of serialized message 00114 @type str: str 00115 """ 00116 try: 00117 end = 0 00118 _x = self 00119 start = end 00120 end += 5 00121 (_x.switch_mode, _x.num_cycles,) = _struct_bi.unpack(str[start:end]) 00122 start = end 00123 end += 4 00124 (length,) = _struct_I.unpack(str[start:end]) 00125 pattern = '<%sf'%length 00126 start = end 00127 end += struct.calcsize(pattern) 00128 self.pulse_pattern = struct.unpack(pattern, str[start:end]) 00129 return self 00130 except struct.error as e: 00131 raise roslib.message.DeserializationError(e) #most likely buffer underfill 00132 00133 00134 def serialize_numpy(self, buff, numpy): 00135 """ 00136 serialize message with numpy array types into buffer 00137 @param buff: buffer 00138 @type buff: StringIO 00139 @param numpy: numpy python module 00140 @type numpy module 00141 """ 00142 try: 00143 _x = self 00144 buff.write(_struct_bi.pack(_x.switch_mode, _x.num_cycles)) 00145 length = len(self.pulse_pattern) 00146 buff.write(_struct_I.pack(length)) 00147 pattern = '<%sf'%length 00148 buff.write(self.pulse_pattern.tostring()) 00149 except struct.error as se: self._check_types(se) 00150 except TypeError as te: self._check_types(te) 00151 00152 def deserialize_numpy(self, str, numpy): 00153 """ 00154 unpack serialized message in str into this message instance using numpy for array types 00155 @param str: byte array of serialized message 00156 @type str: str 00157 @param numpy: numpy python module 00158 @type numpy: module 00159 """ 00160 try: 00161 end = 0 00162 _x = self 00163 start = end 00164 end += 5 00165 (_x.switch_mode, _x.num_cycles,) = _struct_bi.unpack(str[start:end]) 00166 start = end 00167 end += 4 00168 (length,) = _struct_I.unpack(str[start:end]) 00169 pattern = '<%sf'%length 00170 start = end 00171 end += struct.calcsize(pattern) 00172 self.pulse_pattern = numpy.frombuffer(str[start:end], dtype=numpy.float32, count=length) 00173 return self 00174 except struct.error as e: 00175 raise roslib.message.DeserializationError(e) #most likely buffer underfill 00176 00177 _struct_I = roslib.message.struct_I 00178 _struct_bi = struct.Struct("<bi")