Skip to content

Commit 9b78f01

Browse files
committed
exit after displaying an error message since app will be in inconsistent state
1 parent a656d11 commit 9b78f01

File tree

3 files changed

+44
-32
lines changed

3 files changed

+44
-32
lines changed

VW_Flash_GUI.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@
4848
logger = logging.getLogger("VWFlash")
4949

5050

51-
def handle_exception(exc_type, exc_value, exc_traceback):
52-
if issubclass(exc_type, KeyboardInterrupt):
53-
sys.__excepthook__(exc_type, exc_value, exc_traceback)
54-
return
55-
logger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
51+
def show_error_dialog(exc_type, exc_value):
5652
dlg = wx.MessageDialog(
5753
None,
5854
f"A Python exception occured: {exc_type}, {exc_value}. Please check the log file.",
@@ -63,6 +59,15 @@ def handle_exception(exc_type, exc_value, exc_traceback):
6359
dlg.Destroy()
6460

6561

62+
def handle_exception(exc_type, exc_value, exc_traceback):
63+
if issubclass(exc_type, KeyboardInterrupt):
64+
sys.__excepthook__(exc_type, exc_value, exc_traceback)
65+
return
66+
logger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
67+
wx.CallAfter(show_error_dialog, exc_type, exc_value)
68+
wx.CallAfter(wx.Exit)
69+
70+
6671
def handle_threaded_exception(args, /):
6772
(exc_type, exc_value, exc_traceback, thread) = args
6873
handle_exception(exc_type, exc_value, exc_traceback)

lib/constants.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,9 @@ def internal_path(*path_parts) -> str:
241241

242242
testdata = {
243243
b"\x10\x03": b"\x50\x03\x12\x23\x34\x45",
244-
b"\x22\xf1\x90": b"\x62\xf1\x903VW12345678912345",
245244
b"\x10\x4f": b"\x50\x4f\x12\x23\x34\x45",
245+
b"\x10\x02": b"\x50\x02\x12\x23\x34\x45",
246+
b"\x22\xf1\x90": b"\x62\xf1\x903VW12345678912345",
246247
b"\x27\x03": b"\x67\x03\x12\x23\x34\x45",
247248
b"\x27\x04\x12\x23\xa1\x88": b"\x67\x04",
248249
b"\x2c\x03\xf2\x00": b"\x2c\x03\xf2\x00",
@@ -263,6 +264,9 @@ def internal_path(*path_parts) -> str:
263264
b"\x22\xf1\x7c": b"\x62\xf1\x7c\x5a\x53\x43\x2d\x38\x36\x34\x31\x35\x2e\x30\x37\x2e\x31\x38\x37\x38\x34\x33\x30\x33\x32\x30",
264265
b"\x22\xf1\xa5": b"\x62\xf1\xa5\x00\x00\x03\x78\x1f\xd7",
265266
b"\x22\x04\x05": b"\x62\x04\x05\x00",
267+
b"\x22\x06\x00": bytes.fromhex("620600091900122426000e3004"),
268+
b"\x31\x01\x02\x03": b"\x71\x01\x02\x03",
269+
b"\x3e\x00": b"\x7e\x00",
266270
b"\x04": b"\x04",
267271
}
268272

lib/flash_uds.py

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def __len__(self):
330330
if callback:
331331
callback(
332332
flasher_step="SETUP",
333-
flasher_status="In Flasher util ",
333+
flasher_status="Starting...",
334334
flasher_progress=100,
335335
)
336336
else:
@@ -368,7 +368,9 @@ def send_obd(data):
368368

369369
if callback:
370370
callback(
371-
flasher_step="SETUP", flasher_status="Clearing DTCs ", flasher_progress=100
371+
flasher_step="SETUP",
372+
flasher_status="Clearing DTCs...",
373+
flasher_progress=100,
372374
)
373375

374376
detailedLogger.info("Sending 0x4 Clear Emissions DTCs over OBD-2")
@@ -409,7 +411,7 @@ def volkswagen_security_algo(level: int, seed: bytes, params=None) -> bytes:
409411

410412
if callback:
411413
callback(
412-
flasher_step="SETUP",
414+
flasher_step="CONNECTING",
413415
flasher_status="Entering extended diagnostic session... ",
414416
flasher_progress=0,
415417
)
@@ -426,7 +428,7 @@ def volkswagen_security_algo(level: int, seed: bytes, params=None) -> bytes:
426428
callback(
427429
flasher_step="SETUP",
428430
flasher_status="Connected to vehicle with VIN: " + vin,
429-
flasher_progress=100,
431+
flasher_progress=20,
430432
)
431433

432434
detailedLogger.info(
@@ -443,7 +445,7 @@ def volkswagen_security_algo(level: int, seed: bytes, params=None) -> bytes:
443445
callback(
444446
flasher_step="SETUP",
445447
flasher_status="Checking programming precondition",
446-
flasher_progress=100,
448+
flasher_progress=40,
447449
)
448450

449451
detailedLogger.info("Checking programming precondition, routine 0x0203...")
@@ -456,7 +458,7 @@ def volkswagen_security_algo(level: int, seed: bytes, params=None) -> bytes:
456458
callback(
457459
flasher_step="SETUP",
458460
flasher_status="Upgrading to programming session...",
459-
flasher_progress=100,
461+
flasher_progress=60,
460462
)
461463

462464
detailedLogger.info("Upgrading to programming session...")
@@ -488,7 +490,7 @@ def switchpatch_programming_payload(payload):
488490
callback(
489491
flasher_step="SETUP",
490492
flasher_status="Performing Seed/Key authentication...",
491-
flasher_progress=100,
493+
flasher_progress=80,
492494
)
493495

494496
# Perform Seed/Key Security Level 17. This will call volkswagen_security_algo above to perform the Seed/Key auth against the SA2 script.
@@ -501,7 +503,7 @@ def switchpatch_programming_payload(payload):
501503
callback(
502504
flasher_step="SETUP",
503505
flasher_status="Writing Workshop data...",
504-
flasher_progress=100,
506+
flasher_progress=50,
505507
)
506508

507509
detailedLogger.info("Writing flash tool log to LocalIdentifier 0xF15A...")
@@ -536,7 +538,7 @@ def switchpatch_programming_payload(payload):
536538

537539
if callback:
538540
callback(
539-
flasher_step="SETUP",
541+
flasher_step="PROGRAMMING",
540542
flasher_status="Verifying reprogramming dependencies...",
541543
flasher_progress=100,
542544
)
@@ -547,32 +549,33 @@ def switchpatch_programming_payload(payload):
547549

548550
client.tester_present()
549551

550-
# If a periodic task was patched or altered as part of the process, let's give it a few seconds to run
551-
time.sleep(5)
552552
if callback:
553553
callback(
554-
flasher_step="SETUP",
554+
flasher_step="FINALIZING",
555555
flasher_status="Finalizing...",
556556
flasher_progress=100,
557557
)
558+
# If a periodic task was patched or altered as part of the process, let's give it a few seconds to run
559+
time.sleep(5)
558560

559561
detailedLogger.info("Rebooting ECU...")
560562
# Reboot
561-
client.ecu_reset(services.ECUReset.ResetType.hardReset)
562-
563-
conn.close()
564-
565-
detailedLogger.info("Sending 0x4 Clear Emissions DTCs over OBD-2")
566-
send_obd(bytes([0x4]))
567-
568-
if callback:
569-
callback(
570-
flasher_step="SETUP",
571-
flasher_status="DONE!...",
572-
flasher_progress=100,
573-
)
563+
try:
564+
client.ecu_reset(services.ECUReset.ResetType.hardReset)
565+
566+
conn.close()
567+
568+
detailedLogger.info("Sending 0x4 Clear Emissions DTCs over OBD-2")
569+
send_obd(bytes([0x4]))
570+
finally:
571+
if callback:
572+
callback(
573+
flasher_step="DONE",
574+
flasher_status="DONE!...",
575+
flasher_progress=100,
576+
)
574577

575-
detailedLogger.info("Done!")
578+
detailedLogger.info("Done!")
576579
except exceptions.NegativeResponseException as e:
577580
logger.error(
578581
'Server refused our request for service %s with code "%s" (0x%02x)'

0 commit comments

Comments
 (0)