@@ -370,6 +370,51 @@ def exec_raw_no_follow(self, command):
370
370
if not data .endswith (b">" ):
371
371
raise PyboardError ("could not enter raw repl" )
372
372
373
+ t0 = time .time_ns ()
374
+
375
+ if True :
376
+ # raw-paste mode
377
+ self .serial .write (b"\x05 A\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
+
373
418
# write command
374
419
for i in range (0 , len (command_bytes ), 256 ):
375
420
self .serial .write (command_bytes [i : min (i + 256 , len (command_bytes ))])
@@ -381,6 +426,9 @@ def exec_raw_no_follow(self, command):
381
426
if data != b"OK" :
382
427
raise PyboardError ("could not exec command (response: %r)" % data )
383
428
429
+ dt = (time .time_ns () - t0 ) // 1000000 + 1
430
+ print ("raw took" , dt , len (command_bytes ), len (command_bytes ) * 10 / (dt * 1e-3 ))
431
+
384
432
def exec_raw (self , command , timeout = 10 , data_consumer = None ):
385
433
self .exec_raw_no_follow (command )
386
434
return self .follow (timeout , data_consumer )
0 commit comments