Mercurial > templog
annotate rust/src/main.rs @ 592:03b48ec0bb03 rust
fridge, types, configwaiter
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 24 Dec 2016 00:14:58 +0800 |
parents | 4a944663fa8d |
children | bf138339d20a |
rev | line source |
---|---|
588
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
1 extern crate tokio_core; |
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
2 extern crate futures; |
591 | 3 extern crate rustc_serialize; |
588
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
4 |
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
5 use tokio_core::reactor::Core; |
591 | 6 use futures::{Future,Stream}; |
7 use rustc_serialize::json; | |
589
f2508125adf1
Try using traits for periodic stream
Matt Johnston <matt@ucc.asn.au>
parents:
588
diff
changeset
|
8 |
590 | 9 mod sensor; |
592
03b48ec0bb03
fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
591
diff
changeset
|
10 mod fridge; |
03b48ec0bb03
fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
591
diff
changeset
|
11 mod types; |
03b48ec0bb03
fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
591
diff
changeset
|
12 mod configwaiter; |
591 | 13 |
592
03b48ec0bb03
fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
591
diff
changeset
|
14 use types::*; |
591 | 15 |
587 | 16 fn main() { |
17 println!("Wort Templog"); | |
588
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
18 |
592
03b48ec0bb03
fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
591
diff
changeset
|
19 let paramh = ParamHolder::new(); |
591 | 20 let mut readings = Readings::new(); |
592
03b48ec0bb03
fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
591
diff
changeset
|
21 let mut fridge = fridge::Fridge::new(¶mh.p); |
591 | 22 |
588
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
23 let mut core = Core::new().unwrap(); |
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
24 let handle = core.handle(); |
587 | 25 |
591 | 26 let s = sensor::Sensor::run(&handle, 400, "sens1".to_string()); |
27 let t = sensor::Sensor::run(&handle, 747, "frid".to_string()); | |
592
03b48ec0bb03
fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
591
diff
changeset
|
28 let w = configwaiter::ConfigWaiter::run(&handle, 3000); |
587 | 29 |
588
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
30 let h = s.for_each(|r| { |
592
03b48ec0bb03
fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
591
diff
changeset
|
31 fridge.set_params(¶mh.p); |
590 | 32 println!("readings {:?}", r); |
588
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
33 Ok(()) |
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
34 }); |
587 | 35 |
591 | 36 let i = t.for_each(|r| { |
37 println!("fridgereadings {:?}", r); | |
38 Ok(()) | |
39 }); | |
40 | |
592
03b48ec0bb03
fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
591
diff
changeset
|
41 let j = w.for_each(move |ph| { |
03b48ec0bb03
fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
591
diff
changeset
|
42 let paramh = ph; |
03b48ec0bb03
fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
591
diff
changeset
|
43 fridge.set_params(&ph.p); |
03b48ec0bb03
fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
591
diff
changeset
|
44 Ok(()) |
03b48ec0bb03
fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
591
diff
changeset
|
45 }); |
03b48ec0bb03
fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
591
diff
changeset
|
46 |
03b48ec0bb03
fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
591
diff
changeset
|
47 let all = h.select(j); |
591 | 48 |
49 core.run(all); | |
587 | 50 } |
51 |