Skip to content

Commit

Permalink
feat: Expose the response pending timeout to CLI and config
Browse files Browse the repository at this point in the history
When using FlexRay the ISO-TP layer might be too slow for the UDS stack.
In our setup the UDS stack timeouted before the ISO-TP code was ready
with resolving a response pending.

This patch exposes the timeout value in order to be able to configure
this problem away.
  • Loading branch information
rumpelsepp committed Aug 21, 2024
1 parent 891cc86 commit 277bf8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/gallia/command/uds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", 2),
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),
Expand Down
11 changes: 7 additions & 4 deletions src/gallia/services/uds/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: ...
Expand Down Expand Up @@ -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
Expand All @@ -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})
Expand Down

0 comments on commit 277bf8c

Please sign in to comment.