-
Notifications
You must be signed in to change notification settings - Fork 91
/
obd_message.py
4426 lines (4405 loc) · 201 KB
/
obd_message.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
###########################################################################
# ELM327-emulator
# ELM327 Emulator for testing software interfacing OBDII via ELM327 adapter
# https://github.com/Ircama/ELM327-emulator
# (C) Ircama 2021 - CC-BY-NC-SA-4.0
###########################################################################
# List of known ECUs:
ECU_ADDR_J = "747"
ECU_R_ADDR_J = "74F"
ECU_ADDR_K = "7D2"
ECU_R_ADDR_K = "7DA"
ECU_ADDR_H = "7E2" # HVECU address (Hybrid control module)
ECU_R_ADDR_H = "7EA" # Responses sent by HVECU (Hybrid control module) 7E2/7EA
ECU_ADDR_E = "7E0" # Engine control module ECU address
ECU_R_ADDR_E = "7E8" # Responses sent by Engine ECU - ECM (engine control module) 7E0/7E8
ECU_ADDR_T = "7E1" # Transmission control module ECU address (transmission control module)
ECU_R_ADDR_T = "7E9" # Responses sent by Transmission ECU - TCM (transmission control module) 7E1/7E9
ECU_ADDR_U = "7E2"
ECU_R_ADDR_U = "7EA"
ECU_ADDR_M = "7E5" # Continental power train ECU
ECU_R_ADDR_M = "7ED" # Responses sent by the Continental power train ECU - 7E5/7ED
ECU_ADDR_I = "7C0" # ICE ECU address
ECU_R_ADDR_I = "7C8" # Responses sent by ICE ECU address 7C0/7C8
ECU_ADDR_B = "7E3" # Traction Battery ECU address
ECU_R_ADDR_B = "7EB" # Responses sent by Traction Battery ECU - 7E3/7EB
ECU_ADDR_P = "7C4" # Air Conditioning
ECU_R_ADDR_P = "7CC" # Responses sent by Air Conditioning ECU - 7C4/7CC
ECU_ADDR_S = "7B0" # Skid Control address ECU
ECU_R_ADDR_S = "7B8" # Responses sent by 7B0 Skid Control ECU 7B0/7B8
def SZ(size):
return ('<size>' + size + '</size>')
def HD(header):
return ('<header>' + header + '</header>')
def DT(data):
return ('<data>' + data + '</data>')
def ST(writeln):
return ('<writeln>' + writeln + '</writeln>')
def AW(answer):
return ('<answer>' + answer + '</answer>')
def PA(pos_answer):
return ('<pos_answer>' + pos_answer + '</pos_answer>')
def NA(neg_answer):
return ('<neg_answer>' + neg_answer + '</neg_answer>')
ELM_R_OK = ST("OK")
ELM_R_UNKNOWN = ST("?")
ELM_FOOTER = r'[0123456]?$'
ELM_DATA_FOOTER = r'([0-9A-Z][0-9A-Z])+$'
# PID Dictionary
ObdMessage = {
# AT Commands
'AT' : {
'AT_LONG_MSG': {
'Request': '^ATAL$',
'Descr': 'AT Allow long messages',
'Exec': 'self.counters["cmd_long_msg"] = True',
'Log': '"set Long Messages %s", self.counters["cmd_long_msg"]',
'Response': ELM_R_OK
},
'AT_NORMAL_LENGTH': {
'Request': '^ATNL$',
'Descr': 'AT Enforce normal message length',
'Exec': 'self.counters["cmd_long_msg"] = False',
'Log': '"set Long Messages %s", self.counters["cmd_long_msg"]',
'Response': ELM_R_OK
},
'AT_DESCR': {
'Request': '^AT@1' + ELM_FOOTER,
'Descr': 'AT Device description',
'Response': ST("OBDII to RS232 Interpreter")
},
'AT_ID': {
'Request': '^AT@2' + ELM_FOOTER,
'Descr': 'AT Device identifier',
'Response': ST('?')
},
'AT_STORE_ID': {
'Request': '^AT@3' + ELM_FOOTER,
'Descr': 'AT Store the device identifier',
'Response': ST('?')
},
'AT_ADAPTIVE_TIMING': {
'Request': '^ATAT[012]$',
'Descr': 'AT Set adaptive timing mode',
'Exec': 'self.counters["cmd_adaptive_t"] = cmd[4:] or None',
'Log': '"Set adaptive timing %s", self.counters["cmd_adaptive_t"]',
'Response': ELM_R_OK
},
'AT_BYPASS_INIT': {
'Request': '^ATBI$',
'Descr': 'AT Bypass the Initialization sequence',
'Response': ELM_R_OK # ignored at the moment: just answer OK (to be revised)
},
'AT_CAF': {
'Request': '^ATCAF[01]$',
'Descr': 'AT CAN Automatic Formatting',
'Exec': 'self.counters["cmd_caf"] = (cmd[5] == "1")',
'Log': '"Set CAN Automatic Formatting ON/OFF : %s", '
'self.counters["cmd_caf"]',
'Response': ELM_R_OK
},
'AT_CFC': {
'Request': '^ATCFC[01]$',
'Descr': 'AT CAN Fow Control',
'Exec': 'self.counters["cmd_cfc"] = (cmd[5] == "1")',
'Log': '"Set CAN Flow Control ON/OFF : %s", '
'self.counters["cmd_cfc"]',
'Response': ELM_R_OK
},
'AT_FCSM': {
'Request': '^ATFCSM[01]$',
'Descr': 'AT Fow Control Set Mode',
'Exec': 'self.counters["cmd_fcsm"] = (cmd[6] == "1")',
'Log': '"Set Flow Control mode : %s", '
'self.counters["cmd_fcsm"]',
'Response': ELM_R_OK
},
'AT_RESPONSES': {
'Request': '^ATR[01]$',
'Descr': 'AT Turn responses on or off',
'Exec': 'self.counters["cmd_response"] = (cmd[3] == "1")',
'Log': '"Set responses ON/OFF : %s", '
'self.counters["cmd_response"]',
'Response': ELM_R_OK
},
'AT_SET_CAN_RX_ADDR': {
'Request': '^ATCRA',
'Descr': 'AT SET CAN RX Addr',
'Exec': 'self.counters["cmd_cra"] = cmd[5:] or None',
'Log': '"set CAN RX Addr %s", self.counters["cmd_cra"]',
'Response': ELM_R_OK
},
'AT_BRD': {
'Request': '^ATBRD',
'Descr': 'AT Set UART baud rate divisor',
'Exec': 'self.counters["cmd_brd"] = cmd[5:]',
'Log': '"set UART baud rate divisor %s", '
'self.counters["cmd_brd"]',
'Response': ELM_R_OK
},
'AT_BRT': {
'Request': '^ATBRT',
'Descr': 'AT Set UART baud rate timeout',
'Exec': 'self.counters["cmd_brt"] = cmd[5:]',
'Log': '"set UART baud rate timeout %s", '
'self.counters["cmd_brt"]',
'Response': ELM_R_OK
},
'AT_DEFAULT': {
'Request': '^ATD$',
'Descr': 'AT DEFAULT',
'Log': '"Set all configuration to defaults"',
'Exec': 'self.reset(0.1)',
'Response': ELM_R_OK
},
'AT_FI': {
'Request': '^ATFI$',
'Descr': 'AT FAST INIT',
'Log': '"Perform a fast initiation"',
'Response': ELM_R_OK
},
'AT_DKW': {
'Request': '^ATKW$',
'Descr': 'AT DISPLAY KEY WORDS',
'Log': '"Display keywords"',
'ResponseFooter': lambda self, cmd, pid, uc_val:
self.counters["cmd_atkw"] + " " if "cmd_atkw" in self.counters
else "0 "
},
'AT_SKW': {
'Request': '^ATKW[01]$',
'Descr': 'AT SET KEY WORDS',
'Exec': 'self.counters["cmd_atkw"] = cmd[4:]',
'Log': '"Set key words to %s", '
'self.counters["cmd_atkw"]',
'Response': ELM_R_OK
},
'AT_V': {
'Request': '^ATV[01]$',
'Descr': 'AT SET VARIABLE DLC ON/OFF',
'Exec': 'self.counters["cmd_atv"] = cmd[3:]',
'Log': '"Set variable DLC to %s", '
'self.counters["cmd_atv"]',
'Response': ELM_R_OK
},
'AT_DLC': {
'Request': '^ATD[01]$',
'Descr': 'AT Display of the DLC on/off',
'Exec': 'self.counters["cmd_dlc"] = (cmd[3] == "1")',
'Log': '"Set DLC %s", self.counters["cmd_dlc"]',
'Response': ELM_R_OK # ignored at the moment: just answer OK (to be revised)
},
'AT_DESCRIBE_PROTO': {
'Request': '^ATDP$',
'Descr': 'AT set DESCRIBE PROTO',
'Exec': 'time.sleep(0.5)',
'ResponseHeader': \
lambda self, cmd, pid, uc_val: \
ST('AUTO, ISO 15765-4 (CAN 11/500) ') \
if "cmd_proto" not in self.counters or \
not self.counters['cmd_proto'] or \
self.counters['cmd_proto'] == "0" or \
self.counters['cmd_proto'] == "6" \
else ST("ISO 15765-4 (CAN 11/500)")
},
'AT_DESCRIBE_PROTO_N': {
'Request': '^ATDPN$',
'Descr': 'AT Display Protocol Number',
'Exec': 'time.sleep(0.5)',
'Response': ST("A6")
},
'AT_ECHO': {
'Request': '^ATE[01]$',
'Descr': 'AT ECHO',
'Exec': 'self.counters["cmd_echo"] = (not cmd[3] == "0")',
'Log': '"set ECHO ON/OFF : %s", self.counters["cmd_echo"]',
'Response': ELM_R_OK
},
'AT_USE_HEADERS': {
'Request': '^ATH[01]$',
'Descr': 'AT HEADERS',
'Exec': 'self.counters["cmd_use_header"] = (cmd[3] == "1")',
'Log': '"set HEADERS ON/OFF : %s", self.counters["cmd_use_header"]',
'Response': ELM_R_OK
},
'AT_I': {
'Request': '^ATI$',
'Descr': 'AT ELM327 version string',
'ResponseHeader': \
lambda self, cmd, pid, uc_val: \
ST(self.counters['cmd_version'])
},
'AT_IGN': {
'Request': '^ATIGN$',
'Descr': 'AT IgnMon input level',
'Response': (ST("ON"), ST("OFF"))
},
'AT_LINEFEEDS': {
'Request': '^ATL[01]$',
'Descr': 'AT LINEFEEDS',
'Exec': 'self.counters["cmd_linefeeds"] = (cmd[3] == "1")',
'Log': '"set LINEFEEDS ON/OFF : %s", self.counters["cmd_linefeeds"]',
'Response': ELM_R_OK
},
'AT_LP': {
'Request': '^ATLP$',
'Descr': 'AT Low Power mode',
'Response': ELM_R_OK
},
'AT_MEMORY': {
'Request': '^ATM[01]$',
'Descr': 'AT Memory off or on',
'Exec': 'self.counters["cmd_memory"] = (cmd[3] == "1")',
'Log': '"set MEMORY ON/OFF : %s", self.counters["cmd_memory"]',
'Response': ELM_R_OK
},
'AT_R_VOLT': {
'Request': '^ATRV$',
'Descr': 'AT read volt',
'Log':
'"Volt = {:.1f}".format('
'0.1 * abs(9 - (self.counters[pid] + 9) % 18) + 13)',
'ResponseHeader': \
lambda self, cmd, pid, uc_val: \
"<string>{:.1f}</string>".format( \
0.1 * abs(9 - (self.counters[pid] + 9) % 18) + 13),
'Response': ST("V")
},
'AT_SPACES': {
'Request': '^ATS[01]$',
'Descr': 'AT Spaces off or on',
'Exec': 'self.counters["cmd_spaces"] = (cmd[3] == "1")',
'Log': '"set SPACES %s", self.counters["cmd_spaces"]',
'Response': ELM_R_OK
},
'AT_SET_HEADER': {
'Request': '^ATSH[0-9A-F]+$',
'Descr': 'AT SET HEADER',
'Exec': 'self.counters["cmd_set_header"] = '
're.sub(r"^0*([0-9A-F]+)$", r"\\1", cmd[4:])',
'Log': '"Set HEADER to <%s>", self.counters["cmd_set_header"]',
'Response': ELM_R_OK
},
'AT_CAN_HFM': {
'Request': '^ATCM[0-9A-F]+$',
'Descr': 'AT Set the CAN hardware filter mask',
'Exec': 'self.counters["cmd_hfm"] = '
're.sub(r"^0*([0-9A-F]+)$", r"\\1", cmd[4:])',
'Log': '"Set CAN hardware filter mask to <%s>", '
'self.counters["cmd_hfm"]',
'Response': ELM_R_OK
},
'AT_CAN_FP': {
'Request': '^ATCF[0-9A-F]+$',
'Descr': 'AT Set the CAN hardware filter pattern',
'Exec': 'self.counters["cmd_cfp"] = '
're.sub(r"^0*([0-9A-F]+)$", r"\\1", cmd[4:])',
'Log': '"Set CAN hardware filter pattern to <%s>", '
'self.counters["cmd_cfp"]',
'Response': ELM_R_OK
},
'AT_WAKEUP': {
'Request': '^ATSW[0-9A-F]+$',
'Descr': 'AT Set wakeup',
'Exec': 'self.counters["cmd_wakeup"] = cmd[4:]',
'Log': '"Set wakeup to <%s>", '
'self.counters["cmd_wakeup"]',
'Response': ELM_R_OK
},
'AT_FCSH': {
'Request': '^ATFCSH',
'Descr': 'AT FLOW CONTROL SET HEADER',
'Exec': 'self.counters["cmd_fcsh"] = cmd[6:] or None',
'Log': '"set FLOW CONTROL set HEADER %s", '
'self.counters["cmd_fcsh"]',
'Response': ELM_R_OK
},
'AT_FCSD': {
'Request': '^ATFCSD',
'Descr': 'AT FLOW CONTROL SET DATA',
'Exec': 'self.counters["cmd_fcsd"] = cmd[6:] or None',
'Log': '"set FLOW CONTROL set DATA %s", '
'self.counters["cmd_fcsd"]',
'Response': ELM_R_OK
},
'AT_FCSM': {
'Request': '^ATFCSM[0-2]$',
'Descr': 'AT FLOW CONTROL SET MODE',
'Exec': 'self.counters["cmd_fcsm"] = cmd[6:] or None',
'Log': '"set FLOW CONTROL set MODE %s", '
'self.counters["cmd_fcsm"]',
'Response': ELM_R_OK
},
'AT_ISO_BAUD': {
'Request': '^ATIB[149][086]$',
'Descr': 'AT Set ISO baud rate to 10400, 4800, or 9600 baud',
'Exec': 'self.counters["cmd_iso_baud"] = cmd[4:] or None',
'Log': '"Set ISO baud rate to: %s", self.counters["cmd_iso_baud"]',
'Response': ELM_R_OK
},
'AT_PROTO': {
'Request': '^ATSP[0-9A-C]$',
'Descr': 'AT PROTO',
'Exec': 'self.counters["cmd_proto"] = cmd[4] or None',
'Log': '"set PROTO %s", self.counters["cmd_proto"]',
'Response': ELM_R_OK
},
'AT_PROTO_ERASE': {
'Request': '^ATSP00$',
'Descr': 'AT PROTO',
'Exec': 'self.counters["cmd_proto"] = None',
'Log': '"set PROTO %s", self.counters["cmd_proto"]',
'Response': ELM_R_OK
},
'AT_SET_RECEIVE_ADDR': {
'Request': '^ATSR[0-9A-F]+$',
'Descr': 'AT Set Receive Address',
'Exec': 'self.counters["cmd_rec_addr"] = cmd[4:]',
'Log': '"Set Receive Address to %s", '
'self.counters["cmd_rec_addr"]',
'Response': ELM_R_OK
},
'AT_ISO_INIT_ADDR': {
'Request': '^ATIIA[0-9A-F]+$',
'Descr': 'AT Set the ISO 5-baud init address',
'Exec': 'self.counters["cmd_iia"] = int(cmd[5:], 16)',
'Log': '"Set init address to %s", self.counters["cmd_iia"]',
'Response': ELM_R_OK
},
'AT_TRY_PROTO': {
'Request': '^ATTP[0-9A-F]+$',
'Descr': 'AT TRY PROTO',
'Exec': 'self.counters["cmd_try_proto"] = int(cmd[4:], 16)',
'Log': '"Try protocol %s", self.counters["cmd_try_proto"]',
'Response': ELM_R_OK
},
'AT_TEST_ADDR': {
'Request': '^ATTA[0-9A-F][0-9A-F]$',
'Descr': 'AT Set tester address to hh.',
'Exec': 'self.counters["cmd_test_add"] = cmd[4:] or None',
'Log': '"Set tester address to %s", '
'self.counters["cmd_test_add"]',
'Response': ELM_R_OK
},
'AT_WARM_START': {
'Request': '^ATWS$',
'Descr': 'AT WARM START',
'Log': '"Warm start and sleep 0.1 seconds"',
#'Exec': 'self.reset(0.1)',
'ResponseHeader': \
lambda self, cmd, pid, uc_val: \
ST(self.header_version + self.counters['cmd_version'])
},
'AT_RESET': {
'Request': '^ATZ$',
'Descr': 'AT RESET',
'Log': '"Reset and sleep 0.5 seconds"',
'Exec': 'self.reset(0.5)',
'ResponseFooter': \
lambda self, cmd, pid, uc_val: \
ST(self.header_version + self.counters['cmd_version'])
},
'AT_SET_TIMEOUT': {
'Request': '^ATST[0-9A-F]+$',
'Descr': 'AT SET TIMEOUT',
'Exec': 'self.counters["cmd_timeout"] = int(cmd[4:], 16)',
'Log': '"Set timeout %s", self.counters["cmd_timeout"]',
'Response': ELM_R_OK
},
'AT_CEA': {
'Request': '^ATCEA',
'Descr': 'AT CAN EXTENDED ADDRESS',
'Exec': 'self.counters["cmd_cea"] = cmd[5:] or None',
'Log': '"set CEA %s", self.counters["cmd_cea"]',
'Response': ELM_R_OK
},
'AT_PC': {
'Request': '^ATPC$',
'Descr': 'AT PROTOCOL CLOSE',
'Response': ELM_R_OK
},
'AT_SLOW_INIT': {
'Request': '^ATSI$',
'Descr': 'AT Slow (5-baud) initialization',
'Response': ELM_R_OK
},
'AT_AR': {
'Request': '^ATAR$',
'Descr': 'AT Automatically set the Receive Address',
'Response': ELM_R_OK
},
'AT_BD': {
'Request': '^ATBD$',
'Descr': 'AT Buffer dump',
'Response': ST("00 00 00 00 00 00 00 00 00 00 00 00 00")
},
'AT_PPS': {
'Request': '^ATPPS$',
'Descr': 'AT Print programmable parameter summary.',
'Response': ST('00:FF F 01:FF F 02:FF F 03:32 F') +
ST('04:01 F 05:FF F 06:F1 F 07:09 F') +
ST('08:FF F 09:00 F 0A:0A F 0B:FF F') +
ST('0C:68 F 0D:0D F 0E:FF F 0F:FF F') +
ST('10:0D F 11:00 F 12:FF F 13:32 F') +
ST('14:FF F 15:FF F 16:FF F 17:92 F') +
ST('18:00 F 19:FF F 1A:FF F 1B:FF F') +
ST('1C:FF F 1D:FF F 1E:FF F 1F:FF F') +
ST('20:FF F 21:FF F 22:FF F 23:FF F') +
ST('24:00 F 25:00 F 26:00 F 27:FF F') +
ST('28:FF F 29:FF F 2A:38 F 2B:02 F') +
ST('2C:E0 F 2D:04 F 2E:80 F 2F:0A F')
},
'AT_MA': {
'Request': '^ATMA$',
'Descr': 'AT Monitor all messages',
'Response': ST('C4 ') + ST('245 00 ') +
ST('247 06 00200283 00 3127 00 ') +
ST('260 0262 01 00 ') + ST('020 00 ') +
ST('0B4 002344 000AA 1A 6F 1A 6212127 00 ') +
ST('2247 06 020200260 411 0040AA 1A 6F 283 00 ') +
ST('020 00 ') +
ST('0B4 00 001273F9 58 5C 560AA 1 22245 00 '
'3A026247020 02006262 0139B 0127 00 ') +
ST('1394 0020 00 ') + ST('0B4 00 ') +
ST('0250344 00 260 08 FF F1STOPPED') + ST('') +
ST('>TMA') + ST('?') + ST('') + ST('>ATMA') +
ST('0AA 1A 6F 1A 6F 1A 6F 1A 6F ') +
ST('224 00 ') + ST('127 00 ') + ST('344 00 ') +
ST('260 08 FF F2 00 00 FF F2 54 A3 ') + ST('020 00 ') +
ST('230 00 ') + ST('025 00 ') + ST('024 01 FD ') +
ST('1C4 06 7D 00 00 00 00 00 ') +
ST('48B 80 05 05 05 00 00 00 00 ') +
ST('245 00 ') + ST('0AA 1A 6F 1A 6F 1A 6F 1A 6F ') +
ST('2A4 00 ') + ST('361 80 00 00 00 01 FD 01 FB ') +
ST('38B 00 ') + ST('247 06 00 FF 00 00 00 00 ') +
ST('413 01 01 ') + ST('127 00 ') + ST('020 00 ') +
ST('0B4 00 ') + ST('025 00 ') +
ST('02266 10 342F 283 23')
},
#------------------------------------------------------------
# ST Extensions used to configure the STN11xx family of OBD interpreters
'ST_PROTO': {
'Request': '^STP[0-9]+$',
'Descr': 'ST Set current protocol',
'Exec': 'self.counters["cmd_st_proto"] = int(cmd[3:])',
'Log': '"Set current protocol %s", self.counters["cmd_st_proto"]',
'Response': ELM_R_OK
},
'^ST_SLX': {
'Request': '^STSLX',
'Descr': 'AT Enable or disable sleep/wakeup triggers',
'Exec': 'self.counters["cmd_st_slx"] = cmd[5:] or None',
'Log': '"set sleep/wakeup triggers %s", '
'self.counters["cmd_st_slx"]',
'Response': ELM_R_OK
},
'ST_SERIAL_NUMBER': {
'Request': '^STSN$',
'Descr': 'ST Print the device serial number.',
'Response': ST("110012345678")
},
'ST_REPORT_PROTOCOL': {
'Request': '^STPR$',
'Descr': 'ST Report current protocol number.',
'Exec': 'time.sleep(0.5)',
'Response': ST("A6")
},
'ST_DI': {
'Request': '^STDI$',
'Descr': 'AT Print device hardware ID string.',
'Response': ST("OBDLink r1.7")
},
'ST_ID': {
'Request': '^STI$',
'Descr': 'ST Print firmware ID string',
'Response': ST("STN1100 v1.2.3")
},
'ST_IP4': {
'Request': '^STIP4[ 0-9]*$',
'Descr': 'Set Tx Interbyte delay: ms',
'Exec': 'self.counters["cmd_stip4"] = cmd[5:]',
'Log': '"Set Tx Interbyte delay %s", self.counters["cmd_stip4"]',
'Response': ELM_R_OK
},
'ST_PTO': {
'Request': '^STPTO[ 0-9]*$',
'Descr': 'Set OBD Request Timeout',
'Exec': 'self.counters["cmd_stpto"] = cmd[5:]',
'Log': '"Set OBD Request Timeout %s", self.counters["cmd_stpto"]',
'Response': ELM_R_OK
},
'ST_SET_BAUD_RATE': {
'Request': '^STPBR *[1-9][0-9]*$',
'Descr': 'ST Set baud rate',
'Response': ELM_R_OK
},
'ST_SET_BAUD_RATE_1': {
'Request': '^STSBR *[1-9][0-9]*$',
'Descr': 'ST Set baud rate',
'Response': ST("STN1101 v2.1.0")
},
'ST_STCCFCP': {
'Request': '^STCCFCP$',
'Descr': 'ST Clear all CAN flow control address pairs.',
'Response': ELM_R_OK
},
'ST_STCFCPC': {
'Request': '^STCFCPC$',
'Descr': 'ST Clear all flow control address pairs.',
'Response': ELM_R_OK
},
'ST_STCAFCP': {
'Request': '^STCAFCP[0-9A-F, ]+$',
'Descr': 'ST Add CAN flow control address pair.',
'Exec': 'self.counters["cmd_st_fcap"] = cmd[7:] or None',
'Log': '"Add CAN flow control CAN %s", self.counters["cmd_st_fcap"]',
'Response': ELM_R_OK
},
'ST_STCFCPA': {
'Request': '^STCFCPA[0-9A-F, ]+$',
'Descr': 'ST Add a flow control CAN address pair.',
'Exec': 'self.counters["cmd_st_fcap"] = cmd[7:] or None',
'Log': '"Add a flow control CAN %s", self.counters["cmd_st_fcap"]',
'Response': ELM_R_OK
},
},
# OBD Commands
'engineoff' : {
'ELM_PIDS_A': {
'Request': '^0100$',
'Descr': 'PIDS_A',
'ResponseHeader': \
lambda self, cmd, pid, uc_val: \
'<string>SEARCHING...</string>'
'<exec>time.sleep(4.5)</exec>' + ST('') + \
ST('UNABLE TO CONNECT') \
if self.counters[pid] == 1 else \
self.choice([ST('NO DATA'), ST('BUS INIT:ERROR')]),
'Priority': 5
},
'ELM_MIDS_A': {
'Request': '^0600$',
'Descr': 'MIDS_A',
'ResponseHeader': \
lambda self, cmd, pid, uc_val: \
'<string>SEARCHING...</string>'
'<exec>time.sleep(4.5)</exec>' + ST('') + \
ST('UNABLE TO CONNECT') \
if self.counters[pid] == 1 else \
self.choice([ST('NO DATA'), ST('BUS INIT:ERROR')]),
'Priority': 5
},
'AT_DESCRIBE_PROTO_N': {
'Request': '^ATDPN$',
'Descr': 'set DESCRIBE_PROTO_N',
'Exec': 'time.sleep(0.5)',
'Response': ST("A0")
},
'NO_DATA': {
'Request': '^[0-9][0-9][0-9A-F]+$',
'Descr': 'NO_DATA',
'Response': ST('NO DATA'),
'Priority': 6
},
},
'default' : {
# Mode 01 Sending diagnostic data (PID data monitor/on-board system readiness test)
'FUEL_STATUS': {
'Request': '^0103' + ELM_FOOTER,
'Descr': 'Fuel System Status',
'Response': PA('00 00')
},
'ENGINE_LOAD': {
'Request': '^0104' + ELM_FOOTER,
'Descr': 'Calculated Engine Load',
'Response': PA('00')
},
'COOLANT_TEMP': {
'Request': '^0105' + ELM_FOOTER,
'Descr': 'Engine Coolant Temperature',
'Response': PA('7B')
},
'INTAKE_PRESSURE': {
'Request': '^010B' + ELM_FOOTER,
'Descr': 'Intake Manifold Pressure',
'Response': PA('73')
},
'RPM': {
'Request': '^010C' + ELM_FOOTER,
'Descr': 'Engine RPM',
'ResponseFooter': \
lambda self, cmd, pid, uc_val: (
PA(self.sequence(
pid, base=2400, max=200, factor=80, n_bytes=2))
+ ' ' + HD(ECU_R_ADDR_H) + SZ('04') + DT('41 0C '
+ self.sequence(pid, base=2400, max=200, factor=80, n_bytes=2))
)
},
'SPEED': {
'Request': '^010D' + ELM_FOOTER,
'Descr': 'Vehicle Speed',
'ResponseFooter': \
lambda self, cmd, pid, uc_val: (
PA(self.sequence(pid, base=0, max=30, factor=4, n_bytes=1))
+ ' ' + HD(ECU_R_ADDR_H) + SZ('03') + DT('41 0D '
+ self.sequence(pid, base=0, max=30, factor=4, n_bytes=1))
)
},
'INTAKE_TEMP': {
'Request': '^010F' + ELM_FOOTER,
'Descr': 'Intake Air Temp',
'Response': PA('44')
},
'MAF': {
'Request': '^0110' + ELM_FOOTER,
'Descr': 'Air Flow Rate (MAF)',
'Response': PA('05 1F')
},
'THROTTLE_POS': {
'Request': '^0111' + ELM_FOOTER,
'Descr': 'Throttle Position',
'Response': PA('FF')
},
'OBD_COMPLIANCE': {
'Request': '^011C' + ELM_FOOTER,
'Descr': 'OBD Standards Compliance',
'Response': PA('06')
},
'RUN_TIME': {
'Request': '^011F' + ELM_FOOTER,
'Descr': 'Engine Run Time',
'Response': PA('00 8C')
},
'DISTANCE_W_MIL': {
'Request': '^0121' + ELM_FOOTER,
'Descr': 'Distance Traveled with MIL on',
'Response': PA('00 00')
},
'FUEL_RAIL_PRESSURE_DIRECT': {
'Request': '^0123' + ELM_FOOTER,
'Descr': 'Fuel Rail Pressure (direct inject)',
'Response': PA('1A 0E')
},
'COMMANDED_EGR': {
'Request': '^012C' + ELM_FOOTER,
'Descr': 'Commanded EGR',
'Response': PA('0D')
},
'EGR_ERROR': {
'Request': '^012D' + ELM_FOOTER,
'Descr': 'EGR Error',
'Response': PA('80')
},
'DISTANCE_SINCE_DTC_CLEAR': {
'Request': '^0131' + ELM_FOOTER,
'Descr': 'Distance traveled since codes cleared',
'Response': PA('C8 1F')
},
'BAROMETRIC_PRESSURE': {
'Request': '^0133' + ELM_FOOTER,
'Descr': 'Barometric Pressure',
'Response': PA('65')
},
'CATALYST_TEMP_B1S1': {
'Request': '^013C' + ELM_FOOTER,
'Descr': 'Catalyst Temperature: Bank 1 - Sensor 1',
'Response': PA('04 44')
},
'CONTROL_MODULE_VOLTAGE': {
'Request': '^0142' + ELM_FOOTER,
'Descr': 'Control module voltage',
'Response': PA('39 D6')
},
'AMBIANT_AIR_TEMP': {
'Request': '^0146' + ELM_FOOTER,
'Descr': 'Ambient air temperature',
'Response': PA('43')
},
'ACCELERATOR_POS_D': {
'Request': '^0149' + ELM_FOOTER,
'Descr': 'Accelerator pedal position D',
'Response': PA('00')
},
'ACCELERATOR_POS_E': {
'Request': '^014A' + ELM_FOOTER,
'Descr': 'Accelerator pedal position E',
'Response': PA('45')
},
'THROTTLE_ACTUATOR': {
'Request': '^014C' + ELM_FOOTER,
'Descr': 'Commanded throttle actuator',
'Response': PA('00')
},
'RUN_TIME_MIL': {
'Request': '^014D' + ELM_FOOTER,
'Descr': 'Time run with MIL on',
'Response': PA('00 00')
},
'TIME_SINCE_DTC_CLEARED': {
'Request': '^014E' + ELM_FOOTER,
'Descr': 'Time since trouble codes cleared',
'Response': PA('4C 69')
},
'FUEL_TYPE': {
'Request': '^0151' + ELM_FOOTER,
'Descr': 'Fuel Type',
'Response': PA('01')
},
'FUEL_INJECT_TIMING': {
'Request': '^015D' + ELM_FOOTER,
'Descr': 'Fuel injection timing',
'Response': PA('66 00')
},
# Supported PIDs for protocols
'ELM_PIDS_A': {
'Request': '^0100' + ELM_FOOTER,
'Descr': 'PIDS_A',
'ResponseHeader': \
lambda self, cmd, pid, uc_val: \
'<string>SEARCHING...</string>'
'<exec>time.sleep(3)</exec>' + ST('') \
if self.counters[pid] == 1 else "",
'Response':
HD(ECU_R_ADDR_H) + SZ('06') + DT('41 00 98 3A 80 13') +
PA('BE 3F A8 13')
},
'ELM_PIDS_B': {
'Request': '^0120' + ELM_FOOTER,
'Descr': 'PIDS_B',
'Response':
HD(ECU_R_ADDR_H) + SZ('06') + DT('41 20 80 01 A0 01') +
PA('90 15 B0 15')
},
'ELM_PIDS_C': {
'Request': '^0140' + ELM_FOOTER,
'Descr': 'PIDS_C',
'Response':
HD(ECU_R_ADDR_H) + SZ('06') + DT('41 40 44 CC 00 21') +
PA('7A 1C 80 00')
},
# Mode 06 Sending intermittent monitoring system test results (DMTR)
'ELM_MIDS_A': {
'Request': '^0600' + ELM_FOOTER,
'Descr': 'MIDS_A',
'Response': PA('C0 00 00 01')
},
'ELM_MIDS_B': {
'Request': '^0620' + ELM_FOOTER,
'Descr': 'MIDS_B',
'Response': PA('80 00 80 01')
},
'ELM_MIDS_C': {
'Request': '^0640' + ELM_FOOTER,
'Descr': 'MIDS_C',
'Response': PA('00 00 00 01')
},
'ELM_MIDS_D': {
'Request': '^0660' + ELM_FOOTER,
'Descr': 'MIDS_D',
'Response': PA('00 00 00 01')
},
'ELM_MIDS_E': {
'Request': '^0680' + ELM_FOOTER,
'Descr': 'MIDS_E',
'Response': PA('00 00 00 01')
},
'ELM_MIDS_F': {
'Request': '^06A0' + ELM_FOOTER,
'Descr': 'MIDS_F',
'Response': PA('F8 00 00 00')
},
# Mode 07 Sending continuous monitoring system test results (pending code)
# Mode 09 Request vehicle information
'ELM_PIDS_9A': {
'Request': '^0900' + ELM_FOOTER,
'Descr': 'PIDS_9A',
'Response': PA('FF FF FF FF')
},
'VIN_MESSAGE_COUNT': {
'Request': '^0901' + ELM_FOOTER,
'Descr': 'VIN Message Count',
'Response': PA('01')
},
'VIN': { # Check this also: https://stackoverflow.com/a/26752855/10598800, https://www.autocheck.com/vehiclehistory/autocheck/en/vinbasics
'Request': '^0902' + ELM_FOOTER,
'Descr': 'Vehicle Identification Number',
'Response': [
PA("01 57 50 30 5A 5A 5A 39 39 "
"5A 54 53 33 39 30 30 30 30"), # https://www.autodna.com/vin/WP0ZZZ99ZTS390000, https://it.vin-info.com/libro-denuncia/WP0ZZZ99ZTS390000
PA("01 4D 41 54 34 30 33 30 39 "
"36 42 4E 4C 30 30 30 30 30"), # https://community.carloop.io/t/how-to-request-vin/153/11
]
},
'CALIBRATION_ID_MESSAGE_COUNT': {
'Request': '^0903' + ELM_FOOTER,
'Descr': 'Calibration ID message count for PID 04',
'Response': PA('01')
},
'PERF_TRACKING_COMPRESSION': {
'Request': '^090B' + ELM_FOOTER,
'Descr': 'In-use performance tracking (compression ignition)',
'Response': PA('00 00')
},
# UDS raw
'UNKNOWN_00': {
'Request': '^00$',
'Descr': 'UNKNOWN_00',
'Response': AW('7B 00')
},
'UDS_STDS_FLASH': {
'Request': '^1085' + ELM_FOOTER, # 85 = Flash Programming Session
'Descr': 'UDS Start Diagnostic Session - ECU Prog Mode',
'Response': PA('')
},
'UDS_ECU_RESET': {
'Request': '^1101' + ELM_FOOTER,
'Descr': 'EcuReset',
'Response': PA('')
},
'CLEAR_DTC': {
'Request': '^14' + ELM_DATA_FOOTER,
'Descr': 'Clear DTC',
'ResponseFooter': lambda self, cmd, pid, uc_val: (
self.choice([NA('78'), PA(cmd[2:])])
)
},
'UNKNOWN_2100_E': {
'Request': '^2100' + ELM_FOOTER,
'Descr': 'UNKNOWN_2100',
'Response': PA(
'4A4D5A424B313459323731353437303037FFFFFFFF2AFFFFFF'
'FF033D0DA4FFFF9641FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'
'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFF'
'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'
'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF36C9FF30')
},
'ECU_IVN_HW': {
'Request': '^2103' + ELM_FOOTER,
'Descr': 'ECU internal version numbers - Hardware Part Number',
'Response': PA('46 31'),
},
'DTC_CNT': {
'Request': '^220000' + ELM_FOOTER,
'Descr': "Number of DTC's (if any)",
'Response': PA('00BE3FA813')
},
'UDS_REQ_SEED': {
'Request': '^2701' + ELM_FOOTER,
'Descr': 'SecurityAccess - requestSeed',
'Response': PA('B6F1EF') # response SID
},
'UDS_SEND_KEY': {
'Request': '^2702' + ELM_FOOTER,
'Descr': 'SecurityAccess - Send Key to ECU',
'Response': PA('')
},
'UNK_3B00': {
'Request': '^3B00' + ELM_DATA_FOOTER,
'Descr': 'UNK_3B00',
'Response': PA(''),
},
'UNK_3B03': {
'Request': '^3B03' + ELM_DATA_FOOTER,
'Descr': 'UNK_3B03',
'Response': PA(''),
},
# ----------------------------------------------------------------------
# UDS commands used by MT05
'UDS_START_COMM': {
'Request': '^81' + ELM_FOOTER,
'Descr': 'UDS Start Communication',
'Exec': 'self.set_sorted_obd_msg("mt05")',
'Response': PA('EF 8F')
},
'UDS_STOP_COMM': {
'Request': '^82' + ELM_FOOTER,
'Descr': 'UDS Stop Communication',
'Exec': 'self.set_sorted_obd_msg("default")',
'Response': PA('')
},
},
# --------------------------------------------------------------------------
# Pids of a Toyota Auris Hybrid car (ISO 15765-4 CAN 11 bit ID 500 kbaud protocol)
'car': {
# AT Commands
'ELM_DESCR': { # use AT_DESCR to replace the standard behaviour
'Request': '^AT@1' + ELM_FOOTER,
'Descr': 'Device description',
'Header': ECU_ADDR_E,
'Response': [
ST('? '),
ST('OBDII to RS232 Interpreter ')
]
},
'ELM_ID': {
'Request': '^AT@2' + ELM_FOOTER,
'Descr': 'Device identifier',
'Header': ECU_ADDR_E,
'Response': ST('? ')
},
'ELM_VOLTAGE': {
'Request': '^ATRV' + ELM_FOOTER,
'Descr': 'Voltage detected by OBD-II adapter',
'Header': ECU_ADDR_E,
'Response': ST('14.7V ')
# 14.7 volt
},
# OBD Commands
# ------------------------------------------------------------
# MODE 01 - returns values for sensors characterised by PID - Sending diagnostic data (PID data monitor/on-board system readiness test)
'PIDS_A': {
'Request': '^0100' + ELM_FOOTER,
'Descr': 'Supported PIDs [01-20]',
'Header': ECU_ADDR_E,
'Response': HD(ECU_R_ADDR_E) + SZ('06') + DT('41 00 BE 3F A8 13')
},
'STATUS': {
'Request': '^0101' + ELM_FOOTER,
'Descr': 'Status since DTCs cleared',
'Header': ECU_ADDR_E,
'Response': HD(ECU_R_ADDR_E) + SZ('06') + DT('41 01 00 07 A1 00')
},
'FUEL_STATUS': {
'Request': '^0103' + ELM_FOOTER,
'Descr': 'Fuel System Status',
'Header': ECU_ADDR_E,
'Response': [
HD(ECU_R_ADDR_E) + SZ('04') + DT('41 03 00 00'),
HD(ECU_R_ADDR_E) + SZ('04') + DT('41 03 04 00'),
HD(ECU_R_ADDR_E) + SZ('04') + DT('41 03 02 00')
]
},
'ENGINE_LOAD': {
'Request': '^0104' + ELM_FOOTER,
'Descr': 'Calculated Engine Load',
'Header': ECU_ADDR_E,
'Response': [
HD(ECU_R_ADDR_E) + SZ('03') + DT('41 04 FF'),
HD(ECU_R_ADDR_E) + SZ('03') + DT('41 04 57'),
HD(ECU_R_ADDR_E) + SZ('03') + DT('41 04 96'),