Improve read speed

This commit is contained in:
info@revskills.de 2023-04-07 16:50:58 +02:00
parent 652e6f7df2
commit 8c595a221e

View file

@ -15,6 +15,21 @@ from edlclient.Library.utils import *
from edlclient.Library.gpt import gpt from edlclient.Library.gpt import gpt
from edlclient.Library.sparse import QCSparse from edlclient.Library.sparse import QCSparse
from edlclient.Library.utils import progress from edlclient.Library.utils import progress
from queue import Queue
from threading import Thread
rq = Queue()
def writedata(filename, rq):
pos = 0
with open(filename, "wb") as wf:
while True:
data = rq.get()
if data is None:
break
pos += len(data)
wf.write(data)
rq.task_done()
class response: class response:
@ -606,6 +621,7 @@ class firehose(metaclass=LogBase):
return True return True
def cmd_read(self, physical_partition_number, start_sector, num_partition_sectors, filename, display=True): def cmd_read(self, physical_partition_number, start_sector, num_partition_sectors, filename, display=True):
global rq
self.lasterror = b"" self.lasterror = b""
progbar = progress(self.cfg.SECTOR_SIZE_IN_BYTES) progbar = progress(self.cfg.SECTOR_SIZE_IN_BYTES)
if display: if display:
@ -613,52 +629,56 @@ class firehose(metaclass=LogBase):
f"\nReading from physical partition {str(physical_partition_number)}, " + f"\nReading from physical partition {str(physical_partition_number)}, " +
f"sector {str(start_sector)}, sectors {str(num_partition_sectors)}") f"sector {str(start_sector)}, sectors {str(num_partition_sectors)}")
with open(file=filename, mode="wb", buffering=self.cfg.MaxPayloadSizeFromTargetInBytes) as wr: data = f"<?xml version=\"1.0\" ?><data><read SECTOR_SIZE_IN_BYTES=\"{self.cfg.SECTOR_SIZE_IN_BYTES}\"" + \
data = f"<?xml version=\"1.0\" ?><data><read SECTOR_SIZE_IN_BYTES=\"{self.cfg.SECTOR_SIZE_IN_BYTES}\"" + \ f" num_partition_sectors=\"{num_partition_sectors}\"" + \
f" num_partition_sectors=\"{num_partition_sectors}\"" + \ f" physical_partition_number=\"{physical_partition_number}\"" + \
f" physical_partition_number=\"{physical_partition_number}\"" + \ f" start_sector=\"{start_sector}\"/>\n</data>"
f" start_sector=\"{start_sector}\"/>\n</data>"
rsp = self.xmlsend(data, self.skipresponse) rsp = self.xmlsend(data, self.skipresponse)
self.cdc.xmlread = False self.cdc.xmlread = False
time.sleep(0.01) time.sleep(0.01)
if not rsp.resp: if not rsp.resp:
if display: if display:
self.error(rsp.error) self.error(rsp.error)
return b"" return b""
else: else:
bytestoread = self.cfg.SECTOR_SIZE_IN_BYTES * num_partition_sectors bytestoread = self.cfg.SECTOR_SIZE_IN_BYTES * num_partition_sectors
total = bytestoread total = bytestoread
show_progress = progbar.show_progress show_progress = progbar.show_progress
usb_read = self.cdc.read usb_read = self.cdc.read
progbar.show_progress(prefix="Read", pos=0, total=total, display=display) progbar.show_progress(prefix="Read", pos=0, total=total, display=display)
while bytestoread > 0: worker = Thread(target=writedata, args=(filename, rq), daemon=True)
if self.cdc.is_serial: worker.start()
maxsize = self.cfg.MaxPayloadSizeFromTargetInBytes while bytestoread > 0:
else: if self.cdc.is_serial:
maxsize = 5 * 1024 * 1024 maxsize = self.cfg.MaxPayloadSizeFromTargetInBytes
size = min(maxsize, bytestoread) else:
data = usb_read(size) maxsize = 5 * 1024 * 1024
if len(data) > 0: size = min(maxsize, bytestoread)
wr.write(data) data = usb_read(size)
bytestoread -= len(data) if len(data) > 0:
show_progress(prefix="Read", pos=total - bytestoread, total=total, display=display) rq.put(data)
self.cdc.xmlread = True bytestoread -= len(data)
wd = self.wait_for_data() show_progress(prefix="Read", pos=total - bytestoread, total=total, display=display)
info = self.xml.getlog(wd) rq.put(None)
rsp = self.xml.getresponse(wd) worker.join(60)
if "value" in rsp: self.cdc.xmlread = True
if rsp["value"] != "ACK": wd = self.wait_for_data()
info = self.xml.getlog(wd)
rsp = self.xml.getresponse(wd)
if "value" in rsp:
if rsp["value"] != "ACK":
if bytestoread!=0:
self.error(f"Error:") self.error(f"Error:")
for line in info: for line in info:
self.error(line) self.error(line)
self.lasterror += bytes(line + "\n", "utf-8") self.lasterror += bytes(line + "\n", "utf-8")
return False return False
else: else:
if display: if display:
self.error(f"Error:{rsp[2]}") self.error(f"Error:{rsp[2]}")
return False return False
return True return True
def cmd_read_buffer(self, physical_partition_number, start_sector, num_partition_sectors, display=True): def cmd_read_buffer(self, physical_partition_number, start_sector, num_partition_sectors, display=True):
self.lasterror = b"" self.lasterror = b""