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