Mercurial > templog
comparison rust/src/main.rs @ 601:8c21df3711e2 rust
rigid_config
more on sensors
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 15 Feb 2017 23:58:02 +0800 |
parents | f71cf1ad745f |
children | b45b8b4cf0f5 |
comparison
equal
deleted
inserted
replaced
600:9c76f3cf01ea | 601:8c21df3711e2 |
---|---|
3 #[macro_use] | 3 #[macro_use] |
4 extern crate log; | 4 extern crate log; |
5 extern crate env_logger; | 5 extern crate env_logger; |
6 extern crate rustc_serialize; | 6 extern crate rustc_serialize; |
7 extern crate time; | 7 extern crate time; |
8 | |
9 #[macro_use] | |
10 extern crate lazy_static; | |
8 | 11 |
9 #[macro_use] | 12 #[macro_use] |
10 extern crate serde_derive; | 13 extern crate serde_derive; |
11 extern crate serde; | 14 extern crate serde; |
12 | 15 |
28 mod paramwaiter; | 31 mod paramwaiter; |
29 | 32 |
30 use types::*; | 33 use types::*; |
31 use config::Config; | 34 use config::Config; |
32 | 35 |
33 fn run(config: &Config, nowait: bool, testmode: bool) { | 36 fn run(nowait: bool, testmode: bool) { |
34 | 37 |
35 let mut core = Core::new().unwrap(); | 38 let mut core = Core::new().unwrap(); |
36 let handle = core.handle(); | 39 let handle = core.handle(); |
37 | 40 |
38 let mut paramh = ParamHolder::new(); | 41 let mut paramh = ParamHolder::new(); |
39 let mut fridge = fridge::Fridge::new(config, nowait, paramh.p, &handle); | 42 let mut fridge = fridge::Fridge::new(nowait, paramh.p, &handle); |
40 | 43 |
41 let (fridge_reading_s, fridge_reading_r) = mpsc::channel(1); | 44 let (fridge_reading_s, fridge_reading_r) = mpsc::channel(1); |
42 let fridge_reading_r = fridge_reading_r.map_err(|_| io::Error::new(io::ErrorKind::Other, "Problem with fridge_reading_r channel")); | 45 let fridge_reading_r = fridge_reading_r.map_err(|_| io::Error::new(io::ErrorKind::Other, "Problem with fridge_reading_r channel")); |
43 | 46 |
44 let sensor_stream = if testmode { | 47 let sensor_stream = if testmode { |
45 sensor::TestSensor::stream(&handle, config) | 48 sensor::TestSensor::stream(&handle) |
46 } else { | 49 } else { |
47 sensor::OneWireSensor::stream(&handle, config) | 50 sensor::OneWireSensor::stream(&handle) |
48 }; | 51 }; |
49 | 52 |
50 // Send the sensors of interest to the fridge (fridge_reading_s), | 53 // Send the sensors of interest to the fridge (fridge_reading_s), |
51 // while streaming them all to the web sender. | 54 // while streaming them all to the web sender. |
52 let s = sensor_stream.map(|r| { | 55 let s = sensor_stream.map(|r| { |
133 std::process::exit(0); | 136 std::process::exit(0); |
134 } | 137 } |
135 args | 138 args |
136 } | 139 } |
137 | 140 |
141 fn load_config() -> Config { | |
142 let mut nconfig = config::Config::default(); | |
143 | |
144 let conf_filename = "tempserver.conf"; | |
145 nconfig.merge_file(conf_filename) | |
146 .unwrap_or_else(|e| { | |
147 println!("Couldn't parse {}: {}", conf_filename, e); | |
148 std::process::exit(1); | |
149 }) | |
150 } | |
151 | |
152 lazy_static! { | |
153 static ref rigid_config: Config = load_config(); | |
154 } | |
155 | |
138 fn main() { | 156 fn main() { |
139 let mut config = config::Config::default(); | |
140 | 157 |
141 let args = handle_args(); | 158 let args = handle_args(); |
142 setup_log(args.flag_debug); | 159 setup_log(args.flag_debug); |
143 //env_logger::init().unwrap(); | 160 //env_logger::init().unwrap(); |
144 | 161 |
145 info!("wort-templog"); | 162 info!("wort-templog"); |
146 debug!("debug mode"); | 163 debug!("debug mode"); |
147 | 164 |
148 let conf_filename = "tempserver.conf"; | |
149 config = config.merge_file(conf_filename) | |
150 .unwrap_or_else(|e| { | |
151 panic!("Couldn't parse {}: {}", conf_filename, e); | |
152 }); | |
153 | |
154 if args.flag_thisconf { | 165 if args.flag_thisconf { |
155 println!("Current configuration:\n\n{}", | 166 println!("Current configuration:\n\n{}", |
156 config.to_toml_string()); | 167 rigid_config.to_toml_string()); |
157 std::process::exit(0); | 168 std::process::exit(0); |
158 } | 169 } |
159 | 170 |
160 run(&config, args.flag_nowait, args.flag_test); | 171 |
172 | |
173 run(args.flag_nowait, args.flag_test); | |
161 } | 174 } |
162 | 175 |