annotate rust/src/main.rs @ 634:a5721c02d3ee rust

build succeeds
author Matt Johnston <matt@ucc.asn.au>
date Sun, 22 Sep 2019 20:35:40 +0800
parents 490e9e15b98c
children 4424a8b30f9c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
1 #![feature(async_closure)]
632
bde302def78e moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents: 631
diff changeset
2 #[macro_use] extern crate log;
bde302def78e moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents: 631
diff changeset
3 // riker has its own logging?
bde302def78e moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents: 631
diff changeset
4 //extern crate env_logger;
631
c57821a60e51 rust work in progress ?
Matt Johnston <matt@ucc.asn.au>
parents: 627
diff changeset
5
633
490e9e15b98c move some bits to riker
Matt Johnston <matt@ucc.asn.au>
parents: 632
diff changeset
6 #[macro_use] extern crate lazy_static;
490e9e15b98c move some bits to riker
Matt Johnston <matt@ucc.asn.au>
parents: 632
diff changeset
7
589
f2508125adf1 Try using traits for periodic stream
Matt Johnston <matt@ucc.asn.au>
parents: 588
diff changeset
8
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
9 mod config;
590
dccd8504aa38 it runs
Matt Johnston <matt@ucc.asn.au>
parents: 589
diff changeset
10 mod sensor;
609
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 607
diff changeset
11 mod fridge;
592
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents: 591
diff changeset
12 mod types;
615
f153aec221be move Params, epoch code
Matt Johnston <matt@ucc.asn.au>
parents: 614
diff changeset
13 mod params;
591
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
14
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
15 use crate::config::Config;
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
16
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
17 use riker::actors::*;
588
038734052b20 fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents: 587
diff changeset
18
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
19 use structopt::StructOpt;
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
20
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
21 fn run(cf: Config, nowait: bool, testmode: bool) {
587
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
23 let sys = ActorSystem::new().unwrap();
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
24 let props = Props::new_args(params::ParamWaiter::new, cf.clone());
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
25 sys.actor_of(props, "paramwaiter").unwrap();
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
26
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
27 if testmode {
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
28 let props = Props::new_args(sensor::TestSensor::new, cf.clone());
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
29 sys.actor_of(props, "sensor").unwrap()
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
30 } else {
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
31 let props = Props::new_args(sensor::OneWireSensor::new, cf.clone());
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
32 sys.actor_of(props, "sensor").unwrap()
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
33 };
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
34
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
35 let props = Props::new_args(fridge::Fridge::new_actor, (cf.clone(), nowait));
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
36 sys.actor_of(props, "fridge").unwrap();
587
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 }
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
39 #[derive(Debug, StructOpt)]
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
40 #[structopt(name = "Wort Temperature", about = "Matt Johnston 2019 [email protected]")]
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
41 struct Opt {
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
42 /// Replace existing running instance
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
43 #[structopt(long)]
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
44 new: bool,
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
45
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
46 /// Run in background
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
47 #[structopt(short = "D", long)]
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
48 daemon: bool,
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
49
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
50 #[structopt(short, long)]
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
51 debug: bool,
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
52
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
53 /// Use fake sensors etc
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
54 #[structopt(long)]
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
55 test: bool,
598
d4fbfb5c46ff broken update of versions of things
Matt Johnston <matt@ucc.asn.au>
parents: 597
diff changeset
56
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
57 /// Skip initial fridge wait
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
58 #[structopt(long)]
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
59 nowait: bool,
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
60
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
61 /// Print default config (customise in local.conf)
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
62 #[structopt(long)]
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
63 defconf: bool,
598
d4fbfb5c46ff broken update of versions of things
Matt Johnston <matt@ucc.asn.au>
parents: 597
diff changeset
64 }
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
65
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
66 fn handle_args() -> Opt {
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
67 let args = Opt::from_args();
632
bde302def78e moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents: 631
diff changeset
68
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
69 if args.defconf {
632
bde302def78e moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents: 631
diff changeset
70 println!("Default configuration:\n{}\n\n{}",
bde302def78e moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents: 631
diff changeset
71 "(custom options go in local.conf)",
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
72 config::Config::default_toml());
632
bde302def78e moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents: 631
diff changeset
73 std::process::exit(0);
bde302def78e moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents: 631
diff changeset
74 }
bde302def78e moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents: 631
diff changeset
75 args
bde302def78e moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents: 631
diff changeset
76 }
bde302def78e moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents: 631
diff changeset
77
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
78 // fn setup_log(debug: bool) {
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
79 // let loglevel = if debug {
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
80 // log::LevelFilter::Debug
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
81 // } else {
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
82 // log::LevelFilter::Info
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
83 // };
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
84
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
85 // let format = |record: &log::Record| {
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
86 // let datefmt = "%Y-%m-%d %I:%M:%S %p";
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
87 // let ts = chrono::Local::now().format(datefmt);
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
88 // format!("{}: {} - {}", ts, record.level(), record.args())
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
89 // };
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
90
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
91
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
92 // let mut builder = env_logger::Builder::new();
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
93 // builder.format(format).filter(Some("wort_templog"), loglevel);
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
94 // builder.init().unwrap();
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
95 // }
601
8c21df3711e2 rigid_config
Matt Johnston <matt@ucc.asn.au>
parents: 599
diff changeset
96
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
97 fn main() {
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
98
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
99 let args = handle_args();
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
100 // setup_log(args.debug);
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
101 //env_logger::init().unwrap();
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
102
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
103 info!("wort-templog");
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
104 debug!("debug mode");
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
105
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
106 let config = config::Config::load().unwrap();
603
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 601
diff changeset
107
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 633
diff changeset
108 run(config, args.nowait, args.test);
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
109 }