Mercurial > templog
annotate rust/src/main.rs @ 638:a9f353f488d0 rust
fix channels
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 09 Nov 2019 11:35:59 +0800 |
parents | 4424a8b30f9c |
children | 89818a14648b |
rev | line source |
---|---|
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
1 #[macro_use] extern crate log; |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
2 // riker has its own logging? |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
3 //extern crate env_logger; |
631 | 4 |
633 | 5 #[macro_use] extern crate lazy_static; |
6 | |
589
f2508125adf1
Try using traits for periodic stream
Matt Johnston <matt@ucc.asn.au>
parents:
588
diff
changeset
|
7 |
595 | 8 mod config; |
590 | 9 mod sensor; |
609
7bda01659426
not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents:
607
diff
changeset
|
10 mod fridge; |
592
03b48ec0bb03
fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
591
diff
changeset
|
11 mod types; |
615 | 12 mod params; |
591 | 13 |
638 | 14 use std::time::Duration; |
634 | 15 |
16 use riker::actors::*; | |
588
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
17 |
634 | 18 use structopt::StructOpt; |
595 | 19 |
635
4424a8b30f9c
config crate wants everything to be lower case
Matt Johnston <matt@ucc.asn.au>
parents:
634
diff
changeset
|
20 use types::TemplogError; |
4424a8b30f9c
config crate wants everything to be lower case
Matt Johnston <matt@ucc.asn.au>
parents:
634
diff
changeset
|
21 |
4424a8b30f9c
config crate wants everything to be lower case
Matt Johnston <matt@ucc.asn.au>
parents:
634
diff
changeset
|
22 fn run(conf_file: &str, nowait: bool, testmode: bool) -> Result<(), TemplogError> { |
4424a8b30f9c
config crate wants everything to be lower case
Matt Johnston <matt@ucc.asn.au>
parents:
634
diff
changeset
|
23 |
4424a8b30f9c
config crate wants everything to be lower case
Matt Johnston <matt@ucc.asn.au>
parents:
634
diff
changeset
|
24 let cf = config::Config::load(conf_file)?; |
587 | 25 |
634 | 26 let sys = ActorSystem::new().unwrap(); |
638 | 27 |
28 let props = Props::new_args(fridge::Fridge::new_actor, (cf.clone(), testmode, nowait)); | |
29 sys.actor_of(props, "fridge").unwrap(); | |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
30 |
638 | 31 loop { |
32 // TODO: wait for a semaphore or something? | |
33 std::thread::sleep(Duration::from_millis(60000)); | |
34 } | |
587 | 35 } |
36 | |
634 | 37 #[derive(Debug, StructOpt)] |
38 #[structopt(name = "Wort Temperature", about = "Matt Johnston 2019 [email protected]")] | |
39 struct Opt { | |
40 /// Replace existing running instance | |
41 #[structopt(long)] | |
42 new: bool, | |
43 | |
44 /// Run in background | |
45 #[structopt(short = "D", long)] | |
46 daemon: bool, | |
597 | 47 |
634 | 48 #[structopt(short, long)] |
49 debug: bool, | |
50 | |
51 /// Use fake sensors etc | |
52 #[structopt(long)] | |
53 test: bool, | |
598
d4fbfb5c46ff
broken update of versions of things
Matt Johnston <matt@ucc.asn.au>
parents:
597
diff
changeset
|
54 |
634 | 55 /// Skip initial fridge wait |
56 #[structopt(long)] | |
57 nowait: bool, | |
58 | |
635
4424a8b30f9c
config crate wants everything to be lower case
Matt Johnston <matt@ucc.asn.au>
parents:
634
diff
changeset
|
59 /// Print default config (customise in local.toml) |
634 | 60 #[structopt(long)] |
61 defconf: bool, | |
635
4424a8b30f9c
config crate wants everything to be lower case
Matt Johnston <matt@ucc.asn.au>
parents:
634
diff
changeset
|
62 |
4424a8b30f9c
config crate wants everything to be lower case
Matt Johnston <matt@ucc.asn.au>
parents:
634
diff
changeset
|
63 /// Config file |
4424a8b30f9c
config crate wants everything to be lower case
Matt Johnston <matt@ucc.asn.au>
parents:
634
diff
changeset
|
64 #[structopt(short = "c", long, default_value = "local.toml")] |
4424a8b30f9c
config crate wants everything to be lower case
Matt Johnston <matt@ucc.asn.au>
parents:
634
diff
changeset
|
65 config: String, |
598
d4fbfb5c46ff
broken update of versions of things
Matt Johnston <matt@ucc.asn.au>
parents:
597
diff
changeset
|
66 } |
597 | 67 |
634 | 68 fn handle_args() -> Opt { |
69 let args = Opt::from_args(); | |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
70 |
634 | 71 if args.defconf { |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
72 println!("Default configuration:\n{}\n\n{}", |
635
4424a8b30f9c
config crate wants everything to be lower case
Matt Johnston <matt@ucc.asn.au>
parents:
634
diff
changeset
|
73 "(custom options go in local.toml)", |
634 | 74 config::Config::default_toml()); |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
75 std::process::exit(0); |
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 args |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
78 } |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
79 |
634 | 80 // fn setup_log(debug: bool) { |
81 // let loglevel = if debug { | |
82 // log::LevelFilter::Debug | |
83 // } else { | |
84 // log::LevelFilter::Info | |
85 // }; | |
597 | 86 |
634 | 87 // let format = |record: &log::Record| { |
88 // let datefmt = "%Y-%m-%d %I:%M:%S %p"; | |
89 // let ts = chrono::Local::now().format(datefmt); | |
90 // format!("{}: {} - {}", ts, record.level(), record.args()) | |
91 // }; | |
597 | 92 |
93 | |
634 | 94 // let mut builder = env_logger::Builder::new(); |
95 // builder.format(format).filter(Some("wort_templog"), loglevel); | |
96 // builder.init().unwrap(); | |
97 // } | |
601 | 98 |
597 | 99 fn main() { |
100 | |
101 let args = handle_args(); | |
634 | 102 // setup_log(args.debug); |
597 | 103 //env_logger::init().unwrap(); |
104 | |
105 info!("wort-templog"); | |
106 debug!("debug mode"); | |
107 | |
635
4424a8b30f9c
config crate wants everything to be lower case
Matt Johnston <matt@ucc.asn.au>
parents:
634
diff
changeset
|
108 let r = run(&args.config, args.nowait, args.test); |
4424a8b30f9c
config crate wants everything to be lower case
Matt Johnston <matt@ucc.asn.au>
parents:
634
diff
changeset
|
109 if let Err(e) = r { |
4424a8b30f9c
config crate wants everything to be lower case
Matt Johnston <matt@ucc.asn.au>
parents:
634
diff
changeset
|
110 println!("Error running: {}", e); |
4424a8b30f9c
config crate wants everything to be lower case
Matt Johnston <matt@ucc.asn.au>
parents:
634
diff
changeset
|
111 } |
597 | 112 } |