feat: add configuration file management
This commit is contained in:
parent
af793c57ec
commit
4362b1b064
@ -6,6 +6,7 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
config = "0.13.3"
|
||||||
ctrlc = "3.4.0"
|
ctrlc = "3.4.0"
|
||||||
helios-dac = { version = "0.1", default-features = false, features = ["native"] }
|
helios-dac = { version = "0.1", default-features = false, features = ["native"] }
|
||||||
redis = "0.23.0"
|
redis = "0.23.0"
|
||||||
|
47
src/conf.rs
Normal file
47
src/conf.rs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
use config::Config;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Deserialize,Debug)]
|
||||||
|
pub enum DacFamily {
|
||||||
|
Helios,
|
||||||
|
Etherdream
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize,Debug)]
|
||||||
|
pub struct Conf{
|
||||||
|
laser_id : u8,
|
||||||
|
debug : bool,
|
||||||
|
redis_url : String,
|
||||||
|
dac_family: DacFamily,
|
||||||
|
dac_id : Option<u8>,
|
||||||
|
dac_url : Option<String>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn load_config( path : &str )-> Result<Conf, Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
|
let conf_builder = Config::builder()
|
||||||
|
.add_source(config::File::with_name(path));
|
||||||
|
|
||||||
|
|
||||||
|
let settings = match conf_builder.build() {
|
||||||
|
Ok(conf) => conf,
|
||||||
|
Err(err) => {
|
||||||
|
println!("Invalid configuration file / missing file: {:?}", err);
|
||||||
|
return Err(Box::new(err))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let conf = settings
|
||||||
|
.try_deserialize::<Conf>()?;
|
||||||
|
// .try_deserialize::<HashMap<String, String>>()?;
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"{:?}",
|
||||||
|
conf
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(conf)
|
||||||
|
}
|
@ -4,6 +4,7 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
mod redis_ctrl;
|
mod redis_ctrl;
|
||||||
|
mod conf;
|
||||||
|
|
||||||
use helios_dac::{Frame,
|
use helios_dac::{Frame,
|
||||||
Point,
|
Point,
|
||||||
@ -15,11 +16,15 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use redis_ctrl::{RedisCtrl,Order};
|
use redis_ctrl::{RedisCtrl,Order};
|
||||||
|
use conf::{load_config};
|
||||||
|
|
||||||
|
|
||||||
const CENTER : (u16,u16) = (2000, 2000);
|
const CENTER : (u16,u16) = (2000, 2000);
|
||||||
|
|
||||||
|
|
||||||
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
|
let config = load_config("Settings")?;
|
||||||
|
|
||||||
let running = Arc::new(AtomicBool::new(true));
|
let running = Arc::new(AtomicBool::new(true));
|
||||||
let r = running.clone();
|
let r = running.clone();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user