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

feat: Expose the response pending timeout to CLI and config #579

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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