Skip to content

Commit

Permalink
refactor(scan-session) Replace reset with leave_session
Browse files Browse the repository at this point in the history
  • Loading branch information
fkglr committed Nov 28, 2023
1 parent 6cda9b0 commit 63f10c2
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions src/gallia/commands/scan/uds/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ def configure_parser(self) -> None:
)
self.parser.add_argument(
"--reset",
nargs="?",
default=None,
const=0x01,
type=lambda x: int(x, 0),
help="Reset the ECU after each iteration with the optionally given reset level",
action="store_true",
help="Reset and if necessary power cycle the ECU after each iteration",
)
self.parser.add_argument(
"--fast",
Expand Down Expand Up @@ -156,24 +153,16 @@ async def main(self, args: Namespace) -> None:
continue

if args.reset:
try:
logger.info("Resetting the ECU")
resp: UDSResponse = await self.ecu.ecu_reset(args.reset)

if isinstance(resp, NegativeResponse):
logger.warning(
f"Could not reset ECU with {EcuResetSubFuncs(args.reset).name if args.reset in iter(EcuResetSubFuncs) else args.reset}: {resp}"
f"; continuing without reset"
)
else:
logger.info("Waiting for the ECU to recover…")
await self.ecu.wait_for_ecu(timeout=args.timeout)
except (asyncio.TimeoutError, ConnectionError):
logger.info("Resetting the ECU")
success = await self.ecu.leave_session(session)

if not success:
logger.warning(
"Lost connection to the ECU after performing a reset. "
"Attempting to reconnect…"
f"Could not reset ECU; continuing without reset"
)
await self.ecu.reconnect()
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)):
logger.error("Could not change to default session")
Expand Down

0 comments on commit 63f10c2

Please sign in to comment.