def decode(self, data): ''' Decodes response pdu :param data: The packet data to decode ''' self.byte_count = struct.unpack(">B", data[0])[0] self.bits = unpack_bitstring(data[1:])
def decode_bits(self): ''' Decodes a byte worth of bits from the buffer ''' self._pointer += 1 fstring = self._endian + 'B' handle = self._payload[self._pointer - 1:self._pointer] return unpack_bitstring(handle)
def decode(self, data): ''' Decodes response pdu :param data: The packet data to decode ''' self.byte_count = byte2int(data[0]) self.bits = unpack_bitstring(data[1:])
def decode_bits(self): """ Decodes a byte worth of bits from the buffer """ self._pointer += 1 # fstring = self._endian + 'B' handle = self._payload[self._pointer - 1:self._pointer] handle = make_byte_string(handle) return unpack_bitstring(handle)
def decode(self, data): ''' Decodes a write coils request :param data: The packet data to decode ''' self.address, count, self.byte_count = struct.unpack('>HHB', data[0:5]) values = unpack_bitstring(data[5:]) self.values = values[:count]
def decode(self, event): ''' Decodes the event message to its status bits :param event: The event to decode ''' bits = unpack_bitstring(event) self.overrun = bits[4] self.listen = bits[5] self.broadcast = bits[6]
def __get_bit(self, key, offset, count): ''' :param key: The key prefix to use :param offset: The address offset to start at :param count: The number of bits to read ''' response = self.__get_bit_values(key, offset, count) response = (r or self.__bit_default for r in response) result = ''.join(response) result = unpack_bitstring(result) return result[offset:offset + count]
def decode(self, event): ''' Decodes the event message to its status bits :param event: The event to decode ''' # todo fix the start byte count bits = unpack_bitstring(event) self.read = bits[0] self.slave_abort = bits[1] self.slave_busy = bits[2] self.slave_nak = bits[3] self.write_timeout = bits[4] self.listen = bits[5]
def decode_bits(self): """ Decodes a byte worth of bits from the buffer """ self._pointer += 1 handle = self._payload[self._pointer - 1:self._pointer] return unpack_bitstring(handle)
def testBitPacking(self): ''' Test all string <=> bit packing functions ''' self.assertEqual(unpack_bitstring('\x55'), self.bits) self.assertEqual(pack_bitstring(self.bits), '\x55')