jacobschaer / python-doipclient

Pure Python ISO 13400 Client
MIT License
151 stars 50 forks source link

Doesn't work Rouine Activation in some vehicles. #13

Closed Mike7Chu closed 2 years ago

Mike7Chu commented 2 years ago

I tried to connect to a vehicle as DoIP interface with this library. And It didn't work Rotine Activation at below code.

import udsoncan
from doipclient import DoIPClient
from doipclient.connectors import DoIPClientUDSConnector
from udsoncan.client import Client
from udsoncan.exceptions import *
from udsoncan.services import *

udsoncan.setup_logging()

ecu_ip = '192.168.11.1'
ecu_logical_address = 0x0E80

doip_client = DoIPClient(ecu_ip, ecu_logical_address) # This is doesn'work.
print('Success IP is %x',ecu_logical_address)
conn = DoIPClientUDSConnector(doip_client)
C:\ProgramData\Anaconda3\lib\site-packages\doipclient\client.py in __init__(self, ecu_ip_address, ecu_logical_address, tcp_port, udp_port, activation_type, protocol_version, client_logical_address, client_ip_address, use_secure, auto_reconnect_tcp)
    186             result = self.request_activation(self._activation_type, vm_specific=None, disable_retry=True)
    187             print('this is log')
--> 188             if result.response_code != RoutingActivationResponse.ResponseCode.Success:
    189                 raise ConnectionRefusedError(
    190                     f"Activation Request failed with code {result.response_code}"

ConnectionRefusedError: Activation Request failed with code 0

The issue show "ConnectionRefusedError: Activation Request failed with code 0". It means the header is wrong. The root cause is vm_specific=None. In ISO-13400-2, vm-specific is optional. But some vehicle have the specific, It need to vm_specific data. So I want to change vm_specific=ecu_vm_specific.

jacobschaer commented 2 years ago

Yeah, makes sense. If you want to PR something that's fine - should be easy enough.

As a workaround, there's no reason you need to let the constructor handle activation. My original intention was for more complicated situations like this you'd set activation_type = None, and then call request_activation() manually with any customization or preconditions already satisfied (for instance, if you need to toggle the physical activation line using some other API).

If you want the library to take care of it automatically (like for auto-reconnect), probably just add a constructor argument called something like

activation_type_vm_specific=None

Store it on the object, and pass it into request_activation wherever we do now (reconnect and constructor).

Mike7Chu commented 2 years ago

Thanks for your reply. I'll try to change activation_type. :)