use of org.diirt.vtype.VNumberArray in project yamcs-studio by yamcs.
the class VTypeHelper method formatNumberArray.
private static String formatNumberArray(FormatEnum formatEnum, VNumberArray pmArray, int precision) {
ListNumber data = ((VNumberArray) pmArray).getData();
if (formatEnum == FormatEnum.STRING) {
final byte[] bytes = new byte[data.size()];
// Copy bytes until end _or_ '\0'
int len = 0;
while (len < bytes.length) {
final byte b = data.getByte(len);
if (b == 0)
break;
else
bytes[len++] = b;
}
return new String(bytes, 0, len);
} else {
if (data.size() <= 0)
// $NON-NLS-1$
return "[]";
int displayPrecision = calculatePrecision(pmArray, precision);
StringBuilder sb = new StringBuilder(data.size());
sb.append(formatScalarNumber(formatEnum, data.getDouble(0), displayPrecision));
for (int i = 1; i < data.size(); i++) {
sb.append(ARRAY_ELEMENT_SEPARATOR);
sb.append(formatScalarNumber(formatEnum, data.getDouble(i), displayPrecision));
if (i >= MAX_FORMAT_VALUE_COUNT) {
sb.append(ARRAY_ELEMENT_SEPARATOR);
// $NON-NLS-1$
sb.append("...");
sb.append(formatScalarNumber(formatEnum, data.getDouble(data.size() - 1), displayPrecision));
// $NON-NLS-1$
sb.append(" ");
// $NON-NLS-1$
sb.append("[");
sb.append(data.size());
// $NON-NLS-1$
sb.append("]");
break;
}
}
return sb.toString();
}
}
use of org.diirt.vtype.VNumberArray in project yamcs-studio by yamcs.
the class AbstractVNumberArrayVNumberArrayToVNumberArrayFormulaFunction method calculate.
@Override
public final Object calculate(List<Object> args) {
if (NullUtils.containsNull(args)) {
return null;
}
VNumberArray arg1 = (VNumberArray) args.get(0);
VNumberArray arg2 = (VNumberArray) args.get(1);
return newVNumberArray(calculate(arg1.getData(), arg2.getData()), highestSeverityOf(args, false), latestValidTimeOrNowOf(args), displayNone());
}
use of org.diirt.vtype.VNumberArray in project yamcs-studio by yamcs.
the class AbstractVNumberArrayVNumberToVNumberArrayFormulaFunction method calculate.
@Override
public final Object calculate(List<Object> args) {
if (NullUtils.containsNull(args)) {
return null;
}
VNumberArray arg1 = (VNumberArray) args.get(0);
VNumber arg2 = (VNumber) args.get(1);
return newVNumberArray(calculate(arg1.getData(), arg2.getValue().doubleValue()), highestSeverityOf(args, false), latestValidTimeOrNowOf(args), displayNone());
}
use of org.diirt.vtype.VNumberArray in project yamcs-studio by yamcs.
the class ArrayWithBoundariesFormulaFunction method calculate.
@Override
public Object calculate(final List<Object> args) {
if (NullUtils.containsNull(args)) {
return null;
}
VNumberArray array = (VNumberArray) args.get(0);
if (array.getSizes().size() != args.size() - 1) {
throw new IllegalArgumentException("Dimension of the array must match the number of ListNumberProvider");
}
List<ArrayDimensionDisplay> dimDisplay = new ArrayList<>();
for (int i = 1; i < args.size(); i++) {
ListNumberProvider numberGenerator = (ListNumberProvider) args.get(i);
dimDisplay.add(ValueFactory.newDisplay(numberGenerator.createListNumber(array.getSizes().getInt(i - 1) + 1), ""));
}
return ValueFactory.newVNumberArray(array.getData(), array.getSizes(), dimDisplay, array, array, array);
}
use of org.diirt.vtype.VNumberArray 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);
}
Aggregations