aboutsummaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2024-01-02 15:12:47 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2024-01-02 15:12:47 +0100
commit4ba802d0c73a1a1664b4d3e17757e54aeefd81f7 (patch)
tree7c793de9b284e5212a7872a7fb2b74fec303895b /src/config.rs
parent8d79d7640cadab30ff1e7bfa8df41eb08ffbdf48 (diff)
downloadcats-radio-node-4ba802d0c73a1a1664b4d3e17757e54aeefd81f7.tar.gz
cats-radio-node-4ba802d0c73a1a1664b4d3e17757e54aeefd81f7.tar.bz2
cats-radio-node-4ba802d0c73a1a1664b4d3e17757e54aeefd81f7.zip
Add default config, and start adding form
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs67
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<()> {