Skip to content

lib: publish the BLE protocol library as alientek-el15 - #3

Open
rssdev10 wants to merge 11 commits into
mainfrom
restructure-alientek-el15
Open

rssdev10 wants to merge 11 commits into
mainfrom
restructure-alientek-el15

Conversation

@rssdev10

@rssdev10 rssdev10 commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Prepares the Bluetooth LE protocol library for crates.io as alientek-el15 and keeps the el15 app in the same repository. While doing it, several bugs were found and fixed; each fix was measured on a real EL15 (HW 2.0 / SW 1.7).

Restructure (same pattern as skyrc-mc5000)

  • el15-bt/ moves to alientek-el15/. The library has its own version, starting at 0.1.0, and tags alientek-el15-v<version>. The app keeps the workspace version and v* tags.
  • Added crates.io metadata, a crate README with a read-only example, a CHANGELOG, examples/status.rs, and LICENSE as a real file (not a symlink).
  • The apps depend on the library by path + version. el15-app, el15-scpi and scpi-test have publish = false. The README documents how another project can use a local checkout (path or [patch.crates-io]).
  • Bluetooth is the default ble feature. Without it the crate depends only on thiserror. serde is opt-in.
  • tokio is limited to rt, sync and time.
  • release.yml attaches the current library .crate to every app release.
  • tests.yml:
    • clippy runs on all targets
    • the library is linted and tested without default features
    • its docs are built with RUSTDOCFLAGS=-D warnings
    • cargo publish --dry-run runs on it
  • Provenance: the protocol was reverse-engineered from the traffic of ALIENTEK's Android app ATK-xTOOL and cross-checked against DM40GUI. It is not a port of DM40GUI.

Breaking API changes (0.1.0 vs el15-bt 0.1.4, all listed in the CHANGELOG)

  • Prefixes dropped:
    • EL15Status → Status
    • EL15_SERVICE_UUID → SERVICE_UUID
    • HEADER → STATUS_HEADER
  • parse_status_packet returns Result<Status, ParseError>. It rejects a wrong length, wrong header or bad checksum. Before this, a corrupted packet came back with crc_pass: false, valid: true and was emitted as a measurement.
  • Status keeps measurements only:
    • The display strings are removed: mode_name, setpoint unit/label/decimals, raw_hex.
    • warning is Option<Warning>.
  • The firmware version is a FirmwareVersion struct whose Display is unchanged.
  • build_set_setpoint_cmd and build_set_cap_current_cmd return Result and refuse NaN, infinity and negative values. f32::clamp keeps NaN, so typing nan as the CAP current used to put NaN on the wire.
  • Removed MODE_NAMES and Device::watch_central_events. Error is #[non_exhaustive].

Fixes measured on the device

Write pacing. An unpaced three-command burst (mode CAP, setpoint, CAP current) lost the mode switch 4 times out of 6. Device::send now waits 120 ms after the previous write from any task, which also paces init_handshake. With that, the same burst took effect 6/6 with 18/18 ACKs.

Gap Mode switch took effect ACKs
0 ms 2/6 9/18
30 ms 5/6 12/18
60 ms 6/6 13/18
120 ms (or library pacing) 6/6 18/18

Read-only queries were never lost. 300 polls came back as 300 single 28-byte notifications with valid checksums.

Characteristics. The device exposes FFF1/FFF2/FFF3 under FFF0 only. connect now prefers FFF1 and no longer falls back to characteristics of other services.

DCR unit is milliohms, not Ohms. On a Li-ion cell, the voltages at the two test currents (4.1693 V at 24.8 mA, 3.9998 V at 1001.3 mA) give 173.6 mΩ. The device reported 173.15. The docs said Ohms. The field keeps the name dcr_mohm, the CLI label is fixed, and a unit test uses the captured packet.

SCPI. MEAS:DCR? now returns Ohms (the SCPI base unit, like MEAS:RES?) instead of passing the device's mΩ value through.

GUI. The DCR panel showed 0.00 °C, but DCR packets carry no temperature. It now shows ---.

Opcode 0x06 = set device name (docs only, no builder). An earlier probe had overwritten the name with 14 00 …. Writing "EL15" restored the INFO reply byte-for-byte to the official app's capture. The advertised BLE name (_BLE) did not follow on reconnect.

Checks (local, rustc / clippy 1.100.0)

  • cargo test --workspace: library 26 tests, app 49 tests, all passing
  • cargo clippy --workspace --all-targets -- -D warnings: clean
  • cargo clippy -p alientek-el15 --all-targets --no-default-features -- -D warnings: clean
  • cargo test -p alientek-el15 --no-default-features: 22 tests passing
  • cargo clippy -p alientek-el15 --all-targets --all-features -- -D warnings: clean
  • RUSTDOCFLAGS=-D warnings cargo doc -p alientek-el15 --no-deps: clean
  • cargo publish -p alientek-el15 --dry-run: OK

Not in this PR: the AI-assistant instruction files (CLAUDE.md, AGENTS.md, .github/copilot-instructions.md) were updated locally but will be committed separately.

Designed by Claude.

🤖 Generated with Claude Code

rssdev10 and others added 11 commits November 26, 2026 23:28
- el15-bt/ moves to alientek-el15/; the library starts its own version line
  at 0.1.0, the apps keep the workspace version
- crates.io metadata, crate README, CHANGELOG, LICENSE (a real copy) and a
  read-only example
- apps depend on it by path and version and are not published
- provenance: reverse-engineered from the official Android app ATK-xTOOL,
  cross-checked against DM40GUI (not a port of it)
- release.yml attaches the library .crate to every app release
- CI lints all targets, checks the library docs and a publish dry run
- tokio: rt (the notification pump task), sync (its channel) and time
  (scan timeouts, command pacing); the example uses the full runtime
The crate name already says EL15. Breaking:
- EL15Status becomes Status, EL15_SERVICE_UUID becomes SERVICE_UUID,
  HEADER becomes STATUS_HEADER, Status::dcr_mohm becomes dcr_ohm (Ohms)
- parse_status_packet returns Result<Status, ParseError> and rejects a
  wrong length, header or checksum; a corrupted packet used to be emitted
  as a measurement (crc_pass false but valid true)
- firmware version is a FirmwareVersion struct (same Display text); it and
  the CAP current reply check their checksum
- Status keeps measurements only: the display strings (mode_name, setpoint
  unit/label/decimals, raw_hex) go; warning is Option<Warning>
- MODE_NAMES and Device::watch_central_events are removed; Error is
  non_exhaustive and keeps only the variants it returns
- without `ble` the crate keeps the frames, the checksum and the parsers,
  and depends only on thiserror
- INTER_COMMAND_GAP moves to protocol: it is a fact about the device, not
  about btleplug
- serde becomes opt-in; the apps do not serialize library types
- CI lints and tests the library without default features

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tested on the device (HW:2.0 / SW:1.7, load off):
- an unpaced 3-command burst (mode CAP, setpoint, CAP current) lost the
  mode switch 4/6 at 0 ms and 1/6 at 30 ms; ACKs went missing up to 60 ms
- Device::send now waits out INTER_COMMAND_GAP since the previous write
  from any task and never overlaps writes, so send, send_sequence and
  init_handshake are all paced; the same burst then took effect 6/6
- the device exposes FFF1/FFF2/FFF3 under FFF0 only; connect prefers FFF1
  and no longer falls back to a characteristic of another service

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A DCR test on a Li-ion cell (I1 25 mA, I2 1000 mA) reported 173.15 in
bytes 23..27; the voltage drop between the two currents gives 173.6 mOhm.
The docs and the previous commits claimed Ohms; that was wrong.
- keep the field name Status::dcr_mohm, now documented as milliohms
- the GUI card was right; the CLI debug output labelled it Ohm
- unit test from the captured packet

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mbers

Breaking: build_set_setpoint_cmd and build_set_cap_current_cmd return
Result<Vec<u8>, InvalidValue>.
- NaN, infinity and negative values are refused; f32::clamp keeps NaN, so
  typing "nan" as the CAP current used to put NaN on the wire
- the CAP current above 12 A is refused instead of silently clamped; a
  setpoint above 7500 (CR's limit, SETPOINT_MAX) is refused
- the GUI and CLI log or print the refusal and send nothing; SCPI skips
  both the frame and the stored setpoint
DCR status packets carry the I1/I2 test currents where other modes carry
the temperature, so the card always read 0.00 °C. It now shows "---".
Found while checking why the info reply read `14 00 ...` instead of
"EL15": an earlier 10-byte 0x06 probe had been stored as the name.
Writing "EL15" with 0x06 restored the reply byte-for-byte to the official
app's capture. No builder is added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The device reports the DCR result in milliohms and MEAS:DCR? passed that
number through. SCPI replies use base units, as MEAS:RES? already does,
so convert to Ohms. Documented in SCPI_PROTOCOL.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant