serload: add exit command, correctly parse prompt after command

This commit is contained in:
slederer 2026-01-02 22:49:54 +01:00
parent 7751d85765
commit 79baf3cef5

View file

@ -78,6 +78,9 @@ def commandwait(ser, cmd):
print("timeout sending '{}' command".format(cmd)) print("timeout sending '{}' command".format(cmd))
return None return None
if resp.startswith(b"> "):
resp = resp[2:]
if resp != bytearray(cmd + b"\r\n"): if resp != bytearray(cmd + b"\r\n"):
print("invalid response to '{}' command".format(cmd)) print("invalid response to '{}' command".format(cmd))
return None return None
@ -323,7 +326,7 @@ def showdata(ser):
promptseen = True promptseen = True
else: else:
print(c.decode('utf8'), end='') print(c.decode('utf8'), end='')
rest = ser.read(1) rest = ser.read(1) # read trailing space of prompt
def localdir(): def localdir():
@ -360,8 +363,10 @@ def interactive(ser):
print("superfluous argument") print("superfluous argument")
else: else:
localdir() localdir()
elif cmd == 'exit' or cmd == 'x':
done = True
else: else:
print("Unknown command. Valid commands are: dir get ldir put") print("Unknown command. Valid commands are: dir get ldir put exit")
if __name__ == "__main__": if __name__ == "__main__":