pub enum ControlSpec {
Setpoint {
setpoint: f32,
hysteresis: f32,
cooling: bool,
safe_band: f32,
},
Level {
empty: f32,
warn_within: u32,
},
Surge {
rising: bool,
limit: f32,
},
Monitor,
Custom {
kind: String,
params: Params,
},
}Expand description
How a profile turns each reading into control output and alerts.
This is the policy half of a profile’s manifest: the tunable rule a community can
publish and share, with no code to write. Profile::controller assembles it
into a live Controller. In a manifest it is tagged by kind, with the kind’s
parameters beside it:
{ "kind": "setpoint", "setpoint": 5.0, "hysteresis": 0.5, "cooling": true, "safe_band": 3.0 }A kind the library does not know is a Custom policy: it
loads with every other field kept as its Params, and a
PolicyRegistry resolves it to the code that decides it,
so a manifest for a policy of your own reads exactly like one for a setpoint:
{ "kind": "frost_guard", "warn_below": 2.0 }Variants§
Setpoint
Hold a reading near setpoint by switching an output on and off.
Fields
hysteresis: f32Half the deadband width around the setpoint, which stops the output chattering at the threshold.
cooling: boolWhether the output cools (switches on above the band) or heats (switches on below it). An irrigation valve that adds water is a “heater”.
safe_band: f32How far the reading may stray from the setpoint before an
Alert::OutOfRange fires.
Level
Watch a falling level and warn before it reaches empty.
Fields
Surge
Warn when a reading changes faster than limit per sample.
Fields
Monitor
Report readings only, with no control output and no alerts.
Custom
A policy the library does not ship, named by the manifest and decided by code a
PolicyRegistry resolves the kind to.
Implementations§
Source§impl ControlSpec
impl ControlSpec
Sourcepub fn kind(&self) -> &str
pub fn kind(&self) -> &str
Returns the kind as a manifest names it.
§Returns
"setpoint", "level", "surge", "monitor", or a custom kind’s own name.
Sourcepub fn custom(kind: impl Into<String>, params: Params) -> Result<Self>
pub fn custom(kind: impl Into<String>, params: Params) -> Result<Self>
Creates a policy of a kind the library does not ship, checked so it survives a trip through its manifest.
§Arguments
kind- the kind as the manifest will name it, such as"frost_guard".params- every other field the policy needs.
§Returns
The custom policy.
§Errors
Returns Error::Codec if kind is empty or names a
built-in kind, which a manifest would read back as that kind, or if params
holds a field named kind, which the manifest keeps for the kind itself.
§Examples
use pamoja_profile::{ControlSpec, Params};
let guard = ControlSpec::custom("frost_guard", Params::new().with("warn_below", 2.0))?;
assert_eq!(guard.kind(), "frost_guard");
assert!(ControlSpec::custom("setpoint", Params::new()).is_err());Trait Implementations§
Source§impl Clone for ControlSpec
impl Clone for ControlSpec
Source§fn clone(&self) -> ControlSpec
fn clone(&self) -> ControlSpec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more