Skip to content

Commit

Permalink
scan-session: Fix logic
Browse files Browse the repository at this point in the history
  • Loading branch information
fkglr committed Mar 20, 2024
1 parent f91fe2c commit 306fd91
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/gallia/commands/scan/uds/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ def configure_parser(self) -> None:
action="store_true",
help="Use hooks in case of a ConditionsNotCorrect error",
)
self.parser.add_argument(
"--reset",
action="store_true",
help="Reset and if necessary power cycle the ECU after each iteration",
)
self.parser.add_argument(
"--fast",
action="store_true",
Expand Down Expand Up @@ -141,22 +136,14 @@ async def main(self, args: Namespace) -> None:
if stack:
logger.info(f"Starting from session: {g_repr(stack[-1])}")

current_session = 1

for session in sessions:
if session in args.skip:
logger.info(f"Skipping session {g_repr(session)} as requested")
continue

if args.reset:
logger.info("Resetting the ECU")
success = await self.ecu.leave_session(session)

if not success:
logger.warning("Could not reset ECU; continuing without reset")
else:
logger.info("Waiting for the ECU to recover…")
await self.ecu.wait_for_ecu(timeout=args.timeout)

if not (await self.ecu.leave_session(session)):
if not (await self.ecu.leave_session(current_session)):
logger.error("Could not change to default session")
sys.exit(1)

Expand All @@ -167,14 +154,15 @@ async def main(self, args: Namespace) -> None:
if not await self.recover_stack(stack, args.with_hooks):
sys.exit(1)

current_session = stack[-1]

try:
logger.debug(f"Attempting to change to session {session:#04x}")
resp = await self.set_session_with_hooks_handling(session, args.with_hooks)

# do not ignore NCR subFunctionNotSupportedInActiveSession in this case
if (
isinstance(resp, NegativeResponse)
and resp.response_code == UDSErrorCodes.subFunctionNotSupported
isinstance(resp, NegativeResponse) and resp.response_code == UDSErrorCodes.subFunctionNotSupported
):
logger.info(f"Could not change to session {g_repr(session)}: {resp}")
continue
Expand All @@ -192,6 +180,8 @@ async def main(self, args: Namespace) -> None:
positive_results.append(
{"session": session, "stack": stack, "error": None}
)

current_session = session
else:
negative_results.append(
{
Expand Down

0 comments on commit 306fd91

Please sign in to comment.