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

Reset leave session #472

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
46 changes: 8 additions & 38 deletions src/gallia/commands/scan/uds/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,14 +51,6 @@ def configure_parser(self) -> None:
action="store_true",
help="Use hooks in case of a ConditionsNotCorrect error",
)
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",
)
self.parser.add_argument(
"--fast",
action="store_true",
Expand Down Expand Up @@ -146,39 +136,15 @@ 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:
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 (TimeoutError, ConnectionError):
logger.warning(
"Lost connection to the ECU after performing a reset. "
"Attempting to reconnect…"
)
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(current_session)):
logger.error("Could not change to default session")
sys.exit(1)

logger.debug(f"Sleeping for {args.sleep}s after changing to DefaultSession")
Expand All @@ -188,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)
Expand All @@ -213,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(
{
Expand Down