Skip to content

Commit eb4a14e

Browse files
authored
Merge pull request #1 from ExpressLRS/rfmeter-package
Rfmeter package
2 parents 3c8f01e + 968751f commit eb4a14e

12 files changed

Lines changed: 733 additions & 307 deletions

File tree

.github/workflows/lint.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
ruff:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v5
12+
- uses: astral-sh/setup-uv@v6
13+
- run: uv sync
14+
- run: uv run ruff check rfmeter/
15+
- run: uv run ruff format --check rfmeter/

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ ipython_config.py
8585
.venv
8686

8787
.idea
88-
logs/*.csv
88+
logs/**/*.csv
8989

9090
# pyenv
9191
# For a library or package, you might want to ignore these files since the code is

README.md

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,81 +4,92 @@ RfPowerMeter is an open-source toolkit for logging and visualizing RF power meas
44

55
Developed and maintained by **ExpressLRS LLC** and its passionate open source community, working together to advance reliable, high-performance radio control technology.
66

7-
# Before use:
7+
## Setup
88

9-
install `uv` python package manager: https://docs.astral.sh/uv/getting-started/installation/
10-
11-
install the required libraries
12-
13-
```uv sync```
14-
15-
# RF Meter Logger (rf_meter_logger.py)
16-
17-
A Python script to log the measured values from a ImmersionRC RF meter v2, saving the results to a timestamped CSV file.
18-
19-
## Usage
20-
If you run the script without any arguments, it will display usage instructions, the list of supported frequencies, and available serial ports.
9+
Install [uv](https://docs.astral.sh/uv/getting-started/installation/), then:
2110

2211
```bash
23-
uv run rf_meter_logger.py <serial_port> <frequency> [attenuation]
12+
uv sync
2413
```
2514

26-
- `<serial_port>`: The serial port to connect to (e.g., `COM3` on Windows or `/dev/ttyUSB0` on Linux/Mac).
27-
- `<frequency>`: Frequency in MHz. Must be one of the supported values (see below).
28-
- `[attenuation]`: (Optional) Attenuation value to add to dBm readings (float).
15+
## Usage
2916

30-
### Examples
17+
### Record measurements
3118

3219
```bash
33-
uv run rf_meter_logger.py COM3 900
34-
uv run rf_meter_logger.py /dev/ttyUSB0 2400 10.5
20+
rfmeter record --group <group> --test <test> --freq <frequency> [--port <port>] [--attenuation <value>] [--duration <duration>]
3521
```
3622

37-
## Supported Frequencies
38-
- 35, 72, 433, 868, 900, 1200, 2400, 5600, 5650, 5700, 5750, 5800, 5850, 5900, 5950, 6000 (MHz)
23+
- `--group`, `-g`: Test group folder name (e.g. `zerodrag`). Creates `logs/<group>/` directory automatically.
24+
- `--test`, `-t`: Test name (e.g. `868_ant_a`). Used in the output filename.
25+
- `--freq`, `-f`: Frequency in MHz. Must be one of the supported values (see below).
26+
- `--port`, `-p`: Serial port (e.g. `/dev/ttyUSB0`, `COM3`). Auto-detects if only one device is connected.
27+
- `--attenuation`, `-a`: dBm offset to add to readings (default: 0.0).
28+
- `--duration`, `-d`: Recording duration (e.g. `30s`, `30m`, `2h`, `1h30m`). Runs indefinitely if omitted.
3929

40-
## Output
41-
- The script creates a CSV file named with the current date and time (e.g., `250417-235849.csv`).
42-
- Each line in the CSV contains:
43-
`timestamp (ms), dBm, mW`
30+
Output file: `logs/<group>/<test>_<YYMMDD-HHMMSS>.csv`
4431

45-
## Troubleshooting
46-
- If you see "No serial ports found," check your device connection and permissions.
47-
- If you get a serial error, ensure the port is correct and not in use by another application.
32+
#### Examples
4833

34+
```bash
35+
# Auto-detect port, record at 868 MHz
36+
rfmeter record --group zerodrag --test 868_ant_a --freq 868
4937

50-
# RF Power Logger Plotter (plot_powers.py)
38+
# Record for 30 minutes
39+
rfmeter record -g zerodrag -t 868_ant_a -f 868 -d 30m
5140

52-
This script visualizes RF power data from a CSV file (generated from rf_meter_logger.py), providing both raw and moving average plots for dBm and mW values.
41+
# Specify port and attenuation
42+
rfmeter record -g zerodrag -t 868_ant_a -f 868 -p /dev/ttyUSB0 -a 10.5
43+
```
5344

54-
## Features
55-
- Reads CSV files with columns: timestamp (ms), RF power (dBm), RF power (mW)
56-
- Optionally applies a correction offset to dBm values (e.g., for compensation of the RF meter)
57-
- Filters to the first hour of data (≤ 3,600,000 ms)
58-
- Excludes the lowest 1% of data (outliers) for both dBm and mW
59-
- Generates two subplots: one for dBm, one for mW
45+
### Plot measurements
6046

61-
## Usage
6247
```bash
63-
uv run plot_powers.py <csv_file> [correction]
48+
rfmeter plot [<csv_file>] [--group <group>] [--test <test>] [--correction <value>] [--max-time <minutes>] [--outlier-percentile <value>] [--window-size <size>]
6449
```
6550

66-
- `<csv_file>`: Path to the CSV file to plot. The file should have three columns: timestamp in ms, RF power (dBm), RF power (mW), **without a header row**.
67-
- `[correction]` (optional): A numeric value (float) to add to all dBm readings (e.g., for calibration).
51+
- `csv_file`: Path to CSV file. Optional — if omitted, auto-finds the latest recording.
52+
- `--group`, `-g`: Filter by test group folder.
53+
- `--test`, `-t`: Filter by test name (requires `--group`).
54+
- `--correction`, `-c`: dBm correction offset (default: 0.0).
55+
- `--max-time`: Max time to display in minutes (default: 60).
56+
- `--outlier-percentile`: Bottom percentile of data to filter out (default: 0.01).
57+
- `--window-size`: Moving average window size in samples (default: 100).
58+
59+
#### Examples
6860

69-
### Example
7061
```bash
71-
uv run plot_powers.py data.csv
62+
# Plot the most recent recording across all groups
63+
rfmeter plot
64+
65+
# Plot the latest recording in a group
66+
rfmeter plot --group zerodrag
67+
68+
# Plot the latest recording matching a specific test
69+
rfmeter plot --group zerodrag --test 868_ant_a
70+
71+
# Plot a specific file with options
72+
rfmeter plot logs/zerodrag/868_ant_a_260401-230000.csv --correction -2.5 --max-time 30
7273
```
7374

74-
or with a correction offset:
75+
### List serial ports
7576

7677
```bash
77-
uv run plot_powers.py data.csv -2.5
78+
rfmeter list-ports
7879
```
7980

80-
## Output
81+
## Supported Frequencies (MHz)
82+
83+
35, 72, 433, 868, 900, 1200, 2400, 5600, 5650, 5700, 5750, 5800, 5850, 5900, 5950, 6000
84+
85+
## Output Format
8186

82-
- The script displays two plots:
83-
- **RF Power (dBm)**: Raw data and moving average over time (minutes)
84-
- **RF Power (mW)**: Raw data and moving average over time (minutes)
87+
CSV files contain three columns (no header): `timestamp_ms, dBm, mW`
88+
89+
## Note
90+
91+
If not installed globally, prefix commands with `uv run`:
92+
93+
```bash
94+
uv run rfmeter record --group zerodrag --test 868_ant_a --freq 868
95+
```

plot_powers.py

Lines changed: 0 additions & 66 deletions
This file was deleted.

pyproject.toml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,27 @@ description = "ImmersionRC RF Power Meter logger"
55
readme = "README.md"
66
requires-python = ">=3.12"
77
dependencies = [
8-
"matplotlib>=3.10.5",
9-
"pandas>=2.3.1",
10-
"pyqt6>=6.9.1",
8+
"matplotlib>=3.10.8",
9+
"pandas>=3.0.2",
10+
"pyqt6>=6.11.0",
1111
"pyserial>=3.5",
12+
"typer>=0.24",
1213
]
14+
15+
[project.scripts]
16+
rfmeter = "rfmeter.cli:app"
17+
18+
[dependency-groups]
19+
dev = [
20+
"ruff>=0.11",
21+
]
22+
23+
[build-system]
24+
requires = ["hatchling"]
25+
build-backend = "hatchling.build"
26+
27+
[tool.ruff]
28+
line-length = 120
29+
30+
[tool.ruff.lint]
31+
select = ["E", "F", "I", "W"]

requirements.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

rf_meter_logger.py

Lines changed: 0 additions & 93 deletions
This file was deleted.

rfmeter/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""ImmersionRC RF Power Meter CLI tool."""
2+
3+
FREQUENCIES = [35, 72, 433, 868, 900, 1200, 2400, 5600, 5650, 5700, 5750, 5800, 5850, 5900, 5950, 6000]
4+
BAUD_RATE = 9600

0 commit comments

Comments
 (0)