Working ADB transfer at very low speeds (adding a delay in python terminal)

This commit is contained in:
Daniele Verducci su MatissePenguin
2021-01-01 22:42:00 +01:00
parent 2678a2ebfd
commit 55f5d62082
3 changed files with 36 additions and 22 deletions

View File

@ -31,10 +31,13 @@ import os
class TerminalEmulator:
SYNC_SLEEP = 0.001
def __init__(self, w, ser):
w.clear()
w.move(0,0)
while True:
# read serial port and write to curses
if ser.inWaiting():
b = ser.read(1)
@ -45,6 +48,7 @@ class TerminalEmulator:
key = w.getch()
if key == 10 or (key > 31 and key < 256):
# Is a character
time.sleep(self.SYNC_SLEEP)
ser.write(bytes([key]))
elif int(key) == 1: # CTRL+A, enter ADB mode
# Save cursor position
@ -67,20 +71,29 @@ class TerminalEmulator:
w.addstr(0, 0, '[ADB MODE] file to load:', curses.A_REVERSE)
path = w.getstr()
try:
header = bytearray(2)
size = os.path.getsize(path)
# Compute the two header bytes needed to declare the length of the stream
h1 = size & 255 # get lower 8 bits
header[1] = size & 255 # get lower 8 bits
size >>= 8 # shift by 8 bits
h0 = size & 255 # get second lower 8 bits
header[0] = size & 255 # get second lower 8 bits
# Log size for debug
w.addstr("Header bytes: {}".format(header.hex()))
w.refresh()
# Send the two heading bytes (most significant first)
ser.write(h0)
ser.write(h1)
ser.write(header[0:1])
time.sleep(self.SYNC_SLEEP)
ser.write(header[1:2])
time.sleep(self.SYNC_SLEEP)
# Send the actual binary stream
with open(path, "rb") as f:
byte = f.read(1)
while byte:
ser.write(byte)
byte = f.read(1)
time.sleep(self.SYNC_SLEEP)
except IOError as e:
w.move(0,0)
w.clrtoeol()