From 6cda9b05a49b39d0258ea07d8b9e36adb8c82f5a Mon Sep 17 00:00:00 2001 From: fabian Date: Tue, 28 Nov 2023 17:15:21 +0100 Subject: [PATCH 1/4] refactor(ecu-reset): use leave_session --- src/gallia/commands/scan/uds/sessions.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/gallia/commands/scan/uds/sessions.py b/src/gallia/commands/scan/uds/sessions.py index 3803c7e47..e461559fd 100644 --- a/src/gallia/commands/scan/uds/sessions.py +++ b/src/gallia/commands/scan/uds/sessions.py @@ -175,14 +175,8 @@ async def main(self, args: Namespace) -> None: ) await self.ecu.reconnect() - try: - logger.debug("Changing session to DefaultSession") - resp = await self.ecu.set_session(0x01, use_db=False) - if isinstance(resp, NegativeResponse): - logger.error(f"Could not change to default session: {resp}") - sys.exit(1) - except Exception as e: - logger.error(f"Could not change to default session: {e!r}") + if not (await self.ecu.leave_session(session)): + logger.error("Could not change to default session") sys.exit(1) logger.debug( From 63f10c24ac30dca7fcef5710c3a6c4825de56236 Mon Sep 17 00:00:00 2001 From: fabian Date: Tue, 28 Nov 2023 18:34:30 +0100 Subject: [PATCH 2/4] 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") From f91fe2c41be2c8f1067045496d8e2f890feeec27 Mon Sep 17 00:00:00 2001 From: fabian Date: Wed, 20 Mar 2024 19:02:13 +0100 Subject: [PATCH 3/4] Reformatted --- src/gallia/commands/scan/uds/sessions.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/gallia/commands/scan/uds/sessions.py b/src/gallia/commands/scan/uds/sessions.py index b6333ed9e..98d38fccc 100644 --- a/src/gallia/commands/scan/uds/sessions.py +++ b/src/gallia/commands/scan/uds/sessions.py @@ -13,9 +13,7 @@ NegativeResponse, UDSErrorCodes, UDSRequestConfig, - UDSResponse, ) -from gallia.services.uds.core.constants import EcuResetSubFuncs from gallia.services.uds.core.service import DiagnosticSessionControlResponse from gallia.services.uds.core.utils import g_repr from gallia.utils import auto_int @@ -153,9 +151,7 @@ async def main(self, args: Namespace) -> None: success = await self.ecu.leave_session(session) if not success: - logger.warning( - f"Could not reset ECU; continuing without reset" - ) + 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) From e2ca6ba8ee2b6a90e34f4eabb83e9c136fdf60d4 Mon Sep 17 00:00:00 2001 From: fabian Date: Wed, 20 Mar 2024 19:54:24 +0100 Subject: [PATCH 4/4] scan-session: Fix logic --- src/gallia/commands/scan/uds/sessions.py | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/gallia/commands/scan/uds/sessions.py b/src/gallia/commands/scan/uds/sessions.py index 98d38fccc..932eee88e 100644 --- a/src/gallia/commands/scan/uds/sessions.py +++ b/src/gallia/commands/scan/uds/sessions.py @@ -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", @@ -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) @@ -167,6 +154,8 @@ 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) @@ -192,6 +181,8 @@ async def main(self, args: Namespace) -> None: positive_results.append( {"session": session, "stack": stack, "error": None} ) + + current_session = session else: negative_results.append( {