Debian Codegraph @

test/contrib/automotive/obd/obd.uts

raw
1 % Regression tests for the OBD layer
2
3 # More information at http://www.secdev.org/projects/UTscapy/
4
5
6 ############
7 ############
8
9 + Basic operations
10
11 = Load module
12 load_contrib("automotive.obd.obd", globals_dict=globals())
13
14 = Check if positive response answers
15
16 req = OBD(b'\x01\x2f')
17 res = OBD(b'\x41\x2f\x1a')
18 assert res.answers(req)
19
20
21 = Check hashret
22
23 assert req.hashret() == res.hashret()
24
25 = Check if negative response answers
26
27 req = OBD(b'\x01\x2f')
28 res = OBD(b'\x7f\x01\x11')
29 assert res.answers(req)
30
31 = Check if negative response request_correctly_received_response_pending answers not
32
33 req = OBD(b'\x01\x2f')
34 res = OBD(b'\x7f\x01\x78')
35 assert not res.answers(req)
36
37 = Check if negative response request_correctly_received_response_pending answers
38
39 conf.contribs['OBD']['treat-response-pending-as-answer'] = True
40
41 req = OBD(b'\x01\x2f')
42 res = OBD(b'\x7f\x01\x78')
43 assert res.answers(req)
44
45
46 = Check hashret
47
48 assert req.hashret() == res.hashret()
49
50
51 = Check hashret for Service 0x40
52
53 req = OBD(b'\x40')
54 res = OBD(b'\x7F\x40\x11')
55 assert req.hashret() == res.hashret()
56 assert res.answers(req)
57
58
59 = Check hashret for Service 0x51
60
61 req = OBD(b'\x51')
62 res = OBD(b'\x7F\x51\x11')
63 assert req.hashret() == res.hashret()
64 assert res.answers(req)
65
66
67 = Check dissecting a request for Service 01 PID 00
68
69 p = OBD(b'\x01\x00')
70 assert p.service == 0x01
71 assert p.pid[0] == 0x00
72
73
74 = Check dissecting a request for Service 01 PID 75
75
76 p = OBD(b'\x01\x75')
77 assert p.service == 0x01
78 assert p.pid[0] == 0x75
79
80
81 = Check dissecting a request for Service 01 PID 78
82
83
84 p = OBD(b'\x01\x78')
85 assert p.service == 0x01
86 assert p.pid[0] == 0x78
87
88
89 = Check dissecting a request for Service 01 PID 7F
90
91 p = OBD(b'\x01\x7F')
92 assert p.service == 0x01
93 assert p.pid[0] == 0x7F
94
95
96 = Check dissecting a request for Service 01 PID 89
97
98 p = OBD(b'\x01\x89')
99 assert p.service == 0x01
100 assert p.pid[0] == 0x89
101
102
103 = Check dissecting a request for Service 02 PID 00
104
105 p = OBD(b'\x02\x00\x01')
106 assert p.service == 0x02
107 assert p.requests[0].pid == 0x00
108 assert p.requests[0].frame_no == 0x01
109
110
111 = Check dissecting a request for Service 02 PID 75
112
113 p = OBD(b'\x02\x75\x01')
114 assert p.service == 0x02
115 assert p.requests[0].pid == 0x75
116 assert p.requests[0].frame_no == 0x01
117
118
119 = Check dissecting a request for Service 02 PID 78
120
121 p = OBD(b'\x02\x78\x01')
122 assert p.service == 0x02
123 assert p.requests[0].pid == 0x78
124 assert p.requests[0].frame_no == 0x01
125
126
127 = Check dissecting a request for Service 02 PID 7F
128
129 p = OBD(b'\x02\x7F\x01')
130 assert p.service == 0x02
131 assert p.requests[0].pid == 0x7F
132 assert p.requests[0].frame_no == 0x01
133
134
135 = Check dissecting a request for Service 02 PID 89
136
137 p = OBD(b'\x02\x89\x01')
138 assert p.service == 0x02
139 assert p.requests[0].pid == 0x89
140 assert p.requests[0].frame_no == 0x01
141
142
143 = Check dissecting a request for Service 03
144
145 p = OBD(b'\x03')
146 assert p.service == 0x03
147
148
149 = Check dissecting a request for Service 06
150
151 p = OBD(b'\x06\x01')
152 assert p.service == 0x06
153 assert p.mid[0] == 0x01
154
155
156 = Check dissecting a request for Service 06 MID 00
157
158 p = OBD(b'\x06\x00')
159 assert p.service == 0x06
160 assert p.mid[0] == 0x00
161
162
163 = Check dissecting a request for Service 06 MID 00,01,02,03,04
164
165 p = OBD(b'\x06\x00\x01\x02\x03\x04')
166 assert p.service == 0x06
167 assert p.mid[0] == 0x00
168 assert p.mid[1] == 0x01
169 assert p.mid[2] == 0x02
170 assert p.mid[3] == 0x03
171 assert p.mid[4] == 0x04
172
173
174 = Check dissecting a response for Service 06 MID 00
175
176 r = OBD(b'\x06\x00')
177 p = OBD(b'\x46\x00\x00\x00\x00\x00')
178 assert p.service == 0x46
179 assert p.data_records[0].mid == 0x00
180 assert p.data_records[0].supported_mids == ""
181 assert p.answers(r)
182
183 = Check dissecting a response for Service 06 MID 00 and MID 20
184
185 r = OBD(b'\x06\x20\x00')
186 p = OBD(b'\x46\x00\x01\x02\x03\x04\x20\x01\x02\x03\x04')
187 assert p.service == 0x46
188 assert p.data_records[0].mid == 0x00
189 assert p.data_records[0].supported_mids == "MID1E+MID18+MID17+MID0F+MID08"
190 assert p.data_records[1].mid == 0x20
191 assert p.data_records[1].supported_mids == "MID3E+MID38+MID37+MID2F+MID28"
192 assert p.answers(r)
193 r = OBD(b'\x06\x20\x00\x40\x60')
194 assert p.answers(r)
195 r = OBD(b'\x06\x20')
196 assert not p.answers(r)
197
198
199 = Check dissecting a response for Service 06 MID 00, 20, 40, 60, 80, A0
200
201 p = OBD(b'\x46\x00\x01\x02\x03\x04\x20\x01\x02\x03\x04\x40\x01\x02\x03\x04\x60\x01\x02\x03\x04\x80\x01\x02\x03\x04\xA0\x01\x02\x03\x04')
202 assert p.service == 0x46
203 assert p.data_records[0].mid == 0x00
204 assert p.data_records[0].supported_mids == "MID1E+MID18+MID17+MID0F+MID08"
205 assert p.data_records[1].mid == 0x20
206 assert p.data_records[1].supported_mids == "MID3E+MID38+MID37+MID2F+MID28"
207 assert p.data_records[2].mid == 0x40
208 assert p.data_records[2].supported_mids == "MID5E+MID58+MID57+MID4F+MID48"
209 assert p.data_records[3].mid == 0x60
210 assert p.data_records[3].supported_mids == "MID7E+MID78+MID77+MID6F+MID68"
211 assert p.data_records[4].mid == 0x80
212 assert p.data_records[4].supported_mids == "MID9E+MID98+MID97+MID8F+MID88"
213 assert p.data_records[5].mid == 0xA0
214 assert p.data_records[5].supported_mids == "MIDBE+MIDB8+MIDB7+MIDAF+MIDA8"
215 assert len(p.data_records) == 6
216 r = OBD(b'\x06\x00\x20\x40\x60\x80\xA0')
217 assert p.answers(r)
218
219 = Check dissecting a response for Service 06 MID 01
220
221 p = OBD(b'\x46\x01\x01\x0A\x0B\xB0\x0B\xB0\x0B\xB0\x01\x05\x10\x00\x48\x00\x00\x00\x64\x01\x85\x24\x00\x96\x00\x4B\xFF\xFF')
222 assert p.service == 0x46
223 assert p.data_records[0].mid == 0x01
224 assert p.data_records[0].standardized_test_id == 1
225 assert p.data_records[0].unit_and_scaling_id == 10
226 assert p.data_records[0].test_value == 365.024
227 assert p.data_records[0].min_limit == 365.024
228 assert p.data_records[0].max_limit == 365.024
229 assert "Voltage" in p.data_records[0].__repr__()
230 assert "365.024 mV" in p.data_records[0].__repr__()
231 assert p.data_records[1].mid == 0x01
232 assert p.data_records[1].standardized_test_id == 5
233 assert p.data_records[1].unit_and_scaling_id == 16
234 assert p.data_records[1].test_value == 72
235 assert p.data_records[1].min_limit == 0
236 assert p.data_records[1].max_limit == 100
237 assert "Time" in p.data_records[1].__repr__()
238 assert "72 ms" in p.data_records[1].__repr__()
239 assert p.data_records[2].mid == 0x01
240 assert p.data_records[2].standardized_test_id == 0x85
241 assert p.data_records[2].unit_and_scaling_id == 0x24
242 assert p.data_records[2].test_value == 150
243 assert p.data_records[2].min_limit == 75
244 assert p.data_records[2].max_limit == 65535
245 assert "Counts" in p.data_records[2].__repr__()
246 assert "150 counts" in p.data_records[2].__repr__()
247 assert len(p.data_records) == 3
248 r = OBD(b'\x06\x01')
249 assert p.answers(r)
250 r = OBD(b'\x06\x01\x01\x01')
251 assert p.answers(r)
252 r = OBD(b'\x06\x01\x02')
253 assert p.answers(r)
254
255
256 = Check dissecting a response for Service 06 MID 21
257
258 p = OBD(b'\x46\x21\x87\x2F\x00\x00\x00\x00\x00\x00')
259 p.show()
260 assert p.service == 0x46
261 assert p.data_records[0].mid == 0x21
262 assert p.data_records[0].standardized_test_id == 135
263 assert p.data_records[0].unit_and_scaling_id == 0x2F
264 assert p.data_records[0].test_value == 0
265 assert p.data_records[0].min_limit == 0
266 assert p.data_records[0].max_limit == 0
267 assert "Percent" in p.data_records[0].__repr__()
268 assert "0 %" in p.data_records[0].__repr__()
269 assert len(p.data_records) == 1
270 r = OBD(b'\x06\x21')
271 assert p.answers(r)
272
273 = Check dissecting a request for Service 09 IID 00
274
275 p = OBD(b'\x09\x00')
276 assert p.service == 0x09
277 assert p.iid[0] == 0x00
278
279
280 = Check dissecting a request for Service 09 IID 02
281
282 p = OBD(b'\x09\x02')
283 assert p.service == 0x09
284 assert p.iid[0] == 0x02
285
286
287 = Check dissecting a request for Service 09 IID 04
288
289 p = OBD(b'\x09\x04')
290 assert p.service == 0x09
291 assert p.iid[0] == 0x04
292
293
294 = Check dissecting a request for Service 09 IID 00 and IID 02 and IID 04
295
296 p = OBD(b'\x09\x00\x02\x04')
297 assert p.service == 0x09
298 assert p.iid[0] == 0x00
299 assert p.iid[1] == 0x02
300 assert p.iid[2] == 0x04
301
302
303 = Check dissecting a request for Service 09 IID 0A
304
305 p = OBD(b'\x09\x0A')
306 assert p.service == 0x09
307 assert p.iid[0] == 0x0A
308
309
310 = Check dissecting a response for Service 01 PID 75
311
312 p = OBD(b'\x41\x75\x0a\x00\x11\x22\x33\x44\x55')
313 assert p.service == 0x41
314 assert p.data_records[0].pid == 0x75
315 assert p.data_records[0].reserved == 0
316 assert p.data_records[0].turbo_a_turbine_outlet_temperature_supported == 1
317 assert p.data_records[0].turbo_a_turbine_inlet_temperature_supported == 0
318 assert p.data_records[0].turbo_a_compressor_outlet_temperature_supported == 1
319 assert p.data_records[0].turbo_a_compressor_inlet_temperature_supported == 0
320 assert p.data_records[0].turbocharger_a_compressor_inlet_temperature == 0x00-40
321 assert p.data_records[0].turbocharger_a_compressor_outlet_temperature == 0x11-40
322 assert p.data_records[0].turbocharger_a_turbine_inlet_temperature == \
323 round((0x2233 * 0.1) - 40, 3)
324 assert p.data_records[0].turbocharger_a_turbine_outlet_temperature == \
325 round((0x4455 * 0.1) - 40, 3)
326
327 r = OBD(b'\x01\x75')
328 assert p.answers(r)
329
330
331 = Check dissecting a response for Service 01 PID 00 and PID 20
332
333 p = OBD(b'\x41\x00\xBF\xBF\xA8\x91\x20\x80\x00\x00\x00')
334 assert p.service == 0x41
335 assert p.data_records[0].pid == 0
336 assert p.data_records[0].supported_pids == "PID20+PID1C+PID19+PID15+PID13+PID11+PID10+PID0F+PID0E+PID0D+PID0C+PID0B+PID09+PID08+PID07+PID06+PID05+PID04+PID03+PID01"
337 assert p.data_records[1].pid == 0x20
338 assert p.data_records[1].supported_pids == "PID21"
339 assert len(p.data_records) == 2
340 r = OBD(b'\x01\x00\x20')
341 assert p.answers(r)
342
343
344 = Check dissecting a response for Service 01 PID 05,01,15,0C,03
345
346 p = OBD(b'\x41\x05\x6e\x01\x83\x33\xff\x63\x15\xa0\x78\x0c\x0a\x6b\x03\x02\x00')
347 p.show()
348 assert p.service == 0x41
349 assert p.data_records[0].pid == 5
350 assert p.data_records[0].data == 70.0
351 assert p.data_records[1].pid == 0x1
352 assert p.data_records[2].pid == 0x15
353 assert p.data_records[2].outputVoltage == 0.8
354 assert p.data_records[2].trim == -6.25
355 assert p.data_records[3].pid == 12
356 assert p.data_records[3].data == 666.75
357 assert p.data_records[4].pid == 3
358 assert p.data_records[4].fuel_system1 == 0x02
359 assert p.data_records[4].fuel_system2 == 0
360 assert len(p.data_records) == 5
361
362 r = OBD(b'\x01\x05\x01\x15\x0c\x03')
363 assert p.answers(r)
364 r = OBD(b'\x01\x05\x01\x15')
365 assert not p.answers(r)
366 r = OBD(b'\x01\x02')
367 assert not p.answers(r)
368
369
370 p = OBD(b'\x41\x00\xBF\xBF\xA8\x91\x20\x80\x00\x00\x00')
371 p.show()
372 assert p.service == 0x41
373 assert p.data_records[0].pid == 0
374 assert p.data_records[0].supported_pids == "PID20+PID1C+PID19+PID15+PID13+PID11+PID10+PID0F+PID0E+PID0D+PID0C+PID0B+PID09+PID08+PID07+PID06+PID05+PID04+PID03+PID01"
375 assert p.data_records[1].pid == 0x20
376 assert p.data_records[1].supported_pids == "PID21"
377 assert len(p.data_records) == 2
378 r = OBD(b'\x01\x00\x20')
379 assert p.answers(r)
380
381
382
383 = Check dissecting a response for Service 01 PID 78
384
385 p = OBD(b'\x41\x78ABCDEFGHI')
386 assert p.service == 0x41
387 assert p.data_records[0].pid == 0x78
388 assert p.data_records[0].reserved == 4
389 assert p.data_records[0].sensor1_supported == 1
390 assert p.data_records[0].sensor2_supported == 0
391 assert p.data_records[0].sensor3_supported == 0
392 assert p.data_records[0].sensor4_supported == 0
393 assert p.data_records[0].sensor1 == 1656.3
394 assert p.data_records[0].sensor2 == 1707.7
395 assert p.data_records[0].sensor3 == 1759.1
396 assert p.data_records[0].sensor4 == 1810.5
397 r = OBD(b'\x01\x78')
398 assert p.answers(r)
399
400
401 = Check dissecting a response for Service 01 PID 7F
402
403 p = OBD(b'\x41\x7F\x0a'
404 b'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF'
405 b'\x01\x02\x03\x04\x05\x06\x07\x08'
406 b'\x00\x11\x22\x33\x44\x55\x66\x77')
407 assert p.service == 0x41
408 assert p.data_records[0].pid == 0x7F
409 assert p.data_records[0].reserved == 1
410 assert p.data_records[0].total_with_pto_active_supported == 0
411 assert p.data_records[0].total_idle_supported == 1
412 assert p.data_records[0].total_supported == 0
413 assert p.data_records[0].total == 0xFFFFFFFFFFFFFFFF
414 assert p.data_records[0].total_idle == 0x0102030405060708
415 assert p.data_records[0].total_with_pto_active == 0x0011223344556677
416 r = OBD(b'\x01\x7f')
417 assert p.answers(r)
418
419
420
421 = Check dissecting a response for Service 01 PID 89
422
423 p = OBD(b'\x41\x89ABCDEFGHIKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOP')
424 assert p.service == 0x41
425 assert p.data_records[0].pid == 0x89
426 assert p.data_records[0].data == b'ABCDEFGHIKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOP'
427 r = OBD(b'\x01\x89')
428 assert p.answers(r)
429
430
431 = Check dissecting a response for Service 02 PID 75
432
433 p = OBD(b'\x42\x75\01\x0a\x00\x11\x22\x33\x44\x55')
434 assert p.service == 0x42
435 assert p.data_records[0].pid == 0x75
436 assert p.data_records[0].frame_no == 0x01
437 assert p.data_records[0].reserved == 0
438 assert p.data_records[0].turbo_a_turbine_outlet_temperature_supported == 1
439 assert p.data_records[0].turbo_a_turbine_inlet_temperature_supported == 0
440 assert p.data_records[0].turbo_a_compressor_outlet_temperature_supported == 1
441 assert p.data_records[0].turbo_a_compressor_inlet_temperature_supported == 0
442 assert p.data_records[0].turbocharger_a_compressor_inlet_temperature == 0x00 - 40
443 assert p.data_records[0].turbocharger_a_compressor_outlet_temperature == 0x11 - 40
444 assert p.data_records[0].turbocharger_a_turbine_inlet_temperature == \
445 round((0x2233 * 0.1) - 40, 3)
446 assert p.data_records[0].turbocharger_a_turbine_outlet_temperature == \
447 round((0x4455 * 0.1) - 40, 3)
448 r = OBD(b'\x02\x75\x00')
449 assert p.answers(r)
450
451
452 = Check dissecting a response for Service 02 PID 78
453
454 p = OBD(b'\x42\x78\x05ABCDEFGHI')
455 assert p.service == 0x42
456 assert p.data_records[0].pid == 0x78
457 assert p.data_records[0].frame_no == 0x05
458 assert p.data_records[0].reserved == 4
459 assert p.data_records[0].sensor1_supported == 1
460 assert p.data_records[0].sensor2_supported == 0
461 assert p.data_records[0].sensor3_supported == 0
462 assert p.data_records[0].sensor4_supported == 0
463 assert p.data_records[0].sensor1 == 1656.3
464 assert p.data_records[0].sensor2 == 1707.7
465 assert p.data_records[0].sensor3 == 1759.1
466 assert p.data_records[0].sensor4 == 1810.5
467
468 r = OBD(b'\x02\x78\x00')
469 assert p.answers(r)
470
471 = Check dissecting a response for Service 02 PID 7F
472
473 p = OBD(b'\x42\x7F\x01\x03'
474 b'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF'
475 b'\x01\x02\x03\x04\x05\x06\x07\x08'
476 b'\x00\x11\x22\x33\x44\x55\x66\x77')
477 assert p.service == 0x42
478 assert p.data_records[0].pid == 0x7F
479 assert p.data_records[0].frame_no == 0x01
480 assert p.data_records[0].reserved == 0
481 assert p.data_records[0].total_with_pto_active_supported == 0
482 assert p.data_records[0].total_idle_supported == 1
483 assert p.data_records[0].total_supported == 1
484 assert p.data_records[0].total == 0xFFFFFFFFFFFFFFFF
485 assert p.data_records[0].total_idle == 0x0102030405060708
486 assert p.data_records[0].total_with_pto_active == 0x0011223344556677
487
488 r = OBD(b'\x02\x7F\x00')
489 assert p.answers(r)
490
491
492 = Check dissecting a response for Service 02 PID 89
493
494 p = OBD(b'\x42\x89\x01ABCDEFGHIKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOP')
495 assert p.service == 0x42
496 assert p.data_records[0].pid == 0x89
497 assert p.data_records[0].frame_no == 0x01
498 assert p.data_records[0].data == b'ABCDEFGHIKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOP'
499
500 r = OBD(b'\x02\x89\x00')
501 assert p.answers(r)
502
503 = Check dissecting a response for Service 02 PID 0C, 05, 04
504
505 p = OBD(b'\x42\x0c\x00\x20\x80\x04\x00\x80\x05\x00\x28')
506 assert p.service == 0x42
507 assert p.data_records[0].pid == 0x0C
508 assert p.data_records[0].frame_no == 0x0
509 assert p.data_records[0].data == 2080
510 assert p.data_records[1].pid == 0x04
511 assert p.data_records[1].frame_no == 0x0
512 assert p.data_records[1].data == 50.196
513 assert p.data_records[2].pid == 0x05
514 assert p.data_records[2].frame_no == 0x0
515 assert p.data_records[2].data == 0.0
516
517 r = OBD(b'\x02\x0c\x00\x04\x00\x05\x00')
518 r.show()
519 assert p.answers(r)
520
521 = Check dissecting a response for Service 03
522
523 p = OBD(b'\x43\x06\x01\x43\x01\x96\x02\x34\x02\xcd\x03\x57\x0a\x24')
524 assert p.service == 0x43
525 assert p.count == 6
526 assert bytes(p.dtcs[0]) == b'\x01\x43'
527 assert bytes(p.dtcs[1]) == b'\x01\x96'
528 assert bytes(p.dtcs[2]) == b'\x02\x34'
529 assert bytes(p.dtcs[3]) == b'\x02\xcd'
530 assert bytes(p.dtcs[4]) == b'\x03\x57'
531 assert bytes(p.dtcs[5]) == b'\x0a\x24'
532
533 r = OBD(b'\x03')
534 assert p.answers(r)
535
536 = Check dissecting a response for Service 07
537
538 p = OBD(b'\x47\x06\x01\x43\x01\x96\x02\x34\x02\xcd\x03\x57\x0a\x24')
539 assert p.service == 0x47
540 assert p.count == 6
541 assert bytes(p.dtcs[0]) == b'\x01\x43'
542 assert bytes(p.dtcs[1]) == b'\x01\x96'
543 assert bytes(p.dtcs[2]) == b'\x02\x34'
544 assert bytes(p.dtcs[3]) == b'\x02\xcd'
545 assert bytes(p.dtcs[4]) == b'\x03\x57'
546 assert bytes(p.dtcs[5]) == b'\x0a\x24'
547
548 r = OBD(b'\x07')
549 assert p.answers(r)
550
551
552 = Check dissecting a response for Service 08 Tid 00
553
554 p = OBD(b'\x48\x00ABCD')
555 assert p.service == 0x48
556 assert p.data_records[0].tid == 0x00
557 assert p.data_records[0].supported_tids == "TID1E+TID1A+TID18+TID17+TID12+TID0F+TID0A+TID08+TID02"
558 r = OBD(b'\x08\x00')
559 assert p.answers(r)
560
561
562 = Check dissecting a response for Service 08 Tid 01
563
564 p = OBD(b'\x48\x01\x00\x00"\xffd')
565 assert p.service == 0x48
566 assert p.data_records[0].tid == 0x01
567 assert p.data_records[0].data_a == 0.0
568 assert p.data_records[0].data_b == 0.0
569 assert p.data_records[0].data_c == 0.17
570 assert p.data_records[0].data_d == 1.275
571 assert p.data_records[0].data_e == 0.5
572 r = OBD(b'\x08\x01')
573 assert p.answers(r)
574
575
576 = Check dissecting a response for Service 08 Tid 05
577
578 p = OBD(b'\x48\x05\x00\x00\x2b\xff\x7d')
579 assert p.service == 0x48
580 assert p.data_records[0].tid == 0x05
581 assert p.data_records[0].data_a == 0.0
582 assert p.data_records[0].data_b == 0.0
583 assert p.data_records[0].data_c == 0.172
584 assert p.data_records[0].data_d == 1.02
585 assert p.data_records[0].data_e == 0.5
586 r = OBD(b'\x08\x05')
587 assert p.answers(r)
588
589 = Check dissecting a response for Service 08 Tid 09
590
591 p = OBD(b'\x48\x09\x00\x00\x04\x1a\x0c')
592 assert p.service == 0x48
593 assert p.data_records[0].tid == 0x09
594 assert p.data_records[0].data_a == 0.0
595 assert p.data_records[0].data_b == 0.0
596 assert p.data_records[0].data_c == 0.16
597 assert p.data_records[0].data_d == 1.04
598 assert p.data_records[0].data_e == 0.48
599 r = OBD(b'\x08\x09')
600 assert p.answers(r)
601
602
603 = Check dissecting a response for Service 09 IID 00
604
605 p = OBD(b'\x49\x00ABCD')
606 assert p.service == 0x49
607 assert p.data_records[0].iid == 0x00
608 assert p.data_records[0].supported_iids == "IID1E+IID1A+IID18+IID17+IID12+IID0F+IID0A+IID08+IID02"
609 r = OBD(b'\x09\x00')
610 assert p.answers(r)
611
612 = Check dissecting a response for Service 09 IID 02 with one VIN
613
614 p = OBD(b'\x49\x02\x01W0L000051T2123456')
615 assert p.service == 0x49
616 assert p.data_records[0].iid == 0x02
617 assert p.data_records[0].count == 0x01
618 assert p.data_records[0].vehicle_identification_numbers[0] == b'W0L000051T2123456'
619 r = OBD(b'\x09\x02')
620 assert p.answers(r)
621
622 = Check dissecting a response for Service 09 IID 02 with two VINs
623
624 p = OBD(b'\x49\x02\x02W0L000051T2123456W0L000051T2123456')
625 assert p.service == 0x49
626 assert p.data_records[0].iid == 0x02
627 assert p.data_records[0].count == 0x02
628 assert p.data_records[0].vehicle_identification_numbers[0] == b'W0L000051T2123456'
629 assert p.data_records[0].vehicle_identification_numbers[1] == b'W0L000051T2123456'
630 r = OBD(b'\x09\x02')
631 assert p.answers(r)
632
633 = Check dissecting a response for Service 09 IID 04 with one CID
634
635 p = OBD(b'\x49\x04\x01ABCDEFGHIJKLMNOP')
636 assert p.service == 0x49
637 assert p.data_records[0].iid == 0x04
638 assert p.data_records[0].count == 0x01
639 assert p.data_records[0].calibration_identifications[0] == b'ABCDEFGHIJKLMNOP'
640 r = OBD(b'\x09\x04')
641 assert p.answers(r)
642
643 = Check dissecting a response for Service 09 IID 04 with two CID
644
645 p = OBD(b'\x49\x04\x02ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP')
646 assert p.service == 0x49
647 assert p.data_records[0].iid == 0x04
648 assert p.data_records[0].count == 0x02
649 assert p.data_records[0].calibration_identifications[0] == b'ABCDEFGHIJKLMNOP'
650 assert p.data_records[0].calibration_identifications[1] == b'ABCDEFGHIJKLMNOP'
651 r = OBD(b'\x09\x04')
652 assert p.answers(r)
653
654 = Check dissecting a response for Service 09 IID 06
655
656 p = OBD(b'\x49\x06\x02ABCDEFGH')
657 assert p.service == 0x49
658 assert p.data_records[0].iid == 0x06
659 assert p.data_records[0].count == 0x02
660 assert p.data_records[0].calibration_verification_numbers[0] == b'ABCD'
661 assert p.data_records[0].calibration_verification_numbers[1] == b'EFGH'
662 r = OBD(b'\x09\x06')
663 assert p.answers(r)
664
665 = Check dissecting a response for Service 09 IID 08
666
667 p = OBD(b'\x49\x08\x09\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\xFF\xFF')
668 assert p.service == 0x49
669 assert p.data_records[0].iid == 0x08
670 assert p.data_records[0].count == 0x09
671 assert p.data_records[0].data[0] == 1
672 assert p.data_records[0].data[1] == 2
673 assert p.data_records[0].data[2] == 3
674 assert p.data_records[0].data[3] == 4
675 assert p.data_records[0].data[4] == 5
676 assert p.data_records[0].data[5] == 6
677 assert p.data_records[0].data[6] == 7
678 assert p.data_records[0].data[7] == 8
679 assert p.data_records[0].data[8] == 65535
680 r = OBD(b'\x09\x08')
681 assert p.answers(r)
682
683 = Check dissecting a response for Service 09 IID 0A
684
685 p = OBD(b'\x49\x0A\x01ECM\x00-Engine Control\x00')
686 assert p.service == 0x49
687 assert p.data_records[0].iid == 0x0A
688 assert p.data_records[0].count == 0x01
689 assert p.data_records[0].ecu_names[0] == b'ECM\x00-Engine Control\x00'
690 r = OBD(b'\x09\x0a')
691 assert p.answers(r)
692
693 = Check dissecting a response for Service 09 IID 0B
694
695 p = OBD(b'\x49\x0B\x05\x00\x01\x00\x02\x00\x03\x00\x04\xFF\xFF')
696 assert p.service == 0x49
697 assert p.data_records[0].iid == 0x0B
698 assert p.data_records[0].count == 0x05
699 assert p.data_records[0].data[0] == 1
700 assert p.data_records[0].data[1] == 2
701 assert p.data_records[0].data[2] == 3
702 assert p.data_records[0].data[3] == 4
703 assert p.data_records[0].data[4] == 65535
704 r = OBD(b'\x09\x0b')
705 assert p.answers(r)
706
707 = Check dissecting a response for Service 09 IID 02 and IID 04
708
709 p = OBD(b'\x49\x02\x01ABCDEFGHIJKLMNOPQ\x04\x01ABCDEFGHIJKLMNOP')
710 assert p.service == 0x49
711 assert p.data_records[0].iid == 0x02
712 assert p.data_records[0].count == 0x01
713 assert p.data_records[0].vehicle_identification_numbers[0] == b'ABCDEFGHIJKLMNOPQ'
714 assert p.data_records[1].iid == 0x04
715 assert p.data_records[1].count == 0x01
716 assert p.data_records[1].calibration_identifications[0] == b'ABCDEFGHIJKLMNOP'
717 r = OBD(b'\x09\x02\x04')
718 assert p.answers(r)
719
720 b = bytes(p)
721 assert b[0:1] == b'\x49'
722 assert b[1:2] == b'\x02'
723 assert b[2:3] == b'\x01'
724 assert b[3:20] == b'ABCDEFGHIJKLMNOPQ'
725 assert b[20:21] == b'\x04'
726 assert b[21:22] == b'\x01'
727 assert b[22:] == b'ABCDEFGHIJKLMNOP'
728
729
730
731 = Check building a request for Service 01 PID 00
732
733 p = OBD()/OBD_S01(pid=0x00)
734 b = bytes(p)
735 assert b[0:1] == b'\x01'
736 assert b[1:2] == b'\x00'
737
738
739 = Check building a request for Service 01 PID 75
740
741 p = OBD()/OBD_S01(pid=0x75)
742 b = bytes(p)
743 assert b[0:1] == b'\x01'
744 assert b[1:2] == b'\x75'
745
746
747 = Check building a request for Service 01 PID 78
748
749 p = OBD()/OBD_S01(pid=0x78)
750 b = bytes(p)
751 assert b[0:1] == b'\x01'
752 assert b[1:2] == b'\x78'
753
754
755 = Check building a request for Service 01 PID 7F
756
757 p = OBD()/OBD_S01(pid=0x7F)
758 b = bytes(p)
759 assert b[0:1] == b'\x01'
760 assert b[1:2] == b'\x7F'
761
762
763 = Check building a request for Service 01 PID 89
764
765 p = OBD()/OBD_S01(pid=0x89)
766 b = bytes(p)
767 assert b[0:1] == b'\x01'
768 assert b[1:2] == b'\x89'
769
770
771 = Check building a request for Service 02 PID 00
772
773 p = OBD()/OBD_S02(requests=[OBD_S02_Record(pid=0x00, frame_no=0x01)])
774 b = bytes(p)
775 assert b[0:1] == b'\x02'
776 assert b[1:2] == b'\x00'
777 assert b[2:3] == b'\x01'
778
779
780 = Check building a request for Service 02 PID 75
781
782 p = OBD()/OBD_S02(requests=[OBD_S02_Record(pid=0x75, frame_no=0x01)])
783 b = bytes(p)
784 assert b[0:1] == b'\x02'
785 assert b[1:2] == b'\x75'
786 assert b[2:3] == b'\x01'
787
788
789 = Check building a request for Service 02 PID 78
790
791 p = OBD()/OBD_S02(requests=[OBD_S02_Record(pid=0x78, frame_no=0x01)])
792 b = bytes(p)
793 assert b[0:1] == b'\x02'
794 assert b[1:2] == b'\x78'
795 assert b[2:3] == b'\x01'
796
797
798 = Check building a request for Service 02 PID 7F
799
800 p = OBD()/OBD_S02(requests=[OBD_S02_Record(pid=0x7F, frame_no=0x01)])
801 b = bytes(p)
802 assert b[0:1] == b'\x02'
803 assert b[1:2] == b'\x7F'
804 assert b[2:3] == b'\x01'
805
806
807 = Check building a request for Service 02 PID 89
808
809 p = OBD()/OBD_S02(requests=[OBD_S02_Record(pid=0x89, frame_no=0x01)])
810 b = bytes(p)
811 assert b[0:1] == b'\x02'
812 assert b[1:2] == b'\x89'
813 assert b[2:3] == b'\x01'
814
815
816 = Check building a request for Service 03
817
818 p = OBD()/OBD_S03()
819 assert p.service == 0x03
820
821
822 = Check building a request for Service 02 PID 7F
823
824 p = OBD()/OBD_S02(requests=[OBD_S02_Record(pid=0x7F, frame_no=0x01)])
825 b = bytes(p)
826 assert b[0:1] == b'\x02'
827 assert b[1:2] == b'\x7F'
828 assert b[2:3] == b'\x01'
829
830
831 = Check building a request for Service 09 IID 00
832
833 p = OBD()/OBD_S09(iid=0x00)
834 b = bytes(p)
835 assert b[0:1] == b'\x09'
836 assert b[1:2] == b'\x00'
837
838
839 = Check building a request for Service 09 IID 02
840
841 p = OBD()/OBD_S09(iid=0x02)
842 b = bytes(p)
843 assert b[0:1] == b'\x09'
844 assert b[1:2] == b'\x02'
845
846
847 = Check building a request for Service 09 IID 04
848
849 p = OBD()/OBD_S09(iid=0x04)
850 b = bytes(p)
851 assert b[0:1] == b'\x09'
852 assert b[1:2] == b'\x04'
853
854
855 = Check building a request for Service 09 IID 00 and IID 02 and IID 04
856
857 p = OBD()/OBD_S09(iid=[0x00, 0x02, 0x04])
858 b = bytes(p)
859 assert b[0:1] == b'\x09'
860 assert b[1:2] == b'\x00'
861 assert b[2:3] == b'\x02'
862 assert b[3:4] == b'\x04'
863
864
865 = Check building a request for Service 09 IID 0A
866
867 p = OBD()/OBD_S09(iid=0x0A)
868 b = bytes(p)
869 assert b[0:1] == b'\x09'
870 assert b[1:2] == b'\x0A'
871
872
873 = Check building a response for Service 03
874
875 p = OBD()/OBD_S03_PR(dtcs=[OBD_DTC(), OBD_DTC(location='Powertrain', code1=1, code2=3, code3=0, code4=1)])
876 b = bytes(p)
877 assert b[0:1] == b'\x43'
878 assert b[1:2] == b'\x02'
879 assert b[2:4] == b'\x00\x00'
880 assert b[4:6] == b'\x13\x01'
881 r = OBD(b'\x03')
882 assert p.answers(r)
883
884
885 = Check building a default response for Service 03
886
887 p = OBD()/OBD_S03_PR()
888 b = bytes(p)
889 assert len(p) == 2
890 assert b[0:1] == b'\x43'
891 assert b[1:2] == b'\x00'
892 assert p.dtcs == []
893 r = OBD(b'\x03')
894 assert p.answers(r)
895
896 = Check building a response for Service 07
897
898 p = OBD()/OBD_S07_PR(dtcs=[OBD_DTC(location='Chassis', code1=0, code2=5, code3=1, code4=0)])
899 b = bytes(p)
900 assert b[0:1] == b'\x47'
901 assert b[1:2] == b'\x01'
902 assert b[2:4] == b'\x45\x10'
903 r = OBD(b'\x07')
904 assert p.answers(r)
905
906 = Check building a default response for Service 07
907
908 p = OBD()/OBD_S07_PR()
909 b = bytes(p)
910 assert len(p) == 2
911 assert b[0:1] == b'\x47'
912 assert b[1:2] == b'\x00'
913 assert p.dtcs == []
914 r = OBD(b'\x07')
915 assert p.answers(r)
916
917 = Check building a response for Service 0A
918
919 p = OBD()/OBD_S0A_PR(dtcs=[OBD_DTC(), OBD_DTC(location='Body', code1=1, code2=7, code3=8, code4=2), OBD_DTC()])
920 b = bytes(p)
921 assert b[0:1] == b'\x4A'
922 assert b[1:2] == b'\x03'
923 assert b[2:4] == b'\x00\x00'
924 assert b[4:6] == b'\x97\x82'
925 assert b[6:8] == b'\x00\x00'
926 r = OBD(b'\x0a')
927 assert p.answers(r)
928
929 = Check building a default response for Service 0A
930
931 p = OBD()/OBD_S0A_PR()
932 b = bytes(p)
933 assert len(p) == 2
934 assert b[0:1] == b'\x4A'
935 assert b[1:2] == b'\x00'
936 assert p.dtcs == []
937 r = OBD(b'\x0a')
938 assert p.answers(r)
939
940 = Check building a response for Service 09 IID 00
941
942 p = OBD(service=0x49)/OBD_S09_PR(data_records=OBD_S09_PR_Record()/OBD_IID00(b'ABCD'))
943 b = bytes(p)
944 assert b[0:1] == b'\x49'
945 assert b[1:2] == b'\x00'
946 assert b[2:] == b'ABCD'
947 r = OBD(b'\x09\x00')
948 assert p.answers(r)
949
950 = Check building a response for Service 09 IID 02 with one VIN
951
952 p = OBD(service=0x49)/OBD_S09_PR(data_records=OBD_S09_PR_Record()/OBD_IID02(vehicle_identification_numbers=b'W0L000051T2123456'))
953 b = bytes(p)
954 assert b[0:1] == b'\x49'
955 assert b[1:2] == b'\x02'
956 assert b[2:3] == b'\x01'
957 assert b[3:] == b'W0L000051T2123456'
958
959 r = OBD(b'\x09\x02')
960 assert p.answers(r)
961
962 = Check building a response for Service 09 IID 02 with two VINs
963
964 p = OBD(service=0x49)/OBD_S09_PR(data_records=OBD_S09_PR_Record()/OBD_IID02(vehicle_identification_numbers=[b'W0L000051T2123456', b'W0L000051T2123456']))
965 b = bytes(p)
966 assert b[0:1] == b'\x49'
967 assert b[1:2] == b'\x02'
968 assert b[2:3] == b'\x02'
969 assert b[3:20] == b'W0L000051T2123456'
970 assert b[20:] == b'W0L000051T2123456'
971
972 r = OBD(b'\x09\x02')
973 assert p.answers(r)
974
975
976 = Check building a response for Service 09 IID 04 with one CID
977
978 p = OBD(service=0x49)/OBD_S09_PR(data_records=OBD_S09_PR_Record()/OBD_IID04(calibration_identifications=b'ABCDEFGHIJKLMNOP'))
979 b = bytes(p)
980 assert b[0:1] == b'\x49'
981 assert b[1:2] == b'\x04'
982 assert b[2:3] == b'\x01'
983 assert b[3:] == b'ABCDEFGHIJKLMNOP'
984
985 r = OBD(b'\x09\x04')
986 assert p.answers(r)
987
988
989 = Check building a response for Service 09 IID 04 with two CID
990
991 p = OBD(service=0x49)/OBD_S09_PR(data_records=OBD_S09_PR_Record()/OBD_IID04(calibration_identifications=[b'ABCDEFGHIJKLMNOP', b'ABCDEFGHIJKLMNOP']))
992 b = bytes(p)
993 assert b[0:1] == b'\x49'
994 assert b[1:2] == b'\x04'
995 assert b[2:3] == b'\x02'
996 assert b[3:19] == b'ABCDEFGHIJKLMNOP'
997 assert b[19:] == b'ABCDEFGHIJKLMNOP'
998
999 r = OBD(b'\x09\x04')
1000 assert p.answers(r)
1001
1002
1003 = Check building a response for Service 09 IID 0A
1004
1005 p = OBD(service=0x49)/OBD_S09_PR(data_records=OBD_S09_PR_Record()/OBD_IID0A(ecu_names=b'ABCDEFGHIJKLMNOPQRST'))
1006 b = bytes(p)
1007 assert b[0:1] == b'\x49'
1008 assert b[1:2] == b'\x0A'
1009 assert b[2:3] == b'\x01'
1010 assert b[3:] == b'ABCDEFGHIJKLMNOPQRST'
1011
1012 r = OBD(b'\x09\x0a')
1013 assert p.answers(r)
1014
1015
1016 = Check building a response for Service 09 IID 02 and IID 04
1017
1018 p = OBD(service=0x49)/OBD_S09_PR(data_records=[
1019 OBD_S09_PR_Record()/OBD_IID02(vehicle_identification_numbers=b'ABCDEFGHIJKLMNOPQ'),
1020 OBD_S09_PR_Record()/OBD_IID04(calibration_identifications=b'ABCDEFGHIJKLMNOP')
1021 ])
1022 b = bytes(p)
1023 assert b[0:1] == b'\x49'
1024 assert b[1:2] == b'\x02'
1025 assert b[2:3] == b'\x01'
1026 assert b[3:20] == b'ABCDEFGHIJKLMNOPQ'
1027 assert b[20:21] == b'\x04'
1028 assert b[21:22] == b'\x01'
1029 assert b[22:] == b'ABCDEFGHIJKLMNOP'
1030
1031 r = OBD(b'\x09\x02\x04')
1032 assert p.answers(r)
1033