118
118
# Maximum sizes and buffers
119
119
# _MAX_PACKET_SIZE = const(512)
120
120
_MAX_PACKET_SIZE = const (64 )
121
- _DEFAULT_TX_BUF_SIZE = const (4096 )
122
- _DEFAULT_RX_BUF_SIZE = const (4096 )
121
+ _DEFAULT_TX_BUF_SIZE = const (1024 )
122
+ _DEFAULT_RX_BUF_SIZE = const (1024 )
123
123
_CONTAINER_HEADER_SIZE = const (12 )
124
124
125
125
# MTP struct definitions using uctypes
@@ -310,13 +310,15 @@ def _rx_cb(self, ep, res, num_bytes):
310
310
self ._log ("OUT transfer failed with error {}" , res )
311
311
self ._rx_xfer () # Continue receiving
312
312
313
- def _tx_xfer (self ):
313
+ def _tx_xfer (self , quiet = False ):
314
314
"""Submit a new transfer to send data to the host."""
315
315
if self .is_open () and not self .xfer_pending (self .ep_in ) and self ._tx .readable ():
316
316
buf = self ._tx .pend_read ()
317
317
self ._log ("Submitting IN transfer, data size={}" , len (buf ))
318
318
self .submit_xfer (self .ep_in , buf , self ._tx_cb )
319
319
else :
320
+ if quiet :
321
+ return
320
322
if not self .is_open ():
321
323
self ._log ("Cannot submit IN transfer - interface not open" )
322
324
elif self .xfer_pending (self .ep_in ):
@@ -960,19 +962,29 @@ def _cmd_get_object(self, params):
960
962
961
963
# Write header to TX buffer
962
964
self ._tx .write (container )
965
+ print (f'readable: { self ._tx .readable ()} ' )
966
+ if self .is_open () and self .xfer_pending (self .ep_in ):
967
+ time .sleep_ms (11 )
968
+
963
969
self ._tx_xfer ()
970
+ print (f'container passed' )
971
+ if self .is_open () and self .xfer_pending (self .ep_in ):
972
+ time .sleep_ms (12 )
973
+
964
974
965
975
# Now send the file data in chunks
966
976
bytes_sent = 0
967
- chunk_size = min (4096 , self ._tx .writable ()) # Adjust chunk size based on buffer capacity
977
+ chunk_size = min (_DEFAULT_TX_BUF_SIZE , len ( self ._tx ._b ))
968
978
969
979
while bytes_sent < filesize :
970
980
# Wait until we can write to the TX buffer
971
- while not self ._tx .writable () or self ._tx .writable () < chunk_size :
981
+ while not self ._tx .writable (): # or self._tx.writable() < chunk_size:
972
982
if not self .is_open ():
973
983
self ._log ("Interface closed during file transfer" )
974
984
return
975
- time .sleep_ms (1 )
985
+
986
+ time .sleep_ms (10 )
987
+ self ._tx_xfer (quiet = True )
976
988
977
989
# Read a chunk from the file
978
990
remaining = filesize - bytes_sent
@@ -992,7 +1004,7 @@ def _cmd_get_object(self, params):
992
1004
self ._tx_xfer ()
993
1005
994
1006
# Progress indicator for large files
995
- if filesize > 100000 and bytes_sent % 100000 < chunk_size :
1007
+ if filesize > 10_000 and bytes_sent % 10_000 < chunk_size :
996
1008
self ._log ("File transfer progress: {:.1f}%" , (bytes_sent * 100.0 ) / filesize )
997
1009
998
1010
# Ensure final data is sent
0 commit comments