diff options
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 67 |
1 files changed, 60 insertions, 7 deletions
diff --git a/src/config.rs b/src/config.rs index 51bf507..33ba361 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,22 +2,41 @@ use std::fs; use anyhow::Context; use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct FelinetConfig { pub enabled: bool, pub address: String, } -#[derive(Serialize, Deserialize, Clone)] +impl Default for FelinetConfig { + fn default() -> Self { + FelinetConfig { + enabled: false, + address: "https://felinet.cats.radio".to_owned() + } + } +} + +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct TunnelConfig { pub enabled: bool, pub local_ip: String, pub netmask: String, } +impl Default for TunnelConfig { + fn default() -> Self { + TunnelConfig { + enabled: false, + local_ip: "10.73.14.1".to_owned(), + netmask: "255.255.255.0".to_owned(), + } + } +} + type DurationSeconds = std::num::NonZeroU32; -#[derive(Serialize, Deserialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct BeaconConfig { pub period_seconds: Option<DurationSeconds>, #[serde(default)] @@ -31,7 +50,23 @@ pub struct BeaconConfig { pub tx_power: Option<f32>, } -#[derive(Serialize, Deserialize, Clone)] +impl Default for BeaconConfig { + fn default() -> Self { + BeaconConfig { + period_seconds: None, + max_hops: 3, + latitude: None, + longitude: None, + altitude: None, + comment: None, + antenna_height: None, + antenna_gain: None, + tx_power: None, + } + } +} + +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct Config { pub callsign: String, pub ssid: u8, @@ -39,15 +74,33 @@ pub struct Config { pub icon: u16, pub felinet: FelinetConfig, pub beacon: BeaconConfig, - pub tunnel: Option<TunnelConfig>, + pub tunnel: TunnelConfig, +} + +impl Default for Config { + fn default() -> Self { + Config { + callsign: "CHANGEME".to_owned(), + ssid: 0, + icon: 0, + felinet: Default::default(), + beacon: Default::default(), + tunnel: Default::default(), + } + } } const CONFIGFILE : &str = "node-config.toml"; impl Config { pub fn load() -> anyhow::Result<Self> { - let file_contents = fs::read_to_string(CONFIGFILE)?; - toml::from_str(&file_contents).context("parsing config file") + if std::path::Path::new(CONFIGFILE).exists() { + let file_contents = fs::read_to_string(CONFIGFILE)?; + toml::from_str(&file_contents).context("parsing config file") + } + else { + Ok(Default::default()) + } } pub fn store(&self) -> anyhow::Result<()> { |