Skip to content

Commit 33d7d92

Browse files
committed
tools/pyboard.py: Add fast raw-paste mode.
1 parent 507cd95 commit 33d7d92

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tools/pyboard.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,51 @@ def exec_raw_no_follow(self, command):
370370
if not data.endswith(b">"):
371371
raise PyboardError("could not enter raw repl")
372372

373+
t0 = time.time_ns()
374+
375+
if True:
376+
# raw-paste mode
377+
self.serial.write(b"\x05A\x01")
378+
data = self.serial.read(2)
379+
if data == b"R\x00":
380+
# unsupported raw-paste mode
381+
pass
382+
elif data == b"R\x01":
383+
# board supports raw-paste mode
384+
data = self.serial.read(2)
385+
window_size = data[0] | data[1] << 8
386+
window_remain = window_size
387+
i = 0
388+
while i < len(command_bytes):
389+
while window_remain == 0 or self.serial.inWaiting():
390+
data = self.serial.read(1)
391+
if data == b"\x01":
392+
window_remain += window_size
393+
else:
394+
assert 0
395+
b = command_bytes[i : min(i + window_remain, len(command_bytes))]
396+
self.serial.write(b)
397+
window_remain -= len(b)
398+
i += len(b)
399+
self.serial.write(b"\x04")
400+
401+
data = self.read_until(1, b"\x04")
402+
if not data.endswith(b"\x04"):
403+
print(data)
404+
raise PyboardError("could not complete raw paste")
405+
406+
dt = (time.time_ns() - t0) // 1000000 + 1
407+
print(
408+
"raw-paste took", dt, len(command_bytes), len(command_bytes) * 10 / (dt * 1e-3)
409+
)
410+
return
411+
else:
412+
# board doesn't support raw-paste
413+
data = self.read_until(1, b"w REPL; CTRL-B to exit\r\n>")
414+
if not data.endswith(b"w REPL; CTRL-B to exit\r\n>"):
415+
print(data)
416+
raise PyboardError("could not enter raw repl")
417+
373418
# write command
374419
for i in range(0, len(command_bytes), 256):
375420
self.serial.write(command_bytes[i : min(i + 256, len(command_bytes))])
@@ -381,6 +426,9 @@ def exec_raw_no_follow(self, command):
381426
if data != b"OK":
382427
raise PyboardError("could not exec command (response: %r)" % data)
383428

429+
dt = (time.time_ns() - t0) // 1000000 + 1
430+
print("raw took", dt, len(command_bytes), len(command_bytes) * 10 / (dt * 1e-3))
431+
384432
def exec_raw(self, command, timeout=10, data_consumer=None):
385433
self.exec_raw_no_follow(command)
386434
return self.follow(timeout, data_consumer)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy