diff --git a/src/gallia/command/uds.py b/src/gallia/command/uds.py index 147fd67ff..d00885855 100644 --- a/src/gallia/command/uds.py +++ b/src/gallia/command/uds.py @@ -61,6 +61,13 @@ def configure_class_parser(self) -> None: metavar="SECONDS", help="Timeout value to wait for a response from the ECU", ) + group.add_argument( + "--pending-timeout", + default=self.config.get_value("gallia.protocols.uds.pending_timeout", 0.5), + type=float, + metavar="SECONDS", + help="Timeout value to resolve a response pending error", + ) group.add_argument( "--max-retries", default=self.config.get_value("gallia.protocols.uds.max_retries", 3), @@ -121,6 +128,7 @@ async def setup(self, args: Namespace) -> None: self.transport, timeout=args.timeout, max_retry=args.max_retries, + pending_timeout=args.pending_timeout, power_supply=self.power_supply, ) diff --git a/src/gallia/services/uds/core/client.py b/src/gallia/services/uds/core/client.py index 93dd159ed..8757460bc 100644 --- a/src/gallia/services/uds/core/client.py +++ b/src/gallia/services/uds/core/client.py @@ -24,6 +24,8 @@ class UDSRequestConfig: timeout: float | None = None # maximum number of attempts in case of network errors max_retry: int | None = None + # timeout value for resolving a response_pending error + pending_timeout: float | None = None # Skip the hooks which apply to session changes. skip_hooks: bool = False # tags to be applied to the logged output @@ -39,12 +41,13 @@ def __init__( transport: BaseTransport, timeout: float, max_retry: int = 1, + pending_timeout: float = 0.5, ): self.transport = transport self.timeout = timeout self.max_retry = max_retry self.retry_wait = 0.2 - self.pending_timeout = 5 + self.pending_timeout = pending_timeout self.mutex = asyncio.Lock() async def connect(self) -> None: ... @@ -106,8 +109,8 @@ async def request_unsafe( n_pending = 1 MAX_N_PENDING = 120 n_timeout = 0 - waiting_time = 0.5 - max_n_timeout = max(timeout if timeout else 0, 20) / waiting_time + pending_timeout = config.pending_timeout or self.pending_timeout + max_n_timeout = max(timeout if timeout else 0, 20) / pending_timeout while ( isinstance(resp, service.NegativeResponse) and resp.response_code == UDSErrorCodes.requestCorrectlyReceivedResponsePending @@ -117,7 +120,7 @@ async def request_unsafe( + f"waiting for next message: {n_timeout}/{int(max_n_timeout)}s" ) try: - raw_resp = await self._read(timeout=waiting_time, tags=config.tags) + raw_resp = await self._read(timeout=pending_timeout, tags=config.tags) if raw_resp == b"": raise BrokenPipeError("connection to target lost") logger.debug(raw_resp.hex(), extra={"tags": ["read", "uds"] + tags}) diff --git a/src/gallia/services/uds/ecu.py b/src/gallia/services/uds/ecu.py index 043e8768f..33e52b443 100644 --- a/src/gallia/services/uds/ecu.py +++ b/src/gallia/services/uds/ecu.py @@ -62,9 +62,15 @@ def __init__( transport: BaseTransport, timeout: float, max_retry: int = 1, + pending_timeout: float = 0.5, power_supply: PowerSupply | None = None, ) -> None: - super().__init__(transport, timeout, max_retry) + super().__init__( + transport=transport, + timeout=timeout, + max_retry=max_retry, + pending_timeout=pending_timeout, + ) self.tester_present_task: Task[None] | None = None self.tester_present_interval: float | None = None self.power_supply = power_supply