Skip to content

Commit 1aaf2e5

Browse files
authored
Support isotp v2 (#196)
- Added support for isotp v2.x - Also added some missing static typing
1 parent d089b40 commit 1aaf2e5

3 files changed

Lines changed: 305 additions & 119 deletions

File tree

doc/source/udsoncan/examples.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ In this example, we show how to use :class:`PythonIsoTpConnection<udsoncan.conne
7171
Note that, in order to run this code, both ``python-can`` and ``can-isotp`` must be installed.
7272

7373
.. code-block:: python
74-
75-
from can.interfaces.vector import VectorBus
74+
75+
import can
76+
import can.interfaces.vector import VectorBus
7677
from udsoncan.connections import PythonIsoTpConnection
7778
from udsoncan.client import Client
79+
import udsoncan.configs
7880
import isotp
7981
8082
# Refer to isotp documentation for full details about parameters
@@ -95,15 +97,18 @@ Note that, in order to run this code, both ``python-can`` and ``can-isotp`` must
9597
'rate_limit_enable': False, # Disable the rate limiter
9698
'rate_limit_max_bitrate': 1000000, # Ignored when rate_limit_enable=False. Sets the max bitrate when rate_limit_enable=True
9799
'rate_limit_window_size': 0.2, # Ignored when rate_limit_enable=False. Sets the averaging window size for bitrate calculation when rate_limit_enable=True
98-
'listen_mode': False # Does not use the listen_mode which prevent transmission.
100+
'listen_mode': False, # Does not use the listen_mode which prevent transmission.
99101
}
100102
103+
uds_config = udsoncan.configs.default_client_config.copy()
104+
101105
bus = VectorBus(channel=0, bitrate=500000) # Link Layer (CAN protocol)
106+
notifier = can.Notifier(bus, [can.Printer()]) # Add a debug listener that print all messages
102107
tp_addr = isotp.Address(isotp.AddressingMode.Normal_11bits, txid=0x123, rxid=0x456) # Network layer addressing scheme
103-
stack = isotp.CanStack(bus=bus, address=tp_addr, params=isotp_params) # Network/Transport layer (IsoTP protocol)
104-
stack.set_sleep_timing(0, 0) # Speed First (do not sleep)
108+
#stack = isotp.CanStack(bus=bus, address=tp_addr, params=isotp_params) # isotp v1.x has no notifier support
109+
stack = isotp.NotifierBasedCanStack(bus=bus, notifier=notifier, address=tp_addr, params=isotp_params) # Network/Transport layer (IsoTP protocol). Register a new listenenr
105110
conn = PythonIsoTpConnection(stack) # interface between Application and Transport layer
106-
with Client(conn, request_timeout=1) as client: # Application layer (UDS protocol)
111+
with Client(conn, config=uds_config) as client: # Application layer (UDS protocol)
107112
client.change_session(1)
108113
# ...
109114

udsoncan/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,7 +2165,7 @@ def send_request(self, request: Request, timeout: int = -1) -> Optional[Response
21652165
timeout_type_used = 'overall'
21662166
timeout_value = max(overall_timeout_time - time.time(), 0)
21672167

2168-
payload = self.conn.wait_frame(timeout=timeout_value, exception=True)
2168+
recv_payload = self.conn.wait_frame(timeout=timeout_value, exception=True)
21692169
except TimeoutException:
21702170
if timeout_type_used == 'single_request':
21712171
timeout_name_to_report = 'P2* timeout' if using_p2_star else 'P2 timeout'
@@ -2178,13 +2178,13 @@ def send_request(self, request: Request, timeout: int = -1) -> Optional[Response
21782178
except Exception as e:
21792179
raise e
21802180

2181-
if timed_out:
2181+
if timed_out or recv_payload is None:
21822182
if spr_used:
21832183
return None
21842184
raise TimeoutException('Did not receive response in time. %s time has expired (timeout=%.3f sec)' %
21852185
(timeout_name_to_report, timeout_value))
2186-
2187-
response = Response.from_payload(payload)
2186+
2187+
response = Response.from_payload(recv_payload)
21882188
self.last_response = response
21892189
self.logger.debug("Received response from server")
21902190

0 commit comments

Comments
 (0)