s0-meter/src/main.rs

54 lines
1.5 KiB
Rust
Raw Normal View History

2021-02-11 15:05:10 +01:00
#[macro_use]
extern crate clap;
2021-02-23 00:08:28 +01:00
use async_std::task;
2021-02-11 22:09:29 +01:00
mod cfg_reader;
2021-02-25 21:59:09 +01:00
mod pulse_counter;
2021-02-23 00:08:28 +01:00
mod rest_api;
2021-02-11 22:09:29 +01:00
2021-02-11 15:05:10 +01:00
const APP_VERSION: &'static str = env!("CARGO_PKG_VERSION");
const DEFAULT_CONFIG_FILE_NAME: &str = "/etc/s0_logger.cfg";
fn main() {
let cli_args = clap_app!(s0_meter =>
(version: APP_VERSION)
(author: "Harald Kube <harald.kube@gmx.de")
(about: "Listen for S0 pulses at the given GPIO pins")
(@arg v: -v ... "Set the verbosity level (up to -vvv)")
(@arg config: -c --config +takes_value "The name of the config file (default: /etc/s0_logger.cfg)")
).get_matches();
let log_level = cli_args.occurrences_of("v");
match log_level {
0 => println!("No logging"),
1 => println!("A little logging"),
2 => println!("A little more logging"),
_ => println!("A lot logging"),
};
let config_file_name = cli_args
.value_of("config")
.unwrap_or(DEFAULT_CONFIG_FILE_NAME);
println!("Read the config from file '{}'", config_file_name);
2021-02-23 00:08:28 +01:00
let rest_api_config = rest_api::RestApiConfig {
ip_and_port: String::from("127.0.0.1:8080"),
get_channels: fake_get_channels,
get_pulses_by_channel: fake_get_pulses_by_channel,
};
let _ = task::block_on(rest_api::start(&rest_api_config));
}
fn fake_get_channels() -> Vec<usize> {
vec![]
}
fn fake_get_pulses_by_channel(_: usize) -> Result<Vec<rest_api::PulseInfo>, std::io::Error> {
Err(std::io::Error::new(
std::io::ErrorKind::NotFound,
"Not implemented",
))
2021-02-11 15:05:10 +01:00
}