Search in sources :

Example 1 with Time

use of org.diirt.vtype.Time in project yamcs-studio by yamcs.

the class AbstractVNumberVNumberToVNumberFormulaFunction method calculate.

@Override
public final Object calculate(List<Object> args) {
    Object arg1 = args.get(0);
    Object arg2 = args.get(1);
    if (arg1 == null || arg2 == null) {
        return null;
    }
    Alarm alarm = highestSeverityOf(args, false);
    Time time = latestValidTimeOrNowOf(args);
    if (time == null) {
        time = ValueFactory.timeNow();
    }
    return ValueFactory.newVDouble(calculate(((VNumber) args.get(0)).getValue().doubleValue(), ((VNumber) args.get(1)).getValue().doubleValue()), alarm, time, ValueFactory.displayNone());
}
Also used : Alarm(org.diirt.vtype.Alarm) Time(org.diirt.vtype.Time)

Example 2 with Time

use of org.diirt.vtype.Time in project yamcs-studio by yamcs.

the class FormulaFunction method latestValidTimeOrNowOf.

/**
 * Returns the time with latest valid timestamp or now.
 *
 * @param args
 *            a list of values
 * @return the latest time; can't be null
 */
public default Time latestValidTimeOrNowOf(final List<Object> args) {
    Time finalTime = null;
    // Give priority to parameter time to prevent issues with sysdate associated to constants
    // being later than parameter time in case of replays.
    boolean useOnlyParameterTime = false;
    for (Object object : args) {
        if (object != null && object.getClass().getName().startsWith("org.yamcs")) {
            useOnlyParameterTime = true;
            break;
        }
    }
    for (Object object : args) {
        Time newTime;
        if (object != null) {
            if (useOnlyParameterTime && !object.getClass().getName().startsWith("org.yamcs")) {
                continue;
            }
            newTime = ValueUtil.timeOf(object);
            if (newTime != null && newTime.isTimeValid() && (finalTime == null || newTime.getTimestamp().compareTo(finalTime.getTimestamp()) > 0)) {
                finalTime = newTime;
            }
        }
    }
    if (finalTime == null) {
        finalTime = ValueFactory.timeNow();
    }
    return finalTime;
}
Also used : Time(org.diirt.vtype.Time)

Example 3 with Time

use of org.diirt.vtype.Time in project yamcs-studio by yamcs.

the class VStringOfFunction method readValue.

@Override
public VString readValue() {
    VType value = argument.readValue();
    if (forward != null) {
        forward.writeValue(value);
    }
    if (value == null) {
        return null;
    }
    String string = format.format(value);
    Alarm alarm = ValueUtil.alarmOf(value);
    if (alarm == null) {
        alarm = ValueFactory.alarmNone();
    }
    Time time = ValueUtil.timeOf(value);
    if (time == null) {
        time = ValueFactory.timeNow();
    }
    return ValueFactory.newVString(string, alarm, time);
}
Also used : VType(org.diirt.vtype.VType) Alarm(org.diirt.vtype.Alarm) Time(org.diirt.vtype.Time) VString(org.diirt.vtype.VString)

Example 4 with Time

use of org.diirt.vtype.Time in project yamcs-studio by yamcs.

the class HighestSeverityFunction method calculate.

@Override
public Object calculate(final List<Object> args) {
    Alarm alarm = highestSeverityOf(args, true);
    Time time = ValueUtil.timeOf(alarm);
    if (time == null) {
        time = ValueFactory.timeNow();
    }
    return ValueFactory.newVEnum(alarm.getAlarmSeverity().ordinal(), AlarmSeverity.labels(), alarm, time);
}
Also used : Alarm(org.diirt.vtype.Alarm) Time(org.diirt.vtype.Time)

Example 5 with Time

use of org.diirt.vtype.Time in project yamcs-studio by yamcs.

the class ToStringFunction method calculate.

@Override
public Object calculate(List<Object> args) {
    VType value = (VType) args.get(0);
    Alarm alarm = ValueUtil.alarmOf(value);
    if (alarm == null) {
        alarm = ValueFactory.alarmNone();
    }
    Time time = ValueUtil.timeOf(value);
    if (time == null) {
        time = ValueFactory.timeNow();
    }
    return ValueFactory.newVString(ValueUtil.getDefaultValueFormat().format(value), alarm, time);
}
Also used : VType(org.diirt.vtype.VType) Alarm(org.diirt.vtype.Alarm) Time(org.diirt.vtype.Time)

Aggregations

Time (org.diirt.vtype.Time)5 Alarm (org.diirt.vtype.Alarm)4 VType (org.diirt.vtype.VType)2 VString (org.diirt.vtype.VString)1