canconf 0.3.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,9 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ build/
5
+ dist/
6
+ .venv/
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+ *.out
@@ -0,0 +1 @@
1
+ CLAUDE.md
@@ -0,0 +1,81 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## What this is
6
+
7
+ A two-tool package for Linux SocketCAN admins:
8
+
9
+ - **`canconf`** — one-shot reconfigurator for CAN / CAN-FD interfaces. Replaces the long, order-sensitive `ip link set ...` dance with a single terse command like `canconf 500k/2M@0.875/0.75`. Its niche: hosts with two or more CAN interfaces on the same bus that must be configured identically.
10
+ - **`canmon`** — read-only live monitor. Tails state, bittiming, frame-error deltas, and controller bit-error deltas per interface per tick; flags state transitions, config changes, auto-restarts, and threshold breaches.
11
+
12
+ Pure Python 3.9+ stdlib — no runtime dependencies. Distributed on PyPI, meant to be installed via `pipx`.
13
+
14
+ ## Build and test
15
+
16
+ ```bash
17
+ make test # quick dry-run self-checks (no root needed)
18
+ make status # show current CAN interface state
19
+ make dry SPEC=500k/2M # show the ip commands canconf would run
20
+ make vcan # create vcan0 for local testing
21
+ make vcanfd # vcan0 with CAN-FD MTU
22
+ make check # python -m compileall
23
+ make fmt / make lint # ruff (if installed)
24
+ make build # python -m build -> dist/
25
+ make install # pipx install --force . + man page
26
+ make install-editable # pipx install --editable .
27
+ ```
28
+
29
+ From a source checkout, run the tool without installing via `PYTHONPATH=src python -m canconf ...` (this is what `make status`/`make dry` do).
30
+
31
+ Testing against real hardware needs root; `canconf` self-elevates via `sudo -- python -m canconf ...` when not already root. Dry-run (`-n`) never elevates.
32
+
33
+ ## Architecture
34
+
35
+ Three modules under `src/canconf/`:
36
+
37
+ - `common.py` — `discover_ifaces()` (scans `/sys/class/net/*/type` for ARPHRD_CAN = 280), `fmt_rate()` (500000→"500k"), `get_links(stats=False)` (wraps `ip -j -details [-s] link show`, returns `{ifname: dict}`). Shared by both tools.
38
+ - `cli.py` — `canconf` entry point.
39
+ - `monitor.py` — `canmon` entry point.
40
+
41
+ `__init__.py` exports `__version__`; `__main__.py` makes `python -m canconf` run the reconfigurator. `canmon` is exposed only via the pyproject entry point (no `python -m canmon`).
42
+
43
+ **canconf pipeline per run:**
44
+
45
+ 1. **Discover** CAN interfaces by scanning `/sys/class/net/*/type` for ARPHRD_CAN (`280`). This catches `can*`, `vcan*`, `slcan*` without pattern-matching names. Override with `--ifaces`.
46
+
47
+ 2. **Parse** the positional spec. Grammar: `BITRATE[/DBITRATE][@SP[/DSP]]` — a `/` in the rate part switches the action to CAN-FD; an `@` starts sample points. Special specs: `off` / `down`, `up`.
48
+
49
+ 3. **Elevate** via `os.execvp("sudo", [...sys.executable, "-m", "canconf", ...sys.argv[1:]])` if not root. Using `-m canconf` keeps pipx-installed venvs correct (no accidental system-python re-exec).
50
+
51
+ 4. **Apply**: for each selected iface, `ip link set IF down` → `ip link set IF type can ...` (+ `txqueuelen`) → `ip link set IF up`. Default `txqueuelen` is 10000 because the kernel default of 10 is far too low for CAN.
52
+
53
+ 5. **Show** post-apply state unless `--quiet` or `--dry-run`. Status rows include `qlen` (`txqlen` from `ip`) and `drv` (`bittiming_const.name` — typically the SocketCAN driver name). The driver may silently round the requested bitrate to the nearest achievable value given the CAN clock, so reading back the actual config matters.
54
+
55
+ **Introspection (`canconf bitrates`):** derives the achievable bitrate envelope per interface from `bittiming_const` + `clock` using `bitrate = clock / (brp · (1 + tseg1 + tseg2))` — min comes from the max values, max from the mins. Intersects with the set of standard CAN bitrates (10k…1M for nominal, 1M…8M for FD data) and shows both the raw envelope and the matching standard rates. FD support is detected by presence of `data_bittiming_const`.
56
+
57
+ **canmon pipeline per tick:**
58
+
59
+ 1. Call `get_links(stats=True)` and wrap each selected iface in a `Snapshot` dataclass (state, bittiming, rx/tx errors from `stats64`, all of `info_xstats`).
60
+ 2. Compare against the previous tick: detect state transition, bittiming change, restart-count increase, and compute `Δerr/s` and `Δbus/s`.
61
+ 3. At startup: emit the header and one row per iface (initial snapshot). Subsequent ticks: emit a row only for ifaces where *something* changed (state/bittiming/restart count) or the `Δbus/s` threshold was crossed. `--verbose` overrides this and emits every iface every tick. `--once` prints only the startup snapshot and exits.
62
+
63
+ **Key design choices:**
64
+
65
+ - No pattern-matching on interface names — rely on ARPHRD_CAN so exotic transports (slcan, usb-based gs_can, …) are picked up automatically.
66
+ - Status is read from `ip -j -details link show` and pulled from `linkinfo.info_data.bittiming` / `.data_bittiming`. CAN-FD is inferred by the presence of `data_bittiming` (not by `ctrlmode_supported`, which only indicates driver capability).
67
+ - `ip` is shelled out rather than talking netlink directly: keeps the dep surface at zero and the commands are trivially auditable via `-v`/`-n`.
68
+ - Sample-point syntax (`@0.875/0.75`) is opt-in; many users don't care and the kernel picks reasonable defaults.
69
+ - `canmon` measures bit-errors via `info_xstats.bus_error` (monotonic counter maintained by the driver), **not** via the live `berr-counter` TEC/REC (which oscillates and resets). This makes delta-per-second meaningful and makes the tool work without `berr-reporting on` at configure time.
70
+ - `canmon` does not open a CAN socket; it only polls `ip`/sysfs. Zero bus impact, zero need for root.
71
+
72
+ ## Release
73
+
74
+ 1. Bump `version` in `pyproject.toml` **and** `__version__` in `src/canconf/__init__.py` (both must match — `make release` reads pyproject.toml, but the `--version` output reads `__init__.py`).
75
+ 2. Commit the bump.
76
+ 3. `make release` — verifies clean tree, creates `vX.Y.Z` tag, pushes.
77
+ 4. `make publish` — builds wheel + sdist, 5s confirm prompt, `twine upload`.
78
+
79
+ ## Dependencies
80
+
81
+ None at runtime. Build requires `hatchling`; `make publish` needs `twine` on PATH; `make fmt`/`lint` use `ruff` if installed (otherwise skipped).
canconf-0.3.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dr. Michael Lauer
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.
canconf-0.3.0/Makefile ADDED
@@ -0,0 +1,166 @@
1
+ PKG := canconf
2
+ PYTHON ?= python3
3
+ PIPX ?= pipx
4
+ TWINE ?= twine
5
+
6
+ # For running from a source checkout without installing.
7
+ RUN_PY := PYTHONPATH=src $(PYTHON)
8
+
9
+ PREFIX ?= $(HOME)/.local
10
+ MANDIR ?= $(PREFIX)/share/man
11
+
12
+ VERSION := $(shell grep '^version' pyproject.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
13
+
14
+ .PHONY: all help build install install-editable uninstall reinstall \
15
+ run status monitor dry test check fmt lint clean distclean \
16
+ vcan vcanfd vcan-down man man-canmon release publish
17
+
18
+ all: help
19
+
20
+ # --- build / install ---------------------------------------------------------
21
+
22
+ build:
23
+ $(PYTHON) -m build
24
+
25
+ install:
26
+ $(PIPX) install --force .
27
+ install -Dm644 man/canconf.1 $(MANDIR)/man1/canconf.1
28
+ install -Dm644 man/canmon.1 $(MANDIR)/man1/canmon.1
29
+
30
+ install-editable:
31
+ $(PIPX) install --force --editable .
32
+
33
+ uninstall:
34
+ -$(PIPX) uninstall $(PKG)
35
+ rm -f $(MANDIR)/man1/canconf.1 $(MANDIR)/man1/canmon.1
36
+
37
+ reinstall: uninstall install
38
+
39
+ # --- run / test --------------------------------------------------------------
40
+
41
+ # Show current status of all CAN interfaces on this host.
42
+ status:
43
+ $(RUN_PY) -m $(PKG)
44
+
45
+ # Monitor all CAN interfaces from a source checkout.
46
+ monitor:
47
+ $(RUN_PY) -c "from canconf.monitor import main; import sys; sys.exit(main())"
48
+
49
+ # Dry-run a full reconfigure; override SPEC / IFACES on the command line.
50
+ SPEC ?= 500k/2M@0.875/0.75
51
+ IFACES ?=
52
+ dry:
53
+ $(RUN_PY) -m $(PKG) -n $(SPEC) $(if $(IFACES),-i $(IFACES))
54
+
55
+ # Quick sanity checks: parse help, parse a handful of specs.
56
+ test:
57
+ $(RUN_PY) -m $(PKG) --help >/dev/null
58
+ $(RUN_PY) -m $(PKG) -n 500k -i vcan0 >/dev/null
59
+ $(RUN_PY) -m $(PKG) -n 500k/2M -i vcan0 >/dev/null
60
+ $(RUN_PY) -m $(PKG) -n 500k/2M@0.875/0.75 -i vcan0 >/dev/null
61
+ $(RUN_PY) -m $(PKG) -n off -i vcan0 >/dev/null
62
+ $(RUN_PY) -c "from canconf.monitor import main; import sys; sys.argv=['canmon','--help']; sys.exit(main())" >/dev/null
63
+ @echo "ok"
64
+
65
+ # --- quality -----------------------------------------------------------------
66
+
67
+ check:
68
+ $(PYTHON) -m compileall -q src
69
+
70
+ fmt:
71
+ @command -v ruff >/dev/null && ruff format src || echo "ruff not installed, skipping"
72
+
73
+ lint:
74
+ @command -v ruff >/dev/null && ruff check src || echo "ruff not installed, skipping"
75
+
76
+ # --- virtual CAN for local testing -------------------------------------------
77
+
78
+ vcan:
79
+ sudo modprobe vcan
80
+ sudo ip link add dev vcan0 type vcan 2>/dev/null || true
81
+ sudo ip link set up vcan0
82
+
83
+ # vcan with CAN-FD MTU so canconf can test FD code paths.
84
+ vcanfd:
85
+ sudo modprobe vcan
86
+ sudo ip link add dev vcan0 type vcan mtu 72 2>/dev/null || true
87
+ sudo ip link set up vcan0
88
+
89
+ vcan-down:
90
+ -sudo ip link set down vcan0
91
+ -sudo ip link delete vcan0
92
+
93
+ # --- docs --------------------------------------------------------------------
94
+
95
+ man:
96
+ @man ./man/canconf.1
97
+
98
+ man-canmon:
99
+ @man ./man/canmon.1
100
+
101
+ # --- release -----------------------------------------------------------------
102
+
103
+ # Tag the current HEAD with the version from pyproject.toml and push.
104
+ release:
105
+ @if ! git diff --quiet || ! git diff --cached --quiet; then \
106
+ echo "error: uncommitted changes — commit first"; exit 1; \
107
+ fi
108
+ @if git tag | grep -q "^v$(VERSION)$$"; then \
109
+ echo "error: tag v$(VERSION) already exists — bump version in pyproject.toml and src/$(PKG)/__init__.py"; exit 1; \
110
+ fi
111
+ git tag -a v$(VERSION) -m "v$(VERSION)"
112
+ git push --tags
113
+ @echo "Tagged and pushed v$(VERSION)."
114
+ @echo "Run 'make publish' to upload to PyPI."
115
+
116
+ # Build and upload to PyPI. Requires twine and credentials (e.g. ~/.pypirc).
117
+ publish: clean build
118
+ @echo ""
119
+ @echo "About to upload $(PKG) $(VERSION) to PyPI in 5s... (Ctrl-C to abort)"
120
+ @sleep 5
121
+ $(TWINE) upload --skip-existing dist/*
122
+
123
+ # --- housekeeping ------------------------------------------------------------
124
+
125
+ clean:
126
+ rm -rf build dist *.egg-info src/*.egg-info .pytest_cache
127
+ find . -name __pycache__ -type d -exec rm -rf {} +
128
+
129
+ distclean: clean
130
+ rm -rf .venv
131
+
132
+ help:
133
+ @echo "$(PKG) Makefile (v$(VERSION))"
134
+ @echo ""
135
+ @echo "Build / install:"
136
+ @echo " build python -m build (wheel + sdist in dist/)"
137
+ @echo " install pipx install --force . + install man page"
138
+ @echo " install-editable pipx install --editable ."
139
+ @echo " uninstall pipx uninstall + remove man page"
140
+ @echo " reinstall uninstall + install"
141
+ @echo ""
142
+ @echo "Run / test:"
143
+ @echo " status show current CAN interface status (canconf)"
144
+ @echo " monitor live CAN health monitor (canmon)"
145
+ @echo " dry SPEC=500k/2M dry-run a reconfigure"
146
+ @echo " test run quick self-tests"
147
+ @echo " check python -m compileall"
148
+ @echo " fmt / lint ruff format / ruff check (if installed)"
149
+ @echo ""
150
+ @echo "Virtual CAN:"
151
+ @echo " vcan create vcan0 (classic CAN)"
152
+ @echo " vcanfd create vcan0 with CAN-FD MTU"
153
+ @echo " vcan-down tear down vcan0"
154
+ @echo ""
155
+ @echo "Docs:"
156
+ @echo " man view canconf(1)"
157
+ @echo " man-canmon view canmon(1)"
158
+ @echo ""
159
+ @echo "Release:"
160
+ @echo " release tag v\$$VERSION and push"
161
+ @echo " publish build + twine upload"
162
+ @echo ""
163
+ @echo "Housekeeping:"
164
+ @echo " clean / distclean remove build artifacts / .venv"
165
+ @echo ""
166
+ @echo "Variables: PYTHON=$(PYTHON) PIPX=$(PIPX) PREFIX=$(PREFIX)"
canconf-0.3.0/PKG-INFO ADDED
@@ -0,0 +1,285 @@
1
+ Metadata-Version: 2.4
2
+ Name: canconf
3
+ Version: 0.3.0
4
+ Summary: One-shot reconfiguration and live monitoring of SocketCAN / CAN-FD interfaces
5
+ Project-URL: Homepage, https://github.com/mickeyl/canconf
6
+ Project-URL: Repository, https://github.com/mickeyl/canconf
7
+ Project-URL: Issues, https://github.com/mickeyl/canconf/issues
8
+ Author-email: "Dr. Michael Lauer" <mickey@vanille-media.de>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: automotive,can,canbus,canfd,linux,socketcan
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: System Administrators
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: POSIX :: Linux
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Topic :: System :: Hardware
20
+ Classifier: Topic :: System :: Networking
21
+ Classifier: Topic :: Utilities
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+
25
+ # canconf / canmon
26
+
27
+ Two small, single-purpose tools for people who spend their day staring at CAN
28
+ buses on Linux:
29
+
30
+ - **`canconf`** — reconfigure every SocketCAN / CAN-FD interface in one terse
31
+ command, introspect the hardware, inspect the live configuration.
32
+ - **`canmon`** — passive, read-only health monitor: state transitions,
33
+ configuration changes, auto-restarts, and bit-error bursts — printed only
34
+ when something actually happens.
35
+
36
+ Both are pure Python 3.9+ stdlib, zero runtime dependencies, installable as a
37
+ single `pipx install canconf` and immediately useful.
38
+
39
+ ## Why this exists
40
+
41
+ Automotive CAN work — diagnostics, ECU flashing, gateway reverse-engineering,
42
+ bench-testing on the sofa — spends an embarrassing amount of time on the same
43
+ fiddly chores:
44
+
45
+ - **Changing bitrates**. Different ECUs, different generations, different
46
+ vehicle platforms all want different line speeds. Switching from 500k to 250k
47
+ to 1M to FD-at-2M happens several times a day. The stock `ip link` CLI
48
+ wants half a dozen sudo-flavoured incantations for each iface, in the right
49
+ order, with the right keywords — an error-prone tax on iteration speed.
50
+ - **Keeping two interfaces in lock-step.** Dual-channel USB adapters and
51
+ bench rigs with T-tap into the same bus mean every parameter change has to
52
+ be mirrored across both ifaces. Forget one and your capture is misleading.
53
+ - **Knowing the bus is healthy.** When an ECU flash spirals into bus-off, or
54
+ a faulty transceiver starts cooking bit errors, you want to *see it* — not
55
+ realise hours later that half your log is garbage.
56
+ - **Knowing what the hardware can actually do.** Is this adapter FD-capable?
57
+ What bitrates will its clock + timing constants support? Which kernel driver
58
+ backs it? The answers are all there in `/sys` and netlink, but nobody types
59
+ `jq '.linkinfo.info_data.bittiming_const'` for fun.
60
+
61
+ `canconf` and `canmon` compress those chores into commands short enough to
62
+ actually type during a debug loop. If you use `mcangen`, `candump`, python-can,
63
+ or any of the canmatrix family to do real work on the bus, these are the tools
64
+ that keep the plumbing out of your way.
65
+
66
+ ## Installation
67
+
68
+ ### pipx — recommended
69
+
70
+ Installs the two binaries into an isolated venv and puts `canconf` and `canmon`
71
+ on your `PATH`:
72
+
73
+ ```bash
74
+ pipx install canconf
75
+ ```
76
+
77
+ ### pip
78
+
79
+ ```bash
80
+ pip install canconf
81
+ ```
82
+
83
+ ### From source
84
+
85
+ ```bash
86
+ git clone https://github.com/mickeyl/canconf
87
+ cd canconf
88
+ pipx install . # or: pip install -e .
89
+ ```
90
+
91
+ No runtime deps. Needs only `iproute2` (you already have it) and `sudo`
92
+ (`canconf` self-elevates; `canmon` stays non-privileged).
93
+
94
+ ## canconf
95
+
96
+ Replaces:
97
+
98
+ ```bash
99
+ sudo ip link set can0 down
100
+ sudo ip link set can1 down
101
+ sudo ip link set can0 type can bitrate 500000 dbitrate 2000000 sample-point 0.875 dsample-point 0.75 fd on
102
+ sudo ip link set can1 type can bitrate 500000 dbitrate 2000000 sample-point 0.875 dsample-point 0.75 fd on
103
+ sudo ip link set can0 txqueuelen 10000
104
+ sudo ip link set can1 txqueuelen 10000
105
+ sudo ip link set can0 up
106
+ sudo ip link set can1 up
107
+ ```
108
+
109
+ with:
110
+
111
+ ```bash
112
+ canconf 500k/2M@0.875/0.75
113
+ ```
114
+
115
+ ### Grammar
116
+
117
+ ```
118
+ canconf show status of all can* interfaces
119
+ canconf 500k classic CAN @ 500 kbit/s, all interfaces, up
120
+ canconf 500k/2M CAN-FD: nominal 500k, data 2M
121
+ canconf 500k/2M@0.875/0.75 same, with nominal & data sample points
122
+ canconf off | down bring all interfaces down
123
+ canconf up bring all interfaces up (no reconfigure)
124
+ canconf bitrates show achievable bitrates per interface
125
+ ```
126
+
127
+ Positional spec: `BITRATE[/DBITRATE][@SP[/DSP]]`. Bitrates accept the suffixes
128
+ `k`/`M` (`125k`, `500k`, `1M`, `2M`, `5M`, `8M`).
129
+
130
+ ### Features
131
+
132
+ - Discovers all CAN interfaces by ARPHRD type (so `can*`, `vcan*`, `slcan*` are all picked up — no name matching).
133
+ - One compact spec for classic CAN and CAN-FD alike.
134
+ - `canconf bitrates` reports the driver, reference clock, the achievable bitrate envelope (derived from `bittiming_const`), which standard bitrates fall within it, and whether the hardware supports CAN-FD at all. No brute-forcing, all introspection.
135
+ - Sets `txqueuelen 10000` by default (the kernel default of 10 is painfully low for anything other than idle buses).
136
+ - Prints the live post-apply state — including `qlen` and the underlying driver — so you can verify the driver actually accepted what you asked for (drivers silently round bitrates to what the clock can produce).
137
+ - ANSI colour with sensible auto-detection, `NO_COLOR`/`FORCE_COLOR`, and a `--no-color` flag.
138
+ - Self-elevates to root via `sudo`; `--dry-run` is completely non-privileged.
139
+
140
+ ### Options
141
+
142
+ | Flag | Description |
143
+ |------|-------------|
144
+ | `-i`, `--ifaces a,b,c` | Restrict to these interfaces (default: all CAN interfaces) |
145
+ | `-r`, `--restart-ms N` | Auto-restart on bus-off after N ms |
146
+ | `--listen-only` | Listen-only mode |
147
+ | `--loopback` | Loopback mode |
148
+ | `--one-shot` | One-shot mode |
149
+ | `--berr` | Enable bus error reporting |
150
+ | `--term OHM` | Set termination resistor (if the hardware supports it) |
151
+ | `--txqueuelen N` | Override the tx queue length (default: 10000) |
152
+ | `-n`, `--dry-run` | Print the `ip` commands that would run, do nothing |
153
+ | `-v`, `--verbose` | Print each `ip` command as it runs |
154
+ | `-q`, `--quiet` | Suppress the post-apply status dump |
155
+ | `--no-color` | Disable ANSI colour |
156
+ | `-V`, `--version` | Print version and exit |
157
+ | `-h`, `--help` | Show help |
158
+
159
+ ### Example session
160
+
161
+ ```
162
+ ❯ canconf
163
+ can0 UP CAN 500k sp 0.875 qlen 10000 drv gs_usb
164
+ can1 UP CAN 500k sp 0.875 qlen 10000 drv gs_usb
165
+
166
+ ❯ canconf 500k/2M@0.875/0.75
167
+ [sudo] password for mickey:
168
+ can0 UP CAN-FD 500k/2M sp 0.875/0.750 qlen 10000 drv gs_usb
169
+ can1 UP CAN-FD 500k/2M sp 0.875/0.750 qlen 10000 drv gs_usb
170
+
171
+ ❯ canconf bitrates
172
+ === can0 ===
173
+ driver: gs_usb
174
+ clock: 40 MHz
175
+ nominal: 202 .. 13333333
176
+ standard: 10k, 20k, 50k, 100k, 125k, 250k, 500k, 800k, 1M
177
+ FD data: 25510 .. 13333333
178
+ FD std: 1M, 2M, 4M, 5M, 8M
179
+
180
+ === can1 ===
181
+ driver: gs_usb
182
+ clock: 48 MHz
183
+ nominal: 1875 .. 16M
184
+ standard: 10k, 20k, 50k, 100k, 125k, 250k, 500k, 800k, 1M
185
+ FD: not supported
186
+
187
+ ❯ canconf -n 1M -i can0
188
+ + ip link set can0 down
189
+ + ip link set can0 type can bitrate 1000000
190
+ + ip link set can0 txqueuelen 10000
191
+ + ip link set can0 up
192
+ ```
193
+
194
+ ## canmon
195
+
196
+ `canmon` tails every CAN interface at 1 Hz (tunable). It prints the current
197
+ state once at startup and then **stays silent**, emitting a new row only when
198
+ something actually changes: a state transition, a bittiming change, an
199
+ auto-restart, or a tick in which the CAN controller bit-error rate exceeds a
200
+ threshold. It needs no root and reads only from `ip -j -details -s link show`
201
+ plus `/sys/class/net` — no CAN traffic is injected, intercepted, or generated.
202
+
203
+ ```
204
+ ❯ canmon -r 0.5 -t 5
205
+ TIME IFACE STATE BITRATE Δerr/s Δbus/s restarts notes
206
+ 14:23:45 can0 ERROR-ACTIVE 500k 0 0 0
207
+ 14:23:45 can1 ERROR-ACTIVE 500k/2M 0 0 0
208
+ 14:23:46 can0 ERROR-WARNING 500k 12 8 0 STATE ERROR-ACTIVE→ERROR-WARNING BIT-ERRORS 8/s > 5/s
209
+ 14:23:48 can0 BUS-OFF 500k 4 14 0 STATE ERROR-WARNING→BUS-OFF BIT-ERRORS 14/s > 5/s
210
+ 14:23:52 can0 ERROR-ACTIVE 500k 0 0 1 STATE BUS-OFF→ERROR-ACTIVE RESTART #1
211
+ ```
212
+
213
+ (Between 14:23:46 and 14:23:48, and at any other tick with no change, nothing
214
+ is printed. Pass `-v` to force a row every tick.)
215
+
216
+ ### Options
217
+
218
+ | Flag | Description |
219
+ |------|-------------|
220
+ | `-i`, `--ifaces a,b,c` | Restrict to these interfaces |
221
+ | `-r`, `--rate SECONDS` | Tick interval (default: 1.0) |
222
+ | `-t`, `--err-rate N` | Threshold for the `Δbus/s` flag (default: 1) |
223
+ | `-o`, `--once` | Print initial snapshot and exit |
224
+ | `-v`, `--verbose` | Emit a row every tick, not just on change |
225
+ | `--no-color` | Disable ANSI colour |
226
+ | `-V`, `--version` | Print version and exit |
227
+ | `-h`, `--help` | Show help |
228
+
229
+ ### Columns
230
+
231
+ - **Δerr/s** — frame-level `rx+tx` error delta per second (from driver `stats64`).
232
+ - **Δbus/s** — CAN controller bit-error delta per second (from `info_xstats.bus_error`). The number you probably care about most during ECU flashes, cable swaps, or suspect wiring.
233
+ - **restarts** — running total of driver-initiated auto-restarts after bus-off (requires `canconf … -r MS` to be non-zero at configure time).
234
+ - **notes** — event tags: `STATE a→b`, `CONFIG a→b`, `RESTART #N`, `BIT-ERRORS N/s > T/s`. In a colour-capable terminal each tag is coloured by severity, and state tokens are rendered in the same colour as the state column so bus-off transitions jump out.
235
+
236
+ ## Roadmap
237
+
238
+ Things I intend to build as soon as the underlying itch scratches hard enough.
239
+ Contributions welcome; open an issue first if it's non-trivial.
240
+
241
+ ### Short-term
242
+
243
+ - **JSON output** (`canconf --json`, `canmon --json`) for scripting and for
244
+ wiring the tools into dashboards or CI.
245
+ - **Bus-load metrics in `canmon`** — frames/s, bytes/s, and estimated line
246
+ utilisation (%) derived from the driver's rx/tx counters and the active
247
+ bitrate. All the inputs are already read each tick.
248
+ - **Config profiles** — `~/.config/canconf/profiles.toml` so you can name
249
+ frequently-used configurations and apply them with `canconf @passive-500k`
250
+ or `canconf @my-ecu`. Profile files track sample-point, FD, termination,
251
+ listen-only, restart-ms, and per-iface overrides.
252
+ - **`canconf save`/`canconf apply`** — dump the current configuration of all
253
+ interfaces to a profile file, and re-apply it later. Handy for sharing bus
254
+ setups between workstations.
255
+
256
+ ### Medium-term
257
+
258
+ - **`canscan`** — sibling tool. Auto-detect the bitrate of an unknown bus by
259
+ entering listen-only mode and trying each standard rate until frames arrive
260
+ cleanly. Useful when probing an unknown vehicle network.
261
+ - **`canfind`** — map `canX` interfaces back to the physical adapter: USB
262
+ VID:PID, serial number, USB port path, product string. Indispensable when
263
+ four identical USB-CAN dongles are plugged in.
264
+ - **`cansync`** — one-shot synchronised down→configure→up across interfaces,
265
+ with an optional `--at <time>` for lab rigs that need deterministic startup.
266
+ - **Daemon mode for `canmon`** — long-running process that emits to
267
+ syslog/journald (for ops use) and exposes a Prometheus text-format
268
+ endpoint (for lab dashboards and long-term bus health recording).
269
+
270
+ ### Longer-term / speculative
271
+
272
+ - **python-can integration** — provide a small import so `canconf.discover()`
273
+ can feed bus factories, and so python-can users get the same topology
274
+ awareness without re-implementing it.
275
+ - **Test-mode** — `canconf test` sends a handful of frames between discovered
276
+ interfaces (pair-wise or via loopback) and verifies the wiring and bitrate
277
+ match end-to-end. Catches bench setup errors before you chase them in
278
+ protocol logs.
279
+ - **Termination auto-probe** — some CAN transceivers can report whether the
280
+ bus looks correctly terminated. If the driver exposes it, `canmon` should
281
+ surface it alongside the state column.
282
+
283
+ ## License
284
+
285
+ MIT — see [LICENSE](LICENSE).