Merge branch 'feat/726-preset-catalog' into feat/733-remote-presets

pull/746/head
diffwireauto 2 months ago
commit 868d88568d

@ -66,6 +66,13 @@ class RadioPreset {
int? get pathHashMode => pathHashModeForBytes(pathHashBytes);
}
/// Whether a radio using [radioPathHashBytes] fits [preset]'s path hash
/// (#747). Presets without a path hash fit any radio; one with a size only
/// fits a radio on that size. Without this, presets that differ only by path
/// hash (MeshCore's "Canada" 3-byte and "USA") are indistinguishable.
bool presetPathHashMatches(RadioPreset preset, int radioPathHashBytes) =>
preset.pathHashBytes == null || preset.pathHashBytes == radioPathHashBytes;
/// Zero-based firmware path hash mode for a published size in bytes (1-3).
/// Null for null or out-of-range input, so nothing is sent.
int? pathHashModeForBytes(int? bytes) {

@ -2157,7 +2157,9 @@ class _RadioSettingsFormState extends State<_RadioSettingsForm> {
preset.bandwidth == snapshot.bandwidth &&
preset.spreadingFactor == snapshot.spreadingFactor &&
preset.codingRate == snapshot.codingRate &&
(preset.txPowerDbm == null || preset.txPowerDbm == snapshot.txPowerDbm);
(preset.txPowerDbm == null ||
preset.txPowerDbm == snapshot.txPowerDbm) &&
presetPathHashMatches(preset, widget.connector.pathHashByteWidth);
}
String? _findMatchingPresetIdForSnapshot(_RadioSettingsSnapshot snapshot) {

@ -194,6 +194,53 @@ void main() {
});
});
group('presetPathHashMatches (#747)', () {
final r = parseUpstreamPresets(
upstream([
{
'title': 'Canada',
'frequency': '910.525',
'spreading_factor': '7',
'bandwidth': '62.5',
'coding_rate': '5',
'network_settings': {'path_hash_size': 3},
},
{
'title': 'USA',
'frequency': '910.525',
'spreading_factor': '7',
'bandwidth': '62.5',
'coding_rate': '5',
},
]),
);
final canada = r.presets[0];
final usa = r.presets[1];
test('a preset with a path hash only fits a radio on that size', () {
expect(presetPathHashMatches(canada, 3), isTrue);
expect(presetPathHashMatches(canada, 2), isFalse);
expect(presetPathHashMatches(canada, 1), isFalse);
});
test('a preset without one fits any radio', () {
for (final bytes in [1, 2, 3]) {
expect(presetPathHashMatches(usa, bytes), isTrue);
}
});
test('a USA radio on 1- or 2-byte hashes is not mistaken for Canada', () {
// Same radio values; Canada sorts first by region, so without the
// path hash check it wins (the D1 screenshot).
for (final bytes in [1, 2]) {
final fitting = r.presets
.where((p) => presetPathHashMatches(p, bytes))
.map((p) => p.title);
expect(fitting, ['USA']);
}
});
});
group('path hash bytes to firmware mode (#649)', () {
test('published bytes map to the zero-based firmware mode', () {
expect(pathHashModeForBytes(1), 0);

Loading…
Cancel
Save

Powered by TurnKey Linux.