Browse Source

base-station: Add documentation comments.

Mathias Gottschlag 5 years ago
parent
commit
c4e88e5549

+ 6
- 0
base-station/software/src/current.rs View File

1
+//! Cache of the most recently received reports.
2
+
1
 use std::collections::HashMap;
3
 use std::collections::HashMap;
2
 
4
 
3
 use log::error;
5
 use log::error;
4
 
6
 
5
 use protocol::{Location, Value, ValueType};
7
 use protocol::{Location, Value, ValueType};
6
 
8
 
9
+/// Cache of the most recently received reports.
10
+///
11
+/// To remove the need to query MQTT/InfluxDB, this struct holds the most recently received reports
12
+/// from the sensors.
7
 pub struct CurrentValues {
13
 pub struct CurrentValues {
8
     map: HashMap<Key, i64>,
14
     map: HashMap<Key, i64>,
9
 }
15
 }

+ 7
- 0
base-station/software/src/main.rs View File

1
+//! Interface between the NRF24 sensors and MQTT/InfluxDB.
2
+//!
3
+//! TODO: Document configuration and hardware setup.
4
+
1
 use std::env;
5
 use std::env;
2
 use std::io;
6
 use std::io;
3
 use std::sync::Arc;
7
 use std::sync::Arc;
55
     }
59
     }
56
 }
60
 }
57
 
61
 
62
+/// Type which implements packet handling and responds to requests from devices.
58
 struct Application {
63
 struct Application {
59
     radio: Arc<Mutex<Radio>>,
64
     radio: Arc<Mutex<Radio>>,
60
     publish: Arc<Mutex<Publish>>,
65
     publish: Arc<Mutex<Publish>>,
64
 }
69
 }
65
 
70
 
66
 impl Application {
71
 impl Application {
72
+    /// Handles a single packet from a device and either sends the data to MQTT/InfluxDB or
73
+    /// generates a response to the device.
67
     async fn handle_packet(&mut self, device_id: u8, packet: Packet) {
74
     async fn handle_packet(&mut self, device_id: u8, packet: Packet) {
68
         // TODO: More packet types to query timeseries database.
75
         // TODO: More packet types to query timeseries database.
69
         match packet {
76
         match packet {

+ 20
- 0
base-station/software/src/publish.rs View File

1
+//! Interface to a publish values via MQTT.
2
+
1
 use protocol::{Location, Value};
3
 use protocol::{Location, Value};
2
 
4
 
5
+// TODO: Configuration mechanism.
6
+
7
+/// Interface to MQTT.
3
 pub struct Publish {
8
 pub struct Publish {
4
     // TODO
9
     // TODO
5
 }
10
 }
6
 
11
 
7
 impl Publish {
12
 impl Publish {
13
+    /// Initializes the connection to MQTT.
14
+    ///
15
+    /// The function does not return an error. Instead, the code will automatically retry
16
+    /// connection in case the connection cannot be established or the server closes the
17
+    /// connection.
8
     pub fn init() -> Publish {
18
     pub fn init() -> Publish {
9
         // TODO
19
         // TODO
10
         Publish {}
20
         Publish {}
11
     }
21
     }
12
 
22
 
23
+    /// Publishes values received from a device.
24
+    ///
25
+    /// If there is no current connection to MQTT and the connection cannot be reestablished before
26
+    /// the application is stopped, the values are lost. If multiple calls to this function occur
27
+    /// while there is no current connection to MQTT, only the latest values are published.
28
+    ///
29
+    /// # Arguments
30
+    ///
31
+    /// * `location` - the location of the device
32
+    /// * `values` - a list of values to be published
13
     pub async fn publish(&mut self, _location: Location, _values: &[Value]) {
33
     pub async fn publish(&mut self, _location: Location, _values: &[Value]) {
14
         // TODO
34
         // TODO
15
     }
35
     }

+ 13
- 0
base-station/software/src/radio.rs View File

1
+//! Wrapper around the NRF24 driver which provides tokio-compatible asynchronous interfaces.
2
+
1
 /*use std::convert::TryInto;
3
 /*use std::convert::TryInto;
2
 use std::sync::mpsc;
4
 use std::sync::mpsc;
3
 use std::thread;
5
 use std::thread;
26
 const WEATHER_STATION_0_ID: u8 = 0x30;
28
 const WEATHER_STATION_0_ID: u8 = 0x30;
27
 //const WEATHER_STATION_0_KEY: [u8; 16] = include!("../../../common/weather_station_0_key.txt");
29
 //const WEATHER_STATION_0_KEY: [u8; 16] = include!("../../../common/weather_station_0_key.txt");
28
 
30
 
31
+/// Hardware configuration.
29
 pub struct RadioConfig {
32
 pub struct RadioConfig {
30
     // TODO
33
     // TODO
31
 }
34
 }
32
 
35
 
36
+/// Wrapper around the NRF24 radio driver.
33
 pub struct Radio {
37
 pub struct Radio {
34
     // TODO
38
     // TODO
35
 }
39
 }
36
 
40
 
37
 impl Radio {
41
 impl Radio {
42
+    /// Initializes the radio and returns both radio and the stream of incoming packets.
38
     pub async fn init(
43
     pub async fn init(
39
         _config: RadioConfig,
44
         _config: RadioConfig,
40
     ) -> Result<(Radio, UnboundedReceiver<(u8, Packet)>), RadioError> {
45
     ) -> Result<(Radio, UnboundedReceiver<(u8, Packet)>), RadioError> {
42
         panic!("Not yet implemented.");
47
         panic!("Not yet implemented.");
43
     }
48
     }
44
 
49
 
50
+    /// Sends a packet to the specified device.
51
+    ///
52
+    /// The function returns immediately, and the packet might or might not be sent successfully.
53
+    ///
54
+    /// # Arguments
55
+    ///
56
+    /// * `device_id` - the ID of the targeted device
57
+    /// * `packet` - the packet to send
45
     pub fn send_packet_async(&mut self, _device_id: u8, _packet: Packet) {
58
     pub fn send_packet_async(&mut self, _device_id: u8, _packet: Packet) {
46
         // TODO
59
         // TODO
47
         panic!("Not yet implemented.");
60
         panic!("Not yet implemented.");

+ 3
- 0
base-station/software/src/spi.rs View File

1
+//! Implementation of `embedded_hal::blocking::spi::Transfer` for `linux_embedded_hal::spidev`.
2
+
1
 use std::io;
3
 use std::io;
2
 
4
 
3
 use embedded_hal::blocking::spi::Transfer;
5
 use embedded_hal::blocking::spi::Transfer;
4
 use linux_embedded_hal::spidev::Spidev;
6
 use linux_embedded_hal::spidev::Spidev;
5
 use linux_embedded_hal::spidev::SpidevTransfer;
7
 use linux_embedded_hal::spidev::SpidevTransfer;
6
 
8
 
9
+/// Wrapper around `linux_embedded_hal::spidev::Spidev` which provides `Transfer`.
7
 pub struct EmbeddedHalSpidev {
10
 pub struct EmbeddedHalSpidev {
8
     spi: Spidev,
11
     spi: Spidev,
9
 }
12
 }

+ 22
- 0
base-station/software/src/tsdb.rs View File

1
+//! Interface to fill/query a timeseries database (InfluxDB).
2
+
1
 use std::time::Instant;
3
 use std::time::Instant;
2
 
4
 
3
 use protocol::{Location, Value};
5
 use protocol::{Location, Value};
4
 
6
 
7
+// TODO: Configuration mechanism.
8
+
9
+/// Interface to InfluxDB.
5
 pub struct TimeSeriesDatabase {
10
 pub struct TimeSeriesDatabase {
6
     // TODO
11
     // TODO
7
 }
12
 }
8
 
13
 
9
 impl TimeSeriesDatabase {
14
 impl TimeSeriesDatabase {
15
+    /// Initializes the connection to InfluxDB.
16
+    ///
17
+    /// The function does not return an error. Instead, the code will automatically retry
18
+    /// connection in case the connection cannot be established or the server closes the
19
+    /// connection.
10
     pub fn init() -> TimeSeriesDatabase {
20
     pub fn init() -> TimeSeriesDatabase {
11
         // TODO
21
         // TODO
12
         TimeSeriesDatabase {}
22
         TimeSeriesDatabase {}
13
     }
23
     }
14
 
24
 
25
+    /// Inserts values into the database.
26
+    ///
27
+    /// If there is no current connection to InfluxDB and the connection cannot be reestablished
28
+    /// before the application is stopped, the values are lost. If multiple calls to this function
29
+    /// occur while there is no current connection to InfluxDB, the values are queued and all
30
+    /// values are inserted at a later time.
31
+    ///
32
+    /// # Arguments
33
+    ///
34
+    /// * `time` - time at which the values were received
35
+    /// * `location` - location of the device which sent the values
36
+    /// * `values` - list of values to be inserted into the database
15
     pub async fn insert(&mut self, _time: Instant, _location: Location, _values: &[Value]) {
37
     pub async fn insert(&mut self, _time: Instant, _location: Location, _values: &[Value]) {
16
         // TODO
38
         // TODO
17
     }
39
     }

Loading…
Cancel
Save