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

build succeeds
author Matt Johnston <matt@ucc.asn.au>
date Sun, 22 Sep 2019 20:35:40 +0800
parents f3e39e2107fd
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: 611
diff changeset
1 use serde::{Serialize,Deserialize};
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 611
diff changeset
3 use super::types::*;
611
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 601
diff changeset
4
596
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
5 #[derive(Deserialize,Serialize,Debug,Clone)]
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 #[allow(non_snake_case)]
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 pub struct Config {
596
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
8 pub SENSOR_SLEEP: u64,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
9 pub UPLOAD_SLEEP: u64,
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10
596
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
11 pub FRIDGE_DELAY: u64,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
12 pub FRIDGE_WORT_INVALID_TIME: u64,
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13
596
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
14 pub MAX_READINGS: u32,
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15
596
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
16 pub PARAMS_FILE: String,
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17
596
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
18 pub SENSOR_BASE_DIR: String,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
19 pub FRIDGE_GPIO_PIN: u32,
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20
596
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
21 pub AMBIENT_NAME: String,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
22 pub FRIDGE_NAME: String,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
23 pub WORT_NAME: String,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
24 pub INTERNAL_TEMPERATURE: String,
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25
596
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
26 pub HMAC_KEY: String,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
27 pub SERVER_URL: String,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
28 pub UPDATE_URL: String,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
29 pub SETTINGS_URL: String,
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 }
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 impl Config {
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 611
diff changeset
33 pub fn default_toml() -> &'static str {
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 611
diff changeset
34 include_str!("defconfig.toml")
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 }
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36
634
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 611
diff changeset
37 pub fn load() -> Result<Self, TemplogError> {
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 611
diff changeset
38 let mut c = config::Config::default();
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 611
diff changeset
39 c.merge(config::File::from_str(Self::default_toml(), config::FileFormat::Toml));
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 611
diff changeset
40 c.merge(config::File::with_name("local.conf")).unwrap();
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 611
diff changeset
41 c.merge(config::Environment::with_prefix("TEMPLOG")).unwrap();
a5721c02d3ee build succeeds
Matt Johnston <matt@ucc.asn.au>
parents: 611
diff changeset
42 Ok(c.try_into().unwrap())
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
43 }
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 }