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 void open() = 0;
31 virtual void close() = 0;
32
33 // Function called by the Simulation to perform interface synchronization
34 virtual void syncExports() = 0;
36 virtual void syncImports() = 0;
37
38 virtual CPS::Task::List getTasks() = 0;
39
40 virtual void setLogger(CPS::Logger::Log log);
41
42 virtual String &getName() { return mName; }
43
44 // Attributes used in the DPsim simulation. Should only be accessed by the dpsim-thread
45 // Tuple attributes: Attribute to be imported, Current sequenceID, blockOnRead, syncOnSimulationStart
46 std::vector<std::tuple<CPS::AttributeBase::Ptr, UInt, bool, bool>>
47 mImportAttrsDpsim;
48 // Tuple attributes: Attribute to be exported, Current Sequence ID
49 std::vector<std::tuple<CPS::AttributeBase::Ptr, UInt>> mExportAttrsDpsim;
50
51 virtual void addImport(CPS::AttributeBase::Ptr attr, bool blockOnRead = false,
52 bool syncOnSimulationStart = true);
53 virtual void addExport(CPS::AttributeBase::Ptr attr);
54
55protected:
56 CPS::Logger::Log mLog;
57 String mName;
58 bool mSyncOnSimulationStart;
59 UInt mCurrentSequenceDpsimToInterface = 1;
60 UInt mNextSequenceInterfaceToDpsim = 1;
61 std::atomic<bool> mOpened;
62};
63} // namespace DPsim
virtual void syncImports()=0
Function called by the Simulation to perform interface synchronization.