DPsim
Loading...
Searching...
No Matches
InterfaceVillasQueueless.h
Go to the documentation of this file.
1/* Author: Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
2 * SPDX-FileCopyrightText: 2023-2024 Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
3 * SPDX-License-Identifier: MPL-2.0
4 */
5
6#pragma once
7
11#include <dpsim-models/Task.h>
12#include <dpsim/Config.h>
13#include <dpsim/Definitions.h>
14#include <dpsim/Interface.h>
15#include <dpsim/Scheduler.h>
16
17#include <memory>
18#include <villas/kernel/rt.hpp>
19#include <villas/node.hpp>
20#include <villas/node/exceptions.hpp>
21#include <villas/node/memory.hpp>
22#include <villas/pool.hpp>
23#include <villas/sample.hpp>
24#include <villas/signal.hpp>
25#include <villas/signal_list.hpp>
26
27using namespace villas;
28
29namespace DPsim {
32 : public Interface,
33 public SharedFactory<InterfaceVillasQueueless> {
34
35public:
36 typedef std::shared_ptr<InterfaceVillasQueueless> Ptr;
37
42 const String &nodeConfig, const String &name = "",
43 spdlog::level::level_enum logLevel = spdlog::level::level_enum::info);
44
45 virtual void open() override;
46 virtual void close() override;
47
48 // Function called by the Simulation to perform interface synchronization
49 virtual void syncExports() override;
50 // Function called by the Simulation to perform interface synchronization
51 virtual void syncImports() override;
52
53 virtual CPS::Task::List getTasks() override;
54
55 virtual void printVillasSignals() const;
56
58 if (mOpened) {
59 try {
60 close();
61 } catch (const std::exception &e) {
62 SPDLOG_LOGGER_ERROR(mLog, "Error closing interface: {}", e.what());
63 }
64 }
65 }
66
67protected:
69 node::Node *mNode;
70 node::Pool mSamplePool;
71
72 virtual void writeToVillas();
73 virtual Int readFromVillas();
74 void createNode();
75 void createSignals();
78
79public:
80 class PreStep : public CPS::Task {
81 public:
83 : Task(intf.mName + ".Read"), mIntf(intf) {
84 for (const auto &[attr, _seqId, _blockOnRead, _syncOnStart] :
85 intf.mImportAttrsDpsim) {
86 mModifiedAttributes.push_back(attr);
87 }
88 }
89
90 void execute(Real time, Int timeStepCount) override;
91
92 private:
94 };
95
96 class PostStep : public CPS::Task {
97 public:
99 : Task(intf.mName + ".Write"), mIntf(intf) {
100 for (const auto &[attr, _seqId] : intf.mExportAttrsDpsim) {
101 mAttributeDependencies.push_back(attr);
102 }
104 }
105
106 void execute(Real time, Int timeStepCount) override;
107
108 private:
110 };
111};
112} // namespace DPsim
Tasks to be defined by every component.
Definition Task.h:25
std::vector< AttributeBase::Ptr > mModifiedAttributes
Definition Task.h:53
Task()
Definition Task.h:30
std::vector< Ptr > List
Definition Task.h:28
std::string mName
Definition Task.h:51
std::vector< std::tuple< CPS::AttributeBase::Ptr, UInt, bool, bool > > mImportAttrsDpsim
Definition Interface.h:49
std::atomic< bool > mOpened
Definition Interface.h:63
CPS::Logger::Log mLog
Definition Interface.h:58
std::vector< std::tuple< CPS::AttributeBase::Ptr, UInt > > mExportAttrsDpsim
Definition Interface.h:51
Interface(const String &name="", spdlog::level::level_enum logLevel=spdlog::level::level_enum::info)
Definition Interface.h:24
PostStep(InterfaceVillasQueueless &intf)
void execute(Real time, Int timeStepCount) override
void execute(Real time, Int timeStepCount) override
std::shared_ptr< InterfaceVillasQueueless > Ptr
virtual CPS::Task::List getTasks() override
virtual void syncImports() override
Function called by the Simulation to perform interface synchronization.
InterfaceVillasQueueless(const String &nodeConfig, const String &name="", spdlog::level::level_enum logLevel=spdlog::level::level_enum::info)
create a new InterfaceVillasQueueless instance
static CPS::AttributeBase::Ptr external
Definition Scheduler.h:63
CPS::Real Real
Definition Definitions.h:18
CPS::String String
Definition Definitions.h:20
CPS::Int Int
Definition Definitions.h:22