From 0dc048bb9ea33676a64e8284ca3626d70f2bf684 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Thu, 15 Oct 2026 14:32:05 +0700 Subject: [PATCH 1/4] M2L: gate native measurement display on exact CDC, MX and received MMS provenance --- .../qml/BrowserDataModelPane.qml | 11 ++ apps/ied_simulator/src/MmsLiveTreeModel.cpp | 113 +++++++++++-- apps/ied_simulator/src/MmsLiveTreeModel.hpp | 2 + .../src/ied_browser_large_model_qa.cpp | 151 ++++++++++++++++++ 4 files changed, 261 insertions(+), 16 deletions(-) diff --git a/apps/ied_simulator/qml/BrowserDataModelPane.qml b/apps/ied_simulator/qml/BrowserDataModelPane.qml index c6f616245..551e18144 100644 --- a/apps/ied_simulator/qml/BrowserDataModelPane.qml +++ b/apps/ied_simulator/qml/BrowserDataModelPane.qml @@ -264,6 +264,17 @@ Rectangle { model: [ {label: "Reference", value: root.currentNode.reference}, {label: "Value", value: root.currentNode.value}, + {label: "Value source", value: root.currentNode.valueSourceReference}, + {label: "Measurement", value: root.currentNode.measurement + ? root.currentNode.measurement.kind : ""}, + {label: "Magnitude · MMS received", value: root.currentNode.measurement + ? root.currentNode.measurement.magnitude : ""}, + {label: "Magnitude source", value: root.currentNode.measurement + ? root.currentNode.measurement.magnitudeSourceReference : ""}, + {label: "Angle · raw, unit unverified", value: root.currentNode.measurement + ? root.currentNode.measurement.angle : ""}, + {label: "Angle source", value: root.currentNode.measurement + ? root.currentNode.measurement.angleSourceReference : ""}, {label: "Read state", value: root.currentNode.kind === "DA" ? (root.currentNode.hasReceivedValue === true ? "Received" : "Not read") : ""}, diff --git a/apps/ied_simulator/src/MmsLiveTreeModel.cpp b/apps/ied_simulator/src/MmsLiveTreeModel.cpp index 644fdaea9..51a8d559e 100644 --- a/apps/ied_simulator/src/MmsLiveTreeModel.cpp +++ b/apps/ied_simulator/src/MmsLiveTreeModel.cpp @@ -4,6 +4,7 @@ #include #include +#include namespace { QString q(const std::string& value) { return QString::fromStdString(value); } @@ -184,6 +185,9 @@ void MmsLiveTreeModel::applyDocument(const ar::iec61850::mms::MmsLiveModelDocume object.reference = q(dataObject.reference); object.domain = q(logicalDevice.mms_domain); object.description = q(dataObject.inferred_cdc); + object.cdcAuthoritative = + dataObject.confidence == ar::iec61850::mms::MmsLiveModelConfidence::exact && + !dataObject.inferred_cdc.empty(); const auto objectIndex = appendNode(std::move(object)); for (const auto& attribute : dataObject.attributes) { @@ -297,21 +301,92 @@ QString MmsLiveTreeModel::siblingValue(const int nodeIndex, const QString& wante if (nodeIndex < 0 || nodeIndex >= nodes_.size()) return {}; const auto& selected = nodes_.at(nodeIndex); if (selected.kind != NodeKind::dataAttribute) return {}; - if (leafName(selected.attributePath).compare(wantedLeaf, Qt::CaseInsensitive) == 0 || - selected.label.compare(wantedLeaf, Qt::CaseInsensitive) == 0) { - return selected.value; - } + + // q/t is FC-scoped, not any same-DO sibling with a matching leaf name. + // A readable but unread companion must never masquerade as evidence. + const auto matches = [&](const Node& candidate) { + return candidate.kind == NodeKind::dataAttribute && + candidate.hasReceivedValue && + candidate.functionalConstraint.compare( + selected.functionalConstraint, Qt::CaseInsensitive) == 0 && + (leafName(candidate.attributePath).compare(wantedLeaf, Qt::CaseInsensitive) == 0 || + candidate.label.compare(wantedLeaf, Qt::CaseInsensitive) == 0); + }; + if (matches(selected)) return selected.value; if (selected.parent < 0) return {}; - for (const auto siblingIndex : nodes_.at(selected.parent).children) { + for (const int siblingIndex : nodes_.at(selected.parent).children) { const auto& sibling = nodes_.at(siblingIndex); - if (leafName(sibling.attributePath).compare(wantedLeaf, Qt::CaseInsensitive) == 0 || - sibling.label.compare(wantedLeaf, Qt::CaseInsensitive) == 0) { - return sibling.value; - } + if (matches(sibling)) return sibling.value; } return {}; } +QVariantMap MmsLiveTreeModel::measurementForNode(const int nodeIndex) const { + if (nodeIndex < 0 || nodeIndex >= nodes_.size()) return {}; + const auto& selected = nodes_.at(nodeIndex); + const int objectIndex = selected.kind == NodeKind::dataObject + ? nodeIndex : (selected.kind == NodeKind::dataAttribute && + selected.functionalConstraint.compare( + QStringLiteral("MX"), Qt::CaseInsensitive) == 0 + ? selected.parent : -1); + if (objectIndex < 0 || objectIndex >= nodes_.size()) return {}; + const auto& object = nodes_.at(objectIndex); + if (object.kind != NodeKind::dataObject || !object.cdcAuthoritative) return {}; + + // Existing canonical CDC and FC metadata are required. Names such as Hz, + // TotW, "mag" or an incidental "ang" are never sufficient for a phasor. + const QString cdc = object.description.trimmed().toUpper(); + const bool vector = cdc == QStringLiteral("CMV"); + if (!vector && cdc != QStringLiteral("MV") && cdc != QStringLiteral("SAV")) + return {}; + + const Node* magnitude = nullptr; + const Node* angle = nullptr; + for (const int childIndex : object.children) { + const auto& child = nodes_.at(childIndex); + if (child.kind != NodeKind::dataAttribute || !child.hasReceivedValue || + child.functionalConstraint.compare(QStringLiteral("MX"), Qt::CaseInsensitive) != 0) + continue; + const QString type = child.mmsType.trimmed().toLower(); + if (type != QStringLiteral("floating-point") && + type != QStringLiteral("integer") && + type != QStringLiteral("unsigned")) + continue; + bool parsed = false; + const double numeric = child.value.toDouble(&parsed); + if (!parsed || !std::isfinite(numeric)) continue; + const QString path = child.attributePath; + if (vector) { + if (path.compare(QStringLiteral("cVal.mag.f"), Qt::CaseInsensitive) == 0 || + path.endsWith(QStringLiteral(".cVal.mag.f"), Qt::CaseInsensitive)) + magnitude = &child; + else if (path.compare(QStringLiteral("cVal.ang.f"), Qt::CaseInsensitive) == 0 || + path.endsWith(QStringLiteral(".cVal.ang.f"), Qt::CaseInsensitive)) + angle = &child; + } else if (path.compare(QStringLiteral("mag.f"), Qt::CaseInsensitive) == 0 || + path.compare(QStringLiteral("mag.i"), Qt::CaseInsensitive) == 0 || + path.endsWith(QStringLiteral(".mag.f"), Qt::CaseInsensitive) || + path.endsWith(QStringLiteral(".mag.i"), Qt::CaseInsensitive) || + path.compare(QStringLiteral("instMag.f"), Qt::CaseInsensitive) == 0 || + path.endsWith(QStringLiteral(".instMag.f"), Qt::CaseInsensitive)) { + magnitude = &child; + } + } + if (!magnitude) return {}; + QVariantMap result; + result.insert(QStringLiteral("kind"), vector ? QStringLiteral("vector") + : QStringLiteral("scalar")); + result.insert(QStringLiteral("magnitude"), magnitude->value); + result.insert(QStringLiteral("magnitudeSourceReference"), magnitude->reference); + // No engineering unit is present in MmsLiveDataAttribute; never guess Hz, + // W, a multiplier, or a degree sign from a DO name or its numeric type. + if (vector && angle) { + result.insert(QStringLiteral("angle"), angle->value); + result.insert(QStringLiteral("angleSourceReference"), angle->reference); + } + return result; +} + QVariantMap MmsLiveTreeModel::nodeMap(const int nodeIndex) const { QVariantMap result; if (nodeIndex < 0 || nodeIndex >= nodes_.size()) return result; @@ -327,24 +402,30 @@ QVariantMap MmsLiveTreeModel::nodeMap(const int nodeIndex) const { result.insert(QStringLiteral("typeStatus"), node.typeStatus); result.insert(QStringLiteral("description"), node.description); QString displayValue = node.value; - if (displayValue.isEmpty() && node.kind == NodeKind::dataObject) { + bool displayReceived = node.hasReceivedValue; + QString displaySource = displayReceived ? node.reference : QString{}; + if (!displayReceived && node.kind == NodeKind::dataObject) { static const QStringList preferredLeaves{ QStringLiteral("stVal"), QStringLiteral("mag"), QStringLiteral("setVal"), QStringLiteral("instMag"), QStringLiteral("general")}; for (const auto& preferred : preferredLeaves) { for (const auto childIndex : node.children) { const auto& child = nodes_.at(childIndex); - if (child.label.compare(preferred, Qt::CaseInsensitive) == 0 && - !child.value.isEmpty()) { + if (child.hasReceivedValue && + child.label.compare(preferred, Qt::CaseInsensitive) == 0) { displayValue = child.value; + displayReceived = true; + displaySource = child.reference; break; } } - if (!displayValue.isEmpty()) break; + if (displayReceived) break; } } result.insert(QStringLiteral("value"), displayValue); - result.insert(QStringLiteral("hasReceivedValue"), node.hasReceivedValue); + result.insert(QStringLiteral("hasReceivedValue"), displayReceived); + result.insert(QStringLiteral("valueSourceReference"), displaySource); + result.insert(QStringLiteral("measurement"), measurementForNode(nodeIndex)); result.insert(QStringLiteral("engineeringEvidence"), node.engineeringEvidence); result.insert(QStringLiteral("hasChildren"), !node.children.isEmpty()); result.insert(QStringLiteral("childCount"), node.children.size()); @@ -726,8 +807,8 @@ QVariant MmsLiveDetailModel::data(const QModelIndex& index, const int role) cons for (const auto& label : preferred) for (const auto child : n.children) { const auto& leaf = owner_->nodes_.at(child); - if (leaf.label.compare(label, Qt::CaseInsensitive) == 0 && - !leaf.value.isEmpty()) return leaf.value; + if (leaf.hasReceivedValue && + leaf.label.compare(label, Qt::CaseInsensitive) == 0) return leaf.value; } return QString{}; } diff --git a/apps/ied_simulator/src/MmsLiveTreeModel.hpp b/apps/ied_simulator/src/MmsLiveTreeModel.hpp index 52f61314d..c08089bd6 100644 --- a/apps/ied_simulator/src/MmsLiveTreeModel.hpp +++ b/apps/ied_simulator/src/MmsLiveTreeModel.hpp @@ -187,6 +187,7 @@ class MmsLiveTreeModel : public QAbstractListModel { QString typeStatus; QString description; QString value; + bool cdcAuthoritative{}; // true only for an exact CDC source bool hasReceivedValue{}; // updated only at actual MMS sample ingress QVariantMap engineeringEvidence; bool writable{}; @@ -203,6 +204,7 @@ class MmsLiveTreeModel : public QAbstractListModel { void appendVisibleSubtree(int nodeIndex, const QVector* included); [[nodiscard]] int visibleRowForNode(int nodeIndex) const noexcept; [[nodiscard]] QString siblingValue(int nodeIndex, const QString& leafName) const; + [[nodiscard]] QVariantMap measurementForNode(int nodeIndex) const; [[nodiscard]] QVariantMap nodeMap(int nodeIndex) const; [[nodiscard]] int presentationNodeIndex() const noexcept; bool selectNode(int nodeIndex); diff --git a/apps/ied_simulator/src/ied_browser_large_model_qa.cpp b/apps/ied_simulator/src/ied_browser_large_model_qa.cpp index ee4af0396..825fb8c70 100644 --- a/apps/ied_simulator/src/ied_browser_large_model_qa.cpp +++ b/apps/ied_simulator/src/ied_browser_large_model_qa.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -593,6 +594,156 @@ int main(int argc, char** argv) { return 35; } + + // M2L: prove scalar-vs-vector output comes from exact CDC + MX + received + // typed numeric DAs, never guessing an angle or engineering unit. + { + using namespace ar::iec61850::mms; + MmsLiveModelDocument engineeringModel; + engineeringModel.identity.ied_name = "M2L_TYPED"; + MmsLiveLogicalDevice device; + device.mms_domain = "LD_M2L"; + device.instance = "LD_M2L"; + MmsLiveLogicalNode ln; + ln.name = "MMXU1"; + ln.logical_node_class = "MMXU"; + const auto addObject = [&](const std::string& name, const std::string& cdc, + MmsLiveModelConfidence confidence) + -> MmsLiveDataObject& { + ln.data_objects.emplace_back(); + auto& object = ln.data_objects.back(); + object.name = name; + object.reference = "LD_M2L/MMXU1." + name; + object.inferred_cdc = cdc; + object.confidence = confidence; + return object; + }; + const auto addAttribute = [](MmsLiveDataObject& object, + const std::string& path, + const std::string& fc, + const std::string& type) { + MmsLiveDataAttribute attribute; + attribute.attribute_path = object.name + "." + path; + attribute.object_reference = object.reference; + attribute.functional_constraint = fc; + std::string itemPath = path; + std::replace(itemPath.begin(), itemPath.end(), '.', '$'); + attribute.mms_item_name = "MMXU1$" + fc + "$" + object.name + "$" + itemPath; + attribute.mms_reference = "LD_M2L/" + attribute.mms_item_name; + attribute.mms_type = type; + attribute.type_discovery_status = "Exact"; + object.attributes.push_back(std::move(attribute)); + }; + auto& phasor = addObject("PhV", "CMV", MmsLiveModelConfidence::exact); + addAttribute(phasor, "cVal.mag.f", "MX", "floating-point"); + addAttribute(phasor, "cVal.ang.f", "MX", "floating-point"); + addAttribute(phasor, "q", "ST", "bit-string"); // wrong FC must never leak + addAttribute(phasor, "q", "MX", "bit-string"); + addAttribute(phasor, "t", "MX", "utc-time"); + for (const std::string name : {"Hz", "TotW"}) { + auto& scalar = addObject(name, "MV", MmsLiveModelConfidence::exact); + addAttribute(scalar, "mag.f", "MX", "floating-point"); + addAttribute(scalar, "ang.f", "MX", "floating-point"); // spurious, not CMV + } + auto& status = addObject("Health", "SPS", MmsLiveModelConfidence::exact); + addAttribute(status, "stVal", "ST", "boolean"); + auto& uncertain = addObject("EstimatedPhV", "CMV", MmsLiveModelConfidence::low); + addAttribute(uncertain, "cVal.mag.f", "MX", "floating-point"); + addAttribute(uncertain, "cVal.ang.f", "MX", "floating-point"); + device.logical_nodes.push_back(std::move(ln)); + engineeringModel.logical_devices.push_back(std::move(device)); + MmsLiveTreeModel measurementModel; + measurementModel.applyDocument(engineeringModel); + const auto ref = [](const QString& name) { + return QStringLiteral("LD_M2L/MMXU1.") + name; + }; + const auto received = [&measurementModel](const QString& item, + const QString& display) { + measurementModel.applyReadValue( + QStringLiteral("LD_M2L") + QChar(0x1f) + item, display); + }; + if (!measurementModel.nodeForReference(ref(QStringLiteral("PhV"))) + .value(QStringLiteral("measurement")).toMap().isEmpty()) { + std::cerr << "IED_BROWSER_LARGE_MODEL_FAIL m2l_unread_vector\n"; + return 36; + } + received(QStringLiteral("MMXU1$MX$PhV$cVal$mag$f"), QStringLiteral("115.0")); + const auto partial = measurementModel.nodeForReference(ref(QStringLiteral("PhV"))) + .value(QStringLiteral("measurement")).toMap(); + if (partial.value(QStringLiteral("kind")).toString() != QStringLiteral("vector") || + partial.value(QStringLiteral("magnitude")).toString() != QStringLiteral("115.0") || + partial.contains(QStringLiteral("angle")) || + partial.contains(QStringLiteral("unit"))) { + std::cerr << "IED_BROWSER_LARGE_MODEL_FAIL m2l_partial_phasor\n"; + return 37; + } + received(QStringLiteral("MMXU1$MX$PhV$cVal$ang$f"), QStringLiteral("not-number")); + if (measurementModel.nodeForReference(ref(QStringLiteral("PhV"))) + .value(QStringLiteral("measurement")).toMap().contains(QStringLiteral("angle"))) { + std::cerr << "IED_BROWSER_LARGE_MODEL_FAIL m2l_malformed_angle\n"; + return 38; + } + received(QStringLiteral("MMXU1$MX$PhV$cVal$ang$f"), QStringLiteral("30.0")); + const auto vector = measurementModel.nodeForReference(ref(QStringLiteral("PhV"))) + .value(QStringLiteral("measurement")).toMap(); + if (vector.value(QStringLiteral("angle")).toString() != QStringLiteral("30.0") || + !vector.value(QStringLiteral("angleSourceReference")).toString() + .contains(QStringLiteral("cVal$ang$f"))) { + std::cerr << "IED_BROWSER_LARGE_MODEL_FAIL m2l_valid_phasor\n"; + return 39; + } + const auto selectedRef = ref(QStringLiteral("PhV.cVal.mag.f")); + received(QStringLiteral("MMXU1$ST$PhV$q"), QStringLiteral("ST_Q")); + if (!measurementModel.nodeForReference(selectedRef) + .value(QStringLiteral("quality")).toString().isEmpty()) { + std::cerr << "IED_BROWSER_LARGE_MODEL_FAIL m2l_cross_fc_quality\n"; + return 40; + } + received(QStringLiteral("MMXU1$MX$PhV$q"), QStringLiteral("MX_Q")); + received(QStringLiteral("MMXU1$MX$PhV$t"), QStringLiteral("IED_UTC")); + const auto observed = measurementModel.nodeForReference(selectedRef); + if (observed.value(QStringLiteral("quality")).toString() != QStringLiteral("MX_Q") || + observed.value(QStringLiteral("timestamp")).toString() != QStringLiteral("IED_UTC") || + observed.value(QStringLiteral("measurement")).toMap() != vector) { + std::cerr << "IED_BROWSER_LARGE_MODEL_FAIL m2l_companion_provenance\n"; + return 41; + } + for (const QString name : {QStringLiteral("Hz"), QStringLiteral("TotW")}) { + const auto item = QStringLiteral("MMXU1$MX$") + name; + received(item + QStringLiteral("$mag$f"), QStringLiteral("50.25")); + received(item + QStringLiteral("$ang$f"), QStringLiteral("90")); + const auto scalar = measurementModel.nodeForReference(ref(name)) + .value(QStringLiteral("measurement")).toMap(); + if (scalar.value(QStringLiteral("kind")).toString() != QStringLiteral("scalar") || + scalar.value(QStringLiteral("magnitude")).toString() != QStringLiteral("50.25") || + scalar.contains(QStringLiteral("angle")) || scalar.contains(QStringLiteral("unit"))) { + std::cerr << "IED_BROWSER_LARGE_MODEL_FAIL m2l_scalar_false_angle\n"; + return 42; + } + } + received(QStringLiteral("MMXU1$ST$Health$stVal"), QStringLiteral("true")); + if (!measurementModel.nodeForReference(ref(QStringLiteral("Health"))) + .value(QStringLiteral("measurement")).toMap().isEmpty()) { + std::cerr << "IED_BROWSER_LARGE_MODEL_FAIL m2l_boolean_false_magnitude\n"; + return 43; + } + received(QStringLiteral("MMXU1$MX$EstimatedPhV$cVal$mag$f"), QStringLiteral("100")); + received(QStringLiteral("MMXU1$MX$EstimatedPhV$cVal$ang$f"), QStringLiteral("20")); + if (!measurementModel.nodeForReference(ref(QStringLiteral("EstimatedPhV"))) + .value(QStringLiteral("measurement")).toMap().isEmpty()) { + std::cerr << "IED_BROWSER_LARGE_MODEL_FAIL m2l_uncertain_cdc\n"; + return 44; + } + measurementModel.applyDocument(engineeringModel); + if (!measurementModel.nodeForReference(ref(QStringLiteral("PhV"))) + .value(QStringLiteral("measurement")).toMap().isEmpty() || + measurementModel.nodeForReference(selectedRef) + .value(QStringLiteral("hasReceivedValue")).toBool()) { + std::cerr << "IED_BROWSER_LARGE_MODEL_FAIL m2l_source_replacement_stale\n"; + return 45; + } + } + const bool passes = applyMs <= 5000 && filterMs <= 1500 && selectMs <= 500; std::cout << "IED_BROWSER_LARGE_MODEL_" << (passes ? "PASS" : "FAIL") << " nodes=" << model.totalNodeCount() From d0e53de4aaa7a82f2fbce97a1f442efaa20f7687 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Thu, 15 Oct 2026 14:34:03 +0700 Subject: [PATCH 2/4] docs: record verified M2K merge and active M2L exact-head handoff --- docs/WORKBENCH_CURRENT_HANDOFF.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/WORKBENCH_CURRENT_HANDOFF.md b/docs/WORKBENCH_CURRENT_HANDOFF.md index c39aa3227..107ee4cb1 100644 --- a/docs/WORKBENCH_CURRENT_HANDOFF.md +++ b/docs/WORKBENCH_CURRENT_HANDOFF.md @@ -4,6 +4,15 @@ > **Primary strategy and ownership contract:** [WORKBENCH_ARSAS_GUI_SSOT_STRATEGY.md](WORKBENCH_ARSAS_GUI_SSOT_STRATEGY.md). > **Scope:** installed native ARStack Workbench in apps/ied_simulator. Not a web app, WPF clone, or the separate ESP32-P4/SMV Studio track. +## Verified integration checkpoint — 2026-10-15 (subsequent to the historical snapshot below) + +- **M2K MERGED** via [PR #176](https://github.com/masarray/arstack61850/pull/176), squash commit `0cc882022d20f416a33433d5f29a1f8950984d85` (verified as the new `main` at merge). Exact PR head `5c5e425c20acb1b849399f39bf62da0f68c0942b`; native Qt [38678320479](https://github.com/masarray/arstack61850/actions/runs/38678320479) and SCL-Assisted Workbench [38678320482](https://github.com/masarray/arstack61850/actions/runs/38678320482) were **SUCCESS** before merge. All review threads resolved; merge performed with expected head lease. PR #175 native Studio/PTP had already merged to main at `a47d65e` and its independent paths remained preserved. +- **Post-M2K main CI**: [Qt 38698517002](https://github.com/masarray/arstack61850/actions/runs/38698517002), [SCL 38698516965](https://github.com/masarray/arstack61850/actions/runs/38698516965), [Release Hardening 38698517080](https://github.com/masarray/arstack61850/actions/runs/38698517080). SCL was verified **SUCCESS**; Qt and Release Hardening were **IN PROGRESS** when handoff updated, require fresh results. +- **M2L ACTIVE / NOT MERGED**: [PR #178](https://github.com/masarray/arstack61850/pull/178), initial head `0dc048bb9ea33676a64e8284ca3626d70f2bf684` based on `0cc8820`. First slice edits canonical `MmsLiveTreeModel`, existing 60k+ QA and native selected-DA inspector. Exact CDC + MX + received finite numeric MMS gates magnitude/vector; vector angle appears only with actual `CMV cVal.ang.f`; scalar Hz/TotW and Boolean cannot invent angle. q/t companion visibility is restricted to the selected DA's FC and actual reception. No units or degree signs are inferred. Source replacement clears read evidence. +- **M2L QA state**: branch initially opened as draft so draft-head CI was **SKIPPED**, **not PASS**. Ready-for-review plus exact new HEAD Qt/large-model/Browser regression and review signoff are required before merge. Physical IED, Windows installed artifact and native rendered-screen acceptance remain separate; source-only regression is not those gates. +- **Ownership**: Track A owns canonical model and test in PR #178, Track B owns selected inspector QML changes *inside the same PR* to keep the slice vertical, Track C reporting/RCB remains untouched, Track D checks exact-head CI and post-merge runs. Other threads must avoid editing these four PR paths concurrently. +- **Next**: Refresh PR #178 and CI, address any actual compiler/test/review defects, merge only after exact-head checks, verify `main`, then continue M2M native DataSets and selected-state screenshot QA. Never merge legacy #172/#164 by assumption. + ## Current checkpoint | Item | Verified at this snapshot | From 59b612c6a64c179bff222a7470d30f4871f8982a Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Thu, 15 Oct 2026 14:38:18 +0700 Subject: [PATCH 3/4] M2L: index exact MX measurement leaves and test DO received-value source --- apps/ied_simulator/src/MmsLiveTreeModel.cpp | 58 +++++++++---------- .../src/ied_browser_large_model_qa.cpp | 20 +++++++ 2 files changed, 49 insertions(+), 29 deletions(-) diff --git a/apps/ied_simulator/src/MmsLiveTreeModel.cpp b/apps/ied_simulator/src/MmsLiveTreeModel.cpp index 51a8d559e..1a54195e5 100644 --- a/apps/ied_simulator/src/MmsLiveTreeModel.cpp +++ b/apps/ied_simulator/src/MmsLiveTreeModel.cpp @@ -340,37 +340,37 @@ QVariantMap MmsLiveTreeModel::measurementForNode(const int nodeIndex) const { if (!vector && cdc != QStringLiteral("MV") && cdc != QStringLiteral("SAV")) return {}; + // IEC aliases are already indexed at appendNode; use exact reference + // lookups rather than scanning every sibling once per projected DA row. + const auto receivedNumeric = [this, &object](const QString& suffix) -> const Node* { + const auto found = referenceIndex_.constFind( + object.reference + QLatin1Char('.') + suffix); + if (found == referenceIndex_.cend()) return nullptr; + for (const int candidateIndex : found.value()) { + const auto& child = nodes_.at(candidateIndex); + if (child.kind != NodeKind::dataAttribute || !child.hasReceivedValue || + child.parent != (&object - nodes_.constData()) || + child.functionalConstraint.compare(QStringLiteral("MX"), Qt::CaseInsensitive) != 0) + continue; + const QString type = child.mmsType.trimmed().toLower(); + if (type != QStringLiteral("floating-point") && + type != QStringLiteral("integer") && type != QStringLiteral("unsigned")) + continue; + bool parsed = false; + const double numeric = child.value.toDouble(&parsed); + if (parsed && std::isfinite(numeric)) return &child; + } + return nullptr; + }; const Node* magnitude = nullptr; const Node* angle = nullptr; - for (const int childIndex : object.children) { - const auto& child = nodes_.at(childIndex); - if (child.kind != NodeKind::dataAttribute || !child.hasReceivedValue || - child.functionalConstraint.compare(QStringLiteral("MX"), Qt::CaseInsensitive) != 0) - continue; - const QString type = child.mmsType.trimmed().toLower(); - if (type != QStringLiteral("floating-point") && - type != QStringLiteral("integer") && - type != QStringLiteral("unsigned")) - continue; - bool parsed = false; - const double numeric = child.value.toDouble(&parsed); - if (!parsed || !std::isfinite(numeric)) continue; - const QString path = child.attributePath; - if (vector) { - if (path.compare(QStringLiteral("cVal.mag.f"), Qt::CaseInsensitive) == 0 || - path.endsWith(QStringLiteral(".cVal.mag.f"), Qt::CaseInsensitive)) - magnitude = &child; - else if (path.compare(QStringLiteral("cVal.ang.f"), Qt::CaseInsensitive) == 0 || - path.endsWith(QStringLiteral(".cVal.ang.f"), Qt::CaseInsensitive)) - angle = &child; - } else if (path.compare(QStringLiteral("mag.f"), Qt::CaseInsensitive) == 0 || - path.compare(QStringLiteral("mag.i"), Qt::CaseInsensitive) == 0 || - path.endsWith(QStringLiteral(".mag.f"), Qt::CaseInsensitive) || - path.endsWith(QStringLiteral(".mag.i"), Qt::CaseInsensitive) || - path.compare(QStringLiteral("instMag.f"), Qt::CaseInsensitive) == 0 || - path.endsWith(QStringLiteral(".instMag.f"), Qt::CaseInsensitive)) { - magnitude = &child; - } + if (vector) { + magnitude = receivedNumeric(QStringLiteral("cVal.mag.f")); + angle = receivedNumeric(QStringLiteral("cVal.ang.f")); + } else { + magnitude = receivedNumeric(QStringLiteral("mag.f")); + if (!magnitude) magnitude = receivedNumeric(QStringLiteral("mag.i")); + if (!magnitude) magnitude = receivedNumeric(QStringLiteral("instMag.f")); } if (!magnitude) return {}; QVariantMap result; diff --git a/apps/ied_simulator/src/ied_browser_large_model_qa.cpp b/apps/ied_simulator/src/ied_browser_large_model_qa.cpp index 825fb8c70..04ecaeed4 100644 --- a/apps/ied_simulator/src/ied_browser_large_model_qa.cpp +++ b/apps/ied_simulator/src/ied_browser_large_model_qa.cpp @@ -722,6 +722,26 @@ int main(int argc, char** argv) { } } received(QStringLiteral("MMXU1$ST$Health$stVal"), QStringLiteral("true")); + const auto sourcedStatus = measurementModel.nodeForReference( + ref(QStringLiteral("Health"))); + if (sourcedStatus.value(QStringLiteral("value")).toString() != QStringLiteral("true") || + !sourcedStatus.value(QStringLiteral("hasReceivedValue")).toBool() || + !sourcedStatus.value(QStringLiteral("valueSourceReference")).toString() + .contains(QStringLiteral("Health$stVal"))) { + std::cerr << "IED_BROWSER_LARGE_MODEL_FAIL m2l_do_value_source\n"; + return 46; + } + // A successful empty-string sample stays received and source-backed, + // not a fabricated NOT READ or a stale previous nonempty value. + received(QStringLiteral("MMXU1$ST$Health$stVal"), QString{}); + const auto receivedEmptyStatus = measurementModel.nodeForReference( + ref(QStringLiteral("Health"))); + if (!receivedEmptyStatus.value(QStringLiteral("hasReceivedValue")).toBool() || + !receivedEmptyStatus.value(QStringLiteral("value")).toString().isEmpty() || + receivedEmptyStatus.value(QStringLiteral("valueSourceReference")).toString().isEmpty()) { + std::cerr << "IED_BROWSER_LARGE_MODEL_FAIL m2l_do_received_empty\n"; + return 47; + } if (!measurementModel.nodeForReference(ref(QStringLiteral("Health"))) .value(QStringLiteral("measurement")).toMap().isEmpty()) { std::cerr << "IED_BROWSER_LARGE_MODEL_FAIL m2l_boolean_false_magnitude\n"; From 278271d7ca316d154113c1c8968339eea3a83e94 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Thu, 15 Oct 2026 14:39:42 +0700 Subject: [PATCH 4/4] M2L: support typed integer AnalogueValue magnitude and angle with regression --- apps/ied_simulator/src/MmsLiveTreeModel.cpp | 7 +++-- .../src/ied_browser_large_model_qa.cpp | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/apps/ied_simulator/src/MmsLiveTreeModel.cpp b/apps/ied_simulator/src/MmsLiveTreeModel.cpp index 1a54195e5..00302ad19 100644 --- a/apps/ied_simulator/src/MmsLiveTreeModel.cpp +++ b/apps/ied_simulator/src/MmsLiveTreeModel.cpp @@ -342,14 +342,14 @@ QVariantMap MmsLiveTreeModel::measurementForNode(const int nodeIndex) const { // IEC aliases are already indexed at appendNode; use exact reference // lookups rather than scanning every sibling once per projected DA row. - const auto receivedNumeric = [this, &object](const QString& suffix) -> const Node* { + const auto receivedNumeric = [this, &object, objectIndex](const QString& suffix) -> const Node* { const auto found = referenceIndex_.constFind( object.reference + QLatin1Char('.') + suffix); if (found == referenceIndex_.cend()) return nullptr; for (const int candidateIndex : found.value()) { const auto& child = nodes_.at(candidateIndex); if (child.kind != NodeKind::dataAttribute || !child.hasReceivedValue || - child.parent != (&object - nodes_.constData()) || + child.parent != objectIndex || child.functionalConstraint.compare(QStringLiteral("MX"), Qt::CaseInsensitive) != 0) continue; const QString type = child.mmsType.trimmed().toLower(); @@ -366,11 +366,14 @@ QVariantMap MmsLiveTreeModel::measurementForNode(const int nodeIndex) const { const Node* angle = nullptr; if (vector) { magnitude = receivedNumeric(QStringLiteral("cVal.mag.f")); + if (!magnitude) magnitude = receivedNumeric(QStringLiteral("cVal.mag.i")); angle = receivedNumeric(QStringLiteral("cVal.ang.f")); + if (!angle) angle = receivedNumeric(QStringLiteral("cVal.ang.i")); } else { magnitude = receivedNumeric(QStringLiteral("mag.f")); if (!magnitude) magnitude = receivedNumeric(QStringLiteral("mag.i")); if (!magnitude) magnitude = receivedNumeric(QStringLiteral("instMag.f")); + if (!magnitude) magnitude = receivedNumeric(QStringLiteral("instMag.i")); } if (!magnitude) return {}; QVariantMap result; diff --git a/apps/ied_simulator/src/ied_browser_large_model_qa.cpp b/apps/ied_simulator/src/ied_browser_large_model_qa.cpp index 04ecaeed4..3f767bbb5 100644 --- a/apps/ied_simulator/src/ied_browser_large_model_qa.cpp +++ b/apps/ied_simulator/src/ied_browser_large_model_qa.cpp @@ -640,6 +640,11 @@ int main(int argc, char** argv) { addAttribute(phasor, "q", "ST", "bit-string"); // wrong FC must never leak addAttribute(phasor, "q", "MX", "bit-string"); addAttribute(phasor, "t", "MX", "utc-time"); + auto& integerVector = addObject("PhVInteger", "CMV", MmsLiveModelConfidence::exact); + addAttribute(integerVector, "cVal.mag.i", "MX", "integer"); + addAttribute(integerVector, "cVal.ang.i", "MX", "integer"); + auto& integerSav = addObject("SavInteger", "SAV", MmsLiveModelConfidence::exact); + addAttribute(integerSav, "instMag.i", "MX", "integer"); for (const std::string name : {"Hz", "TotW"}) { auto& scalar = addObject(name, "MV", MmsLiveModelConfidence::exact); addAttribute(scalar, "mag.f", "MX", "floating-point"); @@ -721,6 +726,28 @@ int main(int argc, char** argv) { return 42; } } + received(QStringLiteral("MMXU1$MX$PhVInteger$cVal$mag$i"), QStringLiteral("127")); + received(QStringLiteral("MMXU1$MX$PhVInteger$cVal$ang$i"), QStringLiteral("-15")); + const auto integerPhasor = measurementModel.nodeForReference( + ref(QStringLiteral("PhVInteger"))) + .value(QStringLiteral("measurement")).toMap(); + if (integerPhasor.value(QStringLiteral("kind")).toString() != QStringLiteral("vector") || + integerPhasor.value(QStringLiteral("magnitude")).toString() != QStringLiteral("127") || + integerPhasor.value(QStringLiteral("angle")).toString() != QStringLiteral("-15")) { + std::cerr << "IED_BROWSER_LARGE_MODEL_FAIL m2l_integer_analogue_vector\n"; + return 48; + } + received(QStringLiteral("MMXU1$MX$SavInteger$instMag$i"), QStringLiteral("42")); + const auto integerScalar = measurementModel.nodeForReference( + ref(QStringLiteral("SavInteger"))) + .value(QStringLiteral("measurement")).toMap(); + if (integerScalar.value(QStringLiteral("kind")).toString() != QStringLiteral("scalar") || + integerScalar.value(QStringLiteral("magnitude")).toString() != QStringLiteral("42") || + integerScalar.contains(QStringLiteral("angle")) || + integerScalar.contains(QStringLiteral("unit"))) { + std::cerr << "IED_BROWSER_LARGE_MODEL_FAIL m2l_integer_analogue_scalar\n"; + return 49; + } received(QStringLiteral("MMXU1$ST$Health$stVal"), QStringLiteral("true")); const auto sourcedStatus = measurementModel.nodeForReference( ref(QStringLiteral("Health")));