forked from Marianpol/pyclip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_ecu.py
1462 lines (1355 loc) · 55.6 KB
/
mod_ecu.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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#Embedded file name: /build/PyCLIP/android/app/mod_ecu.py
import sys
import time
import xml.dom.minidom
from collections import OrderedDict
from datetime import datetime
from xml.dom.minidom import parse
from kivy import base
from kivy.app import App
from kivy.base import EventLoop
from kivy.clock import Clock
from kivy.core.window import Window
from kivy.graphics import Color, Rectangle
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.uix.scrollview import ScrollView
from kivy.properties import NumericProperty
from kivy.utils import platform
import mod_globals
import mod_zip
from mod_ecu_command import *
from mod_ecu_dataids import *
from mod_ecu_default import *
from mod_ecu_identification import *
from mod_ecu_mnemonic import *
from mod_ecu_parameter import *
from mod_ecu_screen import *
from mod_ecu_service import *
from mod_ecu_state import *
from mod_elm import AllowedList
from mod_elm import dnat
from mod_elm import snat
from mod_optfile import *
from mod_ply import *
from mod_utils import *
os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))
fmn = 1.7
bmn = 2.5
F2A = {'01': '7A',
'02': '01',
'03': '51',
'04': '26',
'05': '2C',
'06': '00',
'07': '24',
'08': '29',
'09': '6E',
'10': '57',
'11': '52',
'12': '79',
'13': '0D',
'14': '00',
'15': '32',
'16': '37',
'17': '6B',
'18': '04',
'19': '3F',
'20': '27',
'21': '08',
'22': '00',
'23': '3A',
'24': '50',
'25': '1C',
'26': '00',
'27': '99',
'28': '00',
'29': '07',
'30': '66',
'31': 'A7',
'32': '60',
'33': '4B',
'34': '2B',
'35': '1B',
'36': '61',
'37': '25',
'38': '1E',
'39': 'D2',
'40': '23',
'41': '0E',
'42': '40',
'43': '7C',
'44': '97',
'45': '3C',
'46': '82',
'47': '4D',
'48': '11',
'49': '47',
'50': '02',
'51': '0F',
'52': '70',
'53': '71',
'54': '72',
'55': '0E',
'56': '1A',
'57': '5D',
'59': 'E2',
'60': 'A5',
'61': 'A6',
'62': '00',
'63': '65',
'64': 'DF',
'65': '2A',
'66': 'FE',
'67': '7B',
'68': '73',
'69': '16',
'70': '62',
'72': '00',
'73': '63',
'74': '81',
'76': '13',
'77': '77',
'78': '64',
'79': 'D1',
'80': 'F7',
'81': 'F8',
'86': '2E',
'87': '06',
'90': '59',
'91': '86',
'92': '87',
'93': '00',
'94': '67',
'95': '93',
'96': '95',
'97': '68',
'98': 'A8',
'99': 'C0'}
ecudump = {}
resizeFont = False
favouriteScreen = ecu_own_screen('FAV')
class MyLabelBlue(ButtonBehavior, Label):
def on_size(self, *args):
self.canvas.before.clear()
with self.canvas.before:
Color(0, 1, 0, 0.25)
Rectangle(pos=self.pos, size=self.size)
class MyLabelGreen(ButtonBehavior, Label):
def __init__(self, mfs = None, **kwargs):
super(MyLabelGreen, self).__init__(**kwargs)
self.text_size = self.size
self.bind(size=self.on_size)
self.bind(text=self.on_text_changed)
self.clicked = False
self.param_name = kwargs["param_name"]
def on_size(self, widget, size):
fs = mod_globals.fontSize
self.text_size = (size[0], None)
self.texture_update()
if self.size_hint_y is None and self.size_hint_x is not None:
self.height = fs * fmn
elif self.size_hint_x is None and self.size_hint_y is not None:
self.width = self.texture_size[0]
self.toNormal()
for dr in favouriteScreen.datarefs:
if dr.name == self.param_name:
self.toAdd()
self.clicked = True
break
def on_text_changed(self, widget, text):
self.on_size(self, self.size)
def toAdd(self, *args):
self.canvas.before.clear()
with self.canvas.before:
Color(0.38, 0.55, 0.95, 0.5)
Rectangle(pos=self.pos, size=self.size)
def toNormal(self, *args):
self.canvas.before.clear()
with self.canvas.before:
Color(0, 0, 1, 0.25)
Rectangle(pos=self.pos, size=self.size)
def on_press(self):
if self.clicked:
self.toNormal()
self.clicked = False
else:
self.toAdd()
self.clicked = True
class showDatarefGui(App):
def __init__(self, ecu, datarefs, path):
self.ecu = ecu
self.blue_part_size = 0.75
self.datarefs = datarefs
self.labels = {}
self.needupdate = False
self.clock_event = None
self.running = True
self.path = path
self.paramsLabels = OrderedDict()
self.csvf = 0
self.csvline = ''
super(showDatarefGui, self).__init__()
Window.bind(on_keyboard=self.key_handler)
def key_handler(self, window, keycode1, keycode2, text, modifiers):
global resizeFont
if resizeFont:
return True
if keycode1 == 45 and mod_globals.fontSize > 10:
mod_globals.fontSize = mod_globals.fontSize - 1
resizeFont = True
if self.clock_event is not None:
self.clock_event.cancel()
self.needupdate = False
self.running = False
self.stop()
return True
if keycode1 == 61 and mod_globals.fontSize < 40:
mod_globals.fontSize = mod_globals.fontSize + 1
resizeFont = True
if self.clock_event is not None:
self.clock_event.cancel()
self.needupdate = False
self.running = False
self.stop()
return True
return False
def on_pause(self):
self.running = False
def on_resume(self):
self.running = True
# self.ecu.elm.send_cmd(self.ecu.ecudata['startDiagReq'])
def make_box_params(self, parameter_name, val):
fs = mod_globals.fontSize
glay = BoxLayout(orientation='horizontal', size_hint=(1, None), height=fs * 2.0)
label1 = MyLabelGreen(text=self.paramsLabels[parameter_name], halign='left', valign='top', size_hint=(self.blue_part_size, None), font_size=fs, on_press= lambda *args: self.ecu.addElem(self.paramsLabels[parameter_name].split(' ')[0]), param_name=parameter_name)
label2 = MyLabelBlue(text=val, halign='right', valign='top', size_hint=(1 - self.blue_part_size, 1), font_size=fs)
glay.add_widget(label1)
glay.add_widget(label2)
self.labels[parameter_name] = label2
return glay
def finish(self, instance):
if self.path[:3] == 'FAV':
self.ecu.saveFavList()
self.needupdate = False
self.running = False
if mod_globals.opt_csv and self.csvf!=0:
self.csvf.close()
self.stop()
def get_ecu_values(self):
if mod_globals.opt_csv and self.csvf!=0:
self.csvline = self.csvline + "\n"
self.csvline = self.csvline.replace(';','\t')
self.csvf.write(pyren_decode(self.csvline).encode('utf8') if mod_globals.opt_csv_human else self.csvline)
self.csvf.flush()
self.csvline = datetime.now().strftime("%H:%M:%S.%f")
dct = OrderedDict()
for dr in self.datarefs:
EventLoop.window._mainloop()
if dr.type == 'State':
if self.ecu.DataIds and "DTC" in self.path and dr in self.ecu.Defaults[mod_globals.ext_cur_DTC[:4]].memDatarefs:
name, codeMR, label, value, csvd = get_state(self.ecu.States[dr.name], self.ecu.Mnemonics, self.ecu.Services, self.ecu.elm, self.ecu.calc, True, self.ecu.DataIds)
else:
name, codeMR, label, value, csvd = get_state(self.ecu.States[dr.name], self.ecu.Mnemonics, self.ecu.Services, self.ecu.elm, self.ecu.calc, True)
key = '%s - %s' % (codeMR, label)
dct[name] = value
self.paramsLabels[name] = key
self.needupdate = True
if dr.type == 'Parameter':
if self.ecu.DataIds and "DTC" in self.path and dr in self.ecu.Defaults[mod_globals.ext_cur_DTC[:4]].memDatarefs:
name, codeMR, label, value, unit, csvd = get_parameter(self.ecu.Parameters[dr.name], self.ecu.Mnemonics, self.ecu.Services, self.ecu.elm, self.ecu.calc, True, self.ecu.DataIds)
else:
name, codeMR, label, value, unit, csvd = get_parameter(self.ecu.Parameters[dr.name], self.ecu.Mnemonics, self.ecu.Services, self.ecu.elm, self.ecu.calc, True)
key = '%s - %s' % (codeMR, label)
val = '%s %s' % (value, unit)
dct[name] = val
self.paramsLabels[name] = key
self.needupdate = True
if dr.type == 'Identification':
name, codeMR, label, value = get_identification(self.ecu.Identifications[dr.name], self.ecu.Mnemonics, self.ecu.Services, self.ecu.elm, self.ecu.calc, True)
key = '%s - %s' % (codeMR, label)
dct[name] = str(value).strip()
self.paramsLabels[name] = key
if dr.type=='Text' or dr.type=='DTCText':
dct[dr.name] = dr.type
if mod_globals.opt_csv and self.csvf!=0 and (dr.type=='State' or dr.type=='Parameter'):
self.csvline += ";" + (pyren_encode(csvd) if mod_globals.opt_csv_human else str(csvd))
return dct
def update_values(self, dt):
if not self.running:
return
self.ecu.elm.clear_cache()
params = self.get_ecu_values()
for param, val in params.iteritems():
if val != 'Text' and val != 'DTCText':
self.labels[param].text = val.strip()
self.ecu.elm.currentScreenDataIds = self.ecu.getDataIds(self.ecu.elm.rsp_cache.keys(), self.ecu.DataIds)
if mod_globals.opt_csv:
self.clock_event = Clock.schedule_once(self.update_values, 0.02)
else:
self.clock_event = Clock.schedule_once(self.update_values, 0.05)
def on_start(self):
from kivy.base import EventLoop
EventLoop.window.bind(on_keyboard=self.hook_keyboard)
def hook_keyboard(self, window, key, *largs):
if key == 27:
self.finish(self)
return True
def build(self):
if mod_globals.opt_perform:
self.ecu.elm.currentScreenDataIds = []
if mod_globals.opt_csv and mod_globals.ext_cur_DTC == '000000':
self.csvf, self.csvline = self.ecu.prepareCSV(self.datarefs, self.path)
layout = GridLayout(cols=1, spacing=(4, 4), size_hint=(1.0, None))
layout.bind(minimum_height=layout.setter('height'))
fs = mod_globals.fontSize
defaultFS = float(fs)/30.0
header = 'ECU : ' + self.ecu.ecudata['ecuname'] + ' ' + self.ecu.ecudata['doc']
layout.add_widget(Label(text=header, font_size=fs, height=fs * bmn, size_hint=(1, None)))
params = self.get_ecu_values()
max_str = ''
for param in self.paramsLabels.values():
len_str = len(param)
if len_str > len(max_str):
max_str = param
tmp_label = Label(text=max_str, font_size=fs)
tmp_label._label.render()
for paramName, val in params.iteritems():
if val == 'Text':
layout.add_widget(Label(text=paramName, font_size=fs, height=fs * fmn, size_hint=(1, None)))
elif val == 'DTCText':
lines = len(paramName.split('\n'))
simb = len(paramName)
operation = simb / int(60/defaultFS)
if lines <= operation:
lines = operation
lines += 1
elif lines - 1 == operation or lines - 2 == operation:
lines += 1
if fs >= 40:
lines += 1
prelabel = TextInput(text=pyren_encode(paramName), font_size=fs*0.9, size_hint=(1, None), multiline=True, height=fs * fmn * lines, readonly=True, foreground_color=[1,1,1,1], background_color=[0,0,1,1])
layout.add_widget(prelabel)
else:
layout.add_widget(self.make_box_params(paramName, val))
quitbutton = Button(text='<BACK>', height=fs * bmn, size_hint=(1, None), on_press=self.finish)
layout.add_widget(quitbutton)
root = ScrollView(size_hint=(None, None), size=Window.size, do_scroll_x=False, pos_hint={'center_x': 0.5,
'center_y': 0.5})
root.add_widget(layout)
if self.needupdate:
self.clock_event = Clock.schedule_once(self.update_values, 0.5)
return root
class ECU():
getDTCmnemo = ''
resetDTCcommand = ''
screens = []
Defaults = {}
Parameters = {}
States = {}
Identifications = {}
Commands = {}
Services = {}
Mnemonics = {}
DataIds = {}
ext_de = []
ecudata = {}
minimumrefreshrate = 0.1
def __init__(self, cecu, tran):
self.elm = 0
self.ecudata = cecu
self.getDTCmnemo = ''
self.resetDTCcommand = ''
self.screens = []
self.Defaults = {}
self.Parameters = {}
self.States = {}
self.Identifications = {}
self.Commands = {}
self.Services = {}
self.Mnemonics = {}
self.DataIds = {}
modelid = self.ecudata['ModelId'].replace('XML', 'xml')
mdom = mod_zip.get_xml_file(modelid)
mdoc = mdom.documentElement
lbltxt = Label(Text='Loading languages')
popup_init = Popup(title='Initializing', content=lbltxt, size=(400, 400), size_hint=(None, None))
base.runTouchApp(slave=True)
popup_init.open()
lbltxt.text = 'Loading screens'
EventLoop.idle()
self.screens = []
sc_class = ecu_screens(self.screens, mdoc, tran)
lbltxt.text = 'Loading optimyzer'
EventLoop.idle()
self.defaults = []
optimizerfile = self.ecudata['OptimizerId'][:-4] + '.p'
dict = mod_zip.get_ecu_p(optimizerfile)
lbltxt.text = 'Loading defaults'
EventLoop.idle()
df_class = ecu_defaults(self.Defaults, mdoc, dict, tran)
lbltxt.text = 'Loading parameters'
EventLoop.idle()
pr_class = ecu_parameters(self.Parameters, mdoc, dict, tran)
lbltxt.text = 'Loading states'
EventLoop.idle()
st_class = ecu_states(self.States, mdoc, dict, tran)
lbltxt.text = 'Loading identifications'
EventLoop.idle()
id_class = ecu_identifications(self.Identifications, mdoc, dict, tran)
lbltxt.text = 'Loading commands'
EventLoop.idle()
cm_class = ecu_commands(self.Commands, mdoc, dict, tran)
lbltxt.text = 'Loading services'
EventLoop.idle()
sv_class = ecu_services(self.Services, mdoc, dict, tran)
lbltxt.text = 'Loading mnemonics'
EventLoop.idle()
mm_class = ecu_mnemonics(self.Mnemonics, mdoc, dict, tran)
lbltxt.text = 'Loading DTC commands'
EventLoop.idle()
self.getDTCmnemo, self.resetDTCcommand = df_class.getDTCCommands(mdoc, dict, cecu['stdType'])
if 'DataIds' in dict.keys():
lbltxt.text = 'Loading Data ids'
EventLoop.idle()
xmlstr = dict['DataIds']
ddom = xml.dom.minidom.parseString(xmlstr.encode('utf-8'))
ddoc = ddom.documentElement
di_class = ecu_dataids(self.DataIds, ddoc, dict, tran)
EventLoop.window.remove_widget(popup_init)
popup_init.dismiss()
base.stopTouchApp()
EventLoop.window.canvas.clear()
def initELM(self, elm):
global ecudump
self.calc = Calc()
self.elm = elm
if self.ecudata['pin'].lower() == 'can':
self.elm.init_can()
self.elm.set_can_addr(self.ecudata['dst'], self.ecudata)
else:
self.elm.init_iso()
self.elm.set_iso_addr(self.ecudata['dst'], self.ecudata)
self.elm.start_session(self.ecudata['startDiagReq'])
if self.ecudata['pin'].lower()=='can' and self.DataIds and mod_globals.opt_csv:
mod_globals.opt_perform = True
self.elm.checkModulePerformaceLevel(self.DataIds)
ecudump = {}
def saveDump(self):
dumpname = mod_globals.dumps_dir + str(int(time.time())) + '_' + self.ecudata['ecuname'] + '.txt'
df = open(dumpname, 'wt')
self.elm.clear_cache()
for service in self.Services.values():
if service.startReq[:2] in AllowedList:
pos = chr(ord(service.startReq[0]) + 4) + service.startReq[1]
rsp = self.elm.request(service.startReq, pos, False)
if ':' in rsp:
continue
df.write('%s:%s\n' % (service.startReq, rsp))
df.close()
def loadDump(self, dumpname = ''):
global ecudump
ecudump = {}
if len(dumpname) == 0:
flist = []
for root, dirs, files in os.walk(mod_globals.dumps_dir):
for f in files:
if self.ecudata['ecuname'] + '.txt' in f:
flist.append(f)
if len(flist) == 0:
return
flist.sort()
dumpname = os.path.join(mod_globals.dumps_dir, flist[-1])
df = open(dumpname, 'rt')
lines = df.readlines()
df.close()
for l in lines:
l = l.strip().replace('\n', '')
if ':' in l:
req, rsp = l.split(':')
ecudump[req] = rsp
self.elm.setDump(ecudump)
def get_st(self, name, no_formatting = False):
if name not in self.States.keys():
for i in self.States.keys():
if name == self.States[i].codeMR:
name = i
break
if name not in self.States.keys():
return ('none', 'unknown state')
self.elm.clear_cache()
if no_formatting:
idName, datastr, help, csvd, icsvd = get_state(self.States[name], self.Mnemonics, self.Services, self.elm, self.calc, no_formatting)
return (datastr, help, csvd)
else:
datastr, help, csvd = get_state(self.States[name], self.Mnemonics, self.Services, self.elm, self.calc)
return (csvd, datastr)
def get_ref_st(self, name):
if name not in self.States.keys():
for i in self.States.keys():
if name == self.States[i].codeMR:
name = i
break
if name not in self.States.keys():
return None
return self.States[name]
def get_pr(self, name, no_formatting = False):
if name not in self.Parameters.keys():
for i in self.Parameters.keys():
if name == self.Parameters[i].codeMR:
name = i
break
if name not in self.Parameters.keys():
return ('none', 'unknown parameter')
self.elm.clear_cache()
if no_formatting:
idName, datastr, help, csvd, unit, icsvd = get_parameter(self.Parameters[name], self.Mnemonics, self.Services, self.elm, self.calc, no_formatting)
return (datastr, help, csvd, unit)
else:
datastr, help, csvd = get_parameter(self.Parameters[name], self.Mnemonics, self.Services, self.elm, self.calc)
return (csvd, datastr)
def get_ref_pr(self, name):
if name not in self.Parameters.keys():
for i in self.Parameters.keys():
if name == self.Parameters[i].codeMR:
name = i
break
if name not in self.Parameters.keys():
return None
return self.Parameters[name]
def get_id(self, name, no_formatting = False):
if name not in self.Identifications.keys():
for i in self.Identifications.keys():
if name == self.Identifications[i].codeMR:
name = i
break
if name not in self.Identifications.keys():
return ('none', 'unknown identification')
self.elm.clear_cache()
if no_formatting == 5:
return get_identification( self.Identifications[name], self.Mnemonics, self.Services, self.elm, self.calc, no_formatting)
elif no_formatting:
idName, datastr, help, csvd = get_identification(self.Identifications[name], self.Mnemonics, self.Services, self.elm, self.calc, no_formatting)
return (datastr, help, csvd)
else:
datastr, help, csvd = get_identification(self.Identifications[name], self.Mnemonics, self.Services, self.elm, self.calc)
return (csvd, datastr)
def get_ref_id(self, name):
if name not in self.Identifications.keys():
for i in self.Identifications.keys():
if name == self.Identifications[i].codeMR:
name = i
break
if name not in self.Identifications.keys():
return None
return self.Identifications[name]
def get_val(self, name):
r1, r2 = self.get_st(name)
if r1 != 'none':
return (r1, r2)
r1, r2 = self.get_pr(name)
if r1 != 'none':
return (r1, r2)
r1, r2 = self.get_id(name)
if r1 != 'none':
return (r1, r2)
return ('none', 'unknown name')
def run_cmd(self, name, param = '', partype = 'HEX'):
if name not in self.Commands.keys():
for i in self.Commands.keys():
if name == self.Commands[i].codeMR:
name = i
break
if name not in self.Commands.keys():
return 'none'
self.elm.clear_cache()
resp = runCommand(self.Commands[name], self, self.elm, param, partype)
return resp
def get_ref_cmd(self, name):
if name not in self.Commands.keys():
for i in self.Commands.keys():
if name == self.Commands[i].codeMR:
name = i
break
if name not in self.Commands.keys():
return None
return self.Commands[name]
def show_commands(self, datarefs, path):
while True:
clearScreen()
header = 'ECU : ' + self.ecudata['ecuname'] + ' ' + self.ecudata['doc'] + '\n'
header = header + 'Screen : ' + path
menu = []
cmds = []
for dr in datarefs:
datastr = dr.name
if dr.type == 'State':
datastr = self.States[dr.name].name + 'States not supported on one screen with commands'
if dr.type == 'Parameter':
datastr = self.Parameters[dr.name].name + 'Parameters not supported on one screen with commands'
if dr.type == 'Identification':
datastr = self.Identifications[dr.name].name + 'Identifications not supported on one screen with commands'
if dr.type == 'Command':
datastr = self.Commands[dr.name].codeMR + ' ' + self.Commands[dr.name].label
cmds.append(dr.name)
menu.append(datastr)
menu.append('<Up>')
choice = ChoiceLong(menu, 'Choose :', header)
if choice[0] == '<Up>':
return
header = header + ' -> ' + cmds[int(choice[1]) - 1] + ' [Command] '
executeCommand(self.Commands[cmds[int(choice[1]) - 1]], self, self.elm, header)
def prepareCSV(self, datarefs, path):
csvf = 0
csvline = "sep=\\t\n"
csvline += u"Time"
nparams = 0
for dr in datarefs:
if dr.type=='State':
csvline += ";" + self.States[dr.name].codeMR + (":" + self.States[dr.name].label if mod_globals.opt_csv_human else "")
nparams += 1
if dr.type=='Parameter':
csvline += (";" + self.Parameters[dr.name].codeMR + (":" +self.Parameters[dr.name].label if mod_globals.opt_csv_human else "") +
" [" + self.Parameters[dr.name].unit + "]")
nparams += 1
csvline = pyren_encode(csvline)
if nparams:
csv_filename = datetime.now().strftime("%y_%m_%d_%H_%M_%S")
csv_filename = csv_filename+'_'+self.ecudata['ecuname']+'_'+path
csv_filename += ".csv"
csv_filename = csv_filename.replace('/','_')
csv_filename = csv_filename.replace(' : ','_')
csv_filename = csv_filename.replace(' -> ','_')
csv_filename = csv_filename.replace(' ','_')
csvf = open(mod_globals.csv_dir + pyren_encode(csv_filename), "wt")
return csvf, csvline
def show_datarefs(self, datarefs, path):
global resizeFont
csvf = 0
mask = False
masks = []
datarefsToRemove = []
for st in self.States:
if st.startswith('MAS'):
mask = True
get_state( self.States[st], self.Mnemonics, self.Services, self.elm, self.calc )
if int(self.States[st].value):
masks.append(self.States[st].name)
if mask:
for dr in datarefs:
if dr.type=='State':
if self.States[dr.name].mask and self.States[dr.name].mask not in masks:
datarefsToRemove.append(dr)
if dr.type=='Parameter':
if self.Parameters[dr.name].mask and self.Parameters[dr.name].mask not in masks:
datarefsToRemove.append(dr)
if dr.type=='Identification':
if self.Identifications[dr.name].mask and self.Identifications[dr.name].mask not in masks:
datarefsToRemove.append(dr)
if dr.type=='Command':
if self.Commands[dr.name].mask and self.Commands[dr.name].mask not in masks:
datarefsToRemove.append(dr)
for dr in datarefsToRemove:
datarefs.remove(dr)
for dr in datarefs:
if dr.type == 'Command':
self.show_commands(datarefs, path)
return
while 1:
gui = showDatarefGui(self, datarefs, path)
gui.run()
if not resizeFont:
return
resizeFont = False
kb = KBHit()
tb = time.time()
if len(datarefs) == 0 and 'DE' not in path:
return
page = 0
while True:
strlst = []
if mod_globals.opt_csv and csvf != 0:
csvline = csvline + '\n'
# csvline = csvline.replace('.', ',')
csvline = csvline.replace(';', '\t')
csvf.write(pyren_decode(csvline).encode('utf8') if mod_globals.opt_csv_human else csvline)
csvf.flush()
csvline = datetime.now().strftime('%H:%M:%S.%f')
self.elm.clear_cache()
if mod_globals.opt_csv and mod_globals.opt_csv_only:
clearScreen()
for dr in datarefs:
datastr = dr.name
help = dr.type
if dr.type == 'State':
datastr, help, csvd = get_state(self.States[dr.name], self.Mnemonics, self.Services, self.elm, self.calc)
if dr.type == 'Parameter':
datastr, help, csvd = get_parameter(self.Parameters[dr.name], self.Mnemonics, self.Services, self.elm, self.calc)
if dr.type == 'Identification':
datastr, help, csvd = get_identification(self.Identifications[dr.name], self.Mnemonics, self.Services, self.elm, self.calc)
if dr.type == 'Command':
datastr = dr.name + ' [Command] ' + self.Commands[dr.name].label
if mod_globals.opt_csv and csvf != 0 and (dr.type == 'State' or dr.type == 'Parameter'):
csvline += ';' + (pyren_encode(csvd) if mod_globals.opt_csv_human else str(csvd))
if not (mod_globals.opt_csv and mod_globals.opt_csv_only):
strlst.append(datastr)
if mod_globals.opt_verbose and len(help) > 0:
tmp_str = ''
for s in help:
s = s.replace('\r', '\n')
s = s.replace('>', '>')
s = s.replace('≤', '<')
tmp_str = tmp_str + s + '\n\n'
W = 50
for line in tmp_str.split('\n'):
i = 0
while i * W < len(line):
strlst.append('\t' + line[i * W:(i + 1) * W])
i = i + 1
strlst.append('')
if not (mod_globals.opt_csv and mod_globals.opt_csv_only):
clearScreen()
header = 'ECU : ' + self.ecudata['ecuname'] + ' ' + self.ecudata['doc'] + '\n'
header = header + 'Screen : ' + path
H = 25
pages = len(strlst) / H
if mod_globals.opt_demo:
self.minimumrefreshrate = 1
tc = time.time()
if tc - tb < self.minimumrefreshrate:
time.sleep(tb + self.minimumrefreshrate - tc)
tb = tc
if kb.kbhit():
c = kb.getch()
if len(c) != 1:
continue
n = ord(c) - ord('0')
if not mod_globals.opt_csv_only and n > 0 and n <= pages + 1:
page = n - 1
continue
if mod_globals.opt_csv and c in mod_globals.opt_usrkey:
csvline += ';' + c
continue
kb.set_normal_term()
if mod_globals.opt_csv and csvf != 0:
csvf.close()
return
def show_subfunction(self, subfunction, path):
while 1:
clearScreen()
if len(subfunction.datarefs) != 0 and len(subfunction.datarefs) > 0:
self.show_datarefs(subfunction.datarefs, path + ' -> ' + subfunction.text)
return
return
def show_function(self, function, path):
while 1:
clearScreen()
menu = []
if len(function.subfunctions) != 0:
for sfu in function.subfunctions:
menu.append(sfu.text)
menu.append('<Up>')
choice = Choice(menu, 'Choose :')
if choice[0] == '<Up>':
return
self.show_subfunction(function.subfunctions[int(choice[1]) - 1], path + ' -> ' + function.text)
if len(function.datarefs) != 0:
self.show_datarefs(function.datarefs, path + ' -> ' + function.text)
return
def show_screen(self, screen):
while 1:
clearScreen()
menu = []
if len(screen.functions) != 0:
for fu in screen.functions:
menu.append(fu.text)
menu.append('<Up>')
choice = Choice(menu, 'Choose :')
if choice[0] == '<Up>':
return
self.show_function(screen.functions[int(choice[1]) - 1], screen.name)
if len(screen.datarefs) != 0:
self.show_datarefs(screen.datarefs, screen.name)
return
def show_defaults_std_a(self):
while 1:
path = 'DE (STD_A)'
clearScreen()
header = 'ECU : ' + self.ecudata['ecuname'] + ' ' + self.ecudata['doc'] + '\n'
header = header + 'Screen : ' + path
menu = []
defstr = {}
hlpstr = {}
self.elm.clear_cache()
dtcs, defstr, hlpstr = get_default_std_a(self.Defaults, self.Mnemonics, self.Services, self.elm, self.calc, self.getDTCmnemo)
listkeys = defstr.keys()
for d in listkeys:
menu.append(defstr[d])
menu.append('<Up>')
menu.append('<Clear>')
choice = Choice(menu, 'Choose one for detailed view or <Clear>:')
if choice[0] == '<Up>':
mod_globals.ext_cur_DTC = '000000'
return
if choice[0] == '<Clear>':
executeCommand(self.Commands[self.resetDTCcommand], self, self.elm, header)
return
index = int(choice[1]) - 1
dtchex = listkeys[index] if len(listkeys) > index else listkeys[0]
mod_globals.ext_cur_DTC = dtchex
path = path + ' -> ' + defstr[dtchex] + '\n\n' + hlpstr[dtchex] + '\n'
tmp_helpString = defstr[dtchex] + '\n\n' + hlpstr[dtchex]
cur_dtrf = []
mem_dtrf = []
helpString = [ecu_screen_dataref(0, tmp_helpString, 'DTCText')]
if self.Defaults[dtchex[:4]].datarefs:
cur_dtrf = [ecu_screen_dataref(0, "\n" + mod_globals.language_dict['300'] + "\n", 'Text')] + self.Defaults[dtchex[:4]].datarefs
if self.Defaults[dtchex[:4]].memDatarefs:
mem_dtrf_txt = mod_globals.language_dict['299'] + " DTC" + mod_globals.ext_cur_DTC + "\n"
mem_dtrf = [ecu_screen_dataref(0, mem_dtrf_txt, 'Text')] + self.Defaults[dtchex[:4]].memDatarefs
tmp_dtrf = helpString + mem_dtrf + cur_dtrf
self.show_datarefs(tmp_dtrf, path)
def show_defaults_std_b(self):
while 1:
path = 'DE (STD_B)'
clearScreen()
header = 'ECU : ' + self.ecudata['ecuname'] + ' ' + self.ecudata['doc'] + '\n'
header = header + 'Screen : ' + path
menu = []
defstr = {}
hlpstr = {}
self.elm.clear_cache()
dtcs, defstr, hlpstr = get_default_std_b(self.Defaults, self.Mnemonics, self.Services, self.elm, self.calc, self.getDTCmnemo)
listkeys = defstr.keys()
for d in listkeys:
menu.append(defstr[d])
menu.append('<Up>')
menu.append('<Clear>')
choice = Choice(menu, 'Choose one for detailed view or <Clear>:')
if choice[0] == '<Up>':
mod_globals.ext_cur_DTC = '000000'
return
if choice[0] == '<Clear>':
executeCommand(self.Commands[self.resetDTCcommand], self, self.elm, header)
return
index = int(choice[1]) - 1
dtchex = listkeys[index] if len(listkeys) > index else listkeys[0]
mod_globals.ext_cur_DTC = dtchex
path = path + ' -> ' + defstr[dtchex] + '\n\n' + hlpstr[dtchex] + '\n'
tmp_helpString = defstr[dtchex] + '\n\n' + hlpstr[dtchex]
cur_dtrf = []
mem_dtrf = []
ext_info_dtrf = []
helpString = [ecu_screen_dataref(0, tmp_helpString, 'DTCText')]
if self.Defaults[dtchex[:4]].datarefs:
cur_dtrf = [ecu_screen_dataref(0, "\n" + mod_globals.language_dict['300'] + "\n", 'Text')] + self.Defaults[dtchex[:4]].datarefs
if self.Defaults[dtchex[:4]].memDatarefs:
mem_dtrf_txt = mod_globals.language_dict['299'] + " DTC" + mod_globals.ext_cur_DTC + "\n"
mem_dtrf = [ecu_screen_dataref(0, mem_dtrf_txt, 'Text')] + self.Defaults[dtchex[:4]].memDatarefs
if self.ext_de:
ext_info_dtrf = [ecu_screen_dataref(0, "\n" + mod_globals.language_dict['1691'] + "\n", 'Text')] + self.ext_de
tmp_dtrf = helpString + mem_dtrf + cur_dtrf + ext_info_dtrf
self.show_datarefs(tmp_dtrf, path)
def show_defaults_failflag(self):
while 1:
path = 'DE (FAILFLAG)'
clearScreen()
header = 'ECU : ' + self.ecudata['ecuname'] + ' ' + self.ecudata['doc'] + '\n'
header = header + 'Screen : ' + path
menu = []
defstr = {}
hlpstr = {}
self.elm.clear_cache()
dtcs, defstr, hlpstr = get_default_failflag(self.Defaults, self.Mnemonics, self.Services, self.elm, self.calc)
for d in sorted(defstr.keys()):
menu.append(defstr[d])
menu.append('<Up>')
menu.append('<Clear>')
choice = Choice(menu, 'Choose one for detailed view or <Clear>:')
if choice[0] == '<Up>':
return
if choice[0] == '<Clear>':
executeCommand(self.Commands[self.resetDTCcommand], self, self.elm, header)
return
dtchex = dtcs[int(choice[1]) - 1]
path = path + ' -> ' + defstr[dtchex] + '\n\n' + hlpstr[dtchex] + '\n'
tmp_helpString = defstr[dtchex] + '\n\n' + hlpstr[dtchex]
helpString = [ecu_screen_dataref(0, tmp_helpString, 'DTCText')]
self.show_datarefs(helpString + self.Defaults[dtchex].datarefs, path)
def show_screens(self):
self.screens.append(favouriteScreen)
while 1:
clearScreen()
header = 'ECU : ' + self.ecudata['ecuname'] + ' ' + self.ecudata['doc'] + '\n'
menu = []
for l in self.screens:
if l.name == 'DE':
l.name = 'DE : Device errors'
if l.name == 'ID':
l.name = 'ID : Identifications'
if l.name == 'SY':
l.name = 'SY : System state'
if l.name == 'LC':
l.name = 'LC : System configuration'
if l.name == 'SP':
l.name = 'SP : System parameters'
if l.name == 'AC':
l.name = 'AC : Executing tests'
if l.name == 'CF':
l.name = 'CF : Changing configuration'
if l.name == 'VP':
l.name = 'VP : VIN programming'
if l.name == 'RZ':
l.name = 'RZ : Resets'
if l.name == 'SC':
l.name = 'SC : Configuration scenarios'
if l.name == 'SCS':
l.name = 'SCS : Security configuration scenarios'
if l.name == 'EZ':
l.name = 'EZ : EZSTEP'
if l.name == 'FAV':
l.name = 'FAV : Favourite Parameteres'
if l.name == 'ED':