Search in sources :

Example 1 with DeadbandType

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());
    }
}
Also used : DeadbandType(org.eclipse.milo.opcua.stack.core.types.enumerated.DeadbandType)

Example 2 with DeadbandType

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);
    }
}
Also used : DeadbandType(org.eclipse.milo.opcua.stack.core.types.enumerated.DeadbandType) UaException(org.eclipse.milo.opcua.stack.core.UaException) DataChangeFilter(org.eclipse.milo.opcua.stack.core.types.structured.DataChangeFilter) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) MonitoringFilter(org.eclipse.milo.opcua.stack.core.types.structured.MonitoringFilter) EventFilter(org.eclipse.milo.opcua.stack.core.types.structured.EventFilter)

Aggregations

DeadbandType (org.eclipse.milo.opcua.stack.core.types.enumerated.DeadbandType)2 UaException (org.eclipse.milo.opcua.stack.core.UaException)1 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)1 DataChangeFilter (org.eclipse.milo.opcua.stack.core.types.structured.DataChangeFilter)1 EventFilter (org.eclipse.milo.opcua.stack.core.types.structured.EventFilter)1 MonitoringFilter (org.eclipse.milo.opcua.stack.core.types.structured.MonitoringFilter)1