Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,53 @@ jobs:
with:
draft: true

# Every app release carries the current library package, even when the library
# did not change. The library has its own version (tags `alientek-el15-v*`, which
# do not match `v*` and so do not trigger this workflow) and is published to
# crates.io by hand.
package-library:
name: package alientek-el15
needs: [create-release]
if: ${{ !cancelled() && needs.create-release.result != 'failure' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6

- uses: dtolnay/rust-toolchain@stable

- uses: Swatinem/rust-cache@v2

- name: Package library crate
id: library
shell: bash
run: |
set -euo pipefail
cargo package --locked -p alientek-el15 --no-verify
crate_file=$(find target/package -maxdepth 1 -name 'alientek-el15-*.crate' -print -quit)
crate_name=$(basename "$crate_file")
mkdir -p dist
cp "$crate_file" "dist/$crate_name"
shasum -a 256 "dist/$crate_name" | awk '{print $1}' > "dist/$crate_name.sha256"
echo "crate_name=$crate_name" >> "$GITHUB_OUTPUT"

- name: Release library package
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v3
with:
files: |
dist/${{ steps.library.outputs.crate_name }}
dist/${{ steps.library.outputs.crate_name }}.sha256

- name: Upload workflow_dispatch library package
if: github.event_name == 'workflow_dispatch'
uses: actions/upload-artifact@v7
with:
name: alientek-el15
path: |
dist/${{ steps.library.outputs.crate_name }}
dist/${{ steps.library.outputs.crate_name }}.sha256
retention-days: 7

build:
name: build (${{ matrix.platform.label }}-${{ matrix.platform.arch }})
needs: [create-release]
Expand Down
16 changes: 15 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,18 @@ jobs:
run: cargo test --workspace

- name: Clippy
run: cargo clippy --workspace -- -D warnings
run: cargo clippy --workspace --all-targets -- -D warnings

- name: Library without Bluetooth
run: |
cargo clippy -p alientek-el15 --all-targets --no-default-features -- -D warnings
cargo test -p alientek-el15 --no-default-features

# The library is published on crates.io; check what docs.rs and crates.io would get.
- name: Library docs
run: cargo doc -p alientek-el15 --no-deps
env:
RUSTDOCFLAGS: -D warnings

- name: Library package
run: cargo publish -p alientek-el15 --dry-run
32 changes: 16 additions & 16 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = [
"el15-bt",
"alientek-el15",
"el15-scpi",
"el15-app",
"scripts/scpi-test",
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,27 @@ Supported features: GUI, CLI, BLE, USB DFU, SCPI

| Crate | Type | Purpose |
| ------------------- | ---- | ------------------------------------------------------------------------------------- |
| `el15-bt` | lib | BLE protocol implementation, ported from [DM40GUI](https://github.com/maj113/DM40GUI) |
| `alientek-el15` | lib | BLE protocol library, published on crates.io (see [its README](alientek-el15/README.md)) |
| `el15-scpi` | lib | SCPI/LXI raw-socket server emulating a RIGOL DL3000 electronic load |
| `el15-app` | bin | Single `el15` binary: iced GUI, headless CLI, USB DFU, and SCPI server |
| `scripts/scpi-test` | bin | Smoke tester for the built-in SCPI server |

## Library

The Bluetooth LE protocol is a separate crate, [`alientek-el15`](alientek-el15/README.md),
published on crates.io with its own version (tags `alientek-el15-v*`; the app keeps `v*`).
The app builds it from the local sources. The protocol was reverse-engineered from the
Bluetooth traffic of ALIENTEK's official Android app, ATK-xTOOL, and cross-checked against
the Python project [DM40GUI](https://github.com/maj113/DM40GUI).

To use a local checkout of the library in another project, depend on it by path, or keep the
crates.io dependency and override it:

```toml
[patch.crates-io]
alientek-el15 = { path = "../el15/alientek-el15" }
```

## Build from source

### Requirements
Expand Down
60 changes: 60 additions & 0 deletions alientek-el15/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Changelog

All notable changes to the `alientek-el15` crate. The companion app has its own release notes
on GitHub.

## Unreleased

## 0.1.0

First release under this name. Earlier versions lived in the app repository as `el15-bt`
(up to 0.1.4, following the app's version) and were not published on crates.io.

- Command frames and the checksum: init, info, poll, load on/off, lock, set mode, set setpoint,
set and read the CAP discharge current.
- Parsers for the status notification, the firmware version and the CAP discharge current.
- Scanning, connecting, and a `Device` handle that sends commands, paced
`INTER_COMMAND_GAP` apart, and turns notifications into `DeviceEvent`s.

Compared with `el15-bt` 0.1.4:

- Renamed: the crate `el15-bt` is now `alientek-el15` (`use alientek_el15::...`); the tracing
target is `alientek_el15`.
- It requires only tokio's `rt`, `sync` and `time` features; applications bring their own
runtime (`Device::connect` spawns a task, so it must run inside one).
- Renamed: `EL15Status` is now `Status`, `EL15_SERVICE_UUID` is `SERVICE_UUID`, `HEADER` is
`STATUS_HEADER`.
- `Status::dcr_mohm` is documented as milliohms. Measured on a cell (173.6 mΩ from the
voltage drop between the two test currents, 173.15 reported); earlier notes said Ohms.
- `parse_status_packet` returns `Result<Status, ParseError>` and rejects a wrong length,
header or **checksum**. Before, a corrupted packet came back with `crc_pass: false` but
`valid: true`, and `Device` emitted it as a measurement. `DeviceEvent::Status` now only
carries packets that passed; the rest still arrive as `RawNotification`.
- `parse_firmware_version` returns a `FirmwareVersion` (it displays as before,
`HW:2.0 SW:1.7`) instead of a `String`, and so does `DeviceEvent::FirmwareVersion`.
It and `parse_cap_current` now check the reply's checksum and exact length.
- `Status` keeps measurements only. Removed: `raw_hex`, `crc_pass`, `valid` (see
`RawNotification` and `ParseError`), `mode_name`, `setpoint_unit`, `setpoint_decimals` and
`setpoint_label` (use `Status::mode()`, `Mode::as_str()` / `Display` and
`Mode::setpoint_info()`). `warning` is an `Option<Warning>` (`Reverse`, `Undervoltage`,
`Protection(code)`) instead of a `String`; `Display` gives the old `REV` / `UVP` / `PROT x`.
- `runtime_s` is read as an unsigned integer instead of a signed one cast to unsigned.
- Removed: `MODE_NAMES` (its type was not nameable; use `Mode::as_str`) and
`Device::watch_central_events` (it exposed btleplug's event type).
- `Error` is `#[non_exhaustive]` and keeps only the variants the crate returns:
`Bluetooth`, `NoAdapter`, `CharacteristicNotFound`.
- New exports: `STATUS_LEN`, `CAP_CURRENT_HEADER`, `FAN_SPEED_MAX`.
- Bluetooth LE is the default feature `ble`; without it the crate needs no Bluetooth stack or
async runtime and depends only on `thiserror`. `INTER_COMMAND_GAP` moved to `protocol` and
is available either way.
- `serde` is no longer a default feature.
- `Device::send` keeps `INTER_COMMAND_GAP` (120 ms) since the previous write from any task,
and writes never overlap. Before, only `send_sequence` paced, and `init_handshake` sent its
two frames back-to-back. Measured on the device: a 3-command burst without pacing lost the
mode switch 4 times out of 6; paced, 6 out of 6 took effect.
- `Device::connect` only uses characteristics of the EL15 service `FFF0`, preferring `FFF1`.
Before, it fell back to any writable or notifying characteristic of the peripheral.
- `build_set_setpoint_cmd` and `build_set_cap_current_cmd` return
`Result<Vec<u8>, InvalidValue>` and refuse NaN, infinity and negative values. The CAP
current above `CAP_CURRENT_MAX_A` (12 A) is refused instead of clamped; a setpoint above
`SETPOINT_MAX` (7500, CR's limit) is refused. Before, NaN reached the wire (`clamp` keeps it).
43 changes: 43 additions & 0 deletions alientek-el15/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "alientek-el15"
# Released on its own (tags `alientek-el15-v*`), independent of the apps' version.
version = "0.1.0"
edition.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
description = "Unofficial client for the ALIENTEK EL15 DC electronic load over Bluetooth LE: command frames, status parsing, scanning and a connection"
documentation = "https://docs.rs/alientek-el15"
readme = "README.md"
keywords = ["alientek", "el15", "electronic-load", "bluetooth", "ble"]
categories = ["hardware-support"]
include = ["src/**/*.rs", "examples/**/*.rs", "Cargo.toml", "README.md", "CHANGELOG.md", "LICENSE"]

[features]
default = ["ble"]
# Bluetooth LE: scanning, connecting and `Device`. Without it the crate keeps the command
# frames, the checksum and the reply parsers, and needs no Bluetooth stack or async runtime.
ble = ["dep:btleplug", "dep:tokio", "dep:tokio-stream", "dep:futures", "dep:uuid", "dep:tracing"]
# Serialize/Deserialize for `Status`, `Mode`, `Warning` and `FirmwareVersion`.
serde = ["dep:serde"]

[dependencies]
thiserror.workspace = true
serde = { workspace = true, optional = true }
btleplug = { workspace = true, optional = true }
# Only what the library uses; applications bring their own runtime.
tokio = { version = "1", features = ["rt", "sync", "time"], optional = true }
tokio-stream = { workspace = true, optional = true }
futures = { workspace = true, optional = true }
uuid = { workspace = true, optional = true }
tracing = { workspace = true, optional = true }

[dev-dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

[[example]]
name = "status"
required-features = ["ble"]

[package.metadata.docs.rs]
all-features = true
21 changes: 21 additions & 0 deletions alientek-el15/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Roman Samarev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
90 changes: 90 additions & 0 deletions alientek-el15/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# alientek-el15

Unofficial Rust client for the **ALIENTEK EL15** programmable DC electronic load over
Bluetooth LE. Not affiliated with or endorsed by ALIENTEK.

- Command frames: init, poll, load on/off, panel lock, mode (CC, CV, CR, CP, CAP, DCR),
setpoint, and the CAP discharge current, each with its checksum.
- Parsers for the 28-byte status notification (voltage, current, power, temperature,
setpoint, capacity, energy, DCR result, fan, load and lock state, protection warnings),
the firmware version and the CAP discharge current.
- Scanning, connecting, and a `Device` handle that sends commands and turns notifications
into `DeviceEvent`s.

Cargo feature `ble` (default) brings Bluetooth LE through `btleplug`. With
`default-features = false` the crate builds without a Bluetooth stack or async runtime and
keeps the command frames, the checksum and the reply parsers, for use over your own link.
Feature `serde` adds `Serialize`/`Deserialize` to the status and version types.

The protocol was reverse-engineered from the Bluetooth traffic of ALIENTEK's official
Android app, ATK-xTOOL, and cross-checked against the Python project DM40GUI. Verified
against an EL15 with hardware 2.0 and firmware 1.7. The full description, with the evidence
for each field, is in
[docs/BT_PROTOCOL.md](https://github.com/rssdev10/el15/blob/main/docs/BT_PROTOCOL.md).

## Example

Print a few readings from the first EL15 in range (read only: the load stays as it is):

```rust,no_run
use alientek_el15::{scan_devices, Device, DeviceEvent};
use tokio_stream::StreamExt;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let info = scan_devices(None).await?.into_iter().next().ok_or("no EL15 found")?;
let (device, mut events) = Device::connect(&info).await?;
// Without the handshake the device reports zeros for temperature and setpoint.
device.init_handshake().await?;

for _ in 0..5 {
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
device.poll().await?;
while let Some(event) = events.next().await {
if let DeviceEvent::Status(s) = event {
println!("{:.3} V {:.3} A {:.1} °C", s.voltage, s.current, s.temperature);
break;
}
}
}

device.disconnect().await?;
Ok(())
}
```

A complete version is in [examples/status.rs](examples/status.rs).

The device silently drops commands written back-to-back. `Device::send` keeps
`INTER_COMMAND_GAP` (120 ms) since the previous write, from any task, so a shared `Device`
is safe to use; if you write frames over your own link (without the `ble` feature), keep the
same gap yourself.

## Using local sources

To try changes to this crate in another project before they are published, point the
dependency at a checkout:

```toml
[dependencies]
alientek-el15 = { path = "../el15/alientek-el15" }
```

or keep the crates.io dependency and override it in the project's `Cargo.toml`:

```toml
[patch.crates-io]
alientek-el15 = { path = "../el15/alientek-el15" }
```

## Safety

The EL15 sinks up to 150 W from the source under test. A wrong mode or setpoint can
over-discharge a battery or overload a power supply. The device's own protections are the
last line of defence, not a substitute for correct settings. Only hardware 2.0 with firmware
1.7 has been tested; other firmware may differ.

## Companion app

The [repository](https://github.com/rssdev10/el15) also holds `el15`, a GUI, CLI and
SCPI server built on this crate, released as binaries.
Loading