islabtech_upw_sensor_v1/device/mod.rs
1//! The trait [`Device`] represents an UPW Sensor v1 device.
2//!
3//! Connect to it either with [`connect_via_network`] or with [`connect_via_network_on_port`].
4//!
5//! # Example
6//! ```rust,no_run
7//! # use islabtech_upw_sensor_v1::{connect_via_network_on_port, Device, Error};
8//! # use tokio;
9//! # use std::{thread::sleep, time::Duration};
10//! # #[tokio::main]
11//! # async fn main() -> Result<(), Error> {
12//! let sensor = connect_via_network_on_port(
13//! "192.168.1.123".parse().unwrap(),
14//! 80.into(), // port
15//! Default::default(), // TLS
16//! );
17//! let status = sensor.system_status().await?;
18//! println!("{status:?}");
19//! # Ok(())
20//! # }
21//! ```
22use crate::{
23 measurements::{Measurement, SuccessfulMeasurement},
24 SystemStatus,
25};
26use std::future::Future;
27
28pub mod network;
29
30// re-exports
31pub use network::{connect_via_network, connect_via_network_on_port};
32
33/// represents an UPW Sensor v1 device
34///
35/// see [`device`](crate::device) for documentation
36pub trait Device {
37 /// returns the latest measurement available or [`None`] if the sensor has just booted and not
38 /// read anything yet
39 ///
40 /// Calling this funtion will not trigger a new measurement. It will merely fetch the latest
41 /// measurement.
42 fn latest_measurement(
43 &self,
44 ) -> impl Future<Output = Result<Option<Measurement>, crate::Error>> + Send;
45
46 /// returns the latest successfull measurement available or [`None`] if the sensor has never read
47 /// a successful measurement since it last booted
48 ///
49 /// Calling this funtion will not trigger a new measurement. It will merely fetch the latest
50 /// measurement.
51 fn latest_successful_measurement(
52 &self,
53 ) -> impl Future<Output = Result<Option<SuccessfulMeasurement>, crate::Error>> + Send;
54
55 /// returns the entire history of [`Measurement`]s since the device booted. This includes
56 /// successful and erroneous measurements. The list may be empty if the device just booted and
57 /// has not performed any measurements yet.
58 fn measurement_history(
59 &self,
60 ) -> impl Future<Output = Result<Vec<Measurement>, crate::Error>> + Send;
61
62 /// returns the device's current system status
63 ///
64 /// see [`SystemStatus`] for more information
65 fn system_status(&self) -> impl Future<Output = Result<SystemStatus, crate::Error>> + Send;
66}