Go to the documentation of this file.00001 import struct
00002 from BAL.protocol.packages.header import TakeoverHeader
00003
00004 CHANNEL_TO_TAKEOVER = 2
00005 CHANNEL_TO_TAKEOVER_SIZE = 5
00006
00007
00008 class ChannelToTakeover(TakeoverHeader):
00009 ABOVE = 1
00010 BELOW = 2
00011
00012 def __init__(self, ch=None, listen_mode=None, value=None, status=None):
00013 super(ChannelToTakeover, self).__init__(CHANNEL_TO_TAKEOVER)
00014 self._ch = ch
00015 self._listen_mode = listen_mode
00016 self._value = value
00017 self._status = status
00018
00019 if ch is not None:
00020 self.set_checksum(self.cal_checksum())
00021
00022 def to_bytes(self):
00023 return super(ChannelToTakeover, self).to_bytes() \
00024 + struct.pack('<B', self._ch) \
00025 + struct.pack('<B', self._listen_mode) \
00026 + struct.pack('<H', self._value) \
00027 + struct.pack('<?', self._status)
00028
00029 def get_length(self):
00030 return super(ChannelToTakeover, self).get_length() + CHANNEL_TO_TAKEOVER_SIZE
00031
00032 def get_channel(self):
00033 return self._ch
00034
00035 def get_listen_mode(self):
00036 return self._listen_mode
00037
00038 def get_value(self):
00039 return self._value
00040
00041 def get_status(self):
00042 return self._status
00043
00044 def convert_to_pkg(self, raw_data):
00045 super(ChannelToTakeover, self).convert_to_pkg(raw_data)
00046 self._ch = struct.unpack('<B', bytearray(raw_data[3]))[0]
00047 self._listen_mode = struct.unpack('<B', bytearray(raw_data[4]))[0]
00048 self._value = struct.unpack('<H', bytearray(raw_data[5:7]))[0]
00049 self._status = struct.unpack('<?', bytearray(raw_data[7]))[0]
00050
00051
00052
00053