@@ -370,6 +370,54 @@ 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
+ elif data == b"\x04 " :
394
+ self .serial .write (b"\x04 " )
395
+ return
396
+ else :
397
+ assert 0 , data
398
+ b = command_bytes [i : min (i + window_remain , len (command_bytes ))]
399
+ self .serial .write (b )
400
+ window_remain -= len (b )
401
+ i += len (b )
402
+ self .serial .write (b"\x04 " )
403
+
404
+ data = self .read_until (1 , b"\x04 " )
405
+ if not data .endswith (b"\x04 " ):
406
+ print (data )
407
+ raise PyboardError ("could not complete raw paste" )
408
+
409
+ dt = (time .time_ns () - t0 ) // 1000000 + 1
410
+ print (
411
+ "raw-paste took" , dt , len (command_bytes ), len (command_bytes ) * 10 / (dt * 1e-3 )
412
+ )
413
+ return
414
+ else :
415
+ # board doesn't support raw-paste
416
+ data = self .read_until (1 , b"w REPL; CTRL-B to exit\r \n >" )
417
+ if not data .endswith (b"w REPL; CTRL-B to exit\r \n >" ):
418
+ print (data )
419
+ raise PyboardError ("could not enter raw repl" )
420
+
373
421
# write command
374
422
for i in range (0 , len (command_bytes ), 256 ):
375
423
self .serial .write (command_bytes [i : min (i + 256 , len (command_bytes ))])
@@ -381,6 +429,9 @@ def exec_raw_no_follow(self, command):
381
429
if data != b"OK" :
382
430
raise PyboardError ("could not exec command (response: %r)" % data )
383
431
432
+ dt = (time .time_ns () - t0 ) // 1000000 + 1
433
+ print ("raw took" , dt , len (command_bytes ), len (command_bytes ) * 10 / (dt * 1e-3 ))
434
+
384
435
def exec_raw (self , command , timeout = 10 , data_consumer = None ):
385
436
self .exec_raw_no_follow (command )
386
437
return self .follow (timeout , data_consumer )
0 commit comments