annotate rust/src/config.rs @ 596:ca8102feaca6 rust

sensor takes config parameter
author Matt Johnston <matt@ucc.asn.au>
date Fri, 06 Jan 2017 22:04:10 +0800
parents e87655ed8429
children a440eafa84a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 extern crate toml;
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 use serde::Serialize;
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
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 FRIDGE_SLEEP: u64,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
9 pub SENSOR_SLEEP: u64,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
10 pub UPLOAD_SLEEP: u64,
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11
596
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
12 pub FRIDGE_DELAY: u64,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
13 pub FRIDGE_WORT_INVALID_TIME: u64,
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14
596
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
15 pub MAX_READINGS: u32,
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16
596
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
17 pub PARAMS_FILE: String,
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18
596
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
19 pub SENSOR_BASE_DIR: String,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
20 pub FRIDGE_GPIO_PIN: u32,
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21
596
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
22 pub AMBIENT_NAME: String,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
23 pub FRIDGE_NAME: String,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
24 pub WORT_NAME: String,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
25 pub INTERNAL_TEMPERATURE: String,
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26
596
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
27 pub HMAC_KEY: String,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
28 pub SERVER_URL: String,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
29 pub UPDATE_URL: String,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
30 pub SETTINGS_URL: String,
595
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
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 impl Config {
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 pub fn new() -> Self {
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 Config {
596
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
37 SENSOR_SLEEP: 5,
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
38 UPLOAD_SLEEP: 83,
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 FRIDGE_DELAY: 600, // 10 mins, to avoid fridge damage from frequent cycling off/on
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 FRIDGE_WORT_INVALID_TIME: 300, // 5 mins
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 // 12 hours of "offline" readings stored
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 MAX_READINGS: 12*60*60 / 15, // 15 is SENSOR_SLEEP
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 //PARAMS_FILE: os.path.join(os.path.dirname(__file__), "tempserver.conf")
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 PARAMS_FILE: "tempserver.conf".to_string(),
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49 SENSOR_BASE_DIR: "/sys/devices/w1_bus_master2".to_string(),
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 FRIDGE_GPIO_PIN: 17,
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51 //WORT_NAME: "28-0000042cf4dd".to_string(),
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 //FRIDGE_NAME: "28-0000042cccc4".to_string(),
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53 //AMBIENT_NAME: "28-0000042c6dbb".to_string(),
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54 AMBIENT_NAME: "missingambient".to_string(),
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 FRIDGE_NAME: "28-0000042c6dbb".to_string(),
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 WORT_NAME: "28-0000042cccc4".to_string(), // was fridge
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 INTERNAL_TEMPERATURE: "/sys/class/thermal/thermal_zone0/temp".to_string(),
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 HMAC_KEY: "a key".to_string(),
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 SERVER_URL: "https://evil.ucc.asn.au/~matt/templog".to_string(),
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 UPDATE_URL: "https://evil.ucc.asn.au/~matt/templog/update".to_string(),
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 SETTINGS_URL: "https://evil.ucc.asn.au/~matt/templog/get_settings".to_string(),
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 }
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 }
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65
596
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
66 pub fn to_toml_string(&self) -> String {
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 let mut e = toml::Encoder::new();
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 self.serialize(&mut e).unwrap();
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 toml::Value::Table(e.toml).to_string()
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70 }
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 }