Skip to content

Commit

Permalink
Merge pull request #125 from rneswold/pull-request
Browse files Browse the repository at this point in the history
Some clean-up
  • Loading branch information
rneswold authored Aug 18, 2024
2 parents 3d05a0d + 349d414 commit b9916e0
Show file tree
Hide file tree
Showing 14 changed files with 485 additions and 413 deletions.
271 changes: 118 additions & 153 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 7 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,18 @@ resolver = "2"

[workspace.dependencies]
async-trait = { version = "0.1", default-features = false }

futures = { version = "0.3", features = ["std"] }

toml = { version = "0.8", default-features = false }
chrono = { version = "0.4", default-features = false }

futures = { version = "0.3", default-features = false }
toml = { version = "0.8", default-features = false }
tokio = { version = "1", default-features = false }
tokio-stream = { version = "0.1", default-features = false }
tracing = { version = "0.1", features = ["std"] }
tracing = { version = "0.1", default-features = false }
tracing-futures = { version = "0.2", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false }

serde = { version = "1.0", default-features = false }
serde_json = { version = "1.0", default-features = false }
serde_derive = { version = "1.0", default-features = false }

palette = "0.7"
serde = { version = "1", default-features = false }
serde_json = { version = "1", default-features = false }
serde_derive = { version = "1", default-features = false }
palette = { version = "0.7", default-features = false }

# Profiles used by all binaries and packages.

Expand Down
13 changes: 11 additions & 2 deletions drivers/drmem-drv-ntp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@ doctest = false

[dependencies]
toml.workspace = true
toml.default-features = false

tokio.workspace = true
tokio.default-features = false
tokio.features = ["net", "time", "macros"]

tokio = { workspace = true, features = ["net", "io-util", "time", "macros"] }
tracing.workspace = true
tracing.default-features = false

tracing-futures.workspace = true
tracing-futures.default-features = false

tracing-subscriber.workspace = true
tracing-subscriber.default-features = false

drmem-api = { path = "../../drmem-api", version = "0.4" }
drmem-api = { path = "../../drmem-api", version = "0.5" }
16 changes: 13 additions & 3 deletions drivers/drmem-drv-sump/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,23 @@ keywords = ["control-system", "automation"]
doctest = false

[dependencies]
socket2 = "0.5"
socket2.version = "0.5"
socket2.default-features = false

toml.workspace = true
toml.default-features = false

tokio.workspace = true
tokio.default-features = false
tokio.features = ["net", "io-util", "time"]

tokio = { workspace = true, features = ["net", "io-util", "time"] }
tracing.workspace = true
tracing.default-features = false

tracing-futures.workspace = true
tracing-futures.default-features = false

tracing-subscriber.workspace = true
tracing-subscriber.default-features = false

drmem-api = { path = "../../drmem-api", version = "0.4" }
drmem-api = { path = "../../drmem-api", version = "0.5" }
28 changes: 24 additions & 4 deletions drivers/drmem-drv-tplink/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,35 @@ keywords = ["control-system", "automation"]
doctest = false

[dependencies]

toml.workspace = true
toml.default-features = false

futures.workspace = true
tokio = { workspace = true, features = ["net", "time", "macros", "io-util"] }
futures.default-features = false

tokio.workspace = true
tokio.default-features = false
tokio.features = ["net", "time", "macros", "io-util"]

tracing.workspace = true
tracing.default-features = false

tracing-futures.workspace = true
tracing-futures.default-features = false

tracing-subscriber.workspace = true
serde = { workspace = true, features = ["derive"] }
tracing-subscriber.default-features = false

serde.workspace = true
serde.default-features = false
serde.features = ["derive"]

serde_derive.workspace = true
serde_json = { workspace = true, features = ["std"] }
serde_derive.default-features = false

serde_json.workspace = true
serde_json.default-features = false
serde_json.features = ["std"]

drmem-api = { path = "../../drmem-api", version = "0.4" }
drmem-api = { path = "../../drmem-api", version = "0.5" }
20 changes: 16 additions & 4 deletions drivers/drmem-drv-weather-wu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,26 @@ keywords = ["control-system", "automation"]
doctest = false

[dependencies]

toml.workspace = true
toml.default-features = false

tokio.workspace = true
tokio.default-features = false

tokio = { workspace = true, features = ["net", "io-util"] }
tracing.workspace = true
tracing.default-features = false

tracing-futures.workspace = true
tracing-futures.default-features = false

tracing-subscriber.workspace = true
tracing-subscriber.default-features = false

reqwest.version = "0.11"
reqwest.default-features = false

reqwest = { default-features = false, version = "0.11" }
weather-underground = "0.1"
weather-underground.version = "0.1"
weather-underground.default-features = false

drmem-api = { path = "../../drmem-api", version = "0.4" }
drmem-api = { path = "../../drmem-api", version = "0.5" }
16 changes: 12 additions & 4 deletions drmem-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "drmem-api"
version = "0.4.1"
version = "0.5.0"
authors = ["Rich Neswold <[email protected]>"]
edition = "2021"
description = "Traits and types used internally by the DrMem control system"
Expand All @@ -17,16 +17,24 @@ doctest = false
maintenance = { status = "actively-developed" }

[dependencies]
async-trait.workspace = true
chrono.workspace = true
chrono.default-features = false

toml.workspace = true

chrono.workspace = true
toml.default-features = false

tokio.workspace = true
tokio.default-features = false

tokio-stream.workspace = true
tokio-stream.default-features = false

serde.workspace = true
serde.default-features = false

serde_derive.workspace = true
serde_derive.default-features = false

palette.workspace = true
palette.default-features = false
palette.features = ["libm"]
129 changes: 2 additions & 127 deletions drmem-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
//! This crate is used by internal tasks of `drmemd` as well as
//! hardware drivers.
//! This crate is used by hardware drivers.
//!
//! The interfaces and types defined in this crate are useful for
//! those wishing to write a new back-end storage module or a driver
//! for the `drmemd` executable.
use async_trait::async_trait;
use chrono::*;
//! those wishing to write a new driver for the `drmemd` executable.
mod types;

Expand All @@ -20,125 +15,5 @@ pub use types::Error;
pub type Result<T> = std::result::Result<T, Error>;

/// Defines the trait that a back-end needs to implement to provide
/// storage for -- and access to -- the state of each driver's
/// devices.
#[async_trait]
pub trait Store {
/// Called when a read-only device is to be registered with the
/// back-end.
///
/// When `drmemd` begins, it starts up the set of drivers
/// specified in the configuration file. As these drivers
/// initialize, they'll register the devices they need. For
/// read-only devices, this method will be called.
///
/// - `driver` is the name of the driver. The framework will
/// guarantee that this parameter is consistent for all devices
/// defined by a driver.
/// - `name` is the full name of the device.
/// - `units` is an optional value which specifies the engineering
/// units returned by the device.
/// - `max_history` is a hint as to how large an archive the user
/// specifies should be used for this device.
///
/// On success, this function returns a pair. The first element is
/// a closure the driver uses to report updates. The second
/// element is an optional value representing the last value of
/// the device, as saved in the back-end.
async fn register_read_only_device(
&mut self,
driver: &str,
name: &types::device::Name,
units: Option<&String>,
max_history: Option<usize>,
) -> Result<(
driver::ReportReading<types::device::Value>,
Option<types::device::Value>,
)>;

/// Called when a read-write device is to be registered with the
/// back-end.
///
/// When `drmemd` begins, it starts up the set of drivers
/// specified in the configuration file. As these drivers
/// initialize, they'll register the devices they need. For
/// read-write devices, this method will be called.
///
/// - `driver` is the name of the driver. The framework will
/// guarantee that this parameter is consistent for all devices
/// defined by a driver.
/// - `name` is the full name of the device.
/// - `units` is an optional value which specifies the engineering
/// units returned by the device.
/// - `max_history` is a hint as to how large an archive the user
/// specifies should be used for this device.
///
/// On success, this function returns a 3-tuple. The first element
/// is a closure the driver uses to report updates. The second
/// element is a handle with which the driver will receive setting
/// requests. The third element is an optional value representing
/// the last value of the device, as saved in the back-end.
async fn register_read_write_device(
&mut self,
driver: &str,
name: &types::device::Name,
units: Option<&String>,
max_history: Option<usize>,
) -> Result<(
driver::ReportReading<types::device::Value>,
driver::RxDeviceSetting,
Option<types::device::Value>,
)>;

/// Called when information from a device is requested.
///
/// On success, this method should return an array of
/// `client::DevInfoReply` data. If a `pattern` is specified, only
/// device names matching the pattern should be returned. The
/// grammar of the pattern is the one used by Redis (to be
/// consistent across back-ends.)
async fn get_device_info(
&mut self,
pattern: Option<&str>,
) -> Result<Vec<client::DevInfoReply>>;

/// Sends a request to a driver to set its device to the specified
/// value.
async fn set_device(
&self,
name: types::device::Name,
value: types::device::Value,
) -> Result<types::device::Value>;

/// Obtains the `mpsc::Sender<>` handle associated with the
/// specified device. This handle can be used to send settings to
/// the device. If 'own` is set to `true`, the requester will be
/// the only one that can send settings to the device. NOTE: `own`
/// is currently unsupported and should always be set to
/// 'false'. When it gets supported, requesters can decide whether
/// they should set it to true.
async fn get_setting_chan(
&self,
name: types::device::Name,
own: bool,
) -> Result<driver::TxDeviceSetting>;

/// Creates a stream that yields values of a device as it updates.
async fn monitor_device(
&mut self,
name: types::device::Name,
start: Option<DateTime<Utc>>,
end: Option<DateTime<Utc>>,
) -> Result<types::device::DataStream<types::device::Reading>>;
}

pub mod client;
pub mod driver;
Loading

0 comments on commit b9916e0

Please sign in to comment.