use of org.eclipse.milo.opcua.stack.core.types.enumerated.DeadbandType in project milo by eclipse.
the class DataChangeMonitoringFilter method deadbandFilter.
private static boolean deadbandFilter(DataValue lastValue, DataValue currentValue, DataChangeFilter filter) {
if (lastValue == null)
return true;
int index = filter.getDeadbandType().intValue();
if (index < 0 || index >= DeadbandType.values().length)
return true;
DeadbandType deadbandType = DeadbandType.values()[index];
if (deadbandType != DeadbandType.Absolute)
return true;
Object last = lastValue.getValue().getValue();
Object current = currentValue.getValue().getValue();
if (last == null || current == null) {
return true;
} else if (last.getClass().isArray() && current.getClass().isArray()) {
return compareArrayDeadband(last, current, filter.getDeadbandValue());
} else {
return compareScalarDeadband(last, current, filter.getDeadbandValue());
}
}
use of org.eclipse.milo.opcua.stack.core.types.enumerated.DeadbandType in project milo by eclipse.
the class SubscriptionManager method validateDataItemFilter.
private MonitoringFilter validateDataItemFilter(Object filterObject, UInteger attributeId, AttributeGroup attributeGroup) throws UaException {
if (filterObject instanceof MonitoringFilter) {
if (filterObject instanceof DataChangeFilter) {
DataChangeFilter filter = (DataChangeFilter) filterObject;
DeadbandType deadbandType = DeadbandType.from(filter.getDeadbandType().intValue());
if (deadbandType == null) {
throw new UaException(StatusCodes.Bad_DeadbandFilterInvalid);
}
if (deadbandType == DeadbandType.Percent) {
// Percent deadband is not currently implemented
throw new UaException(StatusCodes.Bad_MonitoredItemFilterUnsupported);
}
if (deadbandType == DeadbandType.Absolute && !AttributeId.Value.isEqual(attributeId)) {
// Absolute deadband is only allowed for Value attributes
throw new UaException(StatusCodes.Bad_FilterNotAllowed);
}
if (deadbandType != DeadbandType.None) {
NodeId dataTypeId = null;
try {
dataTypeId = attributeGroup.getDataType();
} catch (UaException ignored) {
// noop
}
if (dataTypeId == null) {
dataTypeId = NodeId.NULL_VALUE;
}
if (!Identifiers.Number.equals(dataTypeId) && !subtypeOf(server, dataTypeId, Identifiers.Number)) {
throw new UaException(StatusCodes.Bad_FilterNotAllowed);
}
}
return filter;
} else if (filterObject instanceof EventFilter) {
throw new UaException(StatusCodes.Bad_FilterNotAllowed);
} else {
// AggregateFilter or some future unimplemented filter
throw new UaException(StatusCodes.Bad_MonitoredItemFilterUnsupported);
}
} else {
throw new UaException(StatusCodes.Bad_MonitoredItemFilterInvalid);
}
}
Aggregations