jkctl 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.
- jkctl-0.1.0/.github/workflows/ci.yml +51 -0
- jkctl-0.1.0/.github/workflows/release.yml +53 -0
- jkctl-0.1.0/.gitignore +23 -0
- jkctl-0.1.0/CHANGELOG.md +36 -0
- jkctl-0.1.0/CONTRIBUTING.md +144 -0
- jkctl-0.1.0/LICENSE +287 -0
- jkctl-0.1.0/NOTICE +34 -0
- jkctl-0.1.0/PKG-INFO +278 -0
- jkctl-0.1.0/README.md +243 -0
- jkctl-0.1.0/biome.json +24 -0
- jkctl-0.1.0/docs/how-it-works.md +183 -0
- jkctl-0.1.0/docs/img/bank.png +0 -0
- jkctl-0.1.0/docs/img/dashboard.png +0 -0
- jkctl-0.1.0/docs/reference.md +290 -0
- jkctl-0.1.0/docs/usage.md +301 -0
- jkctl-0.1.0/docs/web-ui.md +701 -0
- jkctl-0.1.0/pyproject.toml +159 -0
- jkctl-0.1.0/src/jkctl/__init__.py +64 -0
- jkctl-0.1.0/src/jkctl/__main__.py +5 -0
- jkctl-0.1.0/src/jkctl/aes.py +359 -0
- jkctl-0.1.0/src/jkctl/cli/__init__.py +58 -0
- jkctl-0.1.0/src/jkctl/cli/commands/__init__.py +51 -0
- jkctl-0.1.0/src/jkctl/cli/commands/config.py +100 -0
- jkctl-0.1.0/src/jkctl/cli/commands/controls.py +278 -0
- jkctl-0.1.0/src/jkctl/cli/commands/devices.py +211 -0
- jkctl-0.1.0/src/jkctl/cli/commands/diag.py +136 -0
- jkctl-0.1.0/src/jkctl/cli/commands/firmware.py +357 -0
- jkctl-0.1.0/src/jkctl/cli/commands/history.py +134 -0
- jkctl-0.1.0/src/jkctl/cli/commands/protocols.py +264 -0
- jkctl-0.1.0/src/jkctl/cli/commands/registers.py +171 -0
- jkctl-0.1.0/src/jkctl/cli/commands/settings.py +274 -0
- jkctl-0.1.0/src/jkctl/cli/commands/status.py +338 -0
- jkctl-0.1.0/src/jkctl/cli/commands/ui.py +240 -0
- jkctl-0.1.0/src/jkctl/cli/exits.py +38 -0
- jkctl-0.1.0/src/jkctl/cli/fanout.py +57 -0
- jkctl-0.1.0/src/jkctl/cli/main.py +68 -0
- jkctl-0.1.0/src/jkctl/cli/parser.py +136 -0
- jkctl-0.1.0/src/jkctl/cli/report.py +66 -0
- jkctl-0.1.0/src/jkctl/cli/target.py +191 -0
- jkctl-0.1.0/src/jkctl/config.py +210 -0
- jkctl-0.1.0/src/jkctl/controls.py +201 -0
- jkctl-0.1.0/src/jkctl/device.py +439 -0
- jkctl-0.1.0/src/jkctl/doctor.py +366 -0
- jkctl-0.1.0/src/jkctl/errors.py +32 -0
- jkctl-0.1.0/src/jkctl/firmware.py +363 -0
- jkctl-0.1.0/src/jkctl/history.py +219 -0
- jkctl-0.1.0/src/jkctl/identity.py +161 -0
- jkctl-0.1.0/src/jkctl/logcodes.json +92 -0
- jkctl-0.1.0/src/jkctl/logcodes.py +74 -0
- jkctl-0.1.0/src/jkctl/modbus.py +630 -0
- jkctl-0.1.0/src/jkctl/names.py +300 -0
- jkctl-0.1.0/src/jkctl/probe.py +457 -0
- jkctl-0.1.0/src/jkctl/protocol.py +353 -0
- jkctl-0.1.0/src/jkctl/protocol_en.json +1 -0
- jkctl-0.1.0/src/jkctl/protocol_zh.json +1 -0
- jkctl-0.1.0/src/jkctl/protocols.json +299 -0
- jkctl-0.1.0/src/jkctl/registers.py +553 -0
- jkctl-0.1.0/src/jkctl/runtime.py +278 -0
- jkctl-0.1.0/src/jkctl/settings.py +303 -0
- jkctl-0.1.0/src/jkctl/simulator.py +557 -0
- jkctl-0.1.0/src/jkctl/tracing.py +200 -0
- jkctl-0.1.0/src/jkctl/upgrade.py +149 -0
- jkctl-0.1.0/src/jkctl/values.py +293 -0
- jkctl-0.1.0/src/jkctl/web/__init__.py +27 -0
- jkctl-0.1.0/src/jkctl/web/api.py +992 -0
- jkctl-0.1.0/src/jkctl/web/schema.py +408 -0
- jkctl-0.1.0/src/jkctl/web/server.py +112 -0
- jkctl-0.1.0/src/jkctl/web/session.py +449 -0
- jkctl-0.1.0/src/jkctl/web/static/app.css +423 -0
- jkctl-0.1.0/src/jkctl/web/static/index.html +30 -0
- jkctl-0.1.0/src/jkctl/web/static/js/api.js +55 -0
- jkctl-0.1.0/src/jkctl/web/static/js/app.js +1199 -0
- jkctl-0.1.0/src/jkctl/web/static/js/bands.js +380 -0
- jkctl-0.1.0/src/jkctl/web/static/js/bank.js +223 -0
- jkctl-0.1.0/src/jkctl/web/static/js/chart.js +299 -0
- jkctl-0.1.0/src/jkctl/web/static/js/dashboard.js +433 -0
- jkctl-0.1.0/src/jkctl/web/static/js/firmware.js +273 -0
- jkctl-0.1.0/src/jkctl/web/static/js/history.js +134 -0
- jkctl-0.1.0/src/jkctl/web/static/js/panels.js +176 -0
- jkctl-0.1.0/src/jkctl/web/static/js/ports.js +145 -0
- jkctl-0.1.0/src/jkctl/web/static/js/registers.js +144 -0
- jkctl-0.1.0/src/jkctl/web/static/js/settings.js +360 -0
- jkctl-0.1.0/src/jkctl/web/static/js/tools.js +510 -0
- jkctl-0.1.0/tests/conftest.py +224 -0
- jkctl-0.1.0/tests/test_aes.py +41 -0
- jkctl-0.1.0/tests/test_cli_commands.py +535 -0
- jkctl-0.1.0/tests/test_cli_core.py +253 -0
- jkctl-0.1.0/tests/test_config.py +123 -0
- jkctl-0.1.0/tests/test_device.py +227 -0
- jkctl-0.1.0/tests/test_errors.py +53 -0
- jkctl-0.1.0/tests/test_fakes.py +43 -0
- jkctl-0.1.0/tests/test_firmware.py +302 -0
- jkctl-0.1.0/tests/test_frontlint.py +44 -0
- jkctl-0.1.0/tests/test_history.py +109 -0
- jkctl-0.1.0/tests/test_htmcheck.py +40 -0
- jkctl-0.1.0/tests/test_identity.py +36 -0
- jkctl-0.1.0/tests/test_modbus.py +224 -0
- jkctl-0.1.0/tests/test_names.py +39 -0
- jkctl-0.1.0/tests/test_protocol.py +139 -0
- jkctl-0.1.0/tests/test_registers.py +249 -0
- jkctl-0.1.0/tests/test_settings.py +111 -0
- jkctl-0.1.0/tests/test_tracing.py +217 -0
- jkctl-0.1.0/tests/test_values.py +100 -0
- jkctl-0.1.0/tests/test_web_api.py +438 -0
- jkctl-0.1.0/tests/test_web_schema.py +100 -0
- jkctl-0.1.0/tests/test_web_server.py +206 -0
- jkctl-0.1.0/tests/test_web_session.py +232 -0
- jkctl-0.1.0/tests/webfake.py +46 -0
- jkctl-0.1.0/tools/rendercheck.py +39 -0
- jkctl-0.1.0/tools/screenshot.py +179 -0
- jkctl-0.1.0/uv.lock +382 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: ["**"]
|
|
6
|
+
# A pull request from a branch of this repository was already checked by
|
|
7
|
+
# the push above; listening to both would run every one of them twice.
|
|
8
|
+
# A fork's branch produces no push event here, so the `if` on the job
|
|
9
|
+
# below lets those -- and only those -- through.
|
|
10
|
+
pull_request:
|
|
11
|
+
# release.yml calls this workflow before it builds, so a tag cannot
|
|
12
|
+
# publish what the checks have not passed.
|
|
13
|
+
workflow_call:
|
|
14
|
+
|
|
15
|
+
permissions:
|
|
16
|
+
contents: read
|
|
17
|
+
|
|
18
|
+
# A newer commit on the same branch makes the older run's answer moot.
|
|
19
|
+
concurrency:
|
|
20
|
+
group: ci-${{ github.event.pull_request.number || github.ref }}
|
|
21
|
+
cancel-in-progress: true
|
|
22
|
+
|
|
23
|
+
jobs:
|
|
24
|
+
test:
|
|
25
|
+
if: >-
|
|
26
|
+
github.event_name != 'pull_request' ||
|
|
27
|
+
github.event.pull_request.head.repo.full_name != github.repository
|
|
28
|
+
runs-on: ubuntu-latest
|
|
29
|
+
strategy:
|
|
30
|
+
fail-fast: false
|
|
31
|
+
matrix:
|
|
32
|
+
python-version: ["3.10", "3.12", "3.14"]
|
|
33
|
+
steps:
|
|
34
|
+
- uses: actions/checkout@v4
|
|
35
|
+
- uses: astral-sh/setup-uv@v5
|
|
36
|
+
with:
|
|
37
|
+
python-version: ${{ matrix.python-version }}
|
|
38
|
+
enable-cache: true
|
|
39
|
+
# --locked: a uv.lock that no longer matches pyproject.toml is a
|
|
40
|
+
# mistake to report, not one to paper over with a fresh resolution.
|
|
41
|
+
# --group browser: the V8 htmcheck parses templates in is kept out of
|
|
42
|
+
# the default set so that installing and developing jkctl stays light
|
|
43
|
+
# on an armv7 host. CI is where it must not be missing: without it
|
|
44
|
+
# htmcheck and its tests would skip, and skip green.
|
|
45
|
+
- run: uv sync --locked --group browser
|
|
46
|
+
- run: uv run ruff format --check .
|
|
47
|
+
- run: uv run ruff check .
|
|
48
|
+
- run: uv run ty check
|
|
49
|
+
# The browser half: Biome parses and lints it, and the two cross-file
|
|
50
|
+
# checks out of `devicectl.devtools` run under pytest.
|
|
51
|
+
- run: uv run pytest
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: ["v*"]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
# A tag must not publish what the checks have not passed.
|
|
12
|
+
check:
|
|
13
|
+
uses: ./.github/workflows/ci.yml
|
|
14
|
+
|
|
15
|
+
publish:
|
|
16
|
+
needs: check
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
environment: pypi
|
|
19
|
+
permissions:
|
|
20
|
+
contents: write # to create the GitHub release
|
|
21
|
+
id-token: write # for PyPI trusted publishing; no token to keep
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v4
|
|
24
|
+
- uses: astral-sh/setup-uv@v5
|
|
25
|
+
with:
|
|
26
|
+
enable-cache: true
|
|
27
|
+
|
|
28
|
+
# The version lives in one place. A tag that disagrees with it would
|
|
29
|
+
# publish something under a name nobody can reproduce from the source.
|
|
30
|
+
- name: The tag must match __version__
|
|
31
|
+
run: |
|
|
32
|
+
tag="${GITHUB_REF_NAME#v}"
|
|
33
|
+
version="$(grep -Po '(?<=^__version__ = ")[^"]+' src/jkctl/__init__.py)"
|
|
34
|
+
if [ "$tag" != "$version" ]; then
|
|
35
|
+
echo "tag $tag does not match __version__ $version" >&2
|
|
36
|
+
exit 1
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
- run: uv build
|
|
40
|
+
|
|
41
|
+
# Install the wheel that is about to be published, on its own, and see
|
|
42
|
+
# that it runs -- a missing package data file would show up here.
|
|
43
|
+
- name: Smoke-test the built wheel
|
|
44
|
+
run: |
|
|
45
|
+
uv run --no-project --with dist/*.whl jkctl --version
|
|
46
|
+
uv run --no-project --with dist/*.whl jkctl protocols list --can
|
|
47
|
+
|
|
48
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
49
|
+
|
|
50
|
+
- name: Create the GitHub release
|
|
51
|
+
env:
|
|
52
|
+
GH_TOKEN: ${{ github.token }}
|
|
53
|
+
run: gh release create "$GITHUB_REF_NAME" --generate-notes dist/*
|
jkctl-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
.venv/
|
|
6
|
+
venv/
|
|
7
|
+
|
|
8
|
+
# Never commit vendor firmware images or encrypted datasource containers
|
|
9
|
+
*.jkbms
|
|
10
|
+
*.jsonds
|
|
11
|
+
*.bin
|
|
12
|
+
*.hex
|
|
13
|
+
|
|
14
|
+
# Probe output and local scratch
|
|
15
|
+
probe-result*.json
|
|
16
|
+
probe-result*.log
|
|
17
|
+
probe*.json
|
|
18
|
+
probe*.log
|
|
19
|
+
|
|
20
|
+
# Build output and tool caches
|
|
21
|
+
/dist/
|
|
22
|
+
.ruff_cache/
|
|
23
|
+
.pytest_cache/
|
jkctl-0.1.0/CHANGELOG.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Notable changes, newest first. The version is set in `src/jkctl/__init__.py`;
|
|
4
|
+
tagging `vX.Y.Z` publishes it (see `.github/workflows/release.yml`).
|
|
5
|
+
|
|
6
|
+
## 0.1.0 — 2026-09-26
|
|
7
|
+
|
|
8
|
+
The first release. A tool for JK BMS battery management systems on an RS485
|
|
9
|
+
bus, reimplemented from JK's own Windows application and register-map
|
|
10
|
+
documents. It requires `devicectl-core>=0.1.0`.
|
|
11
|
+
|
|
12
|
+
What it does:
|
|
13
|
+
|
|
14
|
+
- **Finds and reads a bus.** Scans the sixteen addresses, reports nameplate,
|
|
15
|
+
live pack data, per-cell voltages and resistances, alarms, the board's own
|
|
16
|
+
fault history, and every register of every table -- one board or the whole
|
|
17
|
+
bank at once, as text or `--json`.
|
|
18
|
+
- **Writes the configuration.** The whole settings table, typed, scaled and
|
|
19
|
+
range-checked against JK's own datasource before anything goes out, with a
|
|
20
|
+
write always showing what it will change; the one-key chemistry presets, the
|
|
21
|
+
three main switches, the multiplexed on/off settings, the port protocols and
|
|
22
|
+
the dry contacts.
|
|
23
|
+
- **Board actions.** The emergency start, the power-off, calibration, the
|
|
24
|
+
address, the clock, and the three actions JK's document does not list.
|
|
25
|
+
- **Firmware.** Validates and flashes a `.jkbms` file the way JK's own
|
|
26
|
+
application does, needing no crypto package (PyCryptodome, `cryptography`,
|
|
27
|
+
system OpenSSL, or a bundled pure-Python AES).
|
|
28
|
+
- **A web interface, first.** `jkctl` with no command serves a local page and
|
|
29
|
+
opens a browser on it -- the bank as tiles, live dashboards, draggable
|
|
30
|
+
setpoint bands, and every command the terminal has -- built on the shared
|
|
31
|
+
`devicectl-core` design system with no build step.
|
|
32
|
+
- **Diagnostics.** `jkctl probe` characterises a silent bus, `jkctl doctor`
|
|
33
|
+
reports what looks wrong, `jkctl simulate` serves a fake BMS, and a serial
|
|
34
|
+
trace can be turned on from the page and sent on.
|
|
35
|
+
|
|
36
|
+
See the [README](README.md) and [docs](docs/) for what each of those does.
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
## Getting set up
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
uv sync
|
|
7
|
+
uv run pytest
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
That is the light set -- pytest, ruff, ty -- pure Python, quick, and it
|
|
11
|
+
installs anywhere the program does. The two checks that need a real engine
|
|
12
|
+
(an embedded V8, a headless Chromium) are in a separate `browser` group:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
uv sync --group browser
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Take it if you touch the web UI. It is opt-in because jkctl is meant to run
|
|
19
|
+
on small hosts -- a Raspberry Pi 3 reports `armv7l`, and `mini-racer`
|
|
20
|
+
publishes no armv7 wheel, so having it in the default set would turn
|
|
21
|
+
`uv run jkctl` in a checkout into a V8 build. Once the group is synced a
|
|
22
|
+
plain `uv run` keeps it; a plain `uv sync` trims back to the light set.
|
|
23
|
+
|
|
24
|
+
Everything the checks run:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
uv run ruff format --check .
|
|
28
|
+
uv run ruff check .
|
|
29
|
+
uv run ty check
|
|
30
|
+
uv run pytest
|
|
31
|
+
biome ci src/jkctl/web/static/ # the browser half
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
[Biome] is a single native binary and needs no Node (`pacman -S biome`, a
|
|
35
|
+
release binary, or `npx @biomejs/biome`). It is not a project dependency, and
|
|
36
|
+
the two Python checks run under `pytest` as well, so a plain `uv run pytest`
|
|
37
|
+
covers the browser half too -- `htmcheck` and its tests skip themselves,
|
|
38
|
+
saying which group to sync, when the V8 is not there.
|
|
39
|
+
|
|
40
|
+
Two more need a browser, so they are not in that list and are not run under
|
|
41
|
+
`pytest`. They drive the real page over `jkctl ui --simulate`, which puts a
|
|
42
|
+
bank of fake boards on an in-memory bus and needs no hardware:
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
uv sync --group browser # once: playwright
|
|
46
|
+
uv run python -m playwright install chromium # once: the browser itself
|
|
47
|
+
uv run tools/rendercheck.py # what only a layout engine sees
|
|
48
|
+
uv run tools/screenshot.py # docs/img/, for the README
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`rendercheck` is worth running after anything that touches the page. Every
|
|
52
|
+
defect it looks for got past all seven checks above: a value column wide
|
|
53
|
+
enough to push four columns off-screen, a model number split across two
|
|
54
|
+
lines, a tab that renders nothing because an import was mistyped. None of
|
|
55
|
+
them is a crash, so nothing without a layout engine can see them.
|
|
56
|
+
|
|
57
|
+
[Biome]: https://biomejs.dev/
|
|
58
|
+
|
|
59
|
+
## How the code is laid out
|
|
60
|
+
|
|
61
|
+
`src/jkctl/` is one module per subject, and **none of them prints**. Only
|
|
62
|
+
`cli/` prints, prompts, or returns exit codes. That is what keeps the device
|
|
63
|
+
logic testable and what would let a second front end reuse it unchanged.
|
|
64
|
+
|
|
65
|
+
- `modbus.py` is the wire: framing, CRC, retries, the register bases.
|
|
66
|
+
- `protocol.py` is the field layout, parsed from JK's own datasource.
|
|
67
|
+
- `registers.py` joins the two: a named, typed, bounded, addressable register,
|
|
68
|
+
and whether JK's document marks it writable.
|
|
69
|
+
- `values.py` turns what someone typed into what the wire takes, and refuses
|
|
70
|
+
what will not fit.
|
|
71
|
+
- `device.py` is one BMS, read and written by field name.
|
|
72
|
+
- `identity.py`, `runtime.py`, `settings.py`, `controls.py` are one subject
|
|
73
|
+
each, built on `device.py`.
|
|
74
|
+
- `firmware.py` and `upgrade.py` are the `.jkbms` container and the transfer.
|
|
75
|
+
- `doctor.py` is composition over those: one read, and everything that can be
|
|
76
|
+
concluded from holding two of its numbers up against each other.
|
|
77
|
+
- `history.py` and `logcodes.py` are the board's own stored records: the
|
|
78
|
+
layout, and what JK calls each code.
|
|
79
|
+
- `web/` is the second front end, and it obeys the same rule: it prints
|
|
80
|
+
nothing and decides nothing about the device, it calls the same modules the
|
|
81
|
+
commands call. `web/session.py` owns the serial port and runs every request
|
|
82
|
+
through one worker, because only one program can hold a port and only one
|
|
83
|
+
place should know that.
|
|
84
|
+
|
|
85
|
+
## The browser half
|
|
86
|
+
|
|
87
|
+
`src/jkctl/web/static/` is plain ES modules and plain CSS -- edit and reload,
|
|
88
|
+
there is nothing to build, and the files that ship in the wheel are the files
|
|
89
|
+
you edit. Three things check it in place of a build step:
|
|
90
|
+
|
|
91
|
+
- **Biome** parses and lints it, better than anything hand-written here could.
|
|
92
|
+
- **`devicectl.devtools.frontlint`** looks across the files, which is normally
|
|
93
|
+
a bundler's job: every import has to name a file that exists and a name it
|
|
94
|
+
exports, and every export has to be imported by somebody. Without it a
|
|
95
|
+
mistyped path is a blank page found by reloading and not before.
|
|
96
|
+
- **`devicectl.devtools.htmcheck`** renders every `html` template through the vendored
|
|
97
|
+
preact-htm bundle -- the same parser the browser runs -- and reports the one
|
|
98
|
+
shape no valid output contains. An attribute that lost its `$` does not
|
|
99
|
+
crash the page; it quietly swallows the markup up to the next `}`.
|
|
100
|
+
|
|
101
|
+
Adding a tab means a module in `static/js/`, an entry in `TABS` in `app.js`,
|
|
102
|
+
and an endpoint in `web/api.py` that calls the module the CLI already calls.
|
|
103
|
+
Do not reach for the device from a request handler: hand the work to the
|
|
104
|
+
worker, which owns the port.
|
|
105
|
+
|
|
106
|
+
## Adding a command
|
|
107
|
+
|
|
108
|
+
Write the handler in the right module of `src/jkctl/cli/commands/`, describe
|
|
109
|
+
it in that module's `add_parsers`, and name it in that module's `COMMANDS`.
|
|
110
|
+
Nothing outside that file changes. If the command needs no serial port, or
|
|
111
|
+
only a bus rather than one addressed unit, say so with `Need` in the
|
|
112
|
+
`Command` -- do not open anything yourself.
|
|
113
|
+
|
|
114
|
+
## Tests
|
|
115
|
+
|
|
116
|
+
No test may need hardware, a serial port or a network. The suite wires a real
|
|
117
|
+
`modbus.Bus` straight to `simulator.Sim` in memory (`tests/conftest.py`), so a
|
|
118
|
+
CLI test exercises the actual framing, chunking and decoding. If you teach the
|
|
119
|
+
tool about a new device behaviour, teach the simulator about it too -- that is
|
|
120
|
+
what stops the tool being tested against a model of the device that is kinder
|
|
121
|
+
than the device.
|
|
122
|
+
|
|
123
|
+
CLI tests call `cli.main([...])` and assert on the exit code and `capsys`.
|
|
124
|
+
Prompts are tested by patching `builtins.input`, including the `EOFError`
|
|
125
|
+
case, because a command left running unattended must stop rather than raise.
|
|
126
|
+
|
|
127
|
+
## Writing about the device
|
|
128
|
+
|
|
129
|
+
Every non-obvious constant, refusal and workaround in this codebase exists
|
|
130
|
+
because a real unit behaved that way. Say so in the comment, and say how it is
|
|
131
|
+
known -- a measurement, JK's own document, or a function in the decompiled
|
|
132
|
+
application. A comment that says *what* the code does is worth little; one
|
|
133
|
+
that says why the device made it necessary is worth a great deal, and it is
|
|
134
|
+
the only defence against someone later "simplifying" a workaround away.
|
|
135
|
+
|
|
136
|
+
Anything not yet proven against hardware must say so, in the docstring and in
|
|
137
|
+
`docs/reference.md`.
|
|
138
|
+
|
|
139
|
+
## Before you send it
|
|
140
|
+
|
|
141
|
+
- `uv run ruff format . && uv run ruff check . && uv run ty check && uv run pytest`
|
|
142
|
+
- New device behaviour recorded in `research/windows/windows-findings.md`
|
|
143
|
+
with its evidence.
|
|
144
|
+
- `docs/reference.md` updated if you changed what is proven or what is not.
|
jkctl-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
EUROPEAN UNION PUBLIC LICENCE v. 1.2
|
|
2
|
+
EUPL © the European Union 2007, 2016
|
|
3
|
+
|
|
4
|
+
This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined
|
|
5
|
+
below) which is provided under the terms of this Licence. Any use of the Work,
|
|
6
|
+
other than as authorised under this Licence is prohibited (to the extent such
|
|
7
|
+
use is covered by a right of the copyright holder of the Work).
|
|
8
|
+
|
|
9
|
+
The Work is provided under the terms of this Licence when the Licensor (as
|
|
10
|
+
defined below) has placed the following notice immediately following the
|
|
11
|
+
copyright notice for the Work:
|
|
12
|
+
|
|
13
|
+
Licensed under the EUPL
|
|
14
|
+
|
|
15
|
+
or has expressed by any other means his willingness to license under the EUPL.
|
|
16
|
+
|
|
17
|
+
1. Definitions
|
|
18
|
+
|
|
19
|
+
In this Licence, the following terms have the following meaning:
|
|
20
|
+
|
|
21
|
+
- ‘The Licence’: this Licence.
|
|
22
|
+
|
|
23
|
+
- ‘The Original Work’: the work or software distributed or communicated by the
|
|
24
|
+
Licensor under this Licence, available as Source Code and also as Executable
|
|
25
|
+
Code as the case may be.
|
|
26
|
+
|
|
27
|
+
- ‘Derivative Works’: the works or software that could be created by the
|
|
28
|
+
Licensee, based upon the Original Work or modifications thereof. This Licence
|
|
29
|
+
does not define the extent of modification or dependence on the Original Work
|
|
30
|
+
required in order to classify a work as a Derivative Work; this extent is
|
|
31
|
+
determined by copyright law applicable in the country mentioned in Article 15.
|
|
32
|
+
|
|
33
|
+
- ‘The Work’: the Original Work or its Derivative Works.
|
|
34
|
+
|
|
35
|
+
- ‘The Source Code’: the human-readable form of the Work which is the most
|
|
36
|
+
convenient for people to study and modify.
|
|
37
|
+
|
|
38
|
+
- ‘The Executable Code’: any code which has generally been compiled and which is
|
|
39
|
+
meant to be interpreted by a computer as a program.
|
|
40
|
+
|
|
41
|
+
- ‘The Licensor’: the natural or legal person that distributes or communicates
|
|
42
|
+
the Work under the Licence.
|
|
43
|
+
|
|
44
|
+
- ‘Contributor(s)’: any natural or legal person who modifies the Work under the
|
|
45
|
+
Licence, or otherwise contributes to the creation of a Derivative Work.
|
|
46
|
+
|
|
47
|
+
- ‘The Licensee’ or ‘You’: any natural or legal person who makes any usage of
|
|
48
|
+
the Work under the terms of the Licence.
|
|
49
|
+
|
|
50
|
+
- ‘Distribution’ or ‘Communication’: any act of selling, giving, lending,
|
|
51
|
+
renting, distributing, communicating, transmitting, or otherwise making
|
|
52
|
+
available, online or offline, copies of the Work or providing access to its
|
|
53
|
+
essential functionalities at the disposal of any other natural or legal
|
|
54
|
+
person.
|
|
55
|
+
|
|
56
|
+
2. Scope of the rights granted by the Licence
|
|
57
|
+
|
|
58
|
+
The Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
|
|
59
|
+
sublicensable licence to do the following, for the duration of copyright vested
|
|
60
|
+
in the Original Work:
|
|
61
|
+
|
|
62
|
+
- use the Work in any circumstance and for all usage,
|
|
63
|
+
- reproduce the Work,
|
|
64
|
+
- modify the Work, and make Derivative Works based upon the Work,
|
|
65
|
+
- communicate to the public, including the right to make available or display
|
|
66
|
+
the Work or copies thereof to the public and perform publicly, as the case may
|
|
67
|
+
be, the Work,
|
|
68
|
+
- distribute the Work or copies thereof,
|
|
69
|
+
- lend and rent the Work or copies thereof,
|
|
70
|
+
- sublicense rights in the Work or copies thereof.
|
|
71
|
+
|
|
72
|
+
Those rights can be exercised on any media, supports and formats, whether now
|
|
73
|
+
known or later invented, as far as the applicable law permits so.
|
|
74
|
+
|
|
75
|
+
In the countries where moral rights apply, the Licensor waives his right to
|
|
76
|
+
exercise his moral right to the extent allowed by law in order to make effective
|
|
77
|
+
the licence of the economic rights here above listed.
|
|
78
|
+
|
|
79
|
+
The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to
|
|
80
|
+
any patents held by the Licensor, to the extent necessary to make use of the
|
|
81
|
+
rights granted on the Work under this Licence.
|
|
82
|
+
|
|
83
|
+
3. Communication of the Source Code
|
|
84
|
+
|
|
85
|
+
The Licensor may provide the Work either in its Source Code form, or as
|
|
86
|
+
Executable Code. If the Work is provided as Executable Code, the Licensor
|
|
87
|
+
provides in addition a machine-readable copy of the Source Code of the Work
|
|
88
|
+
along with each copy of the Work that the Licensor distributes or indicates, in
|
|
89
|
+
a notice following the copyright notice attached to the Work, a repository where
|
|
90
|
+
the Source Code is easily and freely accessible for as long as the Licensor
|
|
91
|
+
continues to distribute or communicate the Work.
|
|
92
|
+
|
|
93
|
+
4. Limitations on copyright
|
|
94
|
+
|
|
95
|
+
Nothing in this Licence is intended to deprive the Licensee of the benefits from
|
|
96
|
+
any exception or limitation to the exclusive rights of the rights owners in the
|
|
97
|
+
Work, of the exhaustion of those rights or of other applicable limitations
|
|
98
|
+
thereto.
|
|
99
|
+
|
|
100
|
+
5. Obligations of the Licensee
|
|
101
|
+
|
|
102
|
+
The grant of the rights mentioned above is subject to some restrictions and
|
|
103
|
+
obligations imposed on the Licensee. Those obligations are the following:
|
|
104
|
+
|
|
105
|
+
Attribution right: The Licensee shall keep intact all copyright, patent or
|
|
106
|
+
trademarks notices and all notices that refer to the Licence and to the
|
|
107
|
+
disclaimer of warranties. The Licensee must include a copy of such notices and a
|
|
108
|
+
copy of the Licence with every copy of the Work he/she distributes or
|
|
109
|
+
communicates. The Licensee must cause any Derivative Work to carry prominent
|
|
110
|
+
notices stating that the Work has been modified and the date of modification.
|
|
111
|
+
|
|
112
|
+
Copyleft clause: If the Licensee distributes or communicates copies of the
|
|
113
|
+
Original Works or Derivative Works, this Distribution or Communication will be
|
|
114
|
+
done under the terms of this Licence or of a later version of this Licence
|
|
115
|
+
unless the Original Work is expressly distributed only under this version of the
|
|
116
|
+
Licence — for example by communicating ‘EUPL v. 1.2 only’. The Licensee
|
|
117
|
+
(becoming Licensor) cannot offer or impose any additional terms or conditions on
|
|
118
|
+
the Work or Derivative Work that alter or restrict the terms of the Licence.
|
|
119
|
+
|
|
120
|
+
Compatibility clause: If the Licensee Distributes or Communicates Derivative
|
|
121
|
+
Works or copies thereof based upon both the Work and another work licensed under
|
|
122
|
+
a Compatible Licence, this Distribution or Communication can be done under the
|
|
123
|
+
terms of this Compatible Licence. For the sake of this clause, ‘Compatible
|
|
124
|
+
Licence’ refers to the licences listed in the appendix attached to this Licence.
|
|
125
|
+
Should the Licensee's obligations under the Compatible Licence conflict with
|
|
126
|
+
his/her obligations under this Licence, the obligations of the Compatible
|
|
127
|
+
Licence shall prevail.
|
|
128
|
+
|
|
129
|
+
Provision of Source Code: When distributing or communicating copies of the Work,
|
|
130
|
+
the Licensee will provide a machine-readable copy of the Source Code or indicate
|
|
131
|
+
a repository where this Source will be easily and freely available for as long
|
|
132
|
+
as the Licensee continues to distribute or communicate the Work.
|
|
133
|
+
|
|
134
|
+
Legal Protection: This Licence does not grant permission to use the trade names,
|
|
135
|
+
trademarks, service marks, or names of the Licensor, except as required for
|
|
136
|
+
reasonable and customary use in describing the origin of the Work and
|
|
137
|
+
reproducing the content of the copyright notice.
|
|
138
|
+
|
|
139
|
+
6. Chain of Authorship
|
|
140
|
+
|
|
141
|
+
The original Licensor warrants that the copyright in the Original Work granted
|
|
142
|
+
hereunder is owned by him/her or licensed to him/her and that he/she has the
|
|
143
|
+
power and authority to grant the Licence.
|
|
144
|
+
|
|
145
|
+
Each Contributor warrants that the copyright in the modifications he/she brings
|
|
146
|
+
to the Work are owned by him/her or licensed to him/her and that he/she has the
|
|
147
|
+
power and authority to grant the Licence.
|
|
148
|
+
|
|
149
|
+
Each time You accept the Licence, the original Licensor and subsequent
|
|
150
|
+
Contributors grant You a licence to their contributions to the Work, under the
|
|
151
|
+
terms of this Licence.
|
|
152
|
+
|
|
153
|
+
7. Disclaimer of Warranty
|
|
154
|
+
|
|
155
|
+
The Work is a work in progress, which is continuously improved by numerous
|
|
156
|
+
Contributors. It is not a finished work and may therefore contain defects or
|
|
157
|
+
‘bugs’ inherent to this type of development.
|
|
158
|
+
|
|
159
|
+
For the above reason, the Work is provided under the Licence on an ‘as is’ basis
|
|
160
|
+
and without warranties of any kind concerning the Work, including without
|
|
161
|
+
limitation merchantability, fitness for a particular purpose, absence of defects
|
|
162
|
+
or errors, accuracy, non-infringement of intellectual property rights other than
|
|
163
|
+
copyright as stated in Article 6 of this Licence.
|
|
164
|
+
|
|
165
|
+
This disclaimer of warranty is an essential part of the Licence and a condition
|
|
166
|
+
for the grant of any rights to the Work.
|
|
167
|
+
|
|
168
|
+
8. Disclaimer of Liability
|
|
169
|
+
|
|
170
|
+
Except in the cases of wilful misconduct or damages directly caused to natural
|
|
171
|
+
persons, the Licensor will in no event be liable for any direct or indirect,
|
|
172
|
+
material or moral, damages of any kind, arising out of the Licence or of the use
|
|
173
|
+
of the Work, including without limitation, damages for loss of goodwill, work
|
|
174
|
+
stoppage, computer failure or malfunction, loss of data or any commercial
|
|
175
|
+
damage, even if the Licensor has been advised of the possibility of such damage.
|
|
176
|
+
However, the Licensor will be liable under statutory product liability laws as
|
|
177
|
+
far such laws apply to the Work.
|
|
178
|
+
|
|
179
|
+
9. Additional agreements
|
|
180
|
+
|
|
181
|
+
While distributing the Work, You may choose to conclude an additional agreement,
|
|
182
|
+
defining obligations or services consistent with this Licence. However, if
|
|
183
|
+
accepting obligations, You may act only on your own behalf and on your sole
|
|
184
|
+
responsibility, not on behalf of the original Licensor or any other Contributor,
|
|
185
|
+
and only if You agree to indemnify, defend, and hold each Contributor harmless
|
|
186
|
+
for any liability incurred by, or claims asserted against such Contributor by
|
|
187
|
+
the fact You have accepted any warranty or additional liability.
|
|
188
|
+
|
|
189
|
+
10. Acceptance of the Licence
|
|
190
|
+
|
|
191
|
+
The provisions of this Licence can be accepted by clicking on an icon ‘I agree’
|
|
192
|
+
placed under the bottom of a window displaying the text of this Licence or by
|
|
193
|
+
affirming consent in any other similar way, in accordance with the rules of
|
|
194
|
+
applicable law. Clicking on that icon indicates your clear and irrevocable
|
|
195
|
+
acceptance of this Licence and all of its terms and conditions.
|
|
196
|
+
|
|
197
|
+
Similarly, you irrevocably accept this Licence and all of its terms and
|
|
198
|
+
conditions by exercising any rights granted to You by Article 2 of this Licence,
|
|
199
|
+
such as the use of the Work, the creation by You of a Derivative Work or the
|
|
200
|
+
Distribution or Communication by You of the Work or copies thereof.
|
|
201
|
+
|
|
202
|
+
11. Information to the public
|
|
203
|
+
|
|
204
|
+
In case of any Distribution or Communication of the Work by means of electronic
|
|
205
|
+
communication by You (for example, by offering to download the Work from a
|
|
206
|
+
remote location) the distribution channel or media (for example, a website) must
|
|
207
|
+
at least provide to the public the information requested by the applicable law
|
|
208
|
+
regarding the Licensor, the Licence and the way it may be accessible, concluded,
|
|
209
|
+
stored and reproduced by the Licensee.
|
|
210
|
+
|
|
211
|
+
12. Termination of the Licence
|
|
212
|
+
|
|
213
|
+
The Licence and the rights granted hereunder will terminate automatically upon
|
|
214
|
+
any breach by the Licensee of the terms of the Licence.
|
|
215
|
+
|
|
216
|
+
Such a termination will not terminate the licences of any person who has
|
|
217
|
+
received the Work from the Licensee under the Licence, provided such persons
|
|
218
|
+
remain in full compliance with the Licence.
|
|
219
|
+
|
|
220
|
+
13. Miscellaneous
|
|
221
|
+
|
|
222
|
+
Without prejudice of Article 9 above, the Licence represents the complete
|
|
223
|
+
agreement between the Parties as to the Work.
|
|
224
|
+
|
|
225
|
+
If any provision of the Licence is invalid or unenforceable under applicable
|
|
226
|
+
law, this will not affect the validity or enforceability of the Licence as a
|
|
227
|
+
whole. Such provision will be construed or reformed so as necessary to make it
|
|
228
|
+
valid and enforceable.
|
|
229
|
+
|
|
230
|
+
The European Commission may publish other linguistic versions or new versions of
|
|
231
|
+
this Licence or updated versions of the Appendix, so far this is required and
|
|
232
|
+
reasonable, without reducing the scope of the rights granted by the Licence. New
|
|
233
|
+
versions of the Licence will be published with a unique version number.
|
|
234
|
+
|
|
235
|
+
All linguistic versions of this Licence, approved by the European Commission,
|
|
236
|
+
have identical value. Parties can take advantage of the linguistic version of
|
|
237
|
+
their choice.
|
|
238
|
+
|
|
239
|
+
14. Jurisdiction
|
|
240
|
+
|
|
241
|
+
Without prejudice to specific agreement between parties,
|
|
242
|
+
|
|
243
|
+
- any litigation resulting from the interpretation of this License, arising
|
|
244
|
+
between the European Union institutions, bodies, offices or agencies, as a
|
|
245
|
+
Licensor, and any Licensee, will be subject to the jurisdiction of the Court
|
|
246
|
+
of Justice of the European Union, as laid down in article 272 of the Treaty on
|
|
247
|
+
the Functioning of the European Union,
|
|
248
|
+
|
|
249
|
+
- any litigation arising between other parties and resulting from the
|
|
250
|
+
interpretation of this License, will be subject to the exclusive jurisdiction
|
|
251
|
+
of the competent court where the Licensor resides or conducts its primary
|
|
252
|
+
business.
|
|
253
|
+
|
|
254
|
+
15. Applicable Law
|
|
255
|
+
|
|
256
|
+
Without prejudice to specific agreement between parties,
|
|
257
|
+
|
|
258
|
+
- this Licence shall be governed by the law of the European Union Member State
|
|
259
|
+
where the Licensor has his seat, resides or has his registered office,
|
|
260
|
+
|
|
261
|
+
- this licence shall be governed by Belgian law if the Licensor has no seat,
|
|
262
|
+
residence or registered office inside a European Union Member State.
|
|
263
|
+
|
|
264
|
+
Appendix
|
|
265
|
+
|
|
266
|
+
‘Compatible Licences’ according to Article 5 EUPL are:
|
|
267
|
+
|
|
268
|
+
- GNU General Public License (GPL) v. 2, v. 3
|
|
269
|
+
- GNU Affero General Public License (AGPL) v. 3
|
|
270
|
+
- Open Software License (OSL) v. 2.1, v. 3.0
|
|
271
|
+
- Eclipse Public License (EPL) v. 1.0
|
|
272
|
+
- CeCILL v. 2.0, v. 2.1
|
|
273
|
+
- Mozilla Public Licence (MPL) v. 2
|
|
274
|
+
- GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
|
|
275
|
+
- Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for
|
|
276
|
+
works other than software
|
|
277
|
+
- European Union Public Licence (EUPL) v. 1.1, v. 1.2
|
|
278
|
+
- Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong
|
|
279
|
+
Reciprocity (LiLiQ-R+).
|
|
280
|
+
|
|
281
|
+
The European Commission may update this Appendix to later versions of the above
|
|
282
|
+
licences without producing a new version of the EUPL, as long as they provide
|
|
283
|
+
the rights granted in Article 2 of this Licence and protect the covered Source
|
|
284
|
+
Code from exclusive appropriation.
|
|
285
|
+
|
|
286
|
+
All other changes or additions to this Appendix require the production of a new
|
|
287
|
+
EUPL version.
|
jkctl-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
NOTICE
|
|
2
|
+
======
|
|
3
|
+
|
|
4
|
+
This project is licensed under the European Union Public Licence v1.2
|
|
5
|
+
(EUPL-1.2) -- see LICENSE. Five files shipped in this distribution are not
|
|
6
|
+
covered by that license and remain under their own terms:
|
|
7
|
+
|
|
8
|
+
* ``src/jkctl/protocol_en.json`` and ``src/jkctl/protocol_zh.json`` -- the
|
|
9
|
+
BMS frame and field layout, decrypted from ``config/en_US.jsonds`` and
|
|
10
|
+
``config/zh_CN.jsonds`` as shipped with JK BMS Monitor 3.11.0. Copyright
|
|
11
|
+
Chengdu JIKONG Technology Co., Ltd. Included unmodified (beyond
|
|
12
|
+
decryption) for interoperability with JK battery management systems; no
|
|
13
|
+
license to redistribute them is granted by this project beyond what
|
|
14
|
+
their copyright holder allows.
|
|
15
|
+
|
|
16
|
+
* ``src/jkctl/protocols.json`` -- the UART, CAN and trigger-source lists
|
|
17
|
+
the same application shows in its drop-downs, extracted from its
|
|
18
|
+
resources. The English column beside each is this project's own
|
|
19
|
+
translation and is covered by the EUPL like the rest of it. Same
|
|
20
|
+
copyright holder for the original strings, same terms.
|
|
21
|
+
|
|
22
|
+
* ``src/jkctl/logcodes.json`` -- what the same application calls each code
|
|
23
|
+
a JK board writes into its stored fault records, extracted from its
|
|
24
|
+
code. Same copyright holder, same terms.
|
|
25
|
+
|
|
26
|
+
How all four were obtained is recorded in ``docs/how-it-works.md`` and,
|
|
27
|
+
in full, in ``research/windows/windows-findings.md``.
|
|
28
|
+
|
|
29
|
+
* ``src/jkctl/web/static/vendor/preact-htm.module.js`` -- Preact and htm,
|
|
30
|
+
bundled as one ES module. Copyright Jason Miller and contributors, MIT
|
|
31
|
+
License; the full notice is embedded as a comment at the top of the file.
|
|
32
|
+
Upstream: https://preactjs.com/ and https://github.com/developit/htm
|
|
33
|
+
|
|
34
|
+
Everything else in this distribution is licensed under the EUPL-1.2.
|