Merge pull request #744 from OffbandMesh/feat/726-preset-catalog
epic(#726): in-app radio preset catalog and picker (Companion/Observer)docs/750-contact-naming-plan
commit
e054d894f5
@ -0,0 +1,244 @@
|
||||
{
|
||||
"format": "meshcore-upstream-radio-presets",
|
||||
"format_version": 1,
|
||||
"source": "https://api.meshcore.nz/api/v1/config",
|
||||
"credit": "Radio presets maintained by Liam Cottle for MeshCore (meshcore.nz), the list the stock MeshCore app shows. Mirrored unmodified from https://api.meshcore.nz/api/v1/config. Offband's own additions live in offband.json. Credit: https://github.com/OffbandMesh/config-profiles#credit",
|
||||
"updated_at": "2026-10-01T07:48:36Z",
|
||||
"suggested_radio_settings": {
|
||||
"info_message": "These presets are suggested by the community.",
|
||||
"entries": [
|
||||
{
|
||||
"title": "Australia",
|
||||
"description": "915.800MHz / SF10 / BW250 / CR5",
|
||||
"frequency": "915.800",
|
||||
"spreading_factor": "10",
|
||||
"bandwidth": "250",
|
||||
"coding_rate": "5"
|
||||
},
|
||||
{
|
||||
"title": "Australia (Narrow)",
|
||||
"description": "916.575MHz / SF7 / BW62.5 / CR7",
|
||||
"frequency": "916.575",
|
||||
"spreading_factor": "7",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "7"
|
||||
},
|
||||
{
|
||||
"title": "Australia (Mid)",
|
||||
"description": "915.075MHz / SF9 / BW125 / CR5",
|
||||
"frequency": "915.075",
|
||||
"spreading_factor": "9",
|
||||
"bandwidth": "125",
|
||||
"coding_rate": "5"
|
||||
},
|
||||
{
|
||||
"title": "Australia: SA, WA",
|
||||
"description": "923.125MHz / SF8 / BW62.5 / CR8",
|
||||
"frequency": "923.125",
|
||||
"spreading_factor": "8",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "8"
|
||||
},
|
||||
{
|
||||
"title": "Australia: QLD",
|
||||
"description": "923.125MHz / SF8 / BW62.5 / CR5",
|
||||
"frequency": "923.125",
|
||||
"spreading_factor": "8",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "5"
|
||||
},
|
||||
{
|
||||
"title": "Brazil",
|
||||
"description": "923.125MHz / SF8 / BW62.5 / CR8",
|
||||
"frequency": "923.125",
|
||||
"spreading_factor": "8",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "8"
|
||||
},
|
||||
{
|
||||
"title": "Canada",
|
||||
"description": "910.525MHz / SF7 / BW62.5 / CR5 / 3B",
|
||||
"frequency": "910.525",
|
||||
"spreading_factor": "7",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "5",
|
||||
"network_settings": {
|
||||
"path_hash_size": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "Costa Rica",
|
||||
"description": "910.525MHz / SF11 / BW125 / CR5",
|
||||
"frequency": "910.525",
|
||||
"spreading_factor": "11",
|
||||
"bandwidth": "125",
|
||||
"coding_rate": "5"
|
||||
},
|
||||
{
|
||||
"title": "EU/UK (Narrow)",
|
||||
"description": "869.618MHz / SF8 / BW62.5 / CR8",
|
||||
"frequency": "869.618",
|
||||
"spreading_factor": "8",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "8"
|
||||
},
|
||||
{
|
||||
"title": "EU/UK (Deprecated)",
|
||||
"description": "869.525MHz / SF11 / BW250 / CR5",
|
||||
"frequency": "869.525",
|
||||
"spreading_factor": "11",
|
||||
"bandwidth": "250",
|
||||
"coding_rate": "5"
|
||||
},
|
||||
{
|
||||
"title": "Czech Republic (Narrow)",
|
||||
"description": "869.432MHz / SF7 / BW62.5 / CR5 / 2B",
|
||||
"frequency": "869.432",
|
||||
"spreading_factor": "7",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "5",
|
||||
"network_settings": {
|
||||
"path_hash_size": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "EU 433MHz (Long Range)",
|
||||
"description": "433.650MHz / SF11 / BW250 / CR5",
|
||||
"frequency": "433.650",
|
||||
"spreading_factor": "11",
|
||||
"bandwidth": "250",
|
||||
"coding_rate": "5"
|
||||
},
|
||||
{
|
||||
"title": "EU 433MHz (Narrow)",
|
||||
"description": "433.650MHz / SF8 / BW62.5 / CR8",
|
||||
"frequency": "433.650",
|
||||
"spreading_factor": "8",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "8"
|
||||
},
|
||||
{
|
||||
"title": "Hungary",
|
||||
"description": "869.618MHz / SF7 / BW62.5 / CR5 / 2B",
|
||||
"frequency": "869.618",
|
||||
"spreading_factor": "7",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "5",
|
||||
"network_settings": {
|
||||
"path_hash_size": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "Netherlands",
|
||||
"description": "869.618MHz / SF7 / BW62.5 / CR5",
|
||||
"frequency": "869.618",
|
||||
"spreading_factor": "7",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "5"
|
||||
},
|
||||
{
|
||||
"title": "Netherlands (Limburg)",
|
||||
"description": "869.618MHz / SF8 / BW62.5 / CR8 / 2B",
|
||||
"frequency": "869.618",
|
||||
"spreading_factor": "8",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "8",
|
||||
"network_settings": {
|
||||
"path_hash_size": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "New Zealand (Narrow)",
|
||||
"description": "917.375MHz / SF7 / BW62.5 / CR5 / 2B",
|
||||
"frequency": "917.375",
|
||||
"spreading_factor": "7",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "5",
|
||||
"network_settings": {
|
||||
"path_hash_size": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "New Zealand (Gisborne)",
|
||||
"description": "917.375MHz / SF11 / BW250 / CR5 / 1B",
|
||||
"frequency": "917.375",
|
||||
"spreading_factor": "11",
|
||||
"bandwidth": "250",
|
||||
"coding_rate": "5",
|
||||
"network_settings": {
|
||||
"path_hash_size": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "Portugal 433",
|
||||
"description": "433.375MHz / SF9 / BW62.5 / CR6",
|
||||
"frequency": "433.375",
|
||||
"spreading_factor": "9",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "6"
|
||||
},
|
||||
{
|
||||
"title": "Portugal 868",
|
||||
"description": "869.618MHz / SF7 / BW62.5 / CR6",
|
||||
"frequency": "869.618",
|
||||
"spreading_factor": "7",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "6"
|
||||
},
|
||||
{
|
||||
"title": "Slovakia",
|
||||
"description": "869.618MHz / SF7 / BW62.5 / CR5 / 2B",
|
||||
"frequency": "869.618",
|
||||
"spreading_factor": "7",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "5",
|
||||
"network_settings": {
|
||||
"path_hash_size": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "Switzerland",
|
||||
"description": "869.618MHz / SF8 / BW62.5 / CR8",
|
||||
"frequency": "869.618",
|
||||
"spreading_factor": "8",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "8"
|
||||
},
|
||||
{
|
||||
"title": "USA",
|
||||
"description": "910.525MHz / SF7 / BW62.5 / CR5",
|
||||
"frequency": "910.525",
|
||||
"spreading_factor": "7",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "5"
|
||||
},
|
||||
{
|
||||
"title": "USA - Southern California",
|
||||
"description": "927.875MHz / SF7 / BW62.5 / CR5 / 3B",
|
||||
"frequency": "927.875",
|
||||
"spreading_factor": "7",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "5",
|
||||
"network_settings": {
|
||||
"path_hash_size": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "Vietnam (Narrow)",
|
||||
"description": "920.250MHz / SF8 / BW62.5 / CR5",
|
||||
"frequency": "920.250",
|
||||
"spreading_factor": "8",
|
||||
"bandwidth": "62.5",
|
||||
"coding_rate": "5"
|
||||
},
|
||||
{
|
||||
"title": "Vietnam (Deprecated)",
|
||||
"description": "920.250MHz / SF11 / BW250 / CR5",
|
||||
"frequency": "920.250",
|
||||
"spreading_factor": "11",
|
||||
"bandwidth": "250",
|
||||
"coding_rate": "5"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,407 @@
|
||||
{
|
||||
"format": "offband-radio-presets",
|
||||
"format_version": 1,
|
||||
"description": "Offband radio preset overlay. These entries are added to the MeshCore preset list mirrored in meshcore-upstream.json, and win over it when a title matches. Edit this file to add, change or retire a preset; the app picks the change up on its next refresh, with no app release. See SCHEMA.md.",
|
||||
"presets": [
|
||||
{
|
||||
"id": "usa-arizona",
|
||||
"title": "USA - Arizona",
|
||||
"region": "USA",
|
||||
"frequency": 908.205,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 9,
|
||||
"coding_rate": 8,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "SF9/CR8 per zjs81/meshcore-open#507 (Tucson / Phoenix alignment). Unconfirmed by an Arizona authority; owner decision 2026-10-01."
|
||||
},
|
||||
{
|
||||
"id": "usa-philly-mesh",
|
||||
"title": "USA - Philly Mesh",
|
||||
"region": "USA",
|
||||
"frequency": 919.5,
|
||||
"bandwidth": 500,
|
||||
"spreading_factor": 10,
|
||||
"coding_rate": 5,
|
||||
"tx_power": 20,
|
||||
"path_hash_size": 2,
|
||||
"status": "published",
|
||||
"notes": "phillymesh.net, 2026-10-01: 919.500 / 500 kHz / SF10 / CR 4/5 / path hash mode 1 (2-byte). Replaces their original 902.25 guidance. TX power not published; 20 dBm matches the US entries."
|
||||
},
|
||||
{
|
||||
"id": "usa-oki-mesh-500khz-test",
|
||||
"title": "USA - OKI-Mesh 500kHz Test",
|
||||
"region": "USA",
|
||||
"frequency": 909.75,
|
||||
"bandwidth": 500,
|
||||
"spreading_factor": 10,
|
||||
"coding_rate": 5,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "docs.okimesh.org 500kHz-testing (test started 2026-09-23). OKI has not settled on a frequency; expect this to change. TX power not published; 20 dBm matches the US entries."
|
||||
},
|
||||
{
|
||||
"id": "russia-artyom-vvo",
|
||||
"title": "Russia Artyom (VVO)",
|
||||
"region": "Russia",
|
||||
"frequency": 864.281,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 8,
|
||||
"coding_rate": 6,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-biysk-bsk",
|
||||
"title": "Russia Biysk (BSK)",
|
||||
"region": "Russia",
|
||||
"frequency": 869.0,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 8,
|
||||
"coding_rate": 5,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-chelyabinsk-cek",
|
||||
"title": "Russia Chelyabinsk (CEK)",
|
||||
"region": "Russia",
|
||||
"frequency": 868.731,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 8,
|
||||
"coding_rate": 6,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-cherepovets-cee",
|
||||
"title": "Russia Cherepovets (CEE)",
|
||||
"region": "Russia",
|
||||
"frequency": 868.57,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 7,
|
||||
"coding_rate": 8,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-irkutsk-ikt",
|
||||
"title": "Russia Irkutsk (IKT)",
|
||||
"region": "Russia",
|
||||
"frequency": 868.731,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 7,
|
||||
"coding_rate": 7,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-ivanovo-iwa",
|
||||
"title": "Russia Ivanovo (IWA)",
|
||||
"region": "Russia",
|
||||
"frequency": 868.731,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 8,
|
||||
"coding_rate": 8,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-izhevsk-ijk",
|
||||
"title": "Russia Izhevsk (IJK)",
|
||||
"region": "Russia",
|
||||
"frequency": 868.732,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 8,
|
||||
"coding_rate": 8,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-kaluga-klf",
|
||||
"title": "Russia Kaluga (KLF)",
|
||||
"region": "Russia",
|
||||
"frequency": 868.731,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 7,
|
||||
"coding_rate": 7,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-kazan-kzn",
|
||||
"title": "Russia Kazan (KZN)",
|
||||
"region": "Russia",
|
||||
"frequency": 868.731,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 8,
|
||||
"coding_rate": 6,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-khabarovsk-khv",
|
||||
"title": "Russia Khabarovsk (KHV)",
|
||||
"region": "Russia",
|
||||
"frequency": 864.281,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 8,
|
||||
"coding_rate": 6,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-kirov-kvx",
|
||||
"title": "Russia Kirov (KVX)",
|
||||
"region": "Russia",
|
||||
"frequency": 868.731,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 8,
|
||||
"coding_rate": 8,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-lipetsk-lpk",
|
||||
"title": "Russia Lipetsk (LPK)",
|
||||
"region": "Russia",
|
||||
"frequency": 868.95,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 9,
|
||||
"coding_rate": 7,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-moscow-mow",
|
||||
"title": "Russia Moscow (MOW)",
|
||||
"region": "Russia",
|
||||
"frequency": 868.731,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 7,
|
||||
"coding_rate": 7,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-nizhny-novgorod-goj",
|
||||
"title": "Russia Nizhny Novgorod (GOJ)",
|
||||
"region": "Russia",
|
||||
"frequency": 868.731,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 8,
|
||||
"coding_rate": 6,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-novosibirsk-ovb",
|
||||
"title": "Russia Novosibirsk (OVB)",
|
||||
"region": "Russia",
|
||||
"frequency": 869.0,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 9,
|
||||
"coding_rate": 8,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-rostov-on-don-rov",
|
||||
"title": "Russia Rostov-on-Don (ROV)",
|
||||
"region": "Russia",
|
||||
"frequency": 868.731,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 9,
|
||||
"coding_rate": 7,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-ryazan-rzn",
|
||||
"title": "Russia Ryazan (RZN)",
|
||||
"region": "Russia",
|
||||
"frequency": 868.88,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 9,
|
||||
"coding_rate": 5,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-samara-kuf",
|
||||
"title": "Russia Samara (KUF)",
|
||||
"region": "Russia",
|
||||
"frequency": 864.281,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 8,
|
||||
"coding_rate": 7,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-saratov-gsv",
|
||||
"title": "Russia Saratov (GSV)",
|
||||
"region": "Russia",
|
||||
"frequency": 864.281,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 8,
|
||||
"coding_rate": 7,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-st-petersburg-led",
|
||||
"title": "Russia St. Petersburg (LED)",
|
||||
"region": "Russia",
|
||||
"frequency": 868.856,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 7,
|
||||
"coding_rate": 7,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-tambov-tbw",
|
||||
"title": "Russia Tambov (TBW)",
|
||||
"region": "Russia",
|
||||
"frequency": 868.95,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 10,
|
||||
"coding_rate": 5,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-tula-tya",
|
||||
"title": "Russia Tula (TYA)",
|
||||
"region": "Russia",
|
||||
"frequency": 868.731,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 8,
|
||||
"coding_rate": 7,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-tver-kld",
|
||||
"title": "Russia Tver (KLD)",
|
||||
"region": "Russia",
|
||||
"frequency": 869.169,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 8,
|
||||
"coding_rate": 8,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-ufa-ufa",
|
||||
"title": "Russia Ufa (UFA)",
|
||||
"region": "Russia",
|
||||
"frequency": 868.732,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 8,
|
||||
"coding_rate": 8,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-volgograd-vog",
|
||||
"title": "Russia Volgograd (VOG)",
|
||||
"region": "Russia",
|
||||
"frequency": 869.525,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 7,
|
||||
"coding_rate": 7,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-voronezh-voz",
|
||||
"title": "Russia Voronezh (VOZ)",
|
||||
"region": "Russia",
|
||||
"frequency": 868.731,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 8,
|
||||
"coding_rate": 6,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "russia-yekaterinburg-svx",
|
||||
"title": "Russia Yekaterinburg (SVX)",
|
||||
"region": "Russia",
|
||||
"frequency": 869.046,
|
||||
"bandwidth": 62.5,
|
||||
"spreading_factor": 7,
|
||||
"coding_rate": 7,
|
||||
"tx_power": 20,
|
||||
"status": "published",
|
||||
"notes": "Carried over from zjs81/meshcore-open (Russian regional presets, 2026-05-13)."
|
||||
},
|
||||
{
|
||||
"id": "off-grid-433",
|
||||
"title": "Off-Grid 433",
|
||||
"region": "Off-Grid",
|
||||
"frequency": 433.0,
|
||||
"bandwidth": 250,
|
||||
"spreading_factor": 11,
|
||||
"coding_rate": 8,
|
||||
"tx_power": 20,
|
||||
"off_grid": true,
|
||||
"status": "published",
|
||||
"notes": "Client-repeat frequency, used by the companion's off-grid repeat mode."
|
||||
},
|
||||
{
|
||||
"id": "off-grid-869",
|
||||
"title": "Off-Grid 869",
|
||||
"region": "Off-Grid",
|
||||
"frequency": 869.0,
|
||||
"bandwidth": 250,
|
||||
"spreading_factor": 11,
|
||||
"coding_rate": 8,
|
||||
"tx_power": 14,
|
||||
"off_grid": true,
|
||||
"status": "published",
|
||||
"notes": "Client-repeat frequency, used by the companion's off-grid repeat mode."
|
||||
},
|
||||
{
|
||||
"id": "off-grid-918",
|
||||
"title": "Off-Grid 918",
|
||||
"region": "Off-Grid",
|
||||
"frequency": 918.0,
|
||||
"bandwidth": 250,
|
||||
"spreading_factor": 11,
|
||||
"coding_rate": 8,
|
||||
"tx_power": 20,
|
||||
"off_grid": true,
|
||||
"status": "published",
|
||||
"notes": "Client-repeat frequency, used by the companion's off-grid repeat mode."
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,294 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'radio_settings.dart';
|
||||
|
||||
// Regional radio presets (#647). Two sources, both published in the
|
||||
// OffbandMesh/config-profiles repo under radio-presets/ (schema in its SCHEMA.md):
|
||||
// - meshcore-upstream.json: MeshCore's suggested presets (maintained by Liam
|
||||
// Cottle), mirrored unmodified; numbers arrive as strings.
|
||||
// - offband.json: Offband's overlay; numbers are JSON numbers.
|
||||
// Parsing is resilient: a malformed entry is skipped and counted, never fatal,
|
||||
// but a file of the wrong format or a newer format_version is rejected.
|
||||
|
||||
const String kUpstreamPresetFormat = 'meshcore-upstream-radio-presets';
|
||||
const String kOverlayPresetFormat = 'offband-radio-presets';
|
||||
|
||||
/// Highest format_version this build understands, for both files.
|
||||
const int kRadioPresetFormatVersion = 1;
|
||||
|
||||
enum RadioPresetSource { meshcore, offband }
|
||||
|
||||
class RadioPreset {
|
||||
const RadioPreset({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.region,
|
||||
required this.frequencyMHz,
|
||||
required this.bandwidth,
|
||||
required this.spreadingFactor,
|
||||
required this.codingRate,
|
||||
required this.source,
|
||||
this.txPowerDbm,
|
||||
this.pathHashBytes,
|
||||
this.offGrid = false,
|
||||
});
|
||||
|
||||
final String id;
|
||||
final String title;
|
||||
|
||||
/// Picker group, e.g. "USA", "Australia", "Off-Grid".
|
||||
final String region;
|
||||
final double frequencyMHz;
|
||||
final LoRaBandwidth bandwidth;
|
||||
final LoRaSpreadingFactor spreadingFactor;
|
||||
final LoRaCodingRate codingRate;
|
||||
final RadioPresetSource source;
|
||||
|
||||
/// Null leaves the radio's TX power alone (upstream presets never set it).
|
||||
final int? txPowerDbm;
|
||||
|
||||
/// Path hash size in bytes (1-3), as published. Null leaves the radio's
|
||||
/// setting alone.
|
||||
final int? pathHashBytes;
|
||||
|
||||
/// A client-repeat (off-grid) frequency rather than a regional preset.
|
||||
final bool offGrid;
|
||||
|
||||
/// Frequency in kHz, the unit CMD_SET_RADIO_PARAMS carries.
|
||||
int get frequencyKHz => (frequencyMHz * 1000).round();
|
||||
|
||||
/// The firmware's path hash mode for [pathHashBytes], or null to leave it.
|
||||
///
|
||||
/// Presets publish the size in bytes; firmware takes a zero-based mode
|
||||
/// (`sendFlood(..., path_hash_mode + 1)`): 1 byte = mode 0, 2 bytes = mode 1,
|
||||
/// 3 bytes = mode 2. Passing a published 2 straight through would select
|
||||
/// 3-byte hashes and put the node off its mesh.
|
||||
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) {
|
||||
if (bytes == null || bytes < 1 || bytes > 3) return null;
|
||||
return bytes - 1;
|
||||
}
|
||||
|
||||
class RadioPresetFormatException implements Exception {
|
||||
const RadioPresetFormatException(this.message);
|
||||
final String message;
|
||||
@override
|
||||
String toString() => 'RadioPresetFormatException: $message';
|
||||
}
|
||||
|
||||
class RadioPresetParseResult {
|
||||
const RadioPresetParseResult(this.presets, this.skipped);
|
||||
final List<RadioPreset> presets;
|
||||
|
||||
/// Malformed entries left out, so a partly bad file never looks complete.
|
||||
final int skipped;
|
||||
}
|
||||
|
||||
/// Parse the mirrored MeshCore list (`meshcore-upstream.json`).
|
||||
RadioPresetParseResult parseUpstreamPresets(String source) {
|
||||
final doc = _decodeObject(source, kUpstreamPresetFormat);
|
||||
final srs = doc['suggested_radio_settings'];
|
||||
final entries = srs is Map ? srs['entries'] : null;
|
||||
if (entries is! List) {
|
||||
throw const RadioPresetFormatException(
|
||||
'suggested_radio_settings.entries must be a list',
|
||||
);
|
||||
}
|
||||
final presets = <RadioPreset>[];
|
||||
var skipped = 0;
|
||||
for (final e in entries) {
|
||||
final preset = e is Map ? _upstreamEntry(e) : null;
|
||||
if (preset == null) {
|
||||
skipped++;
|
||||
} else {
|
||||
presets.add(preset);
|
||||
}
|
||||
}
|
||||
return RadioPresetParseResult(presets, skipped);
|
||||
}
|
||||
|
||||
/// Parse the Offband overlay (`offband.json`). Retired entries are dropped.
|
||||
RadioPresetParseResult parseOverlayPresets(String source) {
|
||||
final doc = _decodeObject(source, kOverlayPresetFormat);
|
||||
final entries = doc['presets'];
|
||||
if (entries is! List) {
|
||||
throw const RadioPresetFormatException('presets must be a list');
|
||||
}
|
||||
final presets = <RadioPreset>[];
|
||||
var skipped = 0;
|
||||
for (final e in entries) {
|
||||
if (e is Map && e['status'] == 'retired') continue;
|
||||
final preset = e is Map ? _overlayEntry(e) : null;
|
||||
if (preset == null) {
|
||||
skipped++;
|
||||
} else {
|
||||
presets.add(preset);
|
||||
}
|
||||
}
|
||||
return RadioPresetParseResult(presets, skipped);
|
||||
}
|
||||
|
||||
Map _decodeObject(String source, String format) {
|
||||
final dynamic doc;
|
||||
try {
|
||||
doc = jsonDecode(source);
|
||||
} on FormatException catch (e) {
|
||||
throw RadioPresetFormatException('not valid JSON: ${e.message}');
|
||||
}
|
||||
if (doc is! Map) {
|
||||
throw const RadioPresetFormatException('must be a JSON object');
|
||||
}
|
||||
if (doc['format'] != format) {
|
||||
throw RadioPresetFormatException('format must be "$format"');
|
||||
}
|
||||
final version = doc['format_version'];
|
||||
if (version is! int) {
|
||||
throw const RadioPresetFormatException('format_version is required');
|
||||
}
|
||||
if (version > kRadioPresetFormatVersion) {
|
||||
throw RadioPresetFormatException(
|
||||
'format_version $version is newer than this app supports '
|
||||
'($kRadioPresetFormatVersion). Update the app.',
|
||||
);
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
RadioPreset? _upstreamEntry(Map e) {
|
||||
final title = e['title'];
|
||||
if (title is! String || title.trim().isEmpty) return null;
|
||||
final ns = e['network_settings'];
|
||||
final hash = ns is Map ? _asInt(ns['path_hash_size']) : null;
|
||||
if (ns is Map && ns.containsKey('path_hash_size') && !_validHash(hash)) {
|
||||
return null;
|
||||
}
|
||||
return _build(
|
||||
id: 'meshcore:$title',
|
||||
title: title,
|
||||
region: upstreamRegionFor(title),
|
||||
frequency: _asDouble(e['frequency']),
|
||||
bandwidthKHz: _asDouble(e['bandwidth']),
|
||||
sf: _asInt(e['spreading_factor']),
|
||||
cr: _asInt(e['coding_rate']),
|
||||
source: RadioPresetSource.meshcore,
|
||||
pathHashBytes: hash,
|
||||
);
|
||||
}
|
||||
|
||||
RadioPreset? _overlayEntry(Map e) {
|
||||
final id = e['id'];
|
||||
final title = e['title'];
|
||||
final region = e['region'];
|
||||
if (id is! String || id.isEmpty) return null;
|
||||
if (title is! String || title.trim().isEmpty) return null;
|
||||
if (region is! String || region.trim().isEmpty) return null;
|
||||
// The overlay is hand-edited: numbers must be JSON numbers, not strings.
|
||||
for (final key in const [
|
||||
'frequency',
|
||||
'bandwidth',
|
||||
'spreading_factor',
|
||||
'coding_rate',
|
||||
]) {
|
||||
if (e[key] is! num) return null;
|
||||
}
|
||||
final tx = e['tx_power'];
|
||||
if (tx != null && (tx is! int || tx < -9 || tx > 30)) return null;
|
||||
final hash = e['path_hash_size'];
|
||||
if (hash != null && (hash is! int || !_validHash(hash))) return null;
|
||||
final offGrid = e['off_grid'];
|
||||
if (offGrid != null && offGrid is! bool) return null;
|
||||
return _build(
|
||||
id: 'offband:$id',
|
||||
title: title,
|
||||
region: region,
|
||||
frequency: (e['frequency'] as num).toDouble(),
|
||||
bandwidthKHz: (e['bandwidth'] as num).toDouble(),
|
||||
sf: _asInt(e['spreading_factor']),
|
||||
cr: _asInt(e['coding_rate']),
|
||||
source: RadioPresetSource.offband,
|
||||
txPowerDbm: tx as int?,
|
||||
pathHashBytes: hash as int?,
|
||||
offGrid: offGrid == true,
|
||||
);
|
||||
}
|
||||
|
||||
RadioPreset? _build({
|
||||
required String id,
|
||||
required String title,
|
||||
required String region,
|
||||
required double? frequency,
|
||||
required double? bandwidthKHz,
|
||||
required int? sf,
|
||||
required int? cr,
|
||||
required RadioPresetSource source,
|
||||
int? txPowerDbm,
|
||||
int? pathHashBytes,
|
||||
bool offGrid = false,
|
||||
}) {
|
||||
if (frequency == null || frequency < 150 || frequency > 2500) return null;
|
||||
if (bandwidthKHz == null) return null;
|
||||
final bwHz = (bandwidthKHz * 1000).round();
|
||||
final bandwidth = LoRaBandwidth.values
|
||||
.where((b) => (b.hz - bwHz).abs() <= 50)
|
||||
.firstOrNull;
|
||||
final spreading = LoRaSpreadingFactor.values
|
||||
.where((s) => s.value == sf)
|
||||
.firstOrNull;
|
||||
final coding = LoRaCodingRate.values.where((c) => c.value == cr).firstOrNull;
|
||||
if (bandwidth == null || spreading == null || coding == null) return null;
|
||||
return RadioPreset(
|
||||
id: id,
|
||||
title: title.trim(),
|
||||
region: region.trim(),
|
||||
frequencyMHz: frequency,
|
||||
bandwidth: bandwidth,
|
||||
spreadingFactor: spreading,
|
||||
codingRate: coding,
|
||||
source: source,
|
||||
txPowerDbm: txPowerDbm,
|
||||
pathHashBytes: pathHashBytes,
|
||||
offGrid: offGrid,
|
||||
);
|
||||
}
|
||||
|
||||
bool _validHash(int? bytes) => bytes != null && bytes >= 1 && bytes <= 3;
|
||||
|
||||
double? _asDouble(Object? v) {
|
||||
if (v is num) return v.toDouble();
|
||||
if (v is String) return double.tryParse(v.trim());
|
||||
return null;
|
||||
}
|
||||
|
||||
int? _asInt(Object? v) {
|
||||
final d = _asDouble(v);
|
||||
if (d == null || d != d.roundToDouble()) return null;
|
||||
return d.round();
|
||||
}
|
||||
|
||||
/// The picker group for an upstream title, which carries no region field:
|
||||
/// the part before " - ", ":" or " (" ("USA - Southern California" -> "USA",
|
||||
/// "Australia: QLD" -> "Australia", "EU/UK (Narrow)" -> "EU/UK"), otherwise the
|
||||
/// title without a trailing band number ("Portugal 433" -> "Portugal"),
|
||||
/// otherwise the whole title ("Costa Rica").
|
||||
String upstreamRegionFor(String title) {
|
||||
final t = title.trim();
|
||||
var cut = t.length;
|
||||
for (final sep in const [' - ', ':', ' (']) {
|
||||
final i = t.indexOf(sep);
|
||||
if (i > 0 && i < cut) cut = i;
|
||||
}
|
||||
if (cut < t.length) return t.substring(0, cut).trim();
|
||||
final band = RegExp(r'^(.+?)\s+\d+$').firstMatch(t);
|
||||
return band != null ? band.group(1)! : t;
|
||||
}
|
||||
@ -0,0 +1,217 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../models/radio_preset.dart';
|
||||
import '../storage/prefs_manager.dart';
|
||||
import '../utils/app_logger.dart';
|
||||
import 'config_source_service.dart';
|
||||
|
||||
/// Where the preset files are published (OffbandMesh/config-profiles, #721).
|
||||
const String kRadioPresetBaseUrl =
|
||||
'https://raw.githubusercontent.com/OffbandMesh/config-profiles/main/radio-presets/';
|
||||
const String kUpstreamPresetFile = 'meshcore-upstream.json';
|
||||
const String kOverlayPresetFile = 'offband.json';
|
||||
|
||||
/// The copies bundled with the app, so the picker works offline.
|
||||
const String kRadioPresetAssetDir = 'assets/radio_presets/';
|
||||
|
||||
const String _prefsPrefix = 'radio_presets_v1_';
|
||||
const String _prefsRefreshedKey = '${_prefsPrefix}refreshed_at';
|
||||
|
||||
typedef PresetTextLoader = Future<String> Function(String location);
|
||||
|
||||
/// The regional radio preset list (#728): MeshCore's upstream presets plus
|
||||
/// Offband's overlay, merged with the overlay winning on a matching title.
|
||||
///
|
||||
/// Starts from the last good copy (or the bundled one), and refreshes from
|
||||
/// config-profiles on demand. A file that fails to fetch or parse never
|
||||
/// replaces a good copy; the failure is logged and kept in [refreshError] so
|
||||
/// the picker can show it.
|
||||
class RadioPresetService extends ChangeNotifier {
|
||||
RadioPresetService({
|
||||
PresetTextLoader? fetch,
|
||||
PresetTextLoader? loadAsset,
|
||||
SharedPreferences? prefs,
|
||||
DateTime Function()? clock,
|
||||
}) : _fetch = fetch,
|
||||
_loadAsset = loadAsset ?? rootBundle.loadString,
|
||||
_prefsOverride = prefs,
|
||||
_clock = clock ?? DateTime.now;
|
||||
|
||||
final PresetTextLoader? _fetch;
|
||||
final PresetTextLoader _loadAsset;
|
||||
final SharedPreferences? _prefsOverride;
|
||||
final DateTime Function() _clock;
|
||||
ConfigSourceService? _source;
|
||||
|
||||
SharedPreferences get _prefs => _prefsOverride ?? PrefsManager.instance;
|
||||
|
||||
RadioPresetParseResult _upstream = const RadioPresetParseResult([], 0);
|
||||
RadioPresetParseResult _overlay = const RadioPresetParseResult([], 0);
|
||||
List<RadioPreset> _presets = const [];
|
||||
String? _refreshError;
|
||||
DateTime? _lastRefreshed;
|
||||
bool _refreshing = false;
|
||||
|
||||
List<RadioPreset> get presets => _presets;
|
||||
|
||||
/// Entries left out of the files in use because they were malformed.
|
||||
int get skipped => _upstream.skipped + _overlay.skipped;
|
||||
|
||||
/// Why the last refresh (or load) failed, or null when it succeeded.
|
||||
String? get refreshError => _refreshError;
|
||||
DateTime? get lastRefreshed => _lastRefreshed;
|
||||
bool get refreshing => _refreshing;
|
||||
|
||||
/// Load the last good copy of each file, falling back to the bundled one.
|
||||
Future<void> load() async {
|
||||
final errors = <String>[];
|
||||
_upstream = await _loadLocal(
|
||||
kUpstreamPresetFile,
|
||||
parseUpstreamPresets,
|
||||
errors,
|
||||
);
|
||||
_overlay = await _loadLocal(
|
||||
kOverlayPresetFile,
|
||||
parseOverlayPresets,
|
||||
errors,
|
||||
);
|
||||
final stamp = _prefs.getString(_prefsRefreshedKey);
|
||||
_lastRefreshed = stamp == null ? null : DateTime.tryParse(stamp);
|
||||
_refreshError = errors.isEmpty ? null : errors.join('; ');
|
||||
_rebuild();
|
||||
}
|
||||
|
||||
/// Refresh when the copy in use is older than [maxAge] or was never
|
||||
/// refreshed. Returns whether a refresh ran and succeeded.
|
||||
Future<bool> refreshIfStale({
|
||||
Duration maxAge = const Duration(hours: 12),
|
||||
}) async {
|
||||
final last = _lastRefreshed;
|
||||
if (last != null && _clock().difference(last) < maxAge) return false;
|
||||
return refresh();
|
||||
}
|
||||
|
||||
/// Fetch both files from config-profiles. Each file that parses replaces
|
||||
/// its copy and is saved as the new last good copy; each that fails keeps
|
||||
/// the copy in use. Returns true only when both succeeded.
|
||||
Future<bool> refresh() async {
|
||||
if (_refreshing) return false;
|
||||
_refreshing = true;
|
||||
notifyListeners();
|
||||
final errors = <String>[];
|
||||
final upstream = await _fetchRemote(
|
||||
kUpstreamPresetFile,
|
||||
parseUpstreamPresets,
|
||||
errors,
|
||||
);
|
||||
final overlay = await _fetchRemote(
|
||||
kOverlayPresetFile,
|
||||
parseOverlayPresets,
|
||||
errors,
|
||||
);
|
||||
if (upstream != null) _upstream = upstream;
|
||||
if (overlay != null) _overlay = overlay;
|
||||
if (errors.isEmpty) {
|
||||
_lastRefreshed = _clock();
|
||||
await _prefs.setString(
|
||||
_prefsRefreshedKey,
|
||||
_lastRefreshed!.toIso8601String(),
|
||||
);
|
||||
_refreshError = null;
|
||||
} else {
|
||||
_refreshError = errors.join('; ');
|
||||
}
|
||||
_refreshing = false;
|
||||
_rebuild();
|
||||
return errors.isEmpty;
|
||||
}
|
||||
|
||||
Future<RadioPresetParseResult> _loadLocal(
|
||||
String file,
|
||||
RadioPresetParseResult Function(String) parse,
|
||||
List<String> errors,
|
||||
) async {
|
||||
final cached = _prefs.getString('$_prefsPrefix$file');
|
||||
if (cached != null) {
|
||||
try {
|
||||
return parse(cached);
|
||||
} catch (e) {
|
||||
appLogger.warn(
|
||||
'Saved copy of $file unusable, using the bundled one: $e',
|
||||
tag: 'RadioPresets',
|
||||
);
|
||||
}
|
||||
}
|
||||
try {
|
||||
return parse(await _loadAsset('$kRadioPresetAssetDir$file'));
|
||||
} catch (e) {
|
||||
appLogger.error('Bundled $file failed to load: $e', tag: 'RadioPresets');
|
||||
errors.add('$file: $e');
|
||||
return const RadioPresetParseResult([], 0);
|
||||
}
|
||||
}
|
||||
|
||||
Future<RadioPresetParseResult?> _fetchRemote(
|
||||
String file,
|
||||
RadioPresetParseResult Function(String) parse,
|
||||
List<String> errors,
|
||||
) async {
|
||||
final url = '$kRadioPresetBaseUrl$file';
|
||||
try {
|
||||
final text = _fetch != null
|
||||
? await _fetch(url)
|
||||
: await (_source ??= ConfigSourceService()).fetchText(url);
|
||||
final parsed = parse(text);
|
||||
if (parsed.presets.isEmpty) {
|
||||
throw RadioPresetFormatException('$file has no usable presets');
|
||||
}
|
||||
await _prefs.setString('$_prefsPrefix$file', text);
|
||||
if (parsed.skipped > 0) {
|
||||
appLogger.warn(
|
||||
'$file: ${parsed.skipped} malformed preset(s) skipped',
|
||||
tag: 'RadioPresets',
|
||||
);
|
||||
}
|
||||
return parsed;
|
||||
} catch (e) {
|
||||
appLogger.warn('Refreshing $file failed: $e', tag: 'RadioPresets');
|
||||
errors.add('$file: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void _rebuild() {
|
||||
_presets = mergeRadioPresets(_upstream.presets, _overlay.presets);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_source?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// Upstream presets plus the overlay. An overlay entry whose title matches an
|
||||
/// upstream one (ignoring case) replaces it. Sorted by region, then title.
|
||||
List<RadioPreset> mergeRadioPresets(
|
||||
List<RadioPreset> upstream,
|
||||
List<RadioPreset> overlay,
|
||||
) {
|
||||
final byTitle = <String, RadioPreset>{
|
||||
for (final p in upstream) p.title.toLowerCase(): p,
|
||||
};
|
||||
for (final p in overlay) {
|
||||
byTitle[p.title.toLowerCase()] = p;
|
||||
}
|
||||
final merged = byTitle.values.toList()
|
||||
..sort((a, b) {
|
||||
final r = a.region.toLowerCase().compareTo(b.region.toLowerCase());
|
||||
return r != 0
|
||||
? r
|
||||
: a.title.toLowerCase().compareTo(b.title.toLowerCase());
|
||||
});
|
||||
return merged;
|
||||
}
|
||||
@ -0,0 +1,175 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/radio_preset.dart';
|
||||
import '../services/radio_preset_service.dart';
|
||||
|
||||
/// The regional preset picker (#729): presets grouped by region under
|
||||
/// non-selectable headers, each labelled with its source, plus a status line
|
||||
/// saying where the list came from (and any refresh failure) with a refresh
|
||||
/// button. Used by the companion Radio Settings form and the remote-node
|
||||
/// settings screen.
|
||||
class RadioPresetPicker extends StatelessWidget {
|
||||
const RadioPresetPicker({
|
||||
super.key,
|
||||
required this.service,
|
||||
required this.presets,
|
||||
required this.selectedId,
|
||||
required this.onSelected,
|
||||
});
|
||||
|
||||
final RadioPresetService service;
|
||||
|
||||
/// The presets to offer, already filtered and in display order (grouped
|
||||
/// by region).
|
||||
final List<RadioPreset> presets;
|
||||
final String? selectedId;
|
||||
final ValueChanged<RadioPreset> onSelected;
|
||||
|
||||
static const _regionHeaderPrefix = 'region:';
|
||||
|
||||
RadioPreset? _byId(String? id) =>
|
||||
id == null ? null : presets.where((p) => p.id == id).firstOrNull;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final theme = Theme.of(context);
|
||||
final selected = _byId(selectedId)?.id;
|
||||
final titlesById = {for (final p in presets) p.id: p.title};
|
||||
final items = <DropdownMenuItem<String>>[];
|
||||
String? region;
|
||||
for (final preset in presets) {
|
||||
if (preset.region != region) {
|
||||
region = preset.region;
|
||||
items.add(
|
||||
DropdownMenuItem<String>(
|
||||
value: '$_regionHeaderPrefix$region',
|
||||
enabled: false,
|
||||
child: Text(
|
||||
region,
|
||||
style: theme.textTheme.labelMedium?.copyWith(
|
||||
color: theme.colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
items.add(
|
||||
DropdownMenuItem<String>(
|
||||
value: preset.id,
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(preset.title, overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
switch (preset.source) {
|
||||
RadioPresetSource.meshcore =>
|
||||
l10n.settings_presetSourceMeshCore,
|
||||
RadioPresetSource.offband =>
|
||||
l10n.settings_presetSourceOffband,
|
||||
},
|
||||
style: theme.textTheme.labelSmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
DropdownButtonFormField<String>(
|
||||
key: ValueKey<String?>(selected),
|
||||
initialValue: selected,
|
||||
isExpanded: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_presets,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
selectedItemBuilder: (context) => [
|
||||
for (final item in items)
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: Text(
|
||||
titlesById[item.value] ?? '',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
items: items,
|
||||
// Disabled while a refresh runs, so a pick can't vanish when the
|
||||
// refreshed list lands.
|
||||
onChanged: service.refreshing
|
||||
? null
|
||||
: (id) {
|
||||
final preset = _byId(id);
|
||||
if (preset != null) onSelected(preset);
|
||||
},
|
||||
),
|
||||
_PresetStatus(service: service),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Where the list came from, and any refresh failure, kept on screen until
|
||||
/// the next successful refresh.
|
||||
class _PresetStatus extends StatelessWidget {
|
||||
const _PresetStatus({required this.service});
|
||||
|
||||
final RadioPresetService service;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final theme = Theme.of(context);
|
||||
final String text;
|
||||
Color? color;
|
||||
if (service.refreshing) {
|
||||
text = l10n.settings_presetsUpdating;
|
||||
} else if (service.refreshError != null) {
|
||||
text = l10n.settings_presetsUpdateFailed;
|
||||
color = theme.colorScheme.error;
|
||||
} else if (service.lastRefreshed != null) {
|
||||
text = l10n.settings_presetsUpdatedAt(
|
||||
MaterialLocalizations.of(
|
||||
context,
|
||||
).formatMediumDate(service.lastRefreshed!.toLocal()),
|
||||
);
|
||||
} else {
|
||||
text = l10n.settings_presetsBundled;
|
||||
}
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
text,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: color ?? theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: l10n.settings_presetsRefresh,
|
||||
onPressed: service.refreshing ? null : service.refresh,
|
||||
icon: service.refreshing
|
||||
? const SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.refresh),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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.frequencyKHz,
|
||||
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.frequencyKHz, 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);
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,285 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/models/radio_preset.dart';
|
||||
import 'package:meshcore_open/models/radio_settings.dart';
|
||||
|
||||
String upstream(List<Map<String, dynamic>> entries, {int version = 1}) =>
|
||||
jsonEncode({
|
||||
'format': kUpstreamPresetFormat,
|
||||
'format_version': version,
|
||||
'source': 'https://api.meshcore.nz/api/v1/config',
|
||||
'credit': 'Liam Cottle / MeshCore',
|
||||
'updated_at': '2026-10-01T00:00:00Z',
|
||||
'suggested_radio_settings': {'entries': entries},
|
||||
});
|
||||
|
||||
String overlay(List<Map<String, dynamic>> presets, {int version = 1}) =>
|
||||
jsonEncode({
|
||||
'format': kOverlayPresetFormat,
|
||||
'format_version': version,
|
||||
'presets': presets,
|
||||
});
|
||||
|
||||
Map<String, dynamic> overlayEntry(String id, {Map<String, dynamic>? extra}) => {
|
||||
'id': id,
|
||||
'title': 'USA - $id',
|
||||
'region': 'USA',
|
||||
'frequency': 909.75,
|
||||
'bandwidth': 500,
|
||||
'spreading_factor': 10,
|
||||
'coding_rate': 5,
|
||||
'status': 'published',
|
||||
...?extra,
|
||||
};
|
||||
|
||||
void main() {
|
||||
group('parseUpstreamPresets (#727)', () {
|
||||
test('reads the API shape, where numbers are strings', () {
|
||||
final r = parseUpstreamPresets(
|
||||
upstream([
|
||||
{
|
||||
'title': 'USA - Southern California',
|
||||
'description': '927.875MHz / SF7 / BW62.5 / CR5 / 3B',
|
||||
'frequency': '927.875',
|
||||
'spreading_factor': '7',
|
||||
'bandwidth': '62.5',
|
||||
'coding_rate': '5',
|
||||
'network_settings': {'path_hash_size': 3},
|
||||
},
|
||||
{
|
||||
'title': 'EU/UK (Narrow)',
|
||||
'frequency': '869.618',
|
||||
'spreading_factor': '8',
|
||||
'bandwidth': '62.5',
|
||||
'coding_rate': '8',
|
||||
},
|
||||
]),
|
||||
);
|
||||
expect(r.skipped, 0);
|
||||
final socal = r.presets[0];
|
||||
expect(socal.id, 'meshcore:USA - Southern California');
|
||||
expect(socal.region, 'USA');
|
||||
expect(socal.frequencyKHz, 927875);
|
||||
expect(socal.bandwidth, LoRaBandwidth.bw62_5);
|
||||
expect(socal.spreadingFactor, LoRaSpreadingFactor.sf7);
|
||||
expect(socal.codingRate, LoRaCodingRate.cr4_5);
|
||||
expect(socal.pathHashBytes, 3);
|
||||
expect(socal.txPowerDbm, isNull);
|
||||
expect(socal.source, RadioPresetSource.meshcore);
|
||||
expect(r.presets[1].codingRate, LoRaCodingRate.cr4_8);
|
||||
expect(r.presets[1].pathHashBytes, isNull);
|
||||
});
|
||||
|
||||
test('skips and counts malformed entries instead of failing', () {
|
||||
final r = parseUpstreamPresets(
|
||||
upstream([
|
||||
{
|
||||
'title': 'Good',
|
||||
'frequency': '910.525',
|
||||
'spreading_factor': '7',
|
||||
'bandwidth': '62.5',
|
||||
'coding_rate': '5',
|
||||
},
|
||||
{
|
||||
'title': 'Bad BW',
|
||||
'frequency': '910.525',
|
||||
'spreading_factor': '7',
|
||||
'bandwidth': '63',
|
||||
'coding_rate': '5',
|
||||
},
|
||||
{
|
||||
'title': 'Bad hash',
|
||||
'frequency': '910.525',
|
||||
'spreading_factor': '7',
|
||||
'bandwidth': '62.5',
|
||||
'coding_rate': '5',
|
||||
'network_settings': {'path_hash_size': 4},
|
||||
},
|
||||
{'title': 'Missing values'},
|
||||
]),
|
||||
);
|
||||
expect(r.presets.map((p) => p.title), ['Good']);
|
||||
expect(r.skipped, 3);
|
||||
});
|
||||
|
||||
test('rejects a wrong format or a newer format_version', () {
|
||||
expect(
|
||||
() => parseUpstreamPresets(overlay([])),
|
||||
throwsA(isA<RadioPresetFormatException>()),
|
||||
);
|
||||
expect(
|
||||
() => parseUpstreamPresets(upstream([], version: 2)),
|
||||
throwsA(isA<RadioPresetFormatException>()),
|
||||
);
|
||||
expect(
|
||||
() => parseUpstreamPresets('<html>502</html>'),
|
||||
throwsA(isA<RadioPresetFormatException>()),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('parseOverlayPresets (#727)', () {
|
||||
test(
|
||||
'reads overlay entries with optional TX power, path hash, off-grid',
|
||||
() {
|
||||
final r = parseOverlayPresets(
|
||||
overlay([
|
||||
overlayEntry(
|
||||
'philly',
|
||||
extra: {'tx_power': 20, 'path_hash_size': 2},
|
||||
),
|
||||
overlayEntry(
|
||||
'grid',
|
||||
extra: {
|
||||
'region': 'Off-Grid',
|
||||
'frequency': 918.0,
|
||||
'bandwidth': 250,
|
||||
'spreading_factor': 11,
|
||||
'coding_rate': 8,
|
||||
'off_grid': true,
|
||||
},
|
||||
),
|
||||
]),
|
||||
);
|
||||
expect(r.skipped, 0);
|
||||
final philly = r.presets[0];
|
||||
expect(philly.id, 'offband:philly');
|
||||
expect(philly.bandwidth, LoRaBandwidth.bw500);
|
||||
expect(philly.txPowerDbm, 20);
|
||||
expect(philly.pathHashBytes, 2);
|
||||
expect(philly.source, RadioPresetSource.offband);
|
||||
expect(philly.offGrid, isFalse);
|
||||
expect(r.presets[1].offGrid, isTrue);
|
||||
expect(r.presets[1].region, 'Off-Grid');
|
||||
},
|
||||
);
|
||||
|
||||
test('drops retired entries without counting them as skipped', () {
|
||||
final r = parseOverlayPresets(
|
||||
overlay([
|
||||
overlayEntry('old', extra: {'status': 'retired'}),
|
||||
overlayEntry('new'),
|
||||
]),
|
||||
);
|
||||
expect(r.presets.map((p) => p.id), ['offband:new']);
|
||||
expect(r.skipped, 0);
|
||||
});
|
||||
|
||||
test('skips hand-edit mistakes: string numbers, bad TX, bad hash', () {
|
||||
final r = parseOverlayPresets(
|
||||
overlay([
|
||||
overlayEntry('a', extra: {'frequency': '909.75'}),
|
||||
overlayEntry('b', extra: {'tx_power': 40}),
|
||||
overlayEntry('c', extra: {'path_hash_size': '2'}),
|
||||
overlayEntry('d', extra: {'coding_rate': 4}),
|
||||
]),
|
||||
);
|
||||
expect(r.presets, isEmpty);
|
||||
expect(r.skipped, 4);
|
||||
});
|
||||
});
|
||||
|
||||
group('upstreamRegionFor (#727)', () {
|
||||
test('groups upstream titles by their leading region', () {
|
||||
expect(upstreamRegionFor('USA'), 'USA');
|
||||
expect(upstreamRegionFor('USA - Southern California'), 'USA');
|
||||
expect(upstreamRegionFor('Australia: QLD'), 'Australia');
|
||||
expect(upstreamRegionFor('Australia (Narrow)'), 'Australia');
|
||||
expect(upstreamRegionFor('EU/UK (Narrow)'), 'EU/UK');
|
||||
expect(upstreamRegionFor('Portugal 433'), 'Portugal');
|
||||
expect(upstreamRegionFor('Portugal 868'), 'Portugal');
|
||||
expect(upstreamRegionFor('Costa Rica'), 'Costa Rica');
|
||||
expect(upstreamRegionFor('New Zealand (Gisborne)'), 'New Zealand');
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
expect(pathHashModeForBytes(2), 1);
|
||||
expect(pathHashModeForBytes(3), 2);
|
||||
});
|
||||
|
||||
test('a published 2 never becomes mode 2 (3-byte hashes)', () {
|
||||
expect(pathHashModeForBytes(2), isNot(2));
|
||||
});
|
||||
|
||||
test('absent or out-of-range sizes send nothing', () {
|
||||
expect(pathHashModeForBytes(null), isNull);
|
||||
expect(pathHashModeForBytes(0), isNull);
|
||||
expect(pathHashModeForBytes(4), isNull);
|
||||
});
|
||||
|
||||
test('a parsed preset exposes its mode', () {
|
||||
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',
|
||||
},
|
||||
]),
|
||||
);
|
||||
expect(r.presets[0].pathHashMode, 2);
|
||||
expect(r.presets[1].pathHashMode, isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/models/radio_preset.dart';
|
||||
import 'package:meshcore_open/services/config_source_service.dart';
|
||||
import 'package:meshcore_open/services/radio_preset_service.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
// Fetches the real preset files from config-profiles (#748). Every other
|
||||
// preset test fakes the network, so a 404 on main passed them all and the
|
||||
// owner saw "Couldn't update presets" on a test build twice. This one fails
|
||||
// whenever the app's own refresh would.
|
||||
void main() {
|
||||
test(
|
||||
'refresh from config-profiles succeeds with no error',
|
||||
() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final service = RadioPresetService(
|
||||
prefs: await SharedPreferences.getInstance(),
|
||||
loadAsset: (_) async => throw StateError('bundled copies not used'),
|
||||
);
|
||||
addTearDown(service.dispose);
|
||||
|
||||
final ok = await service.refresh();
|
||||
|
||||
expect(service.refreshError, isNull, reason: 'refresh reported an error');
|
||||
expect(ok, isTrue);
|
||||
expect(service.skipped, 0);
|
||||
final sources = service.presets.map((p) => p.source).toSet();
|
||||
expect(sources, {RadioPresetSource.meshcore, RadioPresetSource.offband});
|
||||
},
|
||||
timeout: const Timeout(Duration(seconds: 60)),
|
||||
);
|
||||
|
||||
test(
|
||||
'a missing file on config-profiles is reported, not ignored',
|
||||
() async {
|
||||
final source = ConfigSourceService();
|
||||
addTearDown(source.dispose);
|
||||
await expectLater(
|
||||
source.fetchText('${kRadioPresetBaseUrl}missing-748.json'),
|
||||
throwsA(
|
||||
isA<ConfigSourceException>().having(
|
||||
(e) => '$e',
|
||||
'message',
|
||||
contains('HTTP 404'),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
timeout: const Timeout(Duration(seconds: 60)),
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,293 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/models/radio_preset.dart';
|
||||
import 'package:meshcore_open/models/radio_settings.dart';
|
||||
import 'package:meshcore_open/services/radio_preset_service.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
String upstreamFile(List<Map<String, dynamic>> entries) => jsonEncode({
|
||||
'format': kUpstreamPresetFormat,
|
||||
'format_version': 1,
|
||||
'source': 'https://api.meshcore.nz/api/v1/config',
|
||||
'credit': 'Liam Cottle / MeshCore',
|
||||
'updated_at': '2026-10-01T00:00:00Z',
|
||||
'suggested_radio_settings': {'entries': entries},
|
||||
});
|
||||
|
||||
String overlayFile(List<Map<String, dynamic>> presets) => jsonEncode({
|
||||
'format': kOverlayPresetFormat,
|
||||
'format_version': 1,
|
||||
'presets': presets,
|
||||
});
|
||||
|
||||
Map<String, dynamic> up(String title, {String freq = '910.525'}) => {
|
||||
'title': title,
|
||||
'frequency': freq,
|
||||
'spreading_factor': '7',
|
||||
'bandwidth': '62.5',
|
||||
'coding_rate': '5',
|
||||
};
|
||||
|
||||
Map<String, dynamic> ov(
|
||||
String id,
|
||||
String title, {
|
||||
double freq = 909.75,
|
||||
String region = 'USA',
|
||||
}) => {
|
||||
'id': id,
|
||||
'title': title,
|
||||
'region': region,
|
||||
'frequency': freq,
|
||||
'bandwidth': 500,
|
||||
'spreading_factor': 10,
|
||||
'coding_rate': 5,
|
||||
'status': 'published',
|
||||
};
|
||||
|
||||
RadioPreset preset(String title, String region, RadioPresetSource source) =>
|
||||
RadioPreset(
|
||||
id: '$source:$title',
|
||||
title: title,
|
||||
region: region,
|
||||
frequencyMHz: 910.525,
|
||||
bandwidth: LoRaBandwidth.bw62_5,
|
||||
spreadingFactor: LoRaSpreadingFactor.sf7,
|
||||
codingRate: LoRaCodingRate.cr4_5,
|
||||
source: source,
|
||||
);
|
||||
|
||||
void main() {
|
||||
late SharedPreferences prefs;
|
||||
final bundled = {
|
||||
'${kRadioPresetAssetDir}meshcore-upstream.json': upstreamFile([
|
||||
up('USA'),
|
||||
up('Canada'),
|
||||
]),
|
||||
'${kRadioPresetAssetDir}offband.json': overlayFile([
|
||||
ov('oki', 'USA - OKI-Mesh 500kHz Test'),
|
||||
]),
|
||||
};
|
||||
|
||||
Future<String> loadBundled(String path) async {
|
||||
final text = bundled[path];
|
||||
if (text == null) throw StateError('no asset $path');
|
||||
return text;
|
||||
}
|
||||
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
prefs = await SharedPreferences.getInstance();
|
||||
});
|
||||
|
||||
RadioPresetService service({
|
||||
Map<String, String>? remote,
|
||||
Object? remoteError,
|
||||
DateTime Function()? clock,
|
||||
}) => RadioPresetService(
|
||||
prefs: prefs,
|
||||
loadAsset: loadBundled,
|
||||
clock: clock,
|
||||
fetch: (url) async {
|
||||
if (remoteError != null) throw remoteError;
|
||||
final file = url.substring(kRadioPresetBaseUrl.length);
|
||||
final text = remote?[file];
|
||||
if (text == null) throw StateError('HTTP 404 for $url');
|
||||
return text;
|
||||
},
|
||||
);
|
||||
|
||||
group('mergeRadioPresets (#728)', () {
|
||||
test('an overlay entry replaces the upstream one with the same title', () {
|
||||
final merged = mergeRadioPresets(
|
||||
[
|
||||
preset('USA', 'USA', RadioPresetSource.meshcore),
|
||||
preset('Canada', 'Canada', RadioPresetSource.meshcore),
|
||||
],
|
||||
[preset('usa', 'USA', RadioPresetSource.offband)],
|
||||
);
|
||||
expect(merged.length, 2);
|
||||
final usa = merged.firstWhere((p) => p.title.toLowerCase() == 'usa');
|
||||
expect(usa.source, RadioPresetSource.offband);
|
||||
});
|
||||
|
||||
test('sorts by region, then title', () {
|
||||
final merged = mergeRadioPresets(
|
||||
[
|
||||
preset('USA', 'USA', RadioPresetSource.meshcore),
|
||||
preset('Australia', 'Australia', RadioPresetSource.meshcore),
|
||||
],
|
||||
[preset('USA - Arizona', 'USA', RadioPresetSource.offband)],
|
||||
);
|
||||
expect(merged.map((p) => p.title), ['Australia', 'USA', 'USA - Arizona']);
|
||||
});
|
||||
});
|
||||
|
||||
group('RadioPresetService (#728)', () {
|
||||
test('offline: loads the bundled copies when nothing is saved', () async {
|
||||
final s = service();
|
||||
await s.load();
|
||||
expect(s.presets.map((p) => p.title), [
|
||||
'Canada',
|
||||
'USA',
|
||||
'USA - OKI-Mesh 500kHz Test',
|
||||
]);
|
||||
expect(s.refreshError, isNull);
|
||||
expect(s.lastRefreshed, isNull);
|
||||
});
|
||||
|
||||
test('refresh replaces the list, saves it, and records the time', () async {
|
||||
final now = DateTime.utc(2026, 10, 1, 12);
|
||||
final s = service(
|
||||
clock: () => now,
|
||||
remote: {
|
||||
kUpstreamPresetFile: upstreamFile([up('USA'), up('Brazil')]),
|
||||
kOverlayPresetFile: overlayFile([
|
||||
ov('philly', 'USA - Philly Mesh', freq: 919.5),
|
||||
]),
|
||||
},
|
||||
);
|
||||
await s.load();
|
||||
expect(await s.refresh(), isTrue);
|
||||
expect(s.presets.map((p) => p.title), [
|
||||
'Brazil',
|
||||
'USA',
|
||||
'USA - Philly Mesh',
|
||||
]);
|
||||
expect(s.refreshError, isNull);
|
||||
expect(s.lastRefreshed, now);
|
||||
|
||||
// The saved copy is what the next launch starts from, even offline.
|
||||
final next = service(remoteError: StateError('offline'));
|
||||
await next.load();
|
||||
expect(next.presets.map((p) => p.title), contains('USA - Philly Mesh'));
|
||||
expect(next.lastRefreshed, now);
|
||||
});
|
||||
|
||||
test('an overlay edit reaches the app with no new build', () async {
|
||||
final s = service(
|
||||
remote: {
|
||||
kUpstreamPresetFile: upstreamFile([up('USA')]),
|
||||
kOverlayPresetFile: overlayFile([
|
||||
ov('oki', 'USA - OKI-Mesh 500kHz Test', freq: 911.5),
|
||||
]),
|
||||
},
|
||||
);
|
||||
await s.load();
|
||||
expect(
|
||||
s.presets.firstWhere((p) => p.id == 'offband:oki').frequencyMHz,
|
||||
909.75,
|
||||
);
|
||||
await s.refresh();
|
||||
expect(
|
||||
s.presets.firstWhere((p) => p.id == 'offband:oki').frequencyMHz,
|
||||
911.5,
|
||||
);
|
||||
});
|
||||
|
||||
test('a failed refresh keeps the list in use and reports why', () async {
|
||||
final s = service(remoteError: StateError('network down'));
|
||||
await s.load();
|
||||
final before = s.presets.map((p) => p.title).toList();
|
||||
expect(await s.refresh(), isFalse);
|
||||
expect(s.presets.map((p) => p.title), before);
|
||||
expect(s.refreshError, contains('network down'));
|
||||
expect(s.lastRefreshed, isNull);
|
||||
expect(prefs.getKeys(), isEmpty);
|
||||
});
|
||||
|
||||
test('a bad or empty file never replaces a good copy', () async {
|
||||
final s = service(
|
||||
remote: {
|
||||
kUpstreamPresetFile: '<html>502 Bad Gateway</html>',
|
||||
kOverlayPresetFile: overlayFile([]),
|
||||
},
|
||||
);
|
||||
await s.load();
|
||||
expect(await s.refresh(), isFalse);
|
||||
expect(s.presets.length, 3);
|
||||
expect(s.refreshError, contains(kUpstreamPresetFile));
|
||||
expect(s.refreshError, contains(kOverlayPresetFile));
|
||||
});
|
||||
|
||||
test('one good file is still taken when the other fails', () async {
|
||||
final s = service(
|
||||
remote: {
|
||||
kOverlayPresetFile: overlayFile([ov('az', 'USA - Arizona')]),
|
||||
},
|
||||
);
|
||||
await s.load();
|
||||
expect(await s.refresh(), isFalse);
|
||||
expect(s.presets.map((p) => p.title), ['Canada', 'USA', 'USA - Arizona']);
|
||||
expect(s.refreshError, contains(kUpstreamPresetFile));
|
||||
});
|
||||
|
||||
test('malformed entries are skipped and counted', () async {
|
||||
final s = service(
|
||||
remote: {
|
||||
kUpstreamPresetFile: upstreamFile([
|
||||
up('USA'),
|
||||
{'title': 'Broken'},
|
||||
]),
|
||||
kOverlayPresetFile: overlayFile([ov('az', 'USA - Arizona')]),
|
||||
},
|
||||
);
|
||||
await s.load();
|
||||
await s.refresh();
|
||||
expect(s.skipped, 1);
|
||||
expect(s.presets.map((p) => p.title), isNot(contains('Broken')));
|
||||
});
|
||||
|
||||
test(
|
||||
'refreshIfStale only refreshes an old or never-refreshed copy',
|
||||
() async {
|
||||
var now = DateTime.utc(2026, 10, 1, 12);
|
||||
var fetches = 0;
|
||||
final s = RadioPresetService(
|
||||
prefs: prefs,
|
||||
loadAsset: loadBundled,
|
||||
clock: () => now,
|
||||
fetch: (url) async {
|
||||
fetches++;
|
||||
return url.endsWith(kUpstreamPresetFile)
|
||||
? upstreamFile([up('USA')])
|
||||
: overlayFile([ov('az', 'USA - Arizona')]);
|
||||
},
|
||||
);
|
||||
await s.load();
|
||||
await s.refreshIfStale();
|
||||
expect(fetches, 2);
|
||||
now = now.add(const Duration(hours: 1));
|
||||
await s.refreshIfStale();
|
||||
expect(fetches, 2);
|
||||
now = now.add(const Duration(hours: 12));
|
||||
await s.refreshIfStale();
|
||||
expect(fetches, 4);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('bundled preset files (#728)', () {
|
||||
test('parse cleanly and do not clash on titles', () {
|
||||
final upstream = parseUpstreamPresets(
|
||||
File('assets/radio_presets/meshcore-upstream.json').readAsStringSync(),
|
||||
);
|
||||
final overlay = parseOverlayPresets(
|
||||
File('assets/radio_presets/offband.json').readAsStringSync(),
|
||||
);
|
||||
expect(upstream.skipped, 0);
|
||||
expect(overlay.skipped, 0);
|
||||
expect(upstream.presets.length, 26);
|
||||
expect(overlay.presets.length, 33);
|
||||
final merged = mergeRadioPresets(upstream.presets, overlay.presets);
|
||||
expect(merged.length, 59);
|
||||
final philly = merged.firstWhere((p) => p.title == 'USA - Philly Mesh');
|
||||
expect(philly.frequencyKHz, 919500);
|
||||
expect(philly.bandwidth, LoRaBandwidth.bw500);
|
||||
expect(philly.pathHashMode, 1);
|
||||
final euNarrow = merged.firstWhere((p) => p.title == 'EU/UK (Narrow)');
|
||||
expect(euNarrow.codingRate, LoRaCodingRate.cr4_8);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,164 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/models/radio_preset.dart';
|
||||
import 'package:meshcore_open/models/radio_settings.dart';
|
||||
import 'package:meshcore_open/services/radio_preset_service.dart';
|
||||
import 'package:meshcore_open/widgets/radio_preset_picker.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
RadioPreset preset(String title, String region, RadioPresetSource source) =>
|
||||
RadioPreset(
|
||||
id: '${source.name}:$title',
|
||||
title: title,
|
||||
region: region,
|
||||
frequencyMHz: 910.525,
|
||||
bandwidth: LoRaBandwidth.bw62_5,
|
||||
spreadingFactor: LoRaSpreadingFactor.sf7,
|
||||
codingRate: LoRaCodingRate.cr4_5,
|
||||
source: source,
|
||||
);
|
||||
|
||||
/// Menu rows only exist while the menu is open; the closed button shows
|
||||
/// titles from selectedItemBuilder instead.
|
||||
Finder menuItems({required bool enabled}) => find.byWidgetPredicate(
|
||||
(w) => w is DropdownMenuItem<String> && w.enabled == enabled,
|
||||
);
|
||||
|
||||
void main() {
|
||||
late RadioPresetService service;
|
||||
final presets = [
|
||||
preset('Australia', 'Australia', RadioPresetSource.meshcore),
|
||||
preset('USA', 'USA', RadioPresetSource.meshcore),
|
||||
preset('USA - Philly Mesh', 'USA', RadioPresetSource.offband),
|
||||
];
|
||||
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
service = RadioPresetService(
|
||||
prefs: await SharedPreferences.getInstance(),
|
||||
loadAsset: (_) async => throw StateError('no assets in this test'),
|
||||
fetch: (_) async => throw StateError('offline'),
|
||||
);
|
||||
});
|
||||
|
||||
Future<List<RadioPreset>> pump(
|
||||
WidgetTester tester, {
|
||||
String? selectedId,
|
||||
}) async {
|
||||
final picked = <RadioPreset>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: ListenableBuilder(
|
||||
listenable: service,
|
||||
builder: (context, _) => RadioPresetPicker(
|
||||
service: service,
|
||||
presets: presets,
|
||||
selectedId: selectedId,
|
||||
onSelected: picked.add,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return picked;
|
||||
}
|
||||
|
||||
Future<void> openMenu(WidgetTester tester) async {
|
||||
await tester.tap(find.byType(DropdownButtonFormField<String>));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('groups presets under region headers with source labels (#729)', (
|
||||
tester,
|
||||
) async {
|
||||
await pump(tester);
|
||||
await openMenu(tester);
|
||||
|
||||
// One non-selectable header per region, one selectable row per preset.
|
||||
expect(menuItems(enabled: false), findsNWidgets(2));
|
||||
expect(menuItems(enabled: true), findsNWidgets(3));
|
||||
expect(find.text('MeshCore'), findsNWidgets(2));
|
||||
expect(find.text('Offband'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('selecting an entry reports it; a region header does nothing', (
|
||||
tester,
|
||||
) async {
|
||||
final picked = await pump(tester);
|
||||
await openMenu(tester);
|
||||
|
||||
await tester.tap(menuItems(enabled: false).last, warnIfMissed: false);
|
||||
await tester.pumpAndSettle();
|
||||
expect(picked, isEmpty);
|
||||
|
||||
// The menu may have closed on the header tap; reopen it if so.
|
||||
if (menuItems(enabled: true).evaluate().isEmpty) {
|
||||
await openMenu(tester);
|
||||
}
|
||||
await tester.tap(find.text('USA - Philly Mesh').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(picked.single.id, 'offband:USA - Philly Mesh');
|
||||
});
|
||||
|
||||
testWidgets('starts on the selected preset', (tester) async {
|
||||
await pump(tester, selectedId: 'offband:USA - Philly Mesh');
|
||||
final field = tester.widget<DropdownButtonFormField<String>>(
|
||||
find.byType(DropdownButtonFormField<String>),
|
||||
);
|
||||
expect(field.initialValue, 'offband:USA - Philly Mesh');
|
||||
});
|
||||
|
||||
testWidgets('an unknown selection shows no preset rather than failing', (
|
||||
tester,
|
||||
) async {
|
||||
await pump(tester, selectedId: 'offband:gone');
|
||||
final field = tester.widget<DropdownButtonFormField<String>>(
|
||||
find.byType(DropdownButtonFormField<String>),
|
||||
);
|
||||
expect(field.initialValue, isNull);
|
||||
});
|
||||
|
||||
testWidgets('a good refresh shows no error (#748)', (tester) async {
|
||||
final files = {
|
||||
for (final f in [kUpstreamPresetFile, kOverlayPresetFile])
|
||||
f: File('$kRadioPresetAssetDir$f').readAsStringSync(),
|
||||
};
|
||||
service = RadioPresetService(
|
||||
prefs: await SharedPreferences.getInstance(),
|
||||
loadAsset: (_) async => throw StateError('no assets in this test'),
|
||||
fetch: (url) async => files[url.split('/').last]!,
|
||||
);
|
||||
await pump(tester);
|
||||
await tester.tap(find.byIcon(Icons.refresh));
|
||||
await tester.pumpAndSettle();
|
||||
expect(service.refreshError, isNull);
|
||||
expect(find.textContaining('Presets updated'), findsOneWidget);
|
||||
expect(
|
||||
find.text("Couldn't update presets. Showing the saved list."),
|
||||
findsNothing,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a failed refresh stays on screen as an error', (tester) async {
|
||||
await pump(tester);
|
||||
expect(
|
||||
find.text('Presets included with this version of the app'),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tap(find.byIcon(Icons.refresh));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.text("Couldn't update presets. Showing the saved list."),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in new issue