DPsim
Loading...
Searching...
No Matches
Interface.h
1// SPDX-License-Identifier: Apache-2.0
2
3#pragma once
4
5#include <thread>
6
7#include <dpsim-models/Attribute.h>
8#include <dpsim-models/Logger.h>
9#include <dpsim-models/Task.h>
10#include <dpsim/Config.h>
11#include <dpsim/Definitions.h>
12#include <dpsim/Interface.h>
13#include <dpsim/Scheduler.h>
14
15namespace DPsim {
16
17class InterfaceWorker;
18
19class Interface : public SharedFactory<Interface> {
20
21public:
22 typedef std::shared_ptr<Interface> Ptr;
23
24 Interface(const String &name = "", spdlog::level::level_enum logLevel =
25 spdlog::level::level_enum::info)
26 : mName(name), mOpened(false) {
27 mLog = CPS::Logger::get("Interface", logLevel);
28 };
29
30 virtual ~Interface() = default;
31
32 virtual void open() = 0;
33 virtual void close() = 0;
34
35 // Function called by the Simulation to perform interface synchronization
36 virtual void syncExports() = 0;
38 virtual void syncImports() = 0;
39
40 virtual CPS::Task::List getTasks() = 0;
41
42 virtual void setLogger(CPS::Logger::Log log);
43
44 virtual String &getName() { return mName; }
45
46 // Attributes used in the DPsim simulation. Should only be accessed by the dpsim-thread
47 // Tuple attributes: Attribute to be imported, Current sequenceID, blockOnRead, syncOnSimulationStart
48 std::vector<std::tuple<CPS::AttributeBase::Ptr, UInt, bool, bool>>
49 mImportAttrsDpsim;
50 // Tuple attributes: Attribute to be exported, Current Sequence ID
51 std::vector<std::tuple<CPS::AttributeBase::Ptr, UInt>> mExportAttrsDpsim;
52
53 virtual void addImport(CPS::AttributeBase::Ptr attr, bool blockOnRead = false,
54 bool syncOnSimulationStart = true);
55 virtual void addExport(CPS::AttributeBase::Ptr attr);
56
57protected:
58 CPS::Logger::Log mLog;
59 String mName;
60 bool mSyncOnSimulationStart;
61 UInt mCurrentSequenceDpsimToInterface = 1;
62 UInt mNextSequenceInterfaceToDpsim = 1;
63 std::atomic<bool> mOpened;
64};
65} // namespace DPsim
virtual void syncImports()=0
Function called by the Simulation to perform interface synchronization.