Skip to content

Commit 4634d44

Browse files
authored
🐛 increase timeout window for completing file transfer (#385)
1 parent 3e08b4f commit 4634d44

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pros/serial/devices/vex/v5_device.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,14 @@ def write_file(self, file: typing.BinaryIO, remote_file: str, file_len: int = -1
585585
if compress and self.status['system_version'] in Spec('>=1.0.5'):
586586
logger(__name__).info('Closing gzip file')
587587
file.close()
588-
self.ft_complete(options=run_after)
588+
# The time to write the file to flash isn't exactly linear with the file size,
589+
# but it's okay even if we slightly underestimate as long as we get a response back
590+
# on one of the 3 tries of ft_complete.
591+
# The point is to set our timeout window so we aren't waiting too long for a response
592+
# that will never happen if, for example, the brain turned off.
593+
ft_timeout = max(file_len/200000, 1.0)
594+
logger(__name__).debug(f'Setting file transfer timeout as {ft_timeout:.2f} seconds')
595+
self.ft_complete(options=run_after, timeout=ft_timeout)
589596

590597
@with_download_channel
591598
def capture_screen(self) -> Tuple[List[List[int]], int, int]:
@@ -688,12 +695,12 @@ def ft_initialize(self, file_name: str, **kwargs) -> Dict[str, Any]:
688695
return rx
689696

690697
@retries
691-
def ft_complete(self, options: FTCompleteOptions = FTCompleteOptions.DONT_RUN):
698+
def ft_complete(self, options: FTCompleteOptions = FTCompleteOptions.DONT_RUN, timeout: float = 1.0):
692699
logger(__name__).debug('Sending ext 0x12 command')
693700
if isinstance(options, bool):
694701
options = self.FTCompleteOptions.RUN_IMMEDIATELY if options else self.FTCompleteOptions.DONT_RUN
695702
tx_payload = struct.pack("<B", options.value)
696-
ret = self._txrx_ext_packet(0x12, tx_payload, 0, timeout=self.default_timeout * 10)
703+
ret = self._txrx_ext_packet(0x12, tx_payload, 0, timeout=timeout)
697704
logger(__name__).debug('Completed ext 0x12 command')
698705
return ret
699706

0 commit comments

Comments
 (0)