s0-meter/src/main.rs

69 lines
1.9 KiB
Rust
Raw Normal View History

2021-02-11 15:05:10 +01:00
#[macro_use]
extern crate clap;
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
use async_std;
use async_std::task;
2021-02-11 15:05:10 +01:00
const APP_VERSION: &'static str = env!("CARGO_PKG_VERSION");
2021-02-11 15:05:10 +01:00
const DEFAULT_CONFIG_FILE_NAME: &str = "/etc/s0_logger.cfg";
const DEFAULT_IP_ADDRESS: &str = "127.0.0.1";
const DEFAULT_IP_PORT: &str = "6310";
2021-02-11 15:05:10 +01:00
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);
if cfg!(feature = "rppal") {
println!("Will access GPIO pins");
} else if cfg!(feature = "hal") {
println!("Will access HAL");
} else {
println!("Will NOT access GPIO pins");
}
let rest_ip_addr = DEFAULT_IP_ADDRESS;
let rest_ip_port = DEFAULT_IP_PORT;
2021-02-23 00:08:28 +01:00
let rest_api_config = rest_api::RestApiConfig {
ip_and_port: format!("{}:{}", &rest_ip_addr, &rest_ip_port),
2021-02-23 00:08:28 +01:00
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
}