Skip to content

Commit f517322

Browse files
authored
Doc update (#109)
1 parent c851cd1 commit f517322

File tree

5 files changed

+39
-16
lines changed

5 files changed

+39
-16
lines changed

doc/source/index.rst

+12-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ It also contains a wrapper for a simplified usage of the `Linux SocketCAN IsoTP
1717

1818
.. note:: You are looking at the isotp v2.x documentation. The legacy `v1.x documentation <https://can-isotp.readthedocs.io/en/v1.x>`_ is still online.
1919

20-
V2.x changes
20+
v2.x changes
2121
------------
2222

2323
V2.x addressed several flaws that were present in v1.x. The main change is regarding the timing capabilities of the module. V2.x can achieve much better timing performance than
@@ -34,6 +34,16 @@ Here is the major API changes to v2.x that might make an application designed wi
3434

3535
- The transport layer can perform blocking sends, allowing an UDS layer to better handle its timeouts (P2/P2* vs P6 timeouts)
3636
- Some methods dedicated to internal usage have been prefixed with an underscore (``_``) to indicates that they are internals
37-
- The CanStack object uses a Notifier instead of performing ``bus.recv()`` solving the popular issue of a CanStack depleting the receive queue and starving other modules from their incoming messages
3837
- The ``isotp.socket.recv()`` method does not return ``None`` on timeout anymore.
3938
The API now comply with the Python socket API and will raise the proper exception in case of timeout.
39+
- The error handler is called from a different thread
40+
- The :class:`TransportLayer<isotp.TransportLayer>` object is now an extension of the legacy v1.x TransportLayer, which has been renamed to ``TransportLayerLogic``. See :ref:`Backward Compatibility<backward_compatibility>` and :ref:`Legacy Methods<legacy_methods>`
41+
42+
On top of that, some improvement makes v2.x preferable over v1.x
43+
44+
- The :class:`NotifierBasedCanStack<isotp.NotifierBasedCanStack>` object has been introduced and uses a notifier instead of calling ``bus.recv()``, solving the popular issue of a CanStack depleting the receive queue and starving other modules from their incoming messages
45+
- :ref:`Asymmetric addressing<asymmetric_addresses>` is possible (different address for reception than transmission)
46+
- Sending data with a generator is now possible, accommodating use cases with large payloads
47+
- The module is fully type-hinted
48+
- It is possible to use a busy-wait to achieve even more precise timings. See the :ref:`wait_func parameter<param_wait_func>`
49+

doc/source/isotp/addressing.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ Example :
161161

162162
------
163163

164+
.. _asymmetric_addresses:
164165

165166
Asymmetric addresses
166167
--------------------
@@ -170,7 +171,7 @@ It is possible to send and receive with different address schemes. The :class:`A
170171
.. autoclass:: isotp.AsymmetricAddress
171172

172173
When using an asymmetric, both ``tx_addr`` and ``rx_addr`` must be partial addresses, meaning that either ``tx_only=True`` or ``rx_only=True`` is set.
173-
Address object instantiated with ``rx_only=True`` will not expect parameter meant for transmission and conversely, when instantiated with ``tx_only=True``
174+
Address objects instantiated with ``rx_only=True`` will not expect the parameters meant for transmission and conversely, when instantiated with ``tx_only=True``
174175
parameters required for reception won't be needed.
175176

176177

@@ -203,7 +204,7 @@ Example :
203204
0x123 [7] 99 21 05 06 07 08 09 // Consecutive frame
204205

205206

206-
The following table indicates the required parameter to construct a :class:`Address<isotp.Address>` object for all possible scenario
207+
The following table indicates the required parameters to construct a :class:`Address<isotp.Address>` object for all possible scenarios
207208

208209
.. csv-table:: :class:`Address<isotp.Address>` required parameters
209210
:header: "Addressing mode", "Full address", "Partial Tx (``tx_only=True``)", "Partial Rx (``rx_only=True``)"

doc/source/isotp/implementation.rst

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Implementation
2-
==============
1+
Pure Python Implementation
2+
==========================
33

44
This sections explains the python implementation of the IsoTP protocol.
55

@@ -14,8 +14,10 @@ In such case, the :class:`isotp.TransportLayer<isotp.TransportLayer>` will be th
1414

1515
If python-can must be used as CAN layer, one can use the :class:`isotp.CanStack<isotp.CanStack>` and :class:`isotp.NotifierBasedCanStack<isotp.NotifierBasedCanStack>` which extends the TransportLayer object with predefined functions that calls python-can.
1616

17-
.. autoclass:: isotp.CanStack
1817
.. autoclass:: isotp.NotifierBasedCanStack
18+
.. autoclass:: isotp.CanStack
19+
20+
.. note:: The :class:`CanStack<isotp.CanStack>` exists mainly for backward compatibility with v1.x. It is suggested to use the :class:`NotifierBasedCanStack<isotp.NotifierBasedCanStack>` to avoid starvation issues and achieve better performances.
1921

2022
The CAN messages going in and out from the transport layer are defined with :class:`isotp.CanMessage<isotp.CanMessage>`.
2123

@@ -95,6 +97,7 @@ The transport layer ``params`` parameter must be a dictionary with the following
9597
.. _param_rx_flowcontrol_timeout:
9698

9799
.. attribute:: rx_flowcontrol_timeout
100+
:annotation: (int)
98101

99102
**default: 1000**
100103

@@ -318,6 +321,8 @@ The :class:`isotp.TransportLayer<isotp.TransportLayer>` object has the following
318321

319322
-----
320323

324+
.. _legacy_methods:
325+
321326
Legacy methods (v1.x)
322327
---------------------
323328

doc/source/isotp/socket.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Without this project
4343

4444
.. code-block:: python
4545
46-
SOL_CAN_ISOTP = 106 # These constants exist in the module header, not in Python.
46+
SOL_CAN_ISOTP = 106 # These constants exist in the linux source code, not in Python
4747
CAN_ISOTP_RECV_FC = 2
4848
# Many more exists.
4949

isotp/protocol.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,13 @@ def recv(self, block: bool = False, timeout: Optional[float] = None) -> Optional
721721
"""
722722
Dequeue an IsoTP frame from the reception queue if available.
723723
724+
:param block: Tells if the read should be blocking or not
725+
:type block: bool
726+
727+
:param timeout: Timeout value used for blocking read only
728+
:type timeout: float
729+
730+
724731
:return: The next available IsoTP frame
725732
:rtype: bytearray or None
726733
"""
@@ -731,7 +738,7 @@ def recv(self, block: bool = False, timeout: Optional[float] = None) -> Optional
731738

732739
def available(self) -> bool:
733740
"""
734-
Returns ``True`` if an IsoTP frame is awaiting in the reception ``queue``. ``False`` otherwise
741+
Returns ``True`` if an IsoTP frame is awaiting in the reception queue. ``False`` otherwise
735742
"""
736743
return not self.rx_queue.empty()
737744

@@ -1482,7 +1489,7 @@ def _read_relay_queue(self, timeout: Optional[float]) -> Optional[CanMessage]:
14821489
return None
14831490

14841491
def start(self) -> None:
1485-
"""Start the IsoTP layer. Starts internal threads that handle the IsoTP communication."""
1492+
"""Starts the IsoTP layer. Starts internal threads that handle the IsoTP communication."""
14861493
self.logger.debug(f"Starting {self.__class__.__name__}")
14871494
if self.started:
14881495
raise RuntimeError("Transport Layer is already started")
@@ -1610,16 +1617,16 @@ def stop_receiving(self):
16101617

16111618
# Protect against usage of non thread-safe methods while threads are running. We don't hide those method for backward compatibility
16121619
@is_documented_by(TransportLayerLogic.process)
1613-
def process(self, *args, **kwargs):
1620+
def process(self, rx_timeout: float = 0.0, do_rx: bool = True, do_tx: bool = True) -> TransportLayerLogic.ProcessStats:
16141621
if self.started:
16151622
raise RuntimeError("Cannot call process() after a start(). See documentation and notes about backward compatibility.")
1616-
super().process(*args, **kwargs)
1623+
return super().process(rx_timeout=rx_timeout, do_rx=do_rx, do_tx=do_tx)
16171624

16181625
@is_documented_by(TransportLayerLogic.reset)
1619-
def reset(self, *args, **kwargs):
1626+
def reset(self):
16201627
if self.started:
16211628
raise RuntimeError("Cannot call reset() after a start(). See documentation and notes about backward compatibility.")
1622-
super().reset(*args, **kwargs)
1629+
super().reset()
16231630

16241631

16251632
class BusOwner:
@@ -1656,7 +1663,7 @@ def _python_can_to_isotp_message(msg: Optional["can.Message"]) -> Optional[CanMe
16561663

16571664
class CanStack(TransportLayer, BusOwner):
16581665
"""
1659-
The IsoTP transport layer preconfigured to use `python-can <https://python-can.readthedocs.io>`__ as CAN layer. python-can must be installed in order to use this class.
1666+
The IsoTP transport layer pre configured to use `python-can <https://python-can.readthedocs.io>`__ as CAN layer. python-can must be installed in order to use this class.
16601667
All parameters except the ``bus`` parameter will be given to the :class:`TransportLayer<isotp.TransportLayer>` constructor
16611668
16621669
This class directly calls ``bus.recv``, consuming the message from the receive queue, potentially starving other application. Consider using the :class:`NotifierBasedCanStack<isotp.NotifierBasedCanStack>`
@@ -1696,7 +1703,7 @@ def set_bus(self, bus: "can.BusABC") -> None:
16961703

16971704
class NotifierBasedCanStack(TransportLayer, BusOwner):
16981705
"""
1699-
The IsoTP transport layer preconfigured to use `python-can <https://python-can.readthedocs.io>`__ as CAN layer and reading through a ``can.Notifier``. python-can must be installed in order to use this class.
1706+
The IsoTP transport layer pre configured to use `python-can <https://python-can.readthedocs.io>`__ as CAN layer and reading through a ``can.Notifier``. python-can must be installed in order to use this class.
17001707
All parameters except the ``bus`` and the ``notifier`` parameter will be given to the :class:`TransportLayer<isotp.TransportLayer>` constructor
17011708
17021709
This class reads by registering a listener to the given notifier and sends by calling ``bus.recv``.

0 commit comments

Comments
 (0)