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.sparse import QCSparse
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:
@ -606,6 +621,7 @@ class firehose(metaclass=LogBase):
return True
def cmd_read(self, physical_partition_number, start_sector, num_partition_sectors, filename, display=True):
global rq
self.lasterror = b""
progbar = progress(self.cfg.SECTOR_SIZE_IN_BYTES)
if display:
@ -613,7 +629,6 @@ class firehose(metaclass=LogBase):
f"\nReading from physical partition {str(physical_partition_number)}, " +
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}\"" + \
f" num_partition_sectors=\"{num_partition_sectors}\"" + \
f" physical_partition_number=\"{physical_partition_number}\"" + \
@ -632,6 +647,8 @@ class firehose(metaclass=LogBase):
show_progress = progbar.show_progress
usb_read = self.cdc.read
progbar.show_progress(prefix="Read", pos=0, total=total, display=display)
worker = Thread(target=writedata, args=(filename, rq), daemon=True)
worker.start()
while bytestoread > 0:
if self.cdc.is_serial:
maxsize = self.cfg.MaxPayloadSizeFromTargetInBytes
@ -640,15 +657,18 @@ class firehose(metaclass=LogBase):
size = min(maxsize, bytestoread)
data = usb_read(size)
if len(data) > 0:
wr.write(data)
rq.put(data)
bytestoread -= len(data)
show_progress(prefix="Read", pos=total - bytestoread, total=total, display=display)
rq.put(None)
worker.join(60)
self.cdc.xmlread = True
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:")
for line in info:
self.error(line)