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