forked from barracuda-fsh/pyobd
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpyobd.py
More file actions
2345 lines (1981 loc) · 108 KB
/
pyobd.py
File metadata and controls
2345 lines (1981 loc) · 108 KB
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
#!/usr/bin/env python
############################################################################
#
# wxgui.py
#
# Copyright 2004 Donour Sizemore (donour@uchicago.edu)
# Copyright 2009 Secons Ltd. (www.obdtester.com)
# Copyright 2021 Jure Poljsak (https://github.com/barracuda-fsh/pyobd)
#
# This file is part of pyOBD.
#
# pyOBD is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# pyOBD is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pyOBD; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################
#import pint
#from mem_top import mem_top
#import logging
import numpy as np
#import multiprocessing
#from multiprocessing import Queue, Process
# import wxversion
# wxversion.select("2.6")
#import matplotlib
from wx.lib import plot as wxplot
#from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
#from matplotlib.figure import Figure
#import matplotlib.pyplot as plt
#matplotlib.use('wxAgg')
#from matplotlib.animation import FuncAnimation
#from matplotlib import style
#import numpy.oldnumeric as _Numeric
#from wxplot import PlotCanvas, PlotGraphics, PolyLine, PolyMarker, PolySpline
import gc
#from pympler.tracker import SummaryTracker
#tracker = SummaryTracker()
import traceback
import wx
#import pdb
import obd_io # OBD2 funcs
import os # os.environ
#import decimal
#import glob
import datetime
import threading
import sys
import serial
#import platform
import time
import configparser # safe application configuration
import webbrowser # open browser from python
#from multiprocessing import Process
#from multiprocessing import Queue
from obd2_codes import pcodes
#from obd2_codes import ptest
from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin
import obd
#from obd import OBDStatus
from obd.utils import OBDStatus
ID_ABOUT = 101
ID_EXIT = 110
ID_CONFIG = 500
ID_CLEAR = 501
ID_GETC = 502
ID_RESET = 503
ID_LOOK = 504
ALL_ON = 505
ALL_OFF = 506
ID_DISCONNECT = 507
ID_HELP_ABOUT = 508
ID_HELP_VISIT = 509
ID_HELP_ORDER = 510
# Define notification event for sensor result window
EVT_RESULT_ID = 1000
EVT_GRAPH_VALUE_ID = 1036
EVT_GRAPHS_VALUE_ID = 1048
EVT_GRAPH_ID = 1035
EVT_GRAPHS_ID = 1049
EVT_COMBOBOX = 1036
EVT_CLOSE_ID = 1037
EVT_BUILD_COMBOBOXGRAPH_ID = 1038
EVT_BUILD_COMBOBOXGRAPHS_ID = 1045
EVT_DESTROY_COMBOBOX_ID = 1039
EVT_COMBOBOXGRAPH_GETSELECTION_ID = 1040
EVT_COMBOBOXGRAPHS_GETSELECTION_ID = 1046
EVT_COMBOBOXGRAPH_SETSELECTION_ID = 1044
EVT_COMBOBOXGRAPHS_SETSELECTION_ID = 1047
EVT_INSERT_SENSOR_ROW_ID = 1041
EVT_INSERT_FREEZEFRAME_ROW_ID = 1042
EVT_FREEZEFRAME_RESULT_ID = 1043
lock = threading.Lock()
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
TESTS = ["MISFIRE_MONITORING",
"FUEL_SYSTEM_MONITORING",
"COMPONENT_MONITORING",
"CATALYST_MONITORING",
"HEATED_CATALYST_MONITORING",
"EVAPORATIVE_SYSTEM_MONITORING",
"SECONDARY_AIR_SYSTEM_MONITORING",
"OXYGEN_SENSOR_MONITORING",
"OXYGEN_SENSOR_HEATER_MONITORING",
"EGR_VVT_SYSTEM_MONITORING",
"NMHC_CATALYST_MONITORING",
"NOX_SCR_AFTERTREATMENT_MONITORING",
"BOOST_PRESSURE_MONITORING",
"EXHAUST_GAS_SENSOR_MONITORING",
"PM_FILTER_MONITORING"]
def EVT_RESULT(win, func, id):
"""Define Result Event."""
win.Connect(-1, -1, id, func)
"""
class MyPanel(wx.Panel):
def __init__(self, parent):
super(MyPanel, self).__init__(parent)
self.label = wx.StaticText(self, label="What Programming Language You Like?", pos=(50, 30))
languages = ['Java', 'C++', 'C#', 'Python', 'Erlang', 'PHP', 'Ruby']
self.combobox = wx.ComboBox(self, choices=languages, pos=(50, 50))
self.label2 = wx.StaticText(self, label="", pos=(50, 80))
self.Bind(wx.EVT_COMBOBOX, self.OnCombo)
def OnCombo(self, event):
self.label2.SetLabel("You Like " + self.combobox.GetValue())
"""
# event pro akutalizaci Trace tabu
class ResultEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_RESULT_ID)
self.data = data
class FreezeframeResultEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_FREEZEFRAME_RESULT_ID)
self.data = data
class InsertSensorRowEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_INSERT_SENSOR_ROW_ID)
self.data = data
class InsertFreezeframeRowEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_INSERT_FREEZEFRAME_ROW_ID)
self.data = data
class BuildComboBoxGraphEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_BUILD_COMBOBOXGRAPH_ID)
self.data = data
class BuildComboBoxGraphsEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_BUILD_COMBOBOXGRAPHS_ID)
self.data = data
class DestroyComboBoxEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_DESTROY_COMBOBOX_ID)
self.data = data
class GetSelectionComboBoxGraphEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_COMBOBOXGRAPH_GETSELECTION_ID)
self.data = data
class GetSelectionComboBoxGraphsEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_COMBOBOXGRAPHS_GETSELECTION_ID)
self.data = data
class SetSelectionComboBoxGraphEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_COMBOBOXGRAPH_SETSELECTION_ID)
self.data = data
class SetSelectionComboBoxGraphsEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_COMBOBOXGRAPHS_SETSELECTION_ID)
self.data = data
class GraphValueEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_GRAPH_VALUE_ID)
self.data = data
class GraphsValueEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_GRAPHS_VALUE_ID)
self.data = data
class GraphEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_GRAPH_ID)
self.data = data
class GraphsEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_GRAPHS_ID)
self.data = data
# event pro aktualizaci DTC tabu
EVT_DTC_ID = 1001
class DTCEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_DTC_ID)
self.data = data
# event pro aktualizaci status tabu
EVT_STATUS_ID = 1002
class StatusEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_STATUS_ID)
self.data = data
class CloseEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_CLOSE_ID)
self.data = data
# event pro aktualizaci tests tabu
EVT_TESTS_ID = 1003
class TestEvent(wx.PyEvent):
"""Simple event to carry arbitrary result data."""
def __init__(self, data):
"""Init Result Event."""
wx.PyEvent.__init__(self)
self.SetEventType(EVT_TESTS_ID)
self.data = data
# defines notification event for debug tracewindow
from debugEvent import *
class MyApp(wx.App):
# A listctrl which auto-resizes the column boxes to fill
class MyListCtrl(wx.ListCtrl, ListCtrlAutoWidthMixin):
def __init__(self, parent, id, pos=wx.DefaultPosition,
size=wx.DefaultSize, style=0):
wx.ListCtrl.__init__(self, parent, id, pos, size, style)
ListCtrlAutoWidthMixin.__init__(self)
class sensorProducer(threading.Thread):
def __init__(self, _notify_window, portName, SERTIMEOUT, RECONNATTEMPTS, BAUDRATE, FAST, _nb):
#from queue import Queue
self.portName = portName
self.RECONNATTEMPTS = RECONNATTEMPTS
self.SERTIMEOUT = SERTIMEOUT
self.port = None
self._notify_window = _notify_window
self.baudrate = BAUDRATE
self.FAST = FAST
self._nb = _nb
threading.Thread.__init__(self)
self.state = "started"
def initCommunication(self):
try:
self.connection.close()
except:
pass
wx.PostEvent(self._notify_window, StatusEvent([0, 1, "Connecting...."]))
self.connection = obd_io.OBDConnection(self.portName, self._notify_window, self.baudrate, self.SERTIMEOUT,self.RECONNATTEMPTS, self.FAST)
if self.connection.connection.status() != 'Car Connected': # Cant open serial port
print(self.connection.connection.status())
#wx.PostEvent(self._notify_window, StatusEvent([666])) # signal apl, that communication was disconnected
#wx.PostEvent(self._notify_window, StatusEvent([0, 1, "Error cant connect..."]))
#self.state="finished"
self.stop()
return None
elif self.connection.connection.status() == 'Car Connected':
wx.PostEvent(self._notify_window, DebugEvent([1, "Communication initialized..."]))
wx.PostEvent(self._notify_window, StatusEvent([0, 1, "Car connected!"]))
r = self.connection.connection.query(obd.commands.ELM_VERSION)
self.ELMver = str(r.value)
r = self.connection.connection.query(obd.commands.ELM_VOLTAGE)
self.ELMvoltage = str(r.value)
wx.PostEvent(self._notify_window, StatusEvent([5, 1, str(self.ELMvoltage)]))
self.protocol = self.connection.connection.protocol_name()
wx.PostEvent(self._notify_window, StatusEvent([2, 1, str(self.ELMver)]))
wx.PostEvent(self._notify_window, StatusEvent([1, 1, str(self.protocol)]))
wx.PostEvent(self._notify_window, StatusEvent([3, 1, str(self.connection.connection.port_name())]))
try:
r = self.connection.connection.query(obd.commands.VIN)
if r.value != None:
self.VIN = r.value.decode()
wx.PostEvent(self._notify_window, StatusEvent([4, 1, str(self.VIN)]))
except:
pass
#traceback.print_exc()
return "OK"
def run(self):
if self.initCommunication() != "OK":
self._notify_window.ThreadControl = 666
self.state = "finished"
return None
self.baudrate = self.connection.connection.interface.baudrate()
self.portName = self.connection.connection.port_name()
prevstate = -1
curstate = -1
first_time_sensors = True
first_time_freezeframe = True
first_time_graph = True
first_time_graphs = True
self.first_time_graph_plot = True
self.first_time_graphs_plot = True
self.graph_counter = 0
self.graph_counter1 = 0
self.graph_dirty1 = False
self.graph_dirty2 = False
self.graph_dirty3 = False
self.graph_dirty4 = False
#sensor_list = []
misfire_cylinder_supported = True
first_time=True
#pimp_counter = 0
#time_prev = datetime.datetime.now()
#time_now = datetime.datetime.now()
def init_all_graphs():
self.graph_x_vals = np.array([])
self.graph_y_vals = np.array([])
self.graph_counter = 0
self.graph_x_vals1 = np.array([])
self.graph_y_vals1 = np.array([])
self.graph_x_vals2 = np.array([])
self.graph_y_vals2 = np.array([])
self.graph_x_vals3 = np.array([])
self.graph_y_vals3 = np.array([])
self.graph_x_vals4 = np.array([])
self.graph_y_vals4 = np.array([])
self.graph_counter1 = 0
self.graph_counter2 = 0
self.graph_counter3 = 0
self.graph_counter4 = 0
init_all_graphs()
def reconnect():
init_all_graphs()
if self.initCommunication() != "OK":
self._notify_window.ThreadControl = 666
while self._notify_window.ThreadControl != 666:
print (self._notify_window.ThreadControl)
if self.connection.connection.status() != OBDStatus.CAR_CONNECTED:
reconnect()
continue
prevstate = curstate
curstate = self._nb.GetSelection() # picking the tab in the GUI
if not first_time:
diff = (time_end - time_start).total_seconds()
if (diff < 0.08333) and (diff > 0):
sleep_time = 0.08333 - diff
time.sleep(sleep_time)
print("Slept for "+str(sleep_time)+" seconds.")
time_start = datetime.datetime.now()
if curstate != 5 and self.graph_counter != 0:
self.graph_x_vals = np.array([])
self.graph_y_vals = np.array([])
self.graph_counter = 0
self.first_time_graph_plot = True
if self.first_time_graph_plot:
self.unit = 'unit'
if self.current_command == None:
desc = 'None'
else:
desc = self.current_command.desc
wx.PostEvent(self._notify_window,
GraphEvent(
[(self.graph_x_vals, self.graph_y_vals, self.unit, desc, self.graph_counter),
(self.first_time_graph_plot)
]))
self.first_time_graph_plot = False
wx.PostEvent(self._notify_window, GraphValueEvent([0, 0, self.current_command.command]))
wx.PostEvent(self._notify_window, GraphValueEvent([0, 1, self.current_command.desc]))
if curstate != 6 and self.graph_counter1 != 0:
self.graph_x_vals1 = np.array([])
self.graph_y_vals1 = np.array([])
self.graph_x_vals2 = np.array([])
self.graph_y_vals2 = np.array([])
self.graph_x_vals3 = np.array([])
self.graph_y_vals3 = np.array([])
self.graph_x_vals4 = np.array([])
self.graph_y_vals4 = np.array([])
self.graph_counter1 = 0
self.graph_counter2 = 0
self.graph_counter3 = 0
self.graph_counter4 = 0
self.first_time_graphs_plot = True
wx.PostEvent(self._notify_window, GraphsEvent(
[(self.graph_x_vals1, self.graph_y_vals1, self.unit1, desc1, self.graph_counter1),
(self.graph_x_vals2, self.graph_y_vals2, self.unit2, desc2, self.graph_counter2),
(self.graph_x_vals3, self.graph_y_vals3, self.unit3, desc3, self.graph_counter3),
(self.graph_x_vals4, self.graph_y_vals4, self.unit4, desc4, self.graph_counter4),
(self.first_time_graphs_plot)
]))
wx.PostEvent(self._notify_window, GraphsValueEvent([0, 0, self.current_command1.command]))
wx.PostEvent(self._notify_window, GraphsValueEvent([0, 1, self.current_command1.desc]))
wx.PostEvent(self._notify_window, GraphsValueEvent([1, 0, self.current_command2.command]))
wx.PostEvent(self._notify_window, GraphsValueEvent([1, 1, self.current_command2.desc]))
wx.PostEvent(self._notify_window, GraphsValueEvent([2, 0, self.current_command3.command]))
wx.PostEvent(self._notify_window, GraphsValueEvent([2, 1, self.current_command3.desc]))
wx.PostEvent(self._notify_window, GraphsValueEvent([3, 0, self.current_command4.command]))
wx.PostEvent(self._notify_window, GraphsValueEvent([3, 1, self.current_command4.desc]))
if curstate == 0: # show status tab
s = self.connection.connection.query(obd.commands.RPM)
if s.value == None:
reconnect()
continue
r = self.connection.connection.query(obd.commands.ELM_VOLTAGE)
self.ELMvoltage = str(r.value)
wx.PostEvent(self._notify_window, StatusEvent([5, 1, str(self.ELMvoltage)]))
elif curstate == 1: # show tests tab
try:
s = self.connection.connection.query(obd.commands.RPM)
if s.value == None:
reconnect()
continue
r = self.connection.connection.query(obd.commands[1][1])
if r.value == None:
# NOT SUPPORTED, so do nothing
continue
if r.value.MISFIRE_MONITORING.available:
wx.PostEvent(self._notify_window, TestEvent([0, 1, "Available"]))
if r.value.MISFIRE_MONITORING.complete:
wx.PostEvent(self._notify_window, TestEvent([0, 2, "Complete"]))
else:
wx.PostEvent(self._notify_window, TestEvent([0, 2, "Incomplete"]))
if r.value.FUEL_SYSTEM_MONITORING.available:
wx.PostEvent(self._notify_window, TestEvent([1, 1, "Available"]))
if r.value.FUEL_SYSTEM_MONITORING.complete:
wx.PostEvent(self._notify_window, TestEvent([1, 2, "Complete"]))
else:
wx.PostEvent(self._notify_window, TestEvent([1, 2, "Incomplete"]))
if r.value.COMPONENT_MONITORING.available:
wx.PostEvent(self._notify_window, TestEvent([2, 1, "Available"]))
if r.value.COMPONENT_MONITORING.complete:
wx.PostEvent(self._notify_window, TestEvent([2, 2, "Complete"]))
else:
wx.PostEvent(self._notify_window, TestEvent([2, 2, "Incomplete"]))
if r.value.CATALYST_MONITORING.available:
wx.PostEvent(self._notify_window, TestEvent([3, 1, "Available"]))
if r.value.CATALYST_MONITORING.complete:
wx.PostEvent(self._notify_window, TestEvent([3, 2, "Complete"]))
else:
wx.PostEvent(self._notify_window, TestEvent([3, 2, "Incomplete"]))
if r.value.HEATED_CATALYST_MONITORING.available:
wx.PostEvent(self._notify_window, TestEvent([4, 1, "Available"]))
if r.value.HEATED_CATALYST_MONITORING.complete:
wx.PostEvent(self._notify_window, TestEvent([4, 2, "Complete"]))
else:
wx.PostEvent(self._notify_window, TestEvent([4, 2, "Incomplete"]))
if r.value.EVAPORATIVE_SYSTEM_MONITORING.available:
wx.PostEvent(self._notify_window, TestEvent([5, 1, "Available"]))
if r.value.EVAPORATIVE_SYSTEM_MONITORING.complete:
wx.PostEvent(self._notify_window, TestEvent([5, 2, "Complete"]))
else:
wx.PostEvent(self._notify_window, TestEvent([5, 2, "Incomplete"]))
if r.value.SECONDARY_AIR_SYSTEM_MONITORING.available:
wx.PostEvent(self._notify_window, TestEvent([6, 1, "Available"]))
if r.value.SECONDARY_AIR_SYSTEM_MONITORING.complete:
wx.PostEvent(self._notify_window, TestEvent([6, 2, "Complete"]))
else:
wx.PostEvent(self._notify_window, TestEvent([6, 2, "Incomplete"]))
if r.value.OXYGEN_SENSOR_MONITORING.available:
wx.PostEvent(self._notify_window, TestEvent([7, 1, "Available"]))
if r.value.OXYGEN_SENSOR_MONITORING.complete:
wx.PostEvent(self._notify_window, TestEvent([7, 2, "Complete"]))
else:
wx.PostEvent(self._notify_window, TestEvent([7, 2, "Incomplete"]))
if r.value.OXYGEN_SENSOR_HEATER_MONITORING.available:
wx.PostEvent(self._notify_window, TestEvent([8, 1, "Available"]))
if r.value.OXYGEN_SENSOR_HEATER_MONITORING.complete:
wx.PostEvent(self._notify_window, TestEvent([8, 2, "Complete"]))
else:
wx.PostEvent(self._notify_window, TestEvent([8, 2, "Incomplete"]))
if r.value.EGR_VVT_SYSTEM_MONITORING.available:
wx.PostEvent(self._notify_window, TestEvent([9, 1, "Available"]))
if r.value.EGR_VVT_SYSTEM_MONITORING.complete:
wx.PostEvent(self._notify_window, TestEvent([9, 2, "Complete"]))
else:
wx.PostEvent(self._notify_window, TestEvent([9, 2, "Incomplete"]))
if r.value.NMHC_CATALYST_MONITORING.available:
wx.PostEvent(self._notify_window, TestEvent([10, 1, "Available"]))
if r.value.NMHC_CATALYST_MONITORING.complete:
wx.PostEvent(self._notify_window, TestEvent([10, 2, "Complete"]))
else:
wx.PostEvent(self._notify_window, TestEvent([10, 2, "Incomplete"]))
if r.value.NOX_SCR_AFTERTREATMENT_MONITORING.available:
wx.PostEvent(self._notify_window, TestEvent([11, 1, "Available"]))
if r.value.NOX_SCR_AFTERTREATMENT_MONITORING.complete:
wx.PostEvent(self._notify_window, TestEvent([11, 2, "Complete"]))
else:
wx.PostEvent(self._notify_window, TestEvent([11, 2, "Incomplete"]))
if r.value.BOOST_PRESSURE_MONITORING.available:
wx.PostEvent(self._notify_window, TestEvent([12, 1, "Available"]))
if r.value.BOOST_PRESSURE_MONITORING.complete:
wx.PostEvent(self._notify_window, TestEvent([12, 2, "Complete"]))
else:
wx.PostEvent(self._notify_window, TestEvent([12, 2, "Incomplete"]))
if r.value.EXHAUST_GAS_SENSOR_MONITORING.available:
wx.PostEvent(self._notify_window, TestEvent([13, 1, "Available"]))
if r.value.EXHAUST_GAS_SENSOR_MONITORING.complete:
wx.PostEvent(self._notify_window, TestEvent([13, 2, "Complete"]))
else:
wx.PostEvent(self._notify_window, TestEvent([13, 2, "Incomplete"]))
if r.value.PM_FILTER_MONITORING.available:
wx.PostEvent(self._notify_window, TestEvent([14, 1, "Available"]))
if r.value.PM_FILTER_MONITORING.complete:
wx.PostEvent(self._notify_window, TestEvent([14, 2, "Complete"]))
else:
wx.PostEvent(self._notify_window, TestEvent([14, 2, "Incomplete"]))
response = self.connection.connection.query(obd.commands.MONITOR_MISFIRE_CYLINDER_1)
if response.value != None:
result = response.value.MISFIRE_COUNT
wx.PostEvent(self._notify_window, TestEvent([15, 2, str(result)]))
response = self.connection.connection.query(obd.commands.MONITOR_MISFIRE_CYLINDER_2)
if response.value != None:
result = response.value.MISFIRE_COUNT
wx.PostEvent(self._notify_window, TestEvent([16, 2, str(result)]))
response = self.connection.connection.query(obd.commands.MONITOR_MISFIRE_CYLINDER_3)
if response.value != None:
result = response.value.MISFIRE_COUNT
wx.PostEvent(self._notify_window, TestEvent([17, 2, str(result)]))
response = self.connection.connection.query(obd.commands.MONITOR_MISFIRE_CYLINDER_4)
if response.value != None:
result = response.value.MISFIRE_COUNT
wx.PostEvent(self._notify_window, TestEvent([18, 2, str(result)]))
response = self.connection.connection.query(obd.commands.MONITOR_MISFIRE_CYLINDER_5)
if response.value != None:
result = response.value.MISFIRE_COUNT
wx.PostEvent(self._notify_window, TestEvent([19, 2, str(result)]))
response = self.connection.connection.query(obd.commands.MONITOR_MISFIRE_CYLINDER_6)
if response.value != None:
result = response.value.MISFIRE_COUNT
wx.PostEvent(self._notify_window, TestEvent([20, 2, str(result)]))
response = self.connection.connection.query(obd.commands.MONITOR_MISFIRE_CYLINDER_7)
if response.value != None:
result = response.value.MISFIRE_COUNT
wx.PostEvent(self._notify_window, TestEvent([21, 2, str(result)]))
response = self.connection.connection.query(obd.commands.MONITOR_MISFIRE_CYLINDER_8)
if response.value != None:
result = response.value.MISFIRE_COUNT
wx.PostEvent(self._notify_window, TestEvent([22, 2, str(result)]))
response = self.connection.connection.query(obd.commands.MONITOR_MISFIRE_CYLINDER_9)
if response.value != None:
result = response.value.MISFIRE_COUNT
wx.PostEvent(self._notify_window, TestEvent([23, 2, str(result)]))
response = self.connection.connection.query(obd.commands.MONITOR_MISFIRE_CYLINDER_10)
if response.value != None:
result = response.value.MISFIRE_COUNT
wx.PostEvent(self._notify_window, TestEvent([24, 2, str(result)]))
response = self.connection.connection.query(obd.commands.MONITOR_MISFIRE_CYLINDER_11)
if response.value != None:
result = response.value.MISFIRE_COUNT
wx.PostEvent(self._notify_window, TestEvent([25, 2, str(result)]))
response = self.connection.connection.query(obd.commands.MONITOR_MISFIRE_CYLINDER_12)
if response.value != None:
result = response.value.MISFIRE_COUNT
wx.PostEvent(self._notify_window, TestEvent([26, 2, str(result)]))
except:
traceback.print_exc()
"""
"MISFIRE_MONITORING",
"FUEL_SYSTEM_MONITORING",
"COMPONENT_MONITORING",
"CATALYST_MONITORING",
"HEATED_CATALYST_MONITORING",
"EVAPORATIVE_SYSTEM_MONITORING",
"SECONDARY_AIR_SYSTEM_MONITORING",
"OXYGEN_SENSOR_MONITORING",
"OXYGEN_SENSOR_HEATER_MONITORING",
"EGR_VVT_SYSTEM_MONITORING",
"NMHC_CATALYST_MONITORING",
"NOX_SCR_AFTERTREATMENT_MONITORING",
"BOOST_PRESSURE_MONITORING",
"EXHAUST_GAS_SENSOR_MONITORING",
"PM_FILTER_MONITORING"
"""
elif curstate == 2: # show sensor tab
if first_time_sensors:
sensor_list = []
counter = 0
first_time_sensors = False
for command in obd.commands[1]:
if command:
if command.command not in (b"0100" , b"0101", b"0120", b"0140", b"0103", b"0102", b"011C", b"0113", b"0141", b"0151"):
s = self.connection.connection.query(command)
if s.value == None:
continue
else:
sensor_list.append([command, command.desc])
#app.sensors.InsertItem(counter, "")
wx.PostEvent(self._notify_window, InsertSensorRowEvent(counter))
wx.PostEvent(self._notify_window, ResultEvent([counter, 0, str(command.command)]))
wx.PostEvent(self._notify_window, ResultEvent([counter, 1, str(command.desc)]))
wx.PostEvent(self._notify_window, ResultEvent([counter, 2, str(s.value)]))
counter = counter + 1
#s = self.connection.connection.query(obd.commands.ELM_VOLTAGE)
#sensor_list.append([obd.commands.ELM_VOLTAGE, obd.commands.ELM_VOLTAGE.desc, str(s.value)])
#wx.PostEvent(self._notify_window, InsertSensorRowEvent(counter))
#wx.PostEvent(self._notify_window, ResultEvent([counter, 0, str(obd.commands.ELM_VOLTAGE.command)]))
#wx.PostEvent(self._notify_window, ResultEvent([counter, 1, str(obd.commands.ELM_VOLTAGE.desc)]))
#wx.PostEvent(self._notify_window, ResultEvent([counter, 2, str(s.value)]))
else:
#for i in range(0, app.sensors.GetItemCount()):
# app.sensors.DeleteItem(0)
counter = 0
for sens in sensor_list:
s = self.connection.connection.query(sens[0])
if s.value == None:
reconnect()
continue
wx.PostEvent(self._notify_window, ResultEvent([counter, 0, str(sens[0].command)]))
wx.PostEvent(self._notify_window, ResultEvent([counter, 1, str(sens[1])]))
wx.PostEvent(self._notify_window, ResultEvent([counter, 2, str(s.value)]))
counter = counter + 1
elif curstate == 3: # show DTC tab
s = self.connection.connection.query(obd.commands.RPM)
if s.value == None:
reconnect()
continue
if self._notify_window.ThreadControl == 1: # clear DTC
r = self.connection.connection.query(obd.commands["CLEAR_DTC"])
if self._notify_window.ThreadControl == 666: # before reset ThreadControl we must check if main thread did not want us to finish
break
self._notify_window.ThreadControl = 0
prevstate = -1 # to reread DTC
if self._notify_window.ThreadControl == 2: # reread DTC
prevstate = -1
if self._notify_window.ThreadControl == 666:
break
self._notify_window.ThreadControl = 0
pass
if prevstate != 3:
wx.PostEvent(self._notify_window, DTCEvent(0)) # clear list
r = self.connection.connection.query(obd.commands.GET_DTC)
DTCCODES = []
print ("DTCCODES:",r.value)
if r.value != None:
for dtccode in r.value:
DTCCODES.append((dtccode[0], "Active", dtccode[1]))
r = self.connection.connection.query(obd.commands.FREEZE_DTC)
print ("FREEZECODES:",r.value)
if r.value != None:
dtccode = r.value
if "P0000" not in dtccode:
DTCCODES.append((dtccode[0], "Passive", dtccode[1]))
print ("DTCcodes and FREEZEcodes:", DTCCODES)
if len(DTCCODES) > 0:
for dtccode in DTCCODES:
wx.PostEvent(self._notify_window, DTCEvent(dtccode))
elif len(DTCCODES) == 0:
wx.PostEvent(self._notify_window, DTCEvent(["", "", "No DTC codes (codes cleared)"]))
elif curstate == 4: # show freezeframe tab
if first_time_freezeframe:
freezeframe_list = []
counter = 0
first_time_freezeframe = False
for command in obd.commands[2]:
if command:
if command.command not in (b"0200" , b"0201", b"0220", b"0240", b"0203", b"0202", b"021C", b"0213", b"0241", b"0251"):
s = self.connection.connection.query(command)
if s.value == None:
continue
else:
freezeframe_list.append([command.command, command.desc, str(s.value)])
wx.PostEvent(self._notify_window, InsertFreezeframeRowEvent(counter))
wx.PostEvent(self._notify_window, FreezeframeResultEvent([counter, 0, str(command.command)]))
wx.PostEvent(self._notify_window, FreezeframeResultEvent([counter, 1, str(command.desc)]))
wx.PostEvent(self._notify_window, FreezeframeResultEvent([counter, 2, str(s.value)]))
counter = counter + 1
else:
counter = 0
for sens in freezeframe_list:
for command in obd.commands[2]:
if command.command == sens[0]:
s = self.connection.connection.query(command)
if s.value == None:
reconnect()
continue
freezeframe_list[counter] = [command.command, command.desc, str(s.value)]
counter = counter + 1
counter = 0
for sens in freezeframe_list:
wx.PostEvent(self._notify_window, FreezeframeResultEvent([counter, 0, str(sens[0])]))
wx.PostEvent(self._notify_window, FreezeframeResultEvent([counter, 1, str(sens[1])]))
wx.PostEvent(self._notify_window, FreezeframeResultEvent([counter, 2, str(sens[2])]))
counter = counter + 1
#if sens[2] == "None" and sens[0]!='0203':
# raise AttributeError
elif curstate == 5: # show Graph tab
if first_time_graph:
print("First time graph")
#wx.PostEvent(self._notify_window, DestroyComboBoxEvent([]))
self.graph_x_vals = np.array([])
self.graph_y_vals = np.array([])
self.graph_counter = 0
self.current_command = None
graph_commands = []
#wx.PostEvent(self._notify_window, GraphEvent((self.current_command, [], [])))
prev_command = None
first_time_graph = False
for command in obd.commands[1]:
if command:
if command.command not in (b"0100" , b"0101", b"0120", b"0140", b"0103", b"0102", b"011C", b"0113", b"0141", b"0151"):
s = self.connection.connection.query(command)
if s.value == None:
continue
else:
graph_commands.append(command)
graph_commands.append(obd.commands.ELM_VOLTAGE)
sensor_descriptions = []
#sensor_descriptions.append("None")
for command in graph_commands:
sensor_descriptions.append(command.desc)
app.build_combobox_graph_event_finished = False
wx.PostEvent(self._notify_window, BuildComboBoxGraphEvent(sensor_descriptions))
while not app.build_combobox_graph_event_finished:
time.sleep(0.01)
app.combobox_graph_set_sel_finished=False
wx.PostEvent(self._notify_window, SetSelectionComboBoxGraphEvent([]))
while not app.combobox_graph_set_sel_finished:
time.sleep(0.01)
else:
app.combobox_graph_get_sel_finished = False
wx.PostEvent(self._notify_window, GetSelectionComboBoxGraphEvent([]))
while not app.combobox_graph_get_sel_finished:
time.sleep(0.01)
curr_selection = app.combobox_selection
if sensor_descriptions[curr_selection] == "None":
curr_selection = -1
if curr_selection != -1:
prev_command = self.current_command
self.current_command = graph_commands[curr_selection]
else:
self.current_command = None
if self.current_command != None:
if (prev_command == None) or (prev_command != self.current_command):
self.graph_x_vals = np.array([])
self.graph_y_vals = np.array([])
self.graph_counter = 0
wx.PostEvent(self._notify_window, GraphValueEvent([0, 0, self.current_command.command]))
wx.PostEvent(self._notify_window, GraphValueEvent([0, 1, self.current_command.desc]))
else:
s = self.connection.connection.query(self.current_command)
if s.value == None:
reconnect()
continue
self.graph_x_vals = np.append(self.graph_x_vals, self.graph_counter)
try:
self.graph_y_vals = np.append(self.graph_y_vals, float(s.value.magnitude))
except AttributeError:
self.graph_y_vals = np.append(self.graph_y_vals, float(0))
if len(self.graph_x_vals) > 450:
self.graph_x_vals = np.delete(self.graph_x_vals, (0))
self.graph_y_vals = np.delete(self.graph_y_vals, (0))
self.graph_counter = self.graph_counter + 1
prev_command = self.current_command
if s.value == None:
wx.PostEvent(self._notify_window, GraphValueEvent([0, 2, str(0)]))
self.unit = "unit"
else:
wx.PostEvent(self._notify_window, GraphValueEvent([0, 2, str(s.value)]))
try:
self.unit = str(s.value).split(' ')[1]
except IndexError:
self.unit = "unit"
else:
self.graph_x_vals = np.array([])
self.graph_y_vals = np.array([])
self.graph_counter = 0
if self.first_time_graph_plot:
self.unit = 'unit'
if self.current_command == None:
desc = 'None'
else:
desc = self.current_command.desc
wx.PostEvent(self._notify_window, GraphEvent([(self.graph_x_vals,self.graph_y_vals, self.unit, desc, self.graph_counter),
(self.first_time_graph_plot)
]))
self.first_time_graph_plot = False
#time.sleep(0.2)
elif curstate == 6: # show Graphs tab
if first_time_graphs:
print("First time graph")
#wx.PostEvent(self._notify_window, DestroyComboBoxEvent([]))
self.graph_x_vals1 = np.array([])
self.graph_y_vals1 = np.array([])
self.graph_x_vals2 = np.array([])
self.graph_y_vals2 = np.array([])
self.graph_x_vals3 = np.array([])
self.graph_y_vals3 = np.array([])
self.graph_x_vals4 = np.array([])
self.graph_y_vals4 = np.array([])
self.graph_counter1 = 0
self.graph_counter2 = 0
self.graph_counter3 = 0
self.graph_counter4 = 0