Skip to content

Vehicle info

Information about a vehicle is acquired by the connector that is plugged into the vehicle. This information can be retrieved by using the methods defined in the vehicle info service.

Detected ECUs

The connector is able to detect the ECUs that are present in the vehicle. For each ECU, it determines how to establish communication. This includes identifying the OBD pins and identifiers used by the ECU, as well as the protocol it follows. If the detected ECUs are requested before the connector has completed the detection, a gRPC UNAVAILABLE error will be returned.

Below is a code snippet that uses the getEcuList call to retrieve the detected ECUs. It then uses that info to configure buses and set up communication with each ISO-TP ECU.

# Retrieve the detected ECUs (requires an authenticated openOBD session)
while True:
    try:
        ecu_list = openobd_session.get_ecu_list()   # type: EcuList
        break
    except OpenOBDException as e:
        if e.status == 14:  # UNAVAILABLE
            # The ECUs are still being detected, so wait a few seconds before trying again
            time.sleep(5)
        else:
            raise e

# Define a BusConfiguration for each detected ISO-TP ECU
bus_configs = {}    # type: dict[str, BusConfiguration]
for ecu in ecu_list.ecus:
    if ecu.WhichOneof("EcuType") == "isotp_ecu":
        can_bus = ecu.isotp_ecu.can_bus
        # Define a unique bus name under which to configure this bus
        bus_name = f"bus{can_bus.pin_plus}-{can_bus.pin_min}"
        if bus_name not in bus_configs:
            bus_configs[bus_name] = BusConfiguration(bus_name=bus_name, can_bus=can_bus)
# Configure the buses
bus_stream_handler = StreamHandler(openobd_session.configure_bus)
bus_stream_handler.send_and_close(bus_configs.values())

# Create an IsotpSocket for each detected ECU
sockets = []
for ecu in ecu_list.ecus:
    if ecu.WhichOneof("EcuType") == "isotp_ecu":
        can_bus = ecu.isotp_ecu.can_bus
        # Use the same bus name as when configuring the buses
        bus_name = f"bus{can_bus.pin_plus}-{can_bus.pin_min}"
        isotp_channel = IsotpChannel(
            bus_name=bus_name,
            request_id=ecu.isotp_ecu.request_id,
            response_id=ecu.isotp_ecu.response_id,
            extended_request_address=ecu.isotp_ecu.extended_request_address,
            extended_response_address=ecu.isotp_ecu.extended_response_address,
        )
        sockets.append(IsotpSocket(openobd_session, isotp_channel))