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 authored and peckto committed Sep 4, 2024
1 parent 2aceca4 commit 241df6b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
8 changes: 8 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", 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),
Expand Down Expand Up @@ -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,
)

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
8 changes: 7 additions & 1 deletion src/gallia/services/uds/ecu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 241df6b

Please sign in to comment.