Skip to content

Commit

Permalink
Support multiple ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
einarmo committed Sep 18, 2024
1 parent fbd5840 commit 9f90b94
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/tests/utils/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ pub fn default_client(test_id: u16, quick_timeout: bool) -> ClientBuilder {
.max_array_length(100_000)
.max_message_size(1024 * 1024 * 64)
.max_chunk_count(64);

if quick_timeout {
client.session_retry_limit(1)
} else {
Expand Down
7 changes: 1 addition & 6 deletions opcua-nodes/src/events/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,7 @@ mod tests {
}

fn get(id: &NodeId, evt: &dyn Event, field: &str) -> Variant {
evt.get_field(
id,
AttributeId::Value,
&NumericRange::None,
&[field.into()],
)
evt.get_field(id, AttributeId::Value, &NumericRange::None, &[field.into()])
}

fn get_nested(id: &NodeId, evt: &dyn Event, fields: &[&str]) -> Variant {
Expand Down
50 changes: 29 additions & 21 deletions opcua-server/src/subscriptions/monitored_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,32 +775,40 @@ pub(super) mod tests {
assert!(DataChangeFilter::abs_compare(100f64, 100f64, 1f64));
assert!(DataChangeFilter::abs_compare(100f64, 101f64, 1f64));
assert!(DataChangeFilter::abs_compare(101f64, 100f64, 1f64));
assert!(
!DataChangeFilter::abs_compare(101.001f64, 100f64, 1f64)
);
assert!(
!DataChangeFilter::abs_compare(100f64, 101.001f64, 1f64)
);
assert!(!DataChangeFilter::abs_compare(101.001f64, 100f64, 1f64));
assert!(!DataChangeFilter::abs_compare(100f64, 101.001f64, 1f64));
}

// Straight tests of pct function
#[test]
fn deadband_pct() {
assert!(
!DataChangeFilter::pct_compare(100f64, 101f64, 0f64, 100f64, 0f64)
);
assert!(
DataChangeFilter::pct_compare(100f64, 101f64, 0f64, 100f64, 1f64)
);
assert!(
!DataChangeFilter::pct_compare(100f64, 101.0001f64, 0f64, 100f64, 1f64)
);
assert!(
!DataChangeFilter::pct_compare(101.0001f64, 100f64, 0f64, 100f64, 1f64)
);
assert!(
DataChangeFilter::pct_compare(101.0001f64, 100f64, 0f64, 100f64, 1.0002f64)
);
assert!(!DataChangeFilter::pct_compare(
100f64, 101f64, 0f64, 100f64, 0f64
));
assert!(DataChangeFilter::pct_compare(
100f64, 101f64, 0f64, 100f64, 1f64
));
assert!(!DataChangeFilter::pct_compare(
100f64,
101.0001f64,
0f64,
100f64,
1f64
));
assert!(!DataChangeFilter::pct_compare(
101.0001f64,
100f64,
0f64,
100f64,
1f64
));
assert!(DataChangeFilter::pct_compare(
101.0001f64,
100f64,
0f64,
100f64,
1.0002f64
));
}

#[test]
Expand Down
29 changes: 25 additions & 4 deletions opcua-types/src/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1872,10 +1872,31 @@ impl Variant {
_ => Err(StatusCode::BadIndexRangeDataMismatch),
}
}
NumericRange::MultipleRanges(_ranges) => {
// Not yet supported
error!("Multiple ranges not supported");
Err(StatusCode::BadIndexRangeNoData)
NumericRange::MultipleRanges(ranges) => {
let mut res = Vec::new();
for range in ranges {
let v = self.range_of(range)?;
match v {
Variant::Array(a) => {
res.extend(a.values.into_iter());
}
r => res.push(r),
}
}
let type_id = if !res.is_empty() {
let VariantTypeId::Scalar(s) = res[0].type_id() else {
return Err(StatusCode::BadIndexRangeNoData);
};
s
} else {
match self.type_id() {
VariantTypeId::Array(s, _) => s,
VariantTypeId::Scalar(s) => s,
VariantTypeId::Empty => return Ok(Variant::Empty),
}
};

Ok(Self::Array(Box::new(Array::new(type_id, res)?)))
}
}
}
Expand Down

0 comments on commit 9f90b94

Please sign in to comment.