Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 increase timeout window for completing file transfer #385

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading