From af793c57ecc2fd1d56a1041ad6361e2aeb9fdb29 Mon Sep 17 00:00:00 2001 From: alban Date: Sat, 3 Jun 2023 17:52:06 +0200 Subject: [PATCH 1/3] feat: add gitignore --- .gitignore | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index eb5a316..0e205d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,20 @@ -target + +# Configuration file +Settings.* + +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +.idea From 4362b1b064100ae474def9342310550ded3dc11b Mon Sep 17 00:00:00 2001 From: alban Date: Sat, 3 Jun 2023 17:52:29 +0200 Subject: [PATCH 2/3] feat: add configuration file management --- Cargo.toml | 1 + src/conf.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 7 ++++++- 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/conf.rs diff --git a/Cargo.toml b/Cargo.toml index 435bde2..1b4a46d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +config = "0.13.3" ctrlc = "3.4.0" helios-dac = { version = "0.1", default-features = false, features = ["native"] } redis = "0.23.0" diff --git a/src/conf.rs b/src/conf.rs new file mode 100644 index 0000000..871d044 --- /dev/null +++ b/src/conf.rs @@ -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, + dac_url : Option +} + + +pub fn load_config( path : &str )-> Result> { + + 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::()?; + // .try_deserialize::>()?; + + println!( + "{:?}", + conf + ); + + Ok(conf) +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index ddf3328..b5ae005 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ /// mod redis_ctrl; +mod conf; use helios_dac::{Frame, Point, @@ -15,11 +16,15 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use redis_ctrl::{RedisCtrl,Order}; +use conf::{load_config}; + const CENTER : (u16,u16) = (2000, 2000); - pub fn main() -> Result<(), Box> { + + let config = load_config("Settings")?; + let running = Arc::new(AtomicBool::new(true)); let r = running.clone(); From 6bcfc831a6a9871c3176f5a50c7cf7047469b5b7 Mon Sep 17 00:00:00 2001 From: alban Date: Sat, 3 Jun 2023 17:53:48 +0200 Subject: [PATCH 3/3] feat: add template settings --- copyme.Settings.toml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 copyme.Settings.toml diff --git a/copyme.Settings.toml b/copyme.Settings.toml new file mode 100644 index 0000000..c9c3513 --- /dev/null +++ b/copyme.Settings.toml @@ -0,0 +1,6 @@ +laser_id = 1 +debug = "true" +redis_url = "127.0.0.1" +dac_family = "Helios" +dac_id = 1 +dac_url = "192.168.1.68"