118118# Maximum sizes and buffers
119119# _MAX_PACKET_SIZE = const(512)
120120_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 )
123123_CONTAINER_HEADER_SIZE = const (12 )
124124
125125# MTP struct definitions using uctypes
@@ -310,13 +310,15 @@ def _rx_cb(self, ep, res, num_bytes):
310310 self ._log ("OUT transfer failed with error {}" , res )
311311 self ._rx_xfer () # Continue receiving
312312
313- def _tx_xfer (self ):
313+ def _tx_xfer (self , quiet = False ):
314314 """Submit a new transfer to send data to the host."""
315315 if self .is_open () and not self .xfer_pending (self .ep_in ) and self ._tx .readable ():
316316 buf = self ._tx .pend_read ()
317317 self ._log ("Submitting IN transfer, data size={}" , len (buf ))
318318 self .submit_xfer (self .ep_in , buf , self ._tx_cb )
319319 else :
320+ if quiet :
321+ return
320322 if not self .is_open ():
321323 self ._log ("Cannot submit IN transfer - interface not open" )
322324 elif self .xfer_pending (self .ep_in ):
@@ -960,19 +962,29 @@ def _cmd_get_object(self, params):
960962
961963 # Write header to TX buffer
962964 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+
963969 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+
964974
965975 # Now send the file data in chunks
966976 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 ))
968978
969979 while bytes_sent < filesize :
970980 # 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:
972982 if not self .is_open ():
973983 self ._log ("Interface closed during file transfer" )
974984 return
975- time .sleep_ms (1 )
985+
986+ time .sleep_ms (10 )
987+ self ._tx_xfer (quiet = True )
976988
977989 # Read a chunk from the file
978990 remaining = filesize - bytes_sent
@@ -992,7 +1004,7 @@ def _cmd_get_object(self, params):
9921004 self ._tx_xfer ()
9931005
9941006 # 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 :
9961008 self ._log ("File transfer progress: {:.1f}%" , (bytes_sent * 100.0 ) / filesize )
9971009
9981010 # Ensure final data is sent
0 commit comments