udsonip.manager
Multi-ECU manager for handling multiple ECUs over a single DoIP connection.
- class udsonip.manager.DoIPManager(gateway_ip: str, client_ip: str | None = None, client_logical_address: int | None = None, protocol_version: int = 3, **kwargs)[source]
Bases:
objectA client for managing connections to multiple ECUs via a single DoIP gateway.
This class provides a high-level interface for managing multiple ECUs that are accessible through a single DoIP gateway. It handles the DoIP connection and allows switching between ECUs using a context manager.
Example
>>> from udsonip import DoIPManager >>> manager = DoIPManager('192.168.1.10') >>> manager.add_ecu('engine', 0x00E0) >>> manager.add_ecu('transmission', 0x00E1) >>> >>> with manager.ecu('engine') as ecu: ... vin = ecu.read_data_by_identifier(constants.UDS_DID_VIN) ... print(f"Engine VIN: {vin.data.decode()}")
- add_ecu(name: str, logical_address: int)[source]
Register an ECU in the manager.
- Parameters:
name – Friendly name for the ECU (e.g., ‘engine’, ‘transmission’)
logical_address – ECU logical address
Example
>>> manager.add_ecu('engine', 0x00E0) >>> manager.add_ecu('transmission', 0x00E1) >>> manager.add_ecu('gateway', 0x0001)
- ecu(name: str)[source]
Context manager for safe ECU communication.
- Parameters:
name – Name of the ECU to communicate with
- Yields:
UDS client configured for the specified ECU
Example
>>> with manager.ecu('engine') as ecu:
- … vin = ecu.read_data_by_identifier(constants.UDS_DID_VIN)
… print(f”Engine VIN: {vin.data.decode()}”)
- list_ecus() Dict[str, int][source]
Get a dictionary of all registered ECUs.
- Returns:
Dictionary mapping ECU names to logical addresses