代码
address, announcement = DoIPClient.await_vehicle_announcement()
logical_address = announcement.logical_address
ip, port = address
print(ip, port, logical_address)
效果
代码
address, announcement = DoIPClient.get_entity(ecu_ip_address=sIp, protocol_version=3, eid=None, vin=None)#请求ECU的车辆识别响应消息。
logical_address = announcement.logical_address
ip, port = address
sIp = ip
sLA = logical_address
效果
可以发出DOIP请求,之所以显示超时未等到回应
是因为,目标Port和实际上的诊断仪port不一致
为了实现指定Tester端口,避免随机端口,重写这个方法get_entity()
def get_entity(
cls, ecu_ip_address="255.255.255.255", protocol_version=0x02, eid=None, vin=None, local_port=8080
):
DoIPClient对象的创建
可见该类创建后,不会请求车辆识别(UDP),所以DoIPClient的对象创建要在车辆声明/车辆ID识别之后,使用获取到的LA+IP等进行TCP通信,创建DoIPClient后会自动进行TCP的三次握手,为了使用固定端口进行通信,这里对DoIPClient这个类进行了重写。
新增了client_port这个参数,注意port = 0表示使用随机端口。
DoIPClient执行TCP三次握手成功之后会调用路由激活!
封装后的自动连接函数
代码
try:
#Get the DoIP Entity Information
address, announcement = DoIPClient.get_entity(ecu_ip_address=sIp, protocol_version=3, eid=None, vin=None, local_port=cPrt)#请求ECU的车辆识别响应消息。
logical_address = announcement.logical_address
ip, port = address
sIp = ip
sLA = logical_address
#Creat DoIP TCP connection
doIPConn = DoIPClient(sIp, int(sLA), tcp_port=13400, udp_port=13400,activation_type=0, protocol_version=3,client_logical_address=int(cLA), client_port = int(cPrt),client_ip_address=cIp, use_secure=False,auto_reconnect_tcp=False)
except Exception as e:
window['-CONSOLE-'].update(e)
效果
上效果图,界面上有的功能都支持