Skip to main content

autodoip

autodoip 是一个零依赖、纯 Python 实现的 DoIP (Diagnostics over IP) 传输层,严格遵循 ISO 13400 标准,适用于汽车 UDS (Unified Diagnostic Services) 诊断通信。

采用 Tester-as-Server 拓扑:Tester 监听单一端口,所有 ECU 主动连接至此端口,帧路由通过 DoIP 头中的逻辑地址完成。

特性

  • 完全符合 ISO 13400 帧格式(版本反码、Payload Type、地址校验)
  • 自动连接管理、空闲超时与断连自动重连
  • 重连成功后抛出 ReconnectionError,由上层决定是否重发(适配有状态诊断会话)
  • 支持多帧响应迭代(例如 0x7F … 0x78 延迟指示)
  • 线程安全的状态切换与收发
  • 零外部依赖,仅使用 Python 标准库

安装

pip install autodoip

要求 Python ≥ 3.14。

快速开始

from autodoip import Endpoint

# 创建端点:监听 192.168.10.1:13400,预定义两个 ECU
endpoint = Endpoint(
    ip="192.168.10.1",
    ecus={
        0x1301: ("192.168.10.10", 0),  # port=0 表示不校验端口
        0x1302: ("192.168.10.20", 13400),
    },
)

endpoint.start()  # 开始接受 ECU 连接

# 查看连接状态
print(endpoint.connections)
# {0x1301: ('192.168.10.10', 0, True), 0x1302: ('192.168.10.20', 13400, False)}

# 切换到已连接的 ECU 并发送诊断请求
endpoint.select(0x1301)
for resp in endpoint.conversation(bytes.fromhex("22FF00")):
    print(resp.hex(" "))

# 处理断连重连(适用于有状态诊断会话)
from autodoip import ReconnectionError

try:
    for resp in endpoint.conversation(bytes.fromhex("22FF00")):
        print(resp.hex(" "))
except ReconnectionError:
    # 连接已恢复,但 ECU 状态已重置(会话、安全访问等)
    # 上层需重新同步状态后重试
    pass

命令行工具

安装后可直接通过 python -m autodoip 发送单次诊断请求:

python -m autodoip \
    --ecu 0x1301 \
    --ecu-ip 192.168.10.10 \
    --payload 22FF00

所有参数说明可通过 --help 查看。

API 概览

类/函数 说明
Endpoint(ip, ecus, port=13400, tester=0x0E80, config=None) DoIP 端点,ipecus 必填
Endpoint.start() 启动监听,幂等;需重启则新建实例
Endpoint.select(addr) -> bool 切换当前 ECU;未连接或操作冲突时返回 False 且不改变选中
Endpoint.conversation(payload) -> Iterator[bytes] 发送 UDS 载荷,返回响应迭代器。断连自动重连:成功抛 ReconnectionError,失败抛 ConnectionError
Endpoint.current -> int | None 当前选中的 ECU 逻辑地址
Endpoint.connections -> dict {addr: (ip, port, connected), ...}
Config(...) 传输调优参数(见下方)
ProtocolError 帧校验失败时抛出的异常
ReconnectionError 断连重连成功后抛出,继承 ConnectionError。上层可据此重新同步 ECU 状态后重试

配置

from autodoip import Config, Endpoint

config = Config(
    accept_timeout=1.5,   # accept 超时 (秒)
    p6_timeout=0.05,      # 单次 recv 超时 (秒)
    p6_star_timeout=5.0,  # 整体接收窗口超时 (秒)
    listen_count=5,       # socket listen backlog
    version=0x02,         # DoIP 协议版本
    msg_type=0x8001,      # Payload Type
    byte_order="big",     # 字节序 ("big" / "little")
)

# 将配置传入 Endpoint
endpoint = Endpoint(
    ip="192.168.10.1",
    ecus={
        0x1301: ("192.168.10.10", 0),
        0x1302: ("192.168.10.20", 13400),
    },
    config=config,
)

许可证

MIT License

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autodoip-0.3.0.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autodoip-0.3.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file autodoip-0.3.0.tar.gz.

File metadata

  • Download URL: autodoip-0.3.0.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for autodoip-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a3050657d23a37ec46ea4b5c7d90a4ee6c3092e995e7c6f90272923d429650b0
MD5 8a67083c2988b647a6383ffccbb667da
BLAKE2b-256 80348a317bddf8731b3e1314da20d09e20b6d619341c821433d829324a0f5325

See more details on using hashes here.

File details

Details for the file autodoip-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: autodoip-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for autodoip-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 247ae4e9d76d09a7bbeb400708de0e4ea87e044221bc40fbbf7c88e8cc8676ad
MD5 77ce96a46b6d5f4134501f865ae71b17
BLAKE2b-256 459d3002a93206608140cae91f6f0babc948c62cd7d5889d33b296e4767788a6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

0.2.4

2 files

0.2.0

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page