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

feat(scan-reset): added option to power-cycle on timeout #325

Draft
wants to merge 3 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: 36 additions & 10 deletions src/gallia/commands/scan/uds/reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def configure_parser(self) -> None:
action="store_true",
help="skip check current session",
)
self.parser.add_argument(
"--power-cycle-on-timeout",
action="store_true",
help="power-cycle ECU in case of a timeout",
)

async def main(self, args: Namespace) -> None:
l_ok: dict[int, list[int]] = {}
Expand Down Expand Up @@ -141,16 +146,37 @@ async def main(self, args: Namespace) -> None:
else:
await self.ecu.wait_for_ecu()

except asyncio.TimeoutError:
self.logger.error(
f"ECU did not respond after reset level {g_repr(sub_func)}; exiting…"
)
sys.exit(1)
except ConnectionError:
msg = f"{g_repr(sub_func)}: lost connection to ECU (post), current session: {g_repr(session)}"
self.logger.warning(msg)
await self.ecu.reconnect()
continue
except (asyncio.TimeoutError, ConnectionError) as e:
if args.power_cycle_on_timeout:
try:
self.logger.warning(
f"ECU did not respond after reset level {g_repr(sub_func)}; trying power-cycle..."
)
await self.ecu.power_cycle()
await self.ecu.wait_for_ecu()
except asyncio.TimeoutError:
self.logger.error(
f"ECU did not respond after power-cycle {g_repr(sub_func)}; exiting…"
)
sys.exit(1)
except ConnectionError:
msg = (
f"{g_repr(sub_func)}: lost connection to ECU (post), current session: "
f"{g_repr(session)}"
)
self.logger.warning(msg)
await self.ecu.reconnect()
continue
elif isinstance(e, asyncio.TimeoutError):
self.logger.error(
f"ECU did not respond after reset level {g_repr(sub_func)}; exiting…"
)
sys.exit(1)
elif isinstance(e, ConnectionError):
msg = f"{g_repr(sub_func)}: lost connection to ECU (post), current session: {g_repr(session)}"
self.logger.warning(msg)
await self.ecu.reconnect()
continue

# We reach this code only for positive responses
if not args.skip_check_session:
Expand Down