Skip to content

Commit

Permalink
increase timeout window for completing file transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewLuGit committed Feb 24, 2025
1 parent 3e08b4f commit c2dc7fe
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pros/serial/devices/vex/v5_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,14 @@ def write_file(self, file: typing.BinaryIO, remote_file: str, file_len: int = -1
if compress and self.status['system_version'] in Spec('>=1.0.5'):
logger(__name__).info('Closing gzip file')
file.close()
self.ft_complete(options=run_after)
# The time to write the file to flash isn't exactly linear with the file size,
# but it's okay even if we slightly underestimate as long as we get a response back
# on one of the 3 tries of ft_complete.
# The point is to set our timeout window so we aren't waiting too long for a response
# that will never happen if, for example, the brain turned off.
ft_timeout = max(file_len/200000, 1.0)
logger(__name__).debug(f'Setting file transfer timeout as {ft_timeout:.2f} seconds')
self.ft_complete(options=run_after, timeout=ft_timeout)

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

@retries
def ft_complete(self, options: FTCompleteOptions = FTCompleteOptions.DONT_RUN):
def ft_complete(self, options: FTCompleteOptions = FTCompleteOptions.DONT_RUN, timeout: float = 1.0):
logger(__name__).debug('Sending ext 0x12 command')
if isinstance(options, bool):
options = self.FTCompleteOptions.RUN_IMMEDIATELY if options else self.FTCompleteOptions.DONT_RUN
tx_payload = struct.pack("<B", options.value)
ret = self._txrx_ext_packet(0x12, tx_payload, 0, timeout=self.default_timeout * 10)
ret = self._txrx_ext_packet(0x12, tx_payload, 0, timeout=timeout)
logger(__name__).debug('Completed ext 0x12 command')
return ret

Expand Down

0 comments on commit c2dc7fe

Please sign in to comment.