-
Notifications
You must be signed in to change notification settings - Fork 16
Add new OPAL-RT Asynchronous Process node-type #924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # CMakeLists.txt | ||
| # | ||
| # Author: Steffen Vogel <[email protected]> | ||
| # SPDX-FileCopyrightText: 2023-2025 OPAL-RT Germany GmbH | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| set(TARGET_RTLAB_ROOT "/usr/opalrt" CACHE STRING "RT-LAB Root directory") | ||
|
|
||
| if(EXISTS "${TARGET_RTLAB_ROOT}/common/bin/opalmodelmk") | ||
| set(ENV{TARGET_RTLAB_ROOT} ${TARGET_RTLAB_ROOT}) | ||
|
|
||
| file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/get_vars.mk" | ||
| "all:\n\techo $(OPAL_LIBS) $(OPAL_LIBPATH)\n") | ||
|
|
||
| execute_process( | ||
| COMMAND make -sf ${TARGET_RTLAB_ROOT}/common/bin/opalmodelmk | ||
| WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" | ||
| OUTPUT_VARIABLE OPAL_VARS | ||
| ) | ||
|
|
||
| string(STRIP ${OPAL_VARS} OPAL_VARS) | ||
| string(REPLACE " " ";" OPAL_VARS ${OPAL_VARS}) | ||
|
|
||
| set(OPAL_LIBRARIES -lOpalCore -lOpalUtils ${OPAL_VARS} -lirc -ldl -pthread -lrt) | ||
| set(OPAL_INCLUDE_DIR ${TARGET_RTLAB_ROOT}/common/include_target) | ||
|
|
||
| add_library(OpalAsyncApi INTERFACE) | ||
| target_include_directories(OpalAsyncApi INTERFACE ${OPAL_INCLUDE_DIR}) | ||
| target_link_libraries(OpalAsyncApi INTERFACE ${OPAL_LIBRARIES}) | ||
| endif() | ||
|
|
||
| find_package_handle_standard_args(OpalAsyncApi DEFAULT_MSG OPAL_LIBRARIES OPAL_INCLUDE_DIR) | ||
|
|
||
| mark_as_advanced(OPAL_LIBRARIES OPAL_INCLUDE_DIR) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # yaml-language-server: $schema=http://json-schema.org/draft-07/schema | ||
| # SPDX-FileCopyrightText: 2025 Institute for Automation of Complex Power Systems, RWTH Aachen University | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| --- | ||
| allOf: | ||
| - $ref: ../node_obj.yaml | ||
| - $ref: opal_async.yaml |
42 changes: 42 additions & 0 deletions
42
doc/openapi/components/schemas/config/nodes/opal_async.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # yaml-language-server: $schema=http://json-schema.org/draft-07/schema | ||
| # Author: Steffen Vogel <[email protected]> | ||
| # SPDX-FileCopyrightText: 2023-2025 OPAL-RT Germany GmbH | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| --- | ||
| allOf: | ||
| - type: object | ||
| properties: | ||
| id: | ||
| description: The Send/Recv ID of the RT-Lab OpAsyncSend/Recv blocks. | ||
| min: 1 | ||
| default: 1 | ||
| type: integer | ||
|
|
||
| in: | ||
| type: object | ||
| properties: | ||
| reply: | ||
| description: Send a confirmation to the Simulink model that signals have been received and processed. | ||
| default: false | ||
| type: boolean | ||
|
|
||
| shmem: | ||
| description: Shared-memory parameters for communication with OpAsyncGenCtrl block of Simulink model. | ||
| type: object | ||
| required: | ||
| - async_name | ||
| - async_size | ||
| - system_ctrl_name | ||
| properties: | ||
| async_name: | ||
| description: Name of the shared memory region used for data exchange with the Simulink model. | ||
| type: string | ||
| async_size: | ||
| description: Size of the shared memory region used for data exchange with the Simulink model. | ||
| type: integer | ||
| system_ctrl_name: | ||
| description: Name of the shared memory region used for logging. | ||
| type: string | ||
|
|
||
| - $ref: ../node_signals.yaml | ||
| - $ref: ../node.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Author: Steffen Vogel <[email protected]> | ||
| # SPDX-FileCopyrightText: 2023-2025 OPAL-RT Germany GmbH | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| nodes = { | ||
| opal_async_node1 = { | ||
| type = "opal.async" | ||
|
|
||
| # The Send/Recv ID of the RT-Lab OpAsyncSend/Recv blocks. | ||
| id = 1 | ||
|
|
||
| in = { | ||
| # Send a confirmation to the Simulink model that signals have been received and processed. | ||
| reply = false | ||
|
|
||
| hooks = ( | ||
| "stats" | ||
| ) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| /* Node type: OPAL-RT Asynchronous Process (libOpalAsyncApi) | ||
| * | ||
| * Author: Steffen Vogel <[email protected]> | ||
| * SPDX-FileCopyrightText: 2023-2025 OPAL-RT Germany GmbH | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <condition_variable> | ||
| #include <mutex> | ||
|
|
||
| #include <spdlog/details/log_msg_buffer.h> | ||
| #include <spdlog/details/null_mutex.h> | ||
| #include <spdlog/sinks/base_sink.h> | ||
|
|
||
| // Define RTLAB before including OpalPrint.h for messages to be sent | ||
| // to the OpalDisplay. Otherwise stdout will be used. | ||
| #define RTLAB | ||
|
|
||
| #include <AsyncApi.h> | ||
| #include <OpalGenAsyncParamCtrl.h> | ||
| #include <OpalPrint.h> | ||
|
|
||
| #include <villas/format.hpp> | ||
| #include <villas/node.hpp> | ||
| #include <villas/popen.hpp> | ||
| #include <villas/sample.hpp> | ||
|
|
||
| namespace villas { | ||
| namespace node { | ||
| namespace opal { | ||
|
|
||
| class LogSink final : public spdlog::sinks::base_sink<std::mutex> { | ||
| private: | ||
| std::string shmemSystemCtrlName; | ||
|
|
||
| public: | ||
| explicit LogSink(const std::string &shmemName); | ||
|
|
||
| ~LogSink() override; | ||
|
|
||
| protected: | ||
| void sink_it_(const spdlog::details::log_msg &msg) override; | ||
|
|
||
| void flush_() override {} | ||
| }; | ||
|
|
||
| } // namespace opal | ||
|
|
||
| // Forward declarations | ||
| struct Sample; | ||
|
|
||
| class OpalAsyncNode : public Node { | ||
|
|
||
| protected: | ||
| // RT-LAB -> VILLASnode | ||
| // Corresponds to AsyncAPI's *Send* direction | ||
| struct { | ||
| unsigned id; | ||
| bool present; | ||
| unsigned length; | ||
|
|
||
| bool reply; | ||
| int mode; | ||
|
|
||
| Opal_SendAsyncParam params; | ||
| } in; | ||
|
|
||
| // VILLASnode -> RT-LAB | ||
| // Corresponds to AsyncAPI's *Recv* direction | ||
| struct { | ||
| unsigned id; | ||
| bool present; | ||
| unsigned length; | ||
|
|
||
| Opal_RecvAsyncParam params; | ||
| } out; | ||
|
|
||
| bool ready; | ||
| std::mutex readyLock; | ||
| std::condition_variable readyCv; | ||
|
|
||
| virtual int _read(struct Sample *smps[], unsigned cnt) override; | ||
|
|
||
| virtual int _write(struct Sample *smps[], unsigned cnt) override; | ||
|
|
||
| public: | ||
| OpalAsyncNode(const uuid_t &id = {}, const std::string &name = "") | ||
| : Node(id, name), ready(false) { | ||
| in.id = 1; | ||
| in.present = false; | ||
| in.length = 0; | ||
| in.reply = true; | ||
|
|
||
| out.id = 1; | ||
| out.present = false; | ||
| out.length = 0; | ||
| } | ||
|
|
||
| virtual const std::string &getDetails() override; | ||
|
|
||
| virtual int start() override; | ||
| virtual int stop() override; | ||
|
|
||
| virtual int parse(json_t *json) override; | ||
|
|
||
| void markReady(); | ||
| void waitReady(); | ||
| }; | ||
|
|
||
| class OpalAsyncNodeFactory : public NodeFactory { | ||
|
|
||
| public: | ||
| using NodeFactory::NodeFactory; | ||
|
|
||
| virtual Node *make(const uuid_t &id = {}, | ||
| const std::string &nme = "") override { | ||
| auto *n = new OpalAsyncNode(id, nme); | ||
|
|
||
| init(n); | ||
|
|
||
| return n; | ||
| } | ||
|
|
||
| virtual int getFlags() const override { | ||
| return (int)NodeFactory::Flags::SUPPORTS_READ | | ||
| (int)NodeFactory::Flags::SUPPORTS_WRITE | | ||
| (int)NodeFactory::Flags::PROVIDES_SIGNALS; | ||
| } | ||
|
|
||
| virtual std::string getName() const override { return "opal.async"; } | ||
|
|
||
| virtual std::string getDescription() const override { | ||
| return "OPAL Asynchronous Process (libOpalAsyncApi)"; | ||
| } | ||
|
|
||
| virtual int getVectorize() const override { return 1; } | ||
|
|
||
| virtual int start(SuperNode *sn) override; | ||
|
|
||
| virtual int stop() override; | ||
| }; | ||
|
|
||
| } // namespace node | ||
| } // namespace villas |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.