forked from baconwaifu/PyVCDS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu_vw.py
102 lines (100 loc) · 4.02 KB
/
menu_vw.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import menu
import struct
import vw
import kwp
import vwtp
import queue
def mod_menu(car):
mod = menu.dselector({k:v for k,v in vw.modules.items() if k in car.enabled }, "Which Module?")
mod = car.module(int(mod))
with mod as m:
while True:
op = menu.selector(["Read Module ID", "Read Manufacturer Info", "Read Firmware Version", "Read Coding", "Re-Code module (EXPERIMENTAL)", "Read Measuring Block", "Load Labels for Module", "Drop to Python Console", "Back"])
if op == 0:
try:
print(m.readID())
except kwp.ENOENT:
print("Module ID measuring block not supported")
if op == 1:
print(m.readManufactureInfo())
if op == 2:
print(m.readFWVersion())
if op == 3:
print("Not Yet Implemented")
if op == 4:
raise NotImplementedError("Writing module coding is currently unavailable")
if op == 5:
raise NotImplementedError("Reading measuring blocks from the menu is currently unsupported")
if op == 6:
if not m.pn: #we need to know the part number of the ECU before we can know it's label file.
m.readPN()
path = input("Enter label directory path:\n> ")
vw.labels.setpath(path)
if m.pn in vw.labels: #there's more to this behind the scenes; it will transparently attempt to load labels on the fly when called for
print("Loaded")
else:
print("Error loading labels: missing or encrypted label file") #again, I *WILL NOT HELP* with decrypting clb labels.
if op == 7:
import pdb; pdb.set_trace()
if op == 8:
break
def main(sock):
with vwtp.VWTPStack(sock) as stack, vw.VWVehicle(stack) as car: #host the connection outside the menu loop.
while True:
opt = ["Enumerate Modules", "Connect to Module", "Read DTCs by module", "Read Measuring Data Block by module", "Long-Coding", "Load Labels from VCDS", "Load Labels from JSON", "Back"]
op = menu.selector(opt)
if op == 0:
print("Enumerating modules, please wait")
car.enum()
print("Modules Available:")
for mod in car.enabled:
print(" " + car.parts[mod]) #pre-formatted string.
elif op == 1: #Connect to Module
if not car.scanned:
print("Enumerating modules, please wait")
car.enum()
mod_menu(car)
elif op == 2:
if not car.scanned:
car.enum()
for mod in car.enabled:
print("Checking module '{}'".format(vw.modules[mod]))
try:
with car.module(mod) as m:
dtc = m.readDTC()
if len(dtc) > 0:
print("Found DTCs:")
else:
print("No Faults detected")
for d in dtc:
if d in vw.labels[module]["dtc"]:
print(vw.labels[module]["dtc"][d])
else:
print("Unknown DTC '{}'".format(d))
except kwp.EPERM:
print("Permissions error getting DTCs from module, skipping")
except (ValueError, queue.Empty, kwp.KWPException) as e:
print("Unknown fault getting DTCs from module:",e)
elif op == 3: #read measuring block
mods = {}
for i in car.enabled:
mods[i] = vw.modules[i]
op2 = dselector(mods)
with car.module(mod) as mod:
blk = menu.dselector(vw.labels[module]["blocks"])
blk = mod.readBlock(blk)
for b in blk:
print(b)
elif op == 4: #long-code
raise NotImplementedError("Need a CAN trace of someone with VCDS reading or writing a long-code")
elif op == 5:
raise NotImplementedError("VCDS Label parsing has not yet been implemented")
elif op == 6:
print("Path to the JSON file?")
path = input("> ")
fd = open(path, "r")
js = fd.read()
fd.close()
vw.loadLabelsFromJSON(js)
elif op == 7:
return