feat(#730): apply a preset's path hash to a companion or observer on save

Saving Radio Settings already sends radio params (cmd 11) and TX power
(cmd 12). When the selected preset carries a path hash size, save now
also sends CMD_SET_PATH_HASH_MODE (61) with the zero-based mode. It is
sent whenever the preset has one, not compared against the reported
width, because that reads as 1 when device info is short (#240).
Off-grid repeat handling is unchanged.

The CMD_SET_RADIO_PARAMS comment said the frequency was in Hz; stock
firmware stores freq / 1000.0 as MHz, so it is kHz. Comment corrected.
A frame test pins the bytes a preset puts on the wire.

Epic: #726
Agent: MagentaHawk (session 5a8922d6)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pull/744/head
diffwireauto 2 months ago
parent 2f0f036eb6
commit c0ec6c650d

@ -1203,7 +1203,8 @@ Uint8List buildSetChannelFrame(int channelIndex, String name, Uint8List psk) {
// Build CMD_SET_RADIO_PARAMS frame
// Format: [cmd][freq x4][bw x4][sf][cr] (pre-v9)
// [cmd][freq x4][bw x4][sf][cr][repeat] (firmware v9+)
// freq: frequency in Hz (300000-2500000)
// freq: frequency in kHz despite the parameter name (stock firmware stores
// freq / 1000.0 as MHz and accepts 150000-2500000)
// bw: bandwidth in Hz (7000-500000)
// sf: spreading factor (5-12)
// cr: coding rate (5-8)

@ -2402,6 +2402,15 @@ class _RadioSettingsFormState extends State<_RadioSettingsForm> {
),
);
await widget.connector.sendFrame(buildSetRadioTxPowerFrame(txPower));
// A preset that carries a path hash size sets it too (stock
// CMD_SET_PATH_HASH_MODE, #730). Sent whenever the preset has one,
// rather than compared against the reported width, which reads as 1
// when device info is short (#240). Setting the same mode is harmless.
final pathHashMode = _presetById(_selectedPresetId)?.pathHashMode;
if (pathHashMode != null) {
_logRadioSettingsState('Setting preset path hash mode $pathHashMode');
await widget.connector.setPathHashMode(pathHashMode);
}
await widget.connector.refreshDeviceInfo();
final rememberedSnapshot = _clientRepeat
? _lastNonRepeatSnapshot

@ -0,0 +1,72 @@
import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/connector/meshcore_protocol.dart';
import 'package:meshcore_open/models/radio_preset.dart';
import 'package:meshcore_open/services/radio_preset_service.dart';
/// What applying a preset puts on the wire to a companion or observer
/// (#730): stock CMD_SET_RADIO_PARAMS (11), CMD_SET_RADIO_TX_POWER (12) and,
/// when the preset carries one, CMD_SET_PATH_HASH_MODE (61).
void main() {
late List<RadioPreset> presets;
setUpAll(() {
presets = mergeRadioPresets(
parseUpstreamPresets(
File('assets/radio_presets/meshcore-upstream.json').readAsStringSync(),
).presets,
parseOverlayPresets(
File('assets/radio_presets/offband.json').readAsStringSync(),
).presets,
);
});
RadioPreset named(String title) =>
presets.firstWhere((p) => p.title == title);
List<int> le32(int v) => [
v & 0xFF,
(v >> 8) & 0xFF,
(v >> 16) & 0xFF,
(v >> 24) & 0xFF,
];
test('radio params: frequency in kHz, bandwidth in Hz, as stock expects', () {
final philly = named('USA - Philly Mesh');
// The form sends MHz * 1000, i.e. kHz; stock stores freq / 1000.0 as MHz.
final frame = buildSetRadioParamsFrame(
philly.frequencyHz,
philly.bandwidth.hz,
philly.spreadingFactor.value,
philly.codingRate.value,
);
expect(frame, [cmdSetRadioParams, ...le32(919500), ...le32(500000), 10, 5]);
// Inside stock's accepted ranges (150000-2500000 kHz, BW <= 500000 Hz).
expect(philly.frequencyHz, inInclusiveRange(150000, 2500000));
expect(philly.bandwidth.hz, lessThanOrEqualTo(500000));
});
test('path hash: published bytes become the zero-based mode on the wire', () {
expect(
buildSetPathHashModeFrame(named('USA - Philly Mesh').pathHashMode!),
[cmdSetPathHashMode, 0, 1],
);
expect(
buildSetPathHashModeFrame(
named('USA - Southern California').pathHashMode!,
),
[cmdSetPathHashMode, 0, 2],
);
expect(
buildSetPathHashModeFrame(named('New Zealand (Gisborne)').pathHashMode!),
[cmdSetPathHashMode, 0, 0],
);
});
test('a preset without path hash or TX power sends neither', () {
final usa = named('USA');
expect(usa.pathHashMode, isNull);
expect(usa.txPowerDbm, isNull);
});
}
Loading…
Cancel
Save

Powered by TurnKey Linux.