refactor conf
This commit is contained in:
parent
61ede78868
commit
edba874ae7
@ -11,10 +11,10 @@ debug = "true"
|
|||||||
redis_url = "redis://127.0.0.1:6379/"
|
redis_url = "redis://127.0.0.1:6379/"
|
||||||
|
|
||||||
# Either Helios or Etherdream
|
# Either Helios or Etherdream
|
||||||
dac_family = "Helios"
|
|
||||||
|
|
||||||
# For Helios. USB Device Id of the DAC
|
# For Helios. USB Device Id of the DAC
|
||||||
dac_id = 0
|
[dac.helios]
|
||||||
|
id = 0
|
||||||
|
|
||||||
# For Etherdream. IP of the DAC
|
# For Etherdream. IP of the DAC
|
||||||
dac_url = "192.168.1.68"
|
# [dac.etherdream]
|
||||||
|
# url = "192.168.1.68"
|
||||||
|
@ -11,7 +11,11 @@ fn do_something() -> redis::RedisResult<()> {
|
|||||||
|
|
||||||
/* do something here */
|
/* do something here */
|
||||||
//let val : String = con.get("/pl/0/0")?;
|
//let val : String = con.get("/pl/0/0")?;
|
||||||
let _ = con.set("/pl/0/0", "[(150.0, 230.0, 65280), (170.0, 170.0, 65280), (230.0, 170.0, 65280), (210.0, 230.0, 65280), (150.0, 230.0, 65280)]")?;
|
let _ = con.set("/pl/0/0", "[(150.0, 230.0, 65280), \
|
||||||
|
(170.0, 170.0, 65280), \
|
||||||
|
(230.0, 170.0, 65280), \
|
||||||
|
(210.0, 230.0, 65280), \
|
||||||
|
(150.0, 230.0, 65280)]")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
32
src/conf.rs
32
src/conf.rs
@ -1,21 +1,31 @@
|
|||||||
use config::Config;
|
use config::Config;
|
||||||
use serde::Deserialize;
|
use serde::{Serialize,Deserialize};
|
||||||
use crate::errors::LJResult;
|
use crate::errors::LJResult;
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub enum DacFamily {
|
|
||||||
Helios,
|
|
||||||
Etherdream,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
|
||||||
pub struct Conf {
|
pub struct Conf {
|
||||||
pub laser_id: u8,
|
pub laser_id: u8,
|
||||||
pub debug: bool,
|
pub debug: bool,
|
||||||
pub redis_url: String,
|
pub redis_url: String,
|
||||||
pub dac_family: DacFamily,
|
pub dac: DacFamily
|
||||||
pub dac_id: Option<u8>,
|
}
|
||||||
pub dac_url: Option<String>,
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub enum DacFamily {
|
||||||
|
#[serde(rename = "helios")]
|
||||||
|
Helios(HeliosConf),
|
||||||
|
#[serde(rename = "etherdream")]
|
||||||
|
Etherdream(EtherDreamConf),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct HeliosConf {
|
||||||
|
pub id: u8
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct EtherDreamConf {
|
||||||
|
pub url: String
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Conf {
|
impl Conf {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# file: valid.toml
|
# file: Settings.toml
|
||||||
|
# Rename me !
|
||||||
|
|
||||||
# The main key of your laser in LJ
|
# The main key of your laser in LJ
|
||||||
laser_id = 0
|
laser_id = 0
|
||||||
@ -6,14 +7,14 @@ laser_id = 0
|
|||||||
# Activate for more debug
|
# Activate for more debug
|
||||||
debug = "true"
|
debug = "true"
|
||||||
|
|
||||||
# Redis URL as IP:port
|
# Redis URL as redis://IP:port/
|
||||||
redis_url = "127.0.0.1"
|
redis_url = "redis://127.0.0.1:6379/"
|
||||||
|
|
||||||
# Either Helios or Etherdream
|
# Either Helios or Etherdream
|
||||||
dac_family = "Helios"
|
|
||||||
|
|
||||||
# For Helios. USB Device Id of the DAC
|
# For Helios. USB Device Id of the DAC
|
||||||
dac_id = 0
|
[dac.helios]
|
||||||
|
id = 0
|
||||||
|
|
||||||
# For Etherdream. IP of the DAC
|
# For Etherdream. IP of the DAC
|
||||||
dac_url = "192.168.1.68"
|
# [dac.etherdream]
|
||||||
|
# url = "192.168.1.68"
|
||||||
|
15
tests/settings/valid_etherdream.toml
Normal file
15
tests/settings/valid_etherdream.toml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# file: Settings.toml
|
||||||
|
# Rename me !
|
||||||
|
|
||||||
|
# The main key of your laser in LJ
|
||||||
|
laser_id = 0
|
||||||
|
|
||||||
|
# Activate for more debug
|
||||||
|
debug = "true"
|
||||||
|
|
||||||
|
# Redis URL as redis://IP:port/
|
||||||
|
redis_url = "redis://127.0.0.1:6379/"
|
||||||
|
|
||||||
|
# For Etherdream. IP of the DAC
|
||||||
|
[dac.etherdream]
|
||||||
|
url = "192.168.1.68"
|
@ -1,4 +1,4 @@
|
|||||||
use lj_rust::conf::{Conf, DacFamily};
|
use lj_rust::conf::{Conf, DacFamily, HeliosConf, EtherDreamConf};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn it_loads_a_valid_conf() {
|
fn it_loads_a_valid_conf() {
|
||||||
@ -14,19 +14,21 @@ fn it_fails_invalid_conf() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn it_finds_struct_fields() {
|
fn it_finds_struct_fields() {
|
||||||
let config = match Conf::new("tests/settings/valid") {
|
let config = Conf::new("tests/settings/valid").unwrap();
|
||||||
Ok(c) => c,
|
assert_eq!(config.laser_id, 0);
|
||||||
Err(err) => {
|
|
||||||
panic!("Unable to load config file: {:?}", err)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
assert_eq!(config.laser_id, u8::from(0));
|
|
||||||
assert_eq!(config.debug, true);
|
assert_eq!(config.debug, true);
|
||||||
assert_eq!(config.redis_url, String::from("127.0.0.1"));
|
assert_eq!(config.redis_url, "redis://127.0.0.1:6379/");
|
||||||
assert!(match config.dac_family {
|
assert!(match config.dac {
|
||||||
DacFamily::Helios => true,
|
DacFamily::Helios(HeliosConf { id: 0 }) => true,
|
||||||
|
_ => false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_finds_etherdream_fields() {
|
||||||
|
let config = Conf::new("tests/settings/valid_etherdream").unwrap();
|
||||||
|
assert!(match config.dac {
|
||||||
|
DacFamily::Etherdream(EtherDreamConf { url }) if url == "192.168.1.68" => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
});
|
});
|
||||||
assert_eq!(config.dac_id, Some(0));
|
|
||||||
assert_eq!(config.dac_url, Some(String::from("192.168.1.68")));
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user