Support yaml config and run for swissfel-daqbuf-ca

This commit is contained in:
Dominik Werder
2023-01-06 16:25:46 +01:00
parent f781166053
commit 6b974e572f
7 changed files with 24 additions and 13 deletions

View File

@@ -18,6 +18,7 @@ bytes = "1.0.1"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
serde_yaml = "0.9.16"
chrono = "0.4"
url = "2.2.2"
clap = { version = "4.0.22", features = ["derive", "cargo"] }

View File

@@ -51,13 +51,23 @@ async fn go() -> Result<(), Error> {
match opts.subcmd {
SubCmd::Retrieval(subcmd) => {
info!("daqbuffer {}", clap::crate_version!());
let mut config_file = File::open(subcmd.config).await?;
let mut config_file = File::open(&subcmd.config).await?;
let mut buf = Vec::new();
config_file.read_to_end(&mut buf).await?;
let node_config: NodeConfig = serde_json::from_slice(&buf)?;
let node_config: Result<NodeConfigCached, Error> = node_config.into();
let node_config = node_config?;
daqbufp2::run_node(node_config.clone()).await?;
if let Ok(cfg) = serde_json::from_slice::<NodeConfig>(&buf) {
let cfg: Result<NodeConfigCached, Error> = cfg.into();
let cfg = cfg?;
daqbufp2::run_node(cfg).await?;
} else if let Ok(cfg) = serde_yaml::from_slice::<NodeConfig>(&buf) {
let cfg: Result<NodeConfigCached, Error> = cfg.into();
let cfg = cfg?;
daqbufp2::run_node(cfg).await?;
} else {
return Err(Error::with_msg_no_trace(format!(
"can not parse config at {}",
subcmd.config
)));
}
}
SubCmd::Proxy(subcmd) => {
info!("daqbuffer proxy {}", clap::crate_version!());