MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / readDatasetAlarmBands

Method readDatasetAlarmBands

app/src/DataModel/Frame.cpp:238–279  ·  view source on GitHub ↗

* @brief Populates @p d.alarmBands from @p obj, accepting both canonical and v3.3 legacy fields. */

Source from the content-addressed store, hash-verified

236 * @brief Populates @p d.alarmBands from @p obj, accepting both canonical and v3.3 legacy fields.
237 */
238void DataModel::readDatasetAlarmBands(Dataset& d, const QJsonObject& obj)
239{
240 d.alarmBands.clear();
241 if (obj.contains(Keys::AlarmBands)) {
242 const auto arr = obj.value(Keys::AlarmBands).toArray();
243 d.alarmBands.reserve(arr.size());
244 for (const auto& v : arr) {
245 AlarmBand b;
246 if (read(b, v.toObject()))
247 d.alarmBands.push_back(std::move(b));
248 }
249 return;
250 }
251
252 if (!ss_jsr(obj, Keys::AlarmEnabled, false).toBool())
253 return;
254
255 double lo =
256 SerialStudio::toDouble(ss_jsr(obj, Keys::AlarmLow, std::numeric_limits<double>::quiet_NaN()));
257 double hi =
258 SerialStudio::toDouble(ss_jsr(obj, Keys::AlarmHigh, std::numeric_limits<double>::quiet_NaN()));
259 if (std::isnan(hi) && obj.contains(Keys::Alarm))
260 hi = SerialStudio::toDouble(ss_jsr(obj, Keys::Alarm, 0));
261
262 const double rangeMin = qMin(d.wgtMin, d.wgtMax);
263 const double rangeMax = qMax(d.wgtMin, d.wgtMax);
264 if (!std::isnan(lo) && lo > rangeMin && lo < rangeMax) {
265 AlarmBand low;
266 low.min = rangeMin;
267 low.max = lo;
268 low.severity = AlarmSeverity::Warning;
269 d.alarmBands.push_back(std::move(low));
270 }
271
272 if (!std::isnan(hi) && hi > rangeMin && hi < rangeMax) {
273 AlarmBand high;
274 high.min = hi;
275 high.max = rangeMax;
276 high.severity = AlarmSeverity::Warning;
277 d.alarmBands.push_back(std::move(high));
278 }
279}
280
281//--------------------------------------------------------------------------------------------------
282// Dataset deserialization

Callers

nothing calls this directly

Calls 7

readFunction · 0.85
ss_jsrFunction · 0.85
isnanFunction · 0.85
clearMethod · 0.45
containsMethod · 0.45
valueMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected