feat(#734): add the preset picker to the repeater and room server settings
The remote-node radio card gains the same grouped RadioPresetPicker as Radio Settings. Picking a preset fills frequency, bandwidth, SF and CR and marks the radio field dirty, so Save sends the existing `set radio`. TX power is untouched: on these nodes it is a separate command. Room servers share this screen (contacts_screen.dart:1063), so they get it too. The selection is matched from the current fields to the nearest kHz (repeaters report e.g. 908.205017). The list refreshes when stale. Epic: #733 Agent: MagentaHawk (session 5a8922d6) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>pull/746/head
parent
67158bcc9d
commit
a8ef70e37e
@ -0,0 +1,34 @@
|
||||
import '../models/radio_preset.dart';
|
||||
|
||||
// Radio presets on remote nodes (repeater, room server, sensor) through the
|
||||
// stock admin CLI (#733). Kept out of the screen so it can be tested.
|
||||
|
||||
/// The preset whose radio values match the form's, or null for custom values.
|
||||
/// The form holds frequency as text (the repeater reports e.g. "908.205017"),
|
||||
/// so frequency matches to the nearest kHz. TX power is not compared: the
|
||||
/// remote screen sets it separately.
|
||||
String? matchRemotePresetId(
|
||||
List<RadioPreset> presets, {
|
||||
required String frequencyText,
|
||||
required int? bandwidthHz,
|
||||
required int? spreadingFactor,
|
||||
required int? codingRate,
|
||||
}) {
|
||||
final mhz = double.tryParse(frequencyText.trim());
|
||||
if (mhz == null ||
|
||||
bandwidthHz == null ||
|
||||
spreadingFactor == null ||
|
||||
codingRate == null) {
|
||||
return null;
|
||||
}
|
||||
final khz = (mhz * 1000).round();
|
||||
for (final p in presets) {
|
||||
if (p.frequencyKHz == khz &&
|
||||
p.bandwidth.hz == bandwidthHz &&
|
||||
p.spreadingFactor.value == spreadingFactor &&
|
||||
p.codingRate.value == codingRate) {
|
||||
return p.id;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -0,0 +1,109 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/helpers/remote_radio_commands.dart';
|
||||
import 'package:meshcore_open/models/radio_preset.dart';
|
||||
import 'package:meshcore_open/models/radio_settings.dart';
|
||||
|
||||
RadioPreset preset(
|
||||
String id, {
|
||||
double mhz = 908.205,
|
||||
LoRaBandwidth bw = LoRaBandwidth.bw62_5,
|
||||
LoRaSpreadingFactor sf = LoRaSpreadingFactor.sf9,
|
||||
LoRaCodingRate cr = LoRaCodingRate.cr4_8,
|
||||
int? tx,
|
||||
int? hashBytes,
|
||||
}) => RadioPreset(
|
||||
id: id,
|
||||
title: id,
|
||||
region: 'USA',
|
||||
frequencyMHz: mhz,
|
||||
bandwidth: bw,
|
||||
spreadingFactor: sf,
|
||||
codingRate: cr,
|
||||
source: RadioPresetSource.offband,
|
||||
txPowerDbm: tx,
|
||||
pathHashBytes: hashBytes,
|
||||
);
|
||||
|
||||
void main() {
|
||||
group('matchRemotePresetId (#734)', () {
|
||||
final presets = [
|
||||
preset('arizona', tx: 20),
|
||||
preset(
|
||||
'oki',
|
||||
mhz: 909.75,
|
||||
bw: LoRaBandwidth.bw500,
|
||||
sf: LoRaSpreadingFactor.sf10,
|
||||
cr: LoRaCodingRate.cr4_5,
|
||||
),
|
||||
];
|
||||
|
||||
test('matches the frequency a repeater reports, to the nearest kHz', () {
|
||||
expect(
|
||||
matchRemotePresetId(
|
||||
presets,
|
||||
frequencyText: '908.205017',
|
||||
bandwidthHz: 62500,
|
||||
spreadingFactor: 9,
|
||||
codingRate: 8,
|
||||
),
|
||||
'arizona',
|
||||
);
|
||||
expect(
|
||||
matchRemotePresetId(
|
||||
presets,
|
||||
frequencyText: '909.750',
|
||||
bandwidthHz: 500000,
|
||||
spreadingFactor: 10,
|
||||
codingRate: 5,
|
||||
),
|
||||
'oki',
|
||||
);
|
||||
});
|
||||
|
||||
test('any differing value means custom (null)', () {
|
||||
expect(
|
||||
matchRemotePresetId(
|
||||
presets,
|
||||
frequencyText: '908.205',
|
||||
bandwidthHz: 62500,
|
||||
spreadingFactor: 9,
|
||||
codingRate: 5,
|
||||
),
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
matchRemotePresetId(
|
||||
presets,
|
||||
frequencyText: '908.300',
|
||||
bandwidthHz: 62500,
|
||||
spreadingFactor: 9,
|
||||
codingRate: 8,
|
||||
),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
|
||||
test('unknown or unparsable fields match nothing', () {
|
||||
expect(
|
||||
matchRemotePresetId(
|
||||
presets,
|
||||
frequencyText: '',
|
||||
bandwidthHz: 62500,
|
||||
spreadingFactor: 9,
|
||||
codingRate: 8,
|
||||
),
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
matchRemotePresetId(
|
||||
presets,
|
||||
frequencyText: '908.205',
|
||||
bandwidthHz: null,
|
||||
spreadingFactor: 9,
|
||||
codingRate: 8,
|
||||
),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Reference in new issue