feat(psu): switch a Modbus RTU bench supply from OpsLog

The manufacturer's document arrived, so this is no longer guesswork: 9600 8N1,
function codes 03 and 06 only, and a register map with the output on/off at
0x0001, the measurements at 0x0010…0x0013 and the set points at 0x0030/0x0031.

ONE REGISTER IS WRITTEN — 0x0001, the output. The map also exposes the voltage
and current set points and the three protection trip levels as writable, and
none of them belong to a logbook: a wrong value there is 30 V where a radio
expected 13.8, or a trip level lifted on a supply feeding an amplifier. They are
read and displayed instead, next to the measured values, which is also how an
operator sees at a glance that the supply is on and the radio is drawing nothing.

The wire layer is tested where it can be. CRC-16/MODBUS is pinned against its
published check value — the CRC of "123456789" is 0x4B37 — which fixes the
polynomial, the initial value, the reflection and the absence of a final xor all
at once; the rest of the protocol is checked frame by frame against the manual,
including the byte order of the CRC, an exception reply told apart from a broken
line, and a reply from another slave on the bus refused. The write echo must
match the value sent: it is the only confirmation the output really switched,
and accepting the frame without it is how a radio ends up dark behind a green
light.

Framing follows the manual's own rules: 3.5 character times of silence between
frames (4 ms at 9600), and a frame is over when the line falls quiet — Modbus
RTU has no terminator, and a serial read that times out returns (0, nil) here,
so the reader is built on a deadline and a quiet-time rather than on an error
that never comes.

Untested against hardware — nobody here has the supply.
This commit is contained in:
2026-08-16 13:15:55 +02:00
parent 9f8e3c73d9
commit 8683a450a7
12 changed files with 1038 additions and 4 deletions
+5
View File
@@ -52,6 +52,7 @@ import (
"hamlog/internal/powergenius"
"hamlog/internal/profile"
"hamlog/internal/pskr"
"hamlog/internal/psu"
"hamlog/internal/qslcard"
"hamlog/internal/qso"
"hamlog/internal/relaydev"
@@ -690,6 +691,7 @@ type App struct {
motorInhibited atomic.Bool // TX currently inhibited by the motor-antenna watcher
antgenius *antgenius.Client // Antenna Genius (4O3A) switch (TCP); nil when disabled
tunergenius *tunergenius.Client // Tuner Genius XL (4O3A) ATU (TCP); nil when disabled
psu *psu.Client // bench power supply over Modbus RTU (serial); nil when disabled
pgxl *powergenius.Client // PowerGenius XL (4O3A) amp fan control (TCP); nil when disabled
spe *spe.Client // legacy pointer: FIRST enabled SPE amp (kept for the pre-multi bindings)
acom *acom.Client // legacy pointer: FIRST enabled ACOM amp
@@ -1415,6 +1417,8 @@ func (a *App) startup(ctx context.Context) {
a.startTunerGenius()
// PowerGenius XL amp fan control: connect in the background if enabled.
a.startAmps()
// Bench power supply (Modbus RTU): connect in the background if enabled.
a.startPSU()
// Autostart: launch the active profile's configured external programs that
// aren't already running (WSJT-X, JTAlert, rotator control, …). Background
@@ -14211,6 +14215,7 @@ func (a *App) reloadAfterProfileSwitch() {
a.restartAsync("antenna", a.startUltrabeam)
a.restartAsync("antgenius", a.startAntGenius)
a.restartAsync("tuner", a.startTunerGenius)
a.restartAsync("psu", a.startPSU)
a.startQSORecorderIfEnabled()
}