gsusb-canfd 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 gsusb-canfd contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,121 @@
1
+ Metadata-Version: 2.4
2
+ Name: gsusb-canfd
3
+ Version: 0.1.0
4
+ Summary: Userspace gs_usb CAN FD driver and CLI (Python implementation)
5
+ Author-email: sorrowfeng <1399600304@qq.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/sorrowfeng/gsusb-canfd
8
+ Project-URL: Repository, https://github.com/sorrowfeng/gsusb-canfd
9
+ Project-URL: Issues, https://github.com/sorrowfeng/gsusb-canfd/issues
10
+ Project-URL: Changelog, https://github.com/sorrowfeng/gsusb-canfd/blob/main/CHANGELOG.md
11
+ Project-URL: Source (Python), https://github.com/sorrowfeng/gsusb-canfd/tree/main/python
12
+ Keywords: can,can-fd,canfd,gs_usb,usb,libusb,pyusb
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: MacOS
16
+ Classifier: Operating System :: Microsoft :: Windows
17
+ Classifier: Operating System :: POSIX :: Linux
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Topic :: Software Development :: Embedded Systems
21
+ Classifier: Topic :: System :: Hardware :: Hardware Drivers
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: pyusb>=1.2.1
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=7; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # gsusb-canfd (Python)
31
+
32
+ Part of the [gsusb-canfd](../README.md) project. Python implementation of the
33
+ library: a userspace **gs_usb** CAN FD driver built directly on `pyusb`/`libusb`.
34
+ It speaks the same wire protocol as the C++ library in this repository, so the two
35
+ are interchangeable.
36
+
37
+ It does **not** depend on the `gs_usb` / `python-can` packages. Those assume the
38
+ candleLight reference endpoints (`OUT = 0x02`) and only configure classic CAN
39
+ timing, so they cannot talk to adapters that use different bulk endpoints or
40
+ CAN FD data-phase timing through `GS_USB_BREQ_BT_CONST_EXT` / `DATA_BITTIMING`.
41
+ This package handles both.
42
+
43
+ ## Install
44
+
45
+ ```bash
46
+ pip install ./python
47
+ ```
48
+
49
+ Requires `libusb-1.0` at runtime (`brew install libusb`, `apt install libusb-1.0-0-dev`).
50
+
51
+ ## Use
52
+
53
+ ```python
54
+ from gsusb_canfd import BusConfig, CanFdBus, CanFrame
55
+
56
+ bus = CanFdBus()
57
+ with bus:
58
+ bus.configure(BusConfig(bitrate=1_000_000, sample_point=0.80,
59
+ data_bitrate=5_000_000, data_sample_point=0.75,
60
+ fd=True))
61
+ bus.send(CanFrame(id=0x501, data=bytes([0x00, 0x02, 0x50, 0x01]),
62
+ fd=True, brs=True))
63
+ while True:
64
+ frame = bus.receive(timeout=0.5)
65
+ if frame and not frame.echo and frame.id == 0x481:
66
+ print(frame)
67
+ ```
68
+
69
+ Extended frames: set `id > 0x7FF` or `CanFrame(extended=True)`.
70
+
71
+ Async receive (callback on a background thread):
72
+
73
+ ```python
74
+ bus.start(lambda frame: print(frame))
75
+ ...
76
+ bus.stop()
77
+ ```
78
+
79
+ ## Devices
80
+
81
+ ```python
82
+ from gsusb_canfd import scan_adapters
83
+
84
+ for i, adapter in enumerate(scan_adapters()):
85
+ print(i, adapter.name(), f"{adapter.vendor_id:04X}:{adapter.product_id:04X}",
86
+ adapter.serial)
87
+ ```
88
+
89
+ Select one with a `DeviceSelector` (`vid`, `pid`, `index`, `channel`, `serial`,
90
+ `product`). By default any gs_usb adapter is auto-discovered (known USB ids plus
91
+ descriptor heuristics); pass explicit `vid`/`pid` to pin one. On devices with
92
+ several CAN channels, `channel` selects which one (`bus.channel_count()` reports
93
+ the count).
94
+
95
+ ## CLI
96
+
97
+ ```bash
98
+ gsusb-canfd list
99
+
100
+ gsusb-canfd monitor --bitrate 1000000 --sample-point 0.80 \
101
+ --data-bitrate 5000000 --data-sample-point 0.75 \
102
+ --trigger --trigger-id 501 --trigger-data 00025001 \
103
+ --count 20
104
+
105
+ gsusb-canfd send --classic 123 1122334455667788
106
+ ```
107
+
108
+ ## Tests
109
+
110
+ The protocol logic (bit timing, DLC mapping, frame codec) is pure Python and is
111
+ covered by unit tests that need no hardware:
112
+
113
+ ```bash
114
+ pip install -e './python[dev]'
115
+ pytest python/tests
116
+ ```
117
+
118
+ ## Releasing
119
+
120
+ See [PUBLISHING.md](PUBLISHING.md); the version lives in
121
+ [`src/gsusb_canfd/_version.py`](src/gsusb_canfd/_version.py).
@@ -0,0 +1,92 @@
1
+ # gsusb-canfd (Python)
2
+
3
+ Part of the [gsusb-canfd](../README.md) project. Python implementation of the
4
+ library: a userspace **gs_usb** CAN FD driver built directly on `pyusb`/`libusb`.
5
+ It speaks the same wire protocol as the C++ library in this repository, so the two
6
+ are interchangeable.
7
+
8
+ It does **not** depend on the `gs_usb` / `python-can` packages. Those assume the
9
+ candleLight reference endpoints (`OUT = 0x02`) and only configure classic CAN
10
+ timing, so they cannot talk to adapters that use different bulk endpoints or
11
+ CAN FD data-phase timing through `GS_USB_BREQ_BT_CONST_EXT` / `DATA_BITTIMING`.
12
+ This package handles both.
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ pip install ./python
18
+ ```
19
+
20
+ Requires `libusb-1.0` at runtime (`brew install libusb`, `apt install libusb-1.0-0-dev`).
21
+
22
+ ## Use
23
+
24
+ ```python
25
+ from gsusb_canfd import BusConfig, CanFdBus, CanFrame
26
+
27
+ bus = CanFdBus()
28
+ with bus:
29
+ bus.configure(BusConfig(bitrate=1_000_000, sample_point=0.80,
30
+ data_bitrate=5_000_000, data_sample_point=0.75,
31
+ fd=True))
32
+ bus.send(CanFrame(id=0x501, data=bytes([0x00, 0x02, 0x50, 0x01]),
33
+ fd=True, brs=True))
34
+ while True:
35
+ frame = bus.receive(timeout=0.5)
36
+ if frame and not frame.echo and frame.id == 0x481:
37
+ print(frame)
38
+ ```
39
+
40
+ Extended frames: set `id > 0x7FF` or `CanFrame(extended=True)`.
41
+
42
+ Async receive (callback on a background thread):
43
+
44
+ ```python
45
+ bus.start(lambda frame: print(frame))
46
+ ...
47
+ bus.stop()
48
+ ```
49
+
50
+ ## Devices
51
+
52
+ ```python
53
+ from gsusb_canfd import scan_adapters
54
+
55
+ for i, adapter in enumerate(scan_adapters()):
56
+ print(i, adapter.name(), f"{adapter.vendor_id:04X}:{adapter.product_id:04X}",
57
+ adapter.serial)
58
+ ```
59
+
60
+ Select one with a `DeviceSelector` (`vid`, `pid`, `index`, `channel`, `serial`,
61
+ `product`). By default any gs_usb adapter is auto-discovered (known USB ids plus
62
+ descriptor heuristics); pass explicit `vid`/`pid` to pin one. On devices with
63
+ several CAN channels, `channel` selects which one (`bus.channel_count()` reports
64
+ the count).
65
+
66
+ ## CLI
67
+
68
+ ```bash
69
+ gsusb-canfd list
70
+
71
+ gsusb-canfd monitor --bitrate 1000000 --sample-point 0.80 \
72
+ --data-bitrate 5000000 --data-sample-point 0.75 \
73
+ --trigger --trigger-id 501 --trigger-data 00025001 \
74
+ --count 20
75
+
76
+ gsusb-canfd send --classic 123 1122334455667788
77
+ ```
78
+
79
+ ## Tests
80
+
81
+ The protocol logic (bit timing, DLC mapping, frame codec) is pure Python and is
82
+ covered by unit tests that need no hardware:
83
+
84
+ ```bash
85
+ pip install -e './python[dev]'
86
+ pytest python/tests
87
+ ```
88
+
89
+ ## Releasing
90
+
91
+ See [PUBLISHING.md](PUBLISHING.md); the version lives in
92
+ [`src/gsusb_canfd/_version.py`](src/gsusb_canfd/_version.py).
@@ -0,0 +1,57 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "gsusb-canfd"
7
+ dynamic = ["version"]
8
+ description = "Userspace gs_usb CAN FD driver and CLI (Python implementation)"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [
14
+ { name = "sorrowfeng", email = "1399600304@qq.com" },
15
+ ]
16
+ keywords = ["can", "can-fd", "canfd", "gs_usb", "usb", "libusb", "pyusb"]
17
+ classifiers = [
18
+ "Development Status :: 4 - Beta",
19
+ "Intended Audience :: Developers",
20
+ "Operating System :: MacOS",
21
+ "Operating System :: Microsoft :: Windows",
22
+ "Operating System :: POSIX :: Linux",
23
+ "Programming Language :: Python :: 3",
24
+ "Programming Language :: Python :: 3 :: Only",
25
+ "Topic :: Software Development :: Embedded Systems",
26
+ "Topic :: System :: Hardware :: Hardware Drivers",
27
+ ]
28
+ dependencies = [
29
+ "pyusb>=1.2.1",
30
+ ]
31
+
32
+ [project.optional-dependencies]
33
+ dev = [
34
+ "pytest>=7",
35
+ ]
36
+
37
+ [project.urls]
38
+ Homepage = "https://github.com/sorrowfeng/gsusb-canfd"
39
+ Repository = "https://github.com/sorrowfeng/gsusb-canfd"
40
+ Issues = "https://github.com/sorrowfeng/gsusb-canfd/issues"
41
+ Changelog = "https://github.com/sorrowfeng/gsusb-canfd/blob/main/CHANGELOG.md"
42
+ "Source (Python)" = "https://github.com/sorrowfeng/gsusb-canfd/tree/main/python"
43
+
44
+ [project.scripts]
45
+ gsusb-canfd = "gsusb_canfd.cli:main"
46
+
47
+ [tool.setuptools.dynamic]
48
+ version = { attr = "gsusb_canfd._version.__version__" }
49
+
50
+ [tool.setuptools.packages.find]
51
+ where = ["src"]
52
+
53
+ [tool.setuptools.package-data]
54
+ gsusb_canfd = ["py.typed"]
55
+
56
+ [tool.pytest.ini_options]
57
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,50 @@
1
+ """Python implementation of the gsusb-canfd library.
2
+
3
+ The wire protocol, bit timing and frame codec live in
4
+ :mod:`gsusb_canfd.protocol`; :class:`~gsusb_canfd.bus.CanFdBus` speaks to the
5
+ adapter through pyusb.
6
+ """
7
+
8
+ from ._version import __version__
9
+ from .bus import (
10
+ DEFAULT_PID,
11
+ DEFAULT_VID,
12
+ AdapterInfo,
13
+ BusConfig,
14
+ CanFdBus,
15
+ DeviceInfo,
16
+ DeviceSelector,
17
+ scan_adapters,
18
+ )
19
+ from .protocol import (
20
+ BitTiming,
21
+ BitTimingConst,
22
+ CanFdError,
23
+ CanFrame,
24
+ calculate_bit_timing,
25
+ decode_frame,
26
+ dlc_to_length,
27
+ encode_frame,
28
+ length_to_dlc,
29
+ )
30
+
31
+ __all__ = [
32
+ "AdapterInfo",
33
+ "BusConfig",
34
+ "BitTiming",
35
+ "BitTimingConst",
36
+ "CanFdBus",
37
+ "CanFdError",
38
+ "CanFrame",
39
+ "DEFAULT_PID",
40
+ "DEFAULT_VID",
41
+ "DeviceInfo",
42
+ "DeviceSelector",
43
+ "calculate_bit_timing",
44
+ "decode_frame",
45
+ "dlc_to_length",
46
+ "encode_frame",
47
+ "length_to_dlc",
48
+ "scan_adapters",
49
+ "__version__",
50
+ ]
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"