Mercurial > templog
comparison rust/src/main.rs @ 615:f153aec221be rust
move Params, epoch code
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 07 Mar 2017 23:56:12 +0800 |
parents | e1bab5b36352 |
children | a85c0c9bc1fa |
comparison
equal
deleted
inserted
replaced
614:e1bab5b36352 | 615:f153aec221be |
---|---|
29 | 29 |
30 mod config; | 30 mod config; |
31 mod sensor; | 31 mod sensor; |
32 mod fridge; | 32 mod fridge; |
33 mod types; | 33 mod types; |
34 mod paramwaiter; | 34 mod params; |
35 | 35 |
36 use types::*; | 36 use types::*; |
37 use config::Config; | 37 use config::Config; |
38 | 38 |
39 fn run(config: &Config, nowait: bool, testmode: bool) { | 39 fn run(config: &Config, nowait: bool, testmode: bool) { |
40 | 40 |
41 let mut core = Core::new().unwrap(); | 41 let mut core = Core::new().unwrap(); |
42 let handle = core.handle(); | 42 let handle = core.handle(); |
43 | 43 |
44 let mut paramh = ParamHolder::new(); | 44 let params = params::Params::load(&config); |
45 let mut fridge = fridge::Fridge::new(&config, nowait, paramh.p, &handle); | 45 let epoch = params.epoch.clone(); |
46 let mut fridge = fridge::Fridge::new(&config, nowait, params, &handle); | |
46 | 47 |
47 let (fridge_reading_s, fridge_reading_r) = mpsc::channel(1); | 48 let (fridge_reading_s, fridge_reading_r) = mpsc::channel(1); |
48 let fridge_reading_r = fridge_reading_r.map_err(|e| TemplogError::new("Problem with fridge_reading_r channel")); | 49 let fridge_reading_r = fridge_reading_r.map_err(|e| TemplogError::new("Problem with fridge_reading_r channel")); |
49 | 50 |
50 let sensor_stream = if testmode { | 51 let sensor_stream = if testmode { |
69 }); | 70 }); |
70 handle.spawn(t); | 71 handle.spawn(t); |
71 r | 72 r |
72 }); | 73 }); |
73 | 74 |
74 let param_stream = paramwaiter::ParamWaiter::stream(config, &handle); | 75 let param_stream = params::ParamWaiter::stream(config, epoch, &handle); |
75 let p = param_stream.map(|p| { | 76 let p = param_stream.map(|p| { |
76 fridge::Message::Params(p) | 77 fridge::Message::Params(p) |
77 }); | 78 }); |
78 | 79 |
79 let timeouts = fridge.wakeups(); | 80 let timeouts = fridge.wakeups(); |
97 --new Replace existing running instance | 98 --new Replace existing running instance |
98 -D, --daemon Run in background | 99 -D, --daemon Run in background |
99 -d, --debug | 100 -d, --debug |
100 -t, --test Use fake sensors etc | 101 -t, --test Use fake sensors etc |
101 --nowait Skip initial fridge wait | 102 --nowait Skip initial fridge wait |
102 --defconf Print default config (customise in tempserver.conf) | 103 --defconf Print default config (customise in local.conf) |
103 --thisconf Print used config | 104 --thisconf Print used config |
104 "; | 105 "; |
105 | 106 |
106 #[derive(RustcDecodable)] | 107 #[derive(RustcDecodable)] |
107 struct Args { | 108 struct Args { |
136 fn handle_args() -> Args { | 137 fn handle_args() -> Args { |
137 let args: Args = docopt::Docopt::new(USAGE).and_then(|d| d.decode()).unwrap_or_else(|e| e.exit()); | 138 let args: Args = docopt::Docopt::new(USAGE).and_then(|d| d.decode()).unwrap_or_else(|e| e.exit()); |
138 | 139 |
139 if args.flag_defconf { | 140 if args.flag_defconf { |
140 println!("Default configuration:\n{}\n\n{}", | 141 println!("Default configuration:\n{}\n\n{}", |
141 "(custom options go in tempserver.conf)", | 142 "(custom options go in local.conf)", |
142 config::Config::default().to_toml_string()); | 143 config::Config::default().to_toml_string()); |
143 std::process::exit(0); | 144 std::process::exit(0); |
144 } | 145 } |
145 args | 146 args |
146 } | 147 } |
147 | 148 |
148 fn load_config() -> Config { | 149 fn load_config() -> Config { |
149 let nconfig = config::Config::default(); | 150 let nconfig = config::Config::default(); |
150 | 151 |
151 let conf_filename = "tempserver.conf"; | 152 let conf_filename = "local.conf"; |
152 nconfig.merge_file(conf_filename) | 153 nconfig.merge_file(conf_filename) |
153 .unwrap_or_else(|e| { | 154 .unwrap_or_else(|e| { |
154 println!("Couldn't parse {}: {}", conf_filename, e); | 155 println!("Couldn't parse {}: {}", conf_filename, e); |
155 std::process::exit(1); | 156 std::process::exit(1); |
156 }) | 157 }) |