feat: 添加ValueType枚举并更新相关结构体
This commit is contained in:
parent
c88a0b2398
commit
02de1f4552
|
|
@ -4,6 +4,20 @@ use uuid::Uuid;
|
|||
|
||||
use crate::model::ScanMode;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ValueType {
|
||||
Null,
|
||||
Bool,
|
||||
Int,
|
||||
UInt,
|
||||
Float,
|
||||
Text,
|
||||
Bytes,
|
||||
Array,
|
||||
Object,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum PointQuality {
|
||||
|
|
@ -69,7 +83,7 @@ pub struct PointMonitorInfo {
|
|||
pub timestamp: Option<DateTime<Utc>>,
|
||||
pub quality: PointQuality,
|
||||
pub value: Option<DataValue>,
|
||||
pub value_type: Option<String>,
|
||||
pub value_type: Option<ValueType>,
|
||||
pub value_text: Option<String>,
|
||||
}
|
||||
|
||||
|
|
@ -85,7 +99,7 @@ pub struct PointValueChangeEvent {
|
|||
pub point_id: Option<Uuid>,
|
||||
pub client_handle: u32,
|
||||
pub value: Option<DataValue>,
|
||||
pub value_type: Option<String>,
|
||||
pub value_type: Option<ValueType>,
|
||||
pub value_text: Option<String>,
|
||||
pub quality: PointQuality,
|
||||
pub protocol: String,
|
||||
|
|
@ -101,7 +115,7 @@ pub struct WsPointMonitorInfo {
|
|||
pub timestamp: Option<String>,
|
||||
pub quality: PointQuality,
|
||||
pub value: Option<serde_json::Value>,
|
||||
pub value_type: Option<String>,
|
||||
pub value_type: Option<ValueType>,
|
||||
}
|
||||
|
||||
impl From<&PointMonitorInfo> for WsPointMonitorInfo {
|
||||
|
|
@ -146,9 +160,17 @@ pub fn opcua_variant_to_data(value: &opcua::types::Variant) -> DataValue {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn opcua_variant_type(value: &opcua::types::Variant) -> String {
|
||||
match value.scalar_type_id() {
|
||||
Some(t) => t.to_string(),
|
||||
None => "unknown".to_string(),
|
||||
pub fn opcua_variant_type(value: &opcua::types::Variant) -> ValueType {
|
||||
use opcua::types::Variant;
|
||||
match value {
|
||||
Variant::Empty => ValueType::Null,
|
||||
Variant::Boolean(_) => ValueType::Bool,
|
||||
Variant::SByte(_) | Variant::Int16(_) | Variant::Int32(_) | Variant::Int64(_) => ValueType::Int,
|
||||
Variant::Byte(_) | Variant::UInt16(_) | Variant::UInt32(_) | Variant::UInt64(_) => ValueType::UInt,
|
||||
Variant::Float(_) | Variant::Double(_) => ValueType::Float,
|
||||
Variant::String(_) => ValueType::Text,
|
||||
Variant::ByteString(_) => ValueType::Bytes,
|
||||
Variant::Array(_) => ValueType::Array,
|
||||
_ => ValueType::Text,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue