use std::time::Instant;
use bacnet_types::enums::PropertyIdentifier;
use bacnet_types::primitives::ObjectIdentifier;
use super::point::Health;
pub(crate) type RowId = u32;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) struct Point {
pub(crate) device: u32,
pub(crate) network: Option<u16>,
pub(crate) object: ObjectIdentifier,
pub(crate) property: PropertyIdentifier,
}
impl Point {
pub(crate) fn device_label(&self) -> String {
match self.network {
Some(network) => format!("{network}:{}", self.device),
None => self.device.to_string(),
}
}
pub(crate) fn whole_object(&self) -> bool {
self.property == PropertyIdentifier::PRESENT_VALUE
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) enum WatchCommand {
Add {
row: RowId,
point: Point,
},
Remove {
row: RowId,
},
Csv(bool),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) enum Source {
Starting,
Cov {
lifetime: u32,
},
Polled(String),
Failed(String),
}
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct Sample {
pub(crate) value: Result<String, String>,
pub(crate) number: Option<f64>,
pub(crate) flags: Option<Health>,
pub(crate) at: Instant,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub(crate) struct WatchStats {
pub(crate) subscriptions: usize,
pub(crate) recent_requests: usize,
pub(crate) csv: Option<String>,
}
pub(crate) const METER_WINDOW_SECS: u64 = 10;
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum WatchEvent {
Source {
row: RowId,
source: Source,
},
Details {
row: RowId,
name: Option<String>,
units: Option<String>,
},
Samples(Vec<(RowId, Sample)>),
Stats(WatchStats),
Notice(String),
}