From 8d79d7640cadab30ff1e7bfa8df41eb08ffbdf48 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Tue, 2 Jan 2024 14:30:44 +0100 Subject: Add more pages, improve nav --- src/config.rs | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/config.rs (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..51bf507 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,57 @@ +use std::fs; +use anyhow::Context; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Clone)] +pub struct FelinetConfig { + pub enabled: bool, + pub address: String, +} + +#[derive(Serialize, Deserialize, Clone)] +pub struct TunnelConfig { + pub enabled: bool, + pub local_ip: String, + pub netmask: String, +} + +type DurationSeconds = std::num::NonZeroU32; + +#[derive(Serialize, Deserialize, Clone)] +pub struct BeaconConfig { + pub period_seconds: Option, + #[serde(default)] + pub max_hops: u8, + pub latitude: Option, + pub longitude: Option, + pub altitude: Option, + pub comment: Option, + pub antenna_height: Option, + pub antenna_gain: Option, + pub tx_power: Option, +} + +#[derive(Serialize, Deserialize, Clone)] +pub struct Config { + pub callsign: String, + pub ssid: u8, + #[serde(default)] + pub icon: u16, + pub felinet: FelinetConfig, + pub beacon: BeaconConfig, + pub tunnel: Option, +} + +const CONFIGFILE : &str = "node-config.toml"; + +impl Config { + pub fn load() -> anyhow::Result { + let file_contents = fs::read_to_string(CONFIGFILE)?; + toml::from_str(&file_contents).context("parsing config file") + } + + pub fn store(&self) -> anyhow::Result<()> { + fs::write(CONFIGFILE, toml::to_string_pretty(&self)?) + .context("writing config file") + } +} -- cgit v1.2.3