Skip to main content

Wiring

Struct Wiring 

Source
pub struct Wiring {
    pub site: String,
    pub profile: String,
    pub sensor: SensorWiring,
    pub output: Option<OutputWiring>,
    pub link: LinkWiring,
    pub battery: Option<BatteryWiring>,
}
Expand description

One site’s wiring: the part, the output, the link, and the battery a profile runs with.

{
  "$schema": "https://pamoja.molex.cloud/schema/wiring-1.json",
  "site": "coop-2",
  "profile": "brooder-heater.json",
  "sensor": { "part": "bme280", "bus": "/dev/i2c-1", "address": "0x76" },
  "output": { "gpio": "/dev/gpiochip0", "line": 17, "active_low": true },
  "link": { "mqtt": "192.168.1.10" }
}

Like a profile it is refused, with the field it was probably meant to be, when it holds a field its format does not have.

Fields§

§site: String

The site’s name, which the node’s logs and its MQTT client id carry.

§profile: String

The profile to run, as a path relative to the wiring file.

§sensor: SensorWiring

The part that takes the readings.

§output: Option<OutputWiring>

The output the profile drives, if it drives one.

§link: LinkWiring

The link the readings are published over.

§battery: Option<BatteryWiring>

The battery the node runs from, if it runs from one.

Implementations§

Source§

impl Wiring

Source

pub const SCHEMA: &'static str = "https://pamoja.molex.cloud/schema/wiring-1.json"

The address of the published JSON Schema for the wiring file format this build writes.

Source

pub fn check(&self) -> Result<()>

Checks the wiring for what a runner could not open.

§Returns

Nothing when every part of the wiring can be opened.

§Errors

Returns Error::Codec naming the first problem: an empty site or profile path; an I2C part with no bus, a DS18B20 with no serial, a replay with no readings, an address past 0x7f or on a part that answers at only one, or a calibration that is not a finite number; a GPIO output with no chip; an MQTT link with no host, port 0, or a password without a username; or a battery on a part that is not a power monitor, or whose full voltage is not above its empty one.

Source

pub fn fits(&self, profile: &Profile) -> Result<Plan>

Checks that this wiring can run a profile, and says how its reading is taken.

§Arguments
  • profile - the profile to run.
§Returns

The plan for the reading: the part’s quantity and how it reaches the profile’s unit.

§Errors

Returns Error::Codec when the profile does not say what it reads, the part does not measure it, the part’s unit does not convert to the profile’s, the profile’s control kind is one only a program of its own can decide, a profile that switches an output has none wired, or one that switches nothing has one wired that would never move.

§Examples
use pamoja_profile::wiring::Wiring;
use pamoja_profile::Profile;

let wiring = Wiring::from_json(r#"{
    "site": "coop-2",
    "profile": "brooder-heater.json",
    "sensor": { "part": "bme280", "bus": "/dev/i2c-1" },
    "output": { "gpio": "/dev/gpiochip0", "line": 17, "active_low": true },
    "link": { "mqtt": "192.168.1.10" }
}"#)?;
let fridge = Profile::vaccine_fridge_monitor();
let plan = wiring.fits(&fridge)?;
assert_eq!((plan.quantity.as_str(), plan.from.as_str()), ("temperature", "celsius"));

// A soil probe's profile cannot run on a thermometer.
let refused = wiring.fits(&Profile::irrigation_node()).unwrap_err().to_string();
assert!(refused.contains("a bme280 measures temperature, relative_humidity, or pressure"));
Source§

impl Wiring

Source

pub fn from_json(text: &str) -> Result<Self>

Loads a wiring file.

§Arguments
  • text - the file’s contents.
§Returns

The wiring.

§Errors

Returns Error::Codec if the text is not a wiring file, is written in a format this build does not read, carries a field the format does not have, with the one it was probably meant to be, or describes wiring check refuses.

Source

pub fn to_json(&self) -> Result<String>

Writes the wiring as its file.

§Returns

The pretty-printed JSON text, which names its format with $schema.

§Errors

Returns Error::Codec if the wiring cannot be serialized.

Trait Implementations§

Source§

impl Clone for Wiring

Source§

fn clone(&self) -> Wiring

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Wiring

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Wiring

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Wiring

Source§

fn eq(&self, other: &Wiring) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Wiring

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Wiring

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.