From bac330d2b6f57eec693f9631a21ebe9585f85312 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Sun, 20 Sep 2026 12:54:39 +0700 Subject: [PATCH 1/2] feat: add persistent canonical IED engineering context --- .github/workflows/ied-simulator-qt.yml | 7 +- apps/ied_simulator/CMakeLists.txt | 26 +- apps/ied_simulator/qml/Main.qml | 6 + .../src/IedEngineeringContextController.cpp | 532 ++++++++++++++++++ .../src/IedEngineeringContextController.hpp | 125 ++++ .../ied_simulator/src/MmsClientController.cpp | 20 +- .../ied_simulator/src/MmsClientController.hpp | 6 + .../src/SclWorkspaceController.hpp | 7 + .../src/SclWorkspaceController_part_01.inc | 21 + .../src/ied_engineering_context_qa.cpp | 192 +++++++ .../scl_assisted_workbench/CMakeLists.txt | 2 + 11 files changed, 940 insertions(+), 4 deletions(-) create mode 100644 apps/ied_simulator/src/IedEngineeringContextController.cpp create mode 100644 apps/ied_simulator/src/IedEngineeringContextController.hpp create mode 100644 apps/ied_simulator/src/ied_engineering_context_qa.cpp diff --git a/.github/workflows/ied-simulator-qt.yml b/.github/workflows/ied-simulator-qt.yml index ab34b2d76..607ee9ae9 100644 --- a/.github/workflows/ied-simulator-qt.yml +++ b/.github/workflows/ied-simulator-qt.yml @@ -61,7 +61,7 @@ jobs: - name: Build run: >- cmake --build build-ied-simulator-qt - --target arstack_ied_simulator ariec61850_mms_read_probe ariec61850_live_discover ariec61850_mms_sgcb_probe ied_setting_control_manifest_qa ied_simulator_guardrails_qa ied_simulator_responsiveness_qa ied_simulator_commissioning_qa ied_simulator_runtime_commissioning_qa ied_simulator_goose_publication_qa ied_goose_workspace_qa ied_mms_client_workbench_qa ied_report_workspace_qa ied_file_settings_workspace_qa ied_scl_workspace_qa ied_product_hardening_qa ied_browser_session_qa ied_browser_large_model_qa --parallel 2 + --target arstack_ied_simulator ariec61850_mms_read_probe ariec61850_live_discover ariec61850_mms_sgcb_probe ied_setting_control_manifest_qa ied_simulator_guardrails_qa ied_simulator_responsiveness_qa ied_simulator_commissioning_qa ied_simulator_runtime_commissioning_qa ied_simulator_goose_publication_qa ied_goose_workspace_qa ied_mms_client_workbench_qa ied_report_workspace_qa ied_file_settings_workspace_qa ied_scl_workspace_qa ied_product_hardening_qa ied_browser_session_qa ied_browser_large_model_qa ied_engineering_context_qa --parallel 2 - name: Bounded activity and child-output guardrails run: ./build-ied-simulator-qt/ied_simulator_guardrails_qa @@ -137,6 +137,11 @@ jobs: QT_QPA_PLATFORM: offscreen run: ./build-ied-simulator-qt/ied_browser_large_model_qa + - name: Canonical IED engineering context gates + env: + QT_QPA_PLATFORM: offscreen + run: ./build-ied-simulator-qt/ied_engineering_context_qa + - name: Prove interactive SCL import uses bounded async path env: QT_QPA_PLATFORM: offscreen diff --git a/apps/ied_simulator/CMakeLists.txt b/apps/ied_simulator/CMakeLists.txt index 0e94bcb74..950dd37f0 100644 --- a/apps/ied_simulator/CMakeLists.txt +++ b/apps/ied_simulator/CMakeLists.txt @@ -62,6 +62,8 @@ qt_add_qml_module(arstack_ied_simulator src/IedSignalModel.hpp src/MmsLiveTreeModel.cpp src/MmsLiveTreeModel.hpp + src/IedEngineeringContextController.cpp + src/IedEngineeringContextController.hpp src/MmsClientController.cpp src/MmsClientController.hpp src/IedBrowserSessionController.cpp @@ -240,6 +242,8 @@ add_executable(ied_mms_client_workbench_qa src/ied_mms_client_workbench_qa.cpp src/MmsLiveTreeModel.cpp src/MmsLiveTreeModel.hpp + src/IedEngineeringContextController.cpp + src/IedEngineeringContextController.hpp src/MmsClientController.cpp src/MmsClientController.hpp src/IedActivityModel.cpp @@ -305,7 +309,11 @@ target_compile_features(ied_file_settings_workspace_qa PRIVATE cxx_std_20) add_executable(ied_scl_workspace_qa src/ied_scl_workspace_qa.cpp src/SclWorkspaceController.cpp - src/SclWorkspaceController.hpp) + src/SclWorkspaceController.hpp + src/IedEngineeringContextController.cpp + src/IedEngineeringContextController.hpp + src/MmsLiveTreeModel.cpp + src/MmsLiveTreeModel.hpp) target_link_libraries(ied_scl_workspace_qa PRIVATE Qt6::Core Qt6::Qml @@ -331,6 +339,8 @@ add_executable(ied_browser_session_qa src/IedBrowserSessionController.hpp src/MmsLiveTreeModel.cpp src/MmsLiveTreeModel.hpp + src/IedEngineeringContextController.cpp + src/IedEngineeringContextController.hpp src/MmsClientController.cpp src/MmsClientController.hpp src/MmsReportController.cpp @@ -372,6 +382,20 @@ target_include_directories(ied_browser_large_model_qa PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src) target_compile_features(ied_browser_large_model_qa PRIVATE cxx_std_20) +add_executable(ied_engineering_context_qa + src/ied_engineering_context_qa.cpp + src/IedEngineeringContextController.cpp + src/IedEngineeringContextController.hpp + src/MmsLiveTreeModel.cpp + src/MmsLiveTreeModel.hpp) +target_link_libraries(ied_engineering_context_qa PRIVATE + Qt6::Core + Qt6::Qml + ARIEC61850::core) +target_include_directories(ied_engineering_context_qa PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/src) +target_compile_features(ied_engineering_context_qa PRIVATE cxx_std_20) + # The regular library intentionally keeps a strict portable connection runtime. # The desktop simulator needs the separate compatibility runtime validated # against common engineering-client AARQ, selector, browse, Identify and diff --git a/apps/ied_simulator/qml/Main.qml b/apps/ied_simulator/qml/Main.qml index bbf9e6ead..e691f81da 100644 --- a/apps/ied_simulator/qml/Main.qml +++ b/apps/ied_simulator/qml/Main.qml @@ -30,6 +30,10 @@ ApplicationWindow { id: hardening objectName: "productHardeningBackend" } + IedEngineeringContextController { + id: iedContext + objectName: "iedEngineeringContextBackend" + } IedFleetController { id: simulator objectName: "simulatorBackend" @@ -37,6 +41,7 @@ ApplicationWindow { MmsClientController { id: mmsClient objectName: "mmsClientBackend" + engineeringContext: iedContext } MmsReportController { id: reports @@ -56,6 +61,7 @@ ApplicationWindow { SclWorkspaceController { id: sclWorkspace objectName: "sclWorkspaceBackend" + engineeringContext: iedContext } GooseMonitorController { id: gooseMonitor diff --git a/apps/ied_simulator/src/IedEngineeringContextController.cpp b/apps/ied_simulator/src/IedEngineeringContextController.cpp new file mode 100644 index 000000000..2bf8104dc --- /dev/null +++ b/apps/ied_simulator/src/IedEngineeringContextController.cpp @@ -0,0 +1,532 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +#include "IedEngineeringContextController.hpp" + +#include + +#include +#include +#include +#include +#include + +namespace mms = ar::iec61850::mms; +namespace scl = ar::iec61850::scl; + +namespace { + +std::string logicalNodeName(const scl::SclLogicalNode& logicalNode) { + if (!logicalNode.name.empty()) return logicalNode.name; + return logicalNode.prefix + logicalNode.ln_class + logicalNode.ln_inst; +} + +std::string logicalNodeName(const scl::SclDataSetEntry& entry) { + return entry.prefix + entry.ln_class + entry.ln_inst; +} + +std::string mmsPath(std::string value) { + std::replace(value.begin(), value.end(), '.', '$'); + return value; +} + +std::string mmsItem(const scl::SclDataSetEntry& entry) { + auto item = logicalNodeName(entry); + if (!entry.functional_constraint.empty()) item += "$" + entry.functional_constraint; + if (!entry.do_name.empty()) item += "$" + mmsPath(entry.do_name); + if (!entry.da_name.empty()) item += "$" + mmsPath(entry.da_name); + return item; +} + +std::string mmsTypeForSclBasicType(std::string value) { + std::transform(value.begin(), value.end(), value.begin(), [](const unsigned char ch) { + return static_cast(std::toupper(ch)); + }); + if (value == "BOOLEAN") return "boolean"; + if (value.starts_with("INT") && value.ends_with("U")) return "unsigned"; + if (value.starts_with("INT") || value == "ENUM" || value == "ENUMERATED") return "integer"; + if (value.starts_with("FLOAT")) return "floating-point"; + if (value.starts_with("VISSTRING") || value == "CURRENCY") return "visible-string"; + if (value.starts_with("UNICODE") || value.starts_with("MMSSTRING")) return "mms-string"; + if (value == "QUALITY" || value == "CHECK" || value == "OPTFLDS" || value == "TRGOPS") return "bit-string"; + if (value == "TIMESTAMP" || value == "ENTRYTIME") return "utc-time"; + if (value.starts_with("OCTET") || value == "PHYCOMADDR") return "octet-string"; + return "unknown"; +} + +QString endpointText(const mms::MmsEndpoint& endpoint) { + if (endpoint.host.empty()) return {}; + const auto host = QString::fromStdString(endpoint.host); + const auto displayHost = host.contains(QLatin1Char(':')) ? QStringLiteral("[%1]").arg(host) : host; + return QStringLiteral("%1:%2").arg(displayHost).arg(endpoint.port); +} + +std::string referenceTail(const std::string& reference, const std::string& fallback) { + if (reference.empty()) return fallback; + const auto slash = reference.find_last_of("/."); + return slash == std::string::npos || slash + 1U >= reference.size() + ? reference + : reference.substr(slash + 1U); +} + +mms::MmsLiveModelDocument buildSclEngineeringModel( + const scl::SclDocument& document, + const std::string& iedName) { + mms::MmsLiveModelDocument model; + model.source = "OpenedSCL"; + model.identity.ied_name = iedName; + model.identity.source = "OpenedSCL"; + model.identity.confidence = mms::MmsLiveModelConfidence::exact; + model.identity.candidate_names = {iedName}; + model.identity.evidence.push_back("IED identity declared by the opened SCL source."); + + const auto accessPoint = std::find_if( + document.mms_access_points.begin(), + document.mms_access_points.end(), + [&](const auto& item) { return item.ied_name == iedName; }); + if (accessPoint != document.mms_access_points.end()) { + model.access_point_name = accessPoint->access_point_name.empty() ? "AP1" : accessPoint->access_point_name; + model.endpoint.host = accessPoint->ip_address; + model.endpoint.port = accessPoint->tcp_port; + } + + std::map> deviceIndex; + std::map, std::less<>> nodeIndex; + + const auto ensureDevice = [&](const std::string& ldInst) -> std::size_t { + const auto domain = iedName + ldInst; + if (const auto found = deviceIndex.find(domain); found != deviceIndex.end()) return found->second; + mms::MmsLiveLogicalDevice device; + device.mms_domain = domain; + device.instance = ldInst; + const auto index = model.logical_devices.size(); + model.logical_devices.push_back(std::move(device)); + deviceIndex.emplace(domain, index); + model.identity.logical_device_aliases.emplace(domain, ldInst); + return index; + }; + + const auto ensureNode = [&]( + const std::string& ldInst, + const std::string& name, + const std::string& prefix, + const std::string& lnClass, + const std::string& instance) -> std::pair { + const auto device = ensureDevice(ldInst); + const auto domain = iedName + ldInst; + const auto key = domain + "\x1f" + name; + if (const auto found = nodeIndex.find(key); found != nodeIndex.end()) return found->second; + mms::MmsLiveLogicalNode node; + node.name = name; + node.prefix = prefix; + node.logical_node_class = lnClass; + node.instance = instance; + const auto nodePos = model.logical_devices[device].logical_nodes.size(); + model.logical_devices[device].logical_nodes.push_back(std::move(node)); + const auto result = std::pair{device, nodePos}; + nodeIndex.emplace(key, result); + return result; + }; + + for (const auto& logicalNode : document.logical_nodes) { + if (logicalNode.ied_name != iedName) continue; + static_cast(ensureNode( + logicalNode.ld_inst, + logicalNodeName(logicalNode), + logicalNode.prefix, + logicalNode.ln_class, + logicalNode.ln_inst)); + } + + std::map> objectIndex; + for (const auto& entry : document.model_entries) { + if (entry.ied_name != iedName || entry.functional_constraint.empty()) continue; + const auto lnName = logicalNodeName(entry); + const auto [devicePos, nodePos] = ensureNode(entry.ld_inst, lnName, entry.prefix, entry.ln_class, entry.ln_inst); + auto& logicalNode = model.logical_devices[devicePos].logical_nodes[nodePos]; + ++logicalNode.functional_constraint_counts[entry.functional_constraint]; + + const auto domain = iedName + entry.ld_inst; + const auto objectKey = domain + "\x1f" + lnName + "\x1f" + entry.do_name; + std::size_t objectPos{}; + if (const auto found = objectIndex.find(objectKey); found != objectIndex.end()) { + objectPos = found->second; + } else { + mms::MmsLiveDataObject object; + object.name = entry.do_name; + object.reference = domain + "/" + lnName + "." + entry.do_name; + object.proposed_do_type_id = entry.type_id; + object.inferred_cdc = entry.cdc; + object.cdc_confidence = entry.cdc.empty() ? 0.0 : 1.0; + object.confidence = entry.cdc.empty() + ? mms::MmsLiveModelConfidence::high + : mms::MmsLiveModelConfidence::exact; + object.evidence.push_back("Opened SCL DataTypeTemplates projection."); + objectPos = logicalNode.data_objects.size(); + logicalNode.data_objects.push_back(std::move(object)); + objectIndex.emplace(objectKey, objectPos); + } + + mms::MmsLiveDataAttribute attribute; + attribute.object_reference = entry.signal_reference.empty() + ? domain + "/" + lnName + "." + entry.do_name + + (entry.da_name.empty() ? std::string{} : "." + entry.da_name) + : entry.signal_reference; + attribute.attribute_path = entry.da_name; + attribute.functional_constraint = entry.functional_constraint; + attribute.mms_item_name = mmsItem(entry); + attribute.mms_reference = domain + "/" + attribute.mms_item_name; + attribute.source = "OpenedSCL"; + attribute.scl_basic_type = entry.basic_type; + attribute.mms_type = mmsTypeForSclBasicType(entry.basic_type); + attribute.type_discovery_status = "Exact"; + attribute.type_discovery_message = "Type supplied by opened SCL; no live GVAA evidence required."; + attribute.type_source = "OpenedSCL"; + attribute.type_confidence = mms::MmsLiveModelConfidence::exact; + attribute.functional_constraint_confidence = mms::MmsLiveModelConfidence::exact; + logicalNode.data_objects[objectPos].attributes.push_back(std::move(attribute)); + } + + for (const auto& dataSet : document.data_sets) { + if (dataSet.ied_name != iedName) continue; + mms::MmsLiveDataSet projected; + projected.reference = dataSet.reference; + projected.domain = iedName + dataSet.ld_inst; + projected.logical_node = dataSet.logical_node_path; + projected.name = dataSet.name; + for (std::size_t index = 0U; index < dataSet.entries.size(); ++index) { + const auto& entry = dataSet.entries[index]; + mms::MmsLiveDataSetMember member; + member.index = index; + member.reference = entry.signal_reference; + member.functional_constraint = entry.functional_constraint; + member.mms_reference = (entry.ied_name + entry.ld_inst) + "/" + mmsItem(entry); + projected.members.push_back(std::move(member)); + } + model.data_sets.push_back(std::move(projected)); + } + + for (const auto& control : document.report_controls) { + if (control.ied_name != iedName) continue; + mms::MmsLiveReportControl projected; + projected.reference = control.control_block_reference; + projected.domain = iedName + control.ld_inst; + projected.logical_node = control.logical_node_path; + projected.name = control.name; + projected.buffered = control.buffered; + projected.data_set_reference = control.data_set_reference; + switch (control.data_set_binding_status) { + case scl::SclDataSetBindingStatus::resolved: projected.data_set_binding_status = "Bound"; break; + case scl::SclDataSetBindingStatus::resolved_empty: projected.data_set_binding_status = "Unbound"; break; + default: projected.data_set_binding_status = "NotRead"; break; + } + projected.report_id = control.report_id; + projected.configuration_revision = std::to_string(control.configuration_revision); + projected.buffer_time_ms = std::to_string(control.buffer_time_milliseconds); + projected.integrity_period_ms = std::to_string(control.integrity_period_milliseconds); + model.report_controls.push_back(std::move(projected)); + } + + for (const auto& stream : document.goose_streams) { + if (stream.ied_name != iedName) continue; + mms::MmsLiveControlBlock projected; + projected.kind = "GSEControl"; + projected.reference = stream.control_block_reference; + projected.domain = iedName + stream.ld_inst; + projected.logical_node = "LLN0"; + projected.name = stream.control_name; + projected.functional_constraint = "GO"; + projected.data_set_reference = stream.data_set_reference; + projected.control_id = stream.go_id; + projected.app_id = stream.address.app_id_text; + projected.configuration_revision = std::to_string(stream.configuration_revision); + projected.minimum_time_ms = std::to_string(stream.min_time_milliseconds); + projected.maximum_time_ms = std::to_string(stream.max_time_milliseconds); + projected.address_status = stream.address.destination_mac_text.empty() ? "NotSpecified" : "DeclaredBySCL"; + projected.discovery_status = "OpenedSCL"; + model.goose_control_blocks.push_back(std::move(projected)); + } + + for (const auto& stream : document.sampled_values_streams) { + if (stream.ied_name != iedName) continue; + mms::MmsLiveControlBlock projected; + projected.kind = "SampledValueControl"; + projected.reference = stream.control_block_reference; + projected.domain = iedName + stream.ld_inst; + projected.logical_node = "LLN0"; + projected.name = stream.control_name; + projected.functional_constraint = "MS"; + projected.data_set_reference = stream.data_set_reference; + projected.smv_id = stream.smv_id.empty() ? stream.sv_id : stream.smv_id; + projected.app_id = stream.address.app_id_text; + projected.configuration_revision = std::to_string(stream.configuration_revision); + projected.sample_rate = std::to_string(stream.sample_rate); + projected.sample_mode = stream.sample_mode; + projected.number_of_asdu = std::to_string(stream.no_asdu); + projected.address_status = stream.address.destination_mac_text.empty() ? "NotSpecified" : "DeclaredBySCL"; + projected.discovery_status = "OpenedSCL"; + model.sampled_value_control_blocks.push_back(std::move(projected)); + } + + for (const auto& setting : document.setting_controls) { + if (setting.ied_name != iedName) continue; + mms::MmsLiveControlBlock projected; + projected.kind = "SettingGroupControl"; + projected.reference = setting.control_block_reference; + projected.domain = iedName + setting.ld_inst; + projected.logical_node = setting.logical_node_path; + projected.name = referenceTail(setting.control_block_reference, "SGCB"); + projected.functional_constraint = "SP"; + projected.discovery_status = "OpenedSCL"; + projected.message = setting.valid() + ? "SettingControl declared by opened SCL." + : "SettingControl declared by opened SCL with incomplete runtime SG evidence."; + model.setting_group_controls.push_back(std::move(projected)); + } + + for (auto& dataSet : model.data_sets) { + for (const auto& report : model.report_controls) { + if (!report.data_set_reference.empty() && report.data_set_reference == dataSet.reference) + dataSet.used_by_report_controls.push_back(report.reference); + } + for (const auto& goose : model.goose_control_blocks) { + if (!goose.data_set_reference.empty() && goose.data_set_reference == dataSet.reference) + dataSet.used_by_goose_controls.push_back(goose.reference); + } + for (const auto& smv : model.sampled_value_control_blocks) { + if (!smv.data_set_reference.empty() && smv.data_set_reference == dataSet.reference) + dataSet.used_by_sampled_value_controls.push_back(smv.reference); + } + } + + model.coverage.logical_device_count = model.logical_devices.size(); + for (const auto& device : model.logical_devices) { + model.coverage.logical_node_count += device.logical_nodes.size(); + for (const auto& node : device.logical_nodes) { + model.coverage.data_object_count += node.data_objects.size(); + for (const auto& object : node.data_objects) { + model.coverage.data_attribute_count += object.attributes.size(); + model.coverage.exact_functional_constraint_count += object.attributes.size(); + model.coverage.exact_mms_type_count += static_cast(std::count_if( + object.attributes.begin(), object.attributes.end(), [](const auto& attribute) { + return attribute.mms_type != "unknown"; + })); + } + } + } + model.coverage.data_set_count = model.data_sets.size(); + model.coverage.report_control_count = model.report_controls.size(); + for (const auto& report : model.report_controls) { + if (report.buffered) ++model.coverage.buffered_report_control_count; + else ++model.coverage.unbuffered_report_control_count; + if (report.data_set_binding_status == "Bound") ++model.coverage.report_control_bound_count; + else if (report.data_set_binding_status == "Unbound") ++model.coverage.report_control_unbound_count; + else ++model.coverage.report_control_binding_not_read_count; + } + model.coverage.goose_control_block_count = model.goose_control_blocks.size(); + model.coverage.sampled_value_control_block_count = model.sampled_value_control_blocks.size(); + model.coverage.setting_group_control_count = model.setting_group_controls.size(); + + model.summary = + "Opened SCL canonical IED context: " + + std::to_string(model.coverage.logical_device_count) + " LD, " + + std::to_string(model.coverage.logical_node_count) + " LN, " + + std::to_string(model.coverage.data_attribute_count) + " DA, " + + std::to_string(model.coverage.data_set_count) + " DataSet, " + + std::to_string(model.coverage.report_control_count) + " ReportControl."; + return model; +} + +} // namespace + +IedEngineeringContextController::IedEngineeringContextController(QObject* parent) + : QObject(parent), treeModel_(this) {} + +QString IedEngineeringContextController::authority() const { + switch (authority_) { + case Authority::openedScl: return QStringLiteral("Open SCL"); + case Authority::liveDiscovery: return QStringLiteral("Live Discovery"); + case Authority::none: return QStringLiteral("None"); + } + return QStringLiteral("None"); +} + +QString IedEngineeringContextController::authorityKey() const { + switch (authority_) { + case Authority::openedScl: return QStringLiteral("scl"); + case Authority::liveDiscovery: return QStringLiteral("live-discovery"); + case Authority::none: return QStringLiteral("none"); + } + return QStringLiteral("none"); +} + +int IedEngineeringContextController::logicalDeviceCount() const noexcept { return model_ ? static_cast(model_->coverage.logical_device_count) : 0; } +int IedEngineeringContextController::logicalNodeCount() const noexcept { return model_ ? static_cast(model_->coverage.logical_node_count) : 0; } +int IedEngineeringContextController::dataObjectCount() const noexcept { return model_ ? static_cast(model_->coverage.data_object_count) : 0; } +int IedEngineeringContextController::dataAttributeCount() const noexcept { return model_ ? static_cast(model_->coverage.data_attribute_count) : 0; } +int IedEngineeringContextController::dataSetCount() const noexcept { return model_ ? static_cast(model_->data_sets.size()) : 0; } +int IedEngineeringContextController::reportCount() const noexcept { return model_ ? static_cast(model_->report_controls.size()) : 0; } +int IedEngineeringContextController::gooseCount() const noexcept { return model_ ? static_cast(model_->goose_control_blocks.size()) : 0; } +int IedEngineeringContextController::sampledValueCount() const noexcept { return model_ ? static_cast(model_->sampled_value_control_blocks.size()) : 0; } +int IedEngineeringContextController::settingGroupCount() const noexcept { return model_ ? static_cast(model_->setting_group_controls.size()) : 0; } + +void IedEngineeringContextController::applyModel(std::shared_ptr model) { + model_ = std::move(model); + if (!model_) { + treeModel_.clear(); + iedName_.clear(); + accessPointName_.clear(); + endpoint_.clear(); + structuralFingerprint_.clear(); + return; + } + treeModel_.applyDocument(*model_); + iedName_ = QString::fromStdString(model_->identity.ied_name); + accessPointName_ = QString::fromStdString(model_->access_point_name); + endpoint_ = endpointText(model_->endpoint); + structuralFingerprint_ = QString::fromStdString(model_->structural_fingerprint_hex()); +} + +bool IedEngineeringContextController::publishSclDocument( + const scl::SclDocument& document, + const QString& sourcePath, + const QString& selectedIedName) { + authority_ = Authority::openedScl; + sclSource_ = std::make_shared(document); + sourcePath_ = sourcePath.trimmed(); + sourceName_ = !sourcePath_.isEmpty() ? QFileInfo(sourcePath_).fileName() : QString::fromStdString(document.source_name); + candidateIeds_.clear(); + for (const auto& ied : document.ieds) candidateIeds_.push_back(QString::fromStdString(ied.name)); + + online_ = false; + runtimeEndpoint_.clear(); + selectionRequired_ = false; + lastError_.clear(); + applyModel({}); + + if (candidateIeds_.isEmpty()) { + lastError_ = QStringLiteral("Opened SCL source contains no selectable IED."); + ++contextGeneration_; + ++runtimeGeneration_; + emit contextChanged(); + emit runtimeChanged(); + return false; + } + + auto requested = selectedIedName.trimmed(); + if (requested.isEmpty() && candidateIeds_.size() == 1) requested = candidateIeds_.constFirst(); + if (requested.isEmpty()) { + selectionRequired_ = true; + lastError_ = QStringLiteral("Opened SCL contains %1 IEDs; select the active IED before Browser binding.") + .arg(candidateIeds_.size()); + ++contextGeneration_; + ++runtimeGeneration_; + emit contextChanged(); + emit runtimeChanged(); + return true; + } + return activateSclIed(requested); +} + +bool IedEngineeringContextController::activateSclIed(const QString& iedName) { + if (authority_ != Authority::openedScl || !sclSource_) { + lastError_ = QStringLiteral("No opened SCL source is available for IED selection."); + emit contextChanged(); + return false; + } + const auto requested = iedName.trimmed(); + const auto found = std::find(candidateIeds_.begin(), candidateIeds_.end(), requested); + if (requested.isEmpty() || found == candidateIeds_.end()) { + lastError_ = QStringLiteral("IED '%1' is not present in the opened SCL source.").arg(requested); + emit contextChanged(); + return false; + } + + applyModel(std::make_shared( + buildSclEngineeringModel(*sclSource_, requested.toStdString()))); + selectionRequired_ = false; + online_ = false; + runtimeEndpoint_.clear(); + lastError_.clear(); + ++contextGeneration_; + ++runtimeGeneration_; + emit contextChanged(); + emit runtimeChanged(); + return true; +} + +bool IedEngineeringContextController::selectIed(const QString& iedName) { + return activateSclIed(iedName); +} + +void IedEngineeringContextController::publishLiveDiscovery(const mms::MmsLiveModelDocument& model) { + authority_ = Authority::liveDiscovery; + sclSource_.reset(); + sourcePath_.clear(); + sourceName_ = QString::fromStdString(model.identity.ied_name); + candidateIeds_ = {QString::fromStdString(model.identity.ied_name)}; + selectionRequired_ = false; + lastError_.clear(); + applyModel(std::make_shared(model)); + online_ = true; + runtimeEndpoint_ = endpoint_; + ++contextGeneration_; + ++runtimeGeneration_; + emit contextChanged(); + emit runtimeChanged(); +} + +void IedEngineeringContextController::publishTrustedSclOnline( + const mms::MmsLiveModelDocument& onlineModel, + const QString& sourcePath) { + const auto onlineIed = QString::fromStdString(onlineModel.identity.ied_name); + if (authority_ == Authority::openedScl && model_ && iedName_ == onlineIed) { + if (sourcePath_.isEmpty()) { + sourcePath_ = sourcePath.trimmed(); + sourceName_ = QFileInfo(sourcePath_).fileName(); + ++contextGeneration_; + emit contextChanged(); + } + setRuntimeOnline(true, endpointText(onlineModel.endpoint)); + return; + } + + authority_ = Authority::openedScl; + sclSource_.reset(); + sourcePath_ = sourcePath.trimmed(); + sourceName_ = QFileInfo(sourcePath_).fileName(); + candidateIeds_ = {onlineIed}; + selectionRequired_ = false; + lastError_.clear(); + applyModel(std::make_shared(onlineModel)); + online_ = true; + runtimeEndpoint_ = endpointText(onlineModel.endpoint); + ++contextGeneration_; + ++runtimeGeneration_; + emit contextChanged(); + emit runtimeChanged(); +} + +void IedEngineeringContextController::setRuntimeOnline(const bool online, const QString& endpoint) { + const auto normalizedEndpoint = online ? endpoint.trimmed() : QString{}; + if (online_ == online && runtimeEndpoint_ == normalizedEndpoint) return; + online_ = online; + runtimeEndpoint_ = normalizedEndpoint; + ++runtimeGeneration_; + emit runtimeChanged(); +} + +void IedEngineeringContextController::clearContext() { + authority_ = Authority::none; + sclSource_.reset(); + applyModel({}); + sourcePath_.clear(); + sourceName_.clear(); + candidateIeds_.clear(); + selectionRequired_ = false; + lastError_.clear(); + online_ = false; + runtimeEndpoint_.clear(); + ++contextGeneration_; + ++runtimeGeneration_; + emit contextChanged(); + emit runtimeChanged(); +} diff --git a/apps/ied_simulator/src/IedEngineeringContextController.hpp b/apps/ied_simulator/src/IedEngineeringContextController.hpp new file mode 100644 index 000000000..7961b56fb --- /dev/null +++ b/apps/ied_simulator/src/IedEngineeringContextController.hpp @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +#pragma once + +#include "MmsLiveTreeModel.hpp" + +#include "ariec61850/mms/live_model.hpp" +#include "ariec61850/scl/model.hpp" + +#include +#include +#include +#include + +#include + +class IedEngineeringContextController final : public QObject { + Q_OBJECT + QML_ELEMENT + + Q_PROPERTY(bool hasSource READ hasSource NOTIFY contextChanged) + Q_PROPERTY(bool loaded READ loaded NOTIFY contextChanged) + Q_PROPERTY(bool selectionRequired READ selectionRequired NOTIFY contextChanged) + Q_PROPERTY(QString authority READ authority NOTIFY contextChanged) + Q_PROPERTY(QString authorityKey READ authorityKey NOTIFY contextChanged) + Q_PROPERTY(QString sourcePath READ sourcePath NOTIFY contextChanged) + Q_PROPERTY(QString sourceName READ sourceName NOTIFY contextChanged) + Q_PROPERTY(QString iedName READ iedName NOTIFY contextChanged) + Q_PROPERTY(QStringList candidateIeds READ candidateIeds NOTIFY contextChanged) + Q_PROPERTY(QString accessPointName READ accessPointName NOTIFY contextChanged) + Q_PROPERTY(QString endpoint READ endpoint NOTIFY contextChanged) + Q_PROPERTY(QString structuralFingerprint READ structuralFingerprint NOTIFY contextChanged) + Q_PROPERTY(QString lastError READ lastError NOTIFY contextChanged) + Q_PROPERTY(bool online READ online NOTIFY runtimeChanged) + Q_PROPERTY(QString runtimeEndpoint READ runtimeEndpoint NOTIFY runtimeChanged) + Q_PROPERTY(qulonglong contextGeneration READ contextGeneration NOTIFY contextChanged) + Q_PROPERTY(qulonglong runtimeGeneration READ runtimeGeneration NOTIFY runtimeChanged) + Q_PROPERTY(int logicalDeviceCount READ logicalDeviceCount NOTIFY contextChanged) + Q_PROPERTY(int logicalNodeCount READ logicalNodeCount NOTIFY contextChanged) + Q_PROPERTY(int dataObjectCount READ dataObjectCount NOTIFY contextChanged) + Q_PROPERTY(int dataAttributeCount READ dataAttributeCount NOTIFY contextChanged) + Q_PROPERTY(int dataSetCount READ dataSetCount NOTIFY contextChanged) + Q_PROPERTY(int reportCount READ reportCount NOTIFY contextChanged) + Q_PROPERTY(int gooseCount READ gooseCount NOTIFY contextChanged) + Q_PROPERTY(int sampledValueCount READ sampledValueCount NOTIFY contextChanged) + Q_PROPERTY(int settingGroupCount READ settingGroupCount NOTIFY contextChanged) + Q_PROPERTY(MmsLiveTreeModel* treeModel READ treeModel CONSTANT) + +public: + explicit IedEngineeringContextController(QObject* parent = nullptr); + + [[nodiscard]] bool hasSource() const noexcept { return authority_ != Authority::none; } + [[nodiscard]] bool loaded() const noexcept { return static_cast(model_); } + [[nodiscard]] bool selectionRequired() const noexcept { return selectionRequired_; } + [[nodiscard]] QString authority() const; + [[nodiscard]] QString authorityKey() const; + [[nodiscard]] QString sourcePath() const { return sourcePath_; } + [[nodiscard]] QString sourceName() const { return sourceName_; } + [[nodiscard]] QString iedName() const { return iedName_; } + [[nodiscard]] QStringList candidateIeds() const { return candidateIeds_; } + [[nodiscard]] QString accessPointName() const { return accessPointName_; } + [[nodiscard]] QString endpoint() const { return endpoint_; } + [[nodiscard]] QString structuralFingerprint() const { return structuralFingerprint_; } + [[nodiscard]] QString lastError() const { return lastError_; } + [[nodiscard]] bool online() const noexcept { return online_; } + [[nodiscard]] QString runtimeEndpoint() const { return runtimeEndpoint_; } + [[nodiscard]] qulonglong contextGeneration() const noexcept { return contextGeneration_; } + [[nodiscard]] qulonglong runtimeGeneration() const noexcept { return runtimeGeneration_; } + + [[nodiscard]] int logicalDeviceCount() const noexcept; + [[nodiscard]] int logicalNodeCount() const noexcept; + [[nodiscard]] int dataObjectCount() const noexcept; + [[nodiscard]] int dataAttributeCount() const noexcept; + [[nodiscard]] int dataSetCount() const noexcept; + [[nodiscard]] int reportCount() const noexcept; + [[nodiscard]] int gooseCount() const noexcept; + [[nodiscard]] int sampledValueCount() const noexcept; + [[nodiscard]] int settingGroupCount() const noexcept; + [[nodiscard]] MmsLiveTreeModel* treeModel() noexcept { return &treeModel_; } + + bool publishSclDocument( + const ar::iec61850::scl::SclDocument& document, + const QString& sourcePath, + const QString& selectedIedName = {}); + void publishLiveDiscovery(const ar::iec61850::mms::MmsLiveModelDocument& model); + void publishTrustedSclOnline( + const ar::iec61850::mms::MmsLiveModelDocument& onlineModel, + const QString& sourcePath); + void setRuntimeOnline(bool online, const QString& endpoint = {}); + + Q_INVOKABLE bool selectIed(const QString& iedName); + Q_INVOKABLE void clearContext(); + + [[nodiscard]] const ar::iec61850::mms::MmsLiveModelDocument* modelSnapshot() const noexcept { + return model_.get(); + } + +signals: + void contextChanged(); + void runtimeChanged(); + +private: + enum class Authority : quint8 { none, openedScl, liveDiscovery }; + + bool activateSclIed(const QString& iedName); + void applyModel(std::shared_ptr model); + + Authority authority_{Authority::none}; + std::shared_ptr sclSource_; + std::shared_ptr model_; + MmsLiveTreeModel treeModel_; + + QString sourcePath_; + QString sourceName_; + QString iedName_; + QStringList candidateIeds_; + QString accessPointName_; + QString endpoint_; + QString structuralFingerprint_; + QString lastError_; + bool selectionRequired_{}; + bool online_{}; + QString runtimeEndpoint_; + qulonglong contextGeneration_{}; + qulonglong runtimeGeneration_{}; +}; diff --git a/apps/ied_simulator/src/MmsClientController.cpp b/apps/ied_simulator/src/MmsClientController.cpp index 1984b0b5e..c4bdd720d 100644 --- a/apps/ied_simulator/src/MmsClientController.cpp +++ b/apps/ied_simulator/src/MmsClientController.cpp @@ -158,6 +158,12 @@ void MmsClientController::setPort(const int value) { emit configurationChanged(); } +void MmsClientController::setEngineeringContext(IedEngineeringContextController* value) { + if (engineeringContext_ == value) return; + engineeringContext_ = value; + emit engineeringContextChanged(); +} + void MmsClientController::setTrustedSclPath(const QString& value) { const auto normalized = value.trimmed(); if (trustedSclPath_ == normalized) return; @@ -251,6 +257,7 @@ bool MmsClientController::connectToIed() { operationBusy_ = false; lastError_.clear(); clearModelState(); + if (engineeringContext_) engineeringContext_->setRuntimeOnline(false); appendDiagnostic(QStringLiteral("Connect %1:%2 · generation %3 · model source %4") .arg(requestedHost) .arg(requestedPort) @@ -355,7 +362,7 @@ bool MmsClientController::connectToIed() { if (self) { QMetaObject::invokeMethod( self, - [self, generation, model, snapshot, initialValues, associationProfile, healthSummary] { + [self, generation, model, snapshot, initialValues, associationProfile, healthSummary, requestedTrustedSclPath] { if (!self || self->generation_ != generation) return; self->treeModel_.applyDocument(*model); for (const auto& value : *initialValues) { @@ -376,6 +383,10 @@ bool MmsClientController::connectToIed() { static_cast(model->coverage.data_attribute_count); self->state_ = State::connected; self->lastError_.clear(); + if (self->engineeringContext_) { + self->engineeringContext_->publishTrustedSclOnline( + *model, requestedTrustedSclPath); + } self->appendDiagnostic(healthSummary); self->appendDiagnostic( QStringLiteral( @@ -421,6 +432,9 @@ bool MmsClientController::connectToIed() { self->dataAttributeCount_ = static_cast(model->coverage.data_attribute_count); self->state_ = State::connected; self->lastError_.clear(); + if (self->engineeringContext_) { + self->engineeringContext_->publishLiveDiscovery(*model); + } self->appendDiagnostic( QStringLiteral("Discovery complete · %1 LD · %2 LN · %3 DA") .arg(self->logicalDeviceCount_) @@ -442,6 +456,7 @@ bool MmsClientController::connectToIed() { if (!self || self->generation_ != generation) return; self->state_ = State::faulted; self->lastError_ = message; + if (self->engineeringContext_) self->engineeringContext_->setRuntimeOnline(false); self->appendDiagnostic(QStringLiteral("Connection failed · %1").arg(message)); emit self->stateChanged(); }, Qt::QueuedConnection); @@ -460,7 +475,8 @@ void MmsClientController::disconnectFromIed() { operationBusy_ = false; lastError_.clear(); clearModelState(); - appendDiagnostic(QStringLiteral("Disconnected · session generation invalidated.")); + if (engineeringContext_) engineeringContext_->setRuntimeOnline(false); + appendDiagnostic(QStringLiteral("Disconnected · session generation invalidated; engineering context retained.")); emit stateChanged(); const auto worker = workerState_; diff --git a/apps/ied_simulator/src/MmsClientController.hpp b/apps/ied_simulator/src/MmsClientController.hpp index 31a55ef86..3c943b1a5 100644 --- a/apps/ied_simulator/src/MmsClientController.hpp +++ b/apps/ied_simulator/src/MmsClientController.hpp @@ -2,6 +2,7 @@ #pragma once #include "MmsLiveTreeModel.hpp" +#include "IedEngineeringContextController.hpp" #include #include @@ -18,6 +19,7 @@ class MmsClientController : public QObject { Q_PROPERTY(QString host READ host WRITE setHost NOTIFY configurationChanged) Q_PROPERTY(int port READ port WRITE setPort NOTIFY configurationChanged) Q_PROPERTY(QString trustedSclPath READ trustedSclPath WRITE setTrustedSclPath NOTIFY configurationChanged) + Q_PROPERTY(IedEngineeringContextController* engineeringContext READ engineeringContext WRITE setEngineeringContext NOTIFY engineeringContextChanged) Q_PROPERTY(bool trustedSclAvailable READ trustedSclAvailable NOTIFY configurationChanged) Q_PROPERTY(QString trustedSclHealth READ trustedSclHealth NOTIFY stateChanged) Q_PROPERTY(bool trustedSclDegraded READ trustedSclDegraded NOTIFY stateChanged) @@ -48,6 +50,7 @@ class MmsClientController : public QObject { [[nodiscard]] int port() const noexcept { return port_; } [[nodiscard]] QString trustedSclPath() const { return trustedSclPath_; } [[nodiscard]] bool trustedSclAvailable() const noexcept { return !trustedSclPath_.isEmpty(); } + [[nodiscard]] IedEngineeringContextController* engineeringContext() const noexcept { return engineeringContext_; } [[nodiscard]] QString trustedSclHealth() const { if (lastError_.contains(QStringLiteral("SCL online identity incompatible"), Qt::CaseInsensitive)) { return QStringLiteral("incompatible"); @@ -70,6 +73,7 @@ class MmsClientController : public QObject { void setHost(const QString& value); void setPort(int value); void setTrustedSclPath(const QString& value); + void setEngineeringContext(IedEngineeringContextController* value); [[nodiscard]] bool connected() const noexcept; [[nodiscard]] bool busy() const noexcept; @@ -99,6 +103,7 @@ class MmsClientController : public QObject { signals: void configurationChanged(); + void engineeringContextChanged(); void stateChanged(); void modelChanged(); void diagnosticsChanged(); @@ -116,6 +121,7 @@ class MmsClientController : public QObject { QString host_{QStringLiteral("127.0.0.1")}; int port_{102}; QString trustedSclPath_; + IedEngineeringContextController* engineeringContext_{}; State state_{State::disconnected}; bool operationBusy_{}; QString iedName_; diff --git a/apps/ied_simulator/src/SclWorkspaceController.hpp b/apps/ied_simulator/src/SclWorkspaceController.hpp index 791414289..eeac27f1d 100644 --- a/apps/ied_simulator/src/SclWorkspaceController.hpp +++ b/apps/ied_simulator/src/SclWorkspaceController.hpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later #pragma once +#include "IedEngineeringContextController.hpp" #include "ariec61850/scl/model.hpp" #include @@ -20,6 +21,7 @@ class SclWorkspaceController : public QObject { QML_ELEMENT Q_PROPERTY(bool loaded READ loaded NOTIFY workspaceChanged) + Q_PROPERTY(IedEngineeringContextController* engineeringContext READ engineeringContext WRITE setEngineeringContext NOTIFY engineeringContextChanged) Q_PROPERTY(bool busy READ busy NOTIFY stateChanged) Q_PROPERTY(QString stateText READ stateText NOTIFY stateChanged) Q_PROPERTY(QString sourcePath READ sourcePath NOTIFY workspaceChanged) @@ -54,6 +56,7 @@ class SclWorkspaceController : public QObject { ~SclWorkspaceController() override; [[nodiscard]] bool loaded() const noexcept { return document_.has_value(); } + [[nodiscard]] IedEngineeringContextController* engineeringContext() const noexcept { return engineeringContext_; } [[nodiscard]] bool busy() const noexcept { return busy_; } [[nodiscard]] QString stateText() const; [[nodiscard]] QString sourcePath() const { return sourcePath_; } @@ -83,6 +86,8 @@ class SclWorkspaceController : public QObject { [[nodiscard]] QString lastExportMode() const { return lastExportMode_; } [[nodiscard]] qulonglong generation() const noexcept { return generation_; } + void setEngineeringContext(IedEngineeringContextController* value); + Q_INVOKABLE bool openFile(const QUrl& fileUrl); Q_INVOKABLE bool saveAs(const QUrl& fileUrl, const QString& targetEdition = QStringLiteral("preserve")); Q_INVOKABLE bool exportCanonical(const QUrl& fileUrl, const QString& targetEdition = QStringLiteral("preserve")); @@ -91,6 +96,7 @@ class SclWorkspaceController : public QObject { signals: void stateChanged(); + void engineeringContextChanged(); void workspaceChanged(); void exportChanged(); void diagnosticsChanged(); @@ -101,6 +107,7 @@ class SclWorkspaceController : public QObject { void setFailure(const QString& text); std::optional document_; + IedEngineeringContextController* engineeringContext_{}; QByteArray sourceBytes_; QString sourcePath_; QString sourceName_; diff --git a/apps/ied_simulator/src/SclWorkspaceController_part_01.inc b/apps/ied_simulator/src/SclWorkspaceController_part_01.inc index bbac5d02e..071077f1b 100644 --- a/apps/ied_simulator/src/SclWorkspaceController_part_01.inc +++ b/apps/ied_simulator/src/SclWorkspaceController_part_01.inc @@ -25,6 +25,15 @@ SclWorkspaceController::SclWorkspaceController(QObject* parent) ioPool_.setExpiryTimeout(-1); } +void SclWorkspaceController::setEngineeringContext(IedEngineeringContextController* value) { + if (engineeringContext_ == value) return; + engineeringContext_ = value; + emit engineeringContextChanged(); + if (engineeringContext_ && document_) { + engineeringContext_->publishSclDocument(*document_, sourcePath_); + } +} + SclWorkspaceController::~SclWorkspaceController() { if (stopSource_) stopSource_->request_stop(); ioPool_.clear(); @@ -240,6 +249,18 @@ bool SclWorkspaceController::openFile(const QUrl& fileUrl) { self->sourceName_ = info.fileName(); self->sourceFormat_ = info.suffix().toLower(); self->lastError_.clear(); + if (self->engineeringContext_) { + const auto published = self->engineeringContext_->publishSclDocument( + *self->document_, self->sourcePath_); + self->appendDiagnostic( + published + ? QStringLiteral("IED engineering context published · %1") + .arg(self->engineeringContext_->selectionRequired() + ? QStringLiteral("IED selection required") + : self->engineeringContext_->iedName()) + : QStringLiteral("IED engineering context rejected · %1") + .arg(self->engineeringContext_->lastError())); + } self->appendDiagnostic(QStringLiteral("Opened %1 · %2 · %3 bytes") .arg(self->sourceName_, self->editionText()) .arg(self->sourceBytes_.size())); diff --git a/apps/ied_simulator/src/ied_engineering_context_qa.cpp b/apps/ied_simulator/src/ied_engineering_context_qa.cpp new file mode 100644 index 000000000..9c5d09175 --- /dev/null +++ b/apps/ied_simulator/src/ied_engineering_context_qa.cpp @@ -0,0 +1,192 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +#include "IedEngineeringContextController.hpp" + +#include + +#include + +namespace scl = ar::iec61850::scl; + +namespace { + +scl::SclDocument makeIed(const std::string& name, const std::string& ip) { + scl::SclDocument document; + document.source_name = name + ".cid"; + document.edition = scl::SclEdition::edition2; + document.ieds.push_back({name, "ARStack", "QA", "1"}); + + scl::SclMmsAccessPoint ap; + ap.ied_name = name; + ap.access_point_name = "AP1"; + ap.ip_address = ip; + ap.tcp_port = 102; + document.mms_access_points.push_back(ap); + + scl::SclLogicalNode ln; + ln.ied_name = name; + ln.ld_inst = "LD0"; + ln.ln_class = "LLN0"; + ln.name = "LLN0"; + document.logical_nodes.push_back(ln); + + scl::SclDataSetEntry status; + status.signal_reference = name + "LD0/LLN0.Mod.stVal"; + status.ied_name = name; + status.ld_inst = "LD0"; + status.ln_class = "LLN0"; + status.do_name = "Mod"; + status.da_name = "stVal"; + status.functional_constraint = "ST"; + status.cdc = "INC"; + status.basic_type = "INT32"; + status.type_id = "DO_INC"; + document.model_entries.push_back(status); + + scl::SclDataSet dataSet; + dataSet.key = name + "LD0/LLN0.Status"; + dataSet.ied_name = name; + dataSet.ld_inst = "LD0"; + dataSet.logical_node_path = "LLN0"; + dataSet.name = "Status"; + dataSet.reference = name + "LD0/LLN0.Status"; + dataSet.entries.push_back(status); + document.data_sets.push_back(dataSet); + + scl::SclReportControl report; + report.ied_name = name; + report.ld_inst = "LD0"; + report.logical_node_path = "LLN0"; + report.name = "StatusReport"; + report.report_id = name + "/Status"; + report.data_set_name = "Status"; + report.data_set_reference = dataSet.reference; + report.data_set_binding_status = scl::SclDataSetBindingStatus::resolved; + report.control_block_reference = name + "LD0/LLN0.RP.StatusReport"; + document.report_controls.push_back(report); + + scl::SclGooseStream goose; + goose.kind = "GOOSE"; + goose.ied_name = name; + goose.ld_inst = "LD0"; + goose.control_name = "StatusGoose"; + goose.control_block_reference = name + "LD0/LLN0.GO.StatusGoose"; + goose.data_set_name = "Status"; + goose.data_set_reference = dataSet.reference; + goose.configuration_revision = 1; + goose.go_id = name + "/StatusGoose"; + goose.address.app_id_text = "1001"; + goose.address.destination_mac_text = "01-0C-CD-01-00-01"; + document.goose_streams.push_back(goose); + + scl::SclSettingControl setting; + setting.ied_name = name; + setting.ld_inst = "LD0"; + setting.logical_node_path = "LLN0"; + setting.control_block_reference = name + "LD0/LLN0.SG.SGCB"; + setting.number_of_setting_groups = 4; + setting.active_setting_group = 1; + document.setting_controls.push_back(setting); + return document; +} + +void appendIed(scl::SclDocument& target, const scl::SclDocument& source) { + target.ieds.insert(target.ieds.end(), source.ieds.begin(), source.ieds.end()); + target.mms_access_points.insert(target.mms_access_points.end(), source.mms_access_points.begin(), source.mms_access_points.end()); + target.logical_nodes.insert(target.logical_nodes.end(), source.logical_nodes.begin(), source.logical_nodes.end()); + target.model_entries.insert(target.model_entries.end(), source.model_entries.begin(), source.model_entries.end()); + target.data_sets.insert(target.data_sets.end(), source.data_sets.begin(), source.data_sets.end()); + target.report_controls.insert(target.report_controls.end(), source.report_controls.begin(), source.report_controls.end()); + target.goose_streams.insert(target.goose_streams.end(), source.goose_streams.begin(), source.goose_streams.end()); + target.setting_controls.insert(target.setting_controls.end(), source.setting_controls.begin(), source.setting_controls.end()); +} + +} // namespace + +int main(int argc, char** argv) { + QCoreApplication app(argc, argv); + IedEngineeringContextController context; + + const auto sclA = makeIed("IED_A", "192.0.2.10"); + if (!context.publishSclDocument(sclA, QStringLiteral("/tmp/IED_A.cid")) || + !context.loaded() || + context.authorityKey() != QStringLiteral("scl") || + context.iedName() != QStringLiteral("IED_A") || + context.endpoint() != QStringLiteral("192.0.2.10:102") || + context.logicalDeviceCount() != 1 || + context.logicalNodeCount() != 1 || + context.dataObjectCount() != 1 || + context.dataAttributeCount() != 1 || + context.dataSetCount() != 1 || + context.reportCount() != 1 || + context.gooseCount() != 1 || + context.settingGroupCount() != 1 || + context.treeModel()->totalNodeCount() < 4 || + context.structuralFingerprint().isEmpty()) { + std::cerr << "IED_ENGINEERING_CONTEXT_FAIL scl_ingress\n"; + return 2; + } + + const auto sclFingerprint = context.structuralFingerprint(); + const auto sourceGeneration = context.contextGeneration(); + context.setRuntimeOnline(true, QStringLiteral("192.0.2.10:102")); + context.setRuntimeOnline(false); + if (!context.loaded() || + context.structuralFingerprint() != sclFingerprint || + context.contextGeneration() != sourceGeneration || + context.online()) { + std::cerr << "IED_ENGINEERING_CONTEXT_FAIL disconnect_persistence\n"; + return 3; + } + + auto multi = sclA; + appendIed(multi, makeIed("IED_B", "192.0.2.11")); + if (!context.publishSclDocument(multi, QStringLiteral("/tmp/multi.scd")) || + context.loaded() || + !context.selectionRequired() || + context.candidateIeds().size() != 2) { + std::cerr << "IED_ENGINEERING_CONTEXT_FAIL multi_ied_boundary\n"; + return 4; + } + if (!context.selectIed(QStringLiteral("IED_B")) || + !context.loaded() || + context.selectionRequired() || + context.iedName() != QStringLiteral("IED_B") || + context.endpoint() != QStringLiteral("192.0.2.11:102")) { + std::cerr << "IED_ENGINEERING_CONTEXT_FAIL explicit_ied_selection\n"; + return 5; + } + + const auto* selected = context.modelSnapshot(); + if (!selected) return 6; + auto live = *selected; + live.source = "LiveMmsDiscovery"; + live.endpoint.host = "192.0.2.11"; + live.endpoint.port = 102; + const auto selectedFingerprint = context.structuralFingerprint(); + context.publishLiveDiscovery(live); + if (!context.loaded() || + context.authorityKey() != QStringLiteral("live-discovery") || + !context.online() || + context.runtimeEndpoint() != QStringLiteral("192.0.2.11:102") || + context.structuralFingerprint() != selectedFingerprint) { + std::cerr << "IED_ENGINEERING_CONTEXT_FAIL live_ingress\n"; + return 7; + } + + context.setRuntimeOnline(false); + if (!context.loaded() || context.online() || context.authorityKey() != QStringLiteral("live-discovery")) { + std::cerr << "IED_ENGINEERING_CONTEXT_FAIL live_disconnect_persistence\n"; + return 8; + } + + std::cout + << "IED_ENGINEERING_CONTEXT_PASS" + << " scl_ingress=pass" + << " live_ingress=pass" + << " multi_ied_selection=pass" + << " disconnect_persistence=pass" + << " structural_authority=pass" + << " fingerprint=" << context.structuralFingerprint().toStdString() + << "\n"; + return 0; +} diff --git a/apps/ied_simulator/tests/scl_assisted_workbench/CMakeLists.txt b/apps/ied_simulator/tests/scl_assisted_workbench/CMakeLists.txt index 8d4258260..fe986c7a3 100644 --- a/apps/ied_simulator/tests/scl_assisted_workbench/CMakeLists.txt +++ b/apps/ied_simulator/tests/scl_assisted_workbench/CMakeLists.txt @@ -18,6 +18,8 @@ add_executable(ied_mms_scl_assisted_workbench_qa ${CMAKE_CURRENT_LIST_DIR}/../../src/ied_mms_scl_assisted_workbench_qa.cpp ${CMAKE_CURRENT_LIST_DIR}/../../src/MmsClientController.cpp ${CMAKE_CURRENT_LIST_DIR}/../../src/MmsClientController.hpp + ${CMAKE_CURRENT_LIST_DIR}/../../src/IedEngineeringContextController.cpp + ${CMAKE_CURRENT_LIST_DIR}/../../src/IedEngineeringContextController.hpp ${CMAKE_CURRENT_LIST_DIR}/../../src/MmsLiveTreeModel.cpp ${CMAKE_CURRENT_LIST_DIR}/../../src/MmsLiveTreeModel.hpp) From 3561ffe89761c932d7db82c27037a5013368ac76 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Sun, 20 Sep 2026 12:57:30 +0700 Subject: [PATCH 2/2] fix: allow Qt QML wrapper for engineering context --- apps/ied_simulator/src/IedEngineeringContextController.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/ied_simulator/src/IedEngineeringContextController.hpp b/apps/ied_simulator/src/IedEngineeringContextController.hpp index 7961b56fb..2b5a0b1ff 100644 --- a/apps/ied_simulator/src/IedEngineeringContextController.hpp +++ b/apps/ied_simulator/src/IedEngineeringContextController.hpp @@ -13,7 +13,7 @@ #include -class IedEngineeringContextController final : public QObject { +class IedEngineeringContextController : public QObject { Q_OBJECT QML_ELEMENT