From c2dc7fe7274a209e0e02a0b328a1aa6ff0e94869 Mon Sep 17 00:00:00 2001 From: Andrew Lu Date: Mon, 24 Feb 2025 15:33:58 -0500 Subject: [PATCH] increase timeout window for completing file transfer --- pros/serial/devices/vex/v5_device.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pros/serial/devices/vex/v5_device.py b/pros/serial/devices/vex/v5_device.py index 2720c0c1..6ec6913d 100644 --- a/pros/serial/devices/vex/v5_device.py +++ b/pros/serial/devices/vex/v5_device.py @@ -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]: @@ -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("