75 lines
2.1 KiB
Rust
75 lines
2.1 KiB
Rust
use std::{path::PathBuf, sync::OnceLock};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::types::Coords;
|
|
|
|
pub(super) static CONFIG_PATH: OnceLock<PathBuf> = OnceLock::new();
|
|
static CONFIG: OnceLock<Config> = OnceLock::new();
|
|
|
|
pub fn access_config<'a>() -> &'a Config {
|
|
CONFIG.get_or_init(|| {
|
|
serde_json::from_str(&std::fs::read_to_string(CONFIG_PATH.get().unwrap()).unwrap()).unwrap()
|
|
})
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
#[serde(default)]
|
|
pub struct Config {
|
|
pub charge_rate_update_interval_seconds: u64,
|
|
pub tesla_update_interval_seconds: u64,
|
|
pub tesla_update_interval_while_charging_seconds: u64,
|
|
pub pl_watch_interval_seconds: u64,
|
|
pub pl_timeout_milliseconds: u64,
|
|
pub coords: Coords,
|
|
pub serial_port: String,
|
|
pub baud_rate: u32,
|
|
pub shutoff_voltage: f64,
|
|
pub shutoff_voltage_time_seconds: u64,
|
|
pub min_rate: i64,
|
|
pub max_rate: i64,
|
|
pub duty_cycle_too_high: f64,
|
|
pub duty_cycle_too_low: f64,
|
|
pub additional_charge_controllers: Vec<ChargeControllerConfig>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
pub enum ChargeControllerConfig {
|
|
Pl {
|
|
serial_port: String,
|
|
baud_rate: u32,
|
|
timeout_milliseconds: u64,
|
|
watch_interval_seconds: u64,
|
|
},
|
|
Tristar {
|
|
serial_port: String,
|
|
baud_rate: i32,
|
|
watch_interval_seconds: u64,
|
|
},
|
|
}
|
|
|
|
impl Default for Config {
|
|
fn default() -> Self {
|
|
Self {
|
|
charge_rate_update_interval_seconds: 30,
|
|
tesla_update_interval_seconds: 120,
|
|
tesla_update_interval_while_charging_seconds: 5,
|
|
pl_watch_interval_seconds: 30,
|
|
pl_timeout_milliseconds: 250,
|
|
coords: Coords {
|
|
latitude: 0.,
|
|
longitude: 0.,
|
|
},
|
|
serial_port: String::from("/dev/ttyUSB0"),
|
|
baud_rate: 9600,
|
|
shutoff_voltage: 52.,
|
|
shutoff_voltage_time_seconds: 15,
|
|
min_rate: 5,
|
|
max_rate: 10,
|
|
duty_cycle_too_high: 0.9,
|
|
duty_cycle_too_low: 0.7,
|
|
additional_charge_controllers: Vec::new(),
|
|
}
|
|
}
|
|
}
|