Mercurial > templog
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 |
rev | line source |
---|---|
634 | 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 | 5 |
633 | 6 #[macro_use] extern crate lazy_static; |
7 | |
589
f2508125adf1
Try using traits for periodic stream
Matt Johnston <matt@ucc.asn.au>
parents:
588
diff
changeset
|
8 |
595 | 9 mod config; |
590 | 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 | 13 mod params; |
591 | 14 |
634 | 15 use crate::config::Config; |
16 | |
17 use riker::actors::*; | |
588
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
18 |
634 | 19 use structopt::StructOpt; |
595 | 20 |
634 | 21 fn run(cf: Config, nowait: bool, testmode: bool) { |
587 | 22 |
634 | 23 let sys = ActorSystem::new().unwrap(); |
24 let props = Props::new_args(params::ParamWaiter::new, cf.clone()); | |
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 | 27 if testmode { |
28 let props = Props::new_args(sensor::TestSensor::new, cf.clone()); | |
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 | 31 let props = Props::new_args(sensor::OneWireSensor::new, cf.clone()); |
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 | 35 let props = Props::new_args(fridge::Fridge::new_actor, (cf.clone(), nowait)); |
36 sys.actor_of(props, "fridge").unwrap(); | |
587 | 37 } |
38 | |
634 | 39 #[derive(Debug, StructOpt)] |
40 #[structopt(name = "Wort Temperature", about = "Matt Johnston 2019 [email protected]")] | |
41 struct Opt { | |
42 /// Replace existing running instance | |
43 #[structopt(long)] | |
44 new: bool, | |
45 | |
46 /// Run in background | |
47 #[structopt(short = "D", long)] | |
48 daemon: bool, | |
597 | 49 |
634 | 50 #[structopt(short, long)] |
51 debug: bool, | |
52 | |
53 /// Use fake sensors etc | |
54 #[structopt(long)] | |
55 test: bool, | |
598
d4fbfb5c46ff
broken update of versions of things
Matt Johnston <matt@ucc.asn.au>
parents:
597
diff
changeset
|
56 |
634 | 57 /// Skip initial fridge wait |
58 #[structopt(long)] | |
59 nowait: bool, | |
60 | |
61 /// Print default config (customise in local.conf) | |
62 #[structopt(long)] | |
63 defconf: bool, | |
598
d4fbfb5c46ff
broken update of versions of things
Matt Johnston <matt@ucc.asn.au>
parents:
597
diff
changeset
|
64 } |
597 | 65 |
634 | 66 fn handle_args() -> Opt { |
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 | 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 | 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 | 78 // fn setup_log(debug: bool) { |
79 // let loglevel = if debug { | |
80 // log::LevelFilter::Debug | |
81 // } else { | |
82 // log::LevelFilter::Info | |
83 // }; | |
597 | 84 |
634 | 85 // let format = |record: &log::Record| { |
86 // let datefmt = "%Y-%m-%d %I:%M:%S %p"; | |
87 // let ts = chrono::Local::now().format(datefmt); | |
88 // format!("{}: {} - {}", ts, record.level(), record.args()) | |
89 // }; | |
597 | 90 |
91 | |
634 | 92 // let mut builder = env_logger::Builder::new(); |
93 // builder.format(format).filter(Some("wort_templog"), loglevel); | |
94 // builder.init().unwrap(); | |
95 // } | |
601 | 96 |
597 | 97 fn main() { |
98 | |
99 let args = handle_args(); | |
634 | 100 // setup_log(args.debug); |
597 | 101 //env_logger::init().unwrap(); |
102 | |
103 info!("wort-templog"); | |
104 debug!("debug mode"); | |
105 | |
634 | 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 | 108 run(config, args.nowait, args.test); |
597 | 109 } |