Переглянути джерело

base-station: Add documentation comments.

Mathias Gottschlag 5 роки тому
джерело
коміт
c4e88e5549

+ 6
- 0
base-station/software/src/current.rs Переглянути файл

@@ -1,9 +1,15 @@
1
+//! Cache of the most recently received reports.
2
+
1 3
 use std::collections::HashMap;
2 4
 
3 5
 use log::error;
4 6
 
5 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 13
 pub struct CurrentValues {
8 14
     map: HashMap<Key, i64>,
9 15
 }

+ 7
- 0
base-station/software/src/main.rs Переглянути файл

@@ -1,3 +1,7 @@
1
+//! Interface between the NRF24 sensors and MQTT/InfluxDB.
2
+//!
3
+//! TODO: Document configuration and hardware setup.
4
+
1 5
 use std::env;
2 6
 use std::io;
3 7
 use std::sync::Arc;
@@ -55,6 +59,7 @@ async fn main() {
55 59
     }
56 60
 }
57 61
 
62
+/// Type which implements packet handling and responds to requests from devices.
58 63
 struct Application {
59 64
     radio: Arc<Mutex<Radio>>,
60 65
     publish: Arc<Mutex<Publish>>,
@@ -64,6 +69,8 @@ struct Application {
64 69
 }
65 70
 
66 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 74
     async fn handle_packet(&mut self, device_id: u8, packet: Packet) {
68 75
         // TODO: More packet types to query timeseries database.
69 76
         match packet {

+ 20
- 0
base-station/software/src/publish.rs Переглянути файл

@@ -1,15 +1,35 @@
1
+//! Interface to a publish values via MQTT.
2
+
1 3
 use protocol::{Location, Value};
2 4
 
5
+// TODO: Configuration mechanism.
6
+
7
+/// Interface to MQTT.
3 8
 pub struct Publish {
4 9
     // TODO
5 10
 }
6 11
 
7 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 18
     pub fn init() -> Publish {
9 19
         // TODO
10 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 33
     pub async fn publish(&mut self, _location: Location, _values: &[Value]) {
14 34
         // TODO
15 35
     }

+ 13
- 0
base-station/software/src/radio.rs Переглянути файл

@@ -1,3 +1,5 @@
1
+//! Wrapper around the NRF24 driver which provides tokio-compatible asynchronous interfaces.
2
+
1 3
 /*use std::convert::TryInto;
2 4
 use std::sync::mpsc;
3 5
 use std::thread;
@@ -26,15 +28,18 @@ const DISPLAY_ID: u8 = 0x20;
26 28
 const WEATHER_STATION_0_ID: u8 = 0x30;
27 29
 //const WEATHER_STATION_0_KEY: [u8; 16] = include!("../../../common/weather_station_0_key.txt");
28 30
 
31
+/// Hardware configuration.
29 32
 pub struct RadioConfig {
30 33
     // TODO
31 34
 }
32 35
 
36
+/// Wrapper around the NRF24 radio driver.
33 37
 pub struct Radio {
34 38
     // TODO
35 39
 }
36 40
 
37 41
 impl Radio {
42
+    /// Initializes the radio and returns both radio and the stream of incoming packets.
38 43
     pub async fn init(
39 44
         _config: RadioConfig,
40 45
     ) -> Result<(Radio, UnboundedReceiver<(u8, Packet)>), RadioError> {
@@ -42,6 +47,14 @@ impl Radio {
42 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 58
     pub fn send_packet_async(&mut self, _device_id: u8, _packet: Packet) {
46 59
         // TODO
47 60
         panic!("Not yet implemented.");

+ 3
- 0
base-station/software/src/spi.rs Переглянути файл

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

+ 22
- 0
base-station/software/src/tsdb.rs Переглянути файл

@@ -1,17 +1,39 @@
1
+//! Interface to fill/query a timeseries database (InfluxDB).
2
+
1 3
 use std::time::Instant;
2 4
 
3 5
 use protocol::{Location, Value};
4 6
 
7
+// TODO: Configuration mechanism.
8
+
9
+/// Interface to InfluxDB.
5 10
 pub struct TimeSeriesDatabase {
6 11
     // TODO
7 12
 }
8 13
 
9 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 20
     pub fn init() -> TimeSeriesDatabase {
11 21
         // TODO
12 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 37
     pub async fn insert(&mut self, _time: Instant, _location: Location, _values: &[Value]) {
16 38
         // TODO
17 39
     }

Завантаження…
Відмінити
Зберегти