• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

WindhoverLabs / phoebus / #111

15 Dec 2023 04:45PM UTC coverage: 17.035% (+0.4%) from 16.596%
#111

push

lorenzo-gomez-windhover
-Add generation time to ParameterViewer

17830 of 104668 relevant lines covered (17.03%)

0.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/core/commander-core/src/main/java/com/windhoverlabs/pv/yamcs/YamcsVType.java
1
package com.windhoverlabs.pv.yamcs;
2

3
// import com.windhoverlabs.data.yamcs.AggregateVType;
4
// import com.windhoverlabs.data.yamcs.ArrayArrayVType;
5
// import com.windhoverlabs.data.yamcs.BinaryVType;
6
// import com.windhoverlabs.data.yamcs.BooleanArrayVType;
7
// import com.windhoverlabs.data.yamcs.BooleanVType;
8
// import com.windhoverlabs.data.yamcs.DoubleArrayVType;
9
// import com.windhoverlabs.data.yamcs.DoubleVType;
10
// import com.windhoverlabs.data.yamcs.EnumeratedArrayVType;
11
// import com.windhoverlabs.data.yamcs.EnumeratedVType;
12
// import com.windhoverlabs.data.yamcs.FloatArrayVType;
13
// import com.windhoverlabs.data.yamcs.FloatVType;
14
// import com.windhoverlabs.data.yamcs.Sint32ArrayVType;
15
// import com.windhoverlabs.data.yamcs.Sint32VType;
16
// import com.windhoverlabs.data.yamcs.Sint64ArrayVType;
17
// import com.windhoverlabs.data.yamcs.Sint64VType;
18
// import com.windhoverlabs.data.yamcs.StringArrayVType;
19
// import com.windhoverlabs.data.yamcs.StringVType;
20
// import com.windhoverlabs.data.yamcs.TimestampVType;
21
// import com.windhoverlabs.data.yamcs.Uint32ArrayVType;
22
// import com.windhoverlabs.data.yamcs.Uint32VType;
23
// import com.windhoverlabs.data.yamcs.Uint64ArrayVType;
24
// import com.windhoverlabs.data.yamcs.Uint64VType;
25
import com.windhoverlabs.yamcs.core.MissionDatabase;
26
// import com.windhoverlabs.yamcs.studio.data.vtype.Alarm;
27
// import com.windhoverlabs.yamcs.studio.data.vtype.AlarmSeverity;
28
// import com.windhoverlabs.yamcs.studio.data.vtype.Display;
29
// import com.windhoverlabs.yamcs.studio.data.vtype.NumberFormats;
30
import java.text.NumberFormat;
31
import org.epics.vtype.VType;
32
import org.yamcs.protobuf.Mdb.AlarmLevelType;
33
import org.yamcs.protobuf.Mdb.AlarmRange;
34
import org.yamcs.protobuf.Pvalue.AcquisitionStatus;
35
import org.yamcs.protobuf.Pvalue.ParameterValue;
36
import org.yamcs.protobuf.Yamcs.NamedObjectId;
37
import org.yamcs.protobuf.Yamcs.Value;
38

39
public class YamcsVType extends VType implements Alarm, Display {
40

41
  private ParameterValue pval;
42
  private YamcsAware yamcsListener;
43
  protected Value value;
44

45
  public YamcsVType(ParameterValue pval, boolean raw) {
×
46
    this.pval = pval;
×
47
    value = raw ? pval.getRawValue() : pval.getEngValue();
×
48
  }
×
49

50
  public NamedObjectId getId() {
51
    return pval.getId();
×
52
  }
53

54
  @Override
55
  public AlarmSeverity getAlarmSeverity() {
56
    if (pval == null) {
×
57
      return AlarmSeverity.NONE;
×
58
    }
59

60
    if (pval.getAcquisitionStatus() == AcquisitionStatus.EXPIRED
×
61
        || pval.getAcquisitionStatus() == AcquisitionStatus.NOT_RECEIVED
×
62
        || pval.getAcquisitionStatus() == AcquisitionStatus.INVALID) {
×
63
      return AlarmSeverity
×
64
          .INVALID; // Workaround to display LOS in the displays, should be 'Expired'
65
    }
66

67
    if (!pval.hasMonitoringResult()) {
×
68
      return AlarmSeverity.NONE;
×
69
    }
70

71
    switch (pval.getMonitoringResult()) {
×
72
      case IN_LIMITS:
73
        return AlarmSeverity.NONE;
×
74
      case DISABLED:
75
        return AlarmSeverity.NONE;
×
76
      case WATCH:
77
      case WARNING:
78
      case DISTRESS:
79
        return AlarmSeverity.MINOR;
×
80
      case CRITICAL:
81
      case SEVERE:
82
        return AlarmSeverity.MAJOR;
×
83
      default:
84
        throw new IllegalStateException("Unexpected alarm severity " + pval.getMonitoringResult());
×
85
    }
86
  }
87

88
  @Override
89
  public String getAlarmName() {
90
    return "";
×
91
  }
92

93
  @Override
94
  public Double getLowerWarningLimit() {
95
    if (pval != null) {
×
96
      // Assumes ordered ranges
97
      for (AlarmRange range : pval.getAlarmRangeList()) {
×
98
        if (range.getLevel() == AlarmLevelType.WATCH
×
99
            || range.getLevel() == AlarmLevelType.WARNING
×
100
            || range.getLevel() == AlarmLevelType.DISTRESS) {
×
101
          if (range.hasMinInclusive()) {
×
102
            return range.getMinInclusive();
×
103
          } else if (range.hasMinExclusive()) {
×
104
            return range.getMinExclusive();
×
105
          }
106
        }
107
      }
×
108
    }
109
    return Double.NaN;
×
110
  }
111

112
  /** Highest value before the warning region */
113
  @Override
114
  public Double getUpperWarningLimit() {
115
    if (pval != null) {
×
116
      // Assumes ordered ranges
117
      for (AlarmRange range : pval.getAlarmRangeList()) {
×
118
        if (range.getLevel() == AlarmLevelType.WATCH
×
119
            || range.getLevel() == AlarmLevelType.WARNING
×
120
            || range.getLevel() == AlarmLevelType.DISTRESS) {
×
121
          if (range.hasMaxInclusive()) {
×
122
            return range.getMaxInclusive();
×
123
          } else if (range.hasMaxExclusive()) {
×
124
            return range.getMaxExclusive();
×
125
          }
126
        }
127
      }
×
128
    }
129
    return Double.NaN;
×
130
  }
131

132
  @Override
133
  public Double getLowerAlarmLimit() {
134
    if (pval != null) {
×
135
      // Assumes ordered ranges
136
      for (AlarmRange range : pval.getAlarmRangeList()) {
×
137
        if (range.getLevel() == AlarmLevelType.CRITICAL
×
138
            || range.getLevel() == AlarmLevelType.SEVERE) {
×
139
          if (range.hasMinInclusive()) {
×
140
            return range.getMinInclusive();
×
141
          } else if (range.hasMinExclusive()) {
×
142
            return range.getMinExclusive();
×
143
          }
144
        }
145
      }
×
146
    }
147
    return Double.NaN;
×
148
  }
149

150
  /** Highest value before the alarm region */
151
  @Override
152
  public Double getUpperAlarmLimit() {
153
    if (pval != null) {
×
154
      // Assumes ordered ranges
155
      for (AlarmRange range : pval.getAlarmRangeList()) {
×
156
        if (range.getLevel() == AlarmLevelType.CRITICAL
×
157
            || range.getLevel() == AlarmLevelType.SEVERE) {
×
158
          if (range.hasMaxInclusive()) {
×
159
            return range.getMaxInclusive();
×
160
          } else if (range.hasMaxExclusive()) {
×
161
            return range.getMaxExclusive();
×
162
          }
163
        }
164
      }
×
165
    }
166
    return Double.NaN;
×
167
  }
168

169
  @Override
170
  public Double getLowerDisplayLimit() {
171
    Double loLimit = getLowerAlarmLimit();
×
172
    if (loLimit == Double.NaN) {
×
173
      loLimit = getLowerWarningLimit();
×
174
    }
175

176
    return loLimit;
×
177
  }
178

179
  @Override
180
  public Double getUpperDisplayLimit() {
181
    Double hiLimit = getUpperAlarmLimit();
×
182
    if (hiLimit == Double.NaN) {
×
183
      hiLimit = getUpperWarningLimit();
×
184
    }
185

186
    return hiLimit;
×
187
  }
188

189
  @Override
190
  public Double getLowerCtrlLimit() {
191
    return Double.NaN;
×
192
  }
193

194
  @Override
195
  public Double getUpperCtrlLimit() {
196
    return Double.NaN;
×
197
  }
198

199
  @Override
200
  public String getUnits() {
201
    if (pval != null) {
×
202
      MissionDatabase mdb = YamcsPlugin.getMissionDatabase();
×
203
      if (mdb != null) {
×
204
        String unit = mdb.getCombinedUnit(pval.getId());
×
205
        return (unit == null) ? "" : unit;
×
206
      }
207
    }
208
    return "";
×
209
  }
210

211
  @Override
212
  public NumberFormat getFormat() {
213
    return NumberFormats.toStringFormat();
×
214
  }
215

216
  //  /** Converts a yamcs ParameterValue to a VType. */
217
  //  public static VType fromYamcs(ParameterValue pval, boolean raw) {
218
  //    Value value;
219
  //    if (raw) {
220
  //      if (!pval.hasRawValue()) {
221
  //        return null;
222
  //      }
223
  //      value = pval.getRawValue();
224
  //    } else {
225
  //      if (!pval.hasEngValue()) {
226
  //        return null;
227
  //      }
228
  //      value = pval.getEngValue();
229
  //    }
230
  //
231
  //    switch (value.getType()) {
232
  //      case UINT32:
233
  //        return new Uint32VType(pval, raw);
234
  //      case SINT32:
235
  //        return new Sint32VType(pval, raw);
236
  //      case UINT64:
237
  //        return new Uint64VType(pval, raw);
238
  //      case SINT64:
239
  //        return new Sint64VType(pval, raw);
240
  //      case FLOAT:
241
  //        return new FloatVType(pval, raw);
242
  //      case DOUBLE:
243
  //        return new DoubleVType(pval, raw);
244
  //      case BOOLEAN:
245
  //        return new BooleanVType(pval, raw);
246
  //      case STRING:
247
  //        return new StringVType(pval, raw);
248
  //      case BINARY:
249
  //        return new BinaryVType(pval, raw);
250
  //      case TIMESTAMP:
251
  //        return new TimestampVType(pval, raw);
252
  //      case ENUMERATED:
253
  //        return new EnumeratedVType(pval, raw);
254
  //      case AGGREGATE:
255
  //        return new AggregateVType(pval, raw);
256
  //      case ARRAY:
257
  //        List<Value> arrayValues = value.getArrayValueList();
258
  //        if (arrayValues.isEmpty()) {
259
  //          return null; // TODO
260
  //        } else {
261
  //          switch (arrayValues.get(0).getType()) {
262
  //            case UINT32:
263
  //              return new Uint32ArrayVType(pval, raw);
264
  //            case SINT32:
265
  //              return new Sint32ArrayVType(pval, raw);
266
  //            case UINT64:
267
  //              return new Uint64ArrayVType(pval, raw);
268
  //            case SINT64:
269
  //              return new Sint64ArrayVType(pval, raw);
270
  //            case FLOAT:
271
  //              return new FloatArrayVType(pval, raw);
272
  //            case DOUBLE:
273
  //              return new DoubleArrayVType(pval, raw);
274
  //            case BOOLEAN:
275
  //              return new BooleanArrayVType(pval, raw);
276
  //            case STRING:
277
  //              return new StringArrayVType(pval, raw);
278
  //            case ENUMERATED:
279
  //              return new EnumeratedArrayVType(pval, raw);
280
  //            case AGGREGATE:
281
  //              return new AggregateArrayVType(pval, raw);
282
  //            case ARRAY:
283
  //              return new ArrayArrayVType(pval, raw);
284
  //            default:
285
  //              throw new IllegalStateException(
286
  //                  "Unexpected type for parameter array value. Got: "
287
  //                      + arrayValues.get(0).getType());
288
  //          }
289
  //        }
290
  //      default:
291
  //        throw new IllegalStateException(
292
  //            "Unexpected type for parameter value. Got: " + value.getType());
293
  //    }
294
  //  }
295

296
  //  @Override
297
  //  public   Time getTime()
298
  //  {
299
  //          return Time.of(Instant.ofEpochSecond(
300
  //                                    pval.getGenerationTime().getSeconds(), pval.getGenerationTime().getNanos()));
301
  //
302
  //  }
303
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc