@classmethod
  def Read(cls, usb, expected_cmds, timeout_ms=None, total_timeout_ms=None):
    """Receive a response from the device."""
    total_timeout_ms = usb.Timeout(total_timeout_ms)
    start = time.time()
    while True:
      msg = usb.BulkRead(24, timeout_ms)
      cmd, arg0, arg1, data_length, data_checksum = cls.Unpack(msg)
      command = cls.constants.get(cmd)
      if not command:
        raise InvalidCommandError(
            'Unknown command: %x' % cmd, cmd, (arg0, arg1))
      if command in expected_cmds:
        break

      if time.time() - start > total_timeout_ms:
        raise InvalidCommandError(
            'Never got one of the expected responses (%s)' % expected_cmds,
            cmd, (timeout_ms, total_timeout_ms))

    if data_length > 0:
      data = ''
      while data_length > 0:
          temp = usb.BulkRead(data_length, timeout_ms)
          data += temp
          data_length -= len(temp)

      actual_checksum = cls.CalculateChecksum(data)
      if actual_checksum != data_checksum:
        raise InvalidChecksumError(
            'Received checksum %s != %s', (actual_checksum, data_checksum))
    else:
      data = ''
    return command, arg0, arg1, data
dataset/ETHPy150Open google/python-adb/adb/adb_protocol.py/AdbMessage.Read/original