()
| 12 | static REGIONS: LazyLock<RwLock<RegionSet>> = LazyLock::new(|| RwLock::new(RegionSet::new())); |
| 13 | |
| 14 | pub fn setup() -> Result<()> { |
| 15 | info!("Setting up regions"); |
| 16 | let conf = config::get(); |
| 17 | |
| 18 | reset(); |
| 19 | |
| 20 | for r in &conf.regions { |
| 21 | let span = span!(Level::INFO, "setup", common_name = %r.common_name, region_id = %r.id); |
| 22 | let _guard = span.enter(); |
| 23 | |
| 24 | if !conf.network.enabled_regions.contains(&r.id) { |
| 25 | continue; |
| 26 | } |
| 27 | |
| 28 | info!("Configuring region"); |
| 29 | |
| 30 | let mut region_conf = region::get( |
| 31 | r.common_name, |
| 32 | r.network.repeater_compatible, |
| 33 | r.network.dwell_time_400ms, |
| 34 | ); |
| 35 | |
| 36 | for ec in &r.network.extra_channels { |
| 37 | trace!( |
| 38 | frequency = ec.frequency, |
| 39 | data_rates = ?ec.data_rates, |
| 40 | "Adding extra channel" |
| 41 | ); |
| 42 | region_conf |
| 43 | .add_channel(ec.frequency, ec.data_rates.clone()) |
| 44 | .context("Add channel")?; |
| 45 | } |
| 46 | |
| 47 | if !r.network.enabled_uplink_channels.is_empty() { |
| 48 | trace!("Disabling all channels first"); |
| 49 | for i in region_conf.get_enabled_uplink_channel_indices() { |
| 50 | region_conf.disable_uplink_channel_index(i)?; |
| 51 | } |
| 52 | |
| 53 | trace!(channels = ?r.network.enabled_uplink_channels, "Enabling channels"); |
| 54 | for i in &r.network.enabled_uplink_channels { |
| 55 | region_conf.enable_uplink_channel_index(*i)?; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | set(&r.id, region_conf); |
| 60 | } |
| 61 | |
| 62 | Ok(()) |
| 63 | } |
| 64 | |
| 65 | fn reset() { |
| 66 | let mut regions_w = REGIONS.write().unwrap(); |
no test coverage detected