Skip to content

Commit

Permalink
Add an experimental Cyphal/CAN media implementation for replaying can…
Browse files Browse the repository at this point in the history
…dump files, release v1.9 (#235)

* Add CandumpMedia

* Update mypy and pylint to the latest versions, introduce required minor adjustments

* Bump version, update changelog
  • Loading branch information
pavel-kirienko committed Jul 15, 2022
1 parent 62690b3 commit 338e206
Show file tree
Hide file tree
Showing 11 changed files with 432 additions and 10 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/pavel.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion CHANGELOG.rst
Expand Up @@ -6,12 +6,15 @@ Changelog
v1.9
----

- Cyphal/CAN: Add support for GS USB adapter support via PythonCAN
- Cyphal/CAN: Support GS USB adapter via PythonCAN
(`#212 <https://github.com/OpenCyphal/pycyphal/pull/212>`_).

- Cyphal/CAN: Adjust SocketCAN socket behavior to avoid ENOBUFS
(`#234 <https://github.com/OpenCyphal/pycyphal/pull/234>`_).

- Cyphal/CAN: Add :mod:``pycyphal.transport.can.media.candump`` media that reads standard CAN bus log files created
by the candump utility (part of SocketCAN).

v1.8
----

Expand Down
4 changes: 2 additions & 2 deletions noxfile.py
Expand Up @@ -124,8 +124,8 @@ def test(session):
# 2. At least MyPy has to be run separately per Python version we support.
# If the interpreter is not CPython, this may need to be conditionally disabled.
session.install(
"mypy == 0.942",
"pylint == 2.13.*",
"mypy == 0.961",
"pylint == 2.14.*",
)
relaxed_static_analysis = "3.7" in session.run("python", "-V", silent=True) # Old Pythons require relaxed checks.
if not relaxed_static_analysis:
Expand Down
2 changes: 1 addition & 1 deletion pycyphal/VERSION
@@ -1 +1 @@
1.9.0.beta2
1.9.0
13 changes: 11 additions & 2 deletions pycyphal/application/_transport_factory.py
Expand Up @@ -90,8 +90,13 @@ def make_transport(
* - ``uavcan.can.iface``
- ``string``
- Whitespace-separated list of CAN iface names.
Each iface name shall follow the format defined in :class:`pycyphal.transport.can.media.pythoncan`.
Each iface name shall follow the format defined in :mod:`pycyphal.transport.can.media.pythoncan`.
E.g.: ``socketcan:vcan0``.
On GNU/Linux, the ``socketcan:`` prefix selects :mod:`pycyphal.transport.can.media.socketcan`
instead of PythonCAN.
All platforms support the ``candump:`` prefix, which selects :mod:`pycyphal.transport.can.media.candump`;
the text after colon is the path of the log file;
e.g., ``candump:/home/pavel/candump-2022-07-14_150815.log``.
* - ``uavcan.can.mtu``
- ``natural16[1]``
Expand Down Expand Up @@ -287,7 +292,11 @@ def init(name: str, default: RelaxedValue) -> ValueProxy:
if iface.lower().startswith("socketcan:"):
from pycyphal.transport.can.media.socketcan import SocketCANMedia

media = SocketCANMedia(iface.split(":")[-1], mtu=mtu)
media = SocketCANMedia(iface.split(":", 1)[-1], mtu=mtu)
elif iface.lower().startswith("candump:"):
from pycyphal.transport.can.media.candump import CandumpMedia

media = CandumpMedia(iface.split(":", 1)[-1])
else:
from pycyphal.transport.can.media.pythoncan import PythonCANMedia

Expand Down
Expand Up @@ -2,6 +2,8 @@
# This software is distributed under the terms of the MIT License.
# Author: Pavel Kirienko <pavel@opencyphal.org>

# mypy: warn_unused_ignores=False

from __future__ import annotations
import bisect
import asyncio
Expand Down Expand Up @@ -273,7 +275,7 @@ def __init__(self, *, subject_count: int, depth: int) -> None:
def update(self, key: float, tolerance: float, index: int, item: T) -> tuple[T, ...] | None:
clust: _Cluster[T] | None = None
# noinspection PyTypeChecker
ni = bisect.bisect_left(self._clusters, key)
ni = bisect.bisect_left(self._clusters, key) # type: ignore
assert 0 <= ni <= len(self._clusters)
neigh: list[tuple[float, int]] = []
if 0 < ni:
Expand Down
5 changes: 5 additions & 0 deletions pycyphal/transport/can/media/candump/__init__.py
@@ -0,0 +1,5 @@
# Copyright (c) 2022 OpenCyphal
# This software is distributed under the terms of the MIT License.
# Author: Pavel Kirienko <pavel@opencyphal.org>

from ._candump import CandumpMedia as CandumpMedia

0 comments on commit 338e206

Please sign in to comment.