Compare commits
15
Commits
44870bc941
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b1fb005f6 | ||
|
|
be9d5c301b | ||
|
|
b73c97dd5b | ||
|
|
6276c3feea | ||
|
|
110c0e1d49 | ||
|
|
05c337b581 | ||
|
|
c10b5faef4 | ||
|
|
79adc8d5c6 | ||
|
|
c33e3caedb | ||
|
|
5084c19899 | ||
|
|
df7483fe30 | ||
|
|
fe3b414fba | ||
|
|
1829e3d17b | ||
|
|
b037225a05 | ||
|
|
e978cf8a84 |
@@ -27,7 +27,7 @@ env:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: self-hosted
|
||||||
container: git.haxx.space/sjg/trx-rs/sdk:latest
|
container: git.haxx.space/sjg/trx-rs/sdk:latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -40,7 +40,7 @@ jobs:
|
|||||||
run: sccache --show-stats
|
run: sccache --show-stats
|
||||||
|
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: self-hosted
|
||||||
container: git.haxx.space/sjg/trx-rs/sdk:latest
|
container: git.haxx.space/sjg/trx-rs/sdk:latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -53,7 +53,7 @@ jobs:
|
|||||||
run: sccache --show-stats
|
run: sccache --show-stats
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
runs-on: ubuntu-latest
|
runs-on: self-hosted
|
||||||
container: git.haxx.space/sjg/trx-rs/sdk:latest
|
container: git.haxx.space/sjg/trx-rs/sdk:latest
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
@@ -83,7 +83,7 @@ jobs:
|
|||||||
run: npm run verify-generated
|
run: npm run verify-generated
|
||||||
|
|
||||||
reuse:
|
reuse:
|
||||||
runs-on: ubuntu-latest
|
runs-on: self-hosted
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: fsfe/reuse-action@v5
|
- uses: fsfe/reuse-action@v5
|
||||||
|
|||||||
@@ -116,6 +116,44 @@ section and the client reads `[trx-client]`.
|
|||||||
|
|
||||||
Open the configured HTTP frontend address in a browser (default `http://localhost:8080`).
|
Open the configured HTTP frontend address in a browser (default `http://localhost:8080`).
|
||||||
|
|
||||||
|
### 5. Install (optional, Linux + systemd)
|
||||||
|
|
||||||
|
To build, install the binaries system-wide, and set up systemd **user** services
|
||||||
|
that run the server and client in the background:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
script/install.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
This builds in release mode, installs `trx-server`, `trx-client`, and
|
||||||
|
`trx-configurator` to `~/.local/bin`, seeds
|
||||||
|
`~/.config/trx-rs/trx-rs.toml` from the example (existing config is never
|
||||||
|
overwritten), and installs `~/.config/systemd/user/{trx-server,trx-client}.service`.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
script/install.sh --prefix /opt/trx-rs # choose another installation prefix
|
||||||
|
script/install.sh --no-sdr # build without SoapySDR support
|
||||||
|
script/install.sh --enable-now # also enable + start the services now
|
||||||
|
script/install.sh --help # all options
|
||||||
|
```
|
||||||
|
|
||||||
|
After editing your config, manage the services with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
systemctl --user enable --now trx-server trx-client # start now + on login
|
||||||
|
journalctl --user -u trx-server -u trx-client -f # follow logs
|
||||||
|
loginctl enable-linger "$USER" # keep running after logout
|
||||||
|
```
|
||||||
|
|
||||||
|
Serial (`/dev/ttyUSB*`) and audio access require your user to be in the
|
||||||
|
`dialout` and `audio` groups. Remove everything with `script/uninstall.sh`
|
||||||
|
(add `--purge` to also delete the config).
|
||||||
|
|
||||||
|
For an unattended or remotely accessible installation, follow the
|
||||||
|
[safe deployment guide](docs/Deployment.md). It covers a dedicated service
|
||||||
|
account, device permissions, authentication, firewall and reverse-proxy
|
||||||
|
boundaries, verification, upgrades, and rollback.
|
||||||
|
|
||||||
## How It Works
|
## How It Works
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
|
|||||||
@@ -926,8 +926,9 @@ main
|
|||||||
### HTTP Frontend Auth
|
### HTTP Frontend Auth
|
||||||
|
|
||||||
- Optional Argon2id-backed managed accounts with HttpOnly session cookies
|
- Optional Argon2id-backed managed accounts with HttpOnly session cookies
|
||||||
- An exclusive Guest role plus composable Read, Control, Write, and Administrator roles, with policy shared by middleware and handlers
|
- An exclusive Guest role plus composable Read, Control, Transmit, Write, and Administrator roles, with policy shared by middleware and handlers
|
||||||
- Guest sessions receive read-only station access but no account-control endpoints or panels
|
- Guest sessions receive read-only station access but no account-control endpoints or panels
|
||||||
|
- Transmit separately gates PTT, TX audio frames, and TX power-limit changes
|
||||||
- Atomic JSON persistence with migration from the legacy single-role schema
|
- Atomic JSON persistence with migration from the legacy single-role schema
|
||||||
- Account enable/disable, administrator CRUD, self-service password changes, and session revocation on security changes
|
- Account enable/disable, administrator CRUD, self-service password changes, and session revocation on security changes
|
||||||
- A database invariant always preserves at least one enabled administrator
|
- A database invariant always preserves at least one enabled administrator
|
||||||
|
|||||||
@@ -0,0 +1,287 @@
|
|||||||
|
# Safe deployment
|
||||||
|
|
||||||
|
This guide deploys trx-rs on Linux as a dedicated, unprivileged user with
|
||||||
|
systemd user services. It keeps radio-device access, configuration, and runtime
|
||||||
|
data separate from an administrator's account.
|
||||||
|
|
||||||
|
The examples use `trx-rs` as the account name and `/opt/trx-rs/bin` for
|
||||||
|
root-owned executables. Adapt group names and firewall commands to your Linux
|
||||||
|
distribution.
|
||||||
|
|
||||||
|
## 1. Decide what must be reachable
|
||||||
|
|
||||||
|
Only expose listeners that another machine actually needs:
|
||||||
|
|
||||||
|
| Listener | Typical port | Recommended exposure |
|
||||||
|
| --- | ---: | --- |
|
||||||
|
| Server control | TCP 4530 | Loopback or trusted radio LAN only |
|
||||||
|
| Server audio | TCP 4531 and per-rig ports | Trusted radio LAN only |
|
||||||
|
| Client web UI | TCP 8080 or a chosen port | Loopback behind HTTPS proxy |
|
||||||
|
| Client rigctl | Per-rig TCP ports | Loopback or trusted LAN only |
|
||||||
|
| Client JSON | Configured TCP port | Loopback or trusted LAN only |
|
||||||
|
|
||||||
|
`127.0.0.1` accepts connections only from the same host. Use a specific LAN
|
||||||
|
address when possible, or `0.0.0.0` when the listener must accept connections
|
||||||
|
on every IPv4 interface. Binding a socket does not configure the host firewall.
|
||||||
|
|
||||||
|
Do not expose unauthenticated control, audio, rigctl, or JSON listeners to the
|
||||||
|
public Internet. Prefer a VPN for links between radio sites. Put the web UI
|
||||||
|
behind an HTTPS reverse proxy when it is remotely accessible.
|
||||||
|
|
||||||
|
## 2. Create the service account
|
||||||
|
|
||||||
|
Create a non-login service account with a home directory:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo useradd --create-home --shell /usr/sbin/nologin trx-rs
|
||||||
|
sudo chmod 0750 /home/trx-rs
|
||||||
|
```
|
||||||
|
|
||||||
|
Add only the hardware groups required on this host. Common group names are
|
||||||
|
`dialout` for serial devices and `audio` for sound devices:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo usermod -aG dialout,audio trx-rs
|
||||||
|
```
|
||||||
|
|
||||||
|
SDR USB access is distribution- and device-specific. Install the vendor's udev
|
||||||
|
rules or add a narrowly scoped rule for the device's USB vendor/product IDs.
|
||||||
|
Avoid making all USB devices world-writable. After reconnecting the device,
|
||||||
|
verify access as the service account:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo -u trx-rs test -r /dev/ttyUSB0
|
||||||
|
sudo -u trx-rs test -w /dev/ttyUSB0
|
||||||
|
sudo -u trx-rs SoapySDRUtil --find
|
||||||
|
```
|
||||||
|
|
||||||
|
Run only the checks relevant to the configured hardware. Group membership and
|
||||||
|
udev-rule changes normally require reconnecting the device or restarting the
|
||||||
|
service.
|
||||||
|
|
||||||
|
## 3. Build and install immutable binaries
|
||||||
|
|
||||||
|
Build from a reviewed revision as a normal development user, not as root:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/stanislawgrams/trx-rs.git
|
||||||
|
cd trx-rs
|
||||||
|
git switch --detach <reviewed-tag-or-commit>
|
||||||
|
cargo build --release -p trx-server -p trx-client -p trx-configurator
|
||||||
|
```
|
||||||
|
|
||||||
|
Install root-owned binaries into a directory the service user cannot modify:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo install -d -o root -g root -m 0755 /opt/trx-rs/bin
|
||||||
|
sudo install -o root -g root -m 0755 \
|
||||||
|
target/release/trx-server \
|
||||||
|
target/release/trx-client \
|
||||||
|
target/release/trx-configurator \
|
||||||
|
/opt/trx-rs/bin/
|
||||||
|
```
|
||||||
|
|
||||||
|
If SDR support is not needed, build `trx-server` with
|
||||||
|
`--no-default-features`. Keep the source revision and Rust toolchain used for
|
||||||
|
the build in deployment records.
|
||||||
|
|
||||||
|
## 4. Install and validate configuration
|
||||||
|
|
||||||
|
Create private configuration and state directories, then seed the example:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo install -d -o trx-rs -g trx-rs -m 0700 \
|
||||||
|
/home/trx-rs/.config/trx-rs \
|
||||||
|
/home/trx-rs/.config/systemd/user
|
||||||
|
sudo install -o trx-rs -g trx-rs -m 0600 \
|
||||||
|
trx-rs.toml.example /home/trx-rs/.config/trx-rs/trx-rs.toml
|
||||||
|
sudoedit /home/trx-rs/.config/trx-rs/trx-rs.toml
|
||||||
|
```
|
||||||
|
|
||||||
|
At minimum:
|
||||||
|
|
||||||
|
- remove unused example rigs and remotes;
|
||||||
|
- select the correct serial, TCP, or SDR device;
|
||||||
|
- give every enabled rig a unique ID and audio port;
|
||||||
|
- use `127.0.0.1` for same-host connections;
|
||||||
|
- use a LAN address or `0.0.0.0` only for deliberately remote listeners;
|
||||||
|
- enable authentication before exposing server control or the web UI;
|
||||||
|
- replace every example password and token;
|
||||||
|
- keep credential files mode `0600` and owned by `trx-rs`;
|
||||||
|
- set `cookie_secure = true` when the web UI is served through HTTPS.
|
||||||
|
|
||||||
|
For a remote server, control and each per-rig audio listener need an explicit
|
||||||
|
non-loopback address:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[trx-server.listen]
|
||||||
|
enabled = true
|
||||||
|
listen = "0.0.0.0"
|
||||||
|
port = 4530
|
||||||
|
|
||||||
|
[trx-server.listen.auth]
|
||||||
|
tokens_file = "/home/trx-rs/.config/trx-rs/server-tokens"
|
||||||
|
|
||||||
|
[[trx-server.rigs]]
|
||||||
|
id = "station-hf"
|
||||||
|
|
||||||
|
[trx-server.rigs.audio]
|
||||||
|
enabled = true
|
||||||
|
listen = "0.0.0.0"
|
||||||
|
port = 4531
|
||||||
|
```
|
||||||
|
|
||||||
|
When using several `[[trx-server.rigs]]` entries, configure audio under each
|
||||||
|
`[trx-server.rigs.audio]` section. Do not rely on the legacy flat
|
||||||
|
`[trx-server.audio]` section.
|
||||||
|
|
||||||
|
For a web UI behind a reverse proxy, keep the backend on loopback and choose an
|
||||||
|
unused port. The proxy upstream must use the same address and port:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[trx-client.frontends.http]
|
||||||
|
enabled = true
|
||||||
|
listen = "127.0.0.1"
|
||||||
|
port = 7345
|
||||||
|
|
||||||
|
[trx-client.frontends.http.auth]
|
||||||
|
enabled = true
|
||||||
|
users_file = "/home/trx-rs/.config/trx-rs/http-users.json"
|
||||||
|
cookie_secure = true
|
||||||
|
```
|
||||||
|
|
||||||
|
Validate the configuration before starting either daemon:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo -u trx-rs /opt/trx-rs/bin/trx-server \
|
||||||
|
--check-config --config /home/trx-rs/.config/trx-rs/trx-rs.toml
|
||||||
|
sudo -u trx-rs /opt/trx-rs/bin/trx-client \
|
||||||
|
--check-config --config /home/trx-rs/.config/trx-rs/trx-rs.toml
|
||||||
|
```
|
||||||
|
|
||||||
|
Treat unknown-key and deprecated-section warnings as deployment errors. They
|
||||||
|
often mean a setting is not applied where expected.
|
||||||
|
|
||||||
|
## 5. Install the systemd user services
|
||||||
|
|
||||||
|
Render the packaged units with the immutable binary directory:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sed 's|@BINDIR@|/opt/trx-rs/bin|g' packaging/systemd/trx-server.service \
|
||||||
|
| sudo tee /home/trx-rs/.config/systemd/user/trx-server.service >/dev/null
|
||||||
|
sed 's|@BINDIR@|/opt/trx-rs/bin|g' packaging/systemd/trx-client.service \
|
||||||
|
| sudo tee /home/trx-rs/.config/systemd/user/trx-client.service >/dev/null
|
||||||
|
sudo chown trx-rs:trx-rs \
|
||||||
|
/home/trx-rs/.config/systemd/user/trx-server.service \
|
||||||
|
/home/trx-rs/.config/systemd/user/trx-client.service
|
||||||
|
sudo chmod 0644 \
|
||||||
|
/home/trx-rs/.config/systemd/user/trx-server.service \
|
||||||
|
/home/trx-rs/.config/systemd/user/trx-client.service
|
||||||
|
```
|
||||||
|
|
||||||
|
Enable lingering so the user manager runs without an interactive login, then
|
||||||
|
start it:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo loginctl enable-linger trx-rs
|
||||||
|
trx_uid=$(id -u trx-rs)
|
||||||
|
sudo systemctl start "user@${trx_uid}.service"
|
||||||
|
```
|
||||||
|
|
||||||
|
Manage the user services through that user's runtime directory:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
trx_uid=$(id -u trx-rs)
|
||||||
|
sudo -u trx-rs XDG_RUNTIME_DIR="/run/user/${trx_uid}" \
|
||||||
|
systemctl --user daemon-reload
|
||||||
|
sudo -u trx-rs XDG_RUNTIME_DIR="/run/user/${trx_uid}" \
|
||||||
|
systemctl --user enable --now trx-server.service trx-client.service
|
||||||
|
```
|
||||||
|
|
||||||
|
The client unit has ordering, but not activation, on `trx-server.service`. If
|
||||||
|
both are enabled locally, the client starts after the server process is
|
||||||
|
started. If the local server is disabled because all remotes are external, the
|
||||||
|
client does not start it. The client retries remote connections; systemd cannot
|
||||||
|
order startup against a service on another host.
|
||||||
|
|
||||||
|
## 6. Firewall and reverse proxy
|
||||||
|
|
||||||
|
Allow only required ports and sources. For example, permit server control and
|
||||||
|
audio only from the trusted radio subnet, not from every interface. Exact
|
||||||
|
commands differ between nftables, firewalld, and ufw.
|
||||||
|
|
||||||
|
For the web UI, terminate TLS in a maintained reverse proxy and send traffic to
|
||||||
|
the loopback backend. Preserve WebSocket upgrade headers if the proxy requires
|
||||||
|
them. Example nginx location:
|
||||||
|
|
||||||
|
```nginx
|
||||||
|
location / {
|
||||||
|
proxy_pass http://127.0.0.1:7345;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Test the backend directly before debugging a `502 Bad Gateway` response:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl --fail --show-error http://127.0.0.1:7345/
|
||||||
|
```
|
||||||
|
|
||||||
|
A refused connection means nothing is listening at the proxy's configured
|
||||||
|
address and port. Check for port conflicts with `ss -ltnp` and confirm the
|
||||||
|
application log reports the same bind address as the proxy upstream.
|
||||||
|
|
||||||
|
## 7. Verify the deployment
|
||||||
|
|
||||||
|
```bash
|
||||||
|
trx_uid=$(id -u trx-rs)
|
||||||
|
sudo -u trx-rs XDG_RUNTIME_DIR="/run/user/${trx_uid}" \
|
||||||
|
systemctl --user status trx-server.service trx-client.service
|
||||||
|
sudo journalctl _UID="${trx_uid}" \
|
||||||
|
-u trx-server.service -u trx-client.service --since today
|
||||||
|
sudo ss -ltnp
|
||||||
|
```
|
||||||
|
|
||||||
|
Verify all of the following:
|
||||||
|
|
||||||
|
- both required services remain active without a restart loop;
|
||||||
|
- radio hardware opens successfully;
|
||||||
|
- logs show the intended control, audio, and frontend bind addresses;
|
||||||
|
- the client connects to every configured control and audio endpoint;
|
||||||
|
- only intended interfaces expose listeners;
|
||||||
|
- authentication works and anonymous access is rejected where configured;
|
||||||
|
- the HTTPS proxy returns the UI and supports live updates;
|
||||||
|
- the service account cannot write `/opt/trx-rs/bin`.
|
||||||
|
|
||||||
|
Do not rely only on `systemctl` reporting `active`: individual frontend tasks
|
||||||
|
can fail after the main client process starts. Always inspect startup logs and
|
||||||
|
probe each required endpoint.
|
||||||
|
|
||||||
|
## 8. Upgrade and roll back
|
||||||
|
|
||||||
|
Build and validate a new revision before replacing the installed executables.
|
||||||
|
Back up configuration and state first. Stop the services, install all binaries
|
||||||
|
from the same build, and restart:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
trx_uid=$(id -u trx-rs)
|
||||||
|
sudo -u trx-rs XDG_RUNTIME_DIR="/run/user/${trx_uid}" \
|
||||||
|
systemctl --user stop trx-client.service trx-server.service
|
||||||
|
sudo install -o root -g root -m 0755 \
|
||||||
|
target/release/trx-server \
|
||||||
|
target/release/trx-client \
|
||||||
|
target/release/trx-configurator \
|
||||||
|
/opt/trx-rs/bin/
|
||||||
|
sudo -u trx-rs XDG_RUNTIME_DIR="/run/user/${trx_uid}" \
|
||||||
|
systemctl --user start trx-server.service trx-client.service
|
||||||
|
```
|
||||||
|
|
||||||
|
Keep the previous binaries or package revision available for rollback. If the
|
||||||
|
new version fails, stop both services, restore the complete previous binary
|
||||||
|
set, restore configuration only if its format changed, and start the services
|
||||||
|
again.
|
||||||
@@ -541,8 +541,8 @@ setting, which is also what LoTW's station locations expect.
|
|||||||
rotate operators through one station callsign, which is why contest loggers record it per QSO.
|
rotate operators through one station callsign, which is why contest loggers record it per QSO.
|
||||||
It is stored per QSO, defaulted from the configured callsign so a single operator never touches
|
It is stored per QSO, defaulted from the configured callsign so a single operator never touches
|
||||||
it, and changed on the station line at the top of the panel where it sticks for the session.
|
it, and changed on the station line at the top of the panel where it sticks for the session.
|
||||||
It cannot be taken from the session's identity: the auth roles are `admin` and `user`, with no
|
It cannot be inferred from the session's identity: an account username need not be an operator
|
||||||
notion of who is logged in.
|
callsign, and operational accounts may be shared.
|
||||||
|
|
||||||
**Server clock, and the log says so.** The server is the machine at the radio; the browser may
|
**Server clock, and the log says so.** The server is the machine at the radio; the browser may
|
||||||
be on a phone in another timezone with a clock nobody has checked. QSO times are UTC from the
|
be on a phone in another timezone with a clock nobody has checked. QSO times are UTC from the
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ When auth is enabled, an **auth gate** blocks the UI with:
|
|||||||
- Role badge display
|
- Role badge display
|
||||||
|
|
||||||
**Guest** provides read-only station access and is exclusive. Non-Guest accounts
|
**Guest** provides read-only station access and is exclusive. Non-Guest accounts
|
||||||
may combine **Read**, **Control**, **Write**, and **Administrator** roles.
|
may combine **Read**, **Control**, **Transmit**, **Write**, and **Administrator** roles.
|
||||||
Administrator implies all permissions.
|
Administrator implies all permissions.
|
||||||
|
|
||||||
Session cookie: `trx_http_sid`, HttpOnly, configurable Secure and SameSite attributes.
|
Session cookie: `trx_http_sid`, HttpOnly, configurable Secure and SameSite attributes.
|
||||||
@@ -337,13 +337,14 @@ Logo and favicon are embedded at compile time via `include_bytes!`. The logo ima
|
|||||||
|
|
||||||
### 7.1 Route Access Classification
|
### 7.1 Route Access Classification
|
||||||
|
|
||||||
Routes are classified into three tiers:
|
Routes are classified into access tiers:
|
||||||
|
|
||||||
| Tier | Examples | Requirement |
|
| Tier | Examples | Requirement |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| **Public** | `/`, `/index.html`, `/map`, login/session endpoints, static assets | None |
|
| **Public** | `/`, `/index.html`, `/map`, login/session endpoints, static assets | None |
|
||||||
| **Read** | `/status`, `/events`, `/audio`, `/decode`, `/spectrum`, `/bookmarks` | Guest, Read, Control, or Administrator role |
|
| **Read** | `/status`, `/events`, `/audio`, `/decode`, `/spectrum`, `/bookmarks` | Guest, Read, Control, Transmit, or Administrator role |
|
||||||
| **Control** | `/set_freq`, `/set_mode`, `/set_ptt`, `/toggle_power`, radio-control POST routes | Control or Administrator role |
|
| **Control** | `/set_freq`, `/set_mode`, `/toggle_power`, receive-side radio-control POST routes | Control or Administrator role |
|
||||||
|
| **Transmit** | `/set_ptt`, `/set_tx_limit`, outbound `/audio` frames | Transmit or Administrator role |
|
||||||
| **Write** | Logbook access and bookmark mutations | Write or Administrator role |
|
| **Write** | Logbook access and bookmark mutations | Write or Administrator role |
|
||||||
|
|
||||||
### 7.2 Session Management
|
### 7.2 Session Management
|
||||||
|
|||||||
+67
-23
@@ -593,7 +593,8 @@ The HTTP frontend supports an optional user/password ACL:
|
|||||||
|
|
||||||
- **Guest** — read-only station access with no Account or Users controls; Guest cannot be combined with another role
|
- **Guest** — read-only station access with no Account or Users controls; Guest cannot be combined with another role
|
||||||
- **Read** — monitoring, audio, decode streams, and bookmark reads
|
- **Read** — monitoring, audio, decode streams, and bookmark reads
|
||||||
- **Control** — full radio receive/transmit controls
|
- **Control** — tuning, mode, power, and receive-side radio controls
|
||||||
|
- **Transmit** — PTT, transmitted audio, and TX power-limit controls
|
||||||
- **Write** — logbook access and bookmark changes
|
- **Write** — logbook access and bookmark changes
|
||||||
- **Administrator** — user management and all other permissions
|
- **Administrator** — user management and all other permissions
|
||||||
|
|
||||||
@@ -644,8 +645,9 @@ credentials in configuration before first startup on an exposed deployment.
|
|||||||
| `/auth/users` | GET/POST | List or add users (admin only) |
|
| `/auth/users` | GET/POST | List or add users (admin only) |
|
||||||
| `/auth/users/{username}` | PATCH/DELETE | Change enabled state/password/roles or remove user (administrator only) |
|
| `/auth/users/{username}` | PATCH/DELETE | Change enabled state/password/roles or remove user (administrator only) |
|
||||||
|
|
||||||
Read routes accept Guest or require Read. Radio mutations require Control. Logbook access and
|
Read routes accept Guest or require Read. Tuning and receive-side radio mutations
|
||||||
bookmark mutations require Write. Administrator grants every permission.
|
require Control. PTT, transmitted audio, and TX limit changes require Transmit.
|
||||||
|
Logbook access and bookmark mutations require Write. Administrator grants every permission.
|
||||||
|
|
||||||
### Frontend Flow
|
### Frontend Flow
|
||||||
|
|
||||||
@@ -750,9 +752,30 @@ A dedicated tab with a clock icon provides:
|
|||||||
## SDR Noise Blanker
|
## SDR Noise Blanker
|
||||||
|
|
||||||
The noise blanker suppresses impulse noise (clicks, pops, ignition interference)
|
The noise blanker suppresses impulse noise (clicks, pops, ignition interference)
|
||||||
on raw IQ samples before any mixing or filtering takes place. It works by
|
on raw IQ samples before any mixing or filtering takes place — the only point in
|
||||||
tracking a running RMS level of the signal and replacing any sample whose
|
the chain where an impulse is still short in time, since the narrow channel
|
||||||
magnitude exceeds **threshold x RMS** with the last known clean sample.
|
filter downstream smears it into un-removable ringing.
|
||||||
|
|
||||||
|
It combines four elements:
|
||||||
|
|
||||||
|
- A **noise-floor tracker** — an exponential estimate of the background level,
|
||||||
|
updated only from clean samples (and frozen during a blank) so a burst cannot
|
||||||
|
drag the reference up and blind the detector.
|
||||||
|
- **Detection** — a sample is flagged when its power exceeds
|
||||||
|
**threshold² × noise-floor**.
|
||||||
|
- **Look-ahead** — the stream is delayed a few microseconds so the gate can
|
||||||
|
begin closing *before* the impulse reaches the output, catching its leading
|
||||||
|
edge instead of letting it leak through.
|
||||||
|
- A **tapered gate** — instead of a hard sample-and-hold (which splatters energy
|
||||||
|
back across the passband and is what made the old blanker sound worse on
|
||||||
|
SSB/CW/data), the gain ramps smoothly down and back up, so blanking costs only
|
||||||
|
a short, quiet notch.
|
||||||
|
|
||||||
|
The blank window, look-ahead, taper, and floor time constant are chosen by a
|
||||||
|
**profile** matched to the interference source. The `threshold` control is
|
||||||
|
orthogonal — it sets detection sensitivity within the chosen profile. All
|
||||||
|
profile timings are specified in real time and converted to samples at the
|
||||||
|
capture rate, so the blanker behaves consistently across SDR sample rates.
|
||||||
|
|
||||||
### Configuration (server-side)
|
### Configuration (server-side)
|
||||||
|
|
||||||
@@ -769,6 +792,7 @@ type = "sdr"
|
|||||||
[rigs.sdr.noise_blanker]
|
[rigs.sdr.noise_blanker]
|
||||||
enabled = true
|
enabled = true
|
||||||
threshold = 10.0 # 1 – 100; lower = more aggressive blanking
|
threshold = 10.0 # 1 – 100; lower = more aggressive blanking
|
||||||
|
profile = "spike" # spike | ignition | powerline | broadband
|
||||||
```
|
```
|
||||||
|
|
||||||
For the legacy single-rig (flat) config the path is `[sdr.noise_blanker]`:
|
For the legacy single-rig (flat) config the path is `[sdr.noise_blanker]`:
|
||||||
@@ -777,15 +801,30 @@ For the legacy single-rig (flat) config the path is `[sdr.noise_blanker]`:
|
|||||||
[sdr.noise_blanker]
|
[sdr.noise_blanker]
|
||||||
enabled = true
|
enabled = true
|
||||||
threshold = 10.0
|
threshold = 10.0
|
||||||
|
profile = "spike"
|
||||||
```
|
```
|
||||||
|
|
||||||
| Field | Type | Default | Range | Description |
|
| Field | Type | Default | Range | Description |
|
||||||
|-------------|-------|---------|---------|-------------|
|
|-------------|--------|-----------|---------|-------------|
|
||||||
| `enabled` | bool | false | — | Turn the noise blanker on or off. |
|
| `enabled` | bool | false | — | Turn the noise blanker on or off. |
|
||||||
| `threshold` | float | 10.0 | 1 – 100 | Multiplier applied to the running RMS. A sample whose magnitude exceeds this multiple is replaced. Lower values blank more aggressively; higher values only catch strong impulses. |
|
| `threshold` | float | 10.0 | 1 – 100 | Multiplier applied to the tracked noise floor. A sample whose magnitude exceeds this multiple is blanked. Lower values blank more aggressively; higher values only catch strong impulses. |
|
||||||
|
| `profile` | string | `"spike"` | see below | Tuning profile matched to the interference source. |
|
||||||
|
|
||||||
The noise blanker is off by default.
|
The noise blanker is off by default.
|
||||||
|
|
||||||
|
### Profiles
|
||||||
|
|
||||||
|
Each profile sets the blank-window width, look-ahead, gate taper, and
|
||||||
|
noise-floor time constant. Pick the one that matches what you are hearing, then
|
||||||
|
fine-tune with the threshold.
|
||||||
|
|
||||||
|
| Profile | Blank window | Best for |
|
||||||
|
|--------------|--------------|----------|
|
||||||
|
| `spike` | Narrowest | Sharp, sparse impulses — ignition sparks, static crashes, keyed relays. The safe default: minimal impact on the wanted signal, good for SSB/CW/digital. |
|
||||||
|
| `ignition` | Medium | Automotive ignition, electric fences, PWM/LED drivers — clusters of medium-width pulses at a high repetition rate. |
|
||||||
|
| `powerline` | Wide | Power-line and arcing noise — buzzy bursts locked to the 100/120 Hz mains cycle. Uses a slower floor tracker to ride out the burst. |
|
||||||
|
| `broadband` | Widest | Dense, continuous impulse noise where suppression matters more than fidelity. Most aggressive gating; expect some softening of the wanted signal. |
|
||||||
|
|
||||||
### Choosing a threshold
|
### Choosing a threshold
|
||||||
|
|
||||||
The threshold controls how aggressively the blanker suppresses impulses.
|
The threshold controls how aggressively the blanker suppresses impulses.
|
||||||
@@ -811,39 +850,44 @@ the running average signal level.
|
|||||||
|
|
||||||
### Web UI
|
### Web UI
|
||||||
|
|
||||||
When the server reports noise-blanker support, two controls appear in the
|
When the server reports noise-blanker support, these controls appear in the
|
||||||
**SDR Settings** row of the web interface:
|
**SDR Settings** row of the web interface:
|
||||||
|
|
||||||
- **Noise Blanker** checkbox — enables or disables the blanker in real time.
|
- **Noise Blanker** checkbox — enables or disables the blanker in real time.
|
||||||
|
The **N** keyboard shortcut toggles it too.
|
||||||
- **NB Threshold** number input (1–100) with a **Set** button — adjusts the
|
- **NB Threshold** number input (1–100) with a **Set** button — adjusts the
|
||||||
detection threshold. Press Enter or click Set to apply.
|
detection sensitivity. Press Enter or click Set to apply.
|
||||||
|
- **NB profile** selector — chooses the profile (Spike / Ignition / Powerline /
|
||||||
|
Broadband). Changing it applies immediately.
|
||||||
|
|
||||||
Both controls stay hidden until the server sends filter state containing NB
|
The controls stay hidden until the server sends filter state containing NB
|
||||||
fields, so they only appear when connected to an SDR backend.
|
fields, so they only appear when connected to an SDR backend.
|
||||||
|
|
||||||
### HTTP API
|
### HTTP API
|
||||||
|
|
||||||
```
|
```
|
||||||
POST /set_sdr_noise_blanker?enabled=true&threshold=10
|
POST /set_sdr_noise_blanker?enabled=true&threshold=10&profile=spike
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parameter | Type | Required | Description |
|
| Parameter | Type | Required | Description |
|
||||||
|-------------|--------|----------|-------------|
|
|-------------|--------|----------|-------------|
|
||||||
| `enabled` | bool | yes | `true` or `false` |
|
| `enabled` | bool | yes | `true` or `false` |
|
||||||
| `threshold` | float | yes | Value between 1 and 100 |
|
| `threshold` | float | yes | Value between 1 and 100 |
|
||||||
|
| `profile` | string | no | `spike` (default), `ignition`, `powerline`, or `broadband` |
|
||||||
|
|
||||||
### How it works
|
### How it works
|
||||||
|
|
||||||
The blanker runs on every IQ block (4096 samples) *before* the mixer stage in
|
The blanker runs on every IQ block *before* the mixer stage in the DSP pipeline,
|
||||||
the DSP pipeline:
|
one sample at a time:
|
||||||
|
|
||||||
1. For each sample, compute magnitude² (`re² + im²`).
|
1. Emit the sample from the look-ahead delay line and ingest the fresh one.
|
||||||
2. Compare against `threshold² × mean_sq` (the exponentially-smoothed running
|
2. Compute the fresh sample's power (`re² + im²`) and compare it against
|
||||||
mean of magnitude²).
|
`threshold² × noise_floor`.
|
||||||
3. If the sample exceeds the threshold, replace it with the previous clean
|
3. If it exceeds the threshold, hold the gate closed for the profile's blank
|
||||||
sample.
|
window; the fresh sample reaches the output a few samples later, by which
|
||||||
4. Otherwise, update the running mean with smoothing factor α = 1/128 and store
|
time the gate has fully ramped to zero — so the leading edge is removed.
|
||||||
the sample as the last clean value.
|
4. Otherwise, update the noise-floor estimate (skipped while blanking) and let
|
||||||
|
the gate ramp back open.
|
||||||
|
|
||||||
Because the blanker operates on raw IQ before frequency translation, it removes
|
Because the blanker operates on raw IQ before frequency translation, it removes
|
||||||
impulse noise across the entire captured bandwidth regardless of the tuned
|
impulse noise across the entire captured bandwidth regardless of the tuned
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2026 Stan Grams <sjg@haxx.space>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
#
|
||||||
|
# systemd *user* unit for the trx-rs radio client and web frontend.
|
||||||
|
#
|
||||||
|
# Install with `script/install.sh` (which substitutes @BINDIR@ and copies this
|
||||||
|
# into ~/.config/systemd/user/), or by hand:
|
||||||
|
# sed "s|@BINDIR@|$HOME/.local/bin|" trx-client.service \
|
||||||
|
# > ~/.config/systemd/user/trx-client.service
|
||||||
|
# systemctl --user daemon-reload
|
||||||
|
# systemctl --user enable --now trx-client.service
|
||||||
|
#
|
||||||
|
# Reads the combined config at ~/.config/trx-rs/trx-rs.toml ([trx-client]
|
||||||
|
# section) and connects to the server (default 127.0.0.1:4530). The web UI
|
||||||
|
# defaults to http://127.0.0.1:8080.
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=trx-rs radio client and web frontend
|
||||||
|
Documentation=https://github.com/stanislawgrams/trx-rs
|
||||||
|
# Wait for networking and, when it is enabled, the local server. After= only
|
||||||
|
# orders units already in the transaction: it deliberately does not start a
|
||||||
|
# disabled trx-server, since the client may connect to a remote server instead.
|
||||||
|
Wants=network-online.target
|
||||||
|
After=network-online.target trx-server.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=@BINDIR@/trx-client --config %h/.config/trx-rs/trx-rs.toml
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=2
|
||||||
|
# Shuts down cleanly on SIGINT (see trx-server.service for the rationale).
|
||||||
|
KillSignal=SIGINT
|
||||||
|
TimeoutStopSec=15
|
||||||
|
NoNewPrivileges=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=default.target
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2026 Stan Grams <sjg@haxx.space>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
#
|
||||||
|
# systemd *user* unit for the trx-rs radio server.
|
||||||
|
#
|
||||||
|
# Install with `script/install.sh` (which substitutes @BINDIR@ and copies this
|
||||||
|
# into ~/.config/systemd/user/), or by hand:
|
||||||
|
# sed "s|@BINDIR@|$HOME/.local/bin|" trx-server.service \
|
||||||
|
# > ~/.config/systemd/user/trx-server.service
|
||||||
|
# systemctl --user daemon-reload
|
||||||
|
# systemctl --user enable --now trx-server.service
|
||||||
|
#
|
||||||
|
# Reads the combined config at ~/.config/trx-rs/trx-rs.toml ([trx-server]
|
||||||
|
# section). Serial (/dev/ttyUSB*) and audio access require your user to be in
|
||||||
|
# the `dialout` and `audio` groups — a user unit cannot grant them itself.
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=trx-rs radio server (CAT/SDR backend)
|
||||||
|
Documentation=https://github.com/stanislawgrams/trx-rs
|
||||||
|
# The server binds its control/audio TCP listeners and may connect to networked
|
||||||
|
# rigs and reporting services, so do not start it before networking is ready.
|
||||||
|
Wants=network-online.target
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=@BINDIR@/trx-server --config %h/.config/trx-rs/trx-rs.toml
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=2
|
||||||
|
# Both binaries shut down cleanly on SIGINT (the server drains audio and exits
|
||||||
|
# 0); systemd's default SIGTERM is not handled, so signal SIGINT instead.
|
||||||
|
KillSignal=SIGINT
|
||||||
|
TimeoutStopSec=15
|
||||||
|
NoNewPrivileges=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=default.target
|
||||||
Executable
+156
@@ -0,0 +1,156 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# SPDX-FileCopyrightText: 2026 Stan Grams <sjg@haxx.space>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
#
|
||||||
|
# Build trx-rs in release mode and install the binaries system-wide, seed a
|
||||||
|
# per-user config, and install systemd *user* services to run the server and
|
||||||
|
# client. Idempotent: existing config is never overwritten.
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||||
|
|
||||||
|
BINARIES=(trx-server trx-client trx-configurator)
|
||||||
|
|
||||||
|
# --- Defaults (override via flags or environment) ---------------------------
|
||||||
|
PREFIX="${PREFIX:-$HOME/.local}"
|
||||||
|
BINDIR="${BINDIR:-}" # derived from PREFIX unless set explicitly
|
||||||
|
NO_SDR=0
|
||||||
|
DO_BUILD=1
|
||||||
|
DO_SYSTEMD=1
|
||||||
|
ENABLE_NOW=0
|
||||||
|
|
||||||
|
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/trx-rs"
|
||||||
|
CONFIG_FILE="$CONFIG_DIR/trx-rs.toml"
|
||||||
|
UNIT_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user"
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat <<EOF
|
||||||
|
Usage: script/install.sh [options]
|
||||||
|
|
||||||
|
Build trx-rs (release) and install it.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--prefix DIR Install prefix; binaries go to DIR/bin (default: \$HOME/.local)
|
||||||
|
--bindir DIR Install binaries directly to DIR (overrides --prefix)
|
||||||
|
--no-sdr Build without SoapySDR support (--no-default-features)
|
||||||
|
--no-build Skip cargo build; install existing target/release binaries
|
||||||
|
--no-systemd Do not install the systemd user services
|
||||||
|
--enable-now Enable and start the user services immediately after install
|
||||||
|
-h, --help Show this help
|
||||||
|
|
||||||
|
Environment:
|
||||||
|
PREFIX, BINDIR Same as the matching flags.
|
||||||
|
|
||||||
|
Installs:
|
||||||
|
binaries -> ${BINDIR:-$PREFIX/bin} (uses sudo if not writable)
|
||||||
|
config -> $CONFIG_FILE (from trx-rs.toml.example, only if absent)
|
||||||
|
services -> $UNIT_DIR/{trx-server,trx-client}.service
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Parse args -------------------------------------------------------------
|
||||||
|
while [ $# -gt 0 ]; do
|
||||||
|
case "$1" in
|
||||||
|
--prefix) PREFIX="$2"; shift 2 ;;
|
||||||
|
--bindir) BINDIR="$2"; shift 2 ;;
|
||||||
|
--no-sdr) NO_SDR=1; shift ;;
|
||||||
|
--no-build) DO_BUILD=0; shift ;;
|
||||||
|
--no-systemd) DO_SYSTEMD=0; shift ;;
|
||||||
|
--enable-now) ENABLE_NOW=1; shift ;;
|
||||||
|
-h|--help) usage; exit 0 ;;
|
||||||
|
*) echo "error: unknown option '$1'" >&2; usage >&2; exit 2 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
[ -n "$BINDIR" ] || BINDIR="$PREFIX/bin"
|
||||||
|
|
||||||
|
log() { printf '\033[1;32m==>\033[0m %s\n' "$*"; }
|
||||||
|
warn() { printf '\033[1;33mwarning:\033[0m %s\n' "$*" >&2; }
|
||||||
|
|
||||||
|
# Return 0 (true) if writing into $1 needs elevated privileges.
|
||||||
|
need_sudo() {
|
||||||
|
local dir="$1"
|
||||||
|
while [ ! -e "$dir" ]; do dir="$(dirname "$dir")"; done
|
||||||
|
[ -w "$dir" ] && return 1 || return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Build ------------------------------------------------------------------
|
||||||
|
if [ "$DO_BUILD" -eq 1 ]; then
|
||||||
|
build_args=(build --release --manifest-path "$PROJECT_ROOT/Cargo.toml")
|
||||||
|
for b in "${BINARIES[@]}"; do build_args+=(-p "$b"); done
|
||||||
|
if [ "$NO_SDR" -eq 1 ]; then
|
||||||
|
# --no-default-features only affects trx-server; harmless elsewhere.
|
||||||
|
build_args+=(-p trx-server --no-default-features)
|
||||||
|
log "Building (release, no SDR)…"
|
||||||
|
else
|
||||||
|
log "Building (release, with SDR)…"
|
||||||
|
fi
|
||||||
|
cargo "${build_args[@]}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Install binaries -------------------------------------------------------
|
||||||
|
SUDO=""
|
||||||
|
if need_sudo "$BINDIR"; then
|
||||||
|
SUDO="sudo"
|
||||||
|
log "Installing binaries to $BINDIR (using sudo)…"
|
||||||
|
else
|
||||||
|
log "Installing binaries to $BINDIR…"
|
||||||
|
fi
|
||||||
|
|
||||||
|
for b in "${BINARIES[@]}"; do
|
||||||
|
src="$PROJECT_ROOT/target/release/$b"
|
||||||
|
if [ ! -x "$src" ]; then
|
||||||
|
echo "error: $src not found (build failed or --no-build with no prior build?)" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
$SUDO install -Dm755 "$src" "$BINDIR/$b"
|
||||||
|
log "installed $BINDIR/$b"
|
||||||
|
done
|
||||||
|
|
||||||
|
# --- Seed per-user config ---------------------------------------------------
|
||||||
|
if [ -e "$CONFIG_FILE" ]; then
|
||||||
|
log "Config already present, leaving it untouched: $CONFIG_FILE"
|
||||||
|
else
|
||||||
|
mkdir -p "$CONFIG_DIR"
|
||||||
|
install -m600 "$PROJECT_ROOT/trx-rs.toml.example" "$CONFIG_FILE"
|
||||||
|
log "Seeded config from example: $CONFIG_FILE"
|
||||||
|
warn "Edit $CONFIG_FILE for your rig before starting the services."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- systemd user services --------------------------------------------------
|
||||||
|
if [ "$DO_SYSTEMD" -eq 1 ]; then
|
||||||
|
mkdir -p "$UNIT_DIR"
|
||||||
|
for unit in trx-server trx-client; do
|
||||||
|
sed "s|@BINDIR@|$BINDIR|g" \
|
||||||
|
"$PROJECT_ROOT/packaging/systemd/$unit.service" \
|
||||||
|
> "$UNIT_DIR/$unit.service"
|
||||||
|
log "installed $UNIT_DIR/$unit.service"
|
||||||
|
done
|
||||||
|
|
||||||
|
if command -v systemctl >/dev/null 2>&1; then
|
||||||
|
systemctl --user daemon-reload || warn "systemctl --user daemon-reload failed"
|
||||||
|
if [ "$ENABLE_NOW" -eq 1 ]; then
|
||||||
|
log "Enabling and starting user services…"
|
||||||
|
systemctl --user enable --now trx-server.service trx-client.service
|
||||||
|
warn "Run 'loginctl enable-linger $USER' to keep services running after logout."
|
||||||
|
else
|
||||||
|
cat <<EOF
|
||||||
|
|
||||||
|
Next steps:
|
||||||
|
1. Edit your config: \$EDITOR $CONFIG_FILE
|
||||||
|
2. Start the services: systemctl --user enable --now trx-server trx-client
|
||||||
|
3. Watch the logs: journalctl --user -u trx-server -u trx-client -f
|
||||||
|
4. Run after logout: loginctl enable-linger $USER
|
||||||
|
|
||||||
|
Web UI (default): http://127.0.0.1:8080
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
warn "systemctl not found; units copied but not reloaded."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "Done."
|
||||||
Executable
+86
@@ -0,0 +1,86 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# SPDX-FileCopyrightText: 2026 Stan Grams <sjg@haxx.space>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
#
|
||||||
|
# Reverse script/install.sh: stop and remove the systemd user services and the
|
||||||
|
# installed binaries. User config (~/.config/trx-rs) is left in place unless
|
||||||
|
# --purge is given.
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
BINARIES=(trx-server trx-client trx-configurator)
|
||||||
|
|
||||||
|
PREFIX="${PREFIX:-$HOME/.local}"
|
||||||
|
BINDIR="${BINDIR:-}"
|
||||||
|
PURGE=0
|
||||||
|
|
||||||
|
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/trx-rs"
|
||||||
|
UNIT_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user"
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat <<EOF
|
||||||
|
Usage: script/uninstall.sh [options]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--prefix DIR Install prefix binaries were installed under (default: \$HOME/.local)
|
||||||
|
--bindir DIR Directory binaries were installed to (overrides --prefix)
|
||||||
|
--purge Also delete the user config directory ($CONFIG_DIR)
|
||||||
|
-h, --help Show this help
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
while [ $# -gt 0 ]; do
|
||||||
|
case "$1" in
|
||||||
|
--prefix) PREFIX="$2"; shift 2 ;;
|
||||||
|
--bindir) BINDIR="$2"; shift 2 ;;
|
||||||
|
--purge) PURGE=1; shift ;;
|
||||||
|
-h|--help) usage; exit 0 ;;
|
||||||
|
*) echo "error: unknown option '$1'" >&2; usage >&2; exit 2 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
[ -n "$BINDIR" ] || BINDIR="$PREFIX/bin"
|
||||||
|
|
||||||
|
log() { printf '\033[1;32m==>\033[0m %s\n' "$*"; }
|
||||||
|
|
||||||
|
need_sudo() {
|
||||||
|
local dir="$1"
|
||||||
|
while [ ! -e "$dir" ]; do dir="$(dirname "$dir")"; done
|
||||||
|
[ -w "$dir" ] && return 1 || return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Stop and remove user services -----------------------------------------
|
||||||
|
if command -v systemctl >/dev/null 2>&1; then
|
||||||
|
log "Stopping and disabling user services…"
|
||||||
|
systemctl --user disable --now trx-client.service trx-server.service 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
for unit in trx-client trx-server; do
|
||||||
|
if [ -e "$UNIT_DIR/$unit.service" ]; then
|
||||||
|
rm -f "$UNIT_DIR/$unit.service"
|
||||||
|
log "removed $UNIT_DIR/$unit.service"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if command -v systemctl >/dev/null 2>&1; then
|
||||||
|
systemctl --user daemon-reload || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Remove binaries --------------------------------------------------------
|
||||||
|
SUDO=""
|
||||||
|
if need_sudo "$BINDIR"; then SUDO="sudo"; fi
|
||||||
|
for b in "${BINARIES[@]}"; do
|
||||||
|
if [ -e "$BINDIR/$b" ]; then
|
||||||
|
$SUDO rm -f "$BINDIR/$b"
|
||||||
|
log "removed $BINDIR/$b"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# --- Optionally purge config ------------------------------------------------
|
||||||
|
if [ "$PURGE" -eq 1 ]; then
|
||||||
|
rm -rf "$CONFIG_DIR"
|
||||||
|
log "purged $CONFIG_DIR"
|
||||||
|
else
|
||||||
|
log "Left config in place: $CONFIG_DIR (use --purge to delete)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "Done."
|
||||||
@@ -45,8 +45,20 @@ impl WefaxConfig {
|
|||||||
60.0 / lpm as f32
|
60.0 / lpm as f32
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Samples per line at the internal sample rate.
|
/// Samples per line at the internal sample rate (rounded to an integer;
|
||||||
|
/// use [`Self::samples_per_line_f64`] for drift-free line slicing).
|
||||||
pub fn samples_per_line(lpm: u16, sample_rate: u32) -> usize {
|
pub fn samples_per_line(lpm: u16, sample_rate: u32) -> usize {
|
||||||
(Self::line_duration_s(lpm) * sample_rate as f32).round() as usize
|
(Self::line_duration_s(lpm) * sample_rate as f32).round() as usize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Exact (fractional) samples per line at the internal sample rate.
|
||||||
|
///
|
||||||
|
/// The line period rarely lands on an integer number of samples
|
||||||
|
/// (e.g. 120 LPM at 11 025 Hz is 5512.5 samples). Slicing on the rounded
|
||||||
|
/// integer accumulates a fractional-sample error every line, which shows
|
||||||
|
/// up as a slow horizontal slant over a tall image. Line boundaries are
|
||||||
|
/// instead computed from this exact value so the error never accumulates.
|
||||||
|
pub fn samples_per_line_f64(lpm: u16, sample_rate: u32) -> f64 {
|
||||||
|
60.0 / f64::from(lpm) * f64::from(sample_rate)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,10 +38,24 @@ const SIGNAL_DETECT_WINDOWS: u32 = 6;
|
|||||||
/// Real WEFAX content typically shows r > 0.5 between adjacent lines.
|
/// Real WEFAX content typically shows r > 0.5 between adjacent lines.
|
||||||
const LINE_CORR_NOISE_THRESHOLD: f32 = 0.2;
|
const LINE_CORR_NOISE_THRESHOLD: f32 = 0.2;
|
||||||
|
|
||||||
/// Number of consecutive uncorrelated scan lines that trigger auto-finalize
|
/// Number of consecutive uncorrelated scan lines that mark the end of a
|
||||||
/// while receiving. At 120 LPM this is 15 s; at 60 LPM it's 30 s. Modelled on
|
/// transmission (carrier truly gone) and trigger auto-finalize. This must be
|
||||||
/// fldigi's line-to-line correlation check for automatic stop.
|
/// long enough to ride through ordinary HF fading (QSB), which routinely
|
||||||
const LINE_CORR_NOISE_LINES: u32 = 30;
|
/// decorrelates adjacent lines for several seconds without the transmission
|
||||||
|
/// having ended. At 120 LPM this is ~60 s; at 60 LPM ~120 s.
|
||||||
|
///
|
||||||
|
/// A short window here is what previously chopped a single chart into many
|
||||||
|
/// PNG "chunks": a 15 s fade tripped the watchdog, the image was finalized,
|
||||||
|
/// and the still-present carrier immediately re-started a fresh image. Real
|
||||||
|
/// WEFAX decoders (fldigi) keep one continuous image per APT cycle up to a
|
||||||
|
/// large line cap and only stop on the APT stop tone or genuine signal loss.
|
||||||
|
const LINE_CORR_NOISE_LINES: u32 = 120;
|
||||||
|
|
||||||
|
/// Hard cap on lines in a single image. A 120 LPM chart runs ~10 min
|
||||||
|
/// (~1200 lines); this cap (≈25 min at 120 LPM) only bounds memory if a
|
||||||
|
/// session is left running on an open carrier. On reaching it the image is
|
||||||
|
/// finalized and the decoder waits for a fresh APT start.
|
||||||
|
const MAX_IMAGE_LINES: u32 = 3000;
|
||||||
|
|
||||||
/// Maximum number of scan-line-equivalent sample windows to wait for phasing
|
/// Maximum number of scan-line-equivalent sample windows to wait for phasing
|
||||||
/// lock before falling through to Receiving. Typical WEFAX phasing lasts
|
/// lock before falling through to Receiving. Typical WEFAX phasing lasts
|
||||||
@@ -107,6 +121,12 @@ pub struct WefaxDecoder {
|
|||||||
/// the decoder falls through to Receiving so a noisy or partial
|
/// the decoder falls through to Receiving so a noisy or partial
|
||||||
/// phasing signal doesn't wedge the state machine.
|
/// phasing signal doesn't wedge the state machine.
|
||||||
phasing_samples: u64,
|
phasing_samples: u64,
|
||||||
|
/// Whether a reception has already been auto-started from bare signal
|
||||||
|
/// variance during this session. After the first image, a new one is only
|
||||||
|
/// started by an APT start tone — this stops the trailing noise / carrier
|
||||||
|
/// that follows one chart from immediately auto-starting another image
|
||||||
|
/// (the mechanism that fragmented a transmission into many chunks).
|
||||||
|
auto_start_used: bool,
|
||||||
/// Current rig dial frequency in Hz (for image filenames).
|
/// Current rig dial frequency in Hz (for image filenames).
|
||||||
freq_hz: u64,
|
freq_hz: u64,
|
||||||
/// Current rig mode name (for image filenames).
|
/// Current rig mode name (for image filenames).
|
||||||
@@ -135,6 +155,7 @@ impl WefaxDecoder {
|
|||||||
signal_detect_buf: Vec::with_capacity(INTERNAL_RATE as usize / 2),
|
signal_detect_buf: Vec::with_capacity(INTERNAL_RATE as usize / 2),
|
||||||
low_corr_lines: 0,
|
low_corr_lines: 0,
|
||||||
phasing_samples: 0,
|
phasing_samples: 0,
|
||||||
|
auto_start_used: false,
|
||||||
freq_hz: 0,
|
freq_hz: 0,
|
||||||
mode: String::new(),
|
mode: String::new(),
|
||||||
}
|
}
|
||||||
@@ -204,7 +225,13 @@ impl WefaxDecoder {
|
|||||||
// Fallback: detect active WEFAX signal by luminance variance.
|
// Fallback: detect active WEFAX signal by luminance variance.
|
||||||
// Like fldigi's "strong image signal" detection — if we see
|
// Like fldigi's "strong image signal" detection — if we see
|
||||||
// sustained modulated signal, auto-start receiving with defaults.
|
// sustained modulated signal, auto-start receiving with defaults.
|
||||||
if self.state == State::Idle {
|
//
|
||||||
|
// Only ever taken once per session: it exists to catch a user
|
||||||
|
// tuning in mid-image with no APT start. After the first image,
|
||||||
|
// a new reception requires an APT start tone, so the residual
|
||||||
|
// carrier / noise that trails a finished chart cannot silently
|
||||||
|
// spawn a second image (which is what produced many chunks).
|
||||||
|
if self.state == State::Idle && !self.auto_start_used {
|
||||||
self.signal_detect_buf.extend_from_slice(&luminance);
|
self.signal_detect_buf.extend_from_slice(&luminance);
|
||||||
let window_size = INTERNAL_RATE as usize / 2;
|
let window_size = INTERNAL_RATE as usize / 2;
|
||||||
while self.signal_detect_buf.len() >= window_size {
|
while self.signal_detect_buf.len() >= window_size {
|
||||||
@@ -340,6 +367,14 @@ impl WefaxDecoder {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bound memory on an open carrier: finalize and wait
|
||||||
|
// for a fresh APT start rather than growing forever.
|
||||||
|
if count >= MAX_IMAGE_LINES {
|
||||||
|
debug!(lines = count, "WEFAX: max image lines — finalizing");
|
||||||
|
carrier_lost = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Emit progress event.
|
// Emit progress event.
|
||||||
if self.config.emit_progress && count % PROGRESS_INTERVAL == 0 {
|
if self.config.emit_progress && count % PROGRESS_INTERVAL == 0 {
|
||||||
let line_data =
|
let line_data =
|
||||||
@@ -402,6 +437,7 @@ impl WefaxDecoder {
|
|||||||
self.signal_detect_buf.clear();
|
self.signal_detect_buf.clear();
|
||||||
self.low_corr_lines = 0;
|
self.low_corr_lines = 0;
|
||||||
self.phasing_samples = 0;
|
self.phasing_samples = 0;
|
||||||
|
self.auto_start_used = false;
|
||||||
events
|
events
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,6 +470,7 @@ impl WefaxDecoder {
|
|||||||
fn transition_to_start_detected(&mut self, ioc: u16) -> WefaxEvent {
|
fn transition_to_start_detected(&mut self, ioc: u16) -> WefaxEvent {
|
||||||
let ioc = self.config.ioc.unwrap_or(ioc);
|
let ioc = self.config.ioc.unwrap_or(ioc);
|
||||||
debug!(ioc, "WEFAX: APT start detected");
|
debug!(ioc, "WEFAX: APT start detected");
|
||||||
|
self.auto_start_used = true;
|
||||||
self.state = State::StartDetected { ioc };
|
self.state = State::StartDetected { ioc };
|
||||||
self.reception_start_ms = Some(
|
self.reception_start_ms = Some(
|
||||||
std::time::SystemTime::now()
|
std::time::SystemTime::now()
|
||||||
@@ -463,6 +500,7 @@ impl WefaxDecoder {
|
|||||||
self.image = Some(ImageAssembler::new(ppl));
|
self.image = Some(ImageAssembler::new(ppl));
|
||||||
self.tone_detector.reset();
|
self.tone_detector.reset();
|
||||||
self.low_corr_lines = 0;
|
self.low_corr_lines = 0;
|
||||||
|
self.auto_start_used = true;
|
||||||
self.state = State::Receiving { ioc, lpm };
|
self.state = State::Receiving { ioc, lpm };
|
||||||
self.state_event("Receiving", ioc, lpm)
|
self.state_event("Receiving", ioc, lpm)
|
||||||
}
|
}
|
||||||
@@ -596,4 +634,47 @@ mod tests {
|
|||||||
dec.reset();
|
dec.reset();
|
||||||
assert_eq!(dec.state, State::Idle);
|
assert_eq!(dec.state, State::Idle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Regression test for the over-chunking bug: once a session has produced
|
||||||
|
/// an image, the trailing carrier / noise must not silently auto-start a
|
||||||
|
/// second image. Only an APT start tone (or an explicit reset) may begin a
|
||||||
|
/// new reception after the first.
|
||||||
|
#[test]
|
||||||
|
fn variance_auto_start_only_fires_once_per_session() {
|
||||||
|
let mut dec = WefaxDecoder::new(11025, WefaxConfig::default());
|
||||||
|
|
||||||
|
// A transition rate that matches no APT tone → drives the variance
|
||||||
|
// based "strong signal" auto-start rather than a tone detection.
|
||||||
|
let strong = generate_apt_start(100.0, 11025, 4.0);
|
||||||
|
dec.process_samples(&strong);
|
||||||
|
assert!(
|
||||||
|
matches!(dec.state, State::Receiving { .. }),
|
||||||
|
"strong signal should auto-start one image, got {:?}",
|
||||||
|
dec.state
|
||||||
|
);
|
||||||
|
assert!(dec.auto_start_used);
|
||||||
|
|
||||||
|
// Simulate the image ending on carrier loss / stop (finalize → idle)
|
||||||
|
// WITHOUT an operator reset.
|
||||||
|
dec.transition_to_idle();
|
||||||
|
assert_eq!(dec.state, State::Idle);
|
||||||
|
|
||||||
|
// The still-present carrier must NOT spawn a second image.
|
||||||
|
dec.process_samples(&generate_apt_start(100.0, 11025, 4.0));
|
||||||
|
assert_eq!(
|
||||||
|
dec.state,
|
||||||
|
State::Idle,
|
||||||
|
"trailing signal must not re-auto-start a fresh image"
|
||||||
|
);
|
||||||
|
|
||||||
|
// An explicit reset re-arms mid-image auto-start.
|
||||||
|
dec.reset();
|
||||||
|
assert!(!dec.auto_start_used);
|
||||||
|
dec.process_samples(&generate_apt_start(100.0, 11025, 4.0));
|
||||||
|
assert!(
|
||||||
|
matches!(dec.state, State::Receiving { .. }),
|
||||||
|
"reset should re-arm variance auto-start, got {:?}",
|
||||||
|
dec.state
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ use crate::config::WefaxConfig;
|
|||||||
|
|
||||||
/// Line slicer for WEFAX image assembly.
|
/// Line slicer for WEFAX image assembly.
|
||||||
pub struct LineSlicer {
|
pub struct LineSlicer {
|
||||||
/// Samples per line at the internal sample rate.
|
/// Exact (fractional) samples per line at the internal sample rate.
|
||||||
samples_per_line: usize,
|
samples_per_line: f64,
|
||||||
/// Pixels per line (IOC × π).
|
/// Pixels per line (IOC × π).
|
||||||
pixels_per_line: usize,
|
pixels_per_line: usize,
|
||||||
/// Phase offset in samples from the phasing detector.
|
/// Phase offset in samples from the phasing detector.
|
||||||
@@ -22,22 +22,37 @@ pub struct LineSlicer {
|
|||||||
buffer: Vec<f32>,
|
buffer: Vec<f32>,
|
||||||
/// Whether we have aligned to the phase offset yet.
|
/// Whether we have aligned to the phase offset yet.
|
||||||
aligned: bool,
|
aligned: bool,
|
||||||
|
/// Index of the next line to emit. Boundaries are derived from this
|
||||||
|
/// against the exact fractional line length so rounding never accumulates.
|
||||||
|
line_index: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LineSlicer {
|
impl LineSlicer {
|
||||||
pub fn new(lpm: u16, ioc: u16, sample_rate: u32, phase_offset: usize) -> Self {
|
pub fn new(lpm: u16, ioc: u16, sample_rate: u32, phase_offset: usize) -> Self {
|
||||||
let samples_per_line = WefaxConfig::samples_per_line(lpm, sample_rate);
|
let samples_per_line = WefaxConfig::samples_per_line_f64(lpm, sample_rate);
|
||||||
let pixels_per_line = WefaxConfig::pixels_per_line(ioc) as usize;
|
let pixels_per_line = WefaxConfig::pixels_per_line(ioc) as usize;
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
samples_per_line,
|
samples_per_line,
|
||||||
pixels_per_line,
|
pixels_per_line,
|
||||||
phase_offset,
|
phase_offset,
|
||||||
buffer: Vec::with_capacity(samples_per_line * 2),
|
buffer: Vec::with_capacity(samples_per_line as usize * 2),
|
||||||
aligned: false,
|
aligned: false,
|
||||||
|
line_index: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Number of samples in line `n`, from the exact fractional line length.
|
||||||
|
///
|
||||||
|
/// Boundaries are `round(n · spl)`; the per-line length is the difference
|
||||||
|
/// of successive boundaries, so lengths alternate (e.g. 5513/5512 for
|
||||||
|
/// 120 LPM at 11 025 Hz) with no cumulative drift.
|
||||||
|
fn line_len(&self, n: u64) -> usize {
|
||||||
|
let start = (n as f64 * self.samples_per_line).round() as u64;
|
||||||
|
let end = ((n + 1) as f64 * self.samples_per_line).round() as u64;
|
||||||
|
(end - start) as usize
|
||||||
|
}
|
||||||
|
|
||||||
/// Feed luminance samples and extract complete image lines.
|
/// Feed luminance samples and extract complete image lines.
|
||||||
///
|
///
|
||||||
/// Returns a vector of completed lines, each as a `Vec<u8>` of
|
/// Returns a vector of completed lines, each as a `Vec<u8>` of
|
||||||
@@ -56,12 +71,18 @@ impl LineSlicer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extract complete lines (single drain at the end to avoid O(n²)).
|
// Extract complete lines (single drain at the end to avoid O(n²)).
|
||||||
|
// Line boundaries follow the exact fractional line length so the
|
||||||
|
// sample clock stays locked over a tall image (no accumulating slant).
|
||||||
let mut offset = 0;
|
let mut offset = 0;
|
||||||
while offset + self.samples_per_line <= self.buffer.len() {
|
loop {
|
||||||
let line_samples = &self.buffer[offset..offset + self.samples_per_line];
|
let len = self.line_len(self.line_index);
|
||||||
let pixels = self.resample_line(line_samples);
|
if offset + len > self.buffer.len() {
|
||||||
lines.push(pixels);
|
break;
|
||||||
offset += self.samples_per_line;
|
}
|
||||||
|
let line_samples = &self.buffer[offset..offset + len];
|
||||||
|
lines.push(self.resample_line(line_samples));
|
||||||
|
offset += len;
|
||||||
|
self.line_index += 1;
|
||||||
}
|
}
|
||||||
if offset > 0 {
|
if offset > 0 {
|
||||||
self.buffer.drain(..offset);
|
self.buffer.drain(..offset);
|
||||||
@@ -77,6 +98,7 @@ impl LineSlicer {
|
|||||||
pub fn reset(&mut self) {
|
pub fn reset(&mut self) {
|
||||||
self.buffer.clear();
|
self.buffer.clear();
|
||||||
self.aligned = false;
|
self.aligned = false;
|
||||||
|
self.line_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resample a line's worth of luminance samples to the target pixel count
|
/// Resample a line's worth of luminance samples to the target pixel count
|
||||||
@@ -129,6 +151,29 @@ mod tests {
|
|||||||
assert!(lines[0].iter().all(|&p| p == 255));
|
assert!(lines[0].iter().all(|&p| p == 255));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn slicer_no_cumulative_drift() {
|
||||||
|
// 120 LPM at 11 025 Hz is 5512.5 samples/line — not an integer. Slicing
|
||||||
|
// on the rounded value (5513) would lose a line every ~11 000 lines and
|
||||||
|
// slant the image; the fractional boundaries must not accumulate error.
|
||||||
|
let lpm = 120;
|
||||||
|
let ioc = 576;
|
||||||
|
let sr = 11025;
|
||||||
|
let spl = WefaxConfig::samples_per_line_f64(lpm, sr);
|
||||||
|
assert_ne!(spl.fract(), 0.0, "test premise: spl is fractional");
|
||||||
|
|
||||||
|
let mut slicer = LineSlicer::new(lpm, ioc, sr, 0);
|
||||||
|
let total = (spl * 1000.0).round() as usize;
|
||||||
|
let samples = vec![1.0f32; total];
|
||||||
|
let lines = slicer.process(&samples);
|
||||||
|
assert_eq!(
|
||||||
|
lines.len(),
|
||||||
|
1000,
|
||||||
|
"exactly 1000 lines should fit in {} samples with no drift",
|
||||||
|
total
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn slicer_linear_interpolation() {
|
fn slicer_linear_interpolation() {
|
||||||
let lpm = 120;
|
let lpm = 120;
|
||||||
|
|||||||
@@ -77,8 +77,12 @@ pub struct ToneDetector {
|
|||||||
|
|
||||||
impl ToneDetector {
|
impl ToneDetector {
|
||||||
pub fn new(sample_rate: u32) -> Self {
|
pub fn new(sample_rate: u32) -> Self {
|
||||||
|
// APT start/stop tones are transmitted for ~5 s (WMO), so requiring a
|
||||||
|
// 2 s sustain costs no real detection latency while sharply cutting
|
||||||
|
// false positives from busy image content that momentarily produces a
|
||||||
|
// 300/450/675-transitions-per-second rate.
|
||||||
let window_size = (sample_rate / 2) as usize; // ~0.5 s window
|
let window_size = (sample_rate / 2) as usize; // ~0.5 s window
|
||||||
let min_sustain_s = 1.0; // fldigi uses 2 consecutive half-second windows
|
let min_sustain_s = 2.0;
|
||||||
let window_duration_s = window_size as f32 / sample_rate as f32;
|
let window_duration_s = window_size as f32 / sample_rate as f32;
|
||||||
let min_sustain_windows = (min_sustain_s / window_duration_s).ceil() as u32;
|
let min_sustain_windows = (min_sustain_s / window_duration_s).ceil() as u32;
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
logout,
|
logout,
|
||||||
normalizeAuthRoles,
|
normalizeAuthRoles,
|
||||||
updateUser
|
updateUser
|
||||||
} from "./chunk-FT2RH7BL.js";
|
} from "./chunk-PISLBJGN.js";
|
||||||
|
|
||||||
// src/webgl-renderer.ts
|
// src/webgl-renderer.ts
|
||||||
(function initTrxWebGl(global) {
|
(function initTrxWebGl(global) {
|
||||||
@@ -1852,10 +1852,9 @@ function buildRoleChoices(selected) {
|
|||||||
input.addEventListener("change", () => {
|
input.addEventListener("change", () => {
|
||||||
if (!input.checked) return;
|
if (!input.checked) return;
|
||||||
if (value === "guest") {
|
if (value === "guest") {
|
||||||
inputs.forEach((choice) => {
|
const administrator = inputs.find((choice) => choice.value === "administrator");
|
||||||
if (choice.value !== "guest") choice.input.checked = false;
|
if (administrator) administrator.input.checked = false;
|
||||||
});
|
} else if (value === "administrator") {
|
||||||
} else {
|
|
||||||
const guest = inputs.find((choice) => choice.value === "guest");
|
const guest = inputs.find((choice) => choice.value === "guest");
|
||||||
if (guest) guest.input.checked = false;
|
if (guest) guest.input.checked = false;
|
||||||
}
|
}
|
||||||
@@ -1972,30 +1971,33 @@ function updateAuthUI() {
|
|||||||
}
|
}
|
||||||
function applyAuthRestrictions() {
|
function applyAuthRestrictions() {
|
||||||
if (authRoles.length === 0) return;
|
if (authRoles.length === 0) return;
|
||||||
if (!hasAuthRole2("control")) {
|
if (!hasAuthRole2("transmit")) {
|
||||||
const pttBtn2 = document.getElementById("ptt-btn");
|
const pttBtn2 = document.getElementById("ptt-btn");
|
||||||
|
const txLimitInput2 = document.getElementById("tx-limit");
|
||||||
|
const txLimitBtn2 = document.getElementById("tx-limit-btn");
|
||||||
|
const txAudioBtn2 = document.getElementById("tx-audio-btn");
|
||||||
|
const txLimitRow2 = document.getElementById("tx-limit-row");
|
||||||
|
if (pttBtn2) pttBtn2.disabled = true;
|
||||||
|
if (txAudioBtn2) txAudioBtn2.disabled = true;
|
||||||
|
if (txLimitBtn2) txLimitBtn2.disabled = true;
|
||||||
|
if (txLimitInput2) txLimitInput2.disabled = true;
|
||||||
|
if (txLimitRow2) txLimitRow2.style.opacity = "0.5";
|
||||||
|
}
|
||||||
|
if (!hasAuthRole2("control")) {
|
||||||
const powerBtn2 = document.getElementById("power-btn");
|
const powerBtn2 = document.getElementById("power-btn");
|
||||||
const lockBtn2 = document.getElementById("lock-btn");
|
const lockBtn2 = document.getElementById("lock-btn");
|
||||||
const freqInput = document.getElementById("freq");
|
const freqInput = document.getElementById("freq");
|
||||||
const centerFreqInput = document.getElementById("center-freq");
|
const centerFreqInput = document.getElementById("center-freq");
|
||||||
const modeSelect = document.getElementById("mode");
|
const modeSelect = document.getElementById("mode");
|
||||||
const txLimitInput2 = document.getElementById("tx-limit");
|
|
||||||
const txLimitBtn2 = document.getElementById("tx-limit-btn");
|
|
||||||
const txAudioBtn2 = document.getElementById("tx-audio-btn");
|
|
||||||
const txLimitRow2 = document.getElementById("tx-limit-row");
|
|
||||||
const jogUp = document.getElementById("jog-up");
|
const jogUp = document.getElementById("jog-up");
|
||||||
const jogDown = document.getElementById("jog-down");
|
const jogDown = document.getElementById("jog-down");
|
||||||
const jogButtons = document.querySelectorAll(".jog-step button");
|
const jogButtons = document.querySelectorAll(".jog-step button");
|
||||||
const vfoButtons = document.querySelectorAll("#vfo-picker button");
|
const vfoButtons = document.querySelectorAll("#vfo-picker button");
|
||||||
if (pttBtn2) pttBtn2.disabled = true;
|
|
||||||
if (powerBtn2) powerBtn2.disabled = true;
|
if (powerBtn2) powerBtn2.disabled = true;
|
||||||
if (lockBtn2) lockBtn2.disabled = true;
|
if (lockBtn2) lockBtn2.disabled = true;
|
||||||
if (txAudioBtn2) txAudioBtn2.disabled = true;
|
|
||||||
if (txLimitBtn2) txLimitBtn2.disabled = true;
|
|
||||||
if (freqInput) freqInput.disabled = true;
|
if (freqInput) freqInput.disabled = true;
|
||||||
if (centerFreqInput) centerFreqInput.disabled = true;
|
if (centerFreqInput) centerFreqInput.disabled = true;
|
||||||
if (modeSelect) modeSelect.disabled = true;
|
if (modeSelect) modeSelect.disabled = true;
|
||||||
if (txLimitInput2) txLimitInput2.disabled = true;
|
|
||||||
vfoButtons.forEach((btn) => btn.disabled = true);
|
vfoButtons.forEach((btn) => btn.disabled = true);
|
||||||
const jogWheel2 = document.getElementById("jog-wheel");
|
const jogWheel2 = document.getElementById("jog-wheel");
|
||||||
if (jogUp) jogUp.disabled = true;
|
if (jogUp) jogUp.disabled = true;
|
||||||
@@ -2032,7 +2034,6 @@ function applyAuthRestrictions() {
|
|||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (txLimitRow2) txLimitRow2.style.opacity = "0.5";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function applyCapabilities(caps) {
|
function applyCapabilities(caps) {
|
||||||
@@ -3728,10 +3729,19 @@ function visibleBandwidthSpecs(freqHz = lastFreqHz, mode = modeEl ? modeEl.value
|
|||||||
}
|
}
|
||||||
return [{ centerHz: freqHz, widthHz: currentBandwidthHz }];
|
return [{ centerHz: freqHz, widthHz: currentBandwidthHz }];
|
||||||
}
|
}
|
||||||
|
function digSidebandDirection() {
|
||||||
|
if (sdrDigSidebandPolicy === "usb") return 1;
|
||||||
|
if (sdrDigSidebandPolicy === "lsb") return -1;
|
||||||
|
if (typeof lastFreqHz === "number" && isFiniteNumber(lastFreqHz)) {
|
||||||
|
return lastFreqHz >= DIG_AUTO_SIDEBAND_THRESHOLD_HZ ? 1 : -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
function sidebandDirectionForMode(mode = modeEl ? modeEl.value : "") {
|
function sidebandDirectionForMode(mode = modeEl ? modeEl.value : "") {
|
||||||
const modeUpper = String(mode || "").toUpperCase();
|
const modeUpper = String(mode || "").toUpperCase();
|
||||||
if (modeUpper === "LSB" || modeUpper === "CWR") return -1;
|
if (modeUpper === "LSB" || modeUpper === "CWR") return -1;
|
||||||
if (modeUpper === "USB" || modeUpper === "CW" || modeUpper === "DIG") return 1;
|
if (modeUpper === "DIG") return sdrDigSidebandSupported ? digSidebandDirection() : 1;
|
||||||
|
if (modeUpper === "USB" || modeUpper === "CW") return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
function displaySpanForBandwidthSpec(spec, mode = modeEl ? modeEl.value : "") {
|
function displaySpanForBandwidthSpec(spec, mode = modeEl ? modeEl.value : "") {
|
||||||
@@ -4250,9 +4260,16 @@ function formatSignal(sUnits) {
|
|||||||
return overDb === 0 ? `${sigUnit("S")}9` : `${sigUnit("S")}9+${overDb}${sigUnit("dB")}`;
|
return overDb === 0 ? `${sigUnit("S")}9` : `${sigUnit("S")}9+${overDb}${sigUnit("dB")}`;
|
||||||
}
|
}
|
||||||
function setDisabled(disabled) {
|
function setDisabled(disabled) {
|
||||||
[freqEl, centerFreqEl, modeEl, pttBtn, powerBtn, txLimitInput, txLimitBtn, lockBtn].forEach((el) => {
|
const controlDisabled = disabled || authEnabled && !hasAuthRole2("control");
|
||||||
if (el) el.disabled = disabled;
|
const transmitDisabled = disabled || authEnabled && !hasAuthRole2("transmit");
|
||||||
|
[freqEl, centerFreqEl, modeEl, powerBtn, lockBtn].forEach((el) => {
|
||||||
|
if (el) el.disabled = controlDisabled;
|
||||||
});
|
});
|
||||||
|
[pttBtn, txLimitInput, txLimitBtn].forEach((el) => {
|
||||||
|
if (el) el.disabled = transmitDisabled;
|
||||||
|
});
|
||||||
|
const transmitAudio = document.getElementById("tx-audio-btn");
|
||||||
|
if (transmitAudio) transmitAudio.disabled = transmitDisabled || !hasWebCodecs;
|
||||||
syncModePicker();
|
syncModePicker();
|
||||||
}
|
}
|
||||||
var serverVersion = null;
|
var serverVersion = null;
|
||||||
@@ -4749,6 +4766,25 @@ function render(update) {
|
|||||||
sdrNbThresholdEl.value = String(Math.round(update.filter.sdr_nb_threshold));
|
sdrNbThresholdEl.value = String(Math.round(update.filter.sdr_nb_threshold));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (typeof update.filter.sdr_nb_profile === "string") {
|
||||||
|
sdrNbProfile = update.filter.sdr_nb_profile;
|
||||||
|
if (sdrNbProfileWrapEl) sdrNbProfileWrapEl.style.display = "";
|
||||||
|
if (sdrNbProfileEl && document.activeElement !== sdrNbProfileEl) {
|
||||||
|
sdrNbProfileEl.value = update.filter.sdr_nb_profile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (typeof update.filter.sdr_dig_sideband === "string") {
|
||||||
|
sdrDigSidebandSupported = true;
|
||||||
|
const prevPolicy = sdrDigSidebandPolicy;
|
||||||
|
sdrDigSidebandPolicy = update.filter.sdr_dig_sideband;
|
||||||
|
if (sdrDigSidebandEl && document.activeElement !== sdrDigSidebandEl) {
|
||||||
|
sdrDigSidebandEl.value = update.filter.sdr_dig_sideband;
|
||||||
|
}
|
||||||
|
updateWfmControls();
|
||||||
|
if (prevPolicy !== sdrDigSidebandPolicy && lastSpectrumData) {
|
||||||
|
scheduleSpectrumDraw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (typeof update.show_sdr_gain_control === "boolean") {
|
if (typeof update.show_sdr_gain_control === "boolean") {
|
||||||
@@ -6088,6 +6124,14 @@ async function refreshUserManagement() {
|
|||||||
password.className = "auth-input";
|
password.className = "auth-input";
|
||||||
password.minLength = 8;
|
password.minLength = 8;
|
||||||
password.maxLength = 1024;
|
password.maxLength = 1024;
|
||||||
|
const syncPasswordAccess = () => {
|
||||||
|
const guestActive = guestInput?.checked === true;
|
||||||
|
password.disabled = guestActive;
|
||||||
|
password.title = guestActive ? "Password changes are unavailable while the Guest role is active" : "";
|
||||||
|
if (guestActive) password.value = "";
|
||||||
|
};
|
||||||
|
roleInputs.forEach(({ input }) => input.addEventListener("change", syncPasswordAccess));
|
||||||
|
syncPasswordAccess();
|
||||||
const save = document.createElement("button");
|
const save = document.createElement("button");
|
||||||
save.type = "button";
|
save.type = "button";
|
||||||
save.textContent = "Save";
|
save.textContent = "Save";
|
||||||
@@ -6607,7 +6651,15 @@ var sdrNbEnabledEl = document.getElementById("sdr-nb-enabled");
|
|||||||
var sdrNbThresholdControlsEl = document.getElementById("sdr-nb-threshold-controls");
|
var sdrNbThresholdControlsEl = document.getElementById("sdr-nb-threshold-controls");
|
||||||
var sdrNbThresholdEl = document.getElementById("sdr-nb-threshold");
|
var sdrNbThresholdEl = document.getElementById("sdr-nb-threshold");
|
||||||
var sdrNbThresholdSetBtn = document.getElementById("sdr-nb-threshold-set");
|
var sdrNbThresholdSetBtn = document.getElementById("sdr-nb-threshold-set");
|
||||||
|
var sdrNbProfileWrapEl = document.getElementById("sdr-nb-profile-wrap");
|
||||||
|
var sdrNbProfileEl = document.getElementById("sdr-nb-profile");
|
||||||
var sdrNbSupported = false;
|
var sdrNbSupported = false;
|
||||||
|
var sdrNbProfile = "spike";
|
||||||
|
var sdrDigSidebandWrapEl = document.getElementById("sdr-dig-sideband-wrap");
|
||||||
|
var sdrDigSidebandEl = document.getElementById("sdr-dig-sideband");
|
||||||
|
var sdrDigSidebandSupported = false;
|
||||||
|
var sdrDigSidebandPolicy = "auto";
|
||||||
|
var DIG_AUTO_SIDEBAND_THRESHOLD_HZ = 1e7;
|
||||||
fetch("/audio", { method: "GET" }).then((r) => {
|
fetch("/audio", { method: "GET" }).then((r) => {
|
||||||
if (r.status === 404) audioRow.style.display = "none";
|
if (r.status === 404) audioRow.style.display = "none";
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
@@ -6977,7 +7029,7 @@ function submitSdrNbState() {
|
|||||||
const threshold = sdrNbThresholdEl ? Number.parseFloat(sdrNbThresholdEl.value) : 10;
|
const threshold = sdrNbThresholdEl ? Number.parseFloat(sdrNbThresholdEl.value) : 10;
|
||||||
if (!isFiniteNumber(threshold) || threshold < 1 || threshold > 100) return;
|
if (!isFiniteNumber(threshold) || threshold < 1 || threshold > 100) return;
|
||||||
postPath(
|
postPath(
|
||||||
`/set_sdr_noise_blanker?enabled=${enabled ? "true" : "false"}&threshold=${encodeURIComponent(threshold)}`
|
`/set_sdr_noise_blanker?enabled=${enabled ? "true" : "false"}&threshold=${encodeURIComponent(threshold)}&profile=${encodeURIComponent(sdrNbProfile)}`
|
||||||
).catch(() => {
|
).catch(() => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -6986,6 +7038,16 @@ if (sdrNbEnabledEl) {
|
|||||||
submitSdrNbState();
|
submitSdrNbState();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (sdrNbProfileEl) {
|
||||||
|
sdrNbProfileEl.addEventListener("change", () => {
|
||||||
|
const profile = sdrNbProfileEl.value || "spike";
|
||||||
|
if (profile !== "spike" && profile !== "ignition" && profile !== "powerline" && profile !== "broadband") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sdrNbProfile = profile;
|
||||||
|
submitSdrNbState();
|
||||||
|
});
|
||||||
|
}
|
||||||
function submitSdrNbThreshold() {
|
function submitSdrNbThreshold() {
|
||||||
if (!sdrNbThresholdEl) return;
|
if (!sdrNbThresholdEl) return;
|
||||||
const parsed = Number.parseFloat(sdrNbThresholdEl.value);
|
const parsed = Number.parseFloat(sdrNbThresholdEl.value);
|
||||||
@@ -7003,11 +7065,28 @@ if (sdrNbThresholdEl) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function submitSdrDigSideband() {
|
||||||
|
if (!sdrDigSidebandSupported || !sdrDigSidebandEl) return;
|
||||||
|
const policy = sdrDigSidebandEl.value || "auto";
|
||||||
|
if (policy !== "auto" && policy !== "usb" && policy !== "lsb") return;
|
||||||
|
sdrDigSidebandPolicy = policy;
|
||||||
|
if (lastSpectrumData) scheduleSpectrumDraw();
|
||||||
|
postPath(`/set_sdr_dig_sideband?policy=${encodeURIComponent(policy)}`).catch(() => {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (sdrDigSidebandEl) {
|
||||||
|
sdrDigSidebandEl.addEventListener("change", () => {
|
||||||
|
submitSdrDigSideband();
|
||||||
|
});
|
||||||
|
}
|
||||||
function updateWfmControls() {
|
function updateWfmControls() {
|
||||||
const mode = (modeEl && modeEl.value ? modeEl.value : "").toUpperCase();
|
const mode = (modeEl && modeEl.value ? modeEl.value : "").toUpperCase();
|
||||||
if (wfmControlsCol) wfmControlsCol.style.display = mode === "WFM" ? "" : "none";
|
if (wfmControlsCol) wfmControlsCol.style.display = mode === "WFM" ? "" : "none";
|
||||||
if (samControlsCol) samControlsCol.style.display = mode === "SAM" ? "" : "none";
|
if (samControlsCol) samControlsCol.style.display = mode === "SAM" ? "" : "none";
|
||||||
if (modeControlsRow) modeControlsRow.style.display = mode === "WFM" || mode === "SAM" ? "" : "none";
|
if (modeControlsRow) modeControlsRow.style.display = mode === "WFM" || mode === "SAM" ? "" : "none";
|
||||||
|
if (sdrDigSidebandWrapEl) {
|
||||||
|
sdrDigSidebandWrapEl.style.display = sdrDigSidebandSupported && mode === "DIG" ? "" : "none";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!hasWebCodecs) {
|
if (!hasWebCodecs) {
|
||||||
rxAudioBtn.disabled = true;
|
rxAudioBtn.disabled = true;
|
||||||
@@ -7329,6 +7408,10 @@ function startTxAudio() {
|
|||||||
void stopTxAudio();
|
void stopTxAudio();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (authEnabled && !hasAuthRole2("transmit")) {
|
||||||
|
audioStatus.textContent = "Transmit role required";
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!hasWebCodecs) {
|
if (!hasWebCodecs) {
|
||||||
audioStatus.textContent = "Audio requires Chrome/Edge";
|
audioStatus.textContent = "Audio requires Chrome/Edge";
|
||||||
return;
|
return;
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
hasAuthRole
|
hasAuthRole
|
||||||
} from "./chunk-FT2RH7BL.js";
|
} from "./chunk-PISLBJGN.js";
|
||||||
import {
|
import {
|
||||||
hostState
|
hostState
|
||||||
} from "./chunk-KL66PICH.js";
|
} from "./chunk-KL66PICH.js";
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
hasAuthRole
|
hasAuthRole
|
||||||
} from "./chunk-FT2RH7BL.js";
|
} from "./chunk-PISLBJGN.js";
|
||||||
import {
|
import {
|
||||||
hostCore,
|
hostCore,
|
||||||
hostState
|
hostState
|
||||||
@@ -214,6 +214,12 @@ function bmBuildDecoderCheckboxes() {
|
|||||||
container.appendChild(label);
|
container.appendChild(label);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function bmSyncDigSidebandVisibility() {
|
||||||
|
const label = bmOptionalEl("bm-dig-sideband-label");
|
||||||
|
if (!label) return;
|
||||||
|
const mode = (bmEl("bm-mode").value || "").trim().toUpperCase();
|
||||||
|
label.style.display = mode === "DIG" ? "" : "none";
|
||||||
|
}
|
||||||
function bmOpenForm(bm) {
|
function bmOpenForm(bm) {
|
||||||
const wrap = bmEl("bm-form-wrap");
|
const wrap = bmEl("bm-form-wrap");
|
||||||
if (!wrap) return;
|
if (!wrap) return;
|
||||||
@@ -227,7 +233,9 @@ function bmOpenForm(bm) {
|
|||||||
bmEl("bm-locator").value = bm ? bm.locator || "" : "";
|
bmEl("bm-locator").value = bm ? bm.locator || "" : "";
|
||||||
bmEl("bm-category-input").value = bm ? bm.category || "" : "";
|
bmEl("bm-category-input").value = bm ? bm.category || "" : "";
|
||||||
bmEl("bm-comment").value = bm ? bm.comment || "" : "";
|
bmEl("bm-comment").value = bm ? bm.comment || "" : "";
|
||||||
|
bmEl("bm-dig-sideband").value = bm ? bm.dig_sideband || "" : "";
|
||||||
bmWriteDecoders(bm?.decoders ?? []);
|
bmWriteDecoders(bm?.decoders ?? []);
|
||||||
|
bmSyncDigSidebandVisibility();
|
||||||
bmEl("bm-form-title").textContent = bm ? "Edit Bookmark" : "Add Bookmark";
|
bmEl("bm-form-title").textContent = bm ? "Edit Bookmark" : "Add Bookmark";
|
||||||
wrap.style.display = "flex";
|
wrap.style.display = "flex";
|
||||||
bmEl("bm-name").focus();
|
bmEl("bm-name").focus();
|
||||||
@@ -263,6 +271,7 @@ async function bmSave(e) {
|
|||||||
const category = bmEl("bm-category-input").value.trim();
|
const category = bmEl("bm-category-input").value.trim();
|
||||||
const comment = bmEl("bm-comment").value.trim();
|
const comment = bmEl("bm-comment").value.trim();
|
||||||
const decoders = bmReadDecoders();
|
const decoders = bmReadDecoders();
|
||||||
|
const dig_sideband = mode.toUpperCase() === "DIG" ? bmEl("bm-dig-sideband").value || null : null;
|
||||||
const formError = bmEl("bm-form-error");
|
const formError = bmEl("bm-form-error");
|
||||||
if (formError) formError.textContent = "";
|
if (formError) formError.textContent = "";
|
||||||
if (!name || !Number.isFinite(freq_hz) || !mode) {
|
if (!name || !Number.isFinite(freq_hz) || !mode) {
|
||||||
@@ -279,7 +288,8 @@ async function bmSave(e) {
|
|||||||
locator: locator || null,
|
locator: locator || null,
|
||||||
category,
|
category,
|
||||||
comment,
|
comment,
|
||||||
decoders
|
decoders,
|
||||||
|
dig_sideband
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
let resp;
|
let resp;
|
||||||
@@ -344,6 +354,12 @@ function bmApply(bm) {
|
|||||||
}
|
}
|
||||||
const tunePromise = (async () => {
|
const tunePromise = (async () => {
|
||||||
await bridge.trx.modules.vchan?.takeSchedulerControl();
|
await bridge.trx.modules.vchan?.takeSchedulerControl();
|
||||||
|
if ((bm.mode || "").toUpperCase() === "DIG" && bm.dig_sideband) {
|
||||||
|
const p = bm.dig_sideband.toLowerCase();
|
||||||
|
if (p === "auto" || p === "usb" || p === "lsb") {
|
||||||
|
await hostCore.postPath("/set_sdr_dig_sideband?policy=" + encodeURIComponent(p));
|
||||||
|
}
|
||||||
|
}
|
||||||
const onVirtual = await bridge.trx.modules.vchan?.interceptMode(bm.mode) ?? false;
|
const onVirtual = await bridge.trx.modules.vchan?.interceptMode(bm.mode) ?? false;
|
||||||
if (!onVirtual) {
|
if (!onVirtual) {
|
||||||
await hostCore.postPath("/set_mode?mode=" + encodeURIComponent(bm.mode));
|
await hostCore.postPath("/set_mode?mode=" + encodeURIComponent(bm.mode));
|
||||||
@@ -596,6 +612,7 @@ function bmPopulateScopePicker() {
|
|||||||
bmEl("bm-form").addEventListener("submit", (event) => {
|
bmEl("bm-form").addEventListener("submit", (event) => {
|
||||||
void bmSave(event);
|
void bmSave(event);
|
||||||
});
|
});
|
||||||
|
bmEl("bm-mode").addEventListener("input", bmSyncDigSidebandVisibility);
|
||||||
bmEl("bm-form-cancel").addEventListener("click", bmCloseForm);
|
bmEl("bm-form-cancel").addEventListener("click", bmCloseForm);
|
||||||
const formWrap = bmEl("bm-form-wrap");
|
const formWrap = bmEl("bm-form-wrap");
|
||||||
if (formWrap) {
|
if (formWrap) {
|
||||||
|
|||||||
+3
-2
@@ -1,10 +1,11 @@
|
|||||||
// src/api/auth.ts
|
// src/api/auth.ts
|
||||||
var AUTH_ROLES = ["guest", "read", "control", "write", "administrator"];
|
var AUTH_ROLES = ["guest", "read", "control", "transmit", "write", "administrator"];
|
||||||
var AUTH_ADMIN_ROLES = AUTH_ROLES.filter((role) => role !== "guest");
|
var AUTH_ADMIN_ROLES = AUTH_ROLES.filter((role) => role !== "guest");
|
||||||
var AUTH_ROLE_LABELS = {
|
var AUTH_ROLE_LABELS = {
|
||||||
guest: "Guest",
|
guest: "Guest",
|
||||||
read: "Read",
|
read: "Read",
|
||||||
control: "Control",
|
control: "Control",
|
||||||
|
transmit: "Transmit",
|
||||||
write: "Write",
|
write: "Write",
|
||||||
administrator: "Administrator"
|
administrator: "Administrator"
|
||||||
};
|
};
|
||||||
@@ -15,7 +16,7 @@ function normalizeAuthRoles(roles) {
|
|||||||
return AUTH_ROLES.filter((role) => roles.includes(role));
|
return AUTH_ROLES.filter((role) => roles.includes(role));
|
||||||
}
|
}
|
||||||
function hasAuthRole(roles, required) {
|
function hasAuthRole(roles, required) {
|
||||||
return roles.includes("administrator") || roles.includes(required) || required === "read" && roles.includes("guest") || required === "read" && roles.includes("control");
|
return roles.includes("administrator") || roles.includes(required) || required === "read" && roles.includes("guest") || required === "read" && (roles.includes("control") || roles.includes("transmit"));
|
||||||
}
|
}
|
||||||
function hasAccountControls(roles) {
|
function hasAccountControls(roles) {
|
||||||
return roles.length > 0 && !roles.includes("guest");
|
return roles.length > 0 && !roles.includes("guest");
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
hasAuthRole
|
hasAuthRole
|
||||||
} from "./chunk-FT2RH7BL.js";
|
} from "./chunk-PISLBJGN.js";
|
||||||
import {
|
import {
|
||||||
hostCore,
|
hostCore,
|
||||||
hostState
|
hostState
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
hasAuthRole
|
hasAuthRole
|
||||||
} from "./chunk-FT2RH7BL.js";
|
} from "./chunk-PISLBJGN.js";
|
||||||
import {
|
import {
|
||||||
hostState
|
hostState
|
||||||
} from "./chunk-KL66PICH.js";
|
} from "./chunk-KL66PICH.js";
|
||||||
|
|||||||
@@ -385,6 +385,23 @@ SPDX-License-Identifier: GPL-2.0-or-later
|
|||||||
</label>
|
</label>
|
||||||
<button id="sdr-nb-threshold-set" type="button" class="wfm-inline-btn">Set</button>
|
<button id="sdr-nb-threshold-set" type="button" class="wfm-inline-btn">Set</button>
|
||||||
</div>
|
</div>
|
||||||
|
<label class="wfm-control" id="sdr-nb-profile-wrap" style="display:none;">
|
||||||
|
<span class="wfm-control-label" title="Matches the blanker to the interference: Spike = sharp bursts, Ignition = engine/PWM, Powerline = mains buzz, Broadband = dense noise.">NB profile</span>
|
||||||
|
<select id="sdr-nb-profile" class="status-input">
|
||||||
|
<option value="spike">Spike</option>
|
||||||
|
<option value="ignition">Ignition</option>
|
||||||
|
<option value="powerline">Powerline</option>
|
||||||
|
<option value="broadband">Broadband</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label class="wfm-control" id="sdr-dig-sideband-wrap" style="display:none;">
|
||||||
|
<span class="wfm-control-label" title="Sideband used to demodulate DIG. Auto = USB ≥ 10 MHz, LSB below.">DIG sideband</span>
|
||||||
|
<select id="sdr-dig-sideband" class="status-input">
|
||||||
|
<option value="auto">Auto (by band)</option>
|
||||||
|
<option value="usb">USB</option>
|
||||||
|
<option value="lsb">LSB</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="full-row label-below-row" id="vchan-row">
|
<div class="full-row label-below-row" id="vchan-row">
|
||||||
@@ -721,6 +738,14 @@ SPDX-License-Identifier: GPL-2.0-or-later
|
|||||||
<label class="bm-label">Bandwidth (Hz)
|
<label class="bm-label">Bandwidth (Hz)
|
||||||
<input type="number" id="bm-bw" class="status-input" min="0" placeholder="optional" />
|
<input type="number" id="bm-bw" class="status-input" min="0" placeholder="optional" />
|
||||||
</label>
|
</label>
|
||||||
|
<label class="bm-label" id="bm-dig-sideband-label" style="display:none;">DIG sideband
|
||||||
|
<select id="bm-dig-sideband" class="status-input">
|
||||||
|
<option value="">Global setting</option>
|
||||||
|
<option value="auto">Auto (by band)</option>
|
||||||
|
<option value="usb">USB</option>
|
||||||
|
<option value="lsb">LSB</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
<label class="bm-label">Locator
|
<label class="bm-label">Locator
|
||||||
<input type="text" id="bm-locator" class="status-input" maxlength="6" placeholder="e.g. JO93" />
|
<input type="text" id="bm-locator" class="status-input" maxlength="6" placeholder="e.g. JO93" />
|
||||||
</label>
|
</label>
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ use trx_core::rig::{
|
|||||||
RigAccessMethod, RigCapabilities, RigInfo, RigRxStatus, RigStatus, RigTxStatus, RigVfo,
|
RigAccessMethod, RigCapabilities, RigInfo, RigRxStatus, RigStatus, RigTxStatus, RigVfo,
|
||||||
RigVfoEntry,
|
RigVfoEntry,
|
||||||
};
|
};
|
||||||
use trx_core::{DecoderConfig, RdsData, RigFilterState, RigMode, RigSnapshot, WfmDenoiseLevel};
|
use trx_core::{
|
||||||
|
DecoderConfig, DigSidebandPolicy, NoiseBlankerProfile, RdsData, RigFilterState, RigMode,
|
||||||
|
RigSnapshot, WfmDenoiseLevel,
|
||||||
|
};
|
||||||
use trx_frontend_http::server::api::rig::{RigListItem, RigListResponse};
|
use trx_frontend_http::server::api::rig::{RigListItem, RigListResponse};
|
||||||
use trx_frontend_http::server::api::FrontendMeta;
|
use trx_frontend_http::server::api::FrontendMeta;
|
||||||
use trx_frontend_http::server::auth::AuthRole;
|
use trx_frontend_http::server::auth::AuthRole;
|
||||||
@@ -49,6 +52,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
export!(RigStatus);
|
export!(RigStatus);
|
||||||
export!(DecoderConfig);
|
export!(DecoderConfig);
|
||||||
export!(WfmDenoiseLevel);
|
export!(WfmDenoiseLevel);
|
||||||
|
export!(DigSidebandPolicy);
|
||||||
|
export!(NoiseBlankerProfile);
|
||||||
export!(RigFilterState);
|
export!(RigFilterState);
|
||||||
export!(RdsData);
|
export!(RdsData);
|
||||||
export!(SpectrumData);
|
export!(SpectrumData);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
"typecheck": "tsc --project tsconfig.json && tsc --project tsconfig.worker.json",
|
"typecheck": "tsc --project tsconfig.json && tsc --project tsconfig.worker.json",
|
||||||
"lint": "eslint \"src/**/*.ts\" \"tests/**/*.mjs\" build.mjs --no-error-on-unmatched-pattern",
|
"lint": "eslint \"src/**/*.ts\" \"tests/**/*.mjs\" build.mjs --no-error-on-unmatched-pattern",
|
||||||
"test": "node --test tests/*.test.mjs",
|
"test": "node --test tests/*.test.mjs",
|
||||||
"test:browser": "node tests/browser-smoke.mjs && node tests/spectrum-layout.mjs && node tests/decode-flow.mjs && node tests/tune-links.mjs && node tests/mobile-layout.mjs && node tests/satellite-predictions.mjs && node tests/background-decode.mjs && node tests/logbook.mjs && node tests/account-management.mjs",
|
"test:browser": "node tests/browser-smoke.mjs && node tests/spectrum-layout.mjs && node tests/decode-flow.mjs && node tests/tune-links.mjs && node tests/mobile-layout.mjs && node tests/satellite-predictions.mjs && node tests/background-decode.mjs && node tests/logbook.mjs && node tests/account-management.mjs && node tests/transmit-role.mjs",
|
||||||
"verify-generated": "npm run generate-types && npm run build && git diff --exit-code -- ../assets/web/generated src/api/generated.ts"
|
"verify-generated": "npm run generate-types && npm run build && git diff --exit-code -- ../assets/web/generated src/api/generated.ts"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -6,12 +6,13 @@ import type { AuthRole } from "./generated.js";
|
|||||||
|
|
||||||
export type { AuthRole };
|
export type { AuthRole };
|
||||||
|
|
||||||
export const AUTH_ROLES: readonly AuthRole[] = ["guest", "read", "control", "write", "administrator"];
|
export const AUTH_ROLES: readonly AuthRole[] = ["guest", "read", "control", "transmit", "write", "administrator"];
|
||||||
export const AUTH_ADMIN_ROLES: readonly AuthRole[] = AUTH_ROLES.filter(role => role !== "guest");
|
export const AUTH_ADMIN_ROLES: readonly AuthRole[] = AUTH_ROLES.filter(role => role !== "guest");
|
||||||
export const AUTH_ROLE_LABELS: Readonly<Record<AuthRole, string>> = {
|
export const AUTH_ROLE_LABELS: Readonly<Record<AuthRole, string>> = {
|
||||||
guest: "Guest",
|
guest: "Guest",
|
||||||
read: "Read",
|
read: "Read",
|
||||||
control: "Control",
|
control: "Control",
|
||||||
|
transmit: "Transmit",
|
||||||
write: "Write",
|
write: "Write",
|
||||||
administrator: "Administrator",
|
administrator: "Administrator",
|
||||||
};
|
};
|
||||||
@@ -28,7 +29,7 @@ export function hasAuthRole(roles: readonly AuthRole[], required: AuthRole): boo
|
|||||||
return roles.includes("administrator")
|
return roles.includes("administrator")
|
||||||
|| roles.includes(required)
|
|| roles.includes(required)
|
||||||
|| required === "read" && roles.includes("guest")
|
|| required === "read" && roles.includes("guest")
|
||||||
|| required === "read" && roles.includes("control");
|
|| required === "read" && (roles.includes("control") || roles.includes("transmit"));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hasAccountControls(roles: readonly AuthRole[]): boolean {
|
export function hasAccountControls(roles: readonly AuthRole[]): boolean {
|
||||||
|
|||||||
@@ -55,7 +55,21 @@ export type DecoderConfig = { aprs_decode_enabled: boolean, hf_aprs_decode_enabl
|
|||||||
|
|
||||||
export type WfmDenoiseLevel = "off" | "auto" | "low" | "medium" | "high";
|
export type WfmDenoiseLevel = "off" | "auto" | "low" | "medium" | "high";
|
||||||
|
|
||||||
export type RigFilterState = { bandwidth_hz: number, cw_center_hz: number, sdr_gain_db?: number | null, sdr_lna_gain_db?: number | null, sdr_agc_enabled?: boolean | null, sdr_squelch_enabled?: boolean | null, sdr_squelch_threshold_db?: number | null, sdr_nb_enabled?: boolean | null, sdr_nb_threshold?: number | null, wfm_deemphasis_us: number, wfm_stereo: boolean, wfm_stereo_detected: boolean, wfm_denoise: WfmDenoiseLevel,
|
export type DigSidebandPolicy = "auto" | "usb" | "lsb";
|
||||||
|
|
||||||
|
export type NoiseBlankerProfile = "spike" | "ignition" | "powerline" | "broadband";
|
||||||
|
|
||||||
|
export type RigFilterState = { bandwidth_hz: number, cw_center_hz: number, sdr_gain_db?: number | null, sdr_lna_gain_db?: number | null, sdr_agc_enabled?: boolean | null, sdr_squelch_enabled?: boolean | null, sdr_squelch_threshold_db?: number | null, sdr_nb_enabled?: boolean | null, sdr_nb_threshold?: number | null,
|
||||||
|
/**
|
||||||
|
* Current noise-blanker tuning profile (SDR backends only). Surfaces in the
|
||||||
|
* UI as the advanced-controls "NB profile" selector.
|
||||||
|
*/
|
||||||
|
sdr_nb_profile?: NoiseBlankerProfile | null,
|
||||||
|
/**
|
||||||
|
* Current DIG sideband policy (SDR backends only). Surfaces in the UI as
|
||||||
|
* the advanced-controls "DIG sideband" selector.
|
||||||
|
*/
|
||||||
|
sdr_dig_sideband?: DigSidebandPolicy | null, wfm_deemphasis_us: number, wfm_stereo: boolean, wfm_stereo_detected: boolean, wfm_denoise: WfmDenoiseLevel,
|
||||||
/**
|
/**
|
||||||
* Co-Channel Interference level (0–100 scale).
|
* Co-Channel Interference level (0–100 scale).
|
||||||
*/
|
*/
|
||||||
@@ -123,7 +137,7 @@ export type RigListResponse = { active_remote: string | null, rigs: Array<RigLis
|
|||||||
|
|
||||||
export type FrontendMeta = { clients: number, rigctl_clients: number, audio_clients: number, rigctl_addr: string | null, active_remote: string | null, remotes: Array<string>, owner_callsign: string | null, owner_website_url: string | null, owner_website_name: string | null, ais_vessel_url_base: string | null, show_sdr_gain_control: boolean, initial_map_zoom: number, spectrum_coverage_margin_hz: number, spectrum_usable_span_ratio: number, bandplan_enabled: boolean, bandplan_region: string, decode_history_retention_min: bigint, server_connected: boolean, };
|
export type FrontendMeta = { clients: number, rigctl_clients: number, audio_clients: number, rigctl_addr: string | null, active_remote: string | null, remotes: Array<string>, owner_callsign: string | null, owner_website_url: string | null, owner_website_name: string | null, ais_vessel_url_base: string | null, show_sdr_gain_control: boolean, initial_map_zoom: number, spectrum_coverage_margin_hz: number, spectrum_usable_span_ratio: number, bandplan_enabled: boolean, bandplan_region: string, decode_history_retention_min: bigint, server_connected: boolean, };
|
||||||
|
|
||||||
export type AuthRole = "guest" | "read" | "control" | "write" | "administrator";
|
export type AuthRole = "guest" | "read" | "control" | "transmit" | "write" | "administrator";
|
||||||
|
|
||||||
export type DecoderActivation = "mode_bound" | "toggle";
|
export type DecoderActivation = "mode_bound" | "toggle";
|
||||||
|
|
||||||
|
|||||||
@@ -447,8 +447,9 @@ function buildRoleChoices(selected: readonly AuthRole[]) {
|
|||||||
input.addEventListener("change", () => {
|
input.addEventListener("change", () => {
|
||||||
if (!input.checked) return;
|
if (!input.checked) return;
|
||||||
if (value === "guest") {
|
if (value === "guest") {
|
||||||
inputs.forEach(choice => { if (choice.value !== "guest") choice.input.checked = false; });
|
const administrator = inputs.find(choice => choice.value === "administrator");
|
||||||
} else {
|
if (administrator) administrator.input.checked = false;
|
||||||
|
} else if (value === "administrator") {
|
||||||
const guest = inputs.find(choice => choice.value === "guest");
|
const guest = inputs.find(choice => choice.value === "guest");
|
||||||
if (guest) guest.input.checked = false;
|
if (guest) guest.input.checked = false;
|
||||||
}
|
}
|
||||||
@@ -584,35 +585,38 @@ function updateAuthUI() {
|
|||||||
function applyAuthRestrictions() {
|
function applyAuthRestrictions() {
|
||||||
if (authRoles.length === 0) return;
|
if (authRoles.length === 0) return;
|
||||||
|
|
||||||
// Disable TX/PTT/frequency/mode/VFO controls for user role
|
if (!hasAuthRole("transmit")) {
|
||||||
if (!hasAuthRole("control")) {
|
|
||||||
const pttBtn = document.getElementById("ptt-btn") as HTMLButtonElement | null;
|
const pttBtn = document.getElementById("ptt-btn") as HTMLButtonElement | null;
|
||||||
|
const txLimitInput = document.getElementById("tx-limit") as HTMLInputElement | null;
|
||||||
|
const txLimitBtn = document.getElementById("tx-limit-btn") as HTMLButtonElement | null;
|
||||||
|
const txAudioBtn = document.getElementById("tx-audio-btn") as HTMLButtonElement | null;
|
||||||
|
const txLimitRow = document.getElementById("tx-limit-row");
|
||||||
|
if (pttBtn) pttBtn.disabled = true;
|
||||||
|
if (txAudioBtn) txAudioBtn.disabled = true;
|
||||||
|
if (txLimitBtn) txLimitBtn.disabled = true;
|
||||||
|
if (txLimitInput) txLimitInput.disabled = true;
|
||||||
|
if (txLimitRow) txLimitRow.style.opacity = "0.5";
|
||||||
|
}
|
||||||
|
|
||||||
|
// General tuning and receive-side controls require Control.
|
||||||
|
if (!hasAuthRole("control")) {
|
||||||
const powerBtn = document.getElementById("power-btn") as HTMLButtonElement | null;
|
const powerBtn = document.getElementById("power-btn") as HTMLButtonElement | null;
|
||||||
const lockBtn = document.getElementById("lock-btn") as HTMLButtonElement | null;
|
const lockBtn = document.getElementById("lock-btn") as HTMLButtonElement | null;
|
||||||
const freqInput = document.getElementById("freq") as HTMLInputElement | null;
|
const freqInput = document.getElementById("freq") as HTMLInputElement | null;
|
||||||
const centerFreqInput = document.getElementById("center-freq") as HTMLInputElement | null;
|
const centerFreqInput = document.getElementById("center-freq") as HTMLInputElement | null;
|
||||||
const modeSelect = document.getElementById("mode") as HTMLSelectElement | null;
|
const modeSelect = document.getElementById("mode") as HTMLSelectElement | null;
|
||||||
const txLimitInput = document.getElementById("tx-limit") as HTMLInputElement | null;
|
|
||||||
const txLimitBtn = document.getElementById("tx-limit-btn") as HTMLButtonElement | null;
|
|
||||||
const txAudioBtn = document.getElementById("tx-audio-btn") as HTMLButtonElement | null;
|
|
||||||
const txLimitRow = document.getElementById("tx-limit-row");
|
|
||||||
const jogUp = document.getElementById("jog-up") as HTMLButtonElement | null;
|
const jogUp = document.getElementById("jog-up") as HTMLButtonElement | null;
|
||||||
const jogDown = document.getElementById("jog-down") as HTMLButtonElement | null;
|
const jogDown = document.getElementById("jog-down") as HTMLButtonElement | null;
|
||||||
const jogButtons = document.querySelectorAll<HTMLButtonElement>(".jog-step button");
|
const jogButtons = document.querySelectorAll<HTMLButtonElement>(".jog-step button");
|
||||||
const vfoButtons = document.querySelectorAll<HTMLButtonElement>("#vfo-picker button");
|
const vfoButtons = document.querySelectorAll<HTMLButtonElement>("#vfo-picker button");
|
||||||
|
|
||||||
// Disable TX buttons
|
|
||||||
if (pttBtn) pttBtn.disabled = true;
|
|
||||||
if (powerBtn) powerBtn.disabled = true;
|
if (powerBtn) powerBtn.disabled = true;
|
||||||
if (lockBtn) lockBtn.disabled = true;
|
if (lockBtn) lockBtn.disabled = true;
|
||||||
if (txAudioBtn) txAudioBtn.disabled = true;
|
|
||||||
if (txLimitBtn) txLimitBtn.disabled = true;
|
|
||||||
|
|
||||||
// Disable frequency/mode inputs
|
// Disable frequency/mode inputs
|
||||||
if (freqInput) freqInput.disabled = true;
|
if (freqInput) freqInput.disabled = true;
|
||||||
if (centerFreqInput) centerFreqInput.disabled = true;
|
if (centerFreqInput) centerFreqInput.disabled = true;
|
||||||
if (modeSelect) modeSelect.disabled = true;
|
if (modeSelect) modeSelect.disabled = true;
|
||||||
if (txLimitInput) txLimitInput.disabled = true;
|
|
||||||
|
|
||||||
// Disable VFO selector
|
// Disable VFO selector
|
||||||
vfoButtons.forEach(btn => btn.disabled = true);
|
vfoButtons.forEach(btn => btn.disabled = true);
|
||||||
@@ -656,9 +660,6 @@ function applyAuthRestrictions() {
|
|||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Hide TX-specific UI but keep controls visible (disabled)
|
|
||||||
if (txLimitRow) txLimitRow.style.opacity = "0.5";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2449,10 +2450,26 @@ function visibleBandwidthSpecs(freqHz: number | null = lastFreqHz, mode = modeEl
|
|||||||
return [{ centerHz: freqHz, widthHz: currentBandwidthHz }];
|
return [{ centerHz: freqHz, widthHz: currentBandwidthHz }];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolve the DIG passband direction from the current policy and dial
|
||||||
|
// frequency, mirroring the backend's demodulator resolution so the spectrum
|
||||||
|
// overlay lands on the same sideband that is actually being demodulated.
|
||||||
|
function digSidebandDirection() {
|
||||||
|
if (sdrDigSidebandPolicy === "usb") return 1;
|
||||||
|
if (sdrDigSidebandPolicy === "lsb") return -1;
|
||||||
|
// "auto": USB at/above the threshold, LSB below.
|
||||||
|
if (typeof lastFreqHz === "number" && isFiniteNumber(lastFreqHz)) {
|
||||||
|
return lastFreqHz >= DIG_AUTO_SIDEBAND_THRESHOLD_HZ ? 1 : -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
function sidebandDirectionForMode(mode = modeEl ? modeEl.value : "") {
|
function sidebandDirectionForMode(mode = modeEl ? modeEl.value : "") {
|
||||||
const modeUpper = String(mode || "").toUpperCase();
|
const modeUpper = String(mode || "").toUpperCase();
|
||||||
if (modeUpper === "LSB" || modeUpper === "CWR") return -1;
|
if (modeUpper === "LSB" || modeUpper === "CWR") return -1;
|
||||||
if (modeUpper === "USB" || modeUpper === "CW" || modeUpper === "DIG") return 1;
|
// On SDR the DIG sideband is configurable; resolve it. On other backends
|
||||||
|
// keep the historical upper-sideband overlay.
|
||||||
|
if (modeUpper === "DIG") return sdrDigSidebandSupported ? digSidebandDirection() : 1;
|
||||||
|
if (modeUpper === "USB" || modeUpper === "CW") return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3080,9 +3097,16 @@ function formatSignal(sUnits: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setDisabled(disabled: boolean) {
|
function setDisabled(disabled: boolean) {
|
||||||
[freqEl, centerFreqEl, modeEl, pttBtn, powerBtn, txLimitInput, txLimitBtn, lockBtn].forEach((el) => {
|
const controlDisabled = disabled || (authEnabled && !hasAuthRole("control"));
|
||||||
if (el) el.disabled = disabled;
|
const transmitDisabled = disabled || (authEnabled && !hasAuthRole("transmit"));
|
||||||
|
[freqEl, centerFreqEl, modeEl, powerBtn, lockBtn].forEach((el) => {
|
||||||
|
if (el) el.disabled = controlDisabled;
|
||||||
});
|
});
|
||||||
|
[pttBtn, txLimitInput, txLimitBtn].forEach((el) => {
|
||||||
|
if (el) el.disabled = transmitDisabled;
|
||||||
|
});
|
||||||
|
const transmitAudio = document.getElementById("tx-audio-btn") as HTMLButtonElement | null;
|
||||||
|
if (transmitAudio) transmitAudio.disabled = transmitDisabled || !hasWebCodecs;
|
||||||
syncModePicker();
|
syncModePicker();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3672,6 +3696,26 @@ function render(update: AppUpdate) {
|
|||||||
sdrNbThresholdEl.value = String(Math.round(update.filter.sdr_nb_threshold));
|
sdrNbThresholdEl.value = String(Math.round(update.filter.sdr_nb_threshold));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (typeof update.filter.sdr_nb_profile === "string") {
|
||||||
|
sdrNbProfile = update.filter.sdr_nb_profile;
|
||||||
|
if (sdrNbProfileWrapEl) sdrNbProfileWrapEl.style.display = "";
|
||||||
|
if (sdrNbProfileEl && document.activeElement !== sdrNbProfileEl) {
|
||||||
|
sdrNbProfileEl.value = update.filter.sdr_nb_profile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (typeof update.filter.sdr_dig_sideband === "string") {
|
||||||
|
sdrDigSidebandSupported = true;
|
||||||
|
const prevPolicy = sdrDigSidebandPolicy;
|
||||||
|
sdrDigSidebandPolicy = update.filter.sdr_dig_sideband;
|
||||||
|
if (sdrDigSidebandEl && document.activeElement !== sdrDigSidebandEl) {
|
||||||
|
sdrDigSidebandEl.value = update.filter.sdr_dig_sideband;
|
||||||
|
}
|
||||||
|
updateWfmControls();
|
||||||
|
// Repaint the passband overlay if the DIG sideband just changed.
|
||||||
|
if (prevPolicy !== sdrDigSidebandPolicy && lastSpectrumData) {
|
||||||
|
scheduleSpectrumDraw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (typeof update.show_sdr_gain_control === "boolean") {
|
if (typeof update.show_sdr_gain_control === "boolean") {
|
||||||
@@ -5166,6 +5210,14 @@ async function refreshUserManagement() {
|
|||||||
}
|
}
|
||||||
const password = document.createElement("input");
|
const password = document.createElement("input");
|
||||||
password.type = "password"; password.placeholder = "New password (8+ characters)"; password.autocomplete = "new-password"; password.className = "auth-input"; password.minLength = 8; password.maxLength = 1024;
|
password.type = "password"; password.placeholder = "New password (8+ characters)"; password.autocomplete = "new-password"; password.className = "auth-input"; password.minLength = 8; password.maxLength = 1024;
|
||||||
|
const syncPasswordAccess = () => {
|
||||||
|
const guestActive = guestInput?.checked === true;
|
||||||
|
password.disabled = guestActive;
|
||||||
|
password.title = guestActive ? "Password changes are unavailable while the Guest role is active" : "";
|
||||||
|
if (guestActive) password.value = "";
|
||||||
|
};
|
||||||
|
roleInputs.forEach(({ input }) => input.addEventListener("change", syncPasswordAccess));
|
||||||
|
syncPasswordAccess();
|
||||||
const save = document.createElement("button"); save.type = "button"; save.textContent = "Save";
|
const save = document.createElement("button"); save.type = "button"; save.textContent = "Save";
|
||||||
save.addEventListener("click", async () => {
|
save.addEventListener("click", async () => {
|
||||||
const changes: { roles?: AuthRole[]; password?: string; enabled?: boolean } = {
|
const changes: { roles?: AuthRole[]; password?: string; enabled?: boolean } = {
|
||||||
@@ -5594,7 +5646,20 @@ const sdrNbEnabledEl = document.getElementById("sdr-nb-enabled") as HTMLInputEle
|
|||||||
const sdrNbThresholdControlsEl = document.getElementById("sdr-nb-threshold-controls");
|
const sdrNbThresholdControlsEl = document.getElementById("sdr-nb-threshold-controls");
|
||||||
const sdrNbThresholdEl = document.getElementById("sdr-nb-threshold") as HTMLInputElement | null;
|
const sdrNbThresholdEl = document.getElementById("sdr-nb-threshold") as HTMLInputElement | null;
|
||||||
const sdrNbThresholdSetBtn = document.getElementById("sdr-nb-threshold-set") as HTMLButtonElement | null;
|
const sdrNbThresholdSetBtn = document.getElementById("sdr-nb-threshold-set") as HTMLButtonElement | null;
|
||||||
|
const sdrNbProfileWrapEl = document.getElementById("sdr-nb-profile-wrap");
|
||||||
|
const sdrNbProfileEl = document.getElementById("sdr-nb-profile") as HTMLSelectElement | null;
|
||||||
let sdrNbSupported = false;
|
let sdrNbSupported = false;
|
||||||
|
// Current NB profile, mirrored from server filter state; sent alongside every
|
||||||
|
// enable/threshold change (including the quick toggle) so it is preserved.
|
||||||
|
let sdrNbProfile = "spike";
|
||||||
|
const sdrDigSidebandWrapEl = document.getElementById("sdr-dig-sideband-wrap");
|
||||||
|
const sdrDigSidebandEl = document.getElementById("sdr-dig-sideband") as HTMLSelectElement | null;
|
||||||
|
let sdrDigSidebandSupported = false;
|
||||||
|
// Current DIG sideband policy ("auto" | "usb" | "lsb"), mirrored from server
|
||||||
|
// filter state. Drives the spectrum passband overlay direction for DIG.
|
||||||
|
let sdrDigSidebandPolicy = "auto";
|
||||||
|
// Matches DigSidebandPolicy::AUTO_THRESHOLD_HZ on the backend.
|
||||||
|
const DIG_AUTO_SIDEBAND_THRESHOLD_HZ = 10_000_000;
|
||||||
|
|
||||||
// Hide audio row if audio is not configured on the server
|
// Hide audio row if audio is not configured on the server
|
||||||
fetch("/audio", { method: "GET" }).then((r) => {
|
fetch("/audio", { method: "GET" }).then((r) => {
|
||||||
@@ -6021,7 +6086,7 @@ function submitSdrNbState() {
|
|||||||
const threshold = sdrNbThresholdEl ? Number.parseFloat(sdrNbThresholdEl.value) : 10;
|
const threshold = sdrNbThresholdEl ? Number.parseFloat(sdrNbThresholdEl.value) : 10;
|
||||||
if (!isFiniteNumber(threshold) || threshold < 1 || threshold > 100) return;
|
if (!isFiniteNumber(threshold) || threshold < 1 || threshold > 100) return;
|
||||||
postPath(
|
postPath(
|
||||||
`/set_sdr_noise_blanker?enabled=${enabled ? "true" : "false"}&threshold=${encodeURIComponent(threshold)}`,
|
`/set_sdr_noise_blanker?enabled=${enabled ? "true" : "false"}&threshold=${encodeURIComponent(threshold)}&profile=${encodeURIComponent(sdrNbProfile)}`,
|
||||||
).catch(() => {});
|
).catch(() => {});
|
||||||
}
|
}
|
||||||
if (sdrNbEnabledEl) {
|
if (sdrNbEnabledEl) {
|
||||||
@@ -6029,6 +6094,21 @@ if (sdrNbEnabledEl) {
|
|||||||
submitSdrNbState();
|
submitSdrNbState();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (sdrNbProfileEl) {
|
||||||
|
sdrNbProfileEl.addEventListener("change", () => {
|
||||||
|
const profile = sdrNbProfileEl.value || "spike";
|
||||||
|
if (
|
||||||
|
profile !== "spike" &&
|
||||||
|
profile !== "ignition" &&
|
||||||
|
profile !== "powerline" &&
|
||||||
|
profile !== "broadband"
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sdrNbProfile = profile;
|
||||||
|
submitSdrNbState();
|
||||||
|
});
|
||||||
|
}
|
||||||
function submitSdrNbThreshold() {
|
function submitSdrNbThreshold() {
|
||||||
if (!sdrNbThresholdEl) return;
|
if (!sdrNbThresholdEl) return;
|
||||||
const parsed = Number.parseFloat(sdrNbThresholdEl.value);
|
const parsed = Number.parseFloat(sdrNbThresholdEl.value);
|
||||||
@@ -6046,6 +6126,21 @@ if (sdrNbThresholdEl) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function submitSdrDigSideband() {
|
||||||
|
if (!sdrDigSidebandSupported || !sdrDigSidebandEl) return;
|
||||||
|
const policy = sdrDigSidebandEl.value || "auto";
|
||||||
|
if (policy !== "auto" && policy !== "usb" && policy !== "lsb") return;
|
||||||
|
// Optimistically move the passband overlay to the chosen sideband so the
|
||||||
|
// display responds instantly, before the server round-trip confirms it.
|
||||||
|
sdrDigSidebandPolicy = policy;
|
||||||
|
if (lastSpectrumData) scheduleSpectrumDraw();
|
||||||
|
postPath(`/set_sdr_dig_sideband?policy=${encodeURIComponent(policy)}`).catch(() => {});
|
||||||
|
}
|
||||||
|
if (sdrDigSidebandEl) {
|
||||||
|
sdrDigSidebandEl.addEventListener("change", () => {
|
||||||
|
submitSdrDigSideband();
|
||||||
|
});
|
||||||
|
}
|
||||||
function updateWfmControls() {
|
function updateWfmControls() {
|
||||||
const mode = (modeEl && modeEl.value ? modeEl.value : "").toUpperCase();
|
const mode = (modeEl && modeEl.value ? modeEl.value : "").toUpperCase();
|
||||||
if (wfmControlsCol) wfmControlsCol.style.display = mode === "WFM" ? "" : "none";
|
if (wfmControlsCol) wfmControlsCol.style.display = mode === "WFM" ? "" : "none";
|
||||||
@@ -6053,6 +6148,11 @@ function updateWfmControls() {
|
|||||||
// The row holds only these two, so it goes with them — an empty one would
|
// The row holds only these two, so it goes with them — an empty one would
|
||||||
// still take a track and a gap in the tray, and draw its divider.
|
// still take a track and a gap in the tray, and draw its divider.
|
||||||
if (modeControlsRow) modeControlsRow.style.display = (mode === "WFM" || mode === "SAM") ? "" : "none";
|
if (modeControlsRow) modeControlsRow.style.display = (mode === "WFM" || mode === "SAM") ? "" : "none";
|
||||||
|
// DIG sideband selector is only meaningful in DIG mode on an SDR backend.
|
||||||
|
if (sdrDigSidebandWrapEl) {
|
||||||
|
sdrDigSidebandWrapEl.style.display =
|
||||||
|
sdrDigSidebandSupported && mode === "DIG" ? "" : "none";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show compatibility warning for non-Chromium browsers
|
// Show compatibility warning for non-Chromium browsers
|
||||||
@@ -6370,6 +6470,10 @@ function stopRxAudio() {
|
|||||||
|
|
||||||
function startTxAudio() {
|
function startTxAudio() {
|
||||||
if (txActive) { void stopTxAudio(); return; }
|
if (txActive) { void stopTxAudio(); return; }
|
||||||
|
if (authEnabled && !hasAuthRole("transmit")) {
|
||||||
|
audioStatus.textContent = "Transmit role required";
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!hasWebCodecs) {
|
if (!hasWebCodecs) {
|
||||||
audioStatus.textContent = "Audio requires Chrome/Edge";
|
audioStatus.textContent = "Audio requires Chrome/Edge";
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ interface Bookmark {
|
|||||||
category?: string | null;
|
category?: string | null;
|
||||||
comment?: string | null;
|
comment?: string | null;
|
||||||
decoders?: string[];
|
decoders?: string[];
|
||||||
|
/** DIG sideband override: "auto" | "usb" | "lsb". Empty/absent = global. */
|
||||||
|
dig_sideband?: string | null;
|
||||||
scope?: string;
|
scope?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,6 +323,14 @@ function bmBuildDecoderCheckboxes() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Show the DIG-sideband override selector only when the mode field is DIG. */
|
||||||
|
function bmSyncDigSidebandVisibility(): void {
|
||||||
|
const label = bmOptionalEl("bm-dig-sideband-label");
|
||||||
|
if (!label) return;
|
||||||
|
const mode = (bmEl("bm-mode").value || "").trim().toUpperCase();
|
||||||
|
label.style.display = mode === "DIG" ? "" : "none";
|
||||||
|
}
|
||||||
|
|
||||||
function bmOpenForm(bm: Bookmark | null): void {
|
function bmOpenForm(bm: Bookmark | null): void {
|
||||||
const wrap = bmEl("bm-form-wrap");
|
const wrap = bmEl("bm-form-wrap");
|
||||||
if (!wrap) return;
|
if (!wrap) return;
|
||||||
@@ -338,7 +348,9 @@ function bmOpenForm(bm: Bookmark | null): void {
|
|||||||
bmEl("bm-locator").value = bm ? (bm.locator || "") : "";
|
bmEl("bm-locator").value = bm ? (bm.locator || "") : "";
|
||||||
bmEl("bm-category-input").value = bm ? (bm.category || "") : "";
|
bmEl("bm-category-input").value = bm ? (bm.category || "") : "";
|
||||||
bmEl("bm-comment").value = bm ? (bm.comment || "") : "";
|
bmEl("bm-comment").value = bm ? (bm.comment || "") : "";
|
||||||
|
bmEl("bm-dig-sideband").value = bm ? (bm.dig_sideband || "") : "";
|
||||||
bmWriteDecoders(bm?.decoders ?? []);
|
bmWriteDecoders(bm?.decoders ?? []);
|
||||||
|
bmSyncDigSidebandVisibility();
|
||||||
bmEl("bm-form-title").textContent = bm ? "Edit Bookmark" : "Add Bookmark";
|
bmEl("bm-form-title").textContent = bm ? "Edit Bookmark" : "Add Bookmark";
|
||||||
|
|
||||||
wrap.style.display = "flex";
|
wrap.style.display = "flex";
|
||||||
@@ -383,6 +395,9 @@ async function bmSave(e: Event): Promise<void> {
|
|||||||
const category = bmEl("bm-category-input").value.trim();
|
const category = bmEl("bm-category-input").value.trim();
|
||||||
const comment = bmEl("bm-comment").value.trim();
|
const comment = bmEl("bm-comment").value.trim();
|
||||||
const decoders = bmReadDecoders();
|
const decoders = bmReadDecoders();
|
||||||
|
// Only meaningful for DIG; stored empty otherwise so it never overrides.
|
||||||
|
const dig_sideband =
|
||||||
|
mode.toUpperCase() === "DIG" ? (bmEl("bm-dig-sideband").value || null) : null;
|
||||||
|
|
||||||
const formError = bmEl("bm-form-error");
|
const formError = bmEl("bm-form-error");
|
||||||
if (formError) formError.textContent = "";
|
if (formError) formError.textContent = "";
|
||||||
@@ -403,6 +418,7 @@ async function bmSave(e: Event): Promise<void> {
|
|||||||
category,
|
category,
|
||||||
comment,
|
comment,
|
||||||
decoders,
|
decoders,
|
||||||
|
dig_sideband,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -477,6 +493,16 @@ function bmApply(bm: Bookmark): void {
|
|||||||
const tunePromise = (async () => {
|
const tunePromise = (async () => {
|
||||||
await bridge.trx.modules.vchan?.takeSchedulerControl();
|
await bridge.trx.modules.vchan?.takeSchedulerControl();
|
||||||
|
|
||||||
|
// For a DIG bookmark carrying a sideband override, set the global DIG
|
||||||
|
// policy first so the backend resolves the intended sideband when DIG is
|
||||||
|
// applied. "auto" is honoured explicitly; an empty override is left alone.
|
||||||
|
if ((bm.mode || "").toUpperCase() === "DIG" && bm.dig_sideband) {
|
||||||
|
const p = bm.dig_sideband.toLowerCase();
|
||||||
|
if (p === "auto" || p === "usb" || p === "lsb") {
|
||||||
|
await hostCore.postPath("/set_sdr_dig_sideband?policy=" + encodeURIComponent(p));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const onVirtual = await bridge.trx.modules.vchan?.interceptMode(bm.mode) ?? false;
|
const onVirtual = await bridge.trx.modules.vchan?.interceptMode(bm.mode) ?? false;
|
||||||
if (!onVirtual) {
|
if (!onVirtual) {
|
||||||
await hostCore.postPath("/set_mode?mode=" + encodeURIComponent(bm.mode));
|
await hostCore.postPath("/set_mode?mode=" + encodeURIComponent(bm.mode));
|
||||||
@@ -770,6 +796,9 @@ function bmPopulateScopePicker() {
|
|||||||
// Form submit
|
// Form submit
|
||||||
bmEl("bm-form").addEventListener("submit", (event) => { void bmSave(event); });
|
bmEl("bm-form").addEventListener("submit", (event) => { void bmSave(event); });
|
||||||
|
|
||||||
|
// Reveal the DIG-sideband override only while the mode field reads DIG.
|
||||||
|
bmEl("bm-mode").addEventListener("input", bmSyncDigSidebandVisibility);
|
||||||
|
|
||||||
// Form cancel
|
// Form cancel
|
||||||
bmEl("bm-form-cancel").addEventListener("click", bmCloseForm);
|
bmEl("bm-form-cancel").addEventListener("click", bmCloseForm);
|
||||||
|
|
||||||
|
|||||||
+16
-1
@@ -8,7 +8,7 @@ import { startBrowser, startWebFixture } from "./web-fixture.mjs";
|
|||||||
|
|
||||||
/* global document */
|
/* global document */
|
||||||
|
|
||||||
const ALL_ROLES = ["read", "control", "write", "administrator"];
|
const ALL_ROLES = ["read", "control", "transmit", "write", "administrator"];
|
||||||
const fixture = await startWebFixture({
|
const fixture = await startWebFixture({
|
||||||
authSession: {
|
authSession: {
|
||||||
authenticated: true,
|
authenticated: true,
|
||||||
@@ -18,6 +18,7 @@ const fixture = await startWebFixture({
|
|||||||
},
|
},
|
||||||
users: [
|
users: [
|
||||||
{ username: "admin", roles: ALL_ROLES, enabled: true },
|
{ username: "admin", roles: ALL_ROLES, enabled: true },
|
||||||
|
{ username: "guest", roles: ["guest"], enabled: true },
|
||||||
{ username: "listener", roles: ["read"], enabled: false },
|
{ username: "listener", roles: ["read"], enabled: false },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@@ -41,6 +42,7 @@ try {
|
|||||||
const rows = [...document.querySelectorAll("#user-list > .sch-row")];
|
const rows = [...document.querySelectorAll("#user-list > .sch-row")];
|
||||||
const rowFor = (username) => rows.find((row) => row.querySelector("strong")?.textContent.startsWith(username));
|
const rowFor = (username) => rows.find((row) => row.querySelector("strong")?.textContent.startsWith(username));
|
||||||
const admin = rowFor("admin");
|
const admin = rowFor("admin");
|
||||||
|
const guest = rowFor("guest");
|
||||||
const listener = rowFor("listener");
|
const listener = rowFor("listener");
|
||||||
const role = (row, value) => row?.querySelector(`input[value="${value}"]`);
|
const role = (row, value) => row?.querySelector(`input[value="${value}"]`);
|
||||||
return {
|
return {
|
||||||
@@ -49,6 +51,7 @@ try {
|
|||||||
adminRoleLocked: role(admin, "administrator")?.disabled,
|
adminRoleLocked: role(admin, "administrator")?.disabled,
|
||||||
adminGuestLocked: role(admin, "guest")?.disabled,
|
adminGuestLocked: role(admin, "guest")?.disabled,
|
||||||
adminRemoveLocked: admin?.querySelector("button.danger")?.disabled,
|
adminRemoveLocked: admin?.querySelector("button.danger")?.disabled,
|
||||||
|
guestPasswordLocked: guest?.querySelector('input[type="password"]')?.disabled,
|
||||||
listenerEnabled: listener?.querySelector('input[type="checkbox"]')?.checked,
|
listenerEnabled: listener?.querySelector('input[type="checkbox"]')?.checked,
|
||||||
listenerRead: role(listener, "read")?.checked,
|
listenerRead: role(listener, "read")?.checked,
|
||||||
};
|
};
|
||||||
@@ -58,8 +61,20 @@ try {
|
|||||||
assert.equal(state.adminRoleLocked, true);
|
assert.equal(state.adminRoleLocked, true);
|
||||||
assert.equal(state.adminGuestLocked, true);
|
assert.equal(state.adminGuestLocked, true);
|
||||||
assert.equal(state.adminRemoveLocked, true);
|
assert.equal(state.adminRemoveLocked, true);
|
||||||
|
assert.equal(state.guestPasswordLocked, true);
|
||||||
assert.equal(state.listenerEnabled, false);
|
assert.equal(state.listenerEnabled, false);
|
||||||
assert.equal(state.listenerRead, true);
|
assert.equal(state.listenerRead, true);
|
||||||
|
|
||||||
|
const listenerRow = page.locator("#user-list > .sch-row").filter({ hasText: "listener" });
|
||||||
|
const listenerPassword = listenerRow.locator('input[type="password"]');
|
||||||
|
await listenerRow.locator('input[value="guest"]').check();
|
||||||
|
assert.equal(await listenerPassword.isDisabled(), true);
|
||||||
|
assert.equal(await listenerRow.locator('input[value="read"]').isChecked(), true);
|
||||||
|
await listenerRow.locator('input[value="control"]').check();
|
||||||
|
assert.equal(await listenerRow.locator('input[value="guest"]').isChecked(), true);
|
||||||
|
assert.equal(await listenerPassword.isDisabled(), true);
|
||||||
|
await listenerRow.locator('input[value="guest"]').uncheck();
|
||||||
|
assert.equal(await listenerPassword.isDisabled(), false);
|
||||||
assert.deepEqual(runtimeErrors, []);
|
assert.deepEqual(runtimeErrors, []);
|
||||||
} finally {
|
} finally {
|
||||||
await browser.close();
|
await browser.close();
|
||||||
|
|||||||
@@ -15,13 +15,15 @@ function loadAuth(fetch) {
|
|||||||
return context.AuthApi;
|
return context.AuthApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
test("role policy centralizes Guest and implied read access", () => {
|
test("role policy centralizes Guest and separates Control from Transmit", () => {
|
||||||
const auth = loadAuth(async () => { throw new Error("unused"); });
|
const auth = loadAuth(async () => { throw new Error("unused"); });
|
||||||
assert.deepEqual(Array.from(auth.AUTH_ROLES), ["guest", "read", "control", "write", "administrator"]);
|
assert.deepEqual(Array.from(auth.AUTH_ROLES), ["guest", "read", "control", "transmit", "write", "administrator"]);
|
||||||
assert.equal(auth.hasAuthRole(["guest"], "read"), true);
|
assert.equal(auth.hasAuthRole(["guest"], "read"), true);
|
||||||
assert.equal(auth.hasAccountControls(["guest"]), false);
|
assert.equal(auth.hasAccountControls(["guest"]), false);
|
||||||
assert.equal(auth.hasAccountControls(["read"]), true);
|
assert.equal(auth.hasAccountControls(["read"]), true);
|
||||||
assert.equal(auth.hasAuthRole(["control"], "read"), true);
|
assert.equal(auth.hasAuthRole(["control"], "read"), true);
|
||||||
|
assert.equal(auth.hasAuthRole(["transmit"], "read"), true);
|
||||||
|
assert.equal(auth.hasAuthRole(["control"], "transmit"), false);
|
||||||
assert.equal(auth.hasAuthRole(["control"], "write"), false);
|
assert.equal(auth.hasAuthRole(["control"], "write"), false);
|
||||||
assert.equal(auth.hasAuthRole(["administrator"], "write"), true);
|
assert.equal(auth.hasAuthRole(["administrator"], "write"), true);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ function hostFixture(overrides = {}) {
|
|||||||
const calls = { postPath: [], setRigFrequency: [], armOptimisticFrequency: [], applyLocalTunedFrequency: [], syncBandwidthInput: [], scheduleSpectrumDraw: 0, syncModePicker: 0 };
|
const calls = { postPath: [], setRigFrequency: [], armOptimisticFrequency: [], applyLocalTunedFrequency: [], syncBandwidthInput: [], scheduleSpectrumDraw: 0, syncModePicker: 0 };
|
||||||
const state = {
|
const state = {
|
||||||
authEnabled: false,
|
authEnabled: false,
|
||||||
authRoles: ["read", "control", "write", "administrator"],
|
authRoles: ["read", "control", "transmit", "write", "administrator"],
|
||||||
lastActiveRigId: null,
|
lastActiveRigId: null,
|
||||||
lastRigIds: [],
|
lastRigIds: [],
|
||||||
lastRigDisplayNames: {},
|
lastRigDisplayNames: {},
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export function createHost({ state = {}, core = {}, modules = {} } = {}) {
|
|||||||
serverLat: null,
|
serverLat: null,
|
||||||
serverLon: null,
|
serverLon: null,
|
||||||
authEnabled: false,
|
authEnabled: false,
|
||||||
authRoles: ["read", "control", "write", "administrator"],
|
authRoles: ["read", "control", "transmit", "write", "administrator"],
|
||||||
lastActiveRigId: null,
|
lastActiveRigId: null,
|
||||||
lastRigIds: [],
|
lastRigIds: [],
|
||||||
lastRigDisplayNames: {},
|
lastRigDisplayNames: {},
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Stan Grams <sjg@haxx.space>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
import assert from "node:assert/strict";
|
||||||
|
import { chromium } from "playwright-core";
|
||||||
|
import { startBrowser, startWebFixture } from "./web-fixture.mjs";
|
||||||
|
|
||||||
|
async function controlState(page) {
|
||||||
|
return {
|
||||||
|
frequency: await page.locator("#freq").isDisabled(),
|
||||||
|
ptt: await page.locator("#ptt-btn").isDisabled(),
|
||||||
|
txAudio: await page.locator("#tx-audio-btn").isDisabled(),
|
||||||
|
txLimit: await page.locator("#tx-limit-btn").isDisabled(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function inspectRole(roles) {
|
||||||
|
const fixture = await startWebFixture({
|
||||||
|
tx: true,
|
||||||
|
authSession: {
|
||||||
|
authenticated: true,
|
||||||
|
username: "operator",
|
||||||
|
roles,
|
||||||
|
auth_disabled: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const session = await startBrowser(chromium);
|
||||||
|
try {
|
||||||
|
await session.page.goto(`${fixture.origin}/`, { waitUntil: "domcontentloaded" });
|
||||||
|
await session.page.locator("#content").waitFor({ state: "visible" });
|
||||||
|
await session.page.waitForTimeout(1200);
|
||||||
|
assert.deepEqual(session.runtimeErrors, []);
|
||||||
|
return await controlState(session.page);
|
||||||
|
} finally {
|
||||||
|
await session.browser.close();
|
||||||
|
await fixture.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.deepEqual(await inspectRole(["control"]), {
|
||||||
|
frequency: false,
|
||||||
|
ptt: true,
|
||||||
|
txAudio: true,
|
||||||
|
txLimit: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(await inspectRole(["transmit"]), {
|
||||||
|
frequency: true,
|
||||||
|
ptt: false,
|
||||||
|
txAudio: false,
|
||||||
|
txLimit: false,
|
||||||
|
});
|
||||||
@@ -145,7 +145,7 @@ export async function startWebFixture({
|
|||||||
bandplanEnabled = false,
|
bandplanEnabled = false,
|
||||||
bandplanUnauthorizedFirst = false,
|
bandplanUnauthorizedFirst = false,
|
||||||
satPasses = null,
|
satPasses = null,
|
||||||
authSession = { authenticated: true, roles: ["read", "control", "write", "administrator"], auth_disabled: true },
|
authSession = { authenticated: true, roles: ["read", "control", "transmit", "write", "administrator"], auth_disabled: true },
|
||||||
users = [],
|
users = [],
|
||||||
} = {}) {
|
} = {}) {
|
||||||
const rigItems = ["rig-a", "rig-b"].map((remote) => ({
|
const rigItems = ["rig-a", "rig-b"].map((remote) => ({
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ pub struct BookmarkInput {
|
|||||||
pub comment: Option<String>,
|
pub comment: Option<String>,
|
||||||
pub category: Option<String>,
|
pub category: Option<String>,
|
||||||
pub decoders: Option<Vec<String>>,
|
pub decoders: Option<Vec<String>>,
|
||||||
|
pub dig_sideband: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A bookmark with its owning scope tag for the list response.
|
/// A bookmark with its owning scope tag for the list response.
|
||||||
@@ -88,6 +89,17 @@ fn normalize_bookmark_locator(locator: Option<String>) -> Option<String> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Normalize a DIG sideband override to `auto`/`usb`/`lsb`, or `None` when
|
||||||
|
/// absent or unrecognized (leaves the current policy untouched on apply).
|
||||||
|
fn normalize_dig_sideband(value: Option<String>) -> Option<String> {
|
||||||
|
value.and_then(|v| match v.trim().to_lowercase().as_str() {
|
||||||
|
"auto" => Some("auto".to_string()),
|
||||||
|
"usb" => Some("usb".to_string()),
|
||||||
|
"lsb" => Some("lsb".to_string()),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Endpoints
|
// Endpoints
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -182,6 +194,7 @@ pub async fn create_bookmark(
|
|||||||
comment: body.comment.clone().unwrap_or_default(),
|
comment: body.comment.clone().unwrap_or_default(),
|
||||||
category: body.category.clone().unwrap_or_default(),
|
category: body.category.clone().unwrap_or_default(),
|
||||||
decoders: body.decoders.clone().unwrap_or_default(),
|
decoders: body.decoders.clone().unwrap_or_default(),
|
||||||
|
dig_sideband: normalize_dig_sideband(body.dig_sideband.clone()),
|
||||||
};
|
};
|
||||||
if store.insert(&bm) {
|
if store.insert(&bm) {
|
||||||
Ok(HttpResponse::Created().json(bm))
|
Ok(HttpResponse::Created().json(bm))
|
||||||
@@ -219,6 +232,7 @@ pub async fn update_bookmark(
|
|||||||
comment: body.comment.clone().unwrap_or_default(),
|
comment: body.comment.clone().unwrap_or_default(),
|
||||||
category: body.category.clone().unwrap_or_default(),
|
category: body.category.clone().unwrap_or_default(),
|
||||||
decoders: body.decoders.clone().unwrap_or_default(),
|
decoders: body.decoders.clone().unwrap_or_default(),
|
||||||
|
dig_sideband: normalize_dig_sideband(body.dig_sideband.clone()),
|
||||||
};
|
};
|
||||||
if store.upsert(&id, &bm) {
|
if store.upsert(&id, &bm) {
|
||||||
Ok(HttpResponse::Ok().json(bm))
|
Ok(HttpResponse::Ok().json(bm))
|
||||||
|
|||||||
@@ -595,6 +595,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
|
|||||||
.service(rig::set_sdr_agc)
|
.service(rig::set_sdr_agc)
|
||||||
.service(rig::set_sdr_squelch)
|
.service(rig::set_sdr_squelch)
|
||||||
.service(rig::set_sdr_noise_blanker)
|
.service(rig::set_sdr_noise_blanker)
|
||||||
|
.service(rig::set_sdr_dig_sideband)
|
||||||
.service(rig::set_wfm_deemphasis)
|
.service(rig::set_wfm_deemphasis)
|
||||||
.service(rig::set_wfm_stereo)
|
.service(rig::set_wfm_stereo)
|
||||||
.service(rig::set_wfm_denoise)
|
.service(rig::set_wfm_denoise)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use uuid::Uuid;
|
|||||||
|
|
||||||
use trx_core::radio::freq::Freq;
|
use trx_core::radio::freq::Freq;
|
||||||
use trx_core::rig::state::WfmDenoiseLevel;
|
use trx_core::rig::state::WfmDenoiseLevel;
|
||||||
use trx_core::{RigCommand, RigRequest, RigState};
|
use trx_core::{DigSidebandPolicy, NoiseBlankerProfile, RigCommand, RigRequest, RigState};
|
||||||
use trx_frontend::{FrontendRuntimeContext, RemoteRigEntry};
|
use trx_frontend::{FrontendRuntimeContext, RemoteRigEntry};
|
||||||
use trx_protocol::parse_mode;
|
use trx_protocol::parse_mode;
|
||||||
|
|
||||||
@@ -279,6 +279,10 @@ pub async fn set_sdr_squelch(
|
|||||||
pub struct SdrNoiseBlankerQuery {
|
pub struct SdrNoiseBlankerQuery {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub threshold: f64,
|
pub threshold: f64,
|
||||||
|
/// `spike` (default), `ignition`, `powerline`, or `broadband`. Optional so
|
||||||
|
/// the quick toggle (which only carries enable/threshold) keeps working.
|
||||||
|
#[serde(default)]
|
||||||
|
pub profile: NoiseBlankerProfile,
|
||||||
pub remote: Option<String>,
|
pub remote: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,12 +297,30 @@ pub async fn set_sdr_noise_blanker(
|
|||||||
RigCommand::SetSdrNoiseBlanker {
|
RigCommand::SetSdrNoiseBlanker {
|
||||||
enabled: q.enabled,
|
enabled: q.enabled,
|
||||||
threshold: q.threshold,
|
threshold: q.threshold,
|
||||||
|
profile: q.profile,
|
||||||
},
|
},
|
||||||
q.remote,
|
q.remote,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
pub struct SdrDigSidebandQuery {
|
||||||
|
/// `auto`, `usb`, or `lsb`.
|
||||||
|
pub policy: DigSidebandPolicy,
|
||||||
|
pub remote: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set how the SDR backend resolves DIG mode to a sideband.
|
||||||
|
#[post("/set_sdr_dig_sideband")]
|
||||||
|
pub async fn set_sdr_dig_sideband(
|
||||||
|
query: web::Query<SdrDigSidebandQuery>,
|
||||||
|
rig_tx: web::Data<mpsc::Sender<RigRequest>>,
|
||||||
|
) -> Result<HttpResponse, Error> {
|
||||||
|
let q = query.into_inner();
|
||||||
|
send_command(&rig_tx, RigCommand::SetSdrDigSideband(q.policy), q.remote).await
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// WFM / SAM settings
|
// WFM / SAM settings
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|||||||
@@ -737,6 +737,7 @@ pub async fn audio_ws(
|
|||||||
body: web::Payload,
|
body: web::Payload,
|
||||||
query: web::Query<AudioQuery>,
|
query: web::Query<AudioQuery>,
|
||||||
context: web::Data<Arc<FrontendRuntimeContext>>,
|
context: web::Data<Arc<FrontendRuntimeContext>>,
|
||||||
|
auth_state: web::Data<crate::server::auth::AuthState>,
|
||||||
) -> Result<HttpResponse, Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
let Some(tx_sender) = context.audio.tx.as_ref().cloned() else {
|
let Some(tx_sender) = context.audio.tx.as_ref().cloned() else {
|
||||||
return Ok(HttpResponse::NotFound().body("audio not enabled"));
|
return Ok(HttpResponse::NotFound().body("audio not enabled"));
|
||||||
@@ -746,6 +747,7 @@ pub async fn audio_ws(
|
|||||||
if !req.headers().contains_key("upgrade") {
|
if !req.headers().contains_key("upgrade") {
|
||||||
return Ok(HttpResponse::NoContent().finish());
|
return Ok(HttpResponse::NoContent().finish());
|
||||||
}
|
}
|
||||||
|
let tx_session_id = crate::server::auth::extract_session_id(&req);
|
||||||
|
|
||||||
// If a channel_id is specified, subscribe to the per-channel broadcaster.
|
// If a channel_id is specified, subscribe to the per-channel broadcaster.
|
||||||
// The entry is created asynchronously when AUDIO_MSG_VCHAN_ALLOCATED arrives
|
// The entry is created asynchronously when AUDIO_MSG_VCHAN_ALLOCATED arrives
|
||||||
@@ -880,6 +882,16 @@ pub async fn audio_ws(
|
|||||||
msg = msg_stream.recv() => {
|
msg = msg_stream.recv() => {
|
||||||
match msg {
|
match msg {
|
||||||
Some(Ok(Message::Binary(data))) => {
|
Some(Ok(Message::Binary(data))) => {
|
||||||
|
let can_transmit = !auth_state.config.enabled
|
||||||
|
|| crate::server::auth::session_id_grants(
|
||||||
|
tx_session_id.as_ref(),
|
||||||
|
&auth_state,
|
||||||
|
crate::server::auth::AuthRole::Transmit,
|
||||||
|
);
|
||||||
|
if !can_transmit {
|
||||||
|
warn!("Audio WS: closing after unauthorized TX frame");
|
||||||
|
break;
|
||||||
|
}
|
||||||
let _ = tx_sender.send(Bytes::from(data.to_vec())).await;
|
let _ = tx_sender.send(Bytes::from(data.to_vec())).await;
|
||||||
}
|
}
|
||||||
Some(Ok(Message::Close(_))) => break,
|
Some(Ok(Message::Close(_))) => break,
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ pub enum AuthRole {
|
|||||||
Guest,
|
Guest,
|
||||||
Read,
|
Read,
|
||||||
Control,
|
Control,
|
||||||
|
Transmit,
|
||||||
Write,
|
Write,
|
||||||
Administrator,
|
Administrator,
|
||||||
}
|
}
|
||||||
@@ -48,22 +49,29 @@ impl AuthRole {
|
|||||||
Self::Guest => "guest",
|
Self::Guest => "guest",
|
||||||
Self::Read => "read",
|
Self::Read => "read",
|
||||||
Self::Control => "control",
|
Self::Control => "control",
|
||||||
|
Self::Transmit => "transmit",
|
||||||
Self::Write => "write",
|
Self::Write => "write",
|
||||||
Self::Administrator => "administrator",
|
Self::Administrator => "administrator",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn full_access() -> BTreeSet<Self> {
|
pub fn full_access() -> BTreeSet<Self> {
|
||||||
[Self::Read, Self::Control, Self::Write, Self::Administrator]
|
[
|
||||||
.into_iter()
|
Self::Read,
|
||||||
.collect()
|
Self::Control,
|
||||||
|
Self::Transmit,
|
||||||
|
Self::Write,
|
||||||
|
Self::Administrator,
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn grants(self, required: Self) -> bool {
|
fn grants(self, required: Self) -> bool {
|
||||||
self == Self::Administrator
|
self == Self::Administrator
|
||||||
|| self == required
|
|| self == required
|
||||||
|| self == Self::Guest && required == Self::Read
|
|| self == Self::Guest && required == Self::Read
|
||||||
|| self == Self::Control && required == Self::Read
|
|| matches!(self, Self::Control | Self::Transmit) && required == Self::Read
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -506,6 +514,10 @@ impl UserStore {
|
|||||||
roles: Option<AuthRoles>,
|
roles: Option<AuthRoles>,
|
||||||
enabled: Option<bool>,
|
enabled: Option<bool>,
|
||||||
) -> Result<(), UserStoreError> {
|
) -> Result<(), UserStoreError> {
|
||||||
|
let roles = roles
|
||||||
|
.map(validate_roles)
|
||||||
|
.transpose()
|
||||||
|
.map_err(UserStoreError::Invalid)?;
|
||||||
if let Some(value) = password {
|
if let Some(value) = password {
|
||||||
validate_password(value).map_err(UserStoreError::Invalid)?;
|
validate_password(value).map_err(UserStoreError::Invalid)?;
|
||||||
}
|
}
|
||||||
@@ -518,6 +530,16 @@ impl UserStore {
|
|||||||
.get(username)
|
.get(username)
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or(UserStoreError::NotFound)?;
|
.ok_or(UserStoreError::NotFound)?;
|
||||||
|
if password.is_some()
|
||||||
|
&& roles
|
||||||
|
.as_ref()
|
||||||
|
.unwrap_or(&old.roles)
|
||||||
|
.contains(&AuthRole::Guest)
|
||||||
|
{
|
||||||
|
return Err(UserStoreError::Invalid(
|
||||||
|
"password changes are not available while the guest role is active".to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
let remains_enabled_administrator = enabled.unwrap_or(old.enabled)
|
let remains_enabled_administrator = enabled.unwrap_or(old.enabled)
|
||||||
&& roles
|
&& roles
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -536,7 +558,7 @@ impl UserStore {
|
|||||||
record.password_hash = hash;
|
record.password_hash = hash;
|
||||||
}
|
}
|
||||||
if let Some(value) = roles {
|
if let Some(value) = roles {
|
||||||
record.roles = validate_roles(value).map_err(UserStoreError::Invalid)?;
|
record.roles = value;
|
||||||
}
|
}
|
||||||
if let Some(value) = enabled {
|
if let Some(value) = enabled {
|
||||||
record.enabled = value;
|
record.enabled = value;
|
||||||
@@ -624,8 +646,8 @@ fn validate_roles(roles: AuthRoles) -> Result<AuthRoles, String> {
|
|||||||
if roles.is_empty() {
|
if roles.is_empty() {
|
||||||
return Err("at least one role is required".to_string());
|
return Err("at least one role is required".to_string());
|
||||||
}
|
}
|
||||||
if roles.contains(&AuthRole::Guest) && roles.len() != 1 {
|
if roles.contains(&AuthRole::Guest) && roles.contains(&AuthRole::Administrator) {
|
||||||
return Err("guest cannot be combined with other roles".to_string());
|
return Err("guest cannot be combined with administrator".to_string());
|
||||||
}
|
}
|
||||||
Ok(roles)
|
Ok(roles)
|
||||||
}
|
}
|
||||||
@@ -776,7 +798,7 @@ pub struct ChangePasswordRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Extract session from cookie
|
/// Extract session from cookie
|
||||||
fn extract_session_id(req: &HttpRequest) -> Option<SessionId> {
|
pub fn extract_session_id(req: &HttpRequest) -> Option<SessionId> {
|
||||||
req.cookie("trx_http_sid")
|
req.cookie("trx_http_sid")
|
||||||
.map(|cookie| cookie.value().to_string())
|
.map(|cookie| cookie.value().to_string())
|
||||||
}
|
}
|
||||||
@@ -789,7 +811,18 @@ pub fn get_session_roles(req: &HttpRequest, auth_state: &AuthState) -> Option<Au
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn session_grants(req: &HttpRequest, auth_state: &AuthState, role: AuthRole) -> bool {
|
pub fn session_grants(req: &HttpRequest, auth_state: &AuthState, role: AuthRole) -> bool {
|
||||||
get_session_roles(req, auth_state).is_some_and(|roles| roles_grant(&roles, role))
|
let session_id = extract_session_id(req);
|
||||||
|
session_id_grants(session_id.as_ref(), auth_state, role)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn session_id_grants(
|
||||||
|
session_id: Option<&SessionId>,
|
||||||
|
auth_state: &AuthState,
|
||||||
|
role: AuthRole,
|
||||||
|
) -> bool {
|
||||||
|
session_id
|
||||||
|
.and_then(|id| auth_state.store.get(id))
|
||||||
|
.is_some_and(|session| roles_grant(&session.roles, role))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn require_session(
|
fn require_session(
|
||||||
@@ -1113,12 +1146,14 @@ enum RouteAccess {
|
|||||||
Account,
|
Account,
|
||||||
/// Read-only resources (Guest, Read, Control, or Administrator required)
|
/// Read-only resources (Guest, Read, Control, or Administrator required)
|
||||||
Read,
|
Read,
|
||||||
/// Bookmarks (Guest, Read, Control, Write, or Administrator required)
|
/// Bookmarks (Guest, Read, Control, Transmit, Write, or Administrator required)
|
||||||
ReadWrite,
|
ReadWrite,
|
||||||
/// Logbook access (Write or Administrator required)
|
/// Logbook access (Write or Administrator required)
|
||||||
Write,
|
Write,
|
||||||
/// Radio control (Control or Administrator required)
|
/// Radio control (Control or Administrator required)
|
||||||
Control,
|
Control,
|
||||||
|
/// Transmit actions (Transmit or Administrator required)
|
||||||
|
Transmit,
|
||||||
/// Managed-account administration.
|
/// Managed-account administration.
|
||||||
Administrator,
|
Administrator,
|
||||||
}
|
}
|
||||||
@@ -1146,6 +1181,9 @@ impl RouteAccess {
|
|||||||
if path == "/auth/users" || path.starts_with("/auth/users/") {
|
if path == "/auth/users" || path.starts_with("/auth/users/") {
|
||||||
return Self::Administrator;
|
return Self::Administrator;
|
||||||
}
|
}
|
||||||
|
if path == "/set_ptt" || path == "/set_tx_limit" {
|
||||||
|
return Self::Transmit;
|
||||||
|
}
|
||||||
|
|
||||||
// Static assets. The band plan is one of them: it is compiled into the
|
// Static assets. The band plan is one of them: it is compiled into the
|
||||||
// binary and identical for every user, but ".json" is not an asset
|
// binary and identical for every user, but ".json" is not an asset
|
||||||
@@ -1206,6 +1244,7 @@ impl RouteAccess {
|
|||||||
.is_some_and(|roles| roles_grant_any(roles, &[AuthRole::Read, AuthRole::Write])),
|
.is_some_and(|roles| roles_grant_any(roles, &[AuthRole::Read, AuthRole::Write])),
|
||||||
Self::Write => roles.is_some_and(|roles| roles_grant(roles, AuthRole::Write)),
|
Self::Write => roles.is_some_and(|roles| roles_grant(roles, AuthRole::Write)),
|
||||||
Self::Control => roles.is_some_and(|roles| roles_grant(roles, AuthRole::Control)),
|
Self::Control => roles.is_some_and(|roles| roles_grant(roles, AuthRole::Control)),
|
||||||
|
Self::Transmit => roles.is_some_and(|roles| roles_grant(roles, AuthRole::Transmit)),
|
||||||
Self::Administrator => {
|
Self::Administrator => {
|
||||||
roles.is_some_and(|roles| roles_grant(roles, AuthRole::Administrator))
|
roles.is_some_and(|roles| roles_grant(roles, AuthRole::Administrator))
|
||||||
}
|
}
|
||||||
@@ -1379,13 +1418,20 @@ mod tests {
|
|||||||
RouteAccess::Control
|
RouteAccess::Control
|
||||||
);
|
);
|
||||||
assert_eq!(RouteAccess::from_path("/set_mode"), RouteAccess::Control);
|
assert_eq!(RouteAccess::from_path("/set_mode"), RouteAccess::Control);
|
||||||
|
assert_eq!(RouteAccess::from_path("/set_ptt"), RouteAccess::Transmit);
|
||||||
|
assert_eq!(
|
||||||
|
RouteAccess::from_path("/set_tx_limit"),
|
||||||
|
RouteAccess::Transmit
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_route_access_allows() {
|
fn test_route_access_allows() {
|
||||||
let guest = roles(&[AuthRole::Guest]);
|
let guest = roles(&[AuthRole::Guest]);
|
||||||
|
let guest_control = roles(&[AuthRole::Guest, AuthRole::Control]);
|
||||||
let read = roles(&[AuthRole::Read]);
|
let read = roles(&[AuthRole::Read]);
|
||||||
let control = roles(&[AuthRole::Control]);
|
let control = roles(&[AuthRole::Control]);
|
||||||
|
let transmit = roles(&[AuthRole::Transmit]);
|
||||||
let write = roles(&[AuthRole::Write]);
|
let write = roles(&[AuthRole::Write]);
|
||||||
let administrator = roles(&[AuthRole::Administrator]);
|
let administrator = roles(&[AuthRole::Administrator]);
|
||||||
assert!(RouteAccess::Public.allows(None));
|
assert!(RouteAccess::Public.allows(None));
|
||||||
@@ -1393,12 +1439,15 @@ mod tests {
|
|||||||
assert!(RouteAccess::Public.allows(Some(&administrator)));
|
assert!(RouteAccess::Public.allows(Some(&administrator)));
|
||||||
assert!(!RouteAccess::Account.allows(None));
|
assert!(!RouteAccess::Account.allows(None));
|
||||||
assert!(!RouteAccess::Account.allows(Some(&guest)));
|
assert!(!RouteAccess::Account.allows(Some(&guest)));
|
||||||
|
assert!(!RouteAccess::Account.allows(Some(&guest_control)));
|
||||||
assert!(RouteAccess::Account.allows(Some(&write)));
|
assert!(RouteAccess::Account.allows(Some(&write)));
|
||||||
|
|
||||||
assert!(!RouteAccess::Read.allows(None));
|
assert!(!RouteAccess::Read.allows(None));
|
||||||
assert!(RouteAccess::Read.allows(Some(&guest)));
|
assert!(RouteAccess::Read.allows(Some(&guest)));
|
||||||
|
assert!(RouteAccess::Control.allows(Some(&guest_control)));
|
||||||
assert!(RouteAccess::Read.allows(Some(&read)));
|
assert!(RouteAccess::Read.allows(Some(&read)));
|
||||||
assert!(RouteAccess::Read.allows(Some(&control)));
|
assert!(RouteAccess::Read.allows(Some(&control)));
|
||||||
|
assert!(RouteAccess::Read.allows(Some(&transmit)));
|
||||||
assert!(!RouteAccess::Read.allows(Some(&write)));
|
assert!(!RouteAccess::Read.allows(Some(&write)));
|
||||||
assert!(RouteAccess::Read.allows(Some(&administrator)));
|
assert!(RouteAccess::Read.allows(Some(&administrator)));
|
||||||
|
|
||||||
@@ -1413,7 +1462,11 @@ mod tests {
|
|||||||
assert!(!RouteAccess::Control.allows(None));
|
assert!(!RouteAccess::Control.allows(None));
|
||||||
assert!(!RouteAccess::Control.allows(Some(&read)));
|
assert!(!RouteAccess::Control.allows(Some(&read)));
|
||||||
assert!(RouteAccess::Control.allows(Some(&control)));
|
assert!(RouteAccess::Control.allows(Some(&control)));
|
||||||
|
assert!(!RouteAccess::Control.allows(Some(&transmit)));
|
||||||
assert!(RouteAccess::Control.allows(Some(&administrator)));
|
assert!(RouteAccess::Control.allows(Some(&administrator)));
|
||||||
|
assert!(!RouteAccess::Transmit.allows(Some(&control)));
|
||||||
|
assert!(RouteAccess::Transmit.allows(Some(&transmit)));
|
||||||
|
assert!(RouteAccess::Transmit.allows(Some(&administrator)));
|
||||||
assert!(!RouteAccess::Administrator.allows(Some(&control)));
|
assert!(!RouteAccess::Administrator.allows(Some(&control)));
|
||||||
assert!(RouteAccess::Administrator.allows(Some(&administrator)));
|
assert!(RouteAccess::Administrator.allows(Some(&administrator)));
|
||||||
}
|
}
|
||||||
@@ -1442,6 +1495,28 @@ mod tests {
|
|||||||
assert!(store.get(&session_id).is_none());
|
assert!(store.get(&session_id).is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn transmit_grant_tracks_live_session_revocation() {
|
||||||
|
let directory = tempfile::tempdir().unwrap();
|
||||||
|
let state = AuthState::new(test_auth_config(directory.path().join("users.json"))).unwrap();
|
||||||
|
let session_id = state.store.create(
|
||||||
|
"operator".to_string(),
|
||||||
|
roles(&[AuthRole::Transmit]),
|
||||||
|
Duration::from_secs(3600),
|
||||||
|
);
|
||||||
|
assert!(session_id_grants(
|
||||||
|
Some(&session_id),
|
||||||
|
&state,
|
||||||
|
AuthRole::Transmit
|
||||||
|
));
|
||||||
|
state.store.remove(&session_id);
|
||||||
|
assert!(!session_id_grants(
|
||||||
|
Some(&session_id),
|
||||||
|
&state,
|
||||||
|
AuthRole::Transmit
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn user_store_bootstraps_and_manages_users() {
|
fn user_store_bootstraps_and_manages_users() {
|
||||||
let directory = tempfile::tempdir().unwrap();
|
let directory = tempfile::tempdir().unwrap();
|
||||||
@@ -1532,12 +1607,25 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn guest_is_an_exclusive_role() {
|
fn guest_can_be_combined_with_non_administrator_roles() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
validate_roles(roles(&[AuthRole::Guest])).unwrap(),
|
validate_roles(roles(&[
|
||||||
roles(&[AuthRole::Guest])
|
AuthRole::Guest,
|
||||||
|
AuthRole::Read,
|
||||||
|
AuthRole::Control,
|
||||||
|
AuthRole::Transmit,
|
||||||
|
AuthRole::Write,
|
||||||
|
]))
|
||||||
|
.unwrap(),
|
||||||
|
roles(&[
|
||||||
|
AuthRole::Guest,
|
||||||
|
AuthRole::Read,
|
||||||
|
AuthRole::Control,
|
||||||
|
AuthRole::Transmit,
|
||||||
|
AuthRole::Write,
|
||||||
|
])
|
||||||
);
|
);
|
||||||
assert!(validate_roles(roles(&[AuthRole::Guest, AuthRole::Read])).is_err());
|
assert!(validate_roles(roles(&[AuthRole::Guest, AuthRole::Administrator])).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -1608,6 +1696,16 @@ mod tests {
|
|||||||
assert_eq!(response.status(), actix_web::http::StatusCode::OK);
|
assert_eq!(response.status(), actix_web::http::StatusCode::OK);
|
||||||
let admin_cookie = response.response().cookies().next().unwrap().to_string();
|
let admin_cookie = response.response().cookies().next().unwrap().to_string();
|
||||||
|
|
||||||
|
let request = aw_test::TestRequest::patch()
|
||||||
|
.uri("/auth/users/guest")
|
||||||
|
.insert_header((actix_web::http::header::COOKIE, admin_cookie.clone()))
|
||||||
|
.set_json(serde_json::json!({"password":"changed-guest-password"}))
|
||||||
|
.to_request();
|
||||||
|
assert_eq!(
|
||||||
|
aw_test::call_service(&app, request).await.status(),
|
||||||
|
actix_web::http::StatusCode::BAD_REQUEST
|
||||||
|
);
|
||||||
|
|
||||||
let request = aw_test::TestRequest::post()
|
let request = aw_test::TestRequest::post()
|
||||||
.uri("/auth/users")
|
.uri("/auth/users")
|
||||||
.insert_header((actix_web::http::header::COOKIE, admin_cookie.clone()))
|
.insert_header((actix_web::http::header::COOKIE, admin_cookie.clone()))
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ pub struct Bookmark {
|
|||||||
pub comment: String,
|
pub comment: String,
|
||||||
pub category: String,
|
pub category: String,
|
||||||
pub decoders: Vec<String>,
|
pub decoders: Vec<String>,
|
||||||
|
/// For `DIG` bookmarks, the sideband policy to apply on tune: `auto`,
|
||||||
|
/// `usb`, or `lsb`. `None` (or non-DIG) leaves the current policy alone.
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
pub dig_sideband: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct BookmarkStore {
|
pub struct BookmarkStore {
|
||||||
|
|||||||
@@ -592,6 +592,21 @@ async fn apply_scheduler_target(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
// Apply any DIG sideband override before switching to DIG so the SDR
|
||||||
|
// backend resolves the intended sideband for this bookmark.
|
||||||
|
if let Some(policy) = bookmark
|
||||||
|
.dig_sideband
|
||||||
|
.as_deref()
|
||||||
|
.and_then(trx_core::DigSidebandPolicy::parse)
|
||||||
|
{
|
||||||
|
scheduler_send(
|
||||||
|
rig_tx,
|
||||||
|
RigCommand::SetSdrDigSideband(policy),
|
||||||
|
remote.to_string(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
scheduler_send(
|
scheduler_send(
|
||||||
rig_tx,
|
rig_tx,
|
||||||
RigCommand::SetMode(trx_protocol::parse_mode(&bookmark.mode)),
|
RigCommand::SetMode(trx_protocol::parse_mode(&bookmark.mode)),
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use crate::shared::{check_socket_conflicts, validate_log_level, validate_tokens,
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
pub use trx_decode_log::DecodeLogsConfig;
|
pub use trx_decode_log::DecodeLogsConfig;
|
||||||
|
|
||||||
use trx_core::rig::state::RigMode;
|
use trx_core::rig::state::{DigSidebandPolicy, NoiseBlankerProfile, RigMode};
|
||||||
|
|
||||||
/// Every decoder the server knows how to run, by config name.
|
/// Every decoder the server knows how to run, by config name.
|
||||||
///
|
///
|
||||||
@@ -393,6 +393,10 @@ pub struct SdrConfig {
|
|||||||
pub squelch: SdrSquelchConfig,
|
pub squelch: SdrSquelchConfig,
|
||||||
/// Noise blanker for impulse noise suppression on IQ samples.
|
/// Noise blanker for impulse noise suppression on IQ samples.
|
||||||
pub noise_blanker: SdrNoiseBlankerConfig,
|
pub noise_blanker: SdrNoiseBlankerConfig,
|
||||||
|
/// How DIG mode picks a sideband: `auto` (USB ≥ 10 MHz, LSB below),
|
||||||
|
/// `usb`, or `lsb`. Overridable at runtime and per-bookmark.
|
||||||
|
#[serde(default)]
|
||||||
|
pub dig_sideband: DigSidebandPolicy,
|
||||||
/// Virtual receiver channels (at least one required when SDR backend is active).
|
/// Virtual receiver channels (at least one required when SDR backend is active).
|
||||||
pub channels: Vec<SdrChannelConfig>,
|
pub channels: Vec<SdrChannelConfig>,
|
||||||
/// Maximum number of simultaneous virtual channels (including the primary).
|
/// Maximum number of simultaneous virtual channels (including the primary).
|
||||||
@@ -433,6 +437,7 @@ impl Default for SdrConfig {
|
|||||||
gain: SdrGainConfig::default(),
|
gain: SdrGainConfig::default(),
|
||||||
squelch: SdrSquelchConfig::default(),
|
squelch: SdrSquelchConfig::default(),
|
||||||
noise_blanker: SdrNoiseBlankerConfig::default(),
|
noise_blanker: SdrNoiseBlankerConfig::default(),
|
||||||
|
dig_sideband: DigSidebandPolicy::default(),
|
||||||
channels: Vec::new(),
|
channels: Vec::new(),
|
||||||
max_virtual_channels: default_max_virtual_channels(),
|
max_virtual_channels: default_max_virtual_channels(),
|
||||||
spectrum_fft_size: default_spectrum_fft_size(),
|
spectrum_fft_size: default_spectrum_fft_size(),
|
||||||
@@ -473,8 +478,14 @@ pub struct SdrNoiseBlankerConfig {
|
|||||||
/// Enables the noise blanker.
|
/// Enables the noise blanker.
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
/// Threshold multiplier for impulse detection (typical range: 1..100).
|
/// Threshold multiplier for impulse detection (typical range: 1..100).
|
||||||
/// A sample whose magnitude exceeds threshold × running RMS is blanked.
|
/// A sample whose magnitude exceeds threshold × the tracked noise floor is
|
||||||
|
/// blanked. Lower values blank more aggressively.
|
||||||
pub threshold: f64,
|
pub threshold: f64,
|
||||||
|
/// Tuning profile matched to the interference source: `spike` (default),
|
||||||
|
/// `ignition`, `powerline`, or `broadband`. Selects the blank window width,
|
||||||
|
/// look-ahead, gate taper, and noise-floor time constant.
|
||||||
|
#[serde(default)]
|
||||||
|
pub profile: NoiseBlankerProfile,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for SdrNoiseBlankerConfig {
|
impl Default for SdrNoiseBlankerConfig {
|
||||||
@@ -482,6 +493,7 @@ impl Default for SdrNoiseBlankerConfig {
|
|||||||
Self {
|
Self {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
threshold: 10.0,
|
threshold: 10.0,
|
||||||
|
profile: NoiseBlankerProfile::Spike,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ pub use rig::command::RigCommand;
|
|||||||
pub use rig::request::RigRequest;
|
pub use rig::request::RigRequest;
|
||||||
pub use rig::response::{RigError, RigResult};
|
pub use rig::response::{RigError, RigResult};
|
||||||
pub use rig::state::{
|
pub use rig::state::{
|
||||||
DecoderConfig, DecoderResetSeqs, RdsData, RigFilterState, RigMode, RigSnapshot, RigState,
|
DecoderConfig, DecoderResetSeqs, DigSidebandPolicy, NoiseBlankerProfile, RdsData,
|
||||||
WfmDenoiseLevel,
|
RigFilterState, RigMode, RigSnapshot, RigState, WfmDenoiseLevel,
|
||||||
};
|
};
|
||||||
pub use rig::AudioSource;
|
pub use rig::AudioSource;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
use crate::radio::freq::Freq;
|
use crate::radio::freq::Freq;
|
||||||
use crate::rig::state::WfmDenoiseLevel;
|
use crate::rig::state::{DigSidebandPolicy, NoiseBlankerProfile, WfmDenoiseLevel};
|
||||||
use crate::RigMode;
|
use crate::RigMode;
|
||||||
|
|
||||||
/// Internal command handled by the rig task.
|
/// Internal command handled by the rig task.
|
||||||
@@ -48,8 +48,17 @@ pub enum RigCommand {
|
|||||||
SetSdrGain(f64),
|
SetSdrGain(f64),
|
||||||
SetSdrLnaGain(f64),
|
SetSdrLnaGain(f64),
|
||||||
SetSdrAgc(bool),
|
SetSdrAgc(bool),
|
||||||
SetSdrSquelch { enabled: bool, threshold_db: f64 },
|
SetSdrSquelch {
|
||||||
SetSdrNoiseBlanker { enabled: bool, threshold: f64 },
|
enabled: bool,
|
||||||
|
threshold_db: f64,
|
||||||
|
},
|
||||||
|
SetSdrNoiseBlanker {
|
||||||
|
enabled: bool,
|
||||||
|
threshold: f64,
|
||||||
|
profile: NoiseBlankerProfile,
|
||||||
|
},
|
||||||
|
/// Set how the SDR backend resolves DIG mode to a sideband (SDR only).
|
||||||
|
SetSdrDigSideband(DigSidebandPolicy),
|
||||||
SetWfmDeemphasis(u32),
|
SetWfmDeemphasis(u32),
|
||||||
SetWfmStereo(bool),
|
SetWfmStereo(bool),
|
||||||
SetWfmDenoise(WfmDenoiseLevel),
|
SetWfmDenoise(WfmDenoiseLevel),
|
||||||
|
|||||||
@@ -470,6 +470,7 @@ pub fn command_from_rig_command(cmd: RigCommand) -> Box<dyn RigCommandHandler> {
|
|||||||
| RigCommand::SetSdrAgc(_)
|
| RigCommand::SetSdrAgc(_)
|
||||||
| RigCommand::SetSdrSquelch { .. }
|
| RigCommand::SetSdrSquelch { .. }
|
||||||
| RigCommand::SetSdrNoiseBlanker { .. }
|
| RigCommand::SetSdrNoiseBlanker { .. }
|
||||||
|
| RigCommand::SetSdrDigSideband(_)
|
||||||
| RigCommand::SetWfmDeemphasis(_)
|
| RigCommand::SetWfmDeemphasis(_)
|
||||||
| RigCommand::SetWfmStereo(_)
|
| RigCommand::SetWfmStereo(_)
|
||||||
| RigCommand::SetWfmDenoise(_)
|
| RigCommand::SetWfmDenoise(_)
|
||||||
|
|||||||
@@ -253,6 +253,7 @@ pub trait RigSdr: Send {
|
|||||||
&'a mut self,
|
&'a mut self,
|
||||||
_enabled: bool,
|
_enabled: bool,
|
||||||
_threshold: f64,
|
_threshold: f64,
|
||||||
|
_profile: crate::rig::state::NoiseBlankerProfile,
|
||||||
) -> Pin<Box<dyn Future<Output = DynResult<()>> + Send + 'a>> {
|
) -> Pin<Box<dyn Future<Output = DynResult<()>> + Send + 'a>> {
|
||||||
Box::pin(std::future::ready(Err(
|
Box::pin(std::future::ready(Err(
|
||||||
Box::new(response::RigError::not_supported("set_sdr_noise_blanker"))
|
Box::new(response::RigError::not_supported("set_sdr_noise_blanker"))
|
||||||
@@ -260,6 +261,17 @@ pub trait RigSdr: Send {
|
|||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set how DIG mode resolves to a sideband (SDR backends only).
|
||||||
|
fn set_sdr_dig_sideband<'a>(
|
||||||
|
&'a mut self,
|
||||||
|
_policy: crate::rig::state::DigSidebandPolicy,
|
||||||
|
) -> Pin<Box<dyn Future<Output = DynResult<()>> + Send + 'a>> {
|
||||||
|
Box::pin(std::future::ready(Err(
|
||||||
|
Box::new(response::RigError::not_supported("set_sdr_dig_sideband"))
|
||||||
|
as Box<dyn std::error::Error + Send + Sync>,
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
fn set_wfm_stereo<'a>(
|
fn set_wfm_stereo<'a>(
|
||||||
&'a mut self,
|
&'a mut self,
|
||||||
_enabled: bool,
|
_enabled: bool,
|
||||||
|
|||||||
@@ -338,6 +338,14 @@ pub struct RigFilterState {
|
|||||||
pub sdr_nb_enabled: Option<bool>,
|
pub sdr_nb_enabled: Option<bool>,
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
pub sdr_nb_threshold: Option<f64>,
|
pub sdr_nb_threshold: Option<f64>,
|
||||||
|
/// Current noise-blanker tuning profile (SDR backends only). Surfaces in the
|
||||||
|
/// UI as the advanced-controls "NB profile" selector.
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
pub sdr_nb_profile: Option<NoiseBlankerProfile>,
|
||||||
|
/// Current DIG sideband policy (SDR backends only). Surfaces in the UI as
|
||||||
|
/// the advanced-controls "DIG sideband" selector.
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
pub sdr_dig_sideband: Option<DigSidebandPolicy>,
|
||||||
#[serde(default = "default_wfm_deemphasis_us")]
|
#[serde(default = "default_wfm_deemphasis_us")]
|
||||||
pub wfm_deemphasis_us: u32,
|
pub wfm_deemphasis_us: u32,
|
||||||
#[serde(default = "default_wfm_stereo")]
|
#[serde(default = "default_wfm_stereo")]
|
||||||
@@ -370,6 +378,155 @@ pub enum WfmDenoiseLevel {
|
|||||||
High,
|
High,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// How the SDR backend resolves the [`RigMode::DIG`] mode to a concrete
|
||||||
|
/// sideband when demodulating.
|
||||||
|
///
|
||||||
|
/// DIG (data / digital) has no inherent sideband; by ham-radio convention it
|
||||||
|
/// follows the SSB convention for the band. `Auto` applies that convention
|
||||||
|
/// (USB at/above 10 MHz, LSB below); `Usb`/`Lsb` force a fixed sideband. The
|
||||||
|
/// setting is a global SDR control (see advanced radio controls) and may be
|
||||||
|
/// overridden per-bookmark.
|
||||||
|
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq, TS)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
|
pub enum DigSidebandPolicy {
|
||||||
|
/// Pick USB or LSB from the dial frequency (USB ≥ 10 MHz, LSB below).
|
||||||
|
#[default]
|
||||||
|
Auto,
|
||||||
|
/// Always demodulate DIG as upper sideband.
|
||||||
|
Usb,
|
||||||
|
/// Always demodulate DIG as lower sideband.
|
||||||
|
Lsb,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DigSidebandPolicy {
|
||||||
|
/// Frequency boundary used by [`DigSidebandPolicy::Auto`]: at or above this
|
||||||
|
/// dial frequency DIG is upper sideband, below it is lower sideband. This is
|
||||||
|
/// the standard amateur SSB/data convention.
|
||||||
|
pub const AUTO_THRESHOLD_HZ: u64 = 10_000_000;
|
||||||
|
|
||||||
|
/// Resolve this policy to a concrete sideband mode ([`RigMode::USB`] or
|
||||||
|
/// [`RigMode::LSB`]) for the given dial frequency.
|
||||||
|
pub fn resolve(self, freq_hz: u64) -> RigMode {
|
||||||
|
match self {
|
||||||
|
DigSidebandPolicy::Usb => RigMode::USB,
|
||||||
|
DigSidebandPolicy::Lsb => RigMode::LSB,
|
||||||
|
DigSidebandPolicy::Auto => {
|
||||||
|
if freq_hz >= Self::AUTO_THRESHOLD_HZ {
|
||||||
|
RigMode::USB
|
||||||
|
} else {
|
||||||
|
RigMode::LSB
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Compact encoding for storage in an atomic (e.g. shared runtime state).
|
||||||
|
pub fn to_u8(self) -> u8 {
|
||||||
|
match self {
|
||||||
|
DigSidebandPolicy::Auto => 0,
|
||||||
|
DigSidebandPolicy::Usb => 1,
|
||||||
|
DigSidebandPolicy::Lsb => 2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Inverse of [`DigSidebandPolicy::to_u8`]; unknown values decode to `Auto`.
|
||||||
|
pub fn from_u8(v: u8) -> Self {
|
||||||
|
match v {
|
||||||
|
1 => DigSidebandPolicy::Usb,
|
||||||
|
2 => DigSidebandPolicy::Lsb,
|
||||||
|
_ => DigSidebandPolicy::Auto,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse a case-insensitive `auto`/`usb`/`lsb` string; `None` if unknown.
|
||||||
|
pub fn parse(s: &str) -> Option<Self> {
|
||||||
|
match s.trim().to_ascii_lowercase().as_str() {
|
||||||
|
"auto" => Some(DigSidebandPolicy::Auto),
|
||||||
|
"usb" => Some(DigSidebandPolicy::Usb),
|
||||||
|
"lsb" => Some(DigSidebandPolicy::Lsb),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Resolve a channel's effective demodulation mode. For [`RigMode::DIG`] this
|
||||||
|
/// applies the sideband `policy` at the given dial frequency; every other mode
|
||||||
|
/// is returned unchanged. Callers hand the result to the DSP while keeping the
|
||||||
|
/// logical `DIG` mode for display and decoder gating.
|
||||||
|
pub fn effective_demod_mode(logical: &RigMode, policy: DigSidebandPolicy, freq_hz: u64) -> RigMode {
|
||||||
|
if *logical == RigMode::DIG {
|
||||||
|
policy.resolve(freq_hz)
|
||||||
|
} else {
|
||||||
|
logical.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Tuning profile for the SDR impulse noise blanker.
|
||||||
|
///
|
||||||
|
/// The blanker removes short, wideband impulse noise from the IQ stream before
|
||||||
|
/// down-conversion. Different interference sources have different pulse widths
|
||||||
|
/// and repetition rates, so a single blank window cannot serve all of them: too
|
||||||
|
/// narrow and it clips only the tip of a wide power-line burst, too wide and it
|
||||||
|
/// punches audible holes in the wanted signal on sparse ignition spikes. Each
|
||||||
|
/// profile selects a matched blank window, look-ahead, gate taper, and
|
||||||
|
/// noise-floor time constant (the concrete values live in the SDR DSP, since
|
||||||
|
/// they are converted to samples at the capture rate). The user-facing
|
||||||
|
/// `threshold` control is orthogonal — it sets detection sensitivity within the
|
||||||
|
/// chosen profile.
|
||||||
|
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq, TS)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
|
pub enum NoiseBlankerProfile {
|
||||||
|
/// Short, sharp, sparse impulses — ignition sparks, static crashes, keyed
|
||||||
|
/// relays. Narrow blank window and fast recovery for minimal impact on the
|
||||||
|
/// wanted signal; the safe default for SSB/CW/digital.
|
||||||
|
#[default]
|
||||||
|
Spike,
|
||||||
|
/// Automotive ignition, electric fences, PWM/LED drivers — clusters of
|
||||||
|
/// medium-width pulses at a high repetition rate. Wider window than `Spike`.
|
||||||
|
Ignition,
|
||||||
|
/// Power-line and arcing noise — buzzy bursts locked to the 100/120 Hz mains
|
||||||
|
/// cycle. Wide blank window with a longer, slower noise-floor tracker.
|
||||||
|
Powerline,
|
||||||
|
/// Dense, continuous impulse noise where suppression matters more than
|
||||||
|
/// fidelity. Widest window and most aggressive gating; expect some softening
|
||||||
|
/// of the wanted signal.
|
||||||
|
Broadband,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl NoiseBlankerProfile {
|
||||||
|
/// Compact encoding for storage in an atomic or terse wire field.
|
||||||
|
pub fn to_u8(self) -> u8 {
|
||||||
|
match self {
|
||||||
|
NoiseBlankerProfile::Spike => 0,
|
||||||
|
NoiseBlankerProfile::Ignition => 1,
|
||||||
|
NoiseBlankerProfile::Powerline => 2,
|
||||||
|
NoiseBlankerProfile::Broadband => 3,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Inverse of [`NoiseBlankerProfile::to_u8`]; unknown values decode to the
|
||||||
|
/// default `Spike`.
|
||||||
|
pub fn from_u8(v: u8) -> Self {
|
||||||
|
match v {
|
||||||
|
1 => NoiseBlankerProfile::Ignition,
|
||||||
|
2 => NoiseBlankerProfile::Powerline,
|
||||||
|
3 => NoiseBlankerProfile::Broadband,
|
||||||
|
_ => NoiseBlankerProfile::Spike,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse a case-insensitive profile name; `None` if unknown.
|
||||||
|
pub fn parse(s: &str) -> Option<Self> {
|
||||||
|
match s.trim().to_ascii_lowercase().as_str() {
|
||||||
|
"spike" => Some(NoiseBlankerProfile::Spike),
|
||||||
|
"ignition" => Some(NoiseBlankerProfile::Ignition),
|
||||||
|
"powerline" => Some(NoiseBlankerProfile::Powerline),
|
||||||
|
"broadband" => Some(NoiseBlankerProfile::Broadband),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn default_wfm_deemphasis_us() -> u32 {
|
fn default_wfm_deemphasis_us() -> u32 {
|
||||||
75
|
75
|
||||||
}
|
}
|
||||||
@@ -506,3 +663,111 @@ pub struct RigSnapshot {
|
|||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
pub vchan_rds: Option<Vec<VchanRdsEntry>>,
|
pub vchan_rds: Option<Vec<VchanRdsEntry>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod dig_sideband_tests {
|
||||||
|
use super::{effective_demod_mode, DigSidebandPolicy, RigMode};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn auto_follows_ssb_band_convention() {
|
||||||
|
// Below 10 MHz → LSB; at/above 10 MHz → USB.
|
||||||
|
assert_eq!(DigSidebandPolicy::Auto.resolve(7_074_000), RigMode::LSB);
|
||||||
|
assert_eq!(DigSidebandPolicy::Auto.resolve(3_580_000), RigMode::LSB);
|
||||||
|
assert_eq!(DigSidebandPolicy::Auto.resolve(9_999_999), RigMode::LSB);
|
||||||
|
assert_eq!(DigSidebandPolicy::Auto.resolve(10_000_000), RigMode::USB);
|
||||||
|
assert_eq!(DigSidebandPolicy::Auto.resolve(14_074_000), RigMode::USB);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn forced_policies_ignore_frequency() {
|
||||||
|
assert_eq!(DigSidebandPolicy::Usb.resolve(3_580_000), RigMode::USB);
|
||||||
|
assert_eq!(DigSidebandPolicy::Lsb.resolve(14_074_000), RigMode::LSB);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn effective_mode_only_rewrites_dig() {
|
||||||
|
// Non-DIG modes pass through untouched regardless of policy/frequency.
|
||||||
|
assert_eq!(
|
||||||
|
effective_demod_mode(&RigMode::USB, DigSidebandPolicy::Lsb, 3_580_000),
|
||||||
|
RigMode::USB
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
effective_demod_mode(&RigMode::FM, DigSidebandPolicy::Usb, 3_580_000),
|
||||||
|
RigMode::FM
|
||||||
|
);
|
||||||
|
// DIG resolves by policy + frequency.
|
||||||
|
assert_eq!(
|
||||||
|
effective_demod_mode(&RigMode::DIG, DigSidebandPolicy::Auto, 7_074_000),
|
||||||
|
RigMode::LSB
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
effective_demod_mode(&RigMode::DIG, DigSidebandPolicy::Auto, 14_074_000),
|
||||||
|
RigMode::USB
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn u8_roundtrips_and_parses() {
|
||||||
|
for p in [
|
||||||
|
DigSidebandPolicy::Auto,
|
||||||
|
DigSidebandPolicy::Usb,
|
||||||
|
DigSidebandPolicy::Lsb,
|
||||||
|
] {
|
||||||
|
assert_eq!(DigSidebandPolicy::from_u8(p.to_u8()), p);
|
||||||
|
}
|
||||||
|
assert_eq!(DigSidebandPolicy::from_u8(200), DigSidebandPolicy::Auto);
|
||||||
|
assert_eq!(
|
||||||
|
DigSidebandPolicy::parse("USB"),
|
||||||
|
Some(DigSidebandPolicy::Usb)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
DigSidebandPolicy::parse(" lsb "),
|
||||||
|
Some(DigSidebandPolicy::Lsb)
|
||||||
|
);
|
||||||
|
assert_eq!(DigSidebandPolicy::parse("nonsense"), None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod noise_blanker_profile_tests {
|
||||||
|
use super::NoiseBlankerProfile;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn default_is_spike() {
|
||||||
|
assert_eq!(NoiseBlankerProfile::default(), NoiseBlankerProfile::Spike);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn u8_round_trips() {
|
||||||
|
for p in [
|
||||||
|
NoiseBlankerProfile::Spike,
|
||||||
|
NoiseBlankerProfile::Ignition,
|
||||||
|
NoiseBlankerProfile::Powerline,
|
||||||
|
NoiseBlankerProfile::Broadband,
|
||||||
|
] {
|
||||||
|
assert_eq!(NoiseBlankerProfile::from_u8(p.to_u8()), p);
|
||||||
|
}
|
||||||
|
// Unknown encodings fall back to the default.
|
||||||
|
assert_eq!(
|
||||||
|
NoiseBlankerProfile::from_u8(200),
|
||||||
|
NoiseBlankerProfile::Spike
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_is_case_insensitive() {
|
||||||
|
assert_eq!(
|
||||||
|
NoiseBlankerProfile::parse("SPIKE"),
|
||||||
|
Some(NoiseBlankerProfile::Spike)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
NoiseBlankerProfile::parse(" powerline "),
|
||||||
|
Some(NoiseBlankerProfile::Powerline)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
NoiseBlankerProfile::parse("Broadband"),
|
||||||
|
Some(NoiseBlankerProfile::Broadband)
|
||||||
|
);
|
||||||
|
assert_eq!(NoiseBlankerProfile::parse("nonsense"), None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -343,6 +343,8 @@ mod tests {
|
|||||||
sdr_squelch_threshold_db: None,
|
sdr_squelch_threshold_db: None,
|
||||||
sdr_nb_enabled: None,
|
sdr_nb_enabled: None,
|
||||||
sdr_nb_threshold: None,
|
sdr_nb_threshold: None,
|
||||||
|
sdr_nb_profile: None,
|
||||||
|
sdr_dig_sideband: None,
|
||||||
wfm_deemphasis_us: 75,
|
wfm_deemphasis_us: 75,
|
||||||
wfm_stereo: true,
|
wfm_stereo: true,
|
||||||
wfm_stereo_detected: false,
|
wfm_stereo_detected: false,
|
||||||
@@ -391,6 +393,8 @@ mod tests {
|
|||||||
sdr_squelch_threshold_db: None,
|
sdr_squelch_threshold_db: None,
|
||||||
sdr_nb_enabled: None,
|
sdr_nb_enabled: None,
|
||||||
sdr_nb_threshold: None,
|
sdr_nb_threshold: None,
|
||||||
|
sdr_nb_profile: None,
|
||||||
|
sdr_dig_sideband: None,
|
||||||
wfm_deemphasis_us: 50,
|
wfm_deemphasis_us: 50,
|
||||||
wfm_stereo: true,
|
wfm_stereo: true,
|
||||||
wfm_stereo_detected: true,
|
wfm_stereo_detected: true,
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ define_command_mapping! {
|
|||||||
SetSdrGain { gain_db } <=> SetSdrGain,
|
SetSdrGain { gain_db } <=> SetSdrGain,
|
||||||
SetSdrLnaGain { gain_db } <=> SetSdrLnaGain,
|
SetSdrLnaGain { gain_db } <=> SetSdrLnaGain,
|
||||||
SetSdrAgc { enabled } <=> SetSdrAgc,
|
SetSdrAgc { enabled } <=> SetSdrAgc,
|
||||||
|
SetSdrDigSideband { policy } <=> SetSdrDigSideband,
|
||||||
SetWfmDeemphasis { deemphasis_us } <=> SetWfmDeemphasis,
|
SetWfmDeemphasis { deemphasis_us } <=> SetWfmDeemphasis,
|
||||||
SetWfmStereo { enabled } <=> SetWfmStereo,
|
SetWfmStereo { enabled } <=> SetWfmStereo,
|
||||||
SetWfmDenoise { level } <=> SetWfmDenoise,
|
SetWfmDenoise { level } <=> SetWfmDenoise,
|
||||||
@@ -156,7 +157,7 @@ define_command_mapping! {
|
|||||||
// ── Multi-field struct passthrough ───────────────────────────────
|
// ── Multi-field struct passthrough ───────────────────────────────
|
||||||
multi:
|
multi:
|
||||||
SetSdrSquelch { enabled, threshold_db } <=> SetSdrSquelch,
|
SetSdrSquelch { enabled, threshold_db } <=> SetSdrSquelch,
|
||||||
SetSdrNoiseBlanker { enabled, threshold } <=> SetSdrNoiseBlanker;
|
SetSdrNoiseBlanker { enabled, threshold, profile } <=> SetSdrNoiseBlanker;
|
||||||
|
|
||||||
// ── Freq conversions (u64 <=> Freq) ──────────────────────────────
|
// ── Freq conversions (u64 <=> Freq) ──────────────────────────────
|
||||||
freq:
|
freq:
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use trx_core::rig::state::RigSnapshot;
|
use trx_core::rig::state::RigSnapshot;
|
||||||
use trx_core::WfmDenoiseLevel;
|
use trx_core::{DigSidebandPolicy, NoiseBlankerProfile, WfmDenoiseLevel};
|
||||||
|
|
||||||
/// Command received from network clients (JSON).
|
/// Command received from network clients (JSON).
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
@@ -105,6 +105,10 @@ pub enum ClientCommand {
|
|||||||
SetSdrNoiseBlanker {
|
SetSdrNoiseBlanker {
|
||||||
enabled: bool,
|
enabled: bool,
|
||||||
threshold: f64,
|
threshold: f64,
|
||||||
|
profile: NoiseBlankerProfile,
|
||||||
|
},
|
||||||
|
SetSdrDigSideband {
|
||||||
|
policy: DigSidebandPolicy,
|
||||||
},
|
},
|
||||||
SetWfmDeemphasis {
|
SetWfmDeemphasis {
|
||||||
deemphasis_us: u32,
|
deemphasis_us: u32,
|
||||||
|
|||||||
@@ -360,6 +360,8 @@ fn build_sdr_rig_from_instance(rig_cfg: &RigInstanceConfig) -> SdrRigBuildResult
|
|||||||
max_virtual_channels: rig_cfg.sdr.max_virtual_channels,
|
max_virtual_channels: rig_cfg.sdr.max_virtual_channels,
|
||||||
nb_enabled: rig_cfg.sdr.noise_blanker.enabled,
|
nb_enabled: rig_cfg.sdr.noise_blanker.enabled,
|
||||||
nb_threshold: rig_cfg.sdr.noise_blanker.threshold,
|
nb_threshold: rig_cfg.sdr.noise_blanker.threshold,
|
||||||
|
nb_profile: rig_cfg.sdr.noise_blanker.profile,
|
||||||
|
dig_sideband: rig_cfg.sdr.dig_sideband,
|
||||||
spectrum_fft_size: rig_cfg.sdr.spectrum_fft_size,
|
spectrum_fft_size: rig_cfg.sdr.spectrum_fft_size,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
@@ -920,11 +922,10 @@ fn bound_sockets(cli: &Cli, cfg: &ServerConfig, rigs: &[RigInstanceConfig]) -> V
|
|||||||
"[listen]",
|
"[listen]",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let audio_ip = cli.listen.unwrap_or(cfg.audio.listen);
|
|
||||||
for rig in rigs {
|
for rig in rigs {
|
||||||
if rig.audio.enabled {
|
if rig.audio.enabled {
|
||||||
sockets.push(BoundSocket::new(
|
sockets.push(BoundSocket::new(
|
||||||
audio_ip,
|
cli.listen.unwrap_or(rig.audio.listen),
|
||||||
rig.audio.port,
|
rig.audio.port,
|
||||||
format!("rig \"{}\" [audio]", rig.id),
|
format!("rig \"{}\" [audio]", rig.id),
|
||||||
));
|
));
|
||||||
@@ -1274,9 +1275,9 @@ async fn main() -> DynResult<()> {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Spawn audio stack.
|
// Spawn audio stack. --listen overrides every configured bind address;
|
||||||
// listen_override priority: --listen CLI flag > global [audio].listen > per-rig default.
|
// otherwise each rig keeps its own [rigs.audio].listen value.
|
||||||
let audio_listen_override = cli.listen.or(Some(cfg.audio.listen));
|
let audio_listen_override = cli.listen;
|
||||||
#[cfg(feature = "soapysdr")]
|
#[cfg(feature = "soapysdr")]
|
||||||
let audio_vchan_manager = sdr_vchan_manager.clone();
|
let audio_vchan_manager = sdr_vchan_manager.clone();
|
||||||
#[cfg(not(feature = "soapysdr"))]
|
#[cfg(not(feature = "soapysdr"))]
|
||||||
@@ -1415,6 +1416,40 @@ mod tests {
|
|||||||
assert!(parse_serial_addr(" ").is_err());
|
assert!(parse_serial_addr(" ").is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bound_sockets_preserves_per_rig_audio_addresses() {
|
||||||
|
let cli = Cli::parse_from(["trx-server"]);
|
||||||
|
let cfg = ServerConfig::default();
|
||||||
|
let mut local = RigInstanceConfig::default();
|
||||||
|
local.id = "local".into();
|
||||||
|
local.audio.listen = "127.0.0.1".parse().unwrap();
|
||||||
|
local.audio.port = 4531;
|
||||||
|
let mut remote = RigInstanceConfig::default();
|
||||||
|
remote.id = "remote".into();
|
||||||
|
remote.audio.listen = "0.0.0.0".parse().unwrap();
|
||||||
|
remote.audio.port = 4532;
|
||||||
|
|
||||||
|
let sockets = bound_sockets(&cli, &cfg, &[local, remote]);
|
||||||
|
let local = sockets.iter().find(|s| s.port == 4531).unwrap();
|
||||||
|
let remote = sockets.iter().find(|s| s.port == 4532).unwrap();
|
||||||
|
assert_eq!(local.addr, "127.0.0.1".parse::<IpAddr>().unwrap());
|
||||||
|
assert_eq!(remote.addr, "0.0.0.0".parse::<IpAddr>().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bound_sockets_applies_cli_listen_to_every_audio_listener() {
|
||||||
|
let cli = Cli::parse_from(["trx-server", "--listen", "192.0.2.10"]);
|
||||||
|
let cfg = ServerConfig::default();
|
||||||
|
let mut rig = RigInstanceConfig::default();
|
||||||
|
rig.id = "remote".into();
|
||||||
|
rig.audio.listen = "127.0.0.1".parse().unwrap();
|
||||||
|
rig.audio.port = 4532;
|
||||||
|
|
||||||
|
let sockets = bound_sockets(&cli, &cfg, &[rig]);
|
||||||
|
let audio = sockets.iter().find(|s| s.port == 4532).unwrap();
|
||||||
|
assert_eq!(audio.addr, "192.0.2.10".parse::<IpAddr>().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn default_audio_bandwidth_for_mode_table() {
|
fn default_audio_bandwidth_for_mode_table() {
|
||||||
assert_eq!(default_audio_bandwidth_for_mode(&RigMode::USB), 3_000);
|
assert_eq!(default_audio_bandwidth_for_mode(&RigMode::USB), 3_000);
|
||||||
|
|||||||
@@ -760,9 +760,13 @@ async fn process_command(
|
|||||||
let _ = ctx.state_tx.send(ctx.state.clone());
|
let _ = ctx.state_tx.send(ctx.state.clone());
|
||||||
return snapshot_from(ctx.state);
|
return snapshot_from(ctx.state);
|
||||||
}
|
}
|
||||||
RigCommand::SetSdrNoiseBlanker { enabled, threshold } => {
|
RigCommand::SetSdrNoiseBlanker {
|
||||||
|
enabled,
|
||||||
|
threshold,
|
||||||
|
profile,
|
||||||
|
} => {
|
||||||
if let Some(sdr) = ctx.rig.as_sdr() {
|
if let Some(sdr) = ctx.rig.as_sdr() {
|
||||||
if let Err(e) = sdr.set_sdr_noise_blanker(enabled, threshold).await {
|
if let Err(e) = sdr.set_sdr_noise_blanker(enabled, threshold, profile).await {
|
||||||
return Err(RigError::communication(format!(
|
return Err(RigError::communication(format!(
|
||||||
"set_sdr_noise_blanker: {e}"
|
"set_sdr_noise_blanker: {e}"
|
||||||
)));
|
)));
|
||||||
@@ -774,6 +778,20 @@ async fn process_command(
|
|||||||
let _ = ctx.state_tx.send(ctx.state.clone());
|
let _ = ctx.state_tx.send(ctx.state.clone());
|
||||||
return snapshot_from(ctx.state);
|
return snapshot_from(ctx.state);
|
||||||
}
|
}
|
||||||
|
RigCommand::SetSdrDigSideband(policy) => {
|
||||||
|
if let Some(sdr) = ctx.rig.as_sdr() {
|
||||||
|
if let Err(e) = sdr.set_sdr_dig_sideband(policy).await {
|
||||||
|
return Err(RigError::communication(format!(
|
||||||
|
"set_sdr_dig_sideband: {e}"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Err(RigError::not_supported("set_sdr_dig_sideband"));
|
||||||
|
}
|
||||||
|
ctx.state.filter = ctx.rig.as_sdr_ref().and_then(|s| s.filter_state());
|
||||||
|
let _ = ctx.state_tx.send(ctx.state.clone());
|
||||||
|
return snapshot_from(ctx.state);
|
||||||
|
}
|
||||||
RigCommand::SetWfmDeemphasis(deemphasis_us) => {
|
RigCommand::SetWfmDeemphasis(deemphasis_us) => {
|
||||||
if let Some(sdr) = ctx.rig.as_sdr() {
|
if let Some(sdr) = ctx.rig.as_sdr() {
|
||||||
if let Err(e) = sdr.set_wfm_deemphasis(deemphasis_us).await {
|
if let Err(e) = sdr.set_wfm_deemphasis(deemphasis_us).await {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
use num_complex::Complex;
|
use num_complex::Complex;
|
||||||
use tokio::sync::broadcast;
|
use tokio::sync::broadcast;
|
||||||
use trx_core::rig::state::{RdsData, RigMode, WfmDenoiseLevel};
|
use trx_core::rig::state::{NoiseBlankerProfile, RdsData, RigMode, WfmDenoiseLevel};
|
||||||
|
|
||||||
use crate::demod::{DcBlocker, Demodulator, SamDemod, SoftAgc, WfmStereoDecoder};
|
use crate::demod::{DcBlocker, Demodulator, SamDemod, SoftAgc, WfmStereoDecoder};
|
||||||
|
|
||||||
@@ -14,38 +14,174 @@ use super::{BlockFirFilterPair, IQ_BLOCK_SIZE};
|
|||||||
// Noise blanker
|
// Noise blanker
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
/// IQ-domain impulse noise blanker.
|
/// Temporal shape of a [`NoiseBlankerProfile`], in real time so the numbers
|
||||||
|
/// scale correctly across capture rates (they are converted to samples at
|
||||||
|
/// runtime). See [`NoiseBlanker`] for how each field is used.
|
||||||
|
struct NbShape {
|
||||||
|
/// Delay applied to the stream so the gate can begin closing *before* a
|
||||||
|
/// detected impulse reaches the output, catching its leading edge.
|
||||||
|
lookahead_us: f32,
|
||||||
|
/// Minimum time the gate is held fully closed after each detected sample.
|
||||||
|
blank_us: f32,
|
||||||
|
/// Raised-cosine gate ramp length (attack == release).
|
||||||
|
ramp_us: f32,
|
||||||
|
/// Time constant of the exponential noise-floor tracker.
|
||||||
|
ref_tc_ms: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl NbShape {
|
||||||
|
const fn for_profile(p: NoiseBlankerProfile) -> Self {
|
||||||
|
match p {
|
||||||
|
// Short, sparse spikes: tight window, quick recovery, fast floor.
|
||||||
|
NoiseBlankerProfile::Spike => NbShape {
|
||||||
|
lookahead_us: 8.0,
|
||||||
|
blank_us: 24.0,
|
||||||
|
ramp_us: 5.0,
|
||||||
|
ref_tc_ms: 4.0,
|
||||||
|
},
|
||||||
|
// Ignition/PWM bursts: medium window at a high repetition rate.
|
||||||
|
NoiseBlankerProfile::Ignition => NbShape {
|
||||||
|
lookahead_us: 12.0,
|
||||||
|
blank_us: 80.0,
|
||||||
|
ramp_us: 8.0,
|
||||||
|
ref_tc_ms: 4.0,
|
||||||
|
},
|
||||||
|
// Power-line buzz: wide window, slow floor to ride out the burst.
|
||||||
|
NoiseBlankerProfile::Powerline => NbShape {
|
||||||
|
lookahead_us: 20.0,
|
||||||
|
blank_us: 200.0,
|
||||||
|
ramp_us: 12.0,
|
||||||
|
ref_tc_ms: 15.0,
|
||||||
|
},
|
||||||
|
// Dense impulse noise: widest, most aggressive gating.
|
||||||
|
NoiseBlankerProfile::Broadband => NbShape {
|
||||||
|
lookahead_us: 24.0,
|
||||||
|
blank_us: 400.0,
|
||||||
|
ramp_us: 16.0,
|
||||||
|
ref_tc_ms: 8.0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Floor for the tracked noise-floor estimate, guarding against a zero divisor
|
||||||
|
/// and cold-start false triggers.
|
||||||
|
const NB_MIN_REF: f32 = 1e-12;
|
||||||
|
|
||||||
|
/// IQ-domain impulse noise blanker with look-ahead and a tapered gate.
|
||||||
///
|
///
|
||||||
/// Maintains a running RMS estimate of the IQ magnitude. When a sample's
|
/// This runs on the wide, undecimated IQ stream — the only place an impulse is
|
||||||
/// magnitude exceeds `threshold × rms`, it is replaced by linear interpolation
|
/// still short in time (narrow filtering downstream smears it into un-removable
|
||||||
/// between the last clean sample and the next clean sample (lookahead of 1).
|
/// ringing). The algorithm has four parts:
|
||||||
///
|
///
|
||||||
/// The RMS tracker uses exponential smoothing with a time constant of ~128
|
/// 1. **Noise-floor tracker** — an exponential mean-square estimate updated
|
||||||
/// samples at the IQ sample rate, fast enough to track band-noise changes
|
/// *only from clean samples* and frozen while blanking, so a burst cannot
|
||||||
/// but slow enough not to follow individual impulses.
|
/// drag the reference up and desensitise detection. Its time constant comes
|
||||||
|
/// from the profile.
|
||||||
|
/// 2. **Detection** — a sample is an impulse when its instantaneous power
|
||||||
|
/// exceeds `threshold² × noise_floor`. `threshold` is the user sensitivity
|
||||||
|
/// knob and is orthogonal to the profile.
|
||||||
|
/// 3. **Look-ahead** — the signal is delayed by `lookahead` samples so the gate
|
||||||
|
/// can start closing before the impulse reaches the output, removing the
|
||||||
|
/// leading edge instead of letting it leak through (the old blanker's main
|
||||||
|
/// failure). Each detection holds the gate shut for a profile-sized window.
|
||||||
|
/// 4. **Tapered gate** — instead of the old hard sample-and-hold (a step that
|
||||||
|
/// splattered energy right back across the passband and made the blanker
|
||||||
|
/// audibly worse on SSB/CW/data), the gain ramps smoothly 1→0→1 over
|
||||||
|
/// `ramp` samples, so blanking costs only a short, quiet notch.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct NoiseBlanker {
|
pub struct NoiseBlanker {
|
||||||
enabled: bool,
|
enabled: bool,
|
||||||
|
profile: NoiseBlankerProfile,
|
||||||
|
sample_rate: f32,
|
||||||
|
/// Detection sensitivity multiplier over the tracked noise floor (>= 1).
|
||||||
threshold: f32,
|
threshold: f32,
|
||||||
/// Exponentially-smoothed mean-square estimate.
|
|
||||||
mean_sq: f32,
|
// Derived from (profile, sample_rate); recomputed when either changes.
|
||||||
/// Last clean sample (used for interpolation fill).
|
lookahead: usize,
|
||||||
last_clean: Complex<f32>,
|
blank_samples: usize,
|
||||||
|
/// Per-sample gate gain increment; `1.0 / ramp_len`.
|
||||||
|
ramp_step: f32,
|
||||||
|
/// Noise-floor EMA coefficient.
|
||||||
|
ref_alpha: f32,
|
||||||
|
/// Samples to seed the noise floor before detection is trusted.
|
||||||
|
warmup: u32,
|
||||||
|
|
||||||
|
// Streaming state.
|
||||||
|
/// Look-ahead ring buffer (length `lookahead`; empty when `lookahead == 0`).
|
||||||
|
delay: Vec<Complex<f32>>,
|
||||||
|
dpos: usize,
|
||||||
|
/// Tracked noise-floor mean-square.
|
||||||
|
ref_sq: f32,
|
||||||
|
/// Samples processed since (re)configuration, capped at `warmup`.
|
||||||
|
seen: u32,
|
||||||
|
/// Remaining forced-blank samples.
|
||||||
|
hold: usize,
|
||||||
|
/// Current gate gain in `0.0..=1.0`.
|
||||||
|
gain: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
const NB_ALPHA: f32 = 1.0 / 128.0;
|
|
||||||
|
|
||||||
impl NoiseBlanker {
|
impl NoiseBlanker {
|
||||||
pub fn new(enabled: bool, threshold: f32) -> Self {
|
pub fn new(cfg: NoiseBlankerConfig, sample_rate: u32) -> Self {
|
||||||
Self {
|
let mut nb = Self {
|
||||||
enabled,
|
enabled: cfg.enabled,
|
||||||
threshold: threshold.max(1.0),
|
profile: cfg.profile,
|
||||||
mean_sq: 1e-10,
|
sample_rate: sample_rate as f32,
|
||||||
last_clean: Complex::new(0.0, 0.0),
|
threshold: cfg.threshold.max(1.0),
|
||||||
|
lookahead: 0,
|
||||||
|
blank_samples: 0,
|
||||||
|
ramp_step: 1.0,
|
||||||
|
ref_alpha: 0.0,
|
||||||
|
warmup: 0,
|
||||||
|
delay: Vec::new(),
|
||||||
|
dpos: 0,
|
||||||
|
ref_sq: NB_MIN_REF,
|
||||||
|
seen: 0,
|
||||||
|
hold: 0,
|
||||||
|
gain: 1.0,
|
||||||
|
};
|
||||||
|
nb.recompute();
|
||||||
|
nb
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Recompute sample-domain parameters from the current profile and sample
|
||||||
|
/// rate, then clear streaming state so the new geometry starts clean.
|
||||||
|
fn recompute(&mut self) {
|
||||||
|
let sr = self.sample_rate.max(1.0);
|
||||||
|
let shape = NbShape::for_profile(self.profile);
|
||||||
|
let per_us = sr / 1_000_000.0;
|
||||||
|
|
||||||
|
self.lookahead = ((shape.lookahead_us * per_us).round() as usize).max(1);
|
||||||
|
self.blank_samples = ((shape.blank_us * per_us).round() as usize).max(1);
|
||||||
|
let ramp_len = (shape.ramp_us * per_us).round().max(1.0);
|
||||||
|
self.ramp_step = 1.0 / ramp_len;
|
||||||
|
let ref_tc = (shape.ref_tc_ms * 1e-3 * sr).max(1.0);
|
||||||
|
self.ref_alpha = 1.0 / ref_tc;
|
||||||
|
// Warm up over roughly one floor time constant, bounded so a huge rate
|
||||||
|
// cannot stall detection for long.
|
||||||
|
self.warmup = ref_tc.min(96_000.0) as u32;
|
||||||
|
|
||||||
|
self.delay = vec![Complex::new(0.0, 0.0); self.lookahead];
|
||||||
|
self.reset_state();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Clear streaming state without touching the derived parameters.
|
||||||
|
fn reset_state(&mut self) {
|
||||||
|
for s in self.delay.iter_mut() {
|
||||||
|
*s = Complex::new(0.0, 0.0);
|
||||||
}
|
}
|
||||||
|
self.dpos = 0;
|
||||||
|
self.ref_sq = NB_MIN_REF;
|
||||||
|
self.seen = 0;
|
||||||
|
self.hold = 0;
|
||||||
|
self.gain = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_enabled(&mut self, enabled: bool) {
|
pub fn set_enabled(&mut self, enabled: bool) {
|
||||||
|
// Engaging fresh: drop any stale delayed samples and re-seed the floor.
|
||||||
|
if enabled && !self.enabled {
|
||||||
|
self.reset_state();
|
||||||
|
}
|
||||||
self.enabled = enabled;
|
self.enabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +189,14 @@ impl NoiseBlanker {
|
|||||||
self.threshold = threshold.max(1.0);
|
self.threshold = threshold.max(1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Process a block of IQ samples in-place, blanking impulse spikes.
|
pub fn set_profile(&mut self, profile: NoiseBlankerProfile) {
|
||||||
|
if profile != self.profile {
|
||||||
|
self.profile = profile;
|
||||||
|
self.recompute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Process a block of IQ samples in-place, blanking impulse noise.
|
||||||
pub fn process(&mut self, block: &mut [Complex<f32>]) {
|
pub fn process(&mut self, block: &mut [Complex<f32>]) {
|
||||||
if !self.enabled || block.is_empty() {
|
if !self.enabled || block.is_empty() {
|
||||||
return;
|
return;
|
||||||
@@ -62,17 +205,59 @@ impl NoiseBlanker {
|
|||||||
let thresh_sq = self.threshold * self.threshold;
|
let thresh_sq = self.threshold * self.threshold;
|
||||||
|
|
||||||
for sample in block.iter_mut() {
|
for sample in block.iter_mut() {
|
||||||
let s = *sample;
|
let x = *sample;
|
||||||
let mag_sq = s.re * s.re + s.im * s.im;
|
let mag_sq = x.re * x.re + x.im * x.im;
|
||||||
|
|
||||||
if mag_sq > thresh_sq * self.mean_sq {
|
// Look-ahead: emit the delayed sample, ingest the fresh one.
|
||||||
// Impulse detected — replace with last clean sample.
|
let y = if self.lookahead == 0 {
|
||||||
*sample = self.last_clean;
|
x
|
||||||
} else {
|
} else {
|
||||||
// Clean sample — update RMS tracker.
|
let out = self.delay[self.dpos];
|
||||||
self.mean_sq += NB_ALPHA * (mag_sq - self.mean_sq);
|
self.delay[self.dpos] = x;
|
||||||
self.last_clean = s;
|
self.dpos += 1;
|
||||||
|
if self.dpos >= self.lookahead {
|
||||||
|
self.dpos = 0;
|
||||||
|
}
|
||||||
|
out
|
||||||
|
};
|
||||||
|
|
||||||
|
// Seed the noise floor before trusting detection.
|
||||||
|
if self.seen < self.warmup {
|
||||||
|
self.seen += 1;
|
||||||
|
self.ref_sq += self.ref_alpha * (mag_sq - self.ref_sq);
|
||||||
|
if self.ref_sq < NB_MIN_REF {
|
||||||
|
self.ref_sq = NB_MIN_REF;
|
||||||
|
}
|
||||||
|
*sample = y;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Detect on the fresh sample; it reaches the output `lookahead`
|
||||||
|
// samples later, by which time the gate has closed.
|
||||||
|
if mag_sq > thresh_sq * self.ref_sq {
|
||||||
|
self.hold = self.blank_samples;
|
||||||
|
} else if self.hold == 0 {
|
||||||
|
// Update the floor only from clean, passed samples.
|
||||||
|
self.ref_sq += self.ref_alpha * (mag_sq - self.ref_sq);
|
||||||
|
if self.ref_sq < NB_MIN_REF {
|
||||||
|
self.ref_sq = NB_MIN_REF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drive the gate toward its target and apply it to the output.
|
||||||
|
let target = if self.hold > 0 {
|
||||||
|
self.hold -= 1;
|
||||||
|
0.0
|
||||||
|
} else {
|
||||||
|
1.0
|
||||||
|
};
|
||||||
|
if self.gain < target {
|
||||||
|
self.gain = (self.gain + self.ramp_step).min(target);
|
||||||
|
} else if self.gain > target {
|
||||||
|
self.gain = (self.gain - self.ramp_step).max(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
*sample = y * self.gain;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,6 +266,7 @@ impl NoiseBlanker {
|
|||||||
pub struct NoiseBlankerConfig {
|
pub struct NoiseBlankerConfig {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub threshold: f32,
|
pub threshold: f32,
|
||||||
|
pub profile: NoiseBlankerProfile,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for NoiseBlankerConfig {
|
impl Default for NoiseBlankerConfig {
|
||||||
@@ -88,6 +274,7 @@ impl Default for NoiseBlankerConfig {
|
|||||||
Self {
|
Self {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
threshold: 10.0,
|
threshold: 10.0,
|
||||||
|
profile: NoiseBlankerProfile::Spike,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -556,7 +743,7 @@ impl ChannelDsp {
|
|||||||
processing_enabled: true,
|
processing_enabled: true,
|
||||||
force_mono_pcm,
|
force_mono_pcm,
|
||||||
squelch: VirtualSquelch::new(squelch_cfg),
|
squelch: VirtualSquelch::new(squelch_cfg),
|
||||||
noise_blanker: NoiseBlanker::new(nb_cfg.enabled, nb_cfg.threshold),
|
noise_blanker: NoiseBlanker::new(nb_cfg, sdr_sample_rate),
|
||||||
last_signal_db: -120.0,
|
last_signal_db: -120.0,
|
||||||
carrier_iq_power: 0.0,
|
carrier_iq_power: 0.0,
|
||||||
carrier_attack_alpha: Self::smeter_alphas(channel_sample_rate).0,
|
carrier_attack_alpha: Self::smeter_alphas(channel_sample_rate).0,
|
||||||
@@ -577,9 +764,15 @@ impl ChannelDsp {
|
|||||||
self.squelch.set_threshold_db(threshold_db);
|
self.squelch.set_threshold_db(threshold_db);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_noise_blanker(&mut self, enabled: bool, threshold: f32) {
|
pub fn set_noise_blanker(
|
||||||
self.noise_blanker.set_enabled(enabled);
|
&mut self,
|
||||||
|
enabled: bool,
|
||||||
|
threshold: f32,
|
||||||
|
profile: NoiseBlankerProfile,
|
||||||
|
) {
|
||||||
|
self.noise_blanker.set_profile(profile);
|
||||||
self.noise_blanker.set_threshold(threshold);
|
self.noise_blanker.set_threshold(threshold);
|
||||||
|
self.noise_blanker.set_enabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_mode(&mut self, mode: &RigMode) {
|
pub fn set_mode(&mut self, mode: &RigMode) {
|
||||||
@@ -1046,30 +1239,89 @@ mod tests {
|
|||||||
assert_eq!(dsp.demodulator, Demodulator::Fm);
|
assert_eq!(dsp.demodulator, Demodulator::Fm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn nb_cfg(enabled: bool, threshold: f32, profile: NoiseBlankerProfile) -> NoiseBlankerConfig {
|
||||||
|
NoiseBlankerConfig {
|
||||||
|
enabled,
|
||||||
|
threshold,
|
||||||
|
profile,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Steady low-level signal, long enough to clear the warm-up window.
|
||||||
|
fn nb_warm(nb: &mut NoiseBlanker) {
|
||||||
|
let mut warm = vec![Complex::new(0.01, 0.01); 40_000];
|
||||||
|
nb.process(&mut warm);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn noise_blanker_suppresses_impulse() {
|
fn noise_blanker_suppresses_impulse() {
|
||||||
let mut nb = NoiseBlanker::new(true, 5.0);
|
let sr = 1_000_000;
|
||||||
// Feed a steady signal to establish the RMS baseline.
|
let mut nb = NoiseBlanker::new(nb_cfg(true, 5.0, NoiseBlankerProfile::Spike), sr);
|
||||||
let mut block: Vec<Complex<f32>> = (0..256).map(|_| Complex::new(0.01, 0.01)).collect();
|
nb_warm(&mut nb);
|
||||||
|
|
||||||
|
// One massive spike embedded in steady signal. With look-ahead the
|
||||||
|
// spike emerges at the output already gated, so *no* output sample may
|
||||||
|
// approach the raw spike power (200) — proving the leading edge did not
|
||||||
|
// leak through, which the old hold-based blanker allowed.
|
||||||
|
let mut block = vec![Complex::new(0.01, 0.01); 512];
|
||||||
|
block[200] = Complex::new(10.0, 10.0);
|
||||||
nb.process(&mut block);
|
nb.process(&mut block);
|
||||||
// Now inject a single massive spike at index 0.
|
|
||||||
let mut block2: Vec<Complex<f32>> = (0..256).map(|_| Complex::new(0.01, 0.01)).collect();
|
let peak = block
|
||||||
block2[0] = Complex::new(10.0, 10.0);
|
.iter()
|
||||||
nb.process(&mut block2);
|
.map(|s| s.re * s.re + s.im * s.im)
|
||||||
// The spike should have been blanked (replaced by last clean sample).
|
.fold(0.0f32, f32::max);
|
||||||
let mag = (block2[0].re * block2[0].re + block2[0].im * block2[0].im).sqrt();
|
assert!(peak < 1.0, "impulse leaked through, peak power {peak}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn noise_blanker_passes_strong_steady_signal() {
|
||||||
|
// A strong *continuous* tone is not impulse noise: the floor tracks it,
|
||||||
|
// so the blanker must leave it essentially untouched rather than gating
|
||||||
|
// a real signal.
|
||||||
|
let sr = 1_000_000;
|
||||||
|
let mut nb = NoiseBlanker::new(nb_cfg(true, 5.0, NoiseBlankerProfile::Spike), sr);
|
||||||
|
let mut warm = vec![Complex::new(0.5, 0.5); 40_000];
|
||||||
|
nb.process(&mut warm);
|
||||||
|
|
||||||
|
let mut block = vec![Complex::new(0.5, 0.5); 512];
|
||||||
|
nb.process(&mut block);
|
||||||
|
// Tail of the block is past all transients and should pass at unity.
|
||||||
|
let tail = block[511];
|
||||||
assert!(
|
assert!(
|
||||||
mag < 1.0,
|
(tail.re - 0.5).abs() < 1e-3 && (tail.im - 0.5).abs() < 1e-3,
|
||||||
"expected impulse to be blanked, got magnitude {}",
|
"steady signal was gated: {tail:?}"
|
||||||
mag
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn noise_blanker_disabled_passes_through() {
|
fn noise_blanker_disabled_passes_through() {
|
||||||
let mut nb = NoiseBlanker::new(false, 5.0);
|
let mut nb = NoiseBlanker::new(nb_cfg(false, 5.0, NoiseBlankerProfile::Spike), 1_000_000);
|
||||||
let mut block = vec![Complex::new(10.0, 10.0); 4];
|
let mut block = vec![Complex::new(10.0, 10.0); 4];
|
||||||
nb.process(&mut block);
|
nb.process(&mut block);
|
||||||
assert_eq!(block[0], Complex::new(10.0, 10.0));
|
assert_eq!(block[0], Complex::new(10.0, 10.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn noise_blanker_wider_profile_blanks_longer() {
|
||||||
|
// A wider profile must hold the gate closed for more samples than a
|
||||||
|
// narrow one on the same impulse.
|
||||||
|
let sr = 1_000_000;
|
||||||
|
let count_blanked = |profile| {
|
||||||
|
let mut nb = NoiseBlanker::new(nb_cfg(true, 5.0, profile), sr);
|
||||||
|
nb_warm(&mut nb);
|
||||||
|
let mut block = vec![Complex::new(0.01, 0.01); 2048];
|
||||||
|
block[100] = Complex::new(10.0, 10.0);
|
||||||
|
nb.process(&mut block);
|
||||||
|
block
|
||||||
|
.iter()
|
||||||
|
.filter(|s| s.re * s.re + s.im * s.im < 1e-6)
|
||||||
|
.count()
|
||||||
|
};
|
||||||
|
assert!(
|
||||||
|
count_blanked(NoiseBlankerProfile::Broadband)
|
||||||
|
> count_blanked(NoiseBlankerProfile::Spike),
|
||||||
|
"broadband profile should blank a wider window than spike"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ use std::sync::atomic::Ordering;
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use trx_core::radio::freq::{Band, Freq};
|
use trx_core::radio::freq::{Band, Freq};
|
||||||
use trx_core::rig::response::RigError;
|
use trx_core::rig::response::RigError;
|
||||||
use trx_core::rig::state::{RigFilterState, SpectrumData, VchanRdsEntry, WfmDenoiseLevel};
|
use trx_core::rig::state::{
|
||||||
|
effective_demod_mode, DigSidebandPolicy, NoiseBlankerProfile, RigFilterState, SpectrumData,
|
||||||
|
VchanRdsEntry, WfmDenoiseLevel,
|
||||||
|
};
|
||||||
use trx_core::rig::{
|
use trx_core::rig::{
|
||||||
AudioSource, Rig, RigAccessMethod, RigCapabilities, RigCat, RigInfo, RigSdr, RigStatusFuture,
|
AudioSource, Rig, RigAccessMethod, RigCapabilities, RigCat, RigInfo, RigSdr, RigStatusFuture,
|
||||||
};
|
};
|
||||||
@@ -73,6 +76,10 @@ pub struct SoapySdrConfig {
|
|||||||
pub nb_enabled: bool,
|
pub nb_enabled: bool,
|
||||||
/// Noise blanker impulse threshold multiplier.
|
/// Noise blanker impulse threshold multiplier.
|
||||||
pub nb_threshold: f64,
|
pub nb_threshold: f64,
|
||||||
|
/// Noise blanker tuning profile (spike/ignition/powerline/broadband).
|
||||||
|
pub nb_profile: NoiseBlankerProfile,
|
||||||
|
/// How DIG mode resolves to a sideband (auto/usb/lsb).
|
||||||
|
pub dig_sideband: DigSidebandPolicy,
|
||||||
/// FFT bin count for the spectrum display; a power of two.
|
/// FFT bin count for the spectrum display; a power of two.
|
||||||
///
|
///
|
||||||
/// Fewer bins cost less DSP and put fewer bytes on the network per frame,
|
/// Fewer bins cost less DSP and put fewer bytes on the network per frame,
|
||||||
@@ -104,6 +111,8 @@ impl Default for SoapySdrConfig {
|
|||||||
max_virtual_channels: 4,
|
max_virtual_channels: 4,
|
||||||
nb_enabled: false,
|
nb_enabled: false,
|
||||||
nb_threshold: 10.0,
|
nb_threshold: 10.0,
|
||||||
|
nb_profile: NoiseBlankerProfile::Spike,
|
||||||
|
dig_sideband: DigSidebandPolicy::Auto,
|
||||||
spectrum_fft_size: 1024,
|
spectrum_fft_size: 1024,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,10 +163,17 @@ pub struct SoapySdrRig {
|
|||||||
nb_enabled: bool,
|
nb_enabled: bool,
|
||||||
/// Noise blanker impulse threshold multiplier.
|
/// Noise blanker impulse threshold multiplier.
|
||||||
nb_threshold: f64,
|
nb_threshold: f64,
|
||||||
|
/// Noise blanker tuning profile on the primary channel.
|
||||||
|
nb_profile: NoiseBlankerProfile,
|
||||||
/// Hidden AIS decoder channels (A and B) when available.
|
/// Hidden AIS decoder channels (A and B) when available.
|
||||||
ais_channel_indices: Option<(usize, usize)>,
|
ais_channel_indices: Option<(usize, usize)>,
|
||||||
/// Virtual channel manager shared with external consumers (e.g. RigHandle).
|
/// Virtual channel manager shared with external consumers (e.g. RigHandle).
|
||||||
|
/// Also owns the shared DIG-sideband policy.
|
||||||
channel_manager: Arc<vchan_impl::SdrVirtualChannelManager>,
|
channel_manager: Arc<vchan_impl::SdrVirtualChannelManager>,
|
||||||
|
/// Concrete demodulation mode last pushed to the primary channel DSP. For
|
||||||
|
/// DIG this is the resolved USB/LSB; used to avoid rebuilding filters on
|
||||||
|
/// every tune step when the resolved sideband hasn't actually changed.
|
||||||
|
applied_primary_mode: RigMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SoapySdrRig {
|
impl SoapySdrRig {
|
||||||
@@ -200,6 +216,8 @@ impl SoapySdrRig {
|
|||||||
let max_virtual_channels = config.max_virtual_channels;
|
let max_virtual_channels = config.max_virtual_channels;
|
||||||
let nb_enabled = config.nb_enabled;
|
let nb_enabled = config.nb_enabled;
|
||||||
let nb_threshold = config.nb_threshold;
|
let nb_threshold = config.nb_threshold;
|
||||||
|
let nb_profile = config.nb_profile;
|
||||||
|
let dig_sideband = config.dig_sideband;
|
||||||
let spectrum_fft_size = config.spectrum_fft_size;
|
let spectrum_fft_size = config.spectrum_fft_size;
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
"initialising SoapySDR backend (args={:?}, gain_mode={:?}, gain_db={}, max_gain_db={:?})",
|
"initialising SoapySDR backend (args={:?}, gain_mode={:?}, gain_db={}, max_gain_db={:?})",
|
||||||
@@ -298,6 +316,7 @@ impl SoapySdrRig {
|
|||||||
dsp::NoiseBlankerConfig {
|
dsp::NoiseBlankerConfig {
|
||||||
enabled: nb_enabled,
|
enabled: nb_enabled,
|
||||||
threshold: nb_threshold as f32,
|
threshold: nb_threshold as f32,
|
||||||
|
profile: nb_profile,
|
||||||
},
|
},
|
||||||
&all_channels,
|
&all_channels,
|
||||||
spectrum_fft_size,
|
spectrum_fft_size,
|
||||||
@@ -364,8 +383,16 @@ impl SoapySdrRig {
|
|||||||
pipeline.clone(),
|
pipeline.clone(),
|
||||||
fixed_slot_count,
|
fixed_slot_count,
|
||||||
max_virtual_channels,
|
max_virtual_channels,
|
||||||
|
dig_sideband,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// Concrete demod mode the primary channel starts in. For DIG this
|
||||||
|
// resolves the configured sideband policy against the initial dial
|
||||||
|
// frequency so the very first image/audio uses the right sideband.
|
||||||
|
let initial_primary_mode =
|
||||||
|
effective_demod_mode(&initial_mode, dig_sideband, initial_freq.hz);
|
||||||
|
let initial_is_dig = initial_mode == RigMode::DIG;
|
||||||
|
|
||||||
let rig = Self {
|
let rig = Self {
|
||||||
info,
|
info,
|
||||||
freq: initial_freq,
|
freq: initial_freq,
|
||||||
@@ -390,9 +417,20 @@ impl SoapySdrRig {
|
|||||||
squelch_threshold_db,
|
squelch_threshold_db,
|
||||||
nb_enabled,
|
nb_enabled,
|
||||||
nb_threshold,
|
nb_threshold,
|
||||||
|
nb_profile,
|
||||||
ais_channel_indices: Some((primary_channel_count, primary_channel_count + 1)),
|
ais_channel_indices: Some((primary_channel_count, primary_channel_count + 1)),
|
||||||
channel_manager,
|
channel_manager,
|
||||||
|
applied_primary_mode: initial_primary_mode.clone(),
|
||||||
};
|
};
|
||||||
|
// If the primary channel starts in DIG, its DSP was created with the
|
||||||
|
// logical DIG demodulator (upper sideband); push the resolved sideband
|
||||||
|
// so an Auto/LSB start is honoured immediately.
|
||||||
|
if initial_is_dig {
|
||||||
|
let dsps = rig.pipeline.channel_dsps.read().unwrap();
|
||||||
|
if let Some(dsp_arc) = dsps.get(rig.primary_channel_idx) {
|
||||||
|
dsp_arc.lock().unwrap().set_mode(&initial_primary_mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
rig.apply_ais_channel_activity();
|
rig.apply_ais_channel_activity();
|
||||||
Ok(rig)
|
Ok(rig)
|
||||||
}
|
}
|
||||||
@@ -448,6 +486,8 @@ impl SoapySdrRig {
|
|||||||
max_virtual_channels,
|
max_virtual_channels,
|
||||||
nb_enabled,
|
nb_enabled,
|
||||||
nb_threshold,
|
nb_threshold,
|
||||||
|
nb_profile: NoiseBlankerProfile::default(),
|
||||||
|
dig_sideband: DigSidebandPolicy::default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -619,6 +659,21 @@ impl RigCat for SoapySdrRig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// In DIG/Auto, tuning across the 10 MHz boundary flips the
|
||||||
|
// sideband. Rebuild the demodulator only when it actually changes,
|
||||||
|
// so ordinary tuning stays glitch-free.
|
||||||
|
if self.mode == RigMode::DIG {
|
||||||
|
let effective = self.channel_manager.dig_policy().resolve(self.freq.hz);
|
||||||
|
if effective != self.applied_primary_mode {
|
||||||
|
let dsps = self.pipeline.channel_dsps.read().unwrap();
|
||||||
|
if let Some(dsp_arc) = dsps.get(self.primary_channel_idx) {
|
||||||
|
let mut dsp = dsp_arc.lock().unwrap();
|
||||||
|
dsp.set_mode(&effective);
|
||||||
|
dsp.set_filter(self.bandwidth_hz);
|
||||||
|
}
|
||||||
|
self.applied_primary_mode = effective;
|
||||||
|
}
|
||||||
|
}
|
||||||
self.update_ais_channel_offsets();
|
self.update_ais_channel_offsets();
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
@@ -632,12 +687,18 @@ impl RigCat for SoapySdrRig {
|
|||||||
tracing::debug!("SoapySdrRig: set_mode -> {:?}", mode);
|
tracing::debug!("SoapySdrRig: set_mode -> {:?}", mode);
|
||||||
self.mode = mode.clone();
|
self.mode = mode.clone();
|
||||||
self.bandwidth_hz = Self::default_bandwidth_for_mode(&mode);
|
self.bandwidth_hz = Self::default_bandwidth_for_mode(&mode);
|
||||||
|
// DIG carries no inherent sideband: resolve it to a concrete
|
||||||
|
// USB/LSB demodulator from the policy + dial frequency. The logical
|
||||||
|
// DIG mode is kept in `self.mode` (and RigState) for display.
|
||||||
|
let effective =
|
||||||
|
effective_demod_mode(&self.mode, self.channel_manager.dig_policy(), self.freq.hz);
|
||||||
|
self.applied_primary_mode = effective.clone();
|
||||||
// Update the primary channel's demodulator in the live pipeline.
|
// Update the primary channel's demodulator in the live pipeline.
|
||||||
{
|
{
|
||||||
let dsps = self.pipeline.channel_dsps.read().unwrap();
|
let dsps = self.pipeline.channel_dsps.read().unwrap();
|
||||||
if let Some(dsp_arc) = dsps.get(self.primary_channel_idx) {
|
if let Some(dsp_arc) = dsps.get(self.primary_channel_idx) {
|
||||||
let mut dsp = dsp_arc.lock().unwrap();
|
let mut dsp = dsp_arc.lock().unwrap();
|
||||||
dsp.set_mode(&mode);
|
dsp.set_mode(&effective);
|
||||||
dsp.set_filter(self.bandwidth_hz);
|
dsp.set_filter(self.bandwidth_hz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -933,6 +994,7 @@ impl RigSdr for SoapySdrRig {
|
|||||||
&'a mut self,
|
&'a mut self,
|
||||||
enabled: bool,
|
enabled: bool,
|
||||||
threshold: f64,
|
threshold: f64,
|
||||||
|
profile: NoiseBlankerProfile,
|
||||||
) -> Pin<Box<dyn std::future::Future<Output = DynResult<()>> + Send + 'a>> {
|
) -> Pin<Box<dyn std::future::Future<Output = DynResult<()>> + Send + 'a>> {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
if !threshold.is_finite() {
|
if !threshold.is_finite() {
|
||||||
@@ -943,13 +1005,38 @@ impl RigSdr for SoapySdrRig {
|
|||||||
}
|
}
|
||||||
self.nb_enabled = enabled;
|
self.nb_enabled = enabled;
|
||||||
self.nb_threshold = threshold;
|
self.nb_threshold = threshold;
|
||||||
|
self.nb_profile = profile;
|
||||||
{
|
{
|
||||||
let dsps = self.pipeline.channel_dsps.read().unwrap();
|
let dsps = self.pipeline.channel_dsps.read().unwrap();
|
||||||
if let Some(dsp_arc) = dsps.get(self.primary_channel_idx) {
|
if let Some(dsp_arc) = dsps.get(self.primary_channel_idx) {
|
||||||
dsp_arc
|
dsp_arc
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_noise_blanker(enabled, threshold as f32);
|
.set_noise_blanker(enabled, threshold as f32, profile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_sdr_dig_sideband<'a>(
|
||||||
|
&'a mut self,
|
||||||
|
policy: DigSidebandPolicy,
|
||||||
|
) -> Pin<Box<dyn std::future::Future<Output = DynResult<()>> + Send + 'a>> {
|
||||||
|
Box::pin(async move {
|
||||||
|
// Update the shared policy (also re-resolves DIG virtual channels).
|
||||||
|
self.channel_manager.set_dig_policy(policy);
|
||||||
|
// Re-apply to the primary channel when it is currently DIG.
|
||||||
|
if self.mode == RigMode::DIG {
|
||||||
|
let effective = policy.resolve(self.freq.hz);
|
||||||
|
if effective != self.applied_primary_mode {
|
||||||
|
let dsps = self.pipeline.channel_dsps.read().unwrap();
|
||||||
|
if let Some(dsp_arc) = dsps.get(self.primary_channel_idx) {
|
||||||
|
let mut dsp = dsp_arc.lock().unwrap();
|
||||||
|
dsp.set_mode(&effective);
|
||||||
|
dsp.set_filter(self.bandwidth_hz);
|
||||||
|
}
|
||||||
|
self.applied_primary_mode = effective;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -1049,6 +1136,8 @@ impl RigSdr for SoapySdrRig {
|
|||||||
sdr_squelch_threshold_db: Some(self.squelch_threshold_db as f64),
|
sdr_squelch_threshold_db: Some(self.squelch_threshold_db as f64),
|
||||||
sdr_nb_enabled: Some(self.nb_enabled),
|
sdr_nb_enabled: Some(self.nb_enabled),
|
||||||
sdr_nb_threshold: Some(self.nb_threshold),
|
sdr_nb_threshold: Some(self.nb_threshold),
|
||||||
|
sdr_nb_profile: Some(self.nb_profile),
|
||||||
|
sdr_dig_sideband: Some(self.channel_manager.dig_policy()),
|
||||||
wfm_deemphasis_us: self.wfm_deemphasis_us,
|
wfm_deemphasis_us: self.wfm_deemphasis_us,
|
||||||
wfm_stereo: self.wfm_stereo,
|
wfm_stereo: self.wfm_stereo,
|
||||||
wfm_stereo_detected,
|
wfm_stereo_detected,
|
||||||
|
|||||||
@@ -22,12 +22,12 @@
|
|||||||
//! updates every `ChannelDsp` in place and pauses out-of-span channels instead
|
//! updates every `ChannelDsp` in place and pauses out-of-span channels instead
|
||||||
//! of destroying them.
|
//! of destroying them.
|
||||||
|
|
||||||
use std::sync::atomic::{AtomicI64, Ordering};
|
use std::sync::atomic::{AtomicI64, AtomicU8, Ordering};
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
use num_complex::Complex;
|
use num_complex::Complex;
|
||||||
use tokio::sync::broadcast;
|
use tokio::sync::broadcast;
|
||||||
use trx_core::rig::state::{RigMode, VchanRdsEntry};
|
use trx_core::rig::state::{effective_demod_mode, DigSidebandPolicy, RigMode, VchanRdsEntry};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::dsp::SdrPipeline;
|
use crate::dsp::SdrPipeline;
|
||||||
@@ -59,7 +59,12 @@ fn default_bandwidth_hz(mode: &RigMode) -> u32 {
|
|||||||
struct ManagedChannel {
|
struct ManagedChannel {
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
freq_hz: u64,
|
freq_hz: u64,
|
||||||
|
/// Logical mode requested by the user (e.g. `DIG`), shown in listings.
|
||||||
mode: RigMode,
|
mode: RigMode,
|
||||||
|
/// Concrete demod mode last pushed to the DSP. For `DIG` this is the
|
||||||
|
/// resolved USB/LSB; tracked so a frequency change only rebuilds the
|
||||||
|
/// demodulator when the resolved sideband actually flips.
|
||||||
|
applied_mode: RigMode,
|
||||||
/// `broadcast::Sender` kept alive so new subscribers can join at any time.
|
/// `broadcast::Sender` kept alive so new subscribers can join at any time.
|
||||||
pcm_tx: broadcast::Sender<Vec<f32>>,
|
pcm_tx: broadcast::Sender<Vec<f32>>,
|
||||||
/// IQ tap sender (kept alive; external consumers may subscribe).
|
/// IQ tap sender (kept alive; external consumers may subscribe).
|
||||||
@@ -91,6 +96,9 @@ pub struct SdrVirtualChannelManager {
|
|||||||
channels: RwLock<Vec<ManagedChannel>>,
|
channels: RwLock<Vec<ManagedChannel>>,
|
||||||
/// Fires whenever a channel is explicitly destroyed.
|
/// Fires whenever a channel is explicitly destroyed.
|
||||||
destroyed_tx: broadcast::Sender<Uuid>,
|
destroyed_tx: broadcast::Sender<Uuid>,
|
||||||
|
/// Shared DIG-sideband policy ([`DigSidebandPolicy`] encoded via `to_u8`).
|
||||||
|
/// Read when resolving any DIG channel's demodulator.
|
||||||
|
dig_sideband: AtomicU8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SdrVirtualChannelManager {
|
impl SdrVirtualChannelManager {
|
||||||
@@ -100,7 +108,12 @@ impl SdrVirtualChannelManager {
|
|||||||
/// - `fixed_slot_count`: number of fixed pipeline slots (primary + AIS),
|
/// - `fixed_slot_count`: number of fixed pipeline slots (primary + AIS),
|
||||||
/// i.e. the index of the first slot available for virtual channels.
|
/// i.e. the index of the first slot available for virtual channels.
|
||||||
/// - `max_total`: maximum total channels including primary (e.g. 4).
|
/// - `max_total`: maximum total channels including primary (e.g. 4).
|
||||||
pub fn new(pipeline: Arc<SdrPipeline>, fixed_slot_count: usize, max_total: usize) -> Self {
|
pub fn new(
|
||||||
|
pipeline: Arc<SdrPipeline>,
|
||||||
|
fixed_slot_count: usize,
|
||||||
|
max_total: usize,
|
||||||
|
dig_sideband: DigSidebandPolicy,
|
||||||
|
) -> Self {
|
||||||
// Seed the channel list with a synthetic primary-channel entry.
|
// Seed the channel list with a synthetic primary-channel entry.
|
||||||
// We use the first PCM sender from the pipeline (index 0).
|
// We use the first PCM sender from the pipeline (index 0).
|
||||||
let primary_pcm_tx = pipeline
|
let primary_pcm_tx = pipeline
|
||||||
@@ -118,6 +131,7 @@ impl SdrVirtualChannelManager {
|
|||||||
id: Uuid::new_v4(),
|
id: Uuid::new_v4(),
|
||||||
freq_hz: 0, // actual freq kept by SoapySdrRig; manager treats ch-0 as opaque
|
freq_hz: 0, // actual freq kept by SoapySdrRig; manager treats ch-0 as opaque
|
||||||
mode: RigMode::USB,
|
mode: RigMode::USB,
|
||||||
|
applied_mode: RigMode::USB,
|
||||||
pcm_tx: primary_pcm_tx,
|
pcm_tx: primary_pcm_tx,
|
||||||
iq_tx: primary_iq_tx,
|
iq_tx: primary_iq_tx,
|
||||||
pipeline_slot: 0,
|
pipeline_slot: 0,
|
||||||
@@ -134,6 +148,7 @@ impl SdrVirtualChannelManager {
|
|||||||
max_total: max_total.max(1),
|
max_total: max_total.max(1),
|
||||||
channels: RwLock::new(vec![primary]),
|
channels: RwLock::new(vec![primary]),
|
||||||
destroyed_tx,
|
destroyed_tx,
|
||||||
|
dig_sideband: AtomicU8::new(dig_sideband.to_u8()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,6 +156,36 @@ impl SdrVirtualChannelManager {
|
|||||||
self.destroyed_tx.clone()
|
self.destroyed_tx.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Current shared DIG-sideband policy.
|
||||||
|
pub fn dig_policy(&self) -> DigSidebandPolicy {
|
||||||
|
DigSidebandPolicy::from_u8(self.dig_sideband.load(Ordering::Relaxed))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update the shared DIG-sideband policy and re-resolve every DIG virtual
|
||||||
|
/// channel's demodulator (the primary channel is handled by `SoapySdrRig`).
|
||||||
|
pub fn set_dig_policy(&self, policy: DigSidebandPolicy) {
|
||||||
|
self.dig_sideband.store(policy.to_u8(), Ordering::Relaxed);
|
||||||
|
let mut channels = self.channels.write().unwrap();
|
||||||
|
let dsps = self.pipeline.channel_dsps.read().unwrap();
|
||||||
|
for ch in channels
|
||||||
|
.iter_mut()
|
||||||
|
.filter(|c| !c.permanent && c.mode == RigMode::DIG)
|
||||||
|
{
|
||||||
|
let effective = policy.resolve(ch.freq_hz);
|
||||||
|
if effective != ch.applied_mode {
|
||||||
|
ch.applied_mode = effective.clone();
|
||||||
|
if let Some(dsp_arc) = dsps.get(ch.pipeline_slot) {
|
||||||
|
dsp_arc.lock().unwrap().set_mode(&effective);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Resolve a channel's effective demod mode under the current policy.
|
||||||
|
fn resolve_mode(&self, logical: &RigMode, freq_hz: u64) -> RigMode {
|
||||||
|
effective_demod_mode(logical, self.dig_policy(), freq_hz)
|
||||||
|
}
|
||||||
|
|
||||||
fn half_span_hz(&self) -> i64 {
|
fn half_span_hz(&self) -> i64 {
|
||||||
i64::from(self.pipeline.sdr_sample_rate) / 2
|
i64::from(self.pipeline.sdr_sample_rate) / 2
|
||||||
}
|
}
|
||||||
@@ -172,10 +217,13 @@ impl SdrVirtualChannelManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bandwidth follows the logical mode; the DSP demodulator follows the
|
||||||
|
// resolved sideband (DIG → USB/LSB by policy + frequency).
|
||||||
let bandwidth_hz = default_bandwidth_hz(mode);
|
let bandwidth_hz = default_bandwidth_hz(mode);
|
||||||
let (pcm_tx, iq_tx) = self
|
let applied_mode = self.resolve_mode(mode, freq_hz);
|
||||||
.pipeline
|
let (pcm_tx, iq_tx) =
|
||||||
.add_virtual_channel(if_hz as f64, mode, bandwidth_hz);
|
self.pipeline
|
||||||
|
.add_virtual_channel(if_hz as f64, &applied_mode, bandwidth_hz);
|
||||||
|
|
||||||
let pipeline_slot = self
|
let pipeline_slot = self
|
||||||
.pipeline
|
.pipeline
|
||||||
@@ -190,6 +238,7 @@ impl SdrVirtualChannelManager {
|
|||||||
id,
|
id,
|
||||||
freq_hz,
|
freq_hz,
|
||||||
mode: mode.clone(),
|
mode: mode.clone(),
|
||||||
|
applied_mode,
|
||||||
pcm_tx,
|
pcm_tx,
|
||||||
iq_tx,
|
iq_tx,
|
||||||
pipeline_slot,
|
pipeline_slot,
|
||||||
@@ -314,9 +363,18 @@ impl VirtualChannelManager for SdrVirtualChannelManager {
|
|||||||
.ok_or(VChanError::NotFound)?;
|
.ok_or(VChanError::NotFound)?;
|
||||||
|
|
||||||
ch.freq_hz = freq_hz;
|
ch.freq_hz = freq_hz;
|
||||||
|
// A DIG/Auto channel flips sideband across the 10 MHz boundary; rebuild
|
||||||
|
// the demodulator only when the resolved sideband actually changes.
|
||||||
|
let effective = self.resolve_mode(&ch.mode, freq_hz);
|
||||||
|
let mode_changed = effective != ch.applied_mode;
|
||||||
|
ch.applied_mode = effective.clone();
|
||||||
let dsps = self.pipeline.channel_dsps.read().unwrap();
|
let dsps = self.pipeline.channel_dsps.read().unwrap();
|
||||||
if let Some(dsp_arc) = dsps.get(ch.pipeline_slot) {
|
if let Some(dsp_arc) = dsps.get(ch.pipeline_slot) {
|
||||||
dsp_arc.lock().unwrap().set_channel_if_hz(if_hz as f64);
|
let mut dsp = dsp_arc.lock().unwrap();
|
||||||
|
dsp.set_channel_if_hz(if_hz as f64);
|
||||||
|
if mode_changed {
|
||||||
|
dsp.set_mode(&effective);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -329,9 +387,11 @@ impl VirtualChannelManager for SdrVirtualChannelManager {
|
|||||||
.ok_or(VChanError::NotFound)?;
|
.ok_or(VChanError::NotFound)?;
|
||||||
|
|
||||||
ch.mode = mode.clone();
|
ch.mode = mode.clone();
|
||||||
|
let effective = self.resolve_mode(mode, ch.freq_hz);
|
||||||
|
ch.applied_mode = effective.clone();
|
||||||
let dsps = self.pipeline.channel_dsps.read().unwrap();
|
let dsps = self.pipeline.channel_dsps.read().unwrap();
|
||||||
if let Some(dsp_arc) = dsps.get(ch.pipeline_slot) {
|
if let Some(dsp_arc) = dsps.get(ch.pipeline_slot) {
|
||||||
dsp_arc.lock().unwrap().set_mode(mode);
|
dsp_arc.lock().unwrap().set_mode(&effective);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -425,6 +485,7 @@ impl VirtualChannelManager for SdrVirtualChannelManager {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::demod::Demodulator;
|
||||||
use crate::dsp::{MockIqSource, NoiseBlankerConfig, SdrPipeline};
|
use crate::dsp::{MockIqSource, NoiseBlankerConfig, SdrPipeline};
|
||||||
|
|
||||||
fn make_pipeline() -> Arc<SdrPipeline> {
|
fn make_pipeline() -> Arc<SdrPipeline> {
|
||||||
@@ -446,7 +507,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn add_and_list() {
|
fn add_and_list() {
|
||||||
let p = make_pipeline();
|
let p = make_pipeline();
|
||||||
let mgr = SdrVirtualChannelManager::new(p, 1, 4);
|
let mgr = SdrVirtualChannelManager::new(p, 1, 4, DigSidebandPolicy::Auto);
|
||||||
// Set center to 14.1 MHz so that 14.074 MHz is within ±960 kHz.
|
// Set center to 14.1 MHz so that 14.074 MHz is within ±960 kHz.
|
||||||
mgr.update_center_hz(14_100_000);
|
mgr.update_center_hz(14_100_000);
|
||||||
assert_eq!(mgr.channels().len(), 1); // primary only
|
assert_eq!(mgr.channels().len(), 1); // primary only
|
||||||
@@ -462,7 +523,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn remove_virtual_channel() {
|
fn remove_virtual_channel() {
|
||||||
let p = make_pipeline();
|
let p = make_pipeline();
|
||||||
let mgr = SdrVirtualChannelManager::new(p, 1, 4);
|
let mgr = SdrVirtualChannelManager::new(p, 1, 4, DigSidebandPolicy::Auto);
|
||||||
mgr.update_center_hz(14_100_000);
|
mgr.update_center_hz(14_100_000);
|
||||||
let (id, _) = mgr.add_channel(14_074_000, &RigMode::USB).unwrap();
|
let (id, _) = mgr.add_channel(14_074_000, &RigMode::USB).unwrap();
|
||||||
mgr.remove_channel(id).unwrap();
|
mgr.remove_channel(id).unwrap();
|
||||||
@@ -472,7 +533,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn cannot_remove_primary() {
|
fn cannot_remove_primary() {
|
||||||
let p = make_pipeline();
|
let p = make_pipeline();
|
||||||
let mgr = SdrVirtualChannelManager::new(p, 1, 4);
|
let mgr = SdrVirtualChannelManager::new(p, 1, 4, DigSidebandPolicy::Auto);
|
||||||
let primary_id = mgr.channels()[0].id;
|
let primary_id = mgr.channels()[0].id;
|
||||||
let err = mgr.remove_channel(primary_id).unwrap_err();
|
let err = mgr.remove_channel(primary_id).unwrap_err();
|
||||||
assert!(matches!(err, VChanError::Permanent));
|
assert!(matches!(err, VChanError::Permanent));
|
||||||
@@ -481,7 +542,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn cap_enforced() {
|
fn cap_enforced() {
|
||||||
let p = make_pipeline();
|
let p = make_pipeline();
|
||||||
let mgr = SdrVirtualChannelManager::new(p, 1, 2); // primary + 1 virtual max
|
let mgr = SdrVirtualChannelManager::new(p, 1, 2, DigSidebandPolicy::Auto); // primary + 1 virtual max
|
||||||
mgr.update_center_hz(14_100_000);
|
mgr.update_center_hz(14_100_000);
|
||||||
mgr.add_channel(14_074_000, &RigMode::USB).unwrap();
|
mgr.add_channel(14_074_000, &RigMode::USB).unwrap();
|
||||||
let err = mgr.add_channel(14_075_000, &RigMode::USB).unwrap_err();
|
let err = mgr.add_channel(14_075_000, &RigMode::USB).unwrap_err();
|
||||||
@@ -491,7 +552,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn out_of_bandwidth() {
|
fn out_of_bandwidth() {
|
||||||
let p = make_pipeline();
|
let p = make_pipeline();
|
||||||
let mgr = SdrVirtualChannelManager::new(p, 1, 4);
|
let mgr = SdrVirtualChannelManager::new(p, 1, 4, DigSidebandPolicy::Auto);
|
||||||
// center_hz = 0, half_span = 960_000 Hz — 10 MHz is way out
|
// center_hz = 0, half_span = 960_000 Hz — 10 MHz is way out
|
||||||
let err = mgr.add_channel(10_000_000, &RigMode::USB).unwrap_err();
|
let err = mgr.add_channel(10_000_000, &RigMode::USB).unwrap_err();
|
||||||
assert!(matches!(err, VChanError::OutOfBandwidth { .. }));
|
assert!(matches!(err, VChanError::OutOfBandwidth { .. }));
|
||||||
@@ -500,7 +561,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn hidden_background_channels_are_outside_visible_cap() {
|
fn hidden_background_channels_are_outside_visible_cap() {
|
||||||
let p = make_pipeline();
|
let p = make_pipeline();
|
||||||
let mgr = SdrVirtualChannelManager::new(p, 1, 2); // primary + 1 visible max
|
let mgr = SdrVirtualChannelManager::new(p, 1, 2, DigSidebandPolicy::Auto); // primary + 1 visible max
|
||||||
mgr.update_center_hz(14_100_000);
|
mgr.update_center_hz(14_100_000);
|
||||||
|
|
||||||
mgr.add_channel(14_074_000, &RigMode::USB).unwrap();
|
mgr.add_channel(14_074_000, &RigMode::USB).unwrap();
|
||||||
@@ -513,10 +574,46 @@ mod tests {
|
|||||||
assert!(visible.iter().all(|channel| channel.id != hidden_id));
|
assert!(visible.iter().all(|channel| channel.id != hidden_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn dig_channel_resolves_sideband_and_tracks_policy() {
|
||||||
|
let p = make_pipeline();
|
||||||
|
let mgr = SdrVirtualChannelManager::new(p.clone(), 1, 6, DigSidebandPolicy::Auto);
|
||||||
|
mgr.update_center_hz(7_100_000);
|
||||||
|
|
||||||
|
// The virtual channel occupies pipeline slot 1 (slot 0 is the primary).
|
||||||
|
let demod_at_slot1 = || {
|
||||||
|
p.channel_dsps.read().unwrap()[1]
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.demodulator
|
||||||
|
.clone()
|
||||||
|
};
|
||||||
|
|
||||||
|
// DIG below 10 MHz under Auto → lower sideband.
|
||||||
|
let (_id, _rx) = mgr.add_channel(7_074_000, &RigMode::DIG).unwrap();
|
||||||
|
assert_eq!(demod_at_slot1(), Demodulator::Lsb);
|
||||||
|
|
||||||
|
// Forcing USB re-resolves the live channel.
|
||||||
|
mgr.set_dig_policy(DigSidebandPolicy::Usb);
|
||||||
|
assert_eq!(demod_at_slot1(), Demodulator::Usb);
|
||||||
|
|
||||||
|
// Back to Auto (still below 10 MHz) → lower sideband again.
|
||||||
|
mgr.set_dig_policy(DigSidebandPolicy::Auto);
|
||||||
|
assert_eq!(demod_at_slot1(), Demodulator::Lsb);
|
||||||
|
|
||||||
|
// The listing keeps the logical DIG mode for display.
|
||||||
|
let ch = mgr
|
||||||
|
.channels()
|
||||||
|
.into_iter()
|
||||||
|
.find(|c| !c.permanent)
|
||||||
|
.expect("virtual channel");
|
||||||
|
assert_eq!(ch.mode, "DIG");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn retune_keeps_virtual_channel_allocated() {
|
fn retune_keeps_virtual_channel_allocated() {
|
||||||
let p = make_pipeline();
|
let p = make_pipeline();
|
||||||
let mgr = SdrVirtualChannelManager::new(p, 1, 4);
|
let mgr = SdrVirtualChannelManager::new(p, 1, 4, DigSidebandPolicy::Auto);
|
||||||
mgr.update_center_hz(14_100_000);
|
mgr.update_center_hz(14_100_000);
|
||||||
let mut destroyed_rx = mgr.subscribe_destroyed();
|
let mut destroyed_rx = mgr.subscribe_destroyed();
|
||||||
|
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ sample_rate = 1920000
|
|||||||
bandwidth = 1500000
|
bandwidth = 1500000
|
||||||
wfm_deemphasis_us = 50
|
wfm_deemphasis_us = 50
|
||||||
center_offset_hz = 100000
|
center_offset_hz = 100000
|
||||||
|
dig_sideband = "auto"
|
||||||
channels = []
|
channels = []
|
||||||
max_virtual_channels = 4
|
max_virtual_channels = 4
|
||||||
spectrum_fft_size = 1024
|
spectrum_fft_size = 1024
|
||||||
@@ -139,6 +140,7 @@ tail_ms = 180
|
|||||||
[trx-server.sdr.noise_blanker]
|
[trx-server.sdr.noise_blanker]
|
||||||
enabled = false
|
enabled = false
|
||||||
threshold = 10.0
|
threshold = 10.0
|
||||||
|
profile = "spike"
|
||||||
|
|
||||||
# Timeout and buffer tuning. The defaults suit most setups.
|
# Timeout and buffer tuning. The defaults suit most setups.
|
||||||
[trx-server.timeouts]
|
[trx-server.timeouts]
|
||||||
|
|||||||
Reference in New Issue
Block a user