annotate rust/src/main.rs @ 591:4a944663fa8d rust

more skeleton
author Matt Johnston <matt@ucc.asn.au>
date Fri, 23 Dec 2016 00:33:19 +0800
parents dccd8504aa38
children 03b48ec0bb03
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
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
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
6 use futures::{Future,Stream};
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
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
dccd8504aa38 it runs
Matt Johnston <matt@ucc.asn.au>
parents: 589
diff changeset
9 mod sensor;
587
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10
591
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
11 #[derive(RustcDecodable, RustcEncodable)]
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
12 struct Params {
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
13 fridge_setpoint: f32,
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
14 fridge_difference: f32,
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
15 overshoot_delay: u32,
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
16 overshoot_factor: f32,
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
17 disabled: bool,
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
18 nowort: bool,
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
19 fridge_range_lower: f32,
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
20 fridge_range_upper: f32,
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
21 }
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
22
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
23 struct ParamHolder {
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
24 p: Params,
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
25 epoch: String, // XXX or a byte array?
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
26 }
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
27
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
28 impl ParamHolder {
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
29 fn new() -> ParamHolder {
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
30 ParamHolder {
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
31 p: Params {
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
32 fridge_setpoint: 16.0,
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
33 fridge_difference: 0.2,
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
34 overshoot_delay: 720, // 12 minutes
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
35 overshoot_factor: 1.0,
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
36 disabled: false,
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
37 nowort: false,
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
38 fridge_range_lower: 3.0,
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
39 fridge_range_upper: 3.0,
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
40 },
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
41 epoch: String::new(),
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
42 }
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
43 }
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
44 }
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
45
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
46 struct Readings {
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
47 temps: Vec<Vec<sensor::Reading>>,
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
48 }
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
49
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
50 impl Readings {
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
51 fn new() -> Readings {
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
52 Readings {
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
53 temps: Vec::new(),
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
54 }
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
55 }
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
56 fn fridge() -> Option<f32> {
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
57 unimplemented!();
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
58 }
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
59
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
60 fn wort() -> Option<f32> {
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
61 unimplemented!();
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
62 }
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
63 }
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
64
587
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 fn main() {
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66 println!("Wort Templog");
588
038734052b20 fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents: 587
diff changeset
67
591
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
68 let param = ParamHolder::new();
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
69 let mut readings = Readings::new();
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
70
588
038734052b20 fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents: 587
diff changeset
71 let mut core = Core::new().unwrap();
038734052b20 fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents: 587
diff changeset
72 let handle = core.handle();
587
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73
591
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
74 let s = sensor::Sensor::run(&handle, 400, "sens1".to_string());
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
75 let t = sensor::Sensor::run(&handle, 747, "frid".to_string());
587
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76
588
038734052b20 fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents: 587
diff changeset
77 let h = s.for_each(|r| {
590
dccd8504aa38 it runs
Matt Johnston <matt@ucc.asn.au>
parents: 589
diff changeset
78 println!("readings {:?}", r);
588
038734052b20 fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents: 587
diff changeset
79 Ok(())
038734052b20 fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents: 587
diff changeset
80 });
587
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81
591
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
82 let i = t.for_each(|r| {
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
83 println!("fridgereadings {:?}", r);
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
84 Ok(())
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
85 });
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
86
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
87 let all = h.select(i);
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
88
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
89 core.run(all);
587
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 }
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91