blob: fa65e95e4474c3a3779aa0a13377e6c52d75d335 [file] [log] [blame]
% Regression tests for the OBD layer
# More information at http://www.secdev.org/projects/UTscapy/
############
############
+ Basic operations
= Load module
load_contrib("automotive.obd.obd", globals_dict=globals())
= Check if positive response answers
req = OBD(b'\x01\x2f')
res = OBD(b'\x41\x2f\x1a')
assert res.answers(req)
= Check hashret
assert req.hashret() == res.hashret()
= Check if negative response answers
req = OBD(b'\x01\x2f')
res = OBD(b'\x7f\x01\x11')
assert res.answers(req)
= Check if negative response request_correctly_received_response_pending answers not
req = OBD(b'\x01\x2f')
res = OBD(b'\x7f\x01\x78')
assert not res.answers(req)
= Check if negative response request_correctly_received_response_pending answers
conf.contribs['OBD']['treat-response-pending-as-answer'] = True
req = OBD(b'\x01\x2f')
res = OBD(b'\x7f\x01\x78')
assert res.answers(req)
= Check hashret
assert req.hashret() == res.hashret()
= Check hashret for Service 0x40
req = OBD(b'\x40')
res = OBD(b'\x7F\x40\x11')
assert req.hashret() == res.hashret()
assert res.answers(req)
= Check hashret for Service 0x51
req = OBD(b'\x51')
res = OBD(b'\x7F\x51\x11')
assert req.hashret() == res.hashret()
assert res.answers(req)
= Check dissecting a request for Service 01 PID 00
p = OBD(b'\x01\x00')
assert p.service == 0x01
assert p.pid[0] == 0x00
= Check dissecting a request for Service 01 PID 75
p = OBD(b'\x01\x75')
assert p.service == 0x01
assert p.pid[0] == 0x75
= Check dissecting a request for Service 01 PID 78
p = OBD(b'\x01\x78')
assert p.service == 0x01
assert p.pid[0] == 0x78
= Check dissecting a request for Service 01 PID 7F
p = OBD(b'\x01\x7F')
assert p.service == 0x01
assert p.pid[0] == 0x7F
= Check dissecting a request for Service 01 PID 89
p = OBD(b'\x01\x89')
assert p.service == 0x01
assert p.pid[0] == 0x89
= Check dissecting a request for Service 02 PID 00
p = OBD(b'\x02\x00\x01')
assert p.service == 0x02
assert p.requests[0].pid == 0x00
assert p.requests[0].frame_no == 0x01
= Check dissecting a request for Service 02 PID 75
p = OBD(b'\x02\x75\x01')
assert p.service == 0x02
assert p.requests[0].pid == 0x75
assert p.requests[0].frame_no == 0x01
= Check dissecting a request for Service 02 PID 78
p = OBD(b'\x02\x78\x01')
assert p.service == 0x02
assert p.requests[0].pid == 0x78
assert p.requests[0].frame_no == 0x01
= Check dissecting a request for Service 02 PID 7F
p = OBD(b'\x02\x7F\x01')
assert p.service == 0x02
assert p.requests[0].pid == 0x7F
assert p.requests[0].frame_no == 0x01
= Check dissecting a request for Service 02 PID 89
p = OBD(b'\x02\x89\x01')
assert p.service == 0x02
assert p.requests[0].pid == 0x89
assert p.requests[0].frame_no == 0x01
= Check dissecting a request for Service 03
p = OBD(b'\x03')
assert p.service == 0x03
= Check dissecting a request for Service 06
p = OBD(b'\x06\x01')
assert p.service == 0x06
assert p.mid[0] == 0x01
= Check dissecting a request for Service 06 MID 00
p = OBD(b'\x06\x00')
assert p.service == 0x06
assert p.mid[0] == 0x00
= Check dissecting a request for Service 06 MID 00,01,02,03,04
p = OBD(b'\x06\x00\x01\x02\x03\x04')
assert p.service == 0x06
assert p.mid[0] == 0x00
assert p.mid[1] == 0x01
assert p.mid[2] == 0x02
assert p.mid[3] == 0x03
assert p.mid[4] == 0x04
= Check dissecting a response for Service 06 MID 00
r = OBD(b'\x06\x00')
p = OBD(b'\x46\x00\x00\x00\x00\x00')
assert p.service == 0x46
assert p.data_records[0].mid == 0x00
assert p.data_records[0].supported_mids == ""
assert p.answers(r)
= Check dissecting a response for Service 06 MID 00 and MID 20
r = OBD(b'\x06\x20\x00')
p = OBD(b'\x46\x00\x01\x02\x03\x04\x20\x01\x02\x03\x04')
assert p.service == 0x46
assert p.data_records[0].mid == 0x00
assert p.data_records[0].supported_mids == "MID1E+MID18+MID17+MID0F+MID08"
assert p.data_records[1].mid == 0x20
assert p.data_records[1].supported_mids == "MID3E+MID38+MID37+MID2F+MID28"
assert p.answers(r)
r = OBD(b'\x06\x20\x00\x40\x60')
assert p.answers(r)
r = OBD(b'\x06\x20')
assert not p.answers(r)
= Check dissecting a response for Service 06 MID 00, 20, 40, 60, 80, A0
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')
assert p.service == 0x46
assert p.data_records[0].mid == 0x00
assert p.data_records[0].supported_mids == "MID1E+MID18+MID17+MID0F+MID08"
assert p.data_records[1].mid == 0x20
assert p.data_records[1].supported_mids == "MID3E+MID38+MID37+MID2F+MID28"
assert p.data_records[2].mid == 0x40
assert p.data_records[2].supported_mids == "MID5E+MID58+MID57+MID4F+MID48"
assert p.data_records[3].mid == 0x60
assert p.data_records[3].supported_mids == "MID7E+MID78+MID77+MID6F+MID68"
assert p.data_records[4].mid == 0x80
assert p.data_records[4].supported_mids == "MID9E+MID98+MID97+MID8F+MID88"
assert p.data_records[5].mid == 0xA0
assert p.data_records[5].supported_mids == "MIDBE+MIDB8+MIDB7+MIDAF+MIDA8"
assert len(p.data_records) == 6
r = OBD(b'\x06\x00\x20\x40\x60\x80\xA0')
assert p.answers(r)
= Check dissecting a response for Service 06 MID 01
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')
assert p.service == 0x46
assert p.data_records[0].mid == 0x01
assert p.data_records[0].standardized_test_id == 1
assert p.data_records[0].unit_and_scaling_id == 10
assert p.data_records[0].test_value == 365.024
assert p.data_records[0].min_limit == 365.024
assert p.data_records[0].max_limit == 365.024
assert "Voltage" in p.data_records[0].__repr__()
assert "365.024 mV" in p.data_records[0].__repr__()
assert p.data_records[1].mid == 0x01
assert p.data_records[1].standardized_test_id == 5
assert p.data_records[1].unit_and_scaling_id == 16
assert p.data_records[1].test_value == 72
assert p.data_records[1].min_limit == 0
assert p.data_records[1].max_limit == 100
assert "Time" in p.data_records[1].__repr__()
assert "72 ms" in p.data_records[1].__repr__()
assert p.data_records[2].mid == 0x01
assert p.data_records[2].standardized_test_id == 0x85
assert p.data_records[2].unit_and_scaling_id == 0x24
assert p.data_records[2].test_value == 150
assert p.data_records[2].min_limit == 75
assert p.data_records[2].max_limit == 65535
assert "Counts" in p.data_records[2].__repr__()
assert "150 counts" in p.data_records[2].__repr__()
assert len(p.data_records) == 3
r = OBD(b'\x06\x01')
assert p.answers(r)
r = OBD(b'\x06\x01\x01\x01')
assert p.answers(r)
r = OBD(b'\x06\x01\x02')
assert p.answers(r)
= Check dissecting a response for Service 06 MID 21
p = OBD(b'\x46\x21\x87\x2F\x00\x00\x00\x00\x00\x00')
p.show()
assert p.service == 0x46
assert p.data_records[0].mid == 0x21
assert p.data_records[0].standardized_test_id == 135
assert p.data_records[0].unit_and_scaling_id == 0x2F
assert p.data_records[0].test_value == 0
assert p.data_records[0].min_limit == 0
assert p.data_records[0].max_limit == 0
assert "Percent" in p.data_records[0].__repr__()
assert "0 %" in p.data_records[0].__repr__()
assert len(p.data_records) == 1
r = OBD(b'\x06\x21')
assert p.answers(r)
= Check dissecting a request for Service 09 IID 00
p = OBD(b'\x09\x00')
assert p.service == 0x09
assert p.iid[0] == 0x00
= Check dissecting a request for Service 09 IID 02
p = OBD(b'\x09\x02')
assert p.service == 0x09
assert p.iid[0] == 0x02
= Check dissecting a request for Service 09 IID 04
p = OBD(b'\x09\x04')
assert p.service == 0x09
assert p.iid[0] == 0x04
= Check dissecting a request for Service 09 IID 00 and IID 02 and IID 04
p = OBD(b'\x09\x00\x02\x04')
assert p.service == 0x09
assert p.iid[0] == 0x00
assert p.iid[1] == 0x02
assert p.iid[2] == 0x04
= Check dissecting a request for Service 09 IID 0A
p = OBD(b'\x09\x0A')
assert p.service == 0x09
assert p.iid[0] == 0x0A
= Check dissecting a response for Service 01 PID 75
p = OBD(b'\x41\x75\x0a\x00\x11\x22\x33\x44\x55')
assert p.service == 0x41
assert p.data_records[0].pid == 0x75
assert p.data_records[0].reserved == 0
assert p.data_records[0].turbo_a_turbine_outlet_temperature_supported == 1
assert p.data_records[0].turbo_a_turbine_inlet_temperature_supported == 0
assert p.data_records[0].turbo_a_compressor_outlet_temperature_supported == 1
assert p.data_records[0].turbo_a_compressor_inlet_temperature_supported == 0
assert p.data_records[0].turbocharger_a_compressor_inlet_temperature == 0x00-40
assert p.data_records[0].turbocharger_a_compressor_outlet_temperature == 0x11-40
assert p.data_records[0].turbocharger_a_turbine_inlet_temperature == \
round((0x2233 * 0.1) - 40, 3)
assert p.data_records[0].turbocharger_a_turbine_outlet_temperature == \
round((0x4455 * 0.1) - 40, 3)
r = OBD(b'\x01\x75')
assert p.answers(r)
= Check dissecting a response for Service 01 PID 00 and PID 20
p = OBD(b'\x41\x00\xBF\xBF\xA8\x91\x20\x80\x00\x00\x00')
assert p.service == 0x41
assert p.data_records[0].pid == 0
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"
assert p.data_records[1].pid == 0x20
assert p.data_records[1].supported_pids == "PID21"
assert len(p.data_records) == 2
r = OBD(b'\x01\x00\x20')
assert p.answers(r)
= Check dissecting a response for Service 01 PID 05,01,15,0C,03
p = OBD(b'\x41\x05\x6e\x01\x83\x33\xff\x63\x15\xa0\x78\x0c\x0a\x6b\x03\x02\x00')
p.show()
assert p.service == 0x41
assert p.data_records[0].pid == 5
assert p.data_records[0].data == 70.0
assert p.data_records[1].pid == 0x1
assert p.data_records[2].pid == 0x15
assert p.data_records[2].outputVoltage == 0.8
assert p.data_records[2].trim == -6.25
assert p.data_records[3].pid == 12
assert p.data_records[3].data == 666.75
assert p.data_records[4].pid == 3
assert p.data_records[4].fuel_system1 == 0x02
assert p.data_records[4].fuel_system2 == 0
assert len(p.data_records) == 5
r = OBD(b'\x01\x05\x01\x15\x0c\x03')
assert p.answers(r)
r = OBD(b'\x01\x05\x01\x15')
assert not p.answers(r)
r = OBD(b'\x01\x02')
assert not p.answers(r)
p = OBD(b'\x41\x00\xBF\xBF\xA8\x91\x20\x80\x00\x00\x00')
p.show()
assert p.service == 0x41
assert p.data_records[0].pid == 0
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"
assert p.data_records[1].pid == 0x20
assert p.data_records[1].supported_pids == "PID21"
assert len(p.data_records) == 2
r = OBD(b'\x01\x00\x20')
assert p.answers(r)
= Check dissecting a response for Service 01 PID 78
p = OBD(b'\x41\x78ABCDEFGHI')
assert p.service == 0x41
assert p.data_records[0].pid == 0x78
assert p.data_records[0].reserved == 4
assert p.data_records[0].sensor1_supported == 1
assert p.data_records[0].sensor2_supported == 0
assert p.data_records[0].sensor3_supported == 0
assert p.data_records[0].sensor4_supported == 0
assert p.data_records[0].sensor1 == 1656.3
assert p.data_records[0].sensor2 == 1707.7
assert p.data_records[0].sensor3 == 1759.1
assert p.data_records[0].sensor4 == 1810.5
r = OBD(b'\x01\x78')
assert p.answers(r)
= Check dissecting a response for Service 01 PID 7F
p = OBD(b'\x41\x7F\x0a'
b'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF'
b'\x01\x02\x03\x04\x05\x06\x07\x08'
b'\x00\x11\x22\x33\x44\x55\x66\x77')
assert p.service == 0x41
assert p.data_records[0].pid == 0x7F
assert p.data_records[0].reserved == 1
assert p.data_records[0].total_with_pto_active_supported == 0
assert p.data_records[0].total_idle_supported == 1
assert p.data_records[0].total_supported == 0
assert p.data_records[0].total == 0xFFFFFFFFFFFFFFFF
assert p.data_records[0].total_idle == 0x0102030405060708
assert p.data_records[0].total_with_pto_active == 0x0011223344556677
r = OBD(b'\x01\x7f')
assert p.answers(r)
= Check dissecting a response for Service 01 PID 89
p = OBD(b'\x41\x89ABCDEFGHIKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOP')
assert p.service == 0x41
assert p.data_records[0].pid == 0x89
assert p.data_records[0].data == b'ABCDEFGHIKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOP'
r = OBD(b'\x01\x89')
assert p.answers(r)
= Check dissecting a response for Service 02 PID 75
p = OBD(b'\x42\x75\01\x0a\x00\x11\x22\x33\x44\x55')
assert p.service == 0x42
assert p.data_records[0].pid == 0x75
assert p.data_records[0].frame_no == 0x01
assert p.data_records[0].reserved == 0
assert p.data_records[0].turbo_a_turbine_outlet_temperature_supported == 1
assert p.data_records[0].turbo_a_turbine_inlet_temperature_supported == 0
assert p.data_records[0].turbo_a_compressor_outlet_temperature_supported == 1
assert p.data_records[0].turbo_a_compressor_inlet_temperature_supported == 0
assert p.data_records[0].turbocharger_a_compressor_inlet_temperature == 0x00 - 40
assert p.data_records[0].turbocharger_a_compressor_outlet_temperature == 0x11 - 40
assert p.data_records[0].turbocharger_a_turbine_inlet_temperature == \
round((0x2233 * 0.1) - 40, 3)
assert p.data_records[0].turbocharger_a_turbine_outlet_temperature == \
round((0x4455 * 0.1) - 40, 3)
r = OBD(b'\x02\x75\x00')
assert p.answers(r)
= Check dissecting a response for Service 02 PID 78
p = OBD(b'\x42\x78\x05ABCDEFGHI')
assert p.service == 0x42
assert p.data_records[0].pid == 0x78
assert p.data_records[0].frame_no == 0x05
assert p.data_records[0].reserved == 4
assert p.data_records[0].sensor1_supported == 1
assert p.data_records[0].sensor2_supported == 0
assert p.data_records[0].sensor3_supported == 0
assert p.data_records[0].sensor4_supported == 0
assert p.data_records[0].sensor1 == 1656.3
assert p.data_records[0].sensor2 == 1707.7
assert p.data_records[0].sensor3 == 1759.1
assert p.data_records[0].sensor4 == 1810.5
r = OBD(b'\x02\x78\x00')
assert p.answers(r)
= Check dissecting a response for Service 02 PID 7F
p = OBD(b'\x42\x7F\x01\x03'
b'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF'
b'\x01\x02\x03\x04\x05\x06\x07\x08'
b'\x00\x11\x22\x33\x44\x55\x66\x77')
assert p.service == 0x42
assert p.data_records[0].pid == 0x7F
assert p.data_records[0].frame_no == 0x01
assert p.data_records[0].reserved == 0
assert p.data_records[0].total_with_pto_active_supported == 0
assert p.data_records[0].total_idle_supported == 1
assert p.data_records[0].total_supported == 1
assert p.data_records[0].total == 0xFFFFFFFFFFFFFFFF
assert p.data_records[0].total_idle == 0x0102030405060708
assert p.data_records[0].total_with_pto_active == 0x0011223344556677
r = OBD(b'\x02\x7F\x00')
assert p.answers(r)
= Check dissecting a response for Service 02 PID 89
p = OBD(b'\x42\x89\x01ABCDEFGHIKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOP')
assert p.service == 0x42
assert p.data_records[0].pid == 0x89
assert p.data_records[0].frame_no == 0x01
assert p.data_records[0].data == b'ABCDEFGHIKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOP'
r = OBD(b'\x02\x89\x00')
assert p.answers(r)
= Check dissecting a response for Service 02 PID 0C, 05, 04
p = OBD(b'\x42\x0c\x00\x20\x80\x04\x00\x80\x05\x00\x28')
assert p.service == 0x42
assert p.data_records[0].pid == 0x0C
assert p.data_records[0].frame_no == 0x0
assert p.data_records[0].data == 2080
assert p.data_records[1].pid == 0x04
assert p.data_records[1].frame_no == 0x0
assert p.data_records[1].data == 50.196
assert p.data_records[2].pid == 0x05
assert p.data_records[2].frame_no == 0x0
assert p.data_records[2].data == 0.0
r = OBD(b'\x02\x0c\x00\x04\x00\x05\x00')
r.show()
assert p.answers(r)
= Check dissecting a response for Service 03
p = OBD(b'\x43\x06\x01\x43\x01\x96\x02\x34\x02\xcd\x03\x57\x0a\x24')
assert p.service == 0x43
assert p.count == 6
assert bytes(p.dtcs[0]) == b'\x01\x43'
assert bytes(p.dtcs[1]) == b'\x01\x96'
assert bytes(p.dtcs[2]) == b'\x02\x34'
assert bytes(p.dtcs[3]) == b'\x02\xcd'
assert bytes(p.dtcs[4]) == b'\x03\x57'
assert bytes(p.dtcs[5]) == b'\x0a\x24'
r = OBD(b'\x03')
assert p.answers(r)
= Check dissecting a response for Service 07
p = OBD(b'\x47\x06\x01\x43\x01\x96\x02\x34\x02\xcd\x03\x57\x0a\x24')
assert p.service == 0x47
assert p.count == 6
assert bytes(p.dtcs[0]) == b'\x01\x43'
assert bytes(p.dtcs[1]) == b'\x01\x96'
assert bytes(p.dtcs[2]) == b'\x02\x34'
assert bytes(p.dtcs[3]) == b'\x02\xcd'
assert bytes(p.dtcs[4]) == b'\x03\x57'
assert bytes(p.dtcs[5]) == b'\x0a\x24'
r = OBD(b'\x07')
assert p.answers(r)
= Check dissecting a response for Service 08 Tid 00
p = OBD(b'\x48\x00ABCD')
assert p.service == 0x48
assert p.data_records[0].tid == 0x00
assert p.data_records[0].supported_tids == "TID1E+TID1A+TID18+TID17+TID12+TID0F+TID0A+TID08+TID02"
r = OBD(b'\x08\x00')
assert p.answers(r)
= Check dissecting a response for Service 08 Tid 01
p = OBD(b'\x48\x01\x00\x00"\xffd')
assert p.service == 0x48
assert p.data_records[0].tid == 0x01
assert p.data_records[0].data_a == 0.0
assert p.data_records[0].data_b == 0.0
assert p.data_records[0].data_c == 0.17
assert p.data_records[0].data_d == 1.275
assert p.data_records[0].data_e == 0.5
r = OBD(b'\x08\x01')
assert p.answers(r)
= Check dissecting a response for Service 08 Tid 05
p = OBD(b'\x48\x05\x00\x00\x2b\xff\x7d')
assert p.service == 0x48
assert p.data_records[0].tid == 0x05
assert p.data_records[0].data_a == 0.0
assert p.data_records[0].data_b == 0.0
assert p.data_records[0].data_c == 0.172
assert p.data_records[0].data_d == 1.02
assert p.data_records[0].data_e == 0.5
r = OBD(b'\x08\x05')
assert p.answers(r)
= Check dissecting a response for Service 08 Tid 09
p = OBD(b'\x48\x09\x00\x00\x04\x1a\x0c')
assert p.service == 0x48
assert p.data_records[0].tid == 0x09
assert p.data_records[0].data_a == 0.0
assert p.data_records[0].data_b == 0.0
assert p.data_records[0].data_c == 0.16
assert p.data_records[0].data_d == 1.04
assert p.data_records[0].data_e == 0.48
r = OBD(b'\x08\x09')
assert p.answers(r)
= Check dissecting a response for Service 09 IID 00
p = OBD(b'\x49\x00ABCD')
assert p.service == 0x49
assert p.data_records[0].iid == 0x00
assert p.data_records[0].supported_iids == "IID1E+IID1A+IID18+IID17+IID12+IID0F+IID0A+IID08+IID02"
r = OBD(b'\x09\x00')
assert p.answers(r)
= Check dissecting a response for Service 09 IID 02 with one VIN
p = OBD(b'\x49\x02\x01W0L000051T2123456')
assert p.service == 0x49
assert p.data_records[0].iid == 0x02
assert p.data_records[0].count == 0x01
assert p.data_records[0].vehicle_identification_numbers[0] == b'W0L000051T2123456'
r = OBD(b'\x09\x02')
assert p.answers(r)
= Check dissecting a response for Service 09 IID 02 with two VINs
p = OBD(b'\x49\x02\x02W0L000051T2123456W0L000051T2123456')
assert p.service == 0x49
assert p.data_records[0].iid == 0x02
assert p.data_records[0].count == 0x02
assert p.data_records[0].vehicle_identification_numbers[0] == b'W0L000051T2123456'
assert p.data_records[0].vehicle_identification_numbers[1] == b'W0L000051T2123456'
r = OBD(b'\x09\x02')
assert p.answers(r)
= Check dissecting a response for Service 09 IID 04 with one CID
p = OBD(b'\x49\x04\x01ABCDEFGHIJKLMNOP')
assert p.service == 0x49
assert p.data_records[0].iid == 0x04
assert p.data_records[0].count == 0x01
assert p.data_records[0].calibration_identifications[0] == b'ABCDEFGHIJKLMNOP'
r = OBD(b'\x09\x04')
assert p.answers(r)
= Check dissecting a response for Service 09 IID 04 with two CID
p = OBD(b'\x49\x04\x02ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP')
assert p.service == 0x49
assert p.data_records[0].iid == 0x04
assert p.data_records[0].count == 0x02
assert p.data_records[0].calibration_identifications[0] == b'ABCDEFGHIJKLMNOP'
assert p.data_records[0].calibration_identifications[1] == b'ABCDEFGHIJKLMNOP'
r = OBD(b'\x09\x04')
assert p.answers(r)
= Check dissecting a response for Service 09 IID 06
p = OBD(b'\x49\x06\x02ABCDEFGH')
assert p.service == 0x49
assert p.data_records[0].iid == 0x06
assert p.data_records[0].count == 0x02
assert p.data_records[0].calibration_verification_numbers[0] == b'ABCD'
assert p.data_records[0].calibration_verification_numbers[1] == b'EFGH'
r = OBD(b'\x09\x06')
assert p.answers(r)
= Check dissecting a response for Service 09 IID 08
p = OBD(b'\x49\x08\x09\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\xFF\xFF')
assert p.service == 0x49
assert p.data_records[0].iid == 0x08
assert p.data_records[0].count == 0x09
assert p.data_records[0].data[0] == 1
assert p.data_records[0].data[1] == 2
assert p.data_records[0].data[2] == 3
assert p.data_records[0].data[3] == 4
assert p.data_records[0].data[4] == 5
assert p.data_records[0].data[5] == 6
assert p.data_records[0].data[6] == 7
assert p.data_records[0].data[7] == 8
assert p.data_records[0].data[8] == 65535
r = OBD(b'\x09\x08')
assert p.answers(r)
= Check dissecting a response for Service 09 IID 0A
p = OBD(b'\x49\x0A\x01ECM\x00-Engine Control\x00')
assert p.service == 0x49
assert p.data_records[0].iid == 0x0A
assert p.data_records[0].count == 0x01
assert p.data_records[0].ecu_names[0] == b'ECM\x00-Engine Control\x00'
r = OBD(b'\x09\x0a')
assert p.answers(r)
= Check dissecting a response for Service 09 IID 0B
p = OBD(b'\x49\x0B\x05\x00\x01\x00\x02\x00\x03\x00\x04\xFF\xFF')
assert p.service == 0x49
assert p.data_records[0].iid == 0x0B
assert p.data_records[0].count == 0x05
assert p.data_records[0].data[0] == 1
assert p.data_records[0].data[1] == 2
assert p.data_records[0].data[2] == 3
assert p.data_records[0].data[3] == 4
assert p.data_records[0].data[4] == 65535
r = OBD(b'\x09\x0b')
assert p.answers(r)
= Check dissecting a response for Service 09 IID 02 and IID 04
p = OBD(b'\x49\x02\x01ABCDEFGHIJKLMNOPQ\x04\x01ABCDEFGHIJKLMNOP')
assert p.service == 0x49
assert p.data_records[0].iid == 0x02
assert p.data_records[0].count == 0x01
assert p.data_records[0].vehicle_identification_numbers[0] == b'ABCDEFGHIJKLMNOPQ'
assert p.data_records[1].iid == 0x04
assert p.data_records[1].count == 0x01
assert p.data_records[1].calibration_identifications[0] == b'ABCDEFGHIJKLMNOP'
r = OBD(b'\x09\x02\x04')
assert p.answers(r)
b = bytes(p)
assert b[0:1] == b'\x49'
assert b[1:2] == b'\x02'
assert b[2:3] == b'\x01'
assert b[3:20] == b'ABCDEFGHIJKLMNOPQ'
assert b[20:21] == b'\x04'
assert b[21:22] == b'\x01'
assert b[22:] == b'ABCDEFGHIJKLMNOP'
= Check building a request for Service 01 PID 00
p = OBD()/OBD_S01(pid=0x00)
b = bytes(p)
assert b[0:1] == b'\x01'
assert b[1:2] == b'\x00'
= Check building a request for Service 01 PID 75
p = OBD()/OBD_S01(pid=0x75)
b = bytes(p)
assert b[0:1] == b'\x01'
assert b[1:2] == b'\x75'
= Check building a request for Service 01 PID 78
p = OBD()/OBD_S01(pid=0x78)
b = bytes(p)
assert b[0:1] == b'\x01'
assert b[1:2] == b'\x78'
= Check building a request for Service 01 PID 7F
p = OBD()/OBD_S01(pid=0x7F)
b = bytes(p)
assert b[0:1] == b'\x01'
assert b[1:2] == b'\x7F'
= Check building a request for Service 01 PID 89
p = OBD()/OBD_S01(pid=0x89)
b = bytes(p)
assert b[0:1] == b'\x01'
assert b[1:2] == b'\x89'
= Check building a request for Service 02 PID 00
p = OBD()/OBD_S02(requests=[OBD_S02_Record(pid=0x00, frame_no=0x01)])
b = bytes(p)
assert b[0:1] == b'\x02'
assert b[1:2] == b'\x00'
assert b[2:3] == b'\x01'
= Check building a request for Service 02 PID 75
p = OBD()/OBD_S02(requests=[OBD_S02_Record(pid=0x75, frame_no=0x01)])
b = bytes(p)
assert b[0:1] == b'\x02'
assert b[1:2] == b'\x75'
assert b[2:3] == b'\x01'
= Check building a request for Service 02 PID 78
p = OBD()/OBD_S02(requests=[OBD_S02_Record(pid=0x78, frame_no=0x01)])
b = bytes(p)
assert b[0:1] == b'\x02'
assert b[1:2] == b'\x78'
assert b[2:3] == b'\x01'
= Check building a request for Service 02 PID 7F
p = OBD()/OBD_S02(requests=[OBD_S02_Record(pid=0x7F, frame_no=0x01)])
b = bytes(p)
assert b[0:1] == b'\x02'
assert b[1:2] == b'\x7F'
assert b[2:3] == b'\x01'
= Check building a request for Service 02 PID 89
p = OBD()/OBD_S02(requests=[OBD_S02_Record(pid=0x89, frame_no=0x01)])
b = bytes(p)
assert b[0:1] == b'\x02'
assert b[1:2] == b'\x89'
assert b[2:3] == b'\x01'
= Check building a request for Service 03
p = OBD()/OBD_S03()
assert p.service == 0x03
= Check building a request for Service 02 PID 7F
p = OBD()/OBD_S02(requests=[OBD_S02_Record(pid=0x7F, frame_no=0x01)])
b = bytes(p)
assert b[0:1] == b'\x02'
assert b[1:2] == b'\x7F'
assert b[2:3] == b'\x01'
= Check building a request for Service 09 IID 00
p = OBD()/OBD_S09(iid=0x00)
b = bytes(p)
assert b[0:1] == b'\x09'
assert b[1:2] == b'\x00'
= Check building a request for Service 09 IID 02
p = OBD()/OBD_S09(iid=0x02)
b = bytes(p)
assert b[0:1] == b'\x09'
assert b[1:2] == b'\x02'
= Check building a request for Service 09 IID 04
p = OBD()/OBD_S09(iid=0x04)
b = bytes(p)
assert b[0:1] == b'\x09'
assert b[1:2] == b'\x04'
= Check building a request for Service 09 IID 00 and IID 02 and IID 04
p = OBD()/OBD_S09(iid=[0x00, 0x02, 0x04])
b = bytes(p)
assert b[0:1] == b'\x09'
assert b[1:2] == b'\x00'
assert b[2:3] == b'\x02'
assert b[3:4] == b'\x04'
= Check building a request for Service 09 IID 0A
p = OBD()/OBD_S09(iid=0x0A)
b = bytes(p)
assert b[0:1] == b'\x09'
assert b[1:2] == b'\x0A'
= Check building a response for Service 03
p = OBD()/OBD_S03_PR(dtcs=[OBD_DTC(), OBD_DTC(location='Powertrain', code1=1, code2=3, code3=0, code4=1)])
b = bytes(p)
assert b[0:1] == b'\x43'
assert b[1:2] == b'\x02'
assert b[2:4] == b'\x00\x00'
assert b[4:6] == b'\x13\x01'
r = OBD(b'\x03')
assert p.answers(r)
= Check building a default response for Service 03
p = OBD()/OBD_S03_PR()
b = bytes(p)
assert len(p) == 2
assert b[0:1] == b'\x43'
assert b[1:2] == b'\x00'
assert p.dtcs == []
r = OBD(b'\x03')
assert p.answers(r)
= Check building a response for Service 07
p = OBD()/OBD_S07_PR(dtcs=[OBD_DTC(location='Chassis', code1=0, code2=5, code3=1, code4=0)])
b = bytes(p)
assert b[0:1] == b'\x47'
assert b[1:2] == b'\x01'
assert b[2:4] == b'\x45\x10'
r = OBD(b'\x07')
assert p.answers(r)
= Check building a default response for Service 07
p = OBD()/OBD_S07_PR()
b = bytes(p)
assert len(p) == 2
assert b[0:1] == b'\x47'
assert b[1:2] == b'\x00'
assert p.dtcs == []
r = OBD(b'\x07')
assert p.answers(r)
= Check building a response for Service 0A
p = OBD()/OBD_S0A_PR(dtcs=[OBD_DTC(), OBD_DTC(location='Body', code1=1, code2=7, code3=8, code4=2), OBD_DTC()])
b = bytes(p)
assert b[0:1] == b'\x4A'
assert b[1:2] == b'\x03'
assert b[2:4] == b'\x00\x00'
assert b[4:6] == b'\x97\x82'
assert b[6:8] == b'\x00\x00'
r = OBD(b'\x0a')
assert p.answers(r)
= Check building a default response for Service 0A
p = OBD()/OBD_S0A_PR()
b = bytes(p)
assert len(p) == 2
assert b[0:1] == b'\x4A'
assert b[1:2] == b'\x00'
assert p.dtcs == []
r = OBD(b'\x0a')
assert p.answers(r)
= Check building a response for Service 09 IID 00
p = OBD(service=0x49)/OBD_S09_PR(data_records=OBD_S09_PR_Record()/OBD_IID00(b'ABCD'))
b = bytes(p)
assert b[0:1] == b'\x49'
assert b[1:2] == b'\x00'
assert b[2:] == b'ABCD'
r = OBD(b'\x09\x00')
assert p.answers(r)
= Check building a response for Service 09 IID 02 with one VIN
p = OBD(service=0x49)/OBD_S09_PR(data_records=OBD_S09_PR_Record()/OBD_IID02(vehicle_identification_numbers=b'W0L000051T2123456'))
b = bytes(p)
assert b[0:1] == b'\x49'
assert b[1:2] == b'\x02'
assert b[2:3] == b'\x01'
assert b[3:] == b'W0L000051T2123456'
r = OBD(b'\x09\x02')
assert p.answers(r)
= Check building a response for Service 09 IID 02 with two VINs
p = OBD(service=0x49)/OBD_S09_PR(data_records=OBD_S09_PR_Record()/OBD_IID02(vehicle_identification_numbers=[b'W0L000051T2123456', b'W0L000051T2123456']))
b = bytes(p)
assert b[0:1] == b'\x49'
assert b[1:2] == b'\x02'
assert b[2:3] == b'\x02'
assert b[3:20] == b'W0L000051T2123456'
assert b[20:] == b'W0L000051T2123456'
r = OBD(b'\x09\x02')
assert p.answers(r)
= Check building a response for Service 09 IID 04 with one CID
p = OBD(service=0x49)/OBD_S09_PR(data_records=OBD_S09_PR_Record()/OBD_IID04(calibration_identifications=b'ABCDEFGHIJKLMNOP'))
b = bytes(p)
assert b[0:1] == b'\x49'
assert b[1:2] == b'\x04'
assert b[2:3] == b'\x01'
assert b[3:] == b'ABCDEFGHIJKLMNOP'
r = OBD(b'\x09\x04')
assert p.answers(r)
= Check building a response for Service 09 IID 04 with two CID
p = OBD(service=0x49)/OBD_S09_PR(data_records=OBD_S09_PR_Record()/OBD_IID04(calibration_identifications=[b'ABCDEFGHIJKLMNOP', b'ABCDEFGHIJKLMNOP']))
b = bytes(p)
assert b[0:1] == b'\x49'
assert b[1:2] == b'\x04'
assert b[2:3] == b'\x02'
assert b[3:19] == b'ABCDEFGHIJKLMNOP'
assert b[19:] == b'ABCDEFGHIJKLMNOP'
r = OBD(b'\x09\x04')
assert p.answers(r)
= Check building a response for Service 09 IID 0A
p = OBD(service=0x49)/OBD_S09_PR(data_records=OBD_S09_PR_Record()/OBD_IID0A(ecu_names=b'ABCDEFGHIJKLMNOPQRST'))
b = bytes(p)
assert b[0:1] == b'\x49'
assert b[1:2] == b'\x0A'
assert b[2:3] == b'\x01'
assert b[3:] == b'ABCDEFGHIJKLMNOPQRST'
r = OBD(b'\x09\x0a')
assert p.answers(r)
= Check building a response for Service 09 IID 02 and IID 04
p = OBD(service=0x49)/OBD_S09_PR(data_records=[
OBD_S09_PR_Record()/OBD_IID02(vehicle_identification_numbers=b'ABCDEFGHIJKLMNOPQ'),
OBD_S09_PR_Record()/OBD_IID04(calibration_identifications=b'ABCDEFGHIJKLMNOP')
])
b = bytes(p)
assert b[0:1] == b'\x49'
assert b[1:2] == b'\x02'
assert b[2:3] == b'\x01'
assert b[3:20] == b'ABCDEFGHIJKLMNOPQ'
assert b[20:21] == b'\x04'
assert b[21:22] == b'\x01'
assert b[22:] == b'ABCDEFGHIJKLMNOP'
r = OBD(b'\x09\x02\x04')
assert p.answers(r)