diff --git a/lib/helpers/remote_radio_commands.dart b/lib/helpers/remote_radio_commands.dart index bd929536..06059e2e 100644 --- a/lib/helpers/remote_radio_commands.dart +++ b/lib/helpers/remote_radio_commands.dart @@ -71,13 +71,15 @@ bool sendsPresetPathHash({ /// 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. +/// remote screen sets it separately. A preset with a path hash only matches +/// a node on that mode (#747): MeshCore's "Canada" and "USA" differ only there. String? matchRemotePresetId( List presets, { required String frequencyText, required int? bandwidthHz, required int? spreadingFactor, required int? codingRate, + required int pathHashMode, }) { final mhz = double.tryParse(frequencyText.trim()); if (mhz == null || @@ -91,7 +93,8 @@ String? matchRemotePresetId( if (p.frequencyKHz == khz && p.bandwidth.hz == bandwidthHz && p.spreadingFactor.value == spreadingFactor && - p.codingRate.value == codingRate) { + p.codingRate.value == codingRate && + presetPathHashMatches(p, pathHashMode + 1)) { return p.id; } } diff --git a/lib/screens/repeater_settings_screen.dart b/lib/screens/repeater_settings_screen.dart index c7bd901f..f1a87478 100644 --- a/lib/screens/repeater_settings_screen.dart +++ b/lib/screens/repeater_settings_screen.dart @@ -236,6 +236,7 @@ class _RepeaterSettingsScreenState extends State { bandwidthHz: _bandwidth, spreadingFactor: _spreadingFactor, codingRate: _codingRate, + pathHashMode: _pathHashMode, ); @override diff --git a/test/helpers/remote_radio_commands_test.dart b/test/helpers/remote_radio_commands_test.dart index 8204b204..5271f2b0 100644 --- a/test/helpers/remote_radio_commands_test.dart +++ b/test/helpers/remote_radio_commands_test.dart @@ -147,6 +147,7 @@ void main() { bandwidthHz: 62500, spreadingFactor: 9, codingRate: 8, + pathHashMode: 0, ), 'arizona', ); @@ -157,6 +158,7 @@ void main() { bandwidthHz: 500000, spreadingFactor: 10, codingRate: 5, + pathHashMode: 0, ), 'oki', ); @@ -170,6 +172,7 @@ void main() { bandwidthHz: 62500, spreadingFactor: 9, codingRate: 5, + pathHashMode: 0, ), isNull, ); @@ -180,6 +183,7 @@ void main() { bandwidthHz: 62500, spreadingFactor: 9, codingRate: 8, + pathHashMode: 0, ), isNull, ); @@ -193,6 +197,7 @@ void main() { bandwidthHz: 62500, spreadingFactor: 9, codingRate: 8, + pathHashMode: 0, ), isNull, ); @@ -203,9 +208,39 @@ void main() { bandwidthHz: null, spreadingFactor: 9, codingRate: 8, + pathHashMode: 0, ), isNull, ); }); + + test('a path hash preset only matches a node on that mode (#747)', () { + final usaPair = [ + preset( + 'canada', + mhz: 910.525, + sf: LoRaSpreadingFactor.sf7, + cr: LoRaCodingRate.cr4_5, + hashBytes: 3, + ), + preset( + 'usa', + mhz: 910.525, + sf: LoRaSpreadingFactor.sf7, + cr: LoRaCodingRate.cr4_5, + ), + ]; + String? match(int mode) => matchRemotePresetId( + usaPair, + frequencyText: '910.525', + bandwidthHz: 62500, + spreadingFactor: 7, + codingRate: 5, + pathHashMode: mode, + ); + expect(match(0), 'usa'); + expect(match(1), 'usa'); + expect(match(2), 'canada'); + }); }); }