forked from Marianpol/pyclip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_ecu_default.py
458 lines (421 loc) · 16.8 KB
/
mod_ecu_default.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
#Embedded file name: /build/PyCLIP/android/app/mod_ecu_default.py
from mod_ecu_mnemonic import *
from mod_ecu_screen import *
from mod_ecu_service import *
from mod_utils import Choice
from xml.dom.minidom import parse
from xml.dom.minidom import parseString
import xml.dom.minidom
import string
import mod_globals
def get_default_std_a(df, mn, se, elm, calc, getDTCmnemo):
resp = ''
elm.cmd('at st fa')
elm.cmd('at at 0')
if len(mn[getDTCmnemo].sids) > 0:
for sid in mn[getDTCmnemo].sids:
service = se[sid]
resp = executeService(service, elm, [], '', False)
elm.cmd('at at 1')
resp = resp.strip().replace(' ', '')
if not all((c in string.hexdigits for c in resp)):
resp = ''
resp = ' '.join((a + b for a, b in zip(resp[::2], resp[1::2])))
descr = {}
helps = {}
dtcs = []
if not resp.startswith(mn[getDTCmnemo].positive) or len(resp) < 6:
return (dtcs, descr, helps)
numberOfDTCs = int(resp[3:5], 16)
DTCs = resp[6:]
while len(DTCs) >= 8 and numberOfDTCs > 0:
dtc = DTCs[:6].replace(' ', '')
status = DTCs[6:8]
numberOfDTCs = numberOfDTCs - 1
if dtc not in df.keys():
DTCs = DTCs[9:]
continue
comp = df[dtc].computation
comp = comp.replace('&', '&')
for m in sorted(df[dtc].mnemolistComp, key=len, reverse=True):
hex_val = get_mnemonicDTC(mn[m], '57 01 ' + DTCs)
comp = comp.replace(m, '0x' + hex_val)
isExists = calc.calculate(comp)
# if isExists == 0:
# DTCs = DTCs[9:]
# continue
infoPeriod = df[dtc].interpInfoPeri
if len(infoPeriod.strip()) != 0:
infoPeriod = infoPeriod.replace('&', '&')
for m in sorted(df[dtc].mnemolistIP, key=len, reverse=True):
hex_val = get_mnemonicDTC(mn[m], '57 01 ' + DTCs)
infoPeriod = infoPeriod.replace(m, '0x' + hex_val)
df[dtc].status = calc.calculate(infoPeriod)
else:
df[dtc].status = 2
# if df[dtc].status == 0:
# DTCs = DTCs[9:]
# continue
isAlive = ''
if df[dtc].status == 1:
isAlive = mod_globals.language_dict['16882']
else:
isAlive = mod_globals.language_dict['646']
# if df[dtc].status == 0:
# DTCs = DTCs[9:]
# continue
comp = df[dtc].interpInfoComp
if len(comp.strip()) != 0:
comp = comp.replace('&', '&')
for m in sorted(df[dtc].mnemolistIC, key=len, reverse=True):
hex_val = get_mnemonicDTC(mn[m], '57 01 ' + DTCs)
comp = comp.replace(m, '0x' + hex_val)
chr_val = calc.calculate(comp)
else:
chr_val = ''
if str(chr_val).encode('utf-8') in df[dtc].caracter.keys():
interpretation = df[dtc].caracter[str(chr_val).encode('utf-8')]
else:
interpretation = ''
description = df[dtc].label
if mod_globals.os == 'android':
defstr = '%-6s (DTC%-6s) %-41s %-6s %-10s' % (df[dtc].agcdRef,
dtc + status,
description,
interpretation,
isAlive)
else:
defstr = '%-6s (DTC%-6s) %-50s %-6s %-10s' % (df[dtc].agcdRef,
dtc + status,
description,
interpretation,
isAlive)
hlpstr = ''
if len(df[dtc].helps):
for l in sorted(df[dtc].helps):
hlpstr = hlpstr + '\t' + l.replace('\n', '') + '\n'
DTCs = DTCs[9:]
dtcs.append(dtc + status)
descr[dtc + status] = defstr
helps[dtc + status] = hlpstr
return (dtcs, descr, helps)
def get_default_std_b(df, mn, se, elm, calc, getDTCmnemo):
resp = ''
elm.cmd('at st fa')
elm.cmd('at at 0')
if len(mn[getDTCmnemo].sids) > 0:
for sid in mn[getDTCmnemo].sids:
service = se[sid]
resp = executeService(service, elm, [], '', False)
elm.cmd('at at 1')
resp = resp.strip().replace(' ', '')
if not all((c in string.hexdigits for c in resp)):
resp = ''
resp = ' '.join((a + b for a, b in zip(resp[::2], resp[1::2])))
descr = {}
helps = {}
dtcs = []
if not resp.startswith(mn[getDTCmnemo].positive) or len(resp) < 6:
return (dtcs, descr, helps)
DTCs = resp[9:]
while len(DTCs) >= 11:
dtc = DTCs[:6].replace(' ', '')
dtcType = DTCs[6:8]
dtcStatus = DTCs[9:11]
if dtc not in df.keys():
DTCs = DTCs[12:]
continue
comp = df[dtc].computation
comp = comp.replace('&', '&')
for m in sorted(df[dtc].mnemolistComp, key=len, reverse=True):
hex_val = get_mnemonicDTC(mn[m], '59 02 FF ' + DTCs)
comp = comp.replace(m, '0x' + hex_val)
isExists = calc.calculate(comp)
# if isExists == 0:
# DTCs = DTCs[12:]
# continue
infoPeriod = df[dtc].interpInfoPeri
if len(infoPeriod.strip()) == 0:
infoPeriod = infoPeriod.replace('&', '&')
for m in sorted(df[dtc].mnemolistIP, key=len, reverse=True):
hex_val = get_mnemonicDTC(mn[m], '59 02 FF ' + DTCs)
infoPeriod = infoPeriod.replace(m, '0x' + hex_val)
df[dtc].status = calc.calculate(infoPeriod)
else:
df[dtc].status = 2
# if df[dtc].status == 0:
# DTCs = DTCs[12:]
# continue
isAlive = ''
if df[dtc].status == 1:
isAlive = mod_globals.language_dict['16882']
else:
isAlive = mod_globals.language_dict['646']
# if df[dtc].status == 0:
# DTCs = DTCs[12:]
# continue
comp = df[dtc].interpInfoComp
if len(comp.strip()) != 0:
comp = comp.replace('&', '&')
for m in sorted(df[dtc].mnemolistIC, key=len, reverse=True):
hex_val = get_mnemonicDTC(mn[m], '59 02 FF ' + DTCs)
comp = comp.replace(m, '0x' + hex_val)
chr_val = calc.calculate(comp)
else:
chr_val = ''
if str(chr_val).encode('utf-8') in df[dtc].caracter.keys():
interpretation = df[dtc].caracter[str(chr_val).encode('utf-8')]
else:
interpretation = ''
description = df[dtc].label
if mod_globals.os == 'android':
defstr = 'DTC%-6s (%s) %-41s %-6s %-10s' % (dtc + dtcType,
df[dtc].agcdRef,
description,
interpretation,
isAlive)
else:
defstr = 'DTC%-6s (%s) %-50s %-6s %-10s' % (dtc + dtcType,
df[dtc].agcdRef,
description,
interpretation,
isAlive)
stBitsDef = ['warningIndicatorRequested',
'testNotCompletedThisOperationCycle',
'testFailedSinceLastClear',
'testNotCompletedSinceLastClear',
'confirmedDTC',
'pendingDTC',
'testFailedThisOperationCycle',
'testFailed']
hlpstr = ''
if len(df[dtc].helps):
for l in sorted(df[dtc].helps):
if l.split(':')[0] == interpretation:
hlpstr = hlpstr + '\t' + l.replace('\n', '') + '\n'
if mod_globals.opt_verbose:
stBits = '{0:0>8b}'.format(int(dtcStatus, 16))
hlpstr = hlpstr + '\t----------- Status byte: ' + dtcStatus + ' -----------\n'
for i in range(0, 8):
hlpstr = hlpstr + '\t%-35s : %s\n' % (stBitsDef[i], stBits[i])
DTCs = DTCs[12:]
dtcs.append(dtc + dtcType)
descr[dtc + dtcType] = defstr
helps[dtc + dtcType] = hlpstr
return (dtcs, descr, helps)
def get_default_failflag(df, mn, se, elm, calc):
descr = {}
helps = {}
dtcs = []
for dtc in sorted(df.keys()):
comp = df[dtc].computation
comp = comp.replace('&', '&')
for m in sorted(df[dtc].mnemolistComp, key=len, reverse=True):
hex_val = get_mnemonic(mn[m], se, elm)
comp = comp.replace(m, '0x' + hex_val)
isExists = calc.calculate(comp)
if isExists == 0:
continue
infoPeriod = df[dtc].interpInfoPeri
if len(infoPeriod.strip()) == 0:
continue
infoPeriod = infoPeriod.replace('&', '&')
for m in sorted(df[dtc].mnemolistIP, key=len, reverse=True):
hex_val = get_mnemonic(mn[m], se, elm)
infoPeriod = infoPeriod.replace(m, '0x' + hex_val)
df[dtc].status = calc.calculate(infoPeriod)
if df[dtc].status == 0:
continue
isAlive = ''
if df[dtc].status == 1:
isAlive = mod_globals.language_dict['16882']
else:
isAlive = mod_globals.language_dict['646']
interp = df[dtc].interpInfoComp
if len(interp.strip()) == 0:
interpretation = ''
else:
interp = interp.replace('&', '&')
for m in sorted(df[dtc].mnemolistIC, key=len, reverse=True):
hex_val = get_mnemonic(mn[m], se, elm)
interp = interp.replace(m, '0x' + hex_val)
tmp_interp = calc.calculate(interp)
interpretation = ''
if str(tmp_interp).encode('utf-8') in df[dtc].caracter.keys():
interpretation = df[dtc].caracter[str(tmp_interp).encode('utf-8')]
else:
interpretation = ''
description = df[dtc].label
if mod_globals.os == 'android':
defstr = '%-6s %-41s %-6s %-10s' % (df[dtc].agcdRef,
description,
interpretation,
isAlive)
else:
defstr = '%-6s %-50s %-6s %-10s' % (df[dtc].agcdRef,
description,
interpretation,
isAlive)
hlpstr = ''
if len(df[dtc].helps):
for l in sorted(df[dtc].helps):
hlpstr = hlpstr + '\t' + l.replace('\n', '') + '\n'
dtcs.append(dtc)
descr[dtc] = defstr
helps[dtc] = hlpstr
return (dtcs, descr, helps)
class ecu_default:
name = ''
code = ''
agcdRef = ''
codeMR = ''
mask = ''
label = ''
status = 0
datarefs = []
memDatarefs = []
helps = []
caracter = {}
interpInfoPeri = ''
mnemolistIP = []
interpInfoComp = ''
mnemolistIC = []
computation = ''
mnemolistComp = []
def __init__(self, df, opt, tran):
self.name = df.getAttribute('name')
self.agcdRef = df.getAttribute('agcdRef')
self.codeMR = df.getAttribute('codeMR')
Mask = df.getElementsByTagName("Mask")
if Mask:
self.mask = Mask.item(0).getAttribute("value")
Label = df.getElementsByTagName('Label')
codetext = Label.item(0).getAttribute('codetext')
defaultText = Label.item(0).getAttribute('defaultText')
self.label = ''
if codetext:
if codetext in tran.keys():
self.label = tran[codetext]
elif defaultText:
self.label = defaultText
self.datarefs = []
CurrentInfo = df.getElementsByTagName('CurrentInfo')
if CurrentInfo:
for ci in CurrentInfo:
DataRef = ci.getElementsByTagName('DataRef')
if DataRef:
for dr in DataRef:
dataref = ecu_screen_dataref(dr)
self.datarefs.append(dataref)
self.memDatarefs = []
MemorisedInfo = df.getElementsByTagName('MemorisedInfo')
if MemorisedInfo:
for mi in MemorisedInfo:
DataRef = mi.getElementsByTagName('DataRef')
if DataRef:
for dr in DataRef:
dataref = ecu_screen_dataref(dr)
self.memDatarefs.append(dataref)
self.helps = []
Helps = df.getElementsByTagName('Helps')
if Helps:
for hl in Helps:
Lines = hl.getElementsByTagName('Line')
if Lines:
for ln in Lines:
line = ''
Label = ln.getElementsByTagName('Label')
if Label:
for la in Label:
codetext = la.getAttribute('codetext')
defaultText = la.getAttribute('defaultText')
if codetext:
if codetext in tran.keys():
line = line + tran[codetext]
elif defaultText:
line = line + defaultText
self.helps.append(line)
self.caracter = {}
Caracterisation = df.getElementsByTagName('Caracterisation')
if Caracterisation:
for cor in Caracterisation:
Correspondance = cor.getElementsByTagName('Correspondance')
if Correspondance:
for co in Correspondance:
ivalue = co.getAttribute('value')
codetext = co.getAttribute('codetext')
defaultText = co.getAttribute('defaultText')
itext = ''
if codetext:
if codetext in tran.keys():
itext = tran[codetext]
elif defaultText:
itext = defaultText
self.caracter[ivalue] = itext
xmlstr = opt[self.name]
odom = xml.dom.minidom.parseString(xmlstr.encode('utf-8'))
odoc = odom.documentElement
tmp = odoc.getAttribute('codeDTC')
if tmp != '':
self.code = hex(int(tmp)).replace('0x', '').zfill(4).upper()
else:
self.code = self.agcdRef
self.computation = ''
Computation = odoc.getElementsByTagName('Computation')
if Computation:
for cmpt in Computation:
tmp = cmpt.getElementsByTagName('Value').item(0).firstChild.nodeValue
self.computation = tmp.replace(' ', '').replace('&', '&')
self.mnemolistComp = []
Mnemo = cmpt.getElementsByTagName('Mnemo')
if Mnemo:
for mn in Mnemo:
self.mnemolistComp.append(mn.getAttribute('name'))
self.interpInfoComp = ''
Interpretation = odoc.getElementsByTagName('Interpretation')
if Interpretation:
for itp in Interpretation:
if itp.getAttribute('name') == 'InfoComp':
tmp = itp.getElementsByTagName('Value').item(0).firstChild.nodeValue
self.interpInfoComp = tmp.replace(' ', '').replace('&', '&')
self.mnemolistIC = []
Mnemo = itp.getElementsByTagName('Mnemo')
if Mnemo:
for mn in Mnemo:
self.mnemolistIC.append(mn.getAttribute('name'))
if itp.getAttribute('name') == 'InfoPeriod':
tmp = itp.getElementsByTagName('Value').item(0).firstChild.nodeValue
self.interpInfoPeri = tmp.replace(' ', '').replace('&', '&')
self.mnemolistIP = []
Mnemo = itp.getElementsByTagName('Mnemo')
if Mnemo:
for mn in Mnemo:
self.mnemolistIP.append(mn.getAttribute('name'))
class ecu_defaults:
def __init__(self, default_list, mdoc, opt, tran):
Defaults = mdoc.getElementsByTagName('Default')
if Defaults:
for df in Defaults:
default = ecu_default(df, opt, tran)
default_list[default.code] = default
def getDTCCommands(self, mdoc, opt, ecu_type):
eraserCommandName = ''
extractDTCmnemo = ''
Eraser = mdoc.getElementsByTagName('Eraser').item(0)
if Eraser:
eraserCommandName = Eraser.getElementsByTagName('DataRef').item(0).getAttribute('name')
xmlstr = opt['Command\\' + eraserCommandName]
odom = xml.dom.minidom.parseString(xmlstr.encode('utf-8'))
odoc = odom.documentElement
xmlstr = ''
if 'ExtractDBDTCCode' in opt.keys():
xmlstr = opt['ExtractDBDTCCode']
elif 'ExtractCode' in opt.keys():
xmlstr = opt['ExtractCode']
if len(xmlstr) > 0 and (ecu_type == 'STD_A' or ecu_type == 'STD_B' or ecu_type == 'UDS'):
odom = xml.dom.minidom.parseString(xmlstr.encode('utf-8'))
odoc = odom.documentElement
Mnemo = odom.getElementsByTagName('Mnemo').item(0)
if Mnemo:
extractDTCmnemo = Mnemo.getAttribute('name')
return (extractDTCmnemo, eraserCommandName)