Compare commits

...

3 Commits

5 changed files with 14 additions and 42 deletions

View File

@ -261,8 +261,8 @@ impl ConnectionManager {
.map(crate::telemetry::PointQuality::from_status_code)
.unwrap_or(crate::telemetry::PointQuality::Unknown);
let _ = event_manager.send(crate::event::ReloadEvent::PointValueChange(
crate::telemetry::PointValueChangeEvent {
let _ = event_manager.send(crate::event::ReloadEvent::PointNewValue(
crate::telemetry::PointNewValue {
source_id,
point_id: Some(point_id),
client_handle: 0,
@ -758,8 +758,8 @@ impl ConnectionManager {
// Emit local updates only when the full batch succeeds.
if let Some(event_manager) = &self.event_manager {
for (source_id, point_id, variant) in success_events {
if let Err(e) = event_manager.send(crate::event::ReloadEvent::PointValueChange(
crate::telemetry::PointValueChangeEvent {
if let Err(e) = event_manager.send(crate::event::ReloadEvent::PointNewValue(
crate::telemetry::PointNewValue {
source_id,
point_id: Some(point_id),
client_handle: 0,
@ -883,8 +883,8 @@ impl ConnectionManager {
.unwrap_or(crate::telemetry::PointQuality::Unknown);
if let Some(event_manager) = &manager.event_manager {
let _ = event_manager.send(crate::event::ReloadEvent::PointValueChange(
crate::telemetry::PointValueChangeEvent {
let _ = event_manager.send(crate::event::ReloadEvent::PointNewValue(
crate::telemetry::PointNewValue {
source_id: current_source_id,
point_id: None,
client_handle,

View File

@ -24,7 +24,7 @@ pub enum ReloadEvent {
source_id: Uuid,
point_ids: Vec<Uuid>,
},
PointValueChange(crate::telemetry::PointValueChangeEvent),
PointNewValue(crate::telemetry::PointNewValue),
}
pub struct EventManager {
@ -118,7 +118,7 @@ impl EventManager {
tracing::error!("Failed to unsubscribe points: {}", e);
}
}
ReloadEvent::PointValueChange(payload) => {
ReloadEvent::PointNewValue(payload) => {
let source_id = payload.source_id;
let client_handle = payload.client_handle;
let point_id = if let Some(point_id) = payload.point_id {
@ -149,8 +149,8 @@ impl EventManager {
}
if let Some(ws_manager) = &ws_manager_clone {
let ws_message = crate::websocket::WsMessage::PointValueChange(
crate::telemetry::WsPointMonitorInfo::from(&monitor),
let ws_message = crate::websocket::WsMessage::PointNewValue(
monitor.clone(),
);
if let Err(e) = ws_manager.send_to_public(ws_message.clone()).await {

View File

@ -21,7 +21,7 @@ pub struct GetPointListQuery {
pub struct PointWithMonitor {
#[serde(flatten)]
pub point: Point,
pub point_monitor: Option<crate::telemetry::WsPointMonitorInfo>,
pub point_monitor: Option<crate::telemetry::PointMonitorInfo>,
}
pub async fn get_point_list(
@ -63,8 +63,7 @@ pub async fn get_point_list(
.map(|point| {
let point_monitor = monitor_guard
.get(&point.id)
.cloned()
.map(|m| crate::telemetry::WsPointMonitorInfo::from(&m));
.cloned();
PointWithMonitor { point, point_monitor }
})
.collect();

View File

@ -94,7 +94,7 @@ impl PointMonitorInfo {
}
#[derive(Debug, Clone)]
pub struct PointValueChangeEvent {
pub struct PointNewValue {
pub source_id: Uuid,
pub point_id: Option<Uuid>,
pub client_handle: u32,
@ -107,33 +107,6 @@ pub struct PointValueChangeEvent {
pub scan_mode: ScanMode,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WsPointMonitorInfo {
pub protocol: String,
pub point_id: Uuid,
pub scan_mode: String,
pub timestamp: Option<String>,
pub quality: PointQuality,
pub value: Option<serde_json::Value>,
pub value_type: Option<ValueType>,
}
impl From<&PointMonitorInfo> for WsPointMonitorInfo {
fn from(m: &PointMonitorInfo) -> Self {
Self {
protocol: m.protocol.clone(),
point_id: m.point_id,
scan_mode: m.scan_mode.to_string(),
timestamp: m
.timestamp
.as_ref()
.map(crate::util::datetime::utc_to_local_string),
quality: m.quality.clone(),
value: m.value_as_json(),
value_type: m.value_type.clone(),
}
}
}
pub fn opcua_variant_to_data(value: &opcua::types::Variant) -> DataValue {
use opcua::types::Variant;

View File

@ -15,7 +15,7 @@ use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", content = "data")]
pub enum WsMessage {
PointValueChange(crate::telemetry::WsPointMonitorInfo),
PointNewValue(crate::telemetry::PointMonitorInfo),
PointSetValueBatchResult(crate::connection::BatchSetPointValueRes),
}