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,7 +629,6 @@ 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}\"" + \
@ -632,6 +647,8 @@ class firehose(metaclass=LogBase):
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)
worker = Thread(target=writedata, args=(filename, rq), daemon=True)
worker.start()
while bytestoread > 0: while bytestoread > 0:
if self.cdc.is_serial: if self.cdc.is_serial:
maxsize = self.cfg.MaxPayloadSizeFromTargetInBytes maxsize = self.cfg.MaxPayloadSizeFromTargetInBytes
@ -640,15 +657,18 @@ class firehose(metaclass=LogBase):
size = min(maxsize, bytestoread) size = min(maxsize, bytestoread)
data = usb_read(size) data = usb_read(size)
if len(data) > 0: if len(data) > 0:
wr.write(data) rq.put(data)
bytestoread -= len(data) bytestoread -= len(data)
show_progress(prefix="Read", pos=total - bytestoread, total=total, display=display) show_progress(prefix="Read", pos=total - bytestoread, total=total, display=display)
rq.put(None)
worker.join(60)
self.cdc.xmlread = True self.cdc.xmlread = True
wd = self.wait_for_data() wd = self.wait_for_data()
info = self.xml.getlog(wd) info = self.xml.getlog(wd)
rsp = self.xml.getresponse(wd) rsp = self.xml.getresponse(wd)
if "value" in rsp: if "value" in rsp:
if rsp["value"] != "ACK": 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)