mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-30 02:52:04 +08:00
Add UDS VIN query (#24311)
* Switch to UDS VIN query * try both * fall back to obd old-commit-hash: 7d2ba9b0a43d6c7cfe463968b9fc0c2b6557b00b
This commit is contained in:
+17
-10
@@ -1,25 +1,32 @@
|
||||
#!/usr/bin/env python3
|
||||
import struct
|
||||
import traceback
|
||||
|
||||
import cereal.messaging as messaging
|
||||
import panda.python.uds as uds
|
||||
from panda.python.uds import FUNCTIONAL_ADDRS
|
||||
from selfdrive.car.isotp_parallel_query import IsoTpParallelQuery
|
||||
from selfdrive.swaglog import cloudlog
|
||||
|
||||
VIN_REQUEST = b'\x09\x02'
|
||||
VIN_RESPONSE = b'\x49\x02\x01'
|
||||
OBD_VIN_REQUEST = b'\x09\x02'
|
||||
OBD_VIN_RESPONSE = b'\x49\x02\x01'
|
||||
|
||||
UDS_VIN_REQUEST = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER]) + struct.pack("!H", uds.DATA_IDENTIFIER_TYPE.VIN)
|
||||
UDS_VIN_RESPONSE = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER + 0x40]) + struct.pack("!H", uds.DATA_IDENTIFIER_TYPE.VIN)
|
||||
|
||||
VIN_UNKNOWN = "0" * 17
|
||||
|
||||
|
||||
def get_vin(logcan, sendcan, bus, timeout=0.1, retry=5, debug=False):
|
||||
for i in range(retry):
|
||||
try:
|
||||
query = IsoTpParallelQuery(sendcan, logcan, bus, FUNCTIONAL_ADDRS, [VIN_REQUEST], [VIN_RESPONSE], functional_addr=True, debug=debug)
|
||||
for addr, vin in query.get_data(timeout).items():
|
||||
return addr[0], vin.decode()
|
||||
print(f"vin query retry ({i+1}) ...")
|
||||
except Exception:
|
||||
cloudlog.warning(f"VIN query exception: {traceback.format_exc()}")
|
||||
for request, response in ((UDS_VIN_REQUEST, UDS_VIN_RESPONSE), (OBD_VIN_REQUEST, OBD_VIN_RESPONSE)):
|
||||
for i in range(retry):
|
||||
try:
|
||||
query = IsoTpParallelQuery(sendcan, logcan, bus, FUNCTIONAL_ADDRS, [request, ], [response, ], functional_addr=True, debug=debug)
|
||||
for addr, vin in query.get_data(timeout).items():
|
||||
return addr[0], vin.decode()
|
||||
print(f"vin query retry ({i+1}) ...")
|
||||
except Exception:
|
||||
cloudlog.warning(f"VIN query exception: {traceback.format_exc()}")
|
||||
|
||||
return 0, VIN_UNKNOWN
|
||||
|
||||
|
||||
Reference in New Issue
Block a user