From 63f10c24ac30dca7fcef5710c3a6c4825de56236 Mon Sep 17 00:00:00 2001 From: fabian Date: Tue, 28 Nov 2023 18:34:30 +0100 Subject: [PATCH] refactor(scan-session) Replace reset with leave_session --- src/gallia/commands/scan/uds/sessions.py | 31 ++++++++---------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/gallia/commands/scan/uds/sessions.py b/src/gallia/commands/scan/uds/sessions.py index e461559fd..5c30176b3 100644 --- a/src/gallia/commands/scan/uds/sessions.py +++ b/src/gallia/commands/scan/uds/sessions.py @@ -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", @@ -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")