Search in sources :

Example 1 with DesiredRateExpression

use of org.diirt.datasource.expression.DesiredRateExpression in project yamcs-studio by yamcs.

the class CaHistogramFormulaFunction method calculateImpl.

Object calculateImpl(final String newName) {
    // If the name does not match, disconnect and connect
    if (!Objects.equals(newName, previousName)) {
        if (currentExpressions != null) {
            for (DesiredRateExpression<?> desiredRateExpression : currentExpressions) {
                if (desiredRateExpression != null) {
                    getDirector().disconnectReadExpression(desiredRateExpression);
                }
            }
        }
        List<DesiredRateExpression<?>> newExpressions = new ArrayList<>();
        if (newName != null) {
            newExpressions.addAll(Collections.nCopies(3, (DesiredRateExpression<?>) null));
        }
        // Connect new expressions
        if (newName != null) {
            DesiredRateExpression<?> newExpression = channel(newName, Object.class);
            getDirector().disconnectReadExpression(newExpression);
            newExpressions.set(0, newExpression);
            newExpression = channel(newName + ".LLIM", Object.class);
            getDirector().disconnectReadExpression(newExpression);
            newExpressions.set(1, newExpression);
            newExpression = channel(newName + ".ULIM", Object.class);
            getDirector().disconnectReadExpression(newExpression);
            newExpressions.set(2, newExpression);
        }
        previousName = newName;
        currentExpressions = newExpressions;
    }
    // No return value
    if (newName == null) {
        return null;
    }
    // Extract values
    VNumberArray array = (VNumberArray) currentExpressions.get(0).getFunction().readValue();
    VNumber lowerRange = (VNumber) currentExpressions.get(1).getFunction().readValue();
    VNumber upperRange = (VNumber) currentExpressions.get(2).getFunction().readValue();
    if (array == null || lowerRange == null || upperRange == null) {
        return null;
    }
    return ValueFactory.newVNumberArray(array.getData(), array.getSizes(), Arrays.asList(ValueFactory.newDisplay(VTableFactory.range(lowerRange.getValue().doubleValue(), upperRange.getValue().doubleValue()).createListNumber(array.getSizes().getInt(0) + 1), "")), array, array, array);
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) ArrayList(java.util.ArrayList) DesiredRateExpression(org.diirt.datasource.expression.DesiredRateExpression) VNumber(org.diirt.vtype.VNumber)

Aggregations

ArrayList (java.util.ArrayList)1 DesiredRateExpression (org.diirt.datasource.expression.DesiredRateExpression)1 VNumber (org.diirt.vtype.VNumber)1 VNumberArray (org.diirt.vtype.VNumberArray)1