Fix broken uploadb.py

putc didn't work well with any byte value on most terminal configuration. It
was a bad idea...
This commit is contained in:
Virgil Dupras 2019-12-02 22:57:22 -05:00
parent 270ad926c9
commit 30a0f69101
1 changed files with 20 additions and 8 deletions

View File

@ -47,14 +47,26 @@ def main():
for i, c in enumerate(fcontents): for i, c in enumerate(fcontents):
c = bytes([c]) c = bytes([c])
sendcmd(fd, 'getc') print('.', end='', flush=True)
os.write(fd, c) for _ in range(5): # try 5 times
os.read(fd, 2) # read prompt sendcmd(fd, 'getc')
sendcmd(fd, 'putc a') os.write(fd, c)
r = os.read(fd, 1) # putc result os.read(fd, 2) # read prompt
os.read(fd, 2) # read prompt sendcmd(fd, 'print a')
if r != c: s = b''
print(f"Mismatch at byte {i}! {c} != {r}") while True:
r = os.read(fd, 1) # putc result
if not r.isdigit():
break
s += r
os.read(fd, 3) # read prompt
if int(s) == c[0]:
break
else:
print(f"Mismatch at byte {i}! {c} != {r}. Retrying")
else:
print("Maximum retries reached, abort")
return 1
sendcmd(fd, 'poke m a') sendcmd(fd, 'poke m a')
os.read(fd, 2) # read prompt os.read(fd, 2) # read prompt
sendcmd(fd, 'm=m+1') sendcmd(fd, 'm=m+1')