Mercurial > templog
comparison rust/src/main.rs @ 595:e87655ed8429 rust
add config
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 05 Jan 2017 23:26:00 +0800 |
parents | aff50ee77252 |
children | ca8102feaca6 |
comparison
equal
deleted
inserted
replaced
594:aff50ee77252 | 595:e87655ed8429 |
---|---|
1 #![feature(proc_macro)] | |
2 | |
1 extern crate tokio_core; | 3 extern crate tokio_core; |
2 extern crate futures; | 4 extern crate futures; |
3 extern crate rustc_serialize; | |
4 #[macro_use] | 5 #[macro_use] |
5 extern crate log; | 6 extern crate log; |
6 extern crate env_logger; | 7 extern crate env_logger; |
8 | |
9 #[macro_use] | |
10 extern crate serde_derive; | |
11 extern crate serde; | |
12 | |
13 extern crate toml; | |
14 | |
7 | 15 |
8 use std::io; | 16 use std::io; |
9 | 17 |
10 use tokio_core::reactor::Core; | 18 use tokio_core::reactor::Core; |
11 use futures::{Stream,Sink,Future}; | 19 use futures::{Stream,Sink,Future}; |
12 use futures::sync::{mpsc}; | 20 use futures::sync::{mpsc}; |
13 use sensor::Sensor; | 21 use sensor::Sensor; |
14 | 22 |
23 mod config; | |
15 mod sensor; | 24 mod sensor; |
16 mod fridge; | 25 mod fridge; |
17 mod types; | 26 mod types; |
18 mod paramwaiter; | 27 mod paramwaiter; |
19 | 28 |
22 fn main() { | 31 fn main() { |
23 env_logger::init().unwrap(); | 32 env_logger::init().unwrap(); |
24 | 33 |
25 println!("Wort Templog"); | 34 println!("Wort Templog"); |
26 debug!("debug log level"); | 35 debug!("debug log level"); |
36 | |
37 let config = config::Config::new(); | |
38 println!("{}", config.to_toml_string()); | |
27 | 39 |
28 let mut core = Core::new().unwrap(); | 40 let mut core = Core::new().unwrap(); |
29 let handle = core.handle(); | 41 let handle = core.handle(); |
30 | 42 |
31 let mut paramh = ParamHolder::new(); | 43 let mut paramh = ParamHolder::new(); |
44 // while streaming them all to the web sender. | 56 // while streaming them all to the web sender. |
45 let s = sensor_stream.map(|r| { | 57 let s = sensor_stream.map(|r| { |
46 debug!("sensors {:?}", r); | 58 debug!("sensors {:?}", r); |
47 let t = sensor_s.clone().send(fridge::Message::Sensor{wort: r.wort(), fridge: r.fridge()}) | 59 let t = sensor_s.clone().send(fridge::Message::Sensor{wort: r.wort(), fridge: r.fridge()}) |
48 .map(|_| ()) | 60 .map(|_| ()) |
49 .map_err(|_| ()); | 61 .map_err(|e| { |
62 warn!("Send error in sensor_s: {}", e.to_string()); | |
63 () | |
64 }); | |
50 handle.spawn(t); | 65 handle.spawn(t); |
51 r | 66 r |
52 }); | 67 }); |
53 | 68 |
54 let param_stream = paramwaiter::ParamWaiter::stream(&handle); | 69 let param_stream = paramwaiter::ParamWaiter::stream(&handle); |