# HG changeset patch # User Matt Johnston # Date 1482424399 -28800 # Node ID 4a944663fa8da2091644380b0d608d1dad60b741 # Parent dccd8504aa38b01d1ce7ac2956915b34b77870b7 more skeleton diff -r dccd8504aa38 -r 4a944663fa8d rust/Cargo.lock --- a/rust/Cargo.lock Wed Dec 21 21:40:32 2016 +0800 +++ b/rust/Cargo.lock Fri Dec 23 00:33:19 2016 +0800 @@ -3,6 +3,7 @@ version = "0.1.0" dependencies = [ "futures 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-core 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -101,6 +102,11 @@ ] [[package]] +name = "rustc-serialize" +version = "0.3.22" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "rustc_version" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -171,6 +177,7 @@ "checksum miow 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d5bfc6782530ac8ace97af10a540054a37126b63b0702ddaaa243b73b5745b9a" "checksum net2 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)" = "5edf9cb6be97212423aed9413dd4729d62b370b5e1c571750e882cebbbc1e3e2" "checksum nix 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0d95c5fa8b641c10ad0b8887454ebaafa3c92b5cd5350f8fc693adafd178e7b" +"checksum rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "237546c689f20bb44980270c73c3b9edd0891c1be49cc1274406134a66d3957b" "checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084" "checksum scoped-tls 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f417c22df063e9450888a7561788e9bd46d3bb3c1466435b4eccb903807f147d" "checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac" diff -r dccd8504aa38 -r 4a944663fa8d rust/Cargo.toml --- a/rust/Cargo.toml Wed Dec 21 21:40:32 2016 +0800 +++ b/rust/Cargo.toml Fri Dec 23 00:33:19 2016 +0800 @@ -6,4 +6,5 @@ [dependencies] futures = "0.1.6" tokio-core = "0.1.1" +rustc-serialize = "0.3.*" diff -r dccd8504aa38 -r 4a944663fa8d rust/rustnotes.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rust/rustnotes.txt Fri Dec 23 00:33:19 2016 +0800 @@ -0,0 +1,19 @@ +fridge +- called on external param change +- called on external reading change +- called on integrator timeout +- called on slowstart timeout + +sensor +- emits readings +- threadpool to read sensors + +sender +- called on timeout + +configwaiter +- emits params +- called on http response +- called on new longpoll +- possibly takes old/existing params + diff -r dccd8504aa38 -r 4a944663fa8d rust/src/main.rs --- a/rust/src/main.rs Wed Dec 21 21:40:32 2016 +0800 +++ b/rust/src/main.rs Fri Dec 23 00:33:19 2016 +0800 @@ -1,24 +1,91 @@ extern crate tokio_core; extern crate futures; +extern crate rustc_serialize; use tokio_core::reactor::Core; -use futures::Stream; +use futures::{Future,Stream}; +use rustc_serialize::json; mod sensor; +#[derive(RustcDecodable, RustcEncodable)] +struct Params { + fridge_setpoint: f32, + fridge_difference: f32, + overshoot_delay: u32, + overshoot_factor: f32, + disabled: bool, + nowort: bool, + fridge_range_lower: f32, + fridge_range_upper: f32, +} + +struct ParamHolder { + p: Params, + epoch: String, // XXX or a byte array? +} + +impl ParamHolder { + fn new() -> ParamHolder { + ParamHolder { + p: Params { + fridge_setpoint: 16.0, + fridge_difference: 0.2, + overshoot_delay: 720, // 12 minutes + overshoot_factor: 1.0, + disabled: false, + nowort: false, + fridge_range_lower: 3.0, + fridge_range_upper: 3.0, + }, + epoch: String::new(), + } + } +} + +struct Readings { + temps: Vec>, +} + +impl Readings { + fn new() -> Readings { + Readings { + temps: Vec::new(), + } + } + fn fridge() -> Option { + unimplemented!(); + } + + fn wort() -> Option { + unimplemented!(); + } +} + fn main() { println!("Wort Templog"); + let param = ParamHolder::new(); + let mut readings = Readings::new(); + let mut core = Core::new().unwrap(); let handle = core.handle(); - let s = sensor::Sensor::run(&handle); + let s = sensor::Sensor::run(&handle, 400, "sens1".to_string()); + let t = sensor::Sensor::run(&handle, 747, "frid".to_string()); let h = s.for_each(|r| { println!("readings {:?}", r); Ok(()) }); - core.run(h); + let i = t.for_each(|r| { + println!("fridgereadings {:?}", r); + Ok(()) + }); + + let all = h.select(i); + + core.run(all); } diff -r dccd8504aa38 -r 4a944663fa8d rust/src/sensor.rs --- a/rust/src/sensor.rs Wed Dec 21 21:40:32 2016 +0800 +++ b/rust/src/sensor.rs Fri Dec 23 00:33:19 2016 +0800 @@ -14,29 +14,28 @@ value: Option, } -pub type Readings = Vec; - pub struct Sensor { current: f32, + suf: String, } impl Sensor { - - fn step(&mut self) -> Readings { + fn step(&mut self) -> Vec { let mut r = Vec::new(); self.current = self.current + 0.1; - r.push(Reading { name: "aaa".to_string(), value: Some(self.current) }); + r.push(Reading { name: "aaa".to_string() + &self.suf, value: Some(self.current) }); + r.push(Reading { name: "b".to_string() + &self.suf, value: Some(self.current/3.0) }); r } - fn new() -> Self { - Sensor { current: 22.0 } + fn new(suffix: String) -> Self { + Sensor { current: 22.0, suf: suffix } } - pub fn run(handle: &Handle) -> Box> { - let mut s = Sensor::new(); + pub fn run(handle: &Handle, rate: u64, suffix: String) -> Box, Error=io::Error>> { + let mut s = Sensor::new(suffix); - let dur = Duration::from_millis(400); + let dur = Duration::from_millis(rate); Interval::new(dur, handle).unwrap().map(move |()| { s.step() }).boxed()