selfdrive/car/ecu_addrs: prefix internal functions with underscore (#32980)
underscore prefix old-commit-hash: c0739cd9ee41ccd372bd8cd816c44dfce4e3a8a2
This commit is contained in:
@@ -10,7 +10,7 @@ from openpilot.selfdrive.pandad import can_list_to_can_capnp
|
|||||||
from openpilot.common.swaglog import cloudlog
|
from openpilot.common.swaglog import cloudlog
|
||||||
|
|
||||||
|
|
||||||
def make_tester_present_msg(addr, bus, subaddr=None):
|
def _make_tester_present_msg(addr, bus, subaddr=None):
|
||||||
dat = [0x02, SERVICE_TYPE.TESTER_PRESENT, 0x0]
|
dat = [0x02, SERVICE_TYPE.TESTER_PRESENT, 0x0]
|
||||||
if subaddr is not None:
|
if subaddr is not None:
|
||||||
dat.insert(0, subaddr)
|
dat.insert(0, subaddr)
|
||||||
@@ -19,7 +19,7 @@ def make_tester_present_msg(addr, bus, subaddr=None):
|
|||||||
return make_can_msg(addr, bytes(dat), bus)
|
return make_can_msg(addr, bytes(dat), bus)
|
||||||
|
|
||||||
|
|
||||||
def is_tester_present_response(msg: capnp.lib.capnp._DynamicStructReader, subaddr: int = None) -> bool:
|
def _is_tester_present_response(msg: capnp.lib.capnp._DynamicStructReader, subaddr: int = None) -> bool:
|
||||||
# ISO-TP messages are always padded to 8 bytes
|
# ISO-TP messages are always padded to 8 bytes
|
||||||
# tester present response is always a single frame
|
# tester present response is always a single frame
|
||||||
dat_offset = 1 if subaddr is not None else 0
|
dat_offset = 1 if subaddr is not None else 0
|
||||||
@@ -33,7 +33,7 @@ def is_tester_present_response(msg: capnp.lib.capnp._DynamicStructReader, subadd
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_all_ecu_addrs(logcan: messaging.SubSocket, sendcan: messaging.PubSocket, bus: int, timeout: float = 1, debug: bool = True) -> set[EcuAddrBusType]:
|
def _get_all_ecu_addrs(logcan: messaging.SubSocket, sendcan: messaging.PubSocket, bus: int, timeout: float = 1, debug: bool = True) -> set[EcuAddrBusType]:
|
||||||
addr_list = [0x700 + i for i in range(256)] + [0x18da00f1 + (i << 8) for i in range(256)]
|
addr_list = [0x700 + i for i in range(256)] + [0x18da00f1 + (i << 8) for i in range(256)]
|
||||||
queries: set[EcuAddrBusType] = {(addr, None, bus) for addr in addr_list}
|
queries: set[EcuAddrBusType] = {(addr, None, bus) for addr in addr_list}
|
||||||
responses = queries
|
responses = queries
|
||||||
@@ -44,7 +44,7 @@ def get_ecu_addrs(logcan: messaging.SubSocket, sendcan: messaging.PubSocket, que
|
|||||||
responses: set[EcuAddrBusType], timeout: float = 1, debug: bool = False) -> set[EcuAddrBusType]:
|
responses: set[EcuAddrBusType], timeout: float = 1, debug: bool = False) -> set[EcuAddrBusType]:
|
||||||
ecu_responses: set[EcuAddrBusType] = set() # set((addr, subaddr, bus),)
|
ecu_responses: set[EcuAddrBusType] = set() # set((addr, subaddr, bus),)
|
||||||
try:
|
try:
|
||||||
msgs = [make_tester_present_msg(addr, bus, subaddr) for addr, subaddr, bus in queries]
|
msgs = [_make_tester_present_msg(addr, bus, subaddr) for addr, subaddr, bus in queries]
|
||||||
|
|
||||||
messaging.drain_sock_raw(logcan)
|
messaging.drain_sock_raw(logcan)
|
||||||
sendcan.send(can_list_to_can_capnp(msgs, msgtype='sendcan'))
|
sendcan.send(can_list_to_can_capnp(msgs, msgtype='sendcan'))
|
||||||
@@ -58,7 +58,7 @@ def get_ecu_addrs(logcan: messaging.SubSocket, sendcan: messaging.PubSocket, que
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
subaddr = None if (msg.address, None, msg.src) in responses else msg.dat[0]
|
subaddr = None if (msg.address, None, msg.src) in responses else msg.dat[0]
|
||||||
if (msg.address, subaddr, msg.src) in responses and is_tester_present_response(msg, subaddr):
|
if (msg.address, subaddr, msg.src) in responses and _is_tester_present_response(msg, subaddr):
|
||||||
if debug:
|
if debug:
|
||||||
print(f"CAN-RX: {hex(msg.address)} - 0x{bytes.hex(msg.dat)}")
|
print(f"CAN-RX: {hex(msg.address)} - 0x{bytes.hex(msg.dat)}")
|
||||||
if (msg.address, subaddr, msg.src) in ecu_responses:
|
if (msg.address, subaddr, msg.src) in ecu_responses:
|
||||||
@@ -94,7 +94,7 @@ if __name__ == "__main__":
|
|||||||
set_obd_multiplexing(params, not args.no_obd)
|
set_obd_multiplexing(params, not args.no_obd)
|
||||||
|
|
||||||
print("Getting ECU addresses ...")
|
print("Getting ECU addresses ...")
|
||||||
ecu_addrs = get_all_ecu_addrs(logcan, sendcan, args.bus, args.timeout, debug=args.debug)
|
ecu_addrs = _get_all_ecu_addrs(logcan, sendcan, args.bus, args.timeout, debug=args.debug)
|
||||||
|
|
||||||
print()
|
print()
|
||||||
print("Found ECUs on rx addresses:")
|
print("Found ECUs on rx addresses:")
|
||||||
|
|||||||
Reference in New Issue
Block a user